Skip to content

Commit cba4fe0

Browse files
test(file-safety): pin the caught error as the cause of the staging-path refusal
safeWriteText.ts:432-434 catches the target lstat failure, compares only its error code and throws StagingPathError with the caught error as its cause. Nothing asserted that cause: the previous mutation run priced four survivors on the line that forwards it, and deleting the { cause } argument left all 135 tests green. This adds the case at the layer that already mocks fs - the DACL-notices spec that drives the same publish - so the refusal cannot lose its cause again without a red test. The case stages a caller-supplied staging file whose target lstat answers EACCES and asserts that the error the catch received arrives as the refusal's cause. Discriminated rather than merely added: with 'super(message, cause === undefined ? undefined : {})' the run prints 'Tests 1 failed | 135 passed (136)' on this case at safeWriteText.daclNotices.spec.ts:243, expecting the EACCES error and receiving undefined; with the third argument removed at the throw site the same single test fails with the same message. With the source as committed the pair prints 'Tests 136 passed (136)'. The lint leg ran from the package directory with suppressions pruned and added no entry for this file; the rewrite that pruning did to src/eslint-suppressions.json was reverted rather than committed. Gates, the two removal runs and the mutation re-run on the priced lines are in .tmp-cr-audit/pr-sweep-r101.txt section 285.
1 parent 251b149 commit cba4fe0

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎src/services/file-safety/__tests__/safeWriteText.daclNotices.spec.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,31 @@ describe("safeWriteText win32 DACL notices", () => {
219219
expect(vi.mocked(fs.rename)).not.toHaveBeenCalled()
220220
})
221221

222+
// The refusal at the target lstat only says the identity comparison could not be made; the
223+
// caught error is the only thing that says why. It has to arrive as the cause, or a support
224+
// report can repeat the sentence without learning whether the target was locked or unreadable.
225+
it("carries the target lstat error as the cause of the staging-path refusal", async () => {
226+
const unreadable = codeError("EACCES", "target identity unreadable")
227+
vi.mocked(fs.lstat).mockImplementation(async (stagedPath) => {
228+
if (String(stagedPath) === CALLER_STAGED) {
229+
return fileStatsWithIdentity(7n, 3n)
230+
}
231+
throw unreadable
232+
})
233+
234+
const failure = await publish({
235+
tempPath: CALLER_STAGED,
236+
execFileRunner: icaclsDouble({}).runner,
237+
}).catch((error: unknown) => error)
238+
239+
expect(failure).toBeInstanceOf(StagingPathError)
240+
// instanceof narrows instead of casting, and the assertion above already fails when the
241+
// publish refused with anything else.
242+
if (failure instanceof StagingPathError) {
243+
expect(failure.cause).toBe(unreadable)
244+
}
245+
})
246+
222247
it("removes the backup copy after a successful publish", async () => {
223248
const { leftoverPaths, warnings } = await publish({ backup: true, execFileRunner: icaclsDouble({}).runner })
224249

0 commit comments

Comments
 (0)