Skip to content

Commit b95d915

Browse files
fix(metadata-protocol)!: the seed membership probe is bounded by the organization's members, and an id-shaped person is judged by membership (#33611)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D4Jsmd91BqTVB7dSii9uJMV)_ Fixes #33280 Clause-②: no (narrowing) — narrowed: on a load for one organization, a person reference (`sys_user` lookup) whose value is UUID- or ObjectId-shaped resolves only when it names a member of that organization, where it was written verbatim. A member's id still resolves to itself; a load with no organization, a dry run and every other reference target keep an id-shaped value verbatim. Unchanged: the name/email lookup resolves the same member it did. Metadata-protocol: none Skills-docs: none — the seed docs (`content/docs/data-modeling/seed-data.mdx`) and `skills/**` already teach a natural key, not an id, for a reference; the membership rule they inherit from the prior seed-scoping change is unchanged in wording. ## 维护者速读 - 改了什么:种子加载器按组织解析人员引用时,先读该组织的 `sys_member`(按 `user_id` 键集分页),再对每页成员做一次 `sys_user` 读取(限定成员 id 与引用值);不再按 offset 翻遍全部署同名人员。UUID/ObjectId 形状的人员引用在按组织加载时也走成员资格判定。 - 为什么改:旧探针成本随部署规模增长(托管环境每个组织都有同名样例人员),offset 翻页在并发删除下可能跳过真正的成员而误报「不是成员」;UUID 形状的值完全绕过成员规则,可以把行挂到组织外的人身上。 - 风险与回滚:收窄仅一处——按组织加载时用 UUID 指向非成员的种子引用,现在留空并报错(与按名字引用一致);成员的 id 照常解析,无组织加载不变。回滚即还原本 PR。 - 先看:`packages/metadata-protocol/src/seed-loader.ts` 的 `probeOrganizationMember`(成员分页与「首页命中即最小 id」的论证),其次 `resolveReferenceItem` 里内部 id 短路的改动与 `judgesInternalIdByMembership`。 - 两分钟验证:`pnpm --filter @objectstack/runtime exec vitest run src/seed-org-scoped-references.integration.test.ts`,预期 21 个用例全绿,其中 #33280 三个新用例。 - 需要你做的:无,席位落地。 ## What changes `probeOrganizationMember` (`packages/metadata-protocol/src/seed-loader.ts`): - Reads the load organization's `sys_member` rows ordered by `user_id`, a page (500) at a time, by keyset (`user_id` greater than the last one seen). No `offset` anywhere, so a concurrent delete cannot shift a page and skip the member. - Each member page is asked ONE `sys_user` read constrained to that page's user ids AND the reference value, `orderBy id asc, limit 1`. Pages ascend by `user_id`, so the first page that answers holds the lowest-id member and the walk stops there: the "lowest id wins" rule of the previous probe holds. - On a miss, one `limit: 1` read of `sys_user` by the value says whether anyone outside the organization answers to it; it only words the verdict ("not a member of organization ..."). - The `id` probe leg reads the one membership row directly (`organization_id` + `user_id`), then confirms the person exists. - Cost is now bounded by the organization: an organization under 500 members answers a resolved reference with one member read and one person read, whatever the number of same-named people deployment-wide. The internal-id skip (`resolveReferenceItem`): an id-shaped value (`looksLikeInternalId`) is still kept verbatim, except on a load pinned to an organization (not a dry run) for the target whose probe scope is `members` (`sys_user`), where it now goes through the same lookup, so its `id` leg applies the membership rule. Decision: check it. A non-UUID id (`usr_...`) already reached the membership probe through the `id` leg; the recognised shapes were the only door past the rule. A seed naming a member by id keeps working (pinned). One changeset: `@objectstack/metadata-protocol` patch, with the BREAKING note and its fix. ## Tests New top-level describe in `packages/runtime/src/seed-org-scoped-references.integration.test.ts` (real `SqlDriver` over better-sqlite3, real `AppPlugin` replayer): - **Bound pin**: the same replay (North resolves the member, South is refused) with 0 and with 120 same-named strangers that sort before the member; the count of `sys_user`/`sys_member` reads is equal for both, on the hit and on the miss. No read carries `offset`; every person read naming the key is constrained to member ids or `limit: 1`; every member read is walled by the load organization. - **Id-shaped person**: a UUID of a North member resolves on North; a UUID of a South-only member is refused on North with the "not a member of organization" error, and vice versa. - **CONTROL**: a load with no organization keeps an id-shaped person value verbatim. The prior pins stay green: 60 same-named people with the member last, the `workspace_id`-walled object (both cases), the pass-2 back-fill that cannot see its row. <details><summary>Ablation (each leg: on-disk mutation by scripts/ablation-replace.mjs, metadata-protocol rebuilt, marker proven in dist/, restore proven blob == HEAD, rebuilt, marker proven absent)</summary> - Leg 1, the previous offset probe restored verbatim (page 50): `ablation-dist-preflight` "marker present in 2 built files"; integration file `Tests 1 failed | 20 passed (21)`, the bound pin red with `expected 6 to be 2` (North reads with 120 strangers vs none). Restore: `blob == HEAD (7ec7f8b) and git diff HEAD is empty`; rebuild then `--absent` green. A first attempt at this leg did not run: the mutated build failed its dts step (an unused constant), so no test ran; the replacement was respelled and the leg re-run. - Leg 2, the internal-id skip restored (the membership judgement forced off): marker present in 2 built files; `Tests 1 failed | 20 passed (21)`, the id-shaped person case red (`expected ... to deeply equal ...`: North's non-member UUID kept). Restore proven the same way; `--absent` green. </details> ## Verification Read at head `3a152285a2` (seed-loader blob `7ec7f8be7dbc`, unchanged since the ablations). <details><summary>Local runs</summary> - `pnpm --filter @objectstack/metadata-protocol test`: Test Files 340 passed, 9 skipped; Tests 22877 passed, 43 skipped. VERDICT command-exit 0. - `pnpm --filter @objectstack/runtime typecheck` (tsc + check:test-typecheck): VERDICT command-exit 0. - `pnpm --filter @objectstack/runtime test` (full suite, a direct dependent): Test Files 602 passed; Tests 10784 passed, 19 skipped. VERDICT command-exit 0. - `eslint --no-inline-config` on the two changed source files: exit 0, no findings. - Derived gate families (`dispatch-gates.mjs --commands`, 65 commands): see the report comment on the card for the reconciled list. `check:dual-build-cjs-loads` answered PREREQUISITE NOT MET (needs a whole-workspace build): NOT MEASURED locally, CI runs it. - Full dogfood battery (narrowing arm): running on this head at the time of writing; its reading is in the report comment on the card. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016WV4cw787kMeaX7oyz7DDC --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8f915f2 commit b95d915

3 files changed

Lines changed: 211 additions & 39 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@objectstack/metadata-protocol': patch
3+
---
4+
5+
fix(metadata-protocol)!: a seed load for one organization finds a person among that organization's members, by keyset, and judges a person named by an id-shaped value by the same membership rule
6+
7+
Clause-②: no (narrowing) — narrowed: on a load for one organization (the per-organization replay, a reseed, an install into an organization), a person reference (`owner_id`, a `sys_user` lookup) whose value is UUID- or ObjectId-shaped is resolved only when it names a member of that organization, where it was written verbatim, so an id of a person outside the organization linked the row to them. A member's id still resolves to itself, and a load with no organization, a dry run and every other reference target keep an id-shaped value verbatim, as before. Unchanged: the lookup by name or email resolves the same member it did.
8+
Metadata-protocol: none
9+
10+
<!-- adr-0087: not-required (no-migration-prescription) no key of any schema is added, removed, renamed or re-shaped and no stored row changes shape: what moves is which person an id-shaped seed reference resolves to on a load for one organization, so there is nothing for a migration to rewrite and no tombstone -->
11+
12+
**BREAKING** for a seed that names a person by an id-shaped value (UUID or ObjectId) on a load for one organization, where that person is not a member of the organization. The row is still seeded; the reference stays empty and the load's error says the person is not a member of that organization, exactly as it does for the same person named by name or email. The fix: add the person to the organization, or name a member of it. The seed documentation already teaches a natural key (`name`, `email`) rather than an id, which differs between environments.
13+
14+
What changes:
15+
16+
- **The membership lookup is bounded by the organization.** It reads the load organization's `sys_member` rows in `user_id` order, a page at a time by keyset (`user_id` greater than the last one seen), and asks ONE `sys_user` read per page, constrained to that page's people and the natural key. It no longer reads every same-named person in the deployment, 50 at a time by offset, which cost two reads per 50 organizations per reference value on a hosted deployment where every organization holds the same seeded names, and which could skip the member under a concurrent delete and say "not a member" falsely. An organization smaller than one page (500 members) answers a resolved reference with one membership read and one person read. Whether someone outside the organization answers to the key is one bounded read (`limit: 1`), asked only on a miss, to word the error.
17+
- **An id-shaped person value is judged by membership** on a load for one organization, as an id of any other shape already was.

‎packages/metadata-protocol/src/seed-loader.ts‎

Lines changed: 98 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2781,7 +2781,15 @@ export class SeedLoaderService implements ISeedLoaderService {
27812781

27822782
// Not a natural key (an internal id, or a non-string the engine will
27832783
// reject on its own terms) — keep it verbatim.
2784-
if (typeof value !== 'string' || this.looksLikeInternalId(value)) {
2784+
//
2785+
// [#33280] Except a person on an organization-scoped load: an id names a
2786+
// person exactly as a name does, so it is judged by the same membership
2787+
// rule. A member's id resolves to itself; an id of someone outside the
2788+
// organization gets the refusal a name gets. A shape the pattern does not
2789+
// recognise (`usr_…`) already reached the probe through its `id` leg, so
2790+
// keeping the recognised shapes verbatim was the only door past the rule.
2791+
if (typeof value !== 'string') return { status: 'kept', value };
2792+
if (this.looksLikeInternalId(value) && !(await this.judgesInternalIdByMembership(ref.targetObject, config))) {
27852793
return { status: 'kept', value };
27862794
}
27872795

@@ -2895,58 +2903,92 @@ export class SeedLoaderService implements ISeedLoaderService {
28952903

28962904
/**
28972905
* [#33207] Resolve a person for an organization-scoped load: `sys_user`
2898-
* carries no organization (identity lives above the organization), so the
2899-
* candidates the field names are kept only when they hold a `sys_member` row
2900-
* in the load's organization. ⛔ A person who is not a member is never
2901-
* resolved, however exactly the name matches: they could not even read the
2902-
* row they would be made to own. The member with the lowest id wins: the
2903-
* candidates are read in id order, so the answer does not depend on the
2904-
* driver's row order.
2906+
* carries no organization (identity lives above the organization), so a
2907+
* person resolves only when they hold a `sys_member` row in the load's
2908+
* organization. ⛔ A person who is not a member is never resolved, however
2909+
* exactly the name matches: they could not even read the row they would be
2910+
* made to own. The member with the lowest id wins, so the answer does not
2911+
* depend on the driver's row order.
2912+
*
2913+
* The probe is driven from the organization's member set, never from the
2914+
* people the key names (#33280): a name is not unique above the organization
2915+
* (every organization may sign its people up under the same seeded names),
2916+
* so reading the same-named people first made the cost grow with the
2917+
* deployment. The members are read in `user_id` order, a page at a time, by
2918+
* keyset (`user_id` greater than the last one seen) — an offset page shifts
2919+
* under a concurrent delete and skips a member, which is a false "not a
2920+
* member". Each page is asked ONE `sys_user` read constrained to that page's
2921+
* people AND the key; the pages ascend, so the first page that answers holds
2922+
* the lowest-id member and the walk stops there. "Not a member" is said only
2923+
* after every member was asked about; whether anyone outside the
2924+
* organization answers to the key is then one bounded read (`limit: 1`),
2925+
* which only words the verdict.
29052926
*
2906-
* A name is not unique above the organization (every organization may sign
2907-
* its people up under the same seeded names), so the candidates are read
2908-
* page by page until a member is found or none is left: "not a member" is
2909-
* said only after every person the key names has been asked about, never
2910-
* on a truncated read. A refused membership read is reported as a refusal
2911-
* on `sys_member`, the table that refused it.
2927+
* The `id` key needs no member page: the membership row of that one person
2928+
* is read directly. A refused membership read is reported as a refusal on
2929+
* `sys_member`, the table that refused it.
29122930
*/
29132931
private async probeOrganizationMember(
29142932
probeField: string,
29152933
value: unknown,
29162934
organizationId: string,
29172935
): Promise<{ id: string | null; nonMemberMatched: boolean; refusal?: ProbeRefusal }> {
29182936
const page = SeedLoaderService.MEMBER_PROBE_PAGE;
2919-
let nonMemberMatched = false;
2920-
for (let offset = 0; ; offset += page) {
2921-
const userProbe: EngineQueryOptions = {
2922-
where: { [probeField]: value },
2937+
const firstUser = async (where: Record<string, unknown>): Promise<string | null> => {
2938+
const users = (await this.engine.find(SystemObjectName.USER, {
2939+
where,
29232940
fields: ['id'],
29242941
orderBy: [{ field: 'id', order: 'asc' }],
2925-
limit: page,
2926-
offset,
2942+
limit: 1,
29272943
context: { isSystem: true },
2928-
};
2929-
const users = (await this.engine.find(SystemObjectName.USER, userProbe)) as Array<Record<string, unknown>> | undefined;
2930-
const candidates = (users ?? []).map((u) => String(u.id ?? u._id)).filter((id) => id !== 'undefined');
2931-
if (candidates.length === 0) return { id: null, nonMemberMatched };
2932-
const memberProbe: EngineQueryOptions = {
2933-
where: { user_id: candidates.length === 1 ? candidates[0] : { $in: candidates }, organization_id: organizationId },
2944+
} satisfies EngineQueryOptions)) as Array<Record<string, unknown>> | undefined;
2945+
const id = users?.[0]?.id ?? users?.[0]?._id;
2946+
return id === undefined || id === null ? null : String(id);
2947+
};
2948+
const readMembers = async (where: Record<string, unknown>, limit: number): Promise<string[]> => {
2949+
const members = (await this.engine.find(SystemObjectName.MEMBER, {
2950+
where: { ...where, organization_id: organizationId },
29342951
fields: ['user_id'],
2935-
limit: candidates.length,
2952+
orderBy: [{ field: 'user_id', order: 'asc' }],
2953+
limit,
29362954
context: { isSystem: true },
2937-
};
2938-
let members: Array<Record<string, unknown>> | undefined;
2955+
} satisfies EngineQueryOptions)) as Array<Record<string, unknown>> | undefined;
2956+
return (members ?? [])
2957+
.map((m) => m.user_id)
2958+
.filter((id) => id !== undefined && id !== null && id !== '')
2959+
.map(String);
2960+
};
2961+
2962+
if (probeField === 'id') {
2963+
let isMember: boolean;
29392964
try {
2940-
members = (await this.engine.find(SystemObjectName.MEMBER, memberProbe)) as Array<Record<string, unknown>> | undefined;
2965+
isMember = (await readMembers({ user_id: value }, 1)).length > 0;
29412966
} catch (err) {
29422967
return { id: null, nonMemberMatched: false, refusal: this.reportRefusedProbe(SystemObjectName.MEMBER, 'user_id', err) };
29432968
}
2944-
const memberIds = new Set((members ?? []).map((m) => String(m.user_id)));
2945-
const member = candidates.find((id) => memberIds.has(id));
2946-
if (member) return { id: member, nonMemberMatched: false };
2947-
nonMemberMatched = true;
2948-
if ((users ?? []).length < page) return { id: null, nonMemberMatched };
2969+
const person = await firstUser({ id: value });
2970+
if (person === null) return { id: null, nonMemberMatched: false };
2971+
return isMember ? { id: person, nonMemberMatched: false } : { id: null, nonMemberMatched: true };
29492972
}
2973+
2974+
for (let after: string | undefined; ;) {
2975+
let memberIds: string[];
2976+
try {
2977+
memberIds = await readMembers(after === undefined ? {} : { user_id: { $gt: after } }, page);
2978+
} catch (err) {
2979+
return { id: null, nonMemberMatched: false, refusal: this.reportRefusedProbe(SystemObjectName.MEMBER, 'user_id', err) };
2980+
}
2981+
if (memberIds.length > 0) {
2982+
const member = await firstUser({
2983+
[probeField]: value,
2984+
id: memberIds.length === 1 ? memberIds[0] : { $in: memberIds },
2985+
});
2986+
if (member !== null) return { id: member, nonMemberMatched: false };
2987+
}
2988+
if (memberIds.length < page) break;
2989+
after = memberIds[memberIds.length - 1];
2990+
}
2991+
return { id: null, nonMemberMatched: (await firstUser({ [probeField]: value })) !== null };
29502992
}
29512993

29522994
/**
@@ -3478,11 +3520,13 @@ export class SeedLoaderService implements ISeedLoaderService {
34783520
}
34793521

34803522
/**
3481-
* [#33207] How many same-named people one page of the membership probe
3482-
* weighs. A name is not unique above the organization, so the probe pages
3483-
* through every person the key names; the page only bounds each read.
3523+
* [#33207] How many members of the load's organization one page of the
3524+
* membership probe weighs (#33280: the probe pages the organization's
3525+
* members by keyset, never the people a key names). The page only bounds
3526+
* each read and the `$in` list the person read carries; an organization
3527+
* smaller than one page is answered by one member read and one person read.
34843528
*/
3485-
private static readonly MEMBER_PROBE_PAGE = 50;
3529+
private static readonly MEMBER_PROBE_PAGE = 500;
34863530

34873531
/**
34883532
* The engine write {@link writeRecoveringSummary} guards, as a NAMED callee.
@@ -4557,6 +4601,21 @@ export class SeedLoaderService implements ISeedLoaderService {
45574601
);
45584602
}
45594603

4604+
/**
4605+
* [#33280] Whether an internal-id-shaped reference value is still judged by
4606+
* the membership rule: only on a load pinned to an organization (the probe
4607+
* is unscoped without one), never on a dry run (which reads no database),
4608+
* and only for the target that resolves through membership (`sys_user`,
4609+
* the `members` probe scope). Every other target keeps its id verbatim.
4610+
*/
4611+
private async judgesInternalIdByMembership(
4612+
targetObject: string,
4613+
config: { dryRun?: boolean; organizationId?: string },
4614+
): Promise<boolean> {
4615+
if (!config.organizationId || config.dryRun) return false;
4616+
return (await this.probeScopeOf(targetObject)).kind === 'members';
4617+
}
4618+
45604619
private looksLikeInternalId(value: string): boolean {
45614620
// UUID v4 pattern
45624621
if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value)) {

‎packages/runtime/src/seed-org-scoped-references.integration.test.ts‎

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,102 @@ describe('#33206 a seed write carries the organization its rows are stamped with
438438
});
439439
});
440440

441+
describe('#33280 the membership probe is bounded by the organization, and an id-shaped person is judged by membership', () => {
442+
/** Every read the load sends to `sys_user` / `sys_member`, with its options. */
443+
function recordPersonReads(engine: ObjectQL) {
444+
const reads: Array<{ object: string; options: EngineQueryOptions }> = [];
445+
const find = engine.find.bind(engine);
446+
vi.spyOn(engine, 'find').mockImplementation((async (object: string, options: EngineQueryOptions) => {
447+
if (object === 'sys_user' || object === 'sys_member') reads.push({ object, options });
448+
return find(object, options);
449+
}) as typeof engine.find);
450+
return reads;
451+
}
452+
453+
/** Replay North then South with `strangers` same-named people outside both organizations. */
454+
async function replayWithStrangers(strangers: number) {
455+
const { engine, replayer, dealsOf } = await boot({ posture: 'isolated', data: [deals([{ name: 'Deal 1', rep: 'Li Na' }])] });
456+
const sys = { context: { isSystem: true } } as any;
457+
// The strangers sort BEFORE the member, so a probe that weighed the
458+
// same-named people first meets every one of them before her.
459+
for (let n = 0; n < strangers; n++) {
460+
await engine.insert('sys_user', { id: `usr_li_${String(n).padStart(3, '0')}`, name: 'Li Na', email: `li.${n}@example.com` }, sys);
461+
}
462+
await engine.insert('sys_user', { id: 'usr_li_zz_member', name: 'Li Na', email: 'li.member@example.com' }, sys);
463+
await engine.insert('sys_member', { id: 'mem_li_n', user_id: 'usr_li_zz_member', organization_id: ORG_NORTH, role: 'member' }, sys);
464+
465+
const reads = recordPersonReads(engine);
466+
const north = await replayer!(ORG_NORTH);
467+
const northReads = reads.length;
468+
const south = await replayer!(ORG_SOUTH);
469+
return { north, south, northReads, southReads: reads.length - northReads, reads, dealsOf };
470+
}
471+
472+
it('the reads a person reference costs do not grow with same-named people outside the organization', async () => {
473+
const few = await replayWithStrangers(0);
474+
const many = await replayWithStrangers(120);
475+
476+
// Same verdicts either way: North's member is found, South is refused.
477+
for (const run of [few, many]) {
478+
expect(run.north.errors).toEqual([]);
479+
expect((await run.dealsOf(ORG_NORTH))[0].rep).toBe('usr_li_zz_member');
480+
expect((await run.dealsOf(ORG_SOUTH))[0].rep ?? null).toBeNull();
481+
expect(run.south.errors).toHaveLength(1);
482+
expect(run.south.errors[0].message).toContain(`not a member of organization ${ORG_SOUTH}`);
483+
}
484+
// The bound: 120 more same-named strangers cost not one more read, on the
485+
// hit (North) or on the miss (South).
486+
expect(many.northReads).toBe(few.northReads);
487+
expect(many.southReads).toBe(few.southReads);
488+
// And the shape that bounds it: no read pages by offset, every person read
489+
// naming the key is constrained to member ids or answers one row, and the
490+
// member read is walled by the load's organization.
491+
expect(many.reads.length).toBeGreaterThan(0);
492+
for (const { object, options } of many.reads) {
493+
expect(options.offset).toBeUndefined();
494+
const where = (options.where ?? {}) as Record<string, unknown>;
495+
if (object === 'sys_member') expect([ORG_NORTH, ORG_SOUTH]).toContain(where.organization_id);
496+
if (object === 'sys_user' && where.name === 'Li Na') {
497+
expect(where.id !== undefined || options.limit === 1).toBe(true);
498+
}
499+
}
500+
});
501+
502+
/** A person whose id is UUID-shaped — the shape `looksLikeInternalId` recognises. */
503+
const UUID_NORTH_MEMBER = '3b9f6c2a-1d4e-4f8a-9c7b-2e5d8a1f0c63';
504+
const UUID_SOUTH_MEMBER = '8e2a4d7c-5b1f-4a3e-8d9c-7f0b2c6e1a94';
505+
506+
it('an id-shaped person reference resolves to a member of the load organization, and an outsider’s id is refused like a name', async () => {
507+
const { engine, replayer, dealsOf } = await boot({
508+
posture: 'isolated',
509+
data: [deals([{ name: 'Mine', rep: UUID_NORTH_MEMBER }, { name: 'Theirs', rep: UUID_SOUTH_MEMBER }])],
510+
});
511+
const sys = { context: { isSystem: true } } as any;
512+
await engine.insert('sys_user', { id: UUID_NORTH_MEMBER, name: 'Chen Jie', email: 'chen@example.com' }, sys);
513+
await engine.insert('sys_user', { id: UUID_SOUTH_MEMBER, name: 'Zhou Min', email: 'zhou@example.com' }, sys);
514+
await engine.insert('sys_member', { id: 'mem_chen_n', user_id: UUID_NORTH_MEMBER, organization_id: ORG_NORTH, role: 'member' }, sys);
515+
await engine.insert('sys_member', { id: 'mem_zhou_s', user_id: UUID_SOUTH_MEMBER, organization_id: ORG_SOUTH, role: 'member' }, sys);
516+
517+
const north = await replayer!(ORG_NORTH);
518+
const south = await replayer!(ORG_SOUTH);
519+
520+
const byName = (rows: Row[]) => Object.fromEntries(rows.map((r) => [r.name, r.rep ?? null]));
521+
// A member's id still names that member — the legitimate seed keeps working.
522+
expect(byName(await dealsOf(ORG_NORTH))).toEqual({ Mine: UUID_NORTH_MEMBER, Theirs: null });
523+
expect(byName(await dealsOf(ORG_SOUTH))).toEqual({ Mine: null, Theirs: UUID_SOUTH_MEMBER });
524+
expect(north.errors).toHaveLength(1);
525+
expect(north.errors[0].message).toContain(`not a member of organization ${ORG_NORTH}`);
526+
expect(south.errors).toHaveLength(1);
527+
expect(south.errors[0].message).toContain(`not a member of organization ${ORG_SOUTH}`);
528+
});
529+
530+
it('CONTROL — a load with no organization keeps an id-shaped person reference verbatim, as before', async () => {
531+
const { dealsOf } = await boot({ posture: 'single', organizations: false, data: [deals([{ name: 'Deal 1', rep: UUID_SOUTH_MEMBER }])] });
532+
const [row] = await dealsOf();
533+
expect(row.rep).toBe(UUID_SOUTH_MEMBER);
534+
});
535+
});
536+
441537
describe('a dataset OF an object walled by a declared tenant column replays per organization on that column', () => {
442538
const tags = (records: Array<Record<string, unknown>>) => ({ object: 'crm_workspace_tag', mode: 'upsert', externalId: 'name', records });
443539
const accounts = (records: Array<Record<string, unknown>>) => ({ object: 'crm_account', mode: 'upsert', externalId: 'name', records });

0 commit comments

Comments
 (0)