From bfbd57a36516cd1d46c7efd2441abe0777f344f3 Mon Sep 17 00:00:00 2001 From: hugo Date: Sun, 22 Feb 2026 15:50:02 +0100 Subject: [PATCH] fix: render root route on post rerenders, too --- .../engine/ValidationApplyPlannerService.ts | 2 +- tests/engine/BlogGenerationEngine.test.ts | 32 +++++++++++++++++++ .../ValidationApplyPlannerService.test.ts | 1 + 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/main/engine/ValidationApplyPlannerService.ts b/src/main/engine/ValidationApplyPlannerService.ts index 4aa9044..1c04cb9 100644 --- a/src/main/engine/ValidationApplyPlannerService.ts +++ b/src/main/engine/ValidationApplyPlannerService.ts @@ -238,6 +238,6 @@ export function buildTargetedValidationPlan(params: BuildTargetedValidationPlanP requestedYearMonths, requestedYearMonthDays, requestedPageSlugs: new Set(initialPlan.requestedPageSlugs), - requestRootRoutes: initialPlan.requestRootRoutes, + requestRootRoutes: initialPlan.requestRootRoutes || initialPlan.requestedPostRoutes.length > 0, }; } diff --git a/tests/engine/BlogGenerationEngine.test.ts b/tests/engine/BlogGenerationEngine.test.ts index 62842f8..cffae65 100644 --- a/tests/engine/BlogGenerationEngine.test.ts +++ b/tests/engine/BlogGenerationEngine.test.ts @@ -1243,6 +1243,38 @@ describe('BlogGenerationEngine', () => { expect(await fileExists(path.join(tempDir, 'html', '2024', '02', '20', 'index.html'))).toBe(false); }); + it('applies validation for a missing post by rerendering the main root page', async () => { + const posts = [ + makePost({ id: '1', slug: 'target-post', title: 'Target Post', createdAt: new Date('2025-01-15T10:00:00Z') }), + makePost({ id: '2', slug: 'older-post', title: 'Older Post', createdAt: new Date('2024-02-20T10:00:00Z') }), + ]; + setupPosts(posts); + + await mkdir(path.join(tempDir, 'html'), { recursive: true }); + await writeFile(path.join(tempDir, 'html', 'index.html'), 'stale-root', 'utf-8'); + + const { BlogGenerationEngine } = await import('../../src/main/engine/BlogGenerationEngine'); + const engine = new BlogGenerationEngine(); + + await engine.applyValidation({ + projectId: 'test', + projectName: 'Test Blog', + dataDir: tempDir, + baseUrl: 'https://example.com', + }, { + sitemapPath: path.join(tempDir, 'html', 'sitemap.xml'), + sitemapChanged: false, + missingUrlPaths: ['/2025/01/15/target-post'], + extraUrlPaths: [], + expectedUrlCount: 1, + existingHtmlUrlCount: 1, + }, vi.fn()); + + const rootHtml = await readFile(path.join(tempDir, 'html', 'index.html'), 'utf-8'); + expect(rootHtml).not.toContain('stale-root'); + expect(rootHtml).toContain('Target Post'); + }); + it('merges date archive renders when multiple missing posts share the same date lineage', async () => { const posts = [ makePost({ id: '1', slug: 'target-post-1', createdAt: new Date('2025-01-15T10:00:00Z') }), diff --git a/tests/engine/ValidationApplyPlannerService.test.ts b/tests/engine/ValidationApplyPlannerService.test.ts index f1a35be..ce00e46 100644 --- a/tests/engine/ValidationApplyPlannerService.test.ts +++ b/tests/engine/ValidationApplyPlannerService.test.ts @@ -90,5 +90,6 @@ describe('ValidationApplyPlannerService', () => { expect(targeted.requestedYearMonthDays.has('2025/01/15')).toBe(true); expect(targeted.requestedYearMonthDays.has('2025/02/20')).toBe(true); expect(targeted.requestedPageSlugs.has('about')).toBe(true); + expect(targeted.requestRootRoutes).toBe(true); }); });