Skip to content

fix: resolve quality and testing review findings#465

Merged
BigSimmo merged 4 commits into
mainfrom
codex/quality-review-integration
Jul 10, 2026
Merged

fix: resolve quality and testing review findings#465
BigSimmo merged 4 commits into
mainfrom
codex/quality-review-integration

Conversation

@BigSimmo

Copy link
Copy Markdown
Owner

Summary

  • Fix document mutation ordering and title prefix/suffix whitespace handling.
  • Replace quadratic ingestion-quality grouping with typed in-place grouping.
  • Validate final SSE answer payloads and Python extractor JSON at runtime.
  • Repair search-mode transitions and strengthen the corresponding browser test contract.
  • Fix tools-page filtering behavior, include the tools-collapse Playwright spec, and use a bounded Vitest timeout for cold worktree imports.
  • Add focused auth callback, Supabase cookie adapter, document mutation, extractor, and dashboard payload tests.
  • Consolidate the standalone auth-coverage task into this branch, including absolute/protocol-relative redirect rejection and provider-error fallback coverage.

Why

The open Codex quality, testing, TypeScript, and coverage tasks identified 17 confirmed P2/P3 issues. This branch replays their reviewed fixes onto current main and removes the duplicate test-only branch from the merge path.

Verification

Current integration branch:

  • Changed-file Prettier — passed
  • Focused Vitest — 5 files, 23 tests passed
  • git diff --check — passed

Original reviewed branch evidence:

  • Full Vitest — 1,427 passed, 1 skipped
  • Coverage — passed
  • Lint and typecheck — passed
  • Tools-collapse Chromium — 3/3 passed
  • Universal-search Chromium — 5/5 passed
  • Answer quick-link regression — passed
  • Production-readiness CI/static variant — ready with expected missing-secret warnings

Not run

Browser checks were not rerun after replay because local API/browser interaction remains confirmation-gated. The integration worktree also lacks the @next/bundle-analyzer package added to main after its original install, so hosted CI's clean install is the authoritative current typecheck/build.

Risk and governance

Touches API mutation behavior, clinical answer payload validation, extractor parsing, and frontend navigation. No database schema, provider credentials, production data, or live services are changed. Failures remain additive/fail-closed and are covered by focused tests.

@supabase

supabase Bot commented Jul 10, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project sjrfecxgysukkwxsowpy because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Improved universal search interactions and enabled smoother transitions into Answer mode.
    • Added clearer filtered results and a Resume workflow lane across tool mockups.
  • Bug Fixes
    • Improved validation for streamed answers and extracted document data.
    • Prevented stale image metadata from being updated during table-fact edits.
    • Preserved title prefixes and suffixes exactly as entered.
    • Strengthened safe authentication redirects and error handling.
  • Tests
    • Expanded coverage for authentication, document updates, answer validation, extraction, search, and Supabase behavior.
  • Documentation
    • Updated the review records ledger.

Walkthrough

The PR adds runtime validation for streamed answers and extracted documents, updates document mutation and ingestion logic, changes universal-search and tool mockup behavior, and expands route, client, unit, and browser test coverage.

Changes

Answer Search Flow

Layer / File(s) Summary
Answer payload contract
src/components/clinical-dashboard/search-utils.ts, tests/clinical-dashboard-search-utils.test.ts
Adds runtime validation for answer payload fields and tests malformed payload rejection.
SSE final-event handling
src/components/ClinicalDashboard.tsx
Validates final stream events, returns on valid answers, cancels the reader, and reports invalid or stalled streams.
Universal-search answer bridge
src/components/clinical-dashboard/universal-search-command-surface.tsx, tests/ui-universal-search.spec.ts, tests/ui-smoke.spec.ts
Moves item selection to click handlers, crosses into Answer mode, mocks the stream, and verifies the request and rendered heading.

Document Processing and Mutation

Layer / File(s) Summary
Document mutation consistency
src/app/api/documents/[id]/table-facts/route.ts, src/app/api/documents/bulk/route.ts, tests/document-mutation-routes.test.ts
Validates linked image generation metadata before table-fact updates and preserves title-boundary spacing; tests committed, stale, bulk, and cache-invalidation paths.
Extractor payload validation
src/lib/extractors/document.ts, tests/extracted-document-validation.test.ts
Replaces unchecked extractor JSON parsing with Zod validation and tests valid and invalid payloads.
Ingestion row grouping
src/app/api/ingestion/quality/route.ts
Uses a generic helper to group jobs, stages, pages, and images by document.

Tools Mockup Filtering

Layer / File(s) Summary
Filtering and workflow presentation
src/components/tools-page-mockups/tools-page-mockup-page.tsx
Hides browsing sections while filtering, adds a Resume lane, and renders filtered results in the split-pane layout.

Runtime Tests and Records

Layer / File(s) Summary
Authentication and Supabase coverage
tests/auth-callback-route.test.ts, tests/supabase-server.test.ts
Adds coverage for callback redirects, auth errors, Supabase configuration, cookie adapters, and read-only cookie writes.
Test runtime configuration
vitest.config.mts, playwright.config.ts
Raises the Vitest timeout and reformats the unchanged Playwright test-match expression.
Review ledger updates
docs/branch-review-ledger.md
Records two additional branch review entries and their checks.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant UniversalSearch
  participant ClinicalDashboard
  participant AnswerStream
  User->>UniversalSearch: Select “Ask this question”
  UniversalSearch->>ClinicalDashboard: Cross into Answer mode with query
  ClinicalDashboard->>AnswerStream: POST /api/answer/stream
  AnswerStream-->>ClinicalDashboard: SSE final event
  ClinicalDashboard-->>User: Render validated answer
Loading

Caution

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

  • Ignore

❌ Failed checks (1 error, 2 warnings)

Check name Status Explanation Resolution
Verification Claims ❌ Error PR notes and ledger rows use generic verification claims like 'Focused Vitest ... passed' and 'Changed-file Prettier — passed' without exact commands. Rewrite each verification item as 'Ran : passed' or 'Not run: ' for tests, builds, audits, and browser checks.
Description check ⚠️ Warning The description is on-topic but misses the required Clinical Governance Preflight section and the template's checkbox-style verification items. Add the template's Summary and Verification checklist items, and complete Clinical Governance Preflight for the touched ingestion, answer, search, and document-access changes.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 70.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (8 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: fixing quality and testing review findings.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Generated And Sensitive Files ✅ Passed Changed files are only docs/source/tests; no .env, secrets, keys, build outputs, or browser artifacts were present, and diff scan found no secret markers.
Risky Git Or Deployment Actions ✅ Passed Changed docs/tests only record review history and local checks; no force-push, hard reset, destructive clean, shared-branch rebase, or unsafe deployment instructions found.
Supabase Project And Schema Safety ✅ Passed PASS: Diff only touches app logic/tests/docs; no .env, supabase config/schema/migrations, RLS/policy changes, or project-ref updates were introduced.
Runtime And Package Manager Integrity ✅ Passed No package-manager or runtime metadata changes appear in the PR diff; repo still pins npm@11.17.0, Node 24.x, and engine-strict=true.
Api Route Failure Handling ✅ Passed Routes and stream/extractor paths now fail closed on invalid input, auth, and upstream errors via zod/catch blocks, 401 handling, and SSE final-payload validation.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/quality-review-integration
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch codex/quality-review-integration

Comment @coderabbitai help to get the list of available commands.

@BigSimmo
BigSimmo merged commit 86217ae into main Jul 10, 2026
14 of 15 checks passed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/components/ClinicalDashboard.tsx (1)

401-431: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Cancel the stream reader on every exit path.

readAnswerStream only cancels the reader on the success path. The error and invalid-final throw paths unwind without cleanup, so retries can leave the response body/reader open until GC and keep the upstream stream running. Wrap the loop in try/finally and cancel there.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/ClinicalDashboard.tsx` around lines 401 - 431, Update
readAnswerStream to guarantee reader cleanup on all exit paths: wrap the
read/parsing loop and final-payload handling in try/finally, and call
reader.cancel().catch(() => undefined) from the finally block. Remove or avoid
relying on the success-only cancellation so errors and invalid final payloads
also terminate the stream.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/tools-page-mockups/tools-page-mockup-page.tsx`:
- Around line 1089-1129: Thread the preview-selection wiring into the
filtered-results branch of SplitPaneMockup: pass selectedToolId and onSelectTool
to each filtered tool tile, or reuse the selection-aware component used by
WideAllToolsSection, instead of rendering plain ToolCard links. Ensure clicking
a filtered result updates the phone preview while preserving navigation
behavior.

---

Outside diff comments:
In `@src/components/ClinicalDashboard.tsx`:
- Around line 401-431: Update readAnswerStream to guarantee reader cleanup on
all exit paths: wrap the read/parsing loop and final-payload handling in
try/finally, and call reader.cancel().catch(() => undefined) from the finally
block. Remove or avoid relying on the success-only cancellation so errors and
invalid final payloads also terminate the stream.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b9643228-6935-4e14-807c-1231b0d915db

📥 Commits

Reviewing files that changed from the base of the PR and between 405b09e and ecb94a8.

📒 Files selected for processing (18)
  • docs/branch-review-ledger.md
  • playwright.config.ts
  • src/app/api/documents/[id]/table-facts/route.ts
  • src/app/api/documents/bulk/route.ts
  • src/app/api/ingestion/quality/route.ts
  • src/components/ClinicalDashboard.tsx
  • src/components/clinical-dashboard/search-utils.ts
  • src/components/clinical-dashboard/universal-search-command-surface.tsx
  • src/components/tools-page-mockups/tools-page-mockup-page.tsx
  • src/lib/extractors/document.ts
  • tests/auth-callback-route.test.ts
  • tests/clinical-dashboard-search-utils.test.ts
  • tests/document-mutation-routes.test.ts
  • tests/extracted-document-validation.test.ts
  • tests/supabase-server.test.ts
  • tests/ui-smoke.spec.ts
  • tests/ui-universal-search.spec.ts
  • vitest.config.mts

Comment on lines +1089 to +1129
{filter.isFiltering ? (
<>
<div className="flex items-center justify-between gap-3">
<div className="flex items-center gap-2">
<LayoutDashboard className="h-4 w-4 text-[color:var(--clinical-accent)]" aria-hidden="true" />
<h2 className="text-base font-extrabold text-[color:var(--text-heading)]">Results</h2>
</div>
<p
aria-live="polite"
className="nums inline-flex min-h-8 items-center rounded-md border border-[color:var(--border)] bg-[color:var(--surface-subtle)] px-2.5 text-xs font-bold text-[color:var(--text-muted)]"
>
Showing {filter.filtered.length} of {tools.length}
</p>
</div>
{filter.filtered.length > 0 ? (
<div className="grid gap-3 sm:grid-cols-2">
{filter.filtered.map((tool) => (
<ToolCard key={tool.id} tool={tool} suggested={tool.id === suggestedId} />
))}
</div>
) : (
<AllToolsEmptyState query={filter.query} onClear={filter.reset} />
)}
</>
) : (
<>
<div className="flex items-center gap-2">
<LayoutDashboard className="h-4 w-4 text-[color:var(--clinical-accent)]" aria-hidden="true" />
<h2 className="text-base font-extrabold text-[color:var(--text-heading)]">Launcher overview</h2>
</div>
<p className="max-w-2xl text-sm font-medium leading-5 text-[color:var(--text-muted)]">
Filters sit beside the overview, while the full-width All tools view below carries the main browsing
weight.
</p>
<div className="grid gap-3 sm:grid-cols-2">
{["clinical-kb-search", suggestedId, "medication-prescribing", "favourites"].map((id) => (
<ToolCard key={id} tool={toolById(id)} suggested={id === suggestedId} />
))}
</div>
</>
)}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n "function ToolCard" -A 40 src/components/tools-page-mockups/tools-page-mockup-page.tsx
rg -n "function WideToolTile" -A 40 src/components/tools-page-mockups/tools-page-mockup-page.tsx

Repository: BigSimmo/Database

Length of output: 3918


🏁 Script executed:

#!/bin/bash
sed -n '980,1185p' src/components/tools-page-mockups/tools-page-mockup-page.tsx

Repository: BigSimmo/Database

Length of output: 8878


🏁 Script executed:

#!/bin/bash
sed -n '1030,1165p' src/components/tools-page-mockups/tools-page-mockup-page.tsx

Repository: BigSimmo/Database

Length of output: 6495


🏁 Script executed:

#!/bin/bash
rg -n "selectedToolId|selectedTool|setSelectedToolId|onSelectTool|WideAllToolsSection|ToolCard|SplitPaneMockup" src/components/tools-page-mockups/tools-page-mockup-page.tsx

Repository: BigSimmo/Database

Length of output: 2539


Filtering in SplitPaneMockup drops the preview-selection wiring The filtered-results branch renders plain ToolCard links, while WideAllToolsSection is the only list here that accepts selectedToolId/onSelectTool. In search mode, clicking a result won’t update the phone preview, so the “click any tool to preview it” interaction is unavailable until filtering is cleared. Consider threading the selection props through the filtered grid or reusing the selection-aware tile component.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/tools-page-mockups/tools-page-mockup-page.tsx` around lines
1089 - 1129, Thread the preview-selection wiring into the filtered-results
branch of SplitPaneMockup: pass selectedToolId and onSelectTool to each filtered
tool tile, or reuse the selection-aware component used by WideAllToolsSection,
instead of rendering plain ToolCard links. Ensure clicking a filtered result
updates the phone preview while preserving navigation behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant