Procházet zdrojové kódy

fix: validate legacy intent fallback

Ma před 6 měsíci
rodič
revize
2df9d31df2

+ 2 - 2
packages/core/src/__tests__/pipeline-runner.test.ts

@@ -798,10 +798,10 @@ describe("PipelineRunner", () => {
     try {
       await runner.writeDraft(bookId);
 
-      // Phase 1: persisted plans disabled, planner is always invoked.
-      expect(planChapter).toHaveBeenCalledTimes(1);
+      expect(planChapter).toHaveBeenCalledTimes(0);
       const writeInput = writeChapter.mock.calls[0]?.[0];
       expect(writeInput?.chapterIntent).toBeDefined();
+      expect(writeInput?.chapterIntent).toContain("Bring the focus back to the mentor conflict.");
     } finally {
       await rm(root, { recursive: true, force: true });
     }

+ 13 - 2
packages/core/src/pipeline/persisted-governed-plan.ts

@@ -149,9 +149,11 @@ async function loadLegacyIntentPlan(
     return null;
   }
 
-  const goal = extractSection(intentMarkdown, "Goal") ?? `Chapter ${chapterNumber}`;
+  const rawGoal = extractSection(intentMarkdown, "Goal");
+  if (!rawGoal || !isMeaningfulLegacyValue(rawGoal)) return null;
+  const goal = rawGoal;
   const outlineNodeRaw = extractSection(intentMarkdown, "Outline Node");
-  const outlineNode = outlineNodeRaw && !/^\(?not found\)?$/i.test(outlineNodeRaw)
+  const outlineNode = outlineNodeRaw && isMeaningfulLegacyValue(outlineNodeRaw)
     ? outlineNodeRaw
     : undefined;
 
@@ -196,6 +198,15 @@ function extractListSection(markdown: string, heading: string): string[] {
     .filter((line) => line.length > 0 && line.toLowerCase() !== "none");
 }
 
+function isMeaningfulLegacyValue(value: string): boolean {
+  const normalized = value.trim();
+  if (!normalized) return false;
+  if (/^\(?not found\)?$/i.test(normalized)) return false;
+  if (/^(?:none|null|undefined|n\/a)$/i.test(normalized)) return false;
+  if (/^[*_`\-\s]+$/.test(normalized)) return false;
+  return true;
+}
+
 function escapeRegExp(value: string): string {
   return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
 }