-
Notifications
You must be signed in to change notification settings - Fork 0
Remove Evidence-based and All sources chips from answer footer #285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
BigSimmo
wants to merge
20
commits into
cursor/fix-all-db-issues-5f13
from
cursor/remove-answer-bar-chips-8b1a
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4f03aef
test(eval): add force-embedding flag + 10 vector-exercising golden cases
BigSimmo a17fa3f
test(eval): harden force-embedding flag and vector-path eval guards
BigSimmo 9400841
test: add deep public access and production scope checks
BigSimmo a382754
refactor(ui): remove duplicate visual-evidence code from ClinicalDash…
BigSimmo 2748e6e
fix: allow anonymous setup-status on production deployments
BigSimmo 8ab57af
merge: consolidate force-embedding eval hardening into platform fixes…
BigSimmo a93b5b9
fix: harden public production access across API, UI, and rate limits
BigSimmo 90fde2d
test: fix unused param lint in document search rate-limit mock
BigSimmo 650d26c
fix(rag): scope anonymous retrieval to public documents via owner sen…
BigSimmo c331802
fix(access): complete forms fallback, signed-url hardening, upload guard
BigSimmo 8981761
feat(db): promote locally reviewed documents to public corpus for ano…
BigSimmo 85f247a
test: stabilize scope-sources stress flow via answer options menu
BigSimmo d9c9084
fix(access): complete public retrieval scope and production access ha…
BigSimmo e474d03
fix: allow anonymous setup-status on production for mobile access
BigSimmo 2bad3a3
Merge pull request #277 from BigSimmo/cursor/hotfix-setup-status-c40b
BigSimmo 7217a8e
merge: reconcile content-access rollout with main hotfix
BigSimmo 3a1cf9c
Auto-hide answer support chips when content sits below on mobile
BigSimmo 8eccda8
Remove Evidence-based and All sources chips from answer footer
BigSimmo 5d86c8f
test: open answer scope via + menu using Scope label
BigSimmo 7a0166d
chore: add answer bar screenshot capture script for chip removal QA
BigSimmo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import { mkdirSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
| import { chromium } from "playwright"; | ||
| import { demoAnswer, demoDocuments } from "../src/lib/demo-data"; | ||
|
|
||
| const baseUrl = process.env.PLAYWRIGHT_BASE_URL ?? "http://localhost:4298"; | ||
| const outDir = join(process.cwd(), "scratch", "screenshots"); | ||
| const outPath = join(outDir, "answer-bar-after-chip-removal.png"); | ||
| const outBottomPath = join(outDir, "answer-bar-bottom-after-chip-removal.png"); | ||
|
|
||
| const readySetupChecks = [ | ||
| { id: "env", label: ".env.local configured", status: "ready", detail: "Test environment ready." }, | ||
| { id: "project", label: "Clinical KB Database target", status: "ready", detail: "Test Supabase project ready." }, | ||
| { id: "schema", label: "supabase/schema.sql applied", status: "ready", detail: "Test schema ready." }, | ||
| { id: "search", label: "Search RPC and vector indexes", status: "ready", detail: "Test search schema ready." }, | ||
| { id: "openai", label: "OpenAI API key available", status: "ready", detail: "Test OpenAI ready." }, | ||
| { id: "worker", label: "npm run worker running", status: "unknown", detail: "Worker not required." }, | ||
| ]; | ||
|
|
||
| async function mockDemoApi(page) { | ||
| await page.route("**/api/setup-status**", async (route) => { | ||
| await route.fulfill({ json: { demoMode: true, checks: readySetupChecks } }); | ||
| }); | ||
| await page.route(/\/api\/documents(?:\?.*)?$/, async (route) => { | ||
| await route.fulfill({ | ||
| json: { | ||
| documents: demoDocuments, | ||
| demoMode: true, | ||
| pagination: { | ||
| limit: 150, | ||
| offset: 0, | ||
| total: demoDocuments.length, | ||
| nextOffset: demoDocuments.length, | ||
| hasMore: false, | ||
| }, | ||
| }, | ||
| }); | ||
| }); | ||
| await page.route(/\/api\/ingestion\/(jobs|batches|quality)(?:\?.*)?$/, async (route) => { | ||
| await route.fulfill({ json: { jobs: [], batches: [], items: [], demoMode: true } }); | ||
| }); | ||
| await page.route(/\/api\/answer(?:\/stream)?(?:\?.*)?$/, async (route) => { | ||
| const body = route.request().postDataJSON(); | ||
| const payload = { ...demoAnswer(body?.query ?? "clozapine monitoring"), demoMode: true }; | ||
| if (route.request().url().includes("/stream")) { | ||
| await route.fulfill({ | ||
| body: [ | ||
| `event: progress\ndata: ${JSON.stringify({ stage: "retrieving", message: "Searching indexed documents." })}`, | ||
| `event: final\ndata: ${JSON.stringify(payload)}`, | ||
| "", | ||
| ].join("\n\n"), | ||
| contentType: "text/event-stream; charset=utf-8", | ||
| }); | ||
| return; | ||
| } | ||
| await route.fulfill({ json: payload }); | ||
| }); | ||
| } | ||
|
|
||
| async function main() { | ||
| mkdirSync(outDir, { recursive: true }); | ||
| const browser = await chromium.launch(); | ||
| const page = await browser.newPage({ viewport: { width: 390, height: 820 } }); | ||
| await mockDemoApi(page); | ||
| await page.goto(`${baseUrl}/`, { waitUntil: "domcontentloaded" }); | ||
| await page.waitForLoadState("networkidle", { timeout: 15000 }).catch(() => undefined); | ||
|
|
||
| const input = page.locator('[data-testid="global-search-input"]:visible').first(); | ||
| await input.waitFor({ state: "visible", timeout: 30000 }); | ||
| await input.fill("clozapine monitoring"); | ||
| await page.locator('[aria-label="Generate source-backed answer"]:visible').first().click(); | ||
| await page.getByTestId("plain-answer-response").waitFor({ timeout: 30000 }); | ||
| await page.waitForTimeout(600); | ||
|
|
||
| const chipCount = await page.locator(".answer-footer-search-chip:visible").count(); | ||
| if (chipCount > 0) { | ||
| throw new Error(`Expected 0 footer chips in answer mode, found ${chipCount}.`); | ||
| } | ||
|
|
||
| await page.screenshot({ path: outPath, fullPage: false }); | ||
| await page.locator("form.answer-footer-search-edge").first().screenshot({ path: outBottomPath }); | ||
| console.log(outPath); | ||
| console.log(outBottomPath); | ||
| await browser.close(); | ||
| } | ||
|
|
||
| main().catch((error) => { | ||
| console.error(error); | ||
| process.exit(1); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,209 @@ | ||
| import fs from "node:fs"; | ||
| import { execSync } from "node:child_process"; | ||
|
|
||
| const ownerScope = `import { isDemoMode, isLocalNoAuthMode } from "@/lib/env"; | ||
|
|
||
| export const PUBLIC_OWNER_FILTER_SENTINEL = "00000000-0000-0000-0000-000000000000"; | ||
|
|
||
| export function requireOwnerScope(ownerId: string | null | undefined): string | undefined { | ||
| if (ownerId) return ownerId; | ||
| if (isDemoMode() || isLocalNoAuthMode() || process.env.NODE_ENV === "test") { | ||
| return undefined; | ||
| } | ||
| throw new Error( | ||
| "Owner-scoped retrieval was called without an ownerId; refusing to run to avoid returning another tenant's data.", | ||
| ); | ||
| } | ||
|
|
||
| export function retrievalOwnerFilter(args: { | ||
| ownerId?: string | null; | ||
| documentIds?: string[]; | ||
| allowGlobalSearch?: boolean; | ||
| }): string | null | undefined { | ||
| if (args.ownerId) return requireOwnerScope(args.ownerId); | ||
| if (isDemoMode() || isLocalNoAuthMode() || process.env.NODE_ENV === "test") { | ||
| return undefined; | ||
| } | ||
| if (args.allowGlobalSearch || args.documentIds?.length) { | ||
| return PUBLIC_OWNER_FILTER_SENTINEL; | ||
| } | ||
| throw new Error( | ||
| "Owner-scoped retrieval was called without an ownerId; refusing to run to avoid returning another tenant's data.", | ||
| ); | ||
| } | ||
| `; | ||
|
|
||
| fs.writeFileSync("src/lib/owner-scope.ts", ownerScope); | ||
|
|
||
| let rag = fs.readFileSync("src/lib/rag.ts", "utf8"); | ||
| rag = rag.replace( | ||
| 'import { requireOwnerScope } from "@/lib/owner-scope";', | ||
| 'import { requireOwnerScope, retrievalOwnerFilter } from "@/lib/owner-scope";', | ||
| ); | ||
| rag = rag.replace( | ||
| /function ownerScopeForDocumentFilteredRetrieval\([\s\S]*?\n\}/, | ||
| `function ownerScopeForDocumentFilteredRetrieval( | ||
| ownerId: string | undefined, | ||
| documentIds: string[] | undefined, | ||
| allowGlobalSearch?: boolean, | ||
| ) { | ||
| return retrievalOwnerFilter({ ownerId, documentIds, allowGlobalSearch }); | ||
| }`, | ||
| ); | ||
| rag = rag.replaceAll( | ||
| "ownerScopeForDocumentFilteredRetrieval(args.ownerId, args.documentIds)", | ||
| "ownerScopeForDocumentFilteredRetrieval(args.ownerId, args.documentIds, args.allowGlobalSearch)", | ||
| ); | ||
| rag = rag.replaceAll( | ||
| "ownerScopeForDocumentFilteredRetrieval(args.ownerId, documentFilterList)", | ||
| "ownerScopeForDocumentFilteredRetrieval(args.ownerId, documentFilterList, args.allowGlobalSearch)", | ||
| ); | ||
| rag = rag.replace( | ||
| `documentFilter ? [documentFilter] : undefined, | ||
| ),`, | ||
| `documentFilter ? [documentFilter] : undefined, | ||
| documentFilter ? undefined : args.allowGlobalSearch, | ||
| ),`, | ||
| ); | ||
| rag = rag.replace( | ||
| `documentIds: documentFilterList, | ||
| matchCount: textCandidateCount,`, | ||
| `documentIds: documentFilterList, | ||
| allowGlobalSearch: args.allowGlobalSearch, | ||
| matchCount: textCandidateCount,`, | ||
| ); | ||
| rag = rag.replaceAll( | ||
| `documentIds: documentFilterList, | ||
| matchCount: Math.min(candidateCount, 48),`, | ||
| `documentIds: documentFilterList, | ||
| allowGlobalSearch: args.allowGlobalSearch, | ||
| matchCount: Math.min(candidateCount, 48),`, | ||
| ); | ||
| rag = rag.replace( | ||
| `documentIds: documentFilterList, | ||
| matchCount: Math.min(candidateCount, 64),`, | ||
| `documentIds: documentFilterList, | ||
| allowGlobalSearch: args.allowGlobalSearch, | ||
| matchCount: Math.min(candidateCount, 64),`, | ||
| ); | ||
| rag = rag.replace( | ||
| "documentIds?: string[];\n matchCount: number;\n}) {\n const runChunkText", | ||
| "documentIds?: string[];\n allowGlobalSearch?: boolean;\n matchCount: number;\n}) {\n const runChunkText", | ||
| ); | ||
| for (const fn of ["searchTableFactCandidates", "searchEmbeddingFieldCandidates", "searchIndexUnitCandidates"]) { | ||
| rag = rag.replace( | ||
| new RegExp(`async function ${fn}\\([\\s\\S]*?documentIds\\?: string\\[\\];\\n matchCount: number;`), | ||
| (m) => m.replace("documentIds?: string[];\n matchCount: number;", "documentIds?: string[];\n allowGlobalSearch?: boolean;\n matchCount: number;"), | ||
| ); | ||
| } | ||
| if (!rag.includes('else documentQuery = documentQuery.is("owner_id", null);')) { | ||
| rag = rag.replace( | ||
| `if (args.ownerId) documentQuery = documentQuery.eq("owner_id", args.ownerId); | ||
| const { data: documents, error: documentsError } = await documentQuery;`, | ||
| `if (args.ownerId) documentQuery = documentQuery.eq("owner_id", args.ownerId); | ||
| else documentQuery = documentQuery.is("owner_id", null); | ||
| const { data: documents, error: documentsError } = await documentQuery;`, | ||
| ); | ||
| } | ||
| fs.writeFileSync("src/lib/rag.ts", rag); | ||
|
|
||
| let enrichment = fs.readFileSync("src/lib/document-enrichment.ts", "utf8"); | ||
| enrichment = enrichment.replace( | ||
| 'import { requireOwnerScope } from "@/lib/owner-scope";', | ||
| 'import { retrievalOwnerFilter } from "@/lib/owner-scope";', | ||
| ); | ||
| enrichment = enrichment.replace( | ||
| "owner_filter: args.ownerId ? requireOwnerScope(args.ownerId) : null,", | ||
| "owner_filter: retrievalOwnerFilter({ ownerId: args.ownerId, documentIds: args.documentIds }),", | ||
| ); | ||
| fs.writeFileSync("src/lib/document-enrichment.ts", enrichment); | ||
|
|
||
| let memory = fs.readFileSync("src/lib/deep-memory.ts", "utf8"); | ||
| if (!memory.includes("retrievalOwnerFilter")) { | ||
| memory = memory.replace( | ||
| 'import { requireOwnerScope } from "@/lib/owner-scope";', | ||
| 'import { retrievalOwnerFilter } from "@/lib/owner-scope";', | ||
| ); | ||
| memory = memory.replace( | ||
| /owner_filter:[\s\S]*?requireOwnerScope\(args\.ownerId\)[\s\S]*?\),/, | ||
| `owner_filter: retrievalOwnerFilter({ | ||
| ownerId: args.ownerId, | ||
| documentIds: args.documentIds, | ||
| allowGlobalSearch: !args.ownerId && !args.documentIds?.length, | ||
| }),`, | ||
| ); | ||
| } | ||
| fs.writeFileSync("src/lib/deep-memory.ts", memory); | ||
|
|
||
| let schema = fs.readFileSync("supabase/schema.sql", "utf8"); | ||
| if (!schema.includes("create or replace function public.retrieval_owner_matches")) { | ||
| schema = schema.replace( | ||
| "create or replace function public.match_document_chunks(", | ||
| `create or replace function public.retrieval_owner_matches(owner_filter uuid, row_owner_id uuid) | ||
| returns boolean | ||
| language sql | ||
| immutable | ||
| parallel safe | ||
| set search_path = public, pg_temp | ||
| as $$ | ||
| select case | ||
| when owner_filter is null then true | ||
| when owner_filter = '00000000-0000-0000-0000-000000000000'::uuid then row_owner_id is null | ||
| else row_owner_id = owner_filter | ||
| end; | ||
| $$; | ||
|
|
||
| create or replace function public.match_document_chunks(`, | ||
| ); | ||
| } | ||
| schema = schema.replaceAll("(owner_filter is null or d.owner_id = owner_filter)", "public.retrieval_owner_matches(owner_filter, d.owner_id)"); | ||
| schema = schema.replaceAll("(owner_filter is null or l.owner_id = owner_filter)", "public.retrieval_owner_matches(owner_filter, l.owner_id)"); | ||
| schema = schema.replaceAll("(owner_filter is null or s.owner_id = owner_filter)", "public.retrieval_owner_matches(owner_filter, s.owner_id)"); | ||
| schema = schema.replaceAll("(owner_filter is null or f.owner_id = owner_filter)", "public.retrieval_owner_matches(owner_filter, f.owner_id)"); | ||
| fs.writeFileSync("supabase/schema.sql", schema); | ||
|
|
||
| const names = [ | ||
| "retrieval_owner_matches", | ||
| "match_document_chunks", | ||
| "match_document_chunks_hybrid", | ||
| "match_document_memory_cards_hybrid", | ||
| "match_documents_for_query", | ||
| "match_document_chunks_text", | ||
| "match_document_lookup_chunks_text", | ||
| "get_related_document_metadata", | ||
| "match_document_table_facts_text", | ||
| "match_document_embedding_fields_hybrid", | ||
| "match_document_index_units_hybrid", | ||
| ]; | ||
| const chunks = names.map((name) => { | ||
| const re = new RegExp(`create or replace function public\\.${name}[\\s\\S]*?\\n\\$\\$;`, "i"); | ||
| const match = schema.match(re); | ||
| if (!match) throw new Error(`missing ${name}`); | ||
| return match[0]; | ||
| }); | ||
| fs.writeFileSync( | ||
| "supabase/migrations/20260705210000_retrieval_owner_filter_sentinel.sql", | ||
| `-- Public-only retrieval owner filter sentinel for hybrid RPCs.\nset search_path = public, extensions, pg_temp;\n\n${chunks.join("\n\n")}\n`, | ||
| ); | ||
|
|
||
| let ownerTest = fs.readFileSync("tests/owner-scope.test.ts", "utf8"); | ||
| if (!ownerTest.includes("retrievalOwnerFilter")) { | ||
| ownerTest += `\ndescribe("retrievalOwnerFilter", () => { | ||
| it("returns the public sentinel for anonymous production global search", async () => { | ||
| vi.doMock("@/lib/env", () => ({ isDemoMode: () => false, isLocalNoAuthMode: () => false })); | ||
| vi.stubEnv("NODE_ENV", "production"); | ||
| const { retrievalOwnerFilter, PUBLIC_OWNER_FILTER_SENTINEL } = await import("../src/lib/owner-scope"); | ||
| expect(retrievalOwnerFilter({ allowGlobalSearch: true })).toBe(PUBLIC_OWNER_FILTER_SENTINEL); | ||
| }); | ||
| });\n`; | ||
| fs.writeFileSync("tests/owner-scope.test.ts", ownerTest); | ||
| } | ||
|
|
||
| execSync( | ||
| "git add src/lib/owner-scope.ts src/lib/rag.ts src/lib/document-enrichment.ts src/lib/deep-memory.ts supabase/schema.sql supabase/migrations/20260705210000_retrieval_owner_filter_sentinel.sql tests/owner-scope.test.ts scripts/commit-access-rag-fix.mjs", | ||
| { stdio: "inherit" }, | ||
| ); | ||
| execSync('git commit -m "fix(rag): scope anonymous retrieval to public documents via owner sentinel"', { | ||
| stdio: "inherit", | ||
| }); | ||
| console.log("committed"); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One-shot commit script in repo
High Severity
The
commit-access-rag-fix.mjsscript is a one-shot maintenance script that overwrites core library and schema files and then automatically commits the changes. This creates a serious footgun, risking unintended local commits and data corruption if executed in dev or CI environments.Additional Locations (1)
scripts/commit-access-rag-fix.mjs#L1-L3Reviewed by Cursor Bugbot for commit 7a0166d. Configure here.