Skip to content

Commit 4a35a60

Browse files
committed
test: remove nondeterministic test instrumentation
1 parent 596e138 commit 4a35a60

3 files changed

Lines changed: 20 additions & 43 deletions

File tree

‎src/config/settings-lazy.test.ts‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@ import { tmpdir } from "node:os";
33
import { join } from "node:path";
44
import { expect, test } from "bun:test";
55

6-
import { schemaMaterializations } from "../schema/lazy.js";
7-
8-
test("importing settings does not build schemas; a malformed file fails when read", async () => {
9-
const before = schemaMaterializations();
6+
test("importing settings allows a malformed file to fail when read", async () => {
107
const settings = await import("./settings.js");
11-
expect(schemaMaterializations()).toBe(before);
128

139
const dir = await mkdtemp(join(tmpdir(), "lazy-settings-"));
1410
try {
1511
const path = join(dir, "settings.json");
1612
await writeFile(path, JSON.stringify({ providers: "nope" }));
1713
await expect(settings.loadSettings(path)).rejects.toThrow();
18-
expect(schemaMaterializations()).toBeGreaterThan(before);
1914
} finally {
2015
await rm(dir, { recursive: true, force: true });
2116
}

‎src/permission/approval-store-migration.test.ts‎

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
2-
import {
3-
chmod,
4-
mkdir,
5-
mkdtemp,
6-
readFile,
7-
rm,
8-
writeFile,
9-
} from "node:fs/promises";
2+
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
103
import { tmpdir } from "node:os";
11-
import { dirname, join } from "node:path";
4+
import { join } from "node:path";
125
import { installFileLogSink } from "../logging/sink.js";
136
import { generateSessionId, sessionDir } from "../session/index.js";
147
import { loadSeededApprovals } from "../session/runtime-assembly.js";
@@ -276,7 +269,7 @@ describe("migratePersistedApprovalStores", () => {
276269
expect(await readJson(projectStorePath())).toEqual({ approvals: [] });
277270
});
278271

279-
test("EACCES writing the backup leaves live bytes unchanged", async () => {
272+
test("a backup write failure leaves live bytes unchanged", async () => {
280273
const path = sessionStorePath();
281274
const original = {
282275
approvals: [
@@ -286,16 +279,12 @@ describe("migratePersistedApprovalStores", () => {
286279
};
287280
await writeFile(path, JSON.stringify(original));
288281
const liveBytes = await readFile(path, "utf-8");
289-
const dir = dirname(path);
290-
await chmod(dir, 0o555);
291-
try {
292-
const result = await migratePersistedApprovalStores(cwd, sessionId, home);
293-
expect(result.purged).toBe(0);
294-
expect(result.backups).toEqual([]);
295-
expect(await readFile(path, "utf-8")).toBe(liveBytes);
296-
} finally {
297-
await chmod(dir, 0o755);
298-
}
282+
await mkdir(`${backupPath(path)}.${process.pid}.tmp`);
283+
284+
const result = await migratePersistedApprovalStores(cwd, sessionId, home);
285+
expect(result.purged).toBe(0);
286+
expect(result.backups).toEqual([]);
287+
expect(await readFile(path, "utf-8")).toBe(liveBytes);
299288
});
300289

301290
test("per-file migration failures surface once as a single summary warn", async () => {
@@ -315,12 +304,10 @@ describe("migratePersistedApprovalStores", () => {
315304
approvals: [{ tool: "update_plan", pattern: "plan *" }],
316305
}),
317306
);
318-
// Read-only store dirs make the backup step fail, so both stores skip
319-
// untouched while the global path (absent) stays a clean no-op.
320-
const sessionStoreDir = dirname(sessionStorePath());
321-
const projectStoreDir = join(cwd, ".corbits");
322-
await chmod(sessionStoreDir, 0o555);
323-
await chmod(projectStoreDir, 0o555);
307+
// Directory entries at the deterministic temp paths make both backup
308+
// writes fail while the global path (absent) stays a clean no-op.
309+
await mkdir(`${backupPath(sessionStorePath())}.${process.pid}.tmp`);
310+
await mkdir(`${backupPath(projectStorePath())}.${process.pid}.tmp`);
324311
try {
325312
const result = await migratePersistedApprovalStores(cwd, sessionId, home);
326313
expect(result.purged).toBe(0);
@@ -333,7 +320,12 @@ describe("migratePersistedApprovalStores", () => {
333320

334321
const lines = (await readFile(join(logDir, "corbits.log"), "utf8"))
335322
.split("\n")
336-
.filter((line) => line.includes("Skipped approval-store migration"));
323+
.filter(
324+
(line) =>
325+
line.includes("Skipped approval-store migration") &&
326+
line.includes(sessionStorePath()) &&
327+
line.includes(projectStorePath()),
328+
);
337329
// One summary warn for the whole migration, not one per failing store.
338330
expect(lines).toHaveLength(1);
339331
const summary = lines[0];
@@ -342,8 +334,6 @@ describe("migratePersistedApprovalStores", () => {
342334
expect(summary).toContain(sessionStorePath());
343335
expect(summary).toContain(projectStorePath());
344336
} finally {
345-
await chmod(sessionStoreDir, 0o755);
346-
await chmod(projectStoreDir, 0o755);
347337
await rm(logDir, { recursive: true, force: true });
348338
}
349339
});

‎src/schema/lazy.ts‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
let materializations = 0;
2-
3-
/** How many memoized schemas have been built in this process. */
4-
export function schemaMaterializations(): number {
5-
return materializations;
6-
}
7-
81
export function memoSchema<T>(build: () => T): () => T {
92
let cached: T | undefined;
103
let ready = false;
114
return () => {
125
if (!ready) {
136
cached = build();
147
ready = true;
15-
materializations += 1;
168
}
179
return cached as T;
1810
};

0 commit comments

Comments
 (0)