experiment(confidence-engine): complete openai reconstruction apparatus

This commit is contained in:
2026-09-06 10:06:06 +01:00
parent a45dd903cf
commit 215c783d11
5 changed files with 281 additions and 7 deletions
@@ -9,7 +9,7 @@
* with a deterministic inline double (zero live model calls).
*/
import { describe, expect, it, beforeAll, afterAll } from "vitest";
import { describe, expect, it, beforeAll, afterAll, vi } from "vitest";
import { execFile } from "child_process";
import { writeFile, unlink } from "fs/promises";
import { join, dirname } from "path";
@@ -159,6 +159,62 @@ describe("start-case-experiment-helper.cjs apparatus", () => {
// ── D — Success output ──────────────────────────────────────────
describe("D — success output", () => {
it("selects the existing OpenAI provider through the helper injection seam", async () => {
const { runStartCaseExperiment } = require(helperPath);
const previousProvider = process.env.START_CASE_EXPERIMENT_PROVIDER;
const previousKey = process.env.OPENAI_API_KEY;
process.env.START_CASE_EXPERIMENT_PROVIDER = "openai";
process.env.OPENAI_API_KEY = "test-key";
try {
const result = await runStartCaseExperiment(
{ scenario: "OpenAI provider selection scenario" },
null,
{
startCase: async (_input, dependencies) => {
expect(typeof dependencies.reconstructionProvider?.generateReconstruction).toBe("function");
expect(dependencies.reconstructionModelName).toBe("gpt-5.6-terra");
return {
success: true,
situationGraph: { nodes: [], edges: [] },
assessment: null,
selectedQuestion: null,
summary: "test",
};
},
},
);
expect(result.success).toBe(true);
} finally {
if (previousProvider === undefined) delete process.env.START_CASE_EXPERIMENT_PROVIDER;
else process.env.START_CASE_EXPERIMENT_PROVIDER = previousProvider;
if (previousKey === undefined) delete process.env.OPENAI_API_KEY;
else process.env.OPENAI_API_KEY = previousKey;
}
});
it("fails before startCase when OpenAI is selected without a key", async () => {
const { runStartCaseExperiment } = require(helperPath);
const previousProvider = process.env.START_CASE_EXPERIMENT_PROVIDER;
const previousKey = process.env.OPENAI_API_KEY;
process.env.START_CASE_EXPERIMENT_PROVIDER = "openai";
delete process.env.OPENAI_API_KEY;
const startCase = vi.fn();
try {
await expect(
runStartCaseExperiment({ scenario: "Missing key scenario" }, null, { startCase }),
).rejects.toThrow("START_CASE_EXPERIMENT_PROVIDER=openai requires OPENAI_API_KEY");
expect(startCase).not.toHaveBeenCalled();
} finally {
if (previousProvider === undefined) delete process.env.START_CASE_EXPERIMENT_PROVIDER;
else process.env.START_CASE_EXPERIMENT_PROVIDER = previousProvider;
if (previousKey === undefined) delete process.env.OPENAI_API_KEY;
else process.env.OPENAI_API_KEY = previousKey;
}
});
it("forwards an explicit reconstruction provider through the startCase path", async () => {
const { runStartCaseExperiment } = require(helperPath);
const reconstructionProvider = { generateReconstruction() {} };