test(#3090): accept the temp roots the suite actually uses, and say which ones

A fourth failure of the same guard, found by review before it reached CI: the
config-schema property suite builds fixtures through a getWritableTmp() helper
that returns the first writable of /private/tmp, /tmp, os.tmpdir(). On macOS
that is /private/tmp while os.tmpdir() is /var/folders/.../T, so five cleanup()
calls in that file were refused outright.

The three earlier breakages were all spellings of one root. This one is not: the
suite legitimately uses more than one temp root, so the premise was wrong rather
than the encoding. tmpRootCandidates() now probes the conventional system temp
dirs alongside os.tmpdir(), each included only if it exists on the host, so the
accepted set stays a bounded explicit list instead of growing a patch per
platform.

Two corrections that follow from the same review:

A root that is itself a filesystem root already ends in a separator, and
appending another built `//`, which only the literal `/` satisfies — TMPDIR=/
would have refused every descendant. The separator is only appended when it is
not already there.

The refusal messages named os.tmpdir(), which stopped being the boundary. They
now name the roots actually compared against. Every failure of this guard so far
was diagnosed from that message in a CI log, so it should show what was checked
rather than a stale approximation of it.

The symlink-escape check keeps its refusal but drops its claim. fs.rmSync does
not follow a top-level symlink — it unlinks the link and leaves the target
alone — so that check was never closing a live escape, and the test asserting
the victim survived would have passed with the guard removed. Both now say what
is true: a defense-in-depth boundary against a future change to the deletion
mechanism, with only the refusal itself load-bearing.

The QA path helpers were evaluated for reuse rather than keeping a third copy of
path containment. They resolve against one project directory and have no
multi-root or Windows short-name handling, so they are not a drop-in; noted
rather than forced.

Refs #3057

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
sim
2026-08-05 20:05:45 -04:00
parent cc0a4685f1
commit 2e81516f1f
2 changed files with 67 additions and 17 deletions

View File

@@ -261,7 +261,7 @@ test('tmpRootCandidates() returns a well-formed, deduplicated list of absolute p
// ─── Test 8: symlink-escape refusal, all platforms ───────────────────────────
test('cleanup refuses a symlink under tmpdir that resolves outside tmpdir, and the victim survives', (t) => {
test('cleanup refuses a symlink under tmpdir that resolves outside tmpdir', (t) => {
const symlinkParent = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-cleanup-symlink-'));
t.after(() => {
if (fs.existsSync(symlinkParent)) cleanup(symlinkParent);
@@ -294,16 +294,27 @@ test('cleanup refuses a symlink under tmpdir that resolves outside tmpdir, and t
}
if (symlinkCreated) {
// The assert.throws below is the load-bearing assertion for this test:
// it proves the guard refuses a symlink whose target resolves outside
// every accepted tmp root.
assert.throws(
() => cleanup(symlinkPath),
(err) => err instanceof Error && err.message.includes(symlinkPath),
'cleanup must throw and name the symlink path when it resolves outside os.tmpdir()'
);
assert.strictEqual(fs.existsSync(victim), true, 'victim directory must survive the refusal');
// These two assertions document the end state only — they are NOT proof
// the guard prevented a deletion that would otherwise have happened. A
// probe on node v26.5.1 showed fs.rmSync({recursive:true, force:true})
// does not follow a top-level symlink target regardless: it unlinks the
// symlink itself and leaves whatever it points at (the victim, here)
// untouched either way. So the victim would survive with or without this
// guard; the guard's own correctness is established solely by the
// assert.throws above.
assert.strictEqual(fs.existsSync(victim), true, 'victim directory still exists (rmSync would not have followed the symlink either way)');
assert.strictEqual(
fs.existsSync(path.join(victim, 'marker.txt')),
true,
'victim contents must survive the refusal'
'victim contents still exist (rmSync would not have followed the symlink either way)'
);
}
});