Skip to content

Commit 71ade1a

Browse files
fix(plugin-webhooks, cli): a departed package's activation row switches no remaining webhook holder, and the ownership ceremony never picks a holder for a two-holder copy (ADR-0150 D8) (#33253)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9DDZYUbJbnXUTqZoZ56k4czR)_ Fixes #32695 Clause-②: yes (widening; narrowing on a departed row switched on) — widening: a departed package's row switched off no longer keeps a remaining holder off, so its outbound deliveries start on upgrade. Narrowing: a departed package's row switched on no longer turns on a holder shipped inactive. Metadata-protocol: none Area-lease pilot #33059 · area E2 · seat `domain:server#5` · os-elon-musk · session_016WV4cyrFFk86Jqf7Mp5Rzw ## 维护者速读 - 改了什么:(S1) webhook 的启停开关里,一条点名“已不再声明该名字的包”的激活行,不再被当作剩下持有者的开关;(S4) 18.x 归属仪式里,两个包同名声明时,未写包的定制副本不再随便挑“列表最后一个包”,改写成不点名包的行并在报告里点名两个持有者。 - 为什么改:卸载包留下的旧开关会把另一个包的 webhook 打开或关掉(真实对外推送),属于 ADR-0150 D8 禁止的“替别人做决定”;仪式里按列表顺序挑包也是猜。 - 风险与回滚:只改 plugin-webhooks 的一个判定函数和 CLI 仪式一步;不点名包的行、持有者自己的行读法不变。回滚即 revert。 - 先看:`packages/plugins/plugin-webhooks/src/declared-webhooks.ts` 的 `webhookSlotSwitch` 与 `reportUnownedRows`;`packages/cli/src/utils/organization-ownership-apply.ts` 的 declared-webhooks 步骤。 - 两分钟验证:`pnpm --filter @objectstack/plugin-webhooks exec vitest run src/declared-webhooks.test.ts`,预期 59 个全过(含 `[#32695]` 四条)。 - 需要你做的:无,区域线程在复审通过后落地。 ## What changes **S1 — a departed package's activation row (`plugin-webhooks`).** `webhookSlotSwitch` read, for a slot with no row of its own, every row that is no slot's own: rows naming no package AND rows naming a package that no longer declares the name. Under one holder those were its switch (`if (slots.length <= 1) return unowned.every(Boolean)`), so a departed package's row switched the remaining holder in both directions; under two, an off row kept both off. Now only a row naming no package (while the environment declares nothing of the name) is read that way — the D8 row a name-keyed reader wrote before. A departed package's row switches no slot, at any holder count, and `DeclaredWebhookSource` says so once per name at `warn` (new export `departedWebhookRows`), naming the departed package, the holders and the per-holder address `?package=PACKAGE` (PR #33204). **S4 — the 18.x ownership ceremony (`cli`).** The declared-webhooks step built `new Map(list.map(d => [d.name, d.packageId]))`, so under two holders of a name the holder listed LAST was the fallback for a customized copy whose definition names no package. Now the step keeps every holder per name; such a copy's activation row names the name's one holder, or — under two or more — no package (the name-keyed switch it was: off keeps each holder with no row of its own off, on turns none on), and the step's notes name every holder and the per-holder address. The card offered "refuse or report"; reporting keeps the run from blocking on a copy whose switch has a non-guessing spelling, and nothing is picked. FROM → TO: | Case | FROM | TO | |---|---|---| | one holder, departed row off, holder shipped on | holder off | holder on (declared default) | | one holder shipped off, departed row on | holder on | holder off (declared default) | | two holders, departed row off | both off | each at its own row / declared default | | ceremony: two package holders, customized copy naming no package | activation row names the last-listed holder | row names no package; note names both | | ceremony: the environment and a package hold the name, customized copy naming no package (either order) | row names the last-listed holder | no switch row written; note reports the copy's switch and names both (review S1) | | row naming no package; a holder's own row; one-holder ceremony | unchanged | unchanged | **On `Clause-②`:** re-declared `yes (widening; narrowing on a departed row switched on)` per review S2, the spelling review#3 accepted on #33252: the departed-off rows start outbound deliveries on upgrade with no operator action (widening), the departed-on row stops one (narrowing). The changeset carries the operator line: to keep such a webhook off, switch the holder off at `POST /api/v1/security/_activation/webhook/NAME?package=PACKAGE`; the `warn` names that address. No export in the published index moves (`departedWebhookRows` is module-internal). **Review round 1 (head 399e550, review#3 FAIL) → 9eefd98:** S1: when the environment is one of a name's holders, the ceremony no longer writes a package-less row for a copy naming no package (that row is the environment slot's own switch, so it picked the environment); it writes none and reports the copy's switch naming every holder. A clone of such a copy is not switched either and says so. S2: Clause-② re-declared, operator line added. N1: `reportUnownedRows` no longer returns after the departed-row warning, so a name with both a departed row and a package-less row under two holders is told both, each once. ## Tests - `plugin-webhooks/src/declared-webhooks.test.ts`: the `[D8] one holder` pin no longer pins the departed row as the switch (that is the defect); new describe `[#32695] a departed package's row switches no remaining holder`: one holder both directions; two holders in both registration orders; said once naming departed package, holders and the address; CONTROL package-less row and own row; two holders with a departed row and a package-less row — each warning said once (N1). - `cli/src/utils/organization-ownership-apply.generation-1.test.ts` (integration project): two holders with the second listed last and first — the row names no package, one note naming both; the environment and a package, the environment listed last and first — no switch row, one note naming both, and not the name-keyed note; CONTROL a copy naming its package beside a second holder listed first; CONTROL one holder, copy naming no package. ## Acceptance notes - `setActivation` (cli) reads and updates an existing activation row by `(metadata_type, name)` only, whatever its `package_id`. Pre-existing and unchanged here; on an 18.x database the ceremony runs before any per-package row exists. Noted, not filed (no repro on a real upgrade path). - The pristine-copy re-source still writes `declared:NAME` (no package) for deliveries; a two-holder redelivery of such a row is refused naming both (`[Q4]` pin, unchanged). ## Verification <details><summary>Ablation (both source files reverted to origin/main, tests kept)</summary> plugin-webhooks `declared-webhooks.test.ts`: `Tests 3 failed | 56 passed (59)` — one-holder both directions, two holders both orders, said-once red; CONTROL green. cli generation-1: `Tests 2 failed | 19 passed (21)` — both two-holder orders red; CONTROLs green. Restored with `git checkout HEAD -- …`, `git diff HEAD` empty. </details> <details><summary>Ablation, review round 1 (the fix reverted to 399e550, new pins kept)</summary> cli generation-1: `Tests 2 failed | 21 passed (23)` — both environment-and-package orders red. plugin-webhooks: `Tests 1 failed | 59 passed (60)` — the N1 pin red. Restored from the saved fixed copies, diff re-checked. </details> <details><summary>Local runs at fab0533</summary> ``` @objectstack/plugin-webhooks full suite :: Test Files 25/25 · Tests 300/300 @objectstack/plugin-webhooks typecheck :: exit 0 @objectstack/cli vitest --project integration organization-ownership-apply.generation-1.test.ts :: 21/21 @objectstack/cli typecheck :: exit 0 ``` The repo gate farm is left to CI on this PR. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_016WV4cyrFFk86Jqf7Mp5Rzw)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_016WV4cyrFFk86Jqf7Mp5Rzw <!-- signed: domain:server#5 · os-elon-musk · session_016WV4cyrFFk86Jqf7Mp5Rzw --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 83cb78d commit 71ade1a

5 files changed

Lines changed: 262 additions & 27 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
'@objectstack/plugin-webhooks': patch
3+
'@objectstack/cli': patch
4+
---
5+
6+
fix(plugin-webhooks, cli): an activation row a departed package left switches no remaining webhook holder, and the 18.x ownership ceremony writes a two-holder copy's switch as a row naming no package instead of picking one holder (ADR-0150 D8)
7+
8+
Clause-②: yes (widening; narrowing on a departed row switched on) — widening: a departed package's row switched off no longer keeps a remaining holder off, so its outbound deliveries start on upgrade. Narrowing: a departed package's row switched on no longer turns on a holder shipped inactive.
9+
Metadata-protocol: none
10+
11+
**A departed package's activation row (plugin-webhooks).** A declared webhook's slot with no activation row of its own read the name's rows naming a package that no longer declares the name as its switch while the name had one holder, and under two holders such a row switched off kept both off. Such a row was the departed package's switch, and it now switches no remaining holder, in either direction:
12+
13+
- one holder, a departed package's row switched off: FROM the holder off TO the holder at its own row, else its declared `isActive`;
14+
- one holder shipped inactive, a departed package's row switched on: FROM the holder on TO the holder off (its declared default);
15+
- two holders, a departed package's row switched off: FROM both off TO each at its own row or its declared default.
16+
17+
The source says so once per name at `warn`, naming the departed package, the holders and the per-holder address (`POST /api/v1/security/_activation/webhook/NAME?package=PACKAGE`). A row naming no package is read exactly as before: the one holder's switch, and under two holders off keeps every holder with no row of its own off and on turns none on. A holder's own row still wins.
18+
19+
**Operator action on upgrade.** A webhook you switched off while another package held its name, and which a remaining package now declares, starts delivering again after this release unless that holder has its own row. To keep it off, switch the holder off at its own address: `POST /api/v1/security/_activation/webhook/NAME?package=PACKAGE` (no `package` for the environment's own). The warning above names each such webhook and its holders.
20+
21+
**The 18.x ownership ceremony's declared-webhooks step (cli).** A customized `sys_webhook` copy writes the declaration's activation row. When the copy's definition names no package, the row named the holder the composition listed LAST for the name. Of a name one holder declares it still names that holder; of a name two or more holders declare it now names no package — the name-keyed switch the copy was — and the step's notes name every holder and the per-holder address. When the environment is one of those holders, a row naming no package would be the environment's own switch, so the step writes no switch row and its notes report the copy's switch (on or off) and name every holder; switch each at its own address. A copy whose definition names its package writes that package's row, as before.

‎packages/cli/src/utils/organization-ownership-apply.generation-1.test.ts‎

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ import {
4848
type NotNullPort,
4949
type OrganizationOwnershipApplyReport,
5050
} from './organization-ownership-apply.js';
51+
// Clocked windows measure behaviour, never loading: the ceremony's dynamic
52+
// imports are paid here, at collection (`check:test-source-alias`).
53+
import '@objectstack/driver-sql';
54+
import '@objectstack/driver-turso';
55+
import '@objectstack/metadata-protocol';
56+
import '@objectstack/platform-objects/plugin';
57+
import '@objectstack/plugin-security';
58+
import '@objectstack/rest';
59+
import '@objectstack/runtime';
60+
import '@objectstack/service-datasource';
5161

5262
const ORG = 'org_default';
5363

@@ -111,7 +121,14 @@ const RULES = ['share_custom', 'share_collides'];
111121

112122
async function apply(
113123
l: ReturnType<typeof ledger> = ledger(),
114-
opts: { posture?: string; webhooks?: boolean; rules?: boolean; notNull?: boolean; notNullPort?: NotNullPort } = {},
124+
opts: {
125+
posture?: string;
126+
webhooks?: boolean;
127+
webhookList?: ReadonlyArray<{ name: string; packageId: string | null }>;
128+
rules?: boolean;
129+
notNull?: boolean;
130+
notNullPort?: NotNullPort;
131+
} = {},
115132
): Promise<OrganizationOwnershipApplyReport> {
116133
const posture = opts.posture ?? 'single';
117134
const database = join(dir, 'fixture.db');
@@ -129,7 +146,7 @@ async function apply(
129146
conflicts: reviewedConflictsOf(reviewed),
130147
},
131148
catalog: { async resolve() { return undefined; } },
132-
...(opts.webhooks === false ? {} : { declaredWebhooks: { async list() { return WEBHOOKS; } } }),
149+
...(opts.webhooks === false ? {} : { declaredWebhooks: { async list() { return opts.webhookList ?? WEBHOOKS; } } }),
133150
...(opts.rules === false
134151
? {}
135152
: { declaredSharingRules: { async rules() { return RULES.map((name) => ({ name, refused: null, packageId: 'com.example.app' })); } } }),
@@ -384,6 +401,73 @@ describe('ownership shape generation 1 — the ceremony steps an 18.0 database o
384401
expect(rows(`SELECT COUNT(*) AS n FROM sys_metadata_activation WHERE metadata_type = 'sharing_rule'`)).toEqual([{ n: 0 }]);
385402
});
386403

404+
/**
405+
* [ADR-0150 D8, #32695] A customized copy writes the declaration's
406+
* activation row, which names one holder. Of a name two packages declare,
407+
* a copy whose definition names no package names none of them: its row
408+
* names no package (the name-keyed switch it was), and the run says so,
409+
* naming each holder. BASE: the holder listed last was picked
410+
* (`new Map(list)`), so the row named whichever package the composition
411+
* listed last.
412+
*/
413+
for (const [order, webhookList] of [
414+
['listed last', [...WEBHOOKS, { name: 'deal_won', packageId: 'com.example.other' }]],
415+
['listed first', [{ name: 'deal_won', packageId: 'com.example.other' }, ...WEBHOOKS]],
416+
] as const) {
417+
it(`5a [#32695] two holders (the second ${order}), a customized copy naming no package: its row names no package, said naming both`, async () => {
418+
const other = 'com.example.other';
419+
db.exec(`UPDATE sys_webhook SET definition_json = json_remove(definition_json, '$._packageId') WHERE id = 'whk_switched'`);
420+
const report = await apply(ledger(), { webhookList });
421+
const done = step(report, 'declared-webhooks');
422+
expect(done.status).toBe('done');
423+
expect(rows(`SELECT name, package_id, active FROM sys_metadata_activation WHERE metadata_type = 'webhook' AND name = 'deal_won'`))
424+
.toEqual([{ name: 'deal_won', package_id: null, active: 1 }]);
425+
const said = done.notes.filter((n) => n.includes('whk_switched') && n.includes('names no package'));
426+
expect(said).toHaveLength(1);
427+
expect(said[0]).toContain("'com.example.app'");
428+
expect(said[0]).toContain(`'${other}'`);
429+
});
430+
}
431+
432+
/**
433+
* [ADR-0150 D8, #32695 review S1] When the environment is one of the
434+
* holders, a row naming no package is the environment slot's OWN switch
435+
* (`webhookSlotSwitch` reads `rows.get(null)` as it), so writing one would
436+
* pick the environment. Nothing is written and the run reports the copy's
437+
* switch, naming each holder, in either listed order.
438+
*/
439+
for (const [order, webhookList] of [
440+
['listed last', [...WEBHOOKS, { name: 'deal_won', packageId: null }]],
441+
['listed first', [{ name: 'deal_won', packageId: null }, ...WEBHOOKS]],
442+
] as const) {
443+
it(`5a [#32695] the environment and a package hold the name (the environment ${order}), a customized copy naming no package: no switch row, said naming both`, async () => {
444+
db.exec(`UPDATE sys_webhook SET definition_json = json_remove(definition_json, '$._packageId') WHERE id = 'whk_switched'`);
445+
const report = await apply(ledger(), { webhookList });
446+
const done = step(report, 'declared-webhooks');
447+
expect(done.status).toBe('done');
448+
expect(rows(`SELECT COUNT(*) AS n FROM sys_metadata_activation WHERE metadata_type = 'webhook' AND name = 'deal_won'`))
449+
.toEqual([{ n: 0 }]);
450+
const said = done.notes.filter((n) => n.includes('whk_switched') && n.includes('no switch row was written'));
451+
expect(said).toHaveLength(1);
452+
expect(said[0]).toContain('the environment');
453+
expect(said[0]).toContain("'com.example.app'");
454+
expect(done.notes.filter((n) => n.includes('whk_switched') && n.includes('switched off it keeps'))).toHaveLength(0);
455+
});
456+
}
457+
458+
it('5a [#32695] CONTROL a customized copy whose definition names its package writes that package\'s row, beside a second holder listed first', async () => {
459+
await apply(ledger(), { webhookList: [{ name: 'deal_won', packageId: 'com.example.other' }, ...WEBHOOKS] });
460+
expect(rows(`SELECT name, package_id, active FROM sys_metadata_activation WHERE metadata_type = 'webhook' AND name = 'deal_won'`))
461+
.toEqual([{ name: 'deal_won', package_id: 'com.example.app', active: 1 }]);
462+
});
463+
464+
it('5a [#32695] CONTROL one holder, a customized copy naming no package: that holder\'s row, as before', async () => {
465+
db.exec(`UPDATE sys_webhook SET definition_json = json_remove(definition_json, '$._packageId') WHERE id = 'whk_switched'`);
466+
await apply();
467+
expect(rows(`SELECT name, package_id, active FROM sys_metadata_activation WHERE metadata_type = 'webhook' AND name = 'deal_won'`))
468+
.toEqual([{ name: 'deal_won', package_id: 'com.example.app', active: 1 }]);
469+
});
470+
387471
it('5a without the declared webhooks to read, a seeded row blocks the step and nothing is deleted', async () => {
388472
const report = await apply(ledger(), { webhooks: false });
389473
expect(step(report, 'declared-webhooks')).toMatchObject({ status: 'blocked', blockers: [expect.stringMatching(/no registry to read them from/)] });

‎packages/cli/src/utils/organization-ownership-apply.ts‎

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3214,6 +3214,12 @@ export interface DeclaredWebhooksPort {
32143214
list(): Promise<ReadonlyArray<{ name: string; packageId: string | null }>>;
32153215
}
32163216

3217+
/** The package a `sys_webhook` row's own definition names (`_packageId`), or `null`. */
3218+
function ownPackageOf(row: Record<string, unknown>): string | null {
3219+
const def = webhookDefinition(row);
3220+
return typeof def?._packageId === 'string' && def._packageId ? def._packageId : null;
3221+
}
3222+
32173223
/** A `sys_webhook` row's `definition_json`, parsed, or `null`. */
32183224
function webhookDefinition(row: Record<string, unknown>): Record<string, unknown> | null {
32193225
const raw = row.definition_json;
@@ -3317,7 +3323,13 @@ async function runDeclaredWebhooks(run: Run): Promise<StepReport> {
33173323
"deployment's own composition, then re-run.",
33183324
]);
33193325
}
3320-
const declared = new Map((await run.opts.declaredWebhooks.list()).map((d) => [d.name, d.packageId] as const));
3326+
// [ADR-0150 D4/D8] Every holder of each declared name, never the one listed last.
3327+
const declared = new Map<string, Array<string | null>>();
3328+
for (const d of await run.opts.declaredWebhooks.list()) {
3329+
const holders = declared.get(d.name) ?? [];
3330+
if (!holders.includes(d.packageId)) holders.push(d.packageId);
3331+
declared.set(d.name, holders);
3332+
}
33213333
const held = rows.filter((r) => declared.has(String(r.name)));
33223334
summary.undeclaredKept = rows.length - held.length;
33233335
if (summary.undeclaredKept > 0) {
@@ -3373,9 +3385,41 @@ async function runDeclaredWebhooks(run: Run): Promise<StepReport> {
33733385
const name = String(row.name);
33743386
const id = String(row.id);
33753387
const def = webhookDefinition(row);
3376-
const packageId = (typeof def?._packageId === 'string' && def._packageId ? def._packageId : null) ?? declared.get(name) ?? null;
3388+
// [ADR-0150 D8] The activation row a customized copy writes names the
3389+
// copy's own package, else the name's one holder. Of a name two or more
3390+
// package holders declare, a copy that names no package names none of
3391+
// them: its row names no package, as the name-keyed switch it was — off,
3392+
// it keeps every holder with no row of its own off; on, it turns none on —
3393+
// and the run says so, naming each holder. When the environment is one of
3394+
// those holders, a row naming no package IS the environment slot's own
3395+
// switch, so writing it would pick the environment: nothing is written and
3396+
// the run reports the copy's switch, naming each holder. Never the first or
3397+
// last one listed.
3398+
const holders = declared.get(name) ?? [];
3399+
const ownPackage = ownPackageOf(row);
3400+
const packageId = ownPackage ?? (holders.length === 1 ? holders[0] : null);
3401+
const unnamed = truthy(row.customized) && ownPackage === null && holders.length > 1;
3402+
const ambiguous = unnamed && holders.includes(null);
3403+
const holderList = holders.map((p) => (p === null ? 'the environment' : `'${p}'`)).join(', ');
3404+
if (ambiguous) {
3405+
notes.push(
3406+
`${table} ${id}: a customized copy of the declared webhook ${name}, which ${holders.length} holders declare ` +
3407+
`(${holderList}), and its definition names no package. A switch row naming no package would be the ` +
3408+
`environment's own, so which holder the copy's switch (${truthy(row.active) ? 'on' : 'off'}) belonged to is ` +
3409+
'not decided here and no switch row was written. Switch each holder at its own address ' +
3410+
`(POST /api/v1/security/_activation/webhook/${name}?package=PACKAGE, no package for the environment).`,
3411+
);
3412+
} else if (unnamed) {
3413+
notes.push(
3414+
`${table} ${id}: a customized copy of the declared webhook ${name}, which ${holders.length} holders declare ` +
3415+
`(${holderList}), and its definition names no ` +
3416+
'package, so its switch is written as a row naming no package: switched off it keeps each holder with no row of ' +
3417+
'its own off, switched on it turns none on. Switch each holder at its own address ' +
3418+
`(POST /api/v1/security/_activation/webhook/${name}?package=PACKAGE).`,
3419+
);
3420+
}
33773421
if (!truthy(row.customized) || isSwitchOnlyEdit(row)) {
3378-
if (truthy(row.customized) && (await setActivation(run, 'webhook', name, packageId, truthy(row.active)))) summary.activationRows++;
3422+
if (truthy(row.customized) && !ambiguous && (await setActivation(run, 'webhook', name, packageId, truthy(row.active)))) summary.activationRows++;
33793423
summary.deliveriesResourced += await resource(id, `${DECLARED_WEBHOOK_REF_PREFIX}${name}`);
33803424
await deleteCopy(row);
33813425
orphaned.push(...secretIdsOf(row));
@@ -3398,11 +3442,12 @@ async function runDeclaredWebhooks(run: Run): Promise<StepReport> {
33983442
);
33993443
const [landed] = await sql.read(table, `SELECT ${q('name')} AS ${q('name')} FROM ${q(table)} WHERE ${q('id')} = ?`, [row.id]);
34003444
if (text(landed?.name) !== clone) throw new Error(`The clone of the declared webhook ${name} (${id}) did not read back as ${clone}.`);
3401-
if (await setActivation(run, 'webhook', name, packageId, false)) summary.activationRows++;
3445+
if (!ambiguous && (await setActivation(run, 'webhook', name, packageId, false))) summary.activationRows++;
34023446
summary.clones++;
34033447
notes.push(
34043448
`${table} ${id}: customized beyond its switch, so it is now the administrator's own webhook ${clone} (its ` +
3405-
`credentials and deliveries with it), and the declared ${name} is switched off.`,
3449+
`credentials and deliveries with it), and the declared ${name} is ` +
3450+
`${ambiguous ? 'not switched (see the note naming its holders)' : 'switched off'}.`,
34063451
);
34073452
}
34083453

‎packages/plugins/plugin-webhooks/src/declared-webhooks.test.ts‎

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -784,11 +784,61 @@ describe('declared webhooks — one declaration per (package, name) slot (ADR-01
784784
expect(await switches(own)).toEqual([[A, true], [B, false]]);
785785
});
786786

787-
it('[D8] one holder: a row naming no package, or a package that no longer declares the name, is its switch, as before', async () => {
787+
it('[D8] one holder: a row naming no package is its switch, as before; its own row wins', async () => {
788788
const one = (rows: any[]) => new DeclaredWebhookSource(engineOver(registryShipping([[A, ALPHA]]), { rows: { [LEDGER]: rows } }), undefined);
789789
expect(await switches(one([slotRow(null, false)]))).toEqual([[A, false]]);
790-
expect(await switches(one([slotRow('com.acme.gone', false)]))).toEqual([[A, false]]);
791-
expect(await switches(one([slotRow('com.acme.gone', false), slotRow(A, true)]))).toEqual([[A, true]]);
790+
expect(await switches(one([slotRow(null, false), slotRow(A, true)]))).toEqual([[A, true]]);
791+
});
792+
793+
/**
794+
* [ADR-0150 D8, #32695] A row naming a package that no longer declares
795+
* the name was that package's switch: it switches no remaining holder, in
796+
* either direction, at any holder count, and is said once per name.
797+
* BASE: under one holder it was read as that holder's switch (off turned
798+
* a shipped-on holder off, on turned a shipped-off holder on); under two,
799+
* off kept both off.
800+
*/
801+
describe('[#32695] a departed package\'s row switches no remaining holder', () => {
802+
const GONE = 'com.acme.gone';
803+
const SHIPPED_OFF = declaredWebhook({ url: 'https://hooks.example/alpha', isActive: false });
804+
const sourceOver = (packages: Array<[string, any]>, rows: any[], warn = vi.fn()) =>
805+
new DeclaredWebhookSource(engineOver(registryShipping(packages), { rows: { [LEDGER]: rows } }), undefined, loggerWith(warn));
806+
807+
it('one holder: the departed row switched off leaves a shipped-on holder on; switched on leaves a shipped-off holder off', async () => {
808+
expect(await switches(sourceOver([[A, ALPHA]], [slotRow(GONE, false)]))).toEqual([[A, true]]);
809+
expect(await switches(sourceOver([[A, SHIPPED_OFF]], [slotRow(GONE, true)]))).toEqual([[A, false]]);
810+
});
811+
812+
it('two holders, in both registration orders: a departed row switched off keeps neither off', async () => {
813+
expect(await switches(sourceOver([[A, ALPHA], [B, BETA]], [slotRow(GONE, false)]))).toEqual([[A, true], [B, true]]);
814+
expect(await switches(sourceOver([[B, BETA], [A, ALPHA]], [slotRow(GONE, false)]))).toEqual([[B, true], [A, true]]);
815+
});
816+
817+
it('said once per name, naming the departed package and the holders, with the per-holder address', async () => {
818+
const warn = vi.fn();
819+
const source = sourceOver([[A, ALPHA]], [slotRow(GONE, false)], warn);
820+
await source.list();
821+
await source.list();
822+
const said = warn.mock.calls.filter(([msg]) => String(msg).includes('no longer declares it'));
823+
expect(said).toHaveLength(1);
824+
expect(said[0][0]).toContain(`package "${GONE}"`);
825+
expect(said[0][0]).toContain(`"${A}"`);
826+
expect(said[0][0]).toContain('?package=PACKAGE');
827+
});
828+
829+
it('two holders, a departed row and a row naming no package: each is told once (review N1)', async () => {
830+
const warn = vi.fn();
831+
const source = sourceOver([[A, ALPHA], [B, BETA]], [slotRow(GONE, false), slotRow(null, false)], warn);
832+
await source.list();
833+
await source.list();
834+
expect(warn.mock.calls.filter(([msg]) => String(msg).includes('no longer declares it'))).toHaveLength(1);
835+
expect(warn.mock.calls.filter(([msg]) => String(msg).includes('no holder\'s own (naming no package)'))).toHaveLength(1);
836+
});
837+
838+
it('CONTROL beside the departed row, a row naming no package is still the one holder\'s switch, and its own row wins over both', async () => {
839+
expect(await switches(sourceOver([[A, ALPHA]], [slotRow(GONE, true), slotRow(null, false)]))).toEqual([[A, false]]);
840+
expect(await switches(sourceOver([[A, ALPHA]], [slotRow(GONE, false), slotRow(null, false), slotRow(A, true)]))).toEqual([[A, true]]);
841+
});
792842
});
793843

794844
it('[Q4] a delivery naming no package (`declared:NAME`, the CLI ceremony\'s shape): one holder judges it as before; two refuse it naming both, sent to neither', async () => {

0 commit comments

Comments
 (0)