test(confidence-engine): prove direct helper production seam

This commit is contained in:
2026-09-04 14:33:02 +01:00
parent 928954ee4a
commit 642554038e
3 changed files with 222 additions and 19 deletions
+34 -19
View File
@@ -14,27 +14,14 @@
* 1 — execution failure or invalid input
*/
// 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");
// Use the standard environment loader already available to this Next repository.
// loadEnvConfig mutates process.env in-place (same semantics as previous bespoke parser).
(function loadEnvironment() {
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;
}
}
const { loadEnvConfig } = require("@next/env");
loadEnvConfig(__dirname, undefined, { logOutput: "none" }, false);
} catch {
// .env.local missing — proceed with whatever is already set.
// loader unavailable — proceed with whatever is already set.
}
})();
@@ -121,6 +108,34 @@ async function runStartCaseExperiment(scenarioInput) {
}
(async () => {
// Import-only mode: prove real production seam without invoking startCase.
// Used only for deterministic apparatus verification of the import path.
if (process.env.START_CASE_EXPERIMENT_HELPER_IMPORT_ONLY === "1") {
try {
const mod = await import("../../lib/graph/orchestrator.js");
const startCaseResolved = typeof mod.startCase === "function";
const output = JSON.stringify({
success: true,
mode: "import-only",
startCaseResolved,
});
console.log(output);
process.exit(0);
} catch (e) {
let failureReason;
if (e.code === "ERR_REQUIRE_ESM" || e.message.includes("ERR_REQUIRE_ESM")) {
failureReason = "CJS cannot import ESM module";
} else if (e.code === "ERR_MODULE_NOT_FOUND" || e.code === "ERR_UNSUPPORTED_DIR_IMPORT") {
failureReason = `Module resolution failed: ${e.message}`;
} else {
failureReason = `Import error: ${e.message}`;
}
const output = JSON.stringify({ success: false, mode: "import-only", startCaseResolved: false, failureReason });
console.log(output);
process.exit(1);
}
}
try {
const scenarioInput = readScenarioInput(process.argv);
const result = await runStartCaseExperiment(scenarioInput);