You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 71ade1a
Browse filesBrowse the repository at this point in the historyBrowse 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>
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.
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
+
constreport=awaitapply(ledger(),{ webhookList });
446
+
constdone=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
+
constsaid=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()=>{
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