Skip to content

Commit acb82a3

Browse files
committed
fix(pm): dispatch-gates derives the change set with -z, so a non-ASCII governed path keeps its tier
changedPathsFromGit read its three path lists (committed, uncommitted, untracked) line by line without -z. Git C-quotes a path holding a non-ASCII byte or a control character, the quoted spelling matches no glob, and a skills/** file derived no tier and no gate family; an untracked one was counted as unreadable. The lists now go through one reader that splices -z in and splits on NUL, untrimmed. A real-git self-test scenario carries one such name per read (two Chinese names, one newline name), with a control that reads the same branch the old way and comes back quoted, tierless and gateless. Claude-Session: https://claude.ai/code/session_01ADHkmPfzYmYaFdzt3TJ9w2 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 895783a commit acb82a3

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)