Repository navigation
Commit e9b44ab
fix(pm): dispatch-gates derives the gates that load a changed scripts/pm module, transitively (#34080)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9MG4BPhsDcJCksmNwyRu6xu)_
Fixes #33848
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:派发工具 `dispatch-gates.mjs` 新增「import 图」匹配键:改动落在 `scripts/pm/**`
下的某个模块时,所有直接或间接 import(含动态
import、再导出)它的门禁脚本所属的门禁族都会被派生出来,输出里打印从门禁脚本到该模块的整条 import 链。
- 为什么改:PR #33804 第一版只改了 `check-governed-queue-guard.mjs` 和
`check-governed-merges.mjs`,`--commands` 派生 35 条、漏了
`check:pm-fleet-write-execute`(它的脚本 import 了被改的函数),开发者「35 条全绿」而 CI
红。现在同一组文件派生 62 条,含 fleet-write 的执行器、校验器和派发器。
- 风险与回滚:只改 `scripts/pm/**`
下一个工具脚本和它的自测,不发布任何包。新键排在所有旧键之后,旧匹配的键与来源标签一字不变,只会多派、不会少派;代价是改大多数 pm
模块会多派约 40 多个门禁族(pm 工具互相 import 成一个大环,这是实测的真实影响面)。回滚即还原本 PR。
- 先看:`scripts/pm/dispatch-gates.mjs` 的 `loadEdgeTargets`(读 import 边,含动态
import 的兜底)与 `coveringKey` 末尾的新分支;自测文件里 `The import-graph key (#33848)`
一节和改过的两条旧用例。
- 两分钟验证:`node scripts/pm/dispatch-gates.mjs --commands
scripts/pm/check-governed-queue-guard.mjs
scripts/pm/check-governed-merges.mjs | grep fleet-write`,预期三行 `pnpm
check:pm-fleet-write-{dispatch,execute,validate}`(修复前零行)。
- 需要你做的:无,席位落地(非受管面)。
## What changes
`dispatch-gates --commands` named a gate when a changed path was the
gate's own script, a CI trigger, a job filter, a literal the gate
spells, or a file it reads. It never named a gate because its script
**imports** the changed module: `coveringKey`'s docblock refused that
key (#13126) on precision, because the shared heads under `scripts/`
(`invoked-as.mjs` and four others) are imported by most families. The pm
tools are the opposite shape, and the measured miss is the card's: on PR
#33804's first head the derivation named 35 gates, not
`check:pm-fleet-write-execute`, whose script imports a changed function
and whose self-test then went red in CI.
A new key, consulted **last** in `coveringKey`, answers a changed path
under `IMPORT_GRAPH_KEY_ROOT` (`scripts/pm/`): a family matches when the
path is in the transitive load closure of its gate files. Read from the
module's side that is the reverse import graph over `scripts/pm/**`, at
any depth. The row prints the chain, e.g. `import graph
scripts/pm/fleet-write/execute.mjs ->
scripts/pm/check-governed-queue-guard.mjs`. Outside `scripts/pm/` the
#13126 refusal stands unchanged (a self-test row pins that).
| Piece | What it does |
|:--|:--|
| `loadEdgeTargets(path, source)` | One file's first-party load edges:
static `import … from`, `export … from` (a re-export loads its target),
the side-effect form, a dynamic `import()` of a string literal or of
`new URL(literal, import.meta.url)`. Comments are masked; a keyword
inside a string or template literal is fixture text, not a load.
Self-test bodies are **not** masked: a `--self-test` run loads them. |
| Unreadable dynamic `import()` | The argument is a variable, a property
or a computed URL. It is not dropped: every code-position module literal
in that file becomes an edge, whether relative or spelled from the repo
root under `scripts/` (toward deriving more). Both shapes are live: a
loader seam (`load = (specifier) => import(specifier)`) with its
relative specifiers in a constant (`ARM_READER_SOURCE`), and a
root-spelled roster loaded in process (`fleet-write/dispatch.mjs`'s
self-test imports each sender through `pathToFileURL(join(REPO_ROOT,
sender))`; `check-dispatch-gates.mjs` loads its engine through
`import(resolve(ROOT, TOOL))`). The root spelling also takes fixture
rows and text reads written the same way (five modules
`check-governed-merges.mjs` names as data); that over-derives, which is
this key's direction. |
| `importGraphReach(files, edgesOf)` | Breadth-first forward closure
from a family's gate files, recording each module's first importer, so
the printed chain is a shortest one. Walks self-test families and gate
files too: the key claims what RUNNING the family loads, never what it
watches, so neither population narrowing applies. |
| `discoverFamilies` | Computes `entry.importReach` for every family,
one scan per file per discovery. |
| `derivationInputs` | Adds every reached module, since its edges decide
what the key names. |
Resolution is the existing first-party rule: relative specifiers only,
inside `scripts/`, outside `node_modules`, the target must exist. A bare
specifier is an installed package.
Measured on this tree (b8685e5), and printed by a self-test row on
every run rather than recorded in prose: the key reaches 28 pm modules
over 1195 (family, module) pairs, and the most-reached module,
`clause2-line.mjs`, names 53 families. The pm tools close into one large
cycle (the governed register, the half-state patrol, the queue guard and
the dispatch-gates engine load one another), so an edit to most pm
modules names forty-odd families. That is the measured size of what such
an edit can break.
Time, measured on a quiet container, two cold runs each: a discovery
took 16.6 s and 14.8 s before the key (base e71ecc1) and 17.2 s and
17.0 s with it (6f34ab1); a whole `--commands` run over one pm path
took 36.0 s and 37.0 s before and 38.0 s and 35.7 s after. The review's
48.7 s was the same run on a loaded box. The stale "~14 s cold" in
`derivationInputs`' docblock now carries these readings.
## Tests
Full battery (`node scripts/pm/dispatch-gates.mjs --self-test`, both
tiers) on b8685e5: **2530 cases pass** (fast 2215 + slow 315), lock
`VERDICT command-exit 0`. Round 1: 2528 passed on 80bc14b and on
e6452d3.
New rows, all in the fast tier:
- Fixture graph (in memory, so the shapes cannot rot with the tree): the
reader takes the static import, the re-export, the side-effect form, a
literal `import()` inside a self-test body and a `new URL` import; it
refuses an import spelled in a template literal or a comment and a bare
package; an unread `import()` widens to every module literal in the
file, relative or root-spelled; CONTROL: the same two literals in a file
with no unread `import()` are no edges.
- ⭐ Transitive row: in the fixture, `b.mjs` reached only through
`gate.mjs -> a.mjs -> b.mjs` names the family, and the row prints that
chain.
- Scope row: a module outside `scripts/pm/` reached by import is still
answered by no key.
- ⭐ Root-spelled roster row (live tree, review M1):
`scripts/pm/issue-create.mjs`, which no file under `scripts/` imports
statically and which the dispatcher's self-test loads by root path,
derives `check:pm-fleet-write-dispatch` through the import graph.
- Price row: prints the modules the key reaches, the (family, module)
pairs and the most-reached module, asserting only that the key reaches
anything.
- ⭐ Replay row (live tree): PR #33804's first file list places
`check:pm-fleet-write-execute` as matched via `import graph
scripts/pm/fleet-write/execute.mjs -> …`, rendered `pnpm
check:pm-fleet-write-execute`; and `check:pm-fleet-write-validate` and
`check:pm-fleet-write-dispatch` match too.
Forced edits to existing rows (both are about the key order this PR
extends):
1. **The #13126 witness** (`the witness holds — bare-root-worklist
--self-test imports THIS file, and no key names that family…`) asserted
the refusal's one known missing lead. That module is under
`scripts/pm/`, so the new key names it; the row now asserts the edge
exists AND the key that names it is the import-graph key (`the witness
is paid back — …`). The other five refusal pins (novel class, worst
head, concentration, the deferred-pair pins) are unchanged and green.
2. **Read-key additivity** (`every read edge earns a key, and none is
re-attributed …`) stripped `entry.reads` and compared against the keys
left. The new key now sits after the read key, so with the reads
stripped it answered those targets and the row reported 7 false
re-attributions (`program text read by …` -> `import graph …`). The row
now strips `entry.importReach` too, so it compares the read key against
the keys consulted BEFORE it, which is its claim.
<details><summary>Ablation: the new branch in coveringKey disabled on
disk, exactly the four key rows red, restored (head e6452d3)</summary>
Through `node scripts/ablation-replace.mjs` (anchor hits 1 -> 0 on disk,
blob `7d65b7fe4962` -> `09197c9f6da0`), the fast tier under
`os-verify-lock.sh`; restore: blob == HEAD (`7d65b7fe4962`) and `git
diff HEAD` empty.
```text
mutation: the import-graph branch's condition prefixed with `false &&`
-> VERDICT command-exit 1, 4 of 2213 failed:
the witness is paid back — bare-root-worklist --self-test imports THIS file, and the import-graph key names that family for a card editing it
the transitive row: a module reached only through an importer of an importer names the family, and the row prints the chain from the gate file
the replay row: PR #33804's first file list derives check:pm-fleet-write-execute, through the import graph
…and the validator and the dispatcher, the other two fleet-write families the card names
(the edge-reader rows and the scope row stay green, as they must: they do not read the key)
```
</details>
<details><summary>Ablation, round 2 (review M1): the root-spelled half
of the fallback disabled on disk, exactly two rows red, restored (head
b8685e5)</summary>
Through `node scripts/ablation-replace.mjs` (anchor hits 1 -> 0, blob
`8e00e6752a69` -> `fcd7324b7a64`), the fast tier under
`os-verify-lock.sh`; restore: blob == HEAD (`8e00e6752a69`) and `git
diff HEAD` empty.
```text
mutation: a root-spelled literal in a file with an unreadable import() is skipped instead of admitted
-> VERDICT command-exit 1, 2 of 2215 failed:
an import() whose argument is not a literal widens toward MORE: every module literal in the file is an edge, relative or spelled from the repo root
a sender the dispatcher loads by a root-spelled path derives check:pm-fleet-write-dispatch, through the import graph
```
</details>
## Acceptance notes
- Additive by construction: the key is the last one `coveringKey`
consults, so every (family, path) pair an earlier key answered keeps its
key and label; the 2,520 rows that existed before stay green except the
two forced edits above.
- Price, stated rather than hidden: a card editing most `scripts/pm/`
modules now derives about 62 commands where it derived about 30 (this
PR's own card: 62). Every added row prints its import chain, so a reader
can check why it is there.
- Not covered by this key: the import closure of a script a gate only
SPAWNS as a child (`node scripts/pm/x.mjs`) is not walked; the existing
run and read keys answer the spawned file itself where they apply.
carrier: #34084.
- The related evidence the delta names (`check:adr-anchors` reddened by
a fixture string on PR #33975) is a different mechanism: that family
declares five hints (`docs/adr`, `scripts/adr-anchors`, its own script
and two `CHANGELOG.md` files) and no whole-tree marker, while its scan
reads the whole tree's text. Its population is under-declared; not fixed
here. carrier: #34086.
- Serial: #34002 (dotAll in `triggerPatternRegex`, same file) is held
and not folded in.
## Verification
Local subset on b8685e5 (round 2; main e71ecc1 merged in): `node
scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` derived 62 commands; 61 exit 0 and one exit
3 (each exit captured before any pipe). `--ran` with every line
annotated `:: exit N`: **62 derived, 61 run, 1 NOT-MEASURED (derived
from the recorded exit 3), 0 UNRUN**. `pnpm check:i18n-coverage` is
derived only through the import graph (its self-test imports the
engine): its self-test half passed, its scan half refused with exit 3
because the CLI build closure is not built here; declared to CI. No
package touched, so no build closure and no package test is owed.
<details><summary>The 62 commands and their exit codes</summary>
```text
node scripts/check-closing-keyword-parity.mjs :: exit 0
node scripts/check-closing-keyword-parity.mjs --self-test :: exit 0
node scripts/check-comment-mask-corpus.mjs :: exit 0
node scripts/check-declaration-mirrors.mjs :: exit 0
node scripts/check-declaration-mirrors.mjs --self-test :: exit 0
node scripts/check-issue-citations.mjs :: exit 0
node scripts/check-self-test-wired.mjs :: exit 0
node scripts/check-self-test-wired.mjs --self-test :: exit 0
node scripts/check-self-test-workflow-commands.mjs :: exit 0
node scripts/check-self-test-workflow-commands.mjs --self-test :: exit 0
node scripts/check-skills-token-ratchet.mjs :: exit 0
node scripts/check-skills-token-ratchet.mjs --self-test :: exit 0
node scripts/check-whole-set-label-write.mjs :: exit 0
node scripts/check-whole-set-label-write.mjs --self-test :: exit 0
node scripts/ci/plan-test-core-shards.mjs --self-test :: exit 0
node scripts/ci/scheduled-full-run-card.mjs --self-test :: exit 0
node scripts/ci/scheduled-full-run.mjs --self-test :: exit 0
node scripts/ci/snapshot-next.mjs --self-test :: exit 0
node scripts/pm/bare-root-worklist.mjs --self-test :: exit 0
node scripts/pm/board-snapshot.mjs --self-test :: exit 0
node scripts/pm/check-governed-queue-guard.mjs --self-test :: exit 0
node scripts/pm/sweep-closed-cards.mjs --self-test :: exit 0
pnpm check:agent-test-spelling :: exit 0
pnpm check:bash32-floor :: exit 0
pnpm check:ci-filter-parity :: exit 0
pnpm check:cli-command-ids :: exit 0
pnpm check:closing-target-claim :: exit 0
pnpm check:commit-card-trailers :: exit 0
pnpm check:cross-package-test-inputs :: exit 0
pnpm check:declared-population-live :: exit 0
pnpm check:driver-memory-census :: exit 0
pnpm check:entry-guard :: exit 0
pnpm check:gitlink-declared :: exit 0
pnpm check:i18n-coverage :: exit 3
pnpm check:issue-citations :: exit 0
pnpm check:nul-bytes :: exit 0
pnpm check:parse-guard :: exit 0
pnpm check:partof-closing-keyword :: exit 0
pnpm check:pm-board-snapshot :: exit 0
pnpm check:pm-close-cards :: exit 0
pnpm check:pm-dispatch-gates :: exit 0
pnpm check:pm-expected-skips :: exit 0
pnpm check:pm-fleet-token :: exit 0
pnpm check:pm-fleet-write-dispatch :: exit 0
pnpm check:pm-fleet-write-execute :: exit 0
pnpm check:pm-fleet-write-validate :: exit 0
pnpm check:pm-governed-merges :: exit 0
pnpm check:pm-governed-prose :: exit 0
pnpm check:pm-half-states :: exit 0
pnpm check:pm-issue-create :: exit 0
pnpm check:pm-issue-transfer :: exit 0
pnpm check:pm-label-write :: exit 0
pnpm check:pm-post-stamped :: exit 0
pnpm check:pm-prior-rulings :: exit 0
pnpm check:pm-record-recognisers :: exit 0
pnpm check:pnpm-filter-targets :: exit 0
pnpm check:pnpm-flag-spellings :: exit 0
pnpm check:ratchet-remedy-authority :: exit 0
pnpm check:refd-timer-probe :: exit 0
pnpm check:scripts-symbol-anchors :: exit 0
pnpm check:single-claim-paths :: exit 0
pnpm check:watch-hint-literal :: exit 0
```
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmRtrFmEsp5pAjTBpMT)_
<!-- signed: domain:skills#1 · os-steve ·
session_01ADHkmPd7uRqHauEehGPr19 -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 8d0035d commit e9b44ab
2 files changed
Lines changed: 395 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6572 | 6572 | | |
6573 | 6573 | | |
6574 | 6574 | | |
| 6575 | + | |
| 6576 | + | |
| 6577 | + | |
| 6578 | + | |
| 6579 | + | |
| 6580 | + | |
| 6581 | + | |
| 6582 | + | |
| 6583 | + | |
| 6584 | + | |
| 6585 | + | |
| 6586 | + | |
| 6587 | + | |
| 6588 | + | |
| 6589 | + | |
| 6590 | + | |
| 6591 | + | |
| 6592 | + | |
| 6593 | + | |
| 6594 | + | |
| 6595 | + | |
| 6596 | + | |
| 6597 | + | |
| 6598 | + | |
| 6599 | + | |
| 6600 | + | |
| 6601 | + | |
| 6602 | + | |
| 6603 | + | |
| 6604 | + | |
| 6605 | + | |
| 6606 | + | |
| 6607 | + | |
| 6608 | + | |
| 6609 | + | |
| 6610 | + | |
| 6611 | + | |
| 6612 | + | |
| 6613 | + | |
| 6614 | + | |
| 6615 | + | |
| 6616 | + | |
| 6617 | + | |
| 6618 | + | |
| 6619 | + | |
| 6620 | + | |
| 6621 | + | |
| 6622 | + | |
| 6623 | + | |
| 6624 | + | |
| 6625 | + | |
| 6626 | + | |
| 6627 | + | |
| 6628 | + | |
| 6629 | + | |
| 6630 | + | |
| 6631 | + | |
| 6632 | + | |
| 6633 | + | |
| 6634 | + | |
| 6635 | + | |
| 6636 | + | |
| 6637 | + | |
| 6638 | + | |
| 6639 | + | |
| 6640 | + | |
| 6641 | + | |
| 6642 | + | |
| 6643 | + | |
| 6644 | + | |
| 6645 | + | |
| 6646 | + | |
| 6647 | + | |
| 6648 | + | |
| 6649 | + | |
| 6650 | + | |
| 6651 | + | |
| 6652 | + | |
| 6653 | + | |
| 6654 | + | |
| 6655 | + | |
| 6656 | + | |
| 6657 | + | |
| 6658 | + | |
| 6659 | + | |
| 6660 | + | |
| 6661 | + | |
| 6662 | + | |
| 6663 | + | |
| 6664 | + | |
| 6665 | + | |
| 6666 | + | |
| 6667 | + | |
| 6668 | + | |
| 6669 | + | |
| 6670 | + | |
| 6671 | + | |
| 6672 | + | |
| 6673 | + | |
| 6674 | + | |
| 6675 | + | |
| 6676 | + | |
| 6677 | + | |
| 6678 | + | |
| 6679 | + | |
| 6680 | + | |
| 6681 | + | |
| 6682 | + | |
| 6683 | + | |
| 6684 | + | |
| 6685 | + | |
| 6686 | + | |
| 6687 | + | |
| 6688 | + | |
| 6689 | + | |
| 6690 | + | |
| 6691 | + | |
| 6692 | + | |
| 6693 | + | |
| 6694 | + | |
| 6695 | + | |
| 6696 | + | |
| 6697 | + | |
| 6698 | + | |
| 6699 | + | |
| 6700 | + | |
| 6701 | + | |
| 6702 | + | |
| 6703 | + | |
| 6704 | + | |
| 6705 | + | |
| 6706 | + | |
| 6707 | + | |
| 6708 | + | |
| 6709 | + | |
| 6710 | + | |
| 6711 | + | |
| 6712 | + | |
| 6713 | + | |
| 6714 | + | |
| 6715 | + | |
| 6716 | + | |
| 6717 | + | |
| 6718 | + | |
| 6719 | + | |
| 6720 | + | |
| 6721 | + | |
| 6722 | + | |
| 6723 | + | |
| 6724 | + | |
| 6725 | + | |
| 6726 | + | |
| 6727 | + | |
| 6728 | + | |
| 6729 | + | |
| 6730 | + | |
| 6731 | + | |
| 6732 | + | |
| 6733 | + | |
| 6734 | + | |
| 6735 | + | |
| 6736 | + | |
| 6737 | + | |
| 6738 | + | |
| 6739 | + | |
| 6740 | + | |
| 6741 | + | |
| 6742 | + | |
6575 | 6743 | | |
6576 | 6744 | | |
6577 | 6745 | | |
| |||
7889 | 8057 | | |
7890 | 8058 | | |
7891 | 8059 | | |
7892 | | - | |
| 8060 | + | |
7893 | 8061 | | |
7894 | 8062 | | |
7895 | 8063 | | |
7896 | 8064 | | |
7897 | | - | |
| 8065 | + | |
| 8066 | + | |
| 8067 | + | |
| 8068 | + | |
| 8069 | + | |
| 8070 | + | |
| 8071 | + | |
| 8072 | + | |
| 8073 | + | |
| 8074 | + | |
| 8075 | + | |
| 8076 | + | |
| 8077 | + | |
| 8078 | + | |
| 8079 | + | |
| 8080 | + | |
| 8081 | + | |
| 8082 | + | |
| 8083 | + | |
| 8084 | + | |
| 8085 | + | |
| 8086 | + | |
| 8087 | + | |
| 8088 | + | |
| 8089 | + | |
| 8090 | + | |
| 8091 | + | |
| 8092 | + | |
| 8093 | + | |
| 8094 | + | |
| 8095 | + | |
| 8096 | + | |
7898 | 8097 | | |
7899 | 8098 | | |
7900 | 8099 | | |
| |||
8010 | 8209 | | |
8011 | 8210 | | |
8012 | 8211 | | |
| 8212 | + | |
| 8213 | + | |
| 8214 | + | |
| 8215 | + | |
| 8216 | + | |
| 8217 | + | |
| 8218 | + | |
| 8219 | + | |
| 8220 | + | |
| 8221 | + | |
8013 | 8222 | | |
8014 | 8223 | | |
8015 | 8224 | | |
| |||
13527 | 13736 | | |
13528 | 13737 | | |
13529 | 13738 | | |
| 13739 | + | |
| 13740 | + | |
| 13741 | + | |
| 13742 | + | |
| 13743 | + | |
| 13744 | + | |
| 13745 | + | |
| 13746 | + | |
| 13747 | + | |
| 13748 | + | |
13530 | 13749 | | |
| 13750 | + | |
| 13751 | + | |
| 13752 | + | |
| 13753 | + | |
| 13754 | + | |
13531 | 13755 | | |
13532 | 13756 | | |
13533 | 13757 | | |
| |||
16361 | 16585 | | |
16362 | 16586 | | |
16363 | 16587 | | |
16364 | | - | |
16365 | | - | |
16366 | | - | |
| 16588 | + | |
| 16589 | + | |
| 16590 | + | |
| 16591 | + | |
| 16592 | + | |
| 16593 | + | |
| 16594 | + | |
| 16595 | + | |
16367 | 16596 | | |
16368 | 16597 | | |
16369 | 16598 | | |
| |||
16378 | 16607 | | |
16379 | 16608 | | |
16380 | 16609 | | |
| 16610 | + | |
| 16611 | + | |
| 16612 | + | |
16381 | 16613 | | |
16382 | 16614 | | |
16383 | 16615 | | |
| |||
0 commit comments