Skip to content

Commit a3aa1d2

Browse files
fix(pm): dispatch-gates derives the change set with -z, so a non-ASCII governed path keeps its tier (#33998)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi916SWCJMeiaqJP9Bb2wnp2s)_ Fixes #33847 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:派发工具 `dispatch-gates.mjs` 的 `changedPathsFromGit` 读变更路径(已提交、未提交、未跟踪三份清单)时改成加 `-z`、按 NUL 切分,三份清单走同一个读取函数,`-z` 由该函数统一插入。 - 为什么改:不加 `-z` 时 git 会把含中文等非 ASCII 字符或换行的路径打印成带引号的转义串,它对不上任何 glob,于是 `skills/**` 下这样命名的受管文件在派发时算不出复审档位,派生的门禁清单也漏掉它;未跟踪的这种文件还被记成「读不到、0 行」。 - 风险与回滚:只改 `scripts/pm/**` 一个工具脚本和它的自测,不发布任何包;所有 ASCII 路径的读数逐字节不变。回滚即还原本 PR。 - 先看:`scripts/pm/dispatch-gates.mjs` 的 `gitPathList`(新读取函数)与 `changedPathsFromGit` 的三处调用;自测文件里 `quoted-names` 场景。 - 两分钟验证:在一个分支上提交 `skills/objectstack-data/文档.md` 后跑 `node scripts/pm/dispatch-gates.mjs --tier`,预期 stderr 列出原样的中文路径,stdout 给出契约复审档位(修复前是带引号的转义串、无档位)。 - 需要你做的:无,席位落地(非受管面)。 ## What changes `changedPathsFromGit` (it feeds `--tier`, `--commands` and the changed-line size) read its three path lists line by line, with no `-z`: | Read | Was | Now | |:--|:--|:--| | committed | `diff --name-only --no-renames MERGE_BASE HEAD`, split on newline, trimmed | `diff -z --name-only --no-renames MERGE_BASE HEAD`, split on NUL, not trimmed | | working tree | `diff --name-only --no-renames HEAD`, same | `diff -z …`, same | | untracked | `ls-files --others --exclude-standard`, same | `ls-files -z …`, same | | `changedLinesFromGit` fallback (no `untracked` passed) | the untracked read above | the same `-z` read | Git C-quotes a path holding a non-ASCII byte, a double quote or a control character (a file named in Chinese prints as a quoted octal string), and that spelling starts with a quote mark, so it matched no glob. Measured on a real repo before the fix: a committed `skills/x/` file named in Chinese plus an untracked one derived `tier: null`, and the untracked one was counted as 1 unreadable file of 0 lines. After: both raw, tier `CONTRACT_REVIEW_TIER`, 0 unreadable. All four reads now go through one reader, `gitPathList`, which splices `-z` in after the subcommand itself, so no caller in this file can list paths the other way. The old `gitLines` had no other caller and is gone. Not done, per the card: `core.quotePath=false` alone, which would still split a newline name in two. Not changed: the size read `diff --numstat -M` (summed by `parseNumstat` in `check-governed-merges.mjs`) only adds the two counts, which quoting never touches; the same call was left as is in #33804 for the same reason. ## Tests `node scripts/pm/dispatch-gates.mjs --self-test` on acb82a3: **2520 cases pass**, exit 0 (lock VERDICT command-exit 0). Five new cases, in the slow tier's real-git section, on a fixture repo that sets `core.quotePath true` itself so it quotes on any machine. Each of the three reads carries one name git quotes: a committed file named in Chinese, an uncommitted edit to another, and an untracked file whose name holds a newline. - CONTROL: the plain read (no `-z`) of the same branch quotes all three, and they derive no tier and name no gate family. - The derived change set lists each name raw (committed 1, worktree 1, untracked 1). - Those raw names derive `CONTRACT_REVIEW_TIER` through `skills/**` (3 hits). - They name `check:skill-*` gate families, the ones the derived `--commands` list is built from. - The untracked newline-named file is counted from disk: 0 unreadable, +3 lines. No existing test was edited. <details><summary>Ablation: the old reader restored on disk, exactly the four new rows red, restored (head acb82a3)</summary> Each mutation through `node scripts/ablation-replace.mjs` (anchor hits 1 then 0 on disk, blob changed), the self-test under `os-verify-lock.sh`; restore: blob == HEAD (`6343de57fbce`) and `git diff HEAD` empty, both legs. ```text leg 2 (the card's ablation): gitPathList body back to the old gitLines body (no -z, split on newline, trimmed) -> VERDICT command-exit 1, 4 of 2520 failed: the derived change set spells each C-quoted name as it is on disk: committed, uncommitted and untracked (newline included) and those raw names derive the contract-review tier through the skills/** glob and they name the skill gate families the derived --commands list is built from and the untracked newline-named file is counted from disk, not as an unreadable file of 0 lines (the CONTROL row stays green, as it must) leg 1: only the spliced -z dropped, NUL split kept -> VERDICT command-exit 1, 12 of 2520 failed: the four rows above, plus 8 older real-git derivation rows: without -z the whole newline-joined listing comes back as ONE name, so -z and the NUL split are bound in one reader and cannot drift apart ``` </details> ## Acceptance notes - Every ASCII path reads byte-identically: the 2515 cases that existed before all stay green on the fix. - `derivationProvenance` prints one path per stderr line, so a path with a newline in its name now prints raw across two lines there. That is display only (stdout and the tier are unaffected); not changed. - Serial: #33848 edits the same two files and waits for this PR to merge. ## Verification Local subset on acb82a3 (final head): `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derived 30 commands; all 30 exit 0 (each exit captured before any pipe). `--ran` with every line annotated `:: exit N`: **30 derived, 30 run, 0 NOT-MEASURED, 0 UNRUN** (a derived zero, all 30 recorded an exit code). `pnpm check:pm-dispatch-gates` is in that 30 (its fast tier, 2205 cases); the full both-tier battery is the 2520 above. The script's other callers of `changedPathsFromGit` are only `check-dispatch-gates.mjs`, covered there. No package touched, so no build closure and no package test is owed; CI runs the rest. <details><summary>The 30 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-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-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 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: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:nul-bytes :: exit 0 pnpm check:parse-guard :: exit 0 pnpm check:pm-dispatch-gates :: 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:watch-hint-literal :: exit 0 ``` </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmPfzYmYaFdzt3TJ9w2)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent b37d5ab commit a3aa1d2

2 files changed

Lines changed: 91 additions & 6 deletions

File tree

‎scripts/pm/dispatch-gates.mjs‎

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15967,10 +15967,27 @@ function runGit(args, cwd) {
1596715967
return { status: r.status ?? 1, stdout: r.stdout ?? '', stderr: (r.stderr ?? '').trim() };
1596815968
}
1596915969

15970-
function gitLines(args, cwd) {
15970+
/**
15971+
* A path list from git, read NUL-separated: `git <subcommand> -z <rest…>`.
15972+
*
15973+
* The `-z` is spliced in here rather than written at each call site, so no
15974+
* caller can list paths the other way. Without it git C-quotes any path that
15975+
* holds a non-ASCII byte, a double quote or a control character
15976+
* (`"skills/x/\346\226\207.md"` for a file named in Chinese), and the quoted
15977+
* spelling begins with a quote mark, so it matches no glob: a governed
15978+
* `skills/**` file read as no tier at all, every derived gate watching it went
15979+
* unnamed, and an untracked one was counted as an unreadable file of 0 lines.
15980+
* ⛔ `core.quotePath=false` alone is no repair: it unquotes the non-ASCII bytes
15981+
* only, and a newline in a path still splits one name into two on a line
15982+
* read. Split on NUL and never trim: a leading or trailing space is part of
15983+
* the name. Same reader shape as `trackedFiles` and the landing gates'
15984+
* `enumerateRows`.
15985+
*/
15986+
function gitPathList([subcommand, ...rest], cwd) {
15987+
const args = [subcommand, '-z', ...rest];
1597115988
const r = runGit(args, cwd);
1597215989
if (r.status !== 0) throw new Error(`git ${args.join(' ')} failed — ${r.stderr || `exit ${r.status}`}`);
15973-
return r.stdout.split('\n').map((s) => s.trim()).filter(Boolean);
15990+
return r.stdout.split('\0').filter(Boolean);
1597415991
}
1597515992

1597615993
/**
@@ -16046,9 +16063,11 @@ export function changedPathsFromGit({ cwd = ROOT, base = DEFAULT_BASE_REF } = {}
1604616063
// --no-renames so a moved file contributes BOTH names. Rename detection
1604716064
// prints only the new one, and a gate watching the old directory is exactly
1604816065
// as implicated by the move as one watching the new.
16049-
const committed = gitLines(['diff', '--name-only', '--no-renames', mergeBase, 'HEAD'], cwd);
16050-
const worktree = gitLines(['diff', '--name-only', '--no-renames', 'HEAD'], cwd);
16051-
const untracked = gitLines(['ls-files', '--others', '--exclude-standard'], cwd);
16066+
// Every list is read NUL-separated (`gitPathList`), so a name git would
16067+
// C-quote reaches the tier and the gate match spelled as it is on disk.
16068+
const committed = gitPathList(['diff', '--name-only', '--no-renames', mergeBase, 'HEAD'], cwd);
16069+
const worktree = gitPathList(['diff', '--name-only', '--no-renames', 'HEAD'], cwd);
16070+
const untracked = gitPathList(['ls-files', '--others', '--exclude-standard'], cwd);
1605216071

1605316072
const paths = [...new Set([...committed, ...worktree, ...untracked])].sort();
1605416073
const size = changedLinesFromGit({ cwd, mergeBase, untracked });
@@ -16084,7 +16103,7 @@ export function changedLinesFromGit({ cwd = ROOT, mergeBase, untracked = null })
1608416103
throw new Error(`git diff --numstat ${mergeBase.slice(0, 9)} failed — ${tracked.stderr || `exit ${tracked.status}`}; the changed-line count cannot be answered, and an unanswered count is never zero`);
1608516104
}
1608616105
const counted = parseNumstat(tracked.stdout);
16087-
const others = untracked ?? gitLines(['ls-files', '--others', '--exclude-standard'], cwd);
16106+
const others = untracked ?? gitPathList(['ls-files', '--others', '--exclude-standard'], cwd);
1608816107
let untrackedLines = 0;
1608916108
let untrackedBinary = 0;
1609016109
let unreadable = 0;

‎scripts/pm/dispatch-gates.self-test.mjs‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11332,6 +11332,72 @@ export function selfTest({ tier = 'full' } = {}) {
1133211332
}
1133311333
t('an unresolvable base ref is refused on its own terms', !!missingBaseErr && /does not resolve/.test(missingBaseErr.message));
1133411334

11335+
// ── A name git would C-quote still reaches the tier and the gates (#33847)
11336+
//
11337+
// Without `-z` git prints a path holding a non-ASCII byte or a control
11338+
// character C-quoted and octal-escaped, and that spelling starts with a
11339+
// quote mark, so no glob covers it: a governed `skills/**` file derived as
11340+
// NO tier and named no gate family. Each of the three reads carries one such
11341+
// name here: a committed file named in Chinese, an uncommitted edit to
11342+
// another, and an untracked file whose name holds a newline (the case
11343+
// `core.quotePath=false` alone would still split in two). The fixture sets
11344+
// `core.quotePath true` itself so the CONTROL quotes on any machine,
11345+
// whatever the global config says.
11346+
//
11347+
// The CONTROL is the load-bearing half: it reads the same branch the old
11348+
// way, in the same repo, and must come back quoted, tierless and gateless —
11349+
// otherwise the rows below would pass against a fixture that never
11350+
// reproduced the defect.
11351+
const quoted = nodePath.join(gitTmp, 'quoted-names');
11352+
mkdirSync(quoted, { recursive: true });
11353+
g(['init', '--initial-branch=main', '.'], quoted);
11354+
g(['config', 'core.quotePath', 'true'], quoted);
11355+
const nonAsciiEdited = 'skills/objectstack-data/\u57fa\u7ebf.md';
11356+
const nonAsciiCommitted = 'skills/objectstack-data/\u6587\u6863.md';
11357+
const newlineUntracked = 'skills/objectstack-data/two\nlines.md';
11358+
commit(quoted, nonAsciiEdited, 'root');
11359+
g(['update-ref', 'refs/remotes/origin/main', g(['rev-parse', 'main'], quoted)], quoted);
11360+
g(['checkout', '-b', 'feature'], quoted);
11361+
commit(quoted, nonAsciiCommitted, 'a skill file named in Chinese');
11362+
write(quoted, nonAsciiEdited, 'edited, not committed\n');
11363+
write(quoted, newlineUntracked, 'never added\n');
11364+
11365+
const plainRead = [
11366+
...g(['diff', '--name-only', '--no-renames', 'origin/main', 'HEAD'], quoted).split('\n'),
11367+
...g(['diff', '--name-only', '--no-renames', 'HEAD'], quoted).split('\n'),
11368+
...g(['ls-files', '--others', '--exclude-standard'], quoted).split('\n'),
11369+
].filter(Boolean);
11370+
const familiesOf = (paths) =>
11371+
[...discoverFamilies().byCheck.entries()].filter(([, e]) => classifyEntry(e, paths).verdict === 'matched').map(([check]) => check);
11372+
t(
11373+
'the CONTROL reproduces the defect: the plain read quotes all three names, so they derive no tier and name no gate family',
11374+
plainRead.length === 3 && plainRead.every((p) => p.startsWith('"')) && deriveTier(plainRead).tier === null && familiesOf(plainRead).length === 0,
11375+
plainRead,
11376+
);
11377+
11378+
const raw = changedPathsFromGit({ cwd: quoted });
11379+
t(
11380+
'the derived change set spells each C-quoted name as it is on disk: committed, uncommitted and untracked (newline included)',
11381+
[nonAsciiCommitted, nonAsciiEdited, newlineUntracked].every((p) => raw.paths.includes(p)) && raw.paths.length === 3 &&
11382+
raw.counts.committed === 1 && raw.counts.worktree === 1 && raw.counts.untracked === 1,
11383+
raw.paths,
11384+
);
11385+
t(
11386+
'and those raw names derive the contract-review tier through the skills/** glob',
11387+
deriveTier(raw.paths).tier === CONTRACT_REVIEW_TIER && deriveTier(raw.paths).hits.length === 3,
11388+
deriveTier(raw.paths),
11389+
);
11390+
t(
11391+
'and they name the skill gate families the derived --commands list is built from',
11392+
familiesOf(raw.paths).some((check) => /^check:skill-/.test(check)),
11393+
familiesOf(raw.paths),
11394+
);
11395+
t(
11396+
'and the untracked newline-named file is counted from disk, not as an unreadable file of 0 lines',
11397+
raw.size.untrackedFiles === 1 && raw.size.unreadableFiles === 0 && raw.size.additions === 3,
11398+
raw.size,
11399+
);
11400+
1133511401
// ── A leftover in-tree test fixture must not reach the change set (#12632)
1133611402
//
1133711403
// The derivation reads untracked files on purpose, so `.gitignore` is the

0 commit comments

Comments
 (0)