-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapture-real-sessions.test.ts
More file actions
48 lines (43 loc) · 1.71 KB
/
Copy pathcapture-real-sessions.test.ts
File metadata and controls
48 lines (43 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { describe, expect, test } from "bun:test";
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { parseScenariosJson } from "../query-golden/schema";
import { envPath, validateProbesAgainstGolden } from "./capture-real-sessions";
import { parseProbesJson } from "./schema";
const EVAL_DIR = join(import.meta.dir);
const REPO_ROOT = join(EVAL_DIR, "../..");
describe("capture-real-sessions helpers", () => {
test("envPath treats empty string like unset", () => {
const prior = process.env.CAPTURE_TEST_PATH;
process.env.CAPTURE_TEST_PATH = "";
expect(envPath("CAPTURE_TEST_PATH", "/fallback")).toBe("/fallback");
if (prior === undefined) delete process.env.CAPTURE_TEST_PATH;
else process.env.CAPTURE_TEST_PATH = prior;
});
test("validateProbesAgainstGolden accepts minimal fixture probes", () => {
const probes = parseProbesJson(
readFileSync(join(EVAL_DIR, "scenarios.json"), "utf-8"),
).probes;
const scenariosPath = join(REPO_ROOT, "fixtures/golden/scenarios.json");
const { scenarios } = parseScenariosJson(
readFileSync(scenariosPath, "utf-8"),
);
const goldenById = new Map(scenarios.map((s) => [s.id, s]));
expect(() =>
validateProbesAgainstGolden(probes, goldenById, scenariosPath),
).not.toThrow();
});
test("validateProbesAgainstGolden rejects unknown goldenId", () => {
const probes = parseProbesJson(
readFileSync(join(EVAL_DIR, "scenarios.json"), "utf-8"),
).probes;
const goldenById = new Map<string, { id: string }>();
expect(() =>
validateProbesAgainstGolden(
probes,
goldenById as never,
"/tmp/scenarios.json",
),
).toThrow(/not found/);
});
});