Skip to content

Commit 31096af

Browse files
test(organizations): a restart between the un-walled seed and the person's sign-up still fills the seed's person columns (#34581)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9J4L3bvmRRFrdqMXF1CMHSi)_ Fixes #34542 Clause-②: no Metadata-protocol: none The claim recorded `Clause-②: yes (widening)`; the diff is test-only, so both lines are corrected to what it measures. On `origin/main` (1e4656d) the card's premise does not hold for keyed datasets (`mode` `ignore`, `upsert`, `update`): no contract change is made. For `insert` / `replace` datasets the first row stays NULL after a restart, measured below; that is a different root cause and is filed as its own finding (see Acceptance notes). ## 维护者速读 - 改了什么:只加了一个测试。在未开组织隔离墙的安装里,带键种子(upsert)写完、被引用的人还没注册时重启一次,再让这个人注册,断言种子行上的人员列被补上。 - 为什么改:卡上担心待补引用只在进程内存里,重启就丢。实测带键模式(ignore、upsert、update)不会丢:未开墙的启动每次都重放内联种子,第二个进程按键找回同一行,又遇到同一个没解析的人,重新挂起,注册时照样补上。持久的持有者就是种子声明本身,所以没有改 seed-settlement 契约。无键模式(insert、replace)重启后原行仍是空的,因为重放每次都另插一行(或被唯一约束拒掉),这是另一个根因,另立卡跟进。 - 风险与回滚:不改任何产品代码,无风险;回滚即 revert。 - 先看:packages/plugins/organizations/src/default-organization-seed-owner.wall.test.ts 末尾新加的 describe(两次启动共用一个 SQLite 文件)。 - 两分钟验证:pnpm --filter @objectstack/organizations exec vitest run src/default-organization-seed-owner.wall.test.ts,预期 7 个用例全绿。 - 需要你做的:无,席位落地。 ## What changes - `packages/plugins/organizations/src/default-organization-seed-owner.wall.test.ts`: a new top-level `describe` in the existing harness file. It boots the un-walled app over a SQLite file (`bootStack({ databaseFile })`), reads the seeded row with NULL `assignee` / `reviewer`, stops the kernel before the named person exists, boots a second kernel cold over the same file, signs the person up, and asserts both columns now name the person on the row the first process seeded (same row id). The file header gains one paragraph saying what the leg shows. No product file changes. For a keyed dataset the held-reference list needs no persisted copy where #34516 put it (`SeedLoaderService`, held by `AppPlugin`): the inline seed of an un-walled boot runs on every start (`AppPlugin` runs it unless the wall is up or `skipSeedData` is set), reference resolution runs before the write decision, and a row the replay matches by its key still reports its landed id (`noteLanded` on the `skip` / `update` paths), so pass 2 holds the same reference again in the new process. That match exists only in the keyed modes (`keyedMode` in `loadDataset`; `decideWriteAction` answers `insert` for `insert` / `replace`), so the claim is limited to them. ## Tests - New: the restart leg above, 2 cases (a PREMISE case and the fill case). - No existing test was changed. ## Acceptance notes - Premise check on `origin/main` 1e4656d, before any edit, with the same two-boot probe: `mode: 'upsert'` dataset, columns filled after the restart; `mode: 'ignore'` dataset, filled too. `mode: 'update'` writes no row on the first boot (nothing to match), so the window does not arise. - Unkeyed modes, same two-boot probe on the same code (product files identical to `origin/main`), one record `{ name: 'Late task', assignee: 'Late Person', reviewer: 'Late Person' }`, the person signing up in the second process: - `mode: 'insert'` (with or without `externalId`) and `mode: 'replace'`: the second boot inserts a second `Late task` row. After the sign-up the new row names the person in both columns; the first process's row keeps `assignee` and `reviewer` NULL. - Same two modes with `name` declared `unique: true`: the second boot's insert is refused by the database (`UNIQUE constraint failed: seedowner_task.organization_id, seedowner_task.name`, logged at `warn`). After the sign-up the one row keeps both columns NULL. - So the card's symptom survives for `insert` / `replace` datasets. Its cause is not the in-memory hold but the unkeyed replay itself, which inserts the dataset again on every un-walled start. It is filed as its own finding: #34613. - Negative control (the probe can fail): the second boot mounting the same app with no datasets leaves both columns NULL after the person signs up (`AssertionError … to match object`, 1 failed). The fill depends on the restart's own replay, which is what the pin holds. - The card's second Done-when line ("one holder, the persisted record") assumed a persisted seed-settlement record. `seed-settlement` is an in-process probe (`ISeedSettlementService`); nothing persisted carries that name. With the replay already re-deriving the hold, a persisted copy would be a second holder of what the seed declaration already says. - What still cannot fill after a restart: a reference whose dataset is no longer declared on the restarted boot (the negative control). That is the seed no longer naming the person, not a lost hold. ## Verification <details><summary>Test file at 2bd14db</summary> ``` pnpm --filter @objectstack/organizations exec vitest run --maxWorkers=2 src/default-organization-seed-owner.wall.test.ts Tests 7 passed (7) os-verify-lock: VERDICT command-exit 0 ``` </details> <details><summary>Typecheck at 399d9b7 (the merge brought no change to this package)</summary> ``` pnpm --filter @objectstack/organizations typecheck os-verify-lock: VERDICT command-exit 0 ``` </details> <details><summary>Derived gate set</summary> `node scripts/pm/dispatch-gates.mjs --commands` derives 53 families for this diff. All 53 ran at 399d9b7 and answered exit 0; `--ran` reconciles 53 run, 0 NOT-MEASURED. Two first answered exit 3 (shallow clone; no full build) and were re-run after `git fetch --unshallow` and `pnpm build`. The same 53 were re-run on 8f3e7e4 (53/53 exit 0) and are re-run on 2bd14db, a header-comment change in the same file; the dev report on the card carries that reading. </details> <!-- signed: repo:objectstack#2 · os-steve · session_01ADHkmPJxG4vBVaLCBWLcWJ --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 842637a commit 31096af

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

‎packages/plugins/organizations/src/default-organization-seed-owner.wall.test.ts‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
* while its column is still NULL. So the un-walled boot resolves the owner too,
2525
* through its own moment rather than the walled replay's.
2626
*
27+
* The held list lives in the process, and the last leg restarts between the
28+
* seed and the person's sign-up. For a keyed dataset (`mode` `ignore`, `upsert`
29+
* or `update`) a restart loses nothing: the durable holder is the seed
30+
* declaration itself. An un-walled boot runs its inline seed on every start;
31+
* the replay matches the row it landed on before by its key, meets the same
32+
* unresolved person there, and holds it again. No second record of the held
33+
* references is kept. An `insert` or `replace` dataset matches no row on
34+
* replay, so its first row is not held again; that leg is not pinned here.
35+
*
2736
* ## What is real
2837
*
2938
* `bootStack` (`@objectstack/verify`): an `ObjectKernel` over in-process
@@ -35,6 +44,9 @@
3544
*/
3645

3746
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
47+
import { mkdtempSync, rmSync } from 'node:fs';
48+
import { tmpdir } from 'node:os';
49+
import { join } from 'node:path';
3850
import { bootStack, type VerifyStack } from '@objectstack/verify';
3951
import { OrganizationsPlugin } from './organizations-plugin.js';
4052

@@ -293,3 +305,75 @@ describe('un-walled: a held seed person reference fills only the seed’s own ro
293305
expect((await taskNamed('Guest task')).assignee).toBeNull();
294306
});
295307
});
308+
309+
/**
310+
* A restart between the un-walled seed and the person's sign-up loses nothing
311+
* for a keyed dataset (`mode: 'upsert'` here). The first process holds the
312+
* reference in memory and stops before the person exists. The second process
313+
* boots cold over the same database file; its own inline seed replays, matches
314+
* the same row by its key, meets the same NULL there, and holds it again, so
315+
* the person's sign-up in the second process fills the row.
316+
*/
317+
describe('un-walled: a restart between the seed and the person’s sign-up still fills the seed’s person columns', () => {
318+
const env = legEnv([
319+
['OS_TENANCY_POSTURE', undefined],
320+
['OS_AUTH_MEMBERSHIP_POLICY', undefined],
321+
]);
322+
const RESTART_NAME = 'Restart Person';
323+
const RESTART_EMAIL = 'restart.person@example.com';
324+
/** Built again for each boot: a live boot holds references into its configuration. */
325+
const restartApp = () => ({
326+
...APP,
327+
manifest: { ...APP.manifest, id: 'com.example.seedowner.restart' },
328+
data: [
329+
{
330+
object: TASK,
331+
mode: 'upsert',
332+
externalId: 'name',
333+
records: [{ name: 'Restart task', assignee: RESTART_NAME, reviewer: RESTART_NAME }],
334+
},
335+
],
336+
});
337+
const dir = mkdtempSync(join(tmpdir(), 'seed-person-restart-'));
338+
const databaseFile = join(dir, 'restart.sqlite');
339+
let stack: VerifyStack | undefined;
340+
let firstProcess: Array<Record<string, unknown>>;
341+
let afterRestart: Array<Record<string, unknown>>;
342+
let afterSignUp: Array<Record<string, unknown>>;
343+
let personId: string;
344+
345+
beforeAll(async () => {
346+
env.apply();
347+
const first = await bootStack(restartApp() as never, { extraPlugins: [new OrganizationsPlugin()], databaseFile });
348+
const firstQl = await first.kernel.getServiceAsync<any>('objectql');
349+
firstProcess = await firstQl.find(TASK, { where: {}, ...SYS });
350+
await first.stop();
351+
352+
stack = await bootStack(restartApp() as never, { extraPlugins: [new OrganizationsPlugin()], databaseFile });
353+
await stack.signIn();
354+
const ql = await stack.kernel.getServiceAsync<any>('objectql');
355+
afterRestart = await ql.find(TASK, { where: {}, ...SYS });
356+
await stack.signUp(RESTART_EMAIL, undefined, RESTART_NAME);
357+
personId = String((await ql.findOne('sys_user', { where: { email: RESTART_EMAIL }, ...SYS }))?.id ?? '');
358+
afterSignUp = await ql.find(TASK, { where: {}, ...SYS });
359+
}, 180_000);
360+
361+
afterAll(async () => {
362+
await stack?.stop();
363+
env.restore();
364+
rmSync(dir, { recursive: true, force: true });
365+
});
366+
367+
it('PREMISE: the first process seeded the row with NULL person columns, and the second booted over that same row', () => {
368+
expect(firstProcess).toHaveLength(1);
369+
expect(firstProcess[0]).toMatchObject({ assignee: null, reviewer: null });
370+
expect(afterRestart).toHaveLength(1);
371+
expect(afterRestart[0]).toMatchObject({ id: firstProcess[0].id, assignee: null, reviewer: null });
372+
});
373+
374+
it('the person’s sign-up after the restart fills both columns on the row the first process seeded', () => {
375+
expect(personId).not.toBe('');
376+
expect(afterSignUp).toHaveLength(1);
377+
expect(afterSignUp[0]).toMatchObject({ id: firstProcess[0].id, assignee: personId, reviewer: personId });
378+
});
379+
});

0 commit comments

Comments
 (0)