From a36729824fbf1d1de1362be697af57c076b7a34b Mon Sep 17 00:00:00 2001 From: BigSimmo <87357024+BigSimmo@users.noreply.github.com> Date: Sat, 11 Jul 2026 22:13:28 +0800 Subject: [PATCH 1/2] test: assert document-viewer link href in doc-search smoke Follow-up to #460 (CodeRabbit suggestion): the document-search smoke test verified the "Open document" link is visible but not that it targets the correct viewer location, so a regression opening the wrong document/page could pass. Assert the href matches /documents/?page=(&chunk=) against the mocked search result. Co-Authored-By: Claude Opus 4.8 --- tests/ui-smoke.spec.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/ui-smoke.spec.ts b/tests/ui-smoke.spec.ts index 5877ba930..9ed502f83 100644 --- a/tests/ui-smoke.spec.ts +++ b/tests/ui-smoke.spec.ts @@ -2150,7 +2150,11 @@ test.describe("Clinical KB UI smoke coverage", () => { await expect(documentResults).toContainText("Synthetic lithium monitoring protocol"); await expect(documentResults).toContainText("Best match"); await expect(documentResults).toContainText("Tables 1"); - await expect(documentResults.getByRole("link", { name: "Open document" }).first()).toBeVisible(); + const openDocumentLink = documentResults.getByRole("link", { name: "Open document" }).first(); + await expect(openDocumentLink).toBeVisible(); + // The viewer link must target the mocked document with page + chunk params, so a regression + // that opens the wrong location can't slip through on link presence alone. + await expect(openDocumentLink).toHaveAttribute("href", /\/documents\/[^?]+\?page=\d+(&chunk=[^&]+)?$/); await expect(page.getByRole("complementary").filter({ hasText: "Selected source" })).toHaveCount(0); await expectNoPageHorizontalOverflow(page); }); From 3224b54a6be0125484cdbae84696cddb38e04ec9 Mon Sep 17 00:00:00 2001 From: BigSimmo <87357024+BigSimmo@users.noreply.github.com> Date: Sat, 11 Jul 2026 22:26:07 +0800 Subject: [PATCH 2/2] test: assert exact document-viewer href in doc-search smoke Addresses Codex P2 + CodeRabbit review: the shape-only regex would still pass if the result linked to the wrong document, page, or chunk. Assert the exact href built from mockDemoApi's lithium result instead. Co-Authored-By: Claude Opus 4.8 --- tests/ui-smoke.spec.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/ui-smoke.spec.ts b/tests/ui-smoke.spec.ts index 9ed502f83..ed9551fba 100644 --- a/tests/ui-smoke.spec.ts +++ b/tests/ui-smoke.spec.ts @@ -2152,9 +2152,12 @@ test.describe("Clinical KB UI smoke coverage", () => { await expect(documentResults).toContainText("Tables 1"); const openDocumentLink = documentResults.getByRole("link", { name: "Open document" }).first(); await expect(openDocumentLink).toBeVisible(); - // The viewer link must target the mocked document with page + chunk params, so a regression - // that opens the wrong location can't slip through on link presence alone. - await expect(openDocumentLink).toHaveAttribute("href", /\/documents\/[^?]+\?page=\d+(&chunk=[^&]+)?$/); + // Exact viewer target built from mockDemoApi's lithium result (document_id / bestPages[0] / + // bestChunkIds[0]): a link to the wrong document, page, or chunk must fail this assertion. + await expect(openDocumentLink).toHaveAttribute( + "href", + "/documents/11111111-1111-4111-8111-111111111111?page=1&chunk=44444444-4444-4444-8444-444444444442", + ); await expect(page.getByRole("complementary").filter({ hasText: "Selected source" })).toHaveCount(0); await expectNoPageHorizontalOverflow(page); });