Skip to content

Commit 9a6b693

Browse files
fix(dde): stage fixture records in the doc-curl harness — no reads from the live examples dir
Final root cause from the node 18 CI log (loadFixtureFromDir → JSON.parse("") on a record): the determinism contract test regenerates the fixture in place while node --test runs suites in parallel, and my harness read the records from the live examples/ dir at runtime — catching a file mid-rewrite. The harness now stages all eleven record files into its tmp dir up front (parse checked, torn-read retry) and points the documented relative record path at the staged copy. The live dir is never read during the contract run. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent 99ea022 commit 9a6b693

1 file changed

Lines changed: 38 additions & 7 deletions

File tree

‎test/delivery/doc-curl-contract.test.js‎

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import test from "node:test";
22
import assert from "node:assert/strict";
33
import { spawn, spawnSync } from "node:child_process";
44
import http from "node:http";
5-
import { mkdtempSync, rmSync, readFileSync, existsSync } from "node:fs";
5+
import { mkdtempSync, rmSync, readFileSync, existsSync, mkdirSync, writeFileSync } from "node:fs";
66
import { tmpdir } from "node:os";
77
import { join, dirname } from "node:path";
88
import { fileURLToPath, pathToFileURL } from "node:url";
@@ -19,8 +19,16 @@ import { fileURLToPath, pathToFileURL } from "node:url";
1919
* is asserted to have been needed):
2020
* 1. port :8787 → an ephemeral port
2121
* 2. import './packages/…' → absolute file:// URL (bash cwd is a tmp dir)
22-
* 3. tmp cwd → the docs assume a repo-root cwd; relative
23-
* record paths are rewritten to absolute
22+
* 3. tmp cwd → the docs assume a repo-root cwd; the
23+
* fixture records are STAGED into the tmp
24+
* dir first and the relative record path
25+
* points at the staged copy — the live
26+
* examples/ dir is never read at runtime,
27+
* because the determinism contract test
28+
* regenerates the fixture in place
29+
* concurrently (node --test parallelism)
30+
* and a mid-rewrite read can catch an
31+
* empty file (JSON.parse("") crash)
2432
* 4. node --input-type=module → the assembly one-liner relies on the
2533
* repo's package.json `type: module`, which
2634
* only applies from the repo cwd; from the
@@ -145,9 +153,32 @@ test("doc curl examples execute against a live documented endpoint and match the
145153

146154
try {
147155
const importBase = pathToFileURL(REPO).href;
148-
const absBase = REPO.replaceAll("\\", "/");
149156
let sawDocumentedStart = false;
150157

158+
// Stage the fixture records into the tmp dir. The live examples/ dir is
159+
// concurrently regenerated in place by the determinism contract test
160+
// (node --test parallelism), so reading it at runtime can catch a file
161+
// mid-rewrite (empty → JSON.parse crash). Each staged record is parsed
162+
// before it is accepted; a torn read just retries (bytes are fixed).
163+
const stagedFixtureDir = join(tmp, "staged-fixture");
164+
mkdirSync(stagedFixtureDir, { recursive: true });
165+
const RECORDS = [
166+
"agreement.json", "acceptance-criteria.json", "parties.json",
167+
"authorization.json", "execution-attestation.json", "delivery-manifest.json",
168+
"acceptance-record.json", "dispute-record.json", "consent-and-disclosure.json",
169+
"retention-policy.json", "hashes.json",
170+
];
171+
for (const name of RECORDS) {
172+
const src = join(REPO, "examples", "delivery-fixture", name);
173+
let text = null;
174+
for (let i = 0; i < 5 && text === null; i++) {
175+
const candidate = readFileSync(src, "utf8");
176+
try { JSON.parse(candidate); text = candidate; } catch { await new Promise((r) => setTimeout(r, 50)); }
177+
}
178+
assert.ok(text !== null, `staging: ${name} could not be read intact (concurrent regeneration?)`);
179+
writeFileSync(join(stagedFixtureDir, name), text);
180+
}
181+
151182
for (const rel of DOC_FILES) {
152183
const md = readFileSync(join(REPO, rel), "utf8").replaceAll("\r\n", "\n");
153184
const fences = extractBashFences(md).filter((f) => /curl /.test(f));
@@ -167,12 +198,12 @@ test("doc curl examples execute against a live documented endpoint and match the
167198
}
168199

169200
// Harness transforms: any relative repo import ('./packages/…') →
170-
// absolute file:// URL, relative record paths → absolute, then the
171-
// documented port → one ephemeral port shared by the run.
201+
// absolute file:// URL, the record path → the staged copy in tmp,
202+
// then the documented port → one ephemeral port shared by the run.
172203
let runnable = commands
173204
.map((c) => c
174205
.replaceAll("'./packages/", `'${importBase}/packages/`)
175-
.replaceAll("'./examples/delivery-fixture'", `'${absBase}/examples/delivery-fixture'`))
206+
.replaceAll("'./examples/delivery-fixture'", `'${stagedFixtureDir.replaceAll("\\", "/")}'`))
176207
.join("\n");
177208
if (port === null) {
178209
assert.ok(

0 commit comments

Comments
 (0)