fix: harden phase summary open questions
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user