Lint: the new route inventory, its tests and the touched tests
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d4fe3bf4ba
commit
8f443c9214
@@ -17,9 +17,6 @@ export { AUDIT_RULE_MAP, parseToolOutput } from '../modules/doctor/rules/tooling
|
||||
export { applySettings, AUDIT_SKIP_RULES, doctorRules, globToRegExp, runDeepProbe, runDoctor } from '../modules/doctor/run.js'
|
||||
export type { RunDoctorOptions } from '../modules/doctor/run.js'
|
||||
export { buildDoctorEndpoint, collectDoctorStatus } from '../modules/doctor/status.js'
|
||||
// routes:check — the site's public routes against the judged snapshot (docs/security.md "Routes nobody has judged")
|
||||
export { runRouteCheck } from '../modules/security/routeCheck.js'
|
||||
export type { RunRouteCheckOptions } from '../modules/security/routeCheck.js'
|
||||
export type { DoctorEndpointOptions } from '../modules/doctor/status.js'
|
||||
export type {
|
||||
DoctorConfig,
|
||||
@@ -32,3 +29,6 @@ export type {
|
||||
DoctorStatus,
|
||||
RuleFinding,
|
||||
} from '../modules/doctor/types.js'
|
||||
// routes:check — the site's public routes against the judged snapshot (docs/security.md "Routes nobody has judged")
|
||||
export { runRouteCheck } from '../modules/security/routeCheck.js'
|
||||
export type { RunRouteCheckOptions } from '../modules/security/routeCheck.js'
|
||||
|
||||
@@ -65,10 +65,10 @@ export const securityRules: DoctorRule[] = [
|
||||
// first segment merely STARTS with those letters (/administracja, /apis): no locale redirect, and no CSP from the
|
||||
// proxy on a single-locale site (IAWL idea 36, fixed in the documented literal in 1.17.1).
|
||||
id: 'proxy-matcher',
|
||||
check: async (ctx) => {
|
||||
check: (ctx) => {
|
||||
const file = `${ctx.src}proxy.ts`
|
||||
const code = stripComments(ctx.read(file))
|
||||
const loose = [...code.matchAll(/\(\?!((?:[\w-]+\|)*[\w-]+)\|/g)].map((m) => m[1]!.split('|')).find((names) => names.some((n) => ['_next', 'admin', 'api'].includes(n)))
|
||||
const loose = [...code.matchAll(/\(\?!((?:[\w-]+\|)*[\w-]+)\|/g)].map((m) => m[1].split('|')).find((names) => names.some((n) => ['_next', 'admin', 'api'].includes(n)))
|
||||
if (!loose) {return []}
|
||||
return [{
|
||||
file,
|
||||
|
||||
@@ -59,6 +59,7 @@ function walk(dir: string): string[] {
|
||||
*/
|
||||
export async function runRouteCheck(options: RunRouteCheckOptions): Promise<number> {
|
||||
const cwd = options.cwd ?? process.cwd()
|
||||
// eslint-disable-next-line no-console -- a command-line check prints its report
|
||||
const log = options.log ?? ((line: string) => console.log(line))
|
||||
const appDir = join(cwd, options.appDir ?? 'src/app')
|
||||
const snapshotFile = join(cwd, options.snapshot ?? 'e2e/routes.snapshot.json')
|
||||
|
||||
@@ -80,7 +80,7 @@ export function listNextRouteFiles(
|
||||
for (const file of files) {
|
||||
const parts = file.split('/').filter((p) => p && !/^\(.*\)$/.test(p))
|
||||
const name = parts.pop() ?? ''
|
||||
const base = name.replace(/\.(?:[cm]?[jt]sx?)$/, '')
|
||||
const base = name.replace(/\.[cm]?[jt]sx?$/, '')
|
||||
const path = `/${parts.join('/')}`
|
||||
if (base === 'route') {
|
||||
const code = read(file)
|
||||
@@ -99,12 +99,12 @@ export function listNextRouteFiles(
|
||||
export type RouteSnapshot = Record<string, string>
|
||||
|
||||
export type RouteSnapshotDiff = {
|
||||
/** Routes the snapshot has and the config no longer opens (not a failure; `--update` drops them). */
|
||||
gone: string[]
|
||||
/** Entries whose reason is empty or still says TODO. */
|
||||
unexplained: string[]
|
||||
/** Routes the config has and the snapshot does not. */
|
||||
unjudged: string[]
|
||||
/** Routes the snapshot has and the config no longer opens (not a failure; `--update` drops them). */
|
||||
gone: string[]
|
||||
}
|
||||
|
||||
export function compareRouteSnapshot(current: string[], snapshot: RouteSnapshot): RouteSnapshotDiff {
|
||||
@@ -112,7 +112,7 @@ export function compareRouteSnapshot(current: string[], snapshot: RouteSnapshot)
|
||||
const now = new Set(current)
|
||||
return {
|
||||
gone: [...judged].filter((id) => !now.has(id)).sort(),
|
||||
unexplained: [...judged].filter((id) => now.has(id) && (!snapshot[id]?.trim() || /^TODO\b/i.test(snapshot[id]!.trim()))).sort(),
|
||||
unexplained: [...judged].filter((id) => now.has(id) && (!snapshot[id]?.trim() || /^TODO\b/i.test(snapshot[id].trim()))).sort(),
|
||||
unjudged: current.filter((id) => !judged.has(id)),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user