|
1 | 1 | import assert from "node:assert/strict" |
2 | 2 | import fs from "node:fs" |
3 | | -import { URL } from "node:url" |
| 3 | +import { URL, fileURLToPath } from "node:url" |
4 | 4 | import { describe, it } from "node:test" |
5 | 5 | import { spawn, spawnSync } from "node:child_process" |
6 | 6 | import os from "node:os" |
@@ -118,19 +118,20 @@ function recorderEnv(bin, outDir, providerMarker, extraEnv) { |
118 | 118 |
|
119 | 119 | const stopBudgetEnv = (stopBudget) => (stopBudget ? { SOLHEIM_SMOKE_STOP_BUDGET_S: String(stopBudget) } : {}) |
120 | 120 |
|
121 | | -const recorderScript = new URL("./solheim-smoke/record.sh", import.meta.url).pathname |
| 121 | +const recorderScript = fileURLToPath(new URL("./solheim-smoke/record.sh", import.meta.url)) |
122 | 122 |
|
123 | 123 | function runRecorder( |
124 | 124 | args, |
125 | | - { ffmpeg, ffmpegWrites = true, ffprobeOk = true, seedFinal, providerMarker, stopBudget } = {}, |
| 125 | + { ffmpeg, ffmpegWrites = true, ffprobeOk = true, seedFinal, seedMetadata, providerMarker, stopBudget, extraEnv } = {}, |
126 | 126 | ) { |
127 | 127 | const dir = fs.mkdtempSync(path.join(os.tmpdir(), "record-sh-")) |
128 | 128 | const bin = stubRecorderBin(dir, { ffmpeg, ffmpegWrites, ffprobeOk }) |
129 | 129 | const paths = recorderPaths(dir) |
130 | 130 | fs.mkdirSync(paths.outDir, { recursive: true }) |
131 | 131 | if (seedFinal !== undefined) fs.writeFileSync(paths.finalRecording, seedFinal) |
| 132 | + for (const name of seedMetadata ?? []) fs.writeFileSync(path.join(paths.outDir, name), "stale") |
132 | 133 | const result = spawnSync("bash", [recorderScript, ...args], { |
133 | | - env: recorderEnv(bin, paths.outDir, providerMarker, stopBudgetEnv(stopBudget)), |
| 134 | + env: recorderEnv(bin, paths.outDir, providerMarker, { ...stopBudgetEnv(stopBudget), ...extraEnv }), |
134 | 135 | encoding: "utf8", |
135 | 136 | timeout: 20_000, |
136 | 137 | }) |
@@ -193,6 +194,28 @@ describe("record.sh exit and validation behavior", () => { |
193 | 194 | run.cleanup() |
194 | 195 | } |
195 | 196 | }) |
| 197 | + it("removes stale verdict and trace metadata at start", () => { |
| 198 | + const run = runRecorder(["true"], { |
| 199 | + seedMetadata: ["verdict.json", "trace.json", "verdict.json.1.tmp"], |
| 200 | + }) |
| 201 | + try { |
| 202 | + for (const name of ["verdict.json", "trace.json", "verdict.json.1.tmp"]) |
| 203 | + assert.equal(fs.existsSync(path.join(run.outDir, name)), false, name) |
| 204 | + } finally { |
| 205 | + run.cleanup() |
| 206 | + } |
| 207 | + }) |
| 208 | + |
| 209 | + it("refuses a supplied command while the provider credential is set", () => { |
| 210 | + const run = runRecorder(["true"], { extraEnv: { SOLHEIM_API_KEY: "sk-test" } }) |
| 211 | + try { |
| 212 | + assert.equal(run.result.status, 2) |
| 213 | + assert.match(run.result.stderr, /Refusing/) |
| 214 | + } finally { |
| 215 | + run.cleanup() |
| 216 | + } |
| 217 | + }) |
| 218 | + |
196 | 219 | it("fails when the recording is missing", () => { |
197 | 220 | const run = runRecorder(["true"], { ffmpegWrites: false }) |
198 | 221 | try { |
|
0 commit comments