fix(#4081): decode git C-quoted paths in codebase-drift --name-status parser (#4307)

* test(#4081): failing-first regression for quotepath C-quoted paths in codebase-drift

* fix(#4081): decode git C-quoted paths in codebase-drift --name-status parse

* test(#4081): set drift_threshold 1 so decoded-path test triggers action_required

* chore(#4081): add changeset fragment

* chore(#4081): fix changeset fragment formatting

* chore(#4081): backfill PR number in changeset

---------

Co-authored-by: sim <sim@local>
This commit is contained in:
Tom Boucher
2026-09-05 00:50:35 -04:00
committed by GitHub
parent 9ee6d54cc3
commit eb336e9f77
4 changed files with 139 additions and 1 deletions

View File

@@ -28,6 +28,11 @@ const { findOrphanSummaries, findUnsummarizedPlans } = coreUtilsMod;
// eslint-disable-next-line @typescript-eslint/no-require-imports -- planning-scope.cjs is an export= CommonJS module
import planningScopeMod = require('./planning-scope.cjs');
const { SCOPE } = planningScopeMod;
// eslint-disable-next-line @typescript-eslint/no-require-imports -- worktree-safety.cjs is an export= CommonJS module
import worktreeSafetyMod = require('./worktree-safety.cjs');
// Single owner of git C-quoted-path decoding (see #4081 note at the
// codebase-drift --name-status parse loop).
const { decodeGitQuotedPath } = worktreeSafetyMod;
import { execGit, platformReadSync as safeReadFile } from './shell-command-projection.cjs';
import { validatePath } from './security.cjs';
import { formatGsdSlash, resolveRuntime } from './runtime-slash.cjs';
@@ -2309,7 +2314,16 @@ function cmdVerifyCodebaseDrift(cwd: string, raw: boolean): void {
const m = line.match(/^([A-Z])\d*\t(.+?)(?:\t(.+))?$/);
if (!m) continue;
const status = m[1];
const file = m[3] || m[2];
// execGit sets no core.quotepath config, so git's default `true` applies:
// any path containing non-ASCII bytes (or `"`, `\`, control bytes) is
// C-quoted — `"docs/\350\256\276…/overview.md"`. Capturing that verbatim
// garbles affected_paths/elements and makes isPathMapped compare the
// quoted prefix (`"docs`) against STRUCTURE.md, misclassifying DOCUMENTED
// directories as new_dir (#4081). Decode with the single owner of the
// git C-quote seam (worktree-safety.cjs); a non-quoted value — the plain
// ASCII common case — passes through untouched. Both capture groups are
// decoded: R/C lines carry old AND new paths, either may be quoted.
const file = decodeGitQuotedPath(m[3] || m[2]);
if (status === 'A' || status === 'R' || status === 'C') added.push(file);
else if (status === 'M') modified.push(file);
else if (status === 'D') deleted.push(file);

View File

@@ -674,6 +674,11 @@ const SUMMARY_ARTIFACT_SUFFIX = 'SUMMARY.md';
* (a trailing lone backslash, or an octal escape with fewer than three
* digits) never throws — it degrades to treating the character literally, so
* a single bad path can never take down the whole cleanup wave.
*
* Exported (#4081) so the codebase-drift gate's `--name-status` parser can
* decode the identical C-quoted form before classifying paths — the gate's
* `execGit` call sets no `core.quotepath` config, so it receives the same
* quoting and must decode it with the same single owner of this seam.
*/
function decodeGitQuotedPath(raw: string): string {
if (raw.length < 2 || !raw.startsWith('"') || !raw.endsWith('"')) return raw;
@@ -2303,6 +2308,9 @@ function pruneOrphanedWorktrees(repoRoot: string, deps: WorktreeDeps & { writeEr
}
export = {
// Re-exported for the codebase-drift gate's --name-status parser (#4081):
// single owner of git C-quoted-path decoding.
decodeGitQuotedPath,
resolveWorktreeContext,
resolveWorktreeLinkage,
parseWorktreePorcelain,