Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: fail closed on untracked diff read errors (#7880)

[._.]/ Adam Eivyc3c43141127b
diff --git a/scripts/pregate.test.js b/scripts/pregate.test.js
index 2b7a2f845c..c515f7687c 100644
--- a/scripts/pregate.test.js
+++ b/scripts/pregate.test.js
@@ -158,6 +158,7 @@ describe('pregate hidden-content invocation', () => {
);
it('passes clean uncommitted changes even when the plan selects no lint or tests', () => {
+ git('config', 'core.autocrlf', 'true');
write(trackedPath, `${clean}staged\n`);
git('add', '--', trackedPath);
write(trackedPath, `${clean}unstaged\n`);
@@ -180,18 +181,31 @@ describe('pregate hidden-content invocation', () => {
expect(snapshot()).toEqual(before);
});
- it('preserves binary and empty-file path findings for untracked additions', () => {
+ it('preserves binary, empty-file, and stdin-like path findings for untracked additions', () => {
const emptyPath = 'docs/empty\u200B.md';
write(emptyPath, '');
write('docs/payload.bin', Buffer.from([0, 1, 2]));
+ write('-', hidden);
const before = snapshot();
const result = run('--skip-lint');
expect(result.status, result.stderr).toBe(1);
expect(result.stderr).toContain(`${emptyPath}:1 — hidden-unicode: filename`);
expect(result.stderr).toContain('docs/payload.bin:1 — opaque-binary:');
+ expect(result.stderr).toContain('./-:2 — hidden-unicode:');
expect(snapshot()).toEqual(before);
});
+ it('rejects a no-index read error even when Git reports the difference exit code', () => {
+ // Git lists an untracked nested repository as a directory. Comparing that
+ // path with /dev/null fails with exit 1 and no patch, rather than exit 2.
+ git('init', '-q', 'docs/nested');
+ write('docs/nested/example.md', clean);
+ const result = run('--skip-lint');
+ expect(result.status).toBe(2);
+ expect(result.stderr).toContain('Cannot read untracked diff for docs/nested/');
+ expect(result.stdout).not.toContain('Pregate passed');
+ });
+
it('fails closed when Git cannot read a blob in the requested committed diff', () => {
const blob = git('rev-parse', `HEAD:${trackedPath}`);
write(trackedPath, `${clean}ordinary addition\n`);
diff --git a/scripts/scan-diff-hidden-content.js b/scripts/scan-diff-hidden-content.js
index a4832efa14..06427532ef 100644
--- a/scripts/scan-diff-hidden-content.js
+++ b/scripts/scan-diff-hidden-content.js
@@ -60,13 +60,17 @@ function* readDiffs(base, includeWorktree) {
}).split('\0').filter(Boolean);
for (const path of untracked) {
// --no-index preserves Git's binary/file-mode/filename presentation without
- // staging the file (including empty files and symlinks). Exit 1 means a
- // difference, not a read error; every other nonzero result fails closed.
- const result = spawnSync('git', [...DIFF_ARGS, '--no-index', '--', '/dev/null', path], {
+ // staging the file (including empty files and symlinks). Git recognizes
+ // /dev/null on every platform, but a bare "-" means stdin even after --.
+ const diffPath = path === '-' ? './-' : path;
+ const result = spawnSync('git', [...DIFF_ARGS, '--no-index', '--', '/dev/null', diffPath], {
encoding: 'utf8', maxBuffer: MAX_DIFF_BYTES,
});
if (result.error) throw result.error;
- if (result.status !== 0 && result.status !== 1) {
+ // Exit 1 means either a difference OR some read errors. A real addition
+ // always emits a patch, even for an empty file. Do not reject stderr alone:
+ // Git can warn about CRLF conversion alongside a successfully read patch.
+ if ((result.status !== 0 && result.status !== 1) || (result.status === 1 && !result.stdout)) {
throw new Error(`Cannot read untracked diff for ${path}: ${result.stderr.trim() || result.signal || result.status}`);
}
yield result.stdout;