test(confidence-engine): expose CU synthesis failure shape
This commit is contained in:
@@ -295,8 +295,37 @@ export async function synthesizeCurrentUnderstanding(
|
||||
// 5. Validate response
|
||||
const validated = validateSynthesisResponse(providerResult.response);
|
||||
if (!validated.valid) {
|
||||
/* ── safe diagnostic: expose shape only, never content ── */
|
||||
|
||||
/* parse string responses for key inspection */
|
||||
let parsedResponse = providerResult.response;
|
||||
if (typeof providerResult.response === "string") {
|
||||
try { parsedResponse = JSON.parse(providerResult.response); } catch {}
|
||||
}
|
||||
|
||||
const hasCU = typeof parsedResponse === "object" &&
|
||||
parsedResponse !== null &&
|
||||
Object.prototype.hasOwnProperty.call(parsedResponse, "currentUnderstanding");
|
||||
|
||||
const diag = {
|
||||
providerApiPath: providerResult.providerApiPath ?? null,
|
||||
responseType: typeof providerResult.response,
|
||||
responseIsNull: providerResult.response === null,
|
||||
responseKeys: (typeof parsedResponse === "object" && parsedResponse !== null && !Array.isArray(parsedResponse))
|
||||
? Object.keys(parsedResponse).sort()
|
||||
: null,
|
||||
hasCurrentUnderstanding: hasCU,
|
||||
currentUnderstandingType: hasCU ? typeof parsedResponse.currentUnderstanding : null,
|
||||
currentUnderstandingLength: hasCU
|
||||
? (typeof parsedResponse.currentUnderstanding === "string"
|
||||
? parsedResponse.currentUnderstanding.length
|
||||
: null)
|
||||
: null,
|
||||
};
|
||||
|
||||
const err = new Error(`Synthesis validation failed: ${validated.error}`);
|
||||
err.statusCode = 502;
|
||||
err.sanitizedDiagnostic = diag;
|
||||
throw err;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user