fix: harden phase summary open questions

This commit is contained in:
User
2026-07-14 15:09:50 +02:00
parent 18701f020e
commit e228c6f2fd
8 changed files with 110 additions and 12 deletions
+15
View File
@@ -119,3 +119,18 @@ export interface PhaseSummaryV2 {
tables?: PhaseTable[];
open_questions?: string[];
}
/** Defensive compatibility for malformed v2 artifacts persisted before the gate
* enforced `open_questions: string[]`. New payloads stay strictly typed as strings. */
export function phaseOpenQuestionText(value: unknown): string | null {
if (typeof value === "string") return value.trim() || null;
if (typeof value === "number" || typeof value === "boolean") return String(value);
if (!value || typeof value !== "object" || Array.isArray(value)) return null;
const record = value as Record<string, unknown>;
for (const field of ["question", "label"]) {
const text = record[field];
if (typeof text === "string" && text.trim()) return text.trim();
}
return null;
}