test(confidence-engine): verify direct decomposition helper

This commit is contained in:
2026-09-04 14:02:36 +01:00
parent 41ea2cb6b9
commit 928954ee4a
3 changed files with 376 additions and 12 deletions
+62 -12
View File
@@ -14,8 +14,29 @@
* 1 — execution failure or invalid input
*/
const dotenv = require("dotenv");
dotenv.config({ path: ".env.local" });
// Minimal .env.local loader — no external dependency required.
// Parses KEY=VALUE lines, skips comments (#) and blank lines.
(function loadDotEnvLocal() {
const fs = require("fs");
const path = require("path");
const envPath = path.resolve(__dirname, "..", ".env.local");
try {
const raw = fs.readFileSync(envPath, "utf-8");
for (const line of raw.split("\n")) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith("#")) continue;
const eqIdx = trimmed.indexOf("=");
if (eqIdx <= 0) continue;
const key = trimmed.slice(0, eqIdx).trim();
const value = trimmed.slice(eqIdx + 1).trim();
if (!(key in process.env)) {
process.env[key] = value;
}
}
} catch {
// .env.local missing — proceed with whatever is already set.
}
})();
function assertRequiredEnv(name) {
const value = process.env[name];
@@ -44,18 +65,42 @@ function readScenarioInput(argv) {
}
async function runStartCaseExperiment(scenarioInput) {
const baseUrl = assertRequiredEnv("OLLAMA_BASE_URL");
const model = assertRequiredEnv("OLLAMA_MODEL");
// Deterministic mode: skip environment checks and use inline test double.
// Controlled via START_CASE_EXPERIMENT_HELPER_MOCK=1 for standalone apparatus tests.
const isMock = process.env.START_CASE_EXPERIMENT_HELPER_MOCK === "1";
if (baseUrl === "http://localhost:11434" || baseUrl === "http://127.0.0.1:11434") {
throw new Error(
`Live experiment harness refuses to use localhost fallback. ` +
`OLLAMA_BASE_URL=${baseUrl}. Configure a real host in .env.local.`
);
let startCase;
if (isMock) {
startCase = async (body) => {
// Deterministic inline test double — no live model calls.
const shouldFail = process.env.START_CASE_EXPERIMENT_HELPER_FORCE_FAIL === "1";
if (shouldFail) {
return { success: false, error: "deterministic mock failure", statusCode: 500 };
}
return {
success: true,
situationGraph: { nodes: [], edges: [], activeUnknownNodeId: null, resolvedNodeIds: [], currentSummary: "test" },
assessment: { phase: "initial", progress: 0 },
selectedQuestion: null,
summary: null,
diagnostics: { validationStatus: "mock", modelName: "inline-test-double", graphReferenceValidation: { valid: true, errors: [] } },
};
};
} else {
const baseUrl = assertRequiredEnv("OLLAMA_BASE_URL");
const model = assertRequiredEnv("OLLAMA_MODEL");
if (baseUrl === "http://localhost:11434" || baseUrl === "http://127.0.0.1:11434") {
throw new Error(
`Live experiment harness refuses to use localhost fallback. ` +
`OLLAMA_BASE_URL=${baseUrl}. Configure a real host in .env.local.`
);
}
const { startCase: _sc } = await import("../../lib/graph/orchestrator.js");
startCase = _sc;
}
const { startCase } = await import("../../lib/graph/orchestrator.js");
const endToEndStartedAt = Date.now();
const result = await startCase(scenarioInput);
const endToEndElapsedMs = Date.now() - endToEndStartedAt;
@@ -83,7 +128,12 @@ async function runStartCaseExperiment(scenarioInput) {
console.log(JSON.stringify(result, null, 2));
process.exit(result.success ? 0 : 1);
} catch (e) {
console.error(`APPARATUS FAILURE: ${e.message}`);
const failure = {
success: false,
error: e.message ?? "unknown",
statusCode: 1,
};
console.log(JSON.stringify(failure));
process.exit(1);
}
})();