98 lines
2.7 KiB
JavaScript
98 lines
2.7 KiB
JavaScript
import { mkdir, writeFile } from "node:fs/promises";
|
|
|
|
const BASE_URL =
|
|
process.env.CONFIDENCE_ENGINE_BASE_URL || "http://127.0.0.1:3000";
|
|
const OUTPUT_DIR = "tests-results/commercial-value-update";
|
|
|
|
const scenario = "I think therefore I am";
|
|
const answer =
|
|
"Deciding whether to build the Confidence Engine due to uncertainty about its commercial value.";
|
|
|
|
async function postJson(path, body) {
|
|
const response = await fetch(`${BASE_URL}${path}`, {
|
|
method: "POST",
|
|
headers: {
|
|
"content-type": "application/json",
|
|
},
|
|
body: JSON.stringify(body),
|
|
});
|
|
|
|
const json = await response.json();
|
|
return { status: response.status, json };
|
|
}
|
|
|
|
function printLine(label, value) {
|
|
const rendered = value === undefined ? null : value;
|
|
console.log(`${label}: ${JSON.stringify(rendered)}`);
|
|
}
|
|
|
|
async function main() {
|
|
await mkdir(OUTPUT_DIR, { recursive: true });
|
|
|
|
const startResult = await postJson("/api/cases/start", { scenario });
|
|
await writeFile(
|
|
`${OUTPUT_DIR}/start-response.json`,
|
|
JSON.stringify(startResult, null, 2),
|
|
);
|
|
|
|
const selectedQuestion = startResult.json?.selectedQuestion?.question || null;
|
|
|
|
let updateResult = {
|
|
status: null,
|
|
json: {
|
|
success: false,
|
|
stage: "request_construction",
|
|
errors: ["Missing selected question from start response"],
|
|
},
|
|
};
|
|
|
|
if (startResult.json?.success && selectedQuestion) {
|
|
updateResult = await postJson("/api/cases/update", {
|
|
situationGraph: startResult.json.situationGraph,
|
|
previousQuestion: selectedQuestion,
|
|
answer,
|
|
});
|
|
}
|
|
|
|
await writeFile(
|
|
`${OUTPUT_DIR}/update-response.json`,
|
|
JSON.stringify(updateResult, null, 2),
|
|
);
|
|
|
|
printLine("start success", startResult.json?.success ?? false);
|
|
printLine("update success", updateResult.json?.success ?? false);
|
|
printLine("update stage", updateResult.json?.stage ?? null);
|
|
printLine(
|
|
"proposal added nodes",
|
|
updateResult.json?.proposal?.addedNodes?.map((node) => node.id) ?? null,
|
|
);
|
|
printLine(
|
|
"proposal added edges",
|
|
updateResult.json?.proposal?.addedEdges?.map((edge) => ({
|
|
id: edge.id,
|
|
fromNodeId: edge.fromNodeId,
|
|
toNodeId: edge.toNodeId,
|
|
relationship: edge.relationship,
|
|
})) ?? null,
|
|
);
|
|
printLine(
|
|
"proposal resolved unknown IDs",
|
|
updateResult.json?.proposal?.resolvedUnknownNodeIds ??
|
|
updateResult.json?.resolvedUnknownNodeIds ??
|
|
null,
|
|
);
|
|
printLine(
|
|
"errors",
|
|
updateResult.json?.errors ??
|
|
updateResult.json?.proposalErrors ??
|
|
updateResult.json?.graphValidationErrors ??
|
|
updateResult.json?.validationErrors ??
|
|
null,
|
|
);
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error(error instanceof Error ? error.message : String(error));
|
|
process.exitCode = 1;
|
|
});
|