fix(sandbox): clear failed ACL temp state

This commit is contained in:
Tianyi Cui
2026-08-10 17:56:38 +08:00
parent be880473e2
commit ba63251c48
2 changed files with 10 additions and 0 deletions
@@ -324,6 +324,7 @@ export class AclSandbox {
this.token = undefined
this.writeSidPtr = undefined
this.tempWriteSidPtr = undefined
this.tempDirResolved = undefined
this.grantedPaths = []
if (cleanupFailures.length > 0) {
throw new AggregateError(
@@ -98,4 +98,13 @@ describe.skipIf(!isWin32 || !pwshAvailable())('AclSandbox write restriction', ()
const broken = new AclSandbox({ writableDirs: [writableDir], tempDir: null, writeSid: 'S-1-4-abc-1', mode: 'workspace-write' })
await expect(broken.init()).rejects.toThrow(/ConvertStringSidToSidW/u)
}, 15_000)
it('failed init clears provisional temp state before a retry', async () => {
const broken = new AclSandbox({ writableDirs: [writableDir], tempDir: null, writeSid: 'S-1-4-abc-1', mode: 'workspace-write' })
const provisionalState = broken as unknown as { tempDirResolved: string | undefined }
provisionalState.tempDirResolved = isolatedTemp
await expect(broken.init()).rejects.toThrow(/ConvertStringSidToSidW/u)
expect(broken.tempDir).toBeUndefined()
}, 15_000)
})