瀏覽代碼

test(sandbox): cover the temp-grant cleanup-failure AggregateError path

Huanqi Cao 2 月之前
父節點
當前提交
bb50783002
共有 1 個文件被更改,包括 14 次插入 和 0 次删除
  1. 14 0
      packages/sandbox/sandbox-local/tests/acl-session.spec.ts

+ 14 - 0
packages/sandbox/sandbox-local/tests/acl-session.spec.ts

@@ -327,6 +327,20 @@ describe('windows-acl write grants (LocalSandboxProvider)', () => {
       // is the map hit (not recreated) — only the failed temp grant joins.
       expect(mockState.grants).toHaveLength(3)
       expect(mockState.grants[2]!.disposed).toBe(true)
+
+      // Temp-side cleanup failure: the standing workspace grant stays (map
+      // hit), the exclusive mkdir fails, AND the temp grant's dispose also
+      // fails — the temp cleanup AggregateError propagates.
+      mockState.grants = []
+      mockState.disposeFailure = new Error('temp cleanup exploded')
+      const dupTemp = shapedTempPath().replace(/abab$/, 'efef')
+      mkdirSync(dupTemp)
+      scratch.push(dupTemp)
+      const dupRecord = { sessionId: SessionId('temp-cleanup-fail'), workspace: ws, tempDir: dupTemp }
+      ctx.sessions.create(SessionId('temp-cleanup-fail'), { seed: [recordEvent(dupRecord)], meta: { cwd: ws } })
+      const dupPolicy: SandboxPolicy = { mode: 'workspace-write', workspaceRoot: ws, sessionId: SessionId('temp-cleanup-fail') }
+      expect(() => sandbox.confine(['true'], dupPolicy)).toThrow(/temp grant materialization failed and its cleanup also failed/)
+      expect(mockState.grants).toHaveLength(1) // only the failed temp grant (the workspace grant was the map hit)
     } finally {
       cleanup()
     }