Skip to content

Commit 88dc2d3

Browse files
fix(dde): determinism test regenerates into a scratch dir — no live-dir writes during the suite
The CI failure on 88e4dae (Node 18 engine job) was a parallel-read race: the determinism test rewrote the ten fixture records in place while the doc-curl harness and the API-page guard read the same directory, so a reader could observe a half-written record (JSON.parse("")). make-fixture now accepts --out <dir> (default unchanged — regeneration stays byte-identical) and the test compares against a temp copy instead. Generated with Codebuff 🤖 Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent 88e4dae commit 88dc2d3

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

‎examples/delivery-fixture/make-fixture.mjs‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ import { artifactSha256 } from "../../packages/delivery/index.js";
3131
const HERE = dirname(fileURLToPath(import.meta.url));
3232
const CHAIN_ID = "1116";
3333

34+
// Output directory: the fixture dir itself by default; `--out <dir>` writes
35+
// elsewhere (used by the determinism test so the live fixture directory is
36+
// never mutated while parallel test files may be reading it).
37+
3438
// Fixed timestamps — determinism over currency. This fixture documents a
3539
// modeled timeline, not wall-clock reality.
3640
const T = Object.freeze({
@@ -414,11 +418,13 @@ for (const [name, rec] of Object.entries(records)) {
414418
records[name] = { json, bytes: buf.length };
415419
}
416420

417-
mkdirSync(HERE, { recursive: true });
421+
const outArg = process.argv.indexOf("--out");
422+
const OUT = outArg > -1 ? process.argv[outArg + 1] : HERE;
423+
mkdirSync(OUT, { recursive: true });
418424
for (const [name, { json }] of Object.entries(records)) {
419-
writeFileSync(join(HERE, name), json, "utf8");
425+
writeFileSync(join(OUT, name), json, "utf8");
420426
}
421-
writeFileSync(join(HERE, "hashes.json"), JSON.stringify(manifest, null, 2) + "\n", "utf8");
427+
writeFileSync(join(OUT, "hashes.json"), JSON.stringify(manifest, null, 2) + "\n", "utf8");
422428

423429
console.log(`fixture written: ${Object.keys(records).length + 1} files (10 records + hashes.json)`);
424430
console.log(` parties: client=${CLIENT_AGENT.address} provider=${PROVIDER_AGENT.address}`);

‎test/delivery/fixture.test.js‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
import { test } from "node:test";
1717
import assert from "node:assert/strict";
1818
import { execFileSync, spawnSync } from "node:child_process";
19-
import { readFileSync } from "node:fs";
19+
import { readFileSync, mkdtempSync, rmSync } from "node:fs";
2020
import { dirname, join } from "node:path";
21+
import { tmpdir } from "node:os";
2122
import { fileURLToPath } from "node:url";
2223

2324
import {
@@ -321,10 +322,19 @@ test("PC mapping: an incomplete fixture names its gaps instead of mapping", () =
321322
// ------------------------------------- generator determinism + CLI
322323

323324
test("generator: two runs produce byte-identical fixture files", () => {
324-
const before = readFileSync(join(FIXTURE_DIR, "agreement.json"));
325-
spawnSync(process.execPath, [join(FIXTURE_DIR, "make-fixture.mjs")], { cwd: REPO });
326-
const after = readFileSync(join(FIXTURE_DIR, "agreement.json"));
327-
assert.ok(before.equals(after), "regeneration must be byte-identical");
325+
// Regenerate into a scratch directory — never into the live fixture dir.
326+
// Parallel test files (doc-curl harness, page guard) read those records;
327+
// writing them in place raced them on CI (torn read → JSON.parse("")).
328+
const scratch = mkdtempSync(join(tmpdir(), "dde-det-"));
329+
try {
330+
const before = readFileSync(join(FIXTURE_DIR, "agreement.json"));
331+
const r = spawnSync(process.execPath, [join(FIXTURE_DIR, "make-fixture.mjs"), "--out", scratch], { cwd: REPO });
332+
assert.equal(r.status, 0, `regeneration must succeed:\n${r.stderr}`);
333+
const after = readFileSync(join(scratch, "agreement.json"));
334+
assert.ok(before.equals(after), "regeneration must be byte-identical");
335+
} finally {
336+
rmSync(scratch, { recursive: true, force: true });
337+
}
328338
});
329339

330340
test("CLI: clean verification exits 0 and prints the boundary", () => {

0 commit comments

Comments
 (0)