* test(#1883): failing-first regression for findContextMdIn / listMilestoneArchiveDirs swallowing EACCES
Adds failing-first regression tests proving an unreadable dir is currently
swallowed as empty/null instead of surfacing the permission error. Covers
EACCES, EIO, the unchanged ENOENT empty path, the array fast-path, and both
CONTEXT.md forms. listMilestoneArchiveDirs is exercised in-process via a new
_listMilestoneArchiveDirs test seam (the validate command runs in a subprocess,
so an fs monkeypatch in the test process cannot reach it).
* fix(#1883): distinguish a permission/IO error from genuine emptiness in dir scans
findContextMdIn (src/planning-workspace.cts) and listMilestoneArchiveDirs
(src/verify.cts) catch-alled every readdirSync error into the empty marker
(null / []), conflating a genuine ENOENT ('nothing there') with an EACCES/EIO
failure ('can't read this'). An unreadable phase dir was silently reported as
'no CONTEXT.md' (discuss/plan gates wrongly skipped context) and an unreadable
milestones/ dir as 'no archives' (active-milestone resolution / archived-phase
filtering misbehaved).
Narrow each catch to ENOENT only — keep the long-standing null/[] contract for
genuine absence (Hyrum: empty path unchanged) and re-throw every other error so
it propagates to the caller's existing try/catch. All six findContextMdIn
callers either pass a pre-read string[] (no readdir) or sit inside a try block
that already handles readdir failures; the two listMilestoneArchiveDirs callers
live in the validate command path where errors reach the command error handler.
Exposes a _listMilestoneArchiveDirs test seam so the permission-error path can
be unit-tested in-process (the validate command runs in a subprocess, so an fs
monkeypatch in the test process cannot reach the private helper).
* fix(tests): delete stale emitted-drift ack for gsd-phase-researcher.md
Pre-existing base-branch defect, not part of #1883: commit 6932fb16d
(enhance(#1699): require read-and-cite provenance, #2768) landed the
gsd-phase-researcher.md growth onto next WITHOUT removing its now-obsolete
emitted-drift-ack.json entry. An ack explains a ripple in a PR diff; once the
change merges to next the ripple becomes part of the baseline, so the ack is
permanently stale for every subsequent PR — the emitted-attribution gate fails
on every branch off next with '1 stale acknowledgment(s) — the ripple they
explained is gone'.
The gate's own error message prescribes the fix: delete the stale entry, and
since gsd-phase-researcher.md was the only entry, delete the file (an empty ack
file signals nothing; its presence is the alarm). This unblocks the red base for
all in-flight PRs, not just this one. Folded inline per the bug-fixer directive
(one-line test-prescribed fix, does not bury the #1883 fix).
* docs(changeset): #1883 permission-error-not-empty
* test(#1883): use t.mock.method + t.after per CONTRIBUTING test conventions
Address code-review finding: replace inline try/finally in test bodies and
manual fs.readdirSync reassignment with t.mock.method (auto-restored) and
t.after for tmp-dir cleanup, matching CONTRIBUTING.md test patterns and the
existing t.mock.method idiom in tests/phase.test.cjs.
* docs(changeset): backfill #1883 PR number to 2802
This commit is contained in:
@@ -2888,3 +2888,63 @@ describe('verifySummaryCore — reusable structured contract (#2572)', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── bug #1883: listMilestoneArchiveDirs must not swallow permission/I-O errors ──
|
||||
// The private helper catch-alled every readdirSync error into [], so an unreadable
|
||||
// milestones/ dir was silently reported as "no archives" (active-milestone
|
||||
// resolution / archived-phase filtering misbehaved). The narrowed catch re-throws
|
||||
// every non-ENOENT error and keeps [] only for genuine absence. Tested in-process
|
||||
// via the _listMilestoneArchiveDirs test seam (the validate command runs in a
|
||||
// subprocess, so an fs monkeypatch in the test process cannot reach it).
|
||||
describe('bug #1883 — listMilestoneArchiveDirs distinguishes a permission error from emptiness', () => {
|
||||
const verifyLib = require('../gsd-core/bin/lib/verify.cjs');
|
||||
const listMilestoneArchiveDirs = verifyLib._listMilestoneArchiveDirs;
|
||||
const os = require('os');
|
||||
|
||||
function fsError(code, targetPath) {
|
||||
const err = new Error(`${code}: operation failed, scandir '${targetPath}'`);
|
||||
err.code = code;
|
||||
err.syscall = 'scandir';
|
||||
err.path = targetPath;
|
||||
return err;
|
||||
}
|
||||
|
||||
// Inject a readdirSync fault scoped to the milestones/ path under test.
|
||||
// t.mock auto-restores after each test — no chmod 0o000 (root bypasses mode bits).
|
||||
function injectMilestonesFault(t, code, targetPath) {
|
||||
const originalReaddirSync = fs.readdirSync;
|
||||
t.mock.method(fs, 'readdirSync', function (p, ...rest) {
|
||||
if (typeof p === 'string' && p.endsWith(path.join('milestones'))) {
|
||||
throw fsError(code, targetPath);
|
||||
}
|
||||
return originalReaddirSync.call(this, p, ...rest);
|
||||
});
|
||||
}
|
||||
|
||||
test('listMilestoneArchiveDirs re-throws a permission (EACCES) error instead of returning []', (t) => {
|
||||
const planBase = path.join(os.tmpdir(), 'gsd-1883-eacces-' + process.pid);
|
||||
injectMilestonesFault(t, 'EACCES', path.join(planBase, 'milestones'));
|
||||
assert.throws(
|
||||
() => listMilestoneArchiveDirs(planBase),
|
||||
(err) => err.code === 'EACCES',
|
||||
'an unreadable milestones/ dir must propagate EACCES, not return [] as if empty',
|
||||
);
|
||||
});
|
||||
|
||||
test('listMilestoneArchiveDirs re-throws any non-ENOENT error (EIO)', (t) => {
|
||||
const planBase = path.join(os.tmpdir(), 'gsd-1883-eio-' + process.pid);
|
||||
injectMilestonesFault(t, 'EIO', path.join(planBase, 'milestones'));
|
||||
assert.throws(
|
||||
() => listMilestoneArchiveDirs(planBase),
|
||||
(err) => err.code === 'EIO',
|
||||
'every non-ENOENT error must propagate',
|
||||
);
|
||||
});
|
||||
|
||||
test('listMilestoneArchiveDirs returns [] for an absent milestones/ dir (ENOENT) — empty path unchanged', () => {
|
||||
const planBase = path.join(os.tmpdir(), 'gsd-1883-absent-' + process.pid);
|
||||
// No milestones/ dir created → real OS readdirSync throws ENOENT.
|
||||
assert.deepStrictEqual(listMilestoneArchiveDirs(planBase), [],
|
||||
'an absent milestones/ dir (ENOENT) must still return [] — Hyrum: empty path unchanged');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user