test: dedupe sandbox registry absence assertions

This commit is contained in:
Peter Steinberger
2026-05-09 02:10:16 +01:00
parent a7bfa44c35
commit 24662e9f67

View File

@@ -188,6 +188,10 @@ async function seedStaleLock(lockPath: string) {
);
}
async function expectPathMissing(targetPath: string): Promise<void> {
await expect(fs.access(targetPath)).rejects.toMatchObject({ code: "ENOENT" });
}
describe("registry race safety", () => {
it("does not migrate legacy registry files from runtime reads", async () => {
await seedContainerRegistry([containerEntry({ containerName: "legacy-container" })]);
@@ -246,10 +250,10 @@ describe("registry race safety", () => {
expect.objectContaining({ kind: "browsers", status: "migrated", entries: 1 }),
]);
await expect(fs.access(SANDBOX_REGISTRY_PATH)).rejects.toThrow();
await expect(fs.access(SANDBOX_BROWSER_REGISTRY_PATH)).rejects.toThrow();
await expect(fs.access(`${SANDBOX_REGISTRY_PATH}.lock`)).rejects.toThrow();
await expect(fs.access(`${SANDBOX_BROWSER_REGISTRY_PATH}.lock`)).rejects.toThrow();
await expectPathMissing(SANDBOX_REGISTRY_PATH);
await expectPathMissing(SANDBOX_BROWSER_REGISTRY_PATH);
await expectPathMissing(`${SANDBOX_REGISTRY_PATH}.lock`);
await expectPathMissing(`${SANDBOX_BROWSER_REGISTRY_PATH}.lock`);
await expect(readRegistry()).resolves.toEqual({
entries: [
expect.objectContaining({
@@ -353,7 +357,7 @@ describe("registry race safety", () => {
const registry = await readRegistry();
expect(registry.entries.map((entry) => entry.containerName)).toEqual(["../escape"]);
await expect(fs.access(`${TEST_STATE_DIR}/escape.json`)).rejects.toThrow();
await expectPathMissing(`${TEST_STATE_DIR}/escape.json`);
});
it("returns registry entries in deterministic container-name order", async () => {
@@ -408,8 +412,8 @@ describe("registry race safety", () => {
await seedMalformedBrowserRegistry("{bad json");
const results = await migrateLegacySandboxRegistryFiles();
await expect(fs.access(SANDBOX_REGISTRY_PATH)).rejects.toThrow();
await expect(fs.access(SANDBOX_BROWSER_REGISTRY_PATH)).rejects.toThrow();
await expectPathMissing(SANDBOX_REGISTRY_PATH);
await expectPathMissing(SANDBOX_BROWSER_REGISTRY_PATH);
expect(results.map((result) => result.status)).toEqual([
"quarantined-invalid",
"quarantined-invalid",