-
Notifications
You must be signed in to change notification settings - Fork 0
fix: finalize design audit regression hardening #806
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
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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 |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ const appDir = path.join(process.cwd(), "src", "app"); | |
| const siteMapPath = path.join(process.cwd(), "docs", "site-map.md"); | ||
| const medicationSlugs = ["acamprosate"] as const; | ||
|
|
||
| type RouteKind = "page" | "api"; | ||
| type RouteKind = "page" | "handler"; | ||
|
|
||
| type DiscoveredRoute = { | ||
| route: string; | ||
|
|
@@ -31,14 +31,23 @@ type RedirectRoute = { | |
|
|
||
| type SiteMapData = { | ||
| pageRoutes: DiscoveredRoute[]; | ||
| publicRouteHandlers: DiscoveredRoute[]; | ||
| apiRoutes: DiscoveredRoute[]; | ||
| appRouteHandlers: DiscoveredRoute[]; | ||
| redirects: RedirectRoute[]; | ||
| nonRoutedMockupArtifacts: string[]; | ||
| }; | ||
|
|
||
| const productRouteHandlerPaths = new Set(["/applications", "/differentials/presentations", "/medications"]); | ||
|
|
||
| const documentedRedirectTargets: Record<string, string> = { | ||
| "/applications": "/tools", | ||
| "/differentials/presentations": "/differentials/presentations/[workflow-slug]", | ||
| "/medications": "/?mode=prescribing", | ||
| }; | ||
|
|
||
| const routeDescriptions: Record<string, string> = { | ||
| "/": "Main Clinical KB shell.", | ||
| "/applications": "Legacy application launcher redirect to Tools.", | ||
| "/differentials": "Differentials home and search surface.", | ||
| "/differentials/diagnoses": "Diagnosis stream.", | ||
| "/differentials/diagnoses/[slug]": "Differential diagnosis detail.", | ||
|
|
@@ -72,6 +81,11 @@ const routeDescriptions: Record<string, string> = { | |
| "/specifiers/map": "Psychiatric specifier family map.", | ||
| }; | ||
|
|
||
| const publicRouteHandlerDescriptions: Record<string, string> = { | ||
| "/auth/callback": "Authentication callback handler.", | ||
| "/icons/[variant]": "Dynamically generated application icon handler.", | ||
| }; | ||
|
|
||
| const apiDescriptions: Record<string, string> = { | ||
| "/api/answer": "Generate answer response.", | ||
| "/api/answer/stream": "Streaming answer response.", | ||
|
|
@@ -128,8 +142,16 @@ function routeSegment(segment: string) { | |
| return segment; | ||
| } | ||
|
|
||
| function isApiRoute(route: string) { | ||
| return route === "/api" || route.startsWith("/api/"); | ||
| } | ||
|
|
||
| function fileToRoute(filePath: string, kind: RouteKind) { | ||
| const suffix = kind === "page" ? "page.tsx" : "route.ts"; | ||
| const suffix = path.basename(filePath); | ||
| const expectedSuffixes = kind === "page" ? ["page.tsx"] : ["route.ts", "route.tsx"]; | ||
| if (!expectedSuffixes.includes(suffix)) { | ||
| throw new Error(`Unsupported ${kind} route file: ${filePath}`); | ||
| } | ||
| const relative = toPosixPath(path.relative(appDir, filePath)); | ||
| const withoutFile = relative.slice(0, -suffix.length).replace(/\/$/, ""); | ||
| const segments = withoutFile.split("/").filter(Boolean).map(routeSegment).filter(Boolean); | ||
|
|
@@ -150,43 +172,22 @@ function collectFiles(root: string, targetFileName: string): string[] { | |
| } | ||
|
|
||
| function discoverRoutes(kind: RouteKind): DiscoveredRoute[] { | ||
| const targetFile = kind === "page" ? "page.tsx" : "route.ts"; | ||
| return collectFiles(appDir, targetFile) | ||
| const targetFiles = kind === "page" ? ["page.tsx"] : ["route.ts", "route.tsx"]; | ||
| return targetFiles | ||
| .flatMap((targetFile) => collectFiles(appDir, targetFile)) | ||
| .map((file) => ({ | ||
| route: fileToRoute(file, kind), | ||
| file: toPosixPath(path.relative(process.cwd(), file)), | ||
| })) | ||
| .sort((left, right) => left.route.localeCompare(right.route) || left.file.localeCompare(right.file)); | ||
| } | ||
|
|
||
| function isApiRoute(route: string) { | ||
| return route === "/api" || route.startsWith("/api/"); | ||
| } | ||
|
|
||
| function extractRedirectTarget(source: string): string | null { | ||
| const pageRedirect = source.match(/\bredirect\(\s*["']([^"']+)["']\s*\)/)?.[1]; | ||
| if (pageRedirect) return pageRedirect; | ||
|
|
||
| const urlRedirect = source.match(/NextResponse\.redirect\(\s*new URL\(\s*["']([^"']+)["']/)?.[1]; | ||
| if (urlRedirect) return urlRedirect; | ||
|
|
||
| const pathnameRedirect = source.match(/\.pathname\s*=\s*["']([^"']+)["']/)?.[1]; | ||
| if (pathnameRedirect) return pathnameRedirect; | ||
|
|
||
| // Template-literal destination builders with a stable route prefix. | ||
| const presentationsRedirect = source.match(/`(\/differentials\/presentations\/)\$\{/)?.[1]; | ||
| if (presentationsRedirect && source.includes("NextResponse.redirect")) { | ||
| return `${presentationsRedirect}[slug]`; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| function discoverRedirects(routes: DiscoveredRoute[]): RedirectRoute[] { | ||
| return routes | ||
| .map((route) => { | ||
| const source = readFileSync(path.join(process.cwd(), route.file), "utf8"); | ||
| const target = extractRedirectTarget(source); | ||
| const target = | ||
| documentedRedirectTargets[route.route] ?? source.match(/\bredirect\(\s*["']([^"']+)["']\s*\)/)?.[1]; | ||
| return target ? { ...route, target } : null; | ||
| }) | ||
| .filter((value): value is RedirectRoute => Boolean(value)) | ||
|
|
@@ -203,20 +204,13 @@ function discoverNonRoutedMockupArtifacts() { | |
|
|
||
| export function collectSiteMapData(): SiteMapData { | ||
| const pageRoutes = discoverRoutes("page"); | ||
| const routeHandlers = discoverRoutes("api"); | ||
| const apiRoutes = routeHandlers.filter((route) => isApiRoute(route.route)); | ||
| const nonApiHandlers = routeHandlers.filter((route) => !isApiRoute(route.route)); | ||
| const redirects = [...discoverRedirects(pageRoutes), ...discoverRedirects(nonApiHandlers)].sort( | ||
| (left, right) => left.route.localeCompare(right.route) || left.file.localeCompare(right.file), | ||
| ); | ||
| const redirectRoutes = new Set(redirects.map((redirect) => redirect.route)); | ||
| const appRouteHandlers = nonApiHandlers.filter((route) => !redirectRoutes.has(route.route)); | ||
|
|
||
| const routeHandlers = discoverRoutes("handler"); | ||
| const publicRouteHandlers = routeHandlers.filter((route) => !isApiRoute(route.route)); | ||
| return { | ||
| pageRoutes, | ||
| apiRoutes, | ||
| appRouteHandlers, | ||
| redirects, | ||
| publicRouteHandlers, | ||
| apiRoutes: routeHandlers.filter((route) => isApiRoute(route.route)), | ||
| redirects: discoverRedirects([...pageRoutes, ...publicRouteHandlers]), | ||
| nonRoutedMockupArtifacts: discoverNonRoutedMockupArtifacts(), | ||
| }; | ||
| } | ||
|
|
@@ -397,14 +391,17 @@ function renderSiteMapRaw(data = collectSiteMapData()) { | |
| ].includes(route.route), | ||
| ); | ||
| const mockupRoutes = data.pageRoutes.filter((route) => route.route.startsWith("/mockups")); | ||
| const publicUtilityRouteHandlers = data.publicRouteHandlers.filter( | ||
| (route) => !productRouteHandlerPaths.has(route.route), | ||
| ); | ||
|
|
||
| const lines = [ | ||
| "# Clinical KB Site Map", | ||
| "", | ||
| "This file is generated by `npm run sitemap:update`. Run `npm run sitemap:check` to verify it is current.", | ||
| "", | ||
| ...section( | ||
| "Main product pages", | ||
| "Main product routes", | ||
| productRoutes.map((route) => routeLine(route, routeDescriptions)), | ||
|
Comment on lines
+394
to
405
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Restore product redirect handlers to “Main product routes.” The renderer drops product handlers from that section, and the regression test incorrectly codifies their absence.
📍 Affects 2 files
🤖 Prompt for AI Agents |
||
| ), | ||
| ...section("Mode/query routes", renderModeRoutes()), | ||
|
|
@@ -481,23 +478,21 @@ function renderSiteMapRaw(data = collectSiteMapData()) { | |
| ] | ||
| : []), | ||
| ]), | ||
| ...section( | ||
| "Public utility route handlers", | ||
| publicUtilityRouteHandlers.map((route) => routeLine(route, publicRouteHandlerDescriptions)), | ||
| ), | ||
| ...section( | ||
| "API routes", | ||
| data.apiRoutes.map((route) => routeLine(route, apiDescriptions)), | ||
| ), | ||
| ...(data.appRouteHandlers.length | ||
| ? section( | ||
| "App route handlers", | ||
| data.appRouteHandlers.map((route) => routeLine(route, routeDescriptions)), | ||
| ) | ||
| : []), | ||
| ...section( | ||
| "Redirects", | ||
| data.redirects.length | ||
| ? data.redirects.map((redirect) => | ||
| bullet(redirect.route, `Redirects to \`${redirect.target}\`. Source: \`${redirect.file}\`.`), | ||
| ) | ||
| : ["- No redirects discovered."], | ||
| : ["- No page-level redirects discovered."], | ||
| ), | ||
| ...section("Known caveats and stale-path flags", [ | ||
| "- `/mockups/*` prototype routes are development-only; production returns 404 and `robots.txt` disallows indexing.", | ||
|
|
||
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
Oops, something went wrong.
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.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: BigSimmo/Database
Length of output: 668
🏁 Script executed:
Repository: BigSimmo/Database
Length of output: 4025
🏁 Script executed:
Repository: BigSimmo/Database
Length of output: 26293
🏁 Script executed:
Repository: BigSimmo/Database
Length of output: 4831
Move
reducedMotionintocontextOptions. Playwright’suseschema exposes this setting undercontextOptions; the top-levelreducedMotionentry here doesn’t match the config type and blocks config type-checking.🧰 Tools
🪛 GitHub Check: Static PR checks
[failure] 58-58:
No overload matches this call.
🤖 Prompt for AI Agents
Source: Linters/SAST tools