diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7a82f3c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,55 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + +permissions: + contents: read + +jobs: + backend: + name: Backend (typecheck, test, build) + runs-on: ubuntu-latest + defaults: + run: + working-directory: apps/backend + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 24 + cache: npm + cache-dependency-path: apps/backend/package-lock.json + - run: npm ci + - run: npm run typecheck + - run: npm test + - run: npm run build + + frontend: + name: Frontend (lint, typecheck, build) + runs-on: ubuntu-latest + defaults: + run: + working-directory: apps/frontend + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 24 + cache: npm + cache-dependency-path: apps/frontend/package-lock.json + - run: npm ci + - run: npm run lint + - run: npm run build + + schema: + name: Report schema in sync + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 24 + - run: node scripts/sync-report-schema.mjs --check diff --git a/.gitignore b/.gitignore index 1677fde..3493905 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,6 @@ tmp/* !tmp/.gitkeep demo -logs \ No newline at end of file +logs +# Evaluation runs (apps/backend/scripts/eval.ts) +eval-results/ diff --git a/README.md b/README.md index cba4879..b018f42 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ RepoInsight-AI evaluates: - Design Decisions - Resume Readiness -Every AI response is validated before generating the final report. +Every AI response is validated against a schema, and every file and line the model cites is checked against the code it was shown. Invented references are removed, and valid ones include the real code snippet. --- @@ -284,6 +284,29 @@ npm run dev --- +# Testing + +```bash +cd apps/backend +npm run typecheck # source, tests and scripts +npm test # Vitest: extraction safety, filtering, citations, analyzers, jobs, pipeline +``` + +GitHub Actions runs the backend checks, the frontend lint and build, and the report schema sync check on every push and pull request. + +## Measuring Consistency + +The evaluation script analyzes the same repositories several times with the real Gemini API and reports how much scores and citations vary: + +```bash +cd apps/backend +npm run eval -- --runs 3 path/to/repo1.zip path/to/repo2.zip +``` + +Results are saved to `apps/backend/eval-results/`. Each run is a paid Gemini call. + +--- + # Environment Variables ## Backend @@ -301,6 +324,9 @@ MAX_CONCURRENT_JOBS=2 # Optional: prompt size cap; files are ranked by importance and added until it is reached MAX_PROMPT_TOKENS=150000 +# Optional: sampling temperature 0-2 (unset = model default) +GEMINI_TEMPERATURE=0.2 + # Optional: save full prompts and model responses (they contain the # uploaded source code) to the log folder. Keep false in production. SAVE_DEBUG_ARTIFACTS=false diff --git a/apps/backend/.env.example b/apps/backend/.env.example index c05cc0c..7501188 100644 --- a/apps/backend/.env.example +++ b/apps/backend/.env.example @@ -8,6 +8,9 @@ MAX_CONCURRENT_JOBS=2 # Prompt size cap. Files are ranked by importance and added until it is reached. MAX_PROMPT_TOKENS=150000 +# Optional sampling temperature (0-2). Lower = more consistent repeat reviews. +# GEMINI_TEMPERATURE=0.2 + # Write full prompts/responses (contain uploaded source code) to the log folder. # Useful locally; keep false in production. SAVE_DEBUG_ARTIFACTS=false diff --git a/apps/backend/package-lock.json b/apps/backend/package-lock.json index 80e36b4..4e9d9fe 100644 --- a/apps/backend/package-lock.json +++ b/apps/backend/package-lock.json @@ -12,6 +12,7 @@ "dotenv": "^17.4.2", "express": "^5.2.1", "multer": "^2.2.0", + "typescript": "^6.0.3", "yauzl": "^2.10.0", "zod": "^4.4.3" }, @@ -19,9 +20,48 @@ "@types/cors": "^2.8.19", "@types/multer": "^2.1.0", "@types/yauzl": "^2.10.3", + "@types/yazl": "^3.3.1", "tsx": "^4.22.4", - "typescript": "^6.0.3", - "typescript-eslint": "^8.62.1" + "typescript-eslint": "^8.62.1", + "vitest": "5.1.0", + "yazl": "^3.3.1" + } + }, + "node_modules/@emnapi/core": { + "version": "2.0.0-beta.2", + "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-2.0.0-beta.2.tgz", + "integrity": "sha512-MzCVoWtcg4Pm2B3je5mMvYMvj3MmBKw+fU7vbsJc9/iT8ip6/eYIHo/Dsm/mr+wsHB6SEyJDuxB09Yy6r/8+4A==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "dependencies": { + "@emnapi/wasi-threads": "2.2.0", + "tslib": "^2.4.0" + } + }, + "node_modules/@emnapi/runtime": { + "version": "2.0.0-beta.2", + "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-2.0.0-beta.2.tgz", + "integrity": "sha512-JcrSPzPvZuNZvJqPTF9Fw25LbOJ8avzFVlaf2grmH4Cku0oGP47tRgqPZadcfj3YoZMHkFVnCYFbQM8I+i5QEw==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@emnapi/wasi-threads": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-2.2.0.tgz", + "integrity": "sha512-JP7OYH38Q7+pyTAe14raZHLQIK7BDKbdwji+Xi3pcd/6QkJYQH3SX4wu6EplGrGJWRepoNzedfm0G3B9Z4e9Rw==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "dependencies": { + "tslib": "^2.4.0" } }, "node_modules/@esbuild/aix-ppc64": { @@ -673,6 +713,68 @@ "url": "https://github.com/sponsors/nzakas" } }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.3.tgz", + "integrity": "sha512-lhTtjtoEArWBjismtfS761S9Hlyn+nIZqOZVYoZ1Xn82PMNMVnk+jj/NhC4fAXGTs7ydONcJiR5vyQBTMDu27g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz", + "integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.31", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.31.tgz", + "integrity": "sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/resolve-uri": "^3.1.0", + "@jridgewell/sourcemap-codec": "^1.4.14" + } + }, + "node_modules/@napi-rs/wasm-runtime": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.2.6.tgz", + "integrity": "sha512-mRyDmEw9/fCDXCGfL1sbgIw/GUK0PVxRW4YwgPN61F3LQ+fSyoBFarJVzgGyhF6kRzEQZ0FejDqm4WLXSeqQmw==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "dependencies": { + "@tybys/wasm-util": "^0.10.3" + }, + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=23.5.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + }, + "peerDependencies": { + "@emnapi/core": "^1.7.1 || 2.0.0-beta.2", + "@emnapi/runtime": "^1.7.1 || 2.0.0-beta.2" + } + }, + "node_modules/@oxc-project/types": { + "version": "0.156.0", + "resolved": "https://registry.npmjs.org/@oxc-project/types/-/types-0.156.0.tgz", + "integrity": "sha512-1Duyg48TdJNdyhEB8Xn1L36bT9Pv6GUtlKjHxOys8xkaF/rQq3XJE+bAurSK/AgIz5mGFsb77cn9Pb20+WCScw==", + "dev": true, + "license": "MIT", + "peer": true, + "funding": { + "url": "https://github.com/sponsors/oxc-project" + } + }, "node_modules/@protobufjs/aspromise": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", @@ -724,11 +826,339 @@ "integrity": "sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==", "license": "BSD-3-Clause" }, - "node_modules/@protobufjs/utf8": { + "node_modules/@protobufjs/utf8": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.1.tgz", + "integrity": "sha512-oOAWABowe8EAbMyWKM0tYDKi8Yaox52D+HWZhAIJqQXbqe0xI/GV7FhLWqlEKreMkfDjshR5FKgi3mnle0h6Eg==", + "license": "BSD-3-Clause" + }, + "node_modules/@rolldown/binding-android-arm-eabi": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.2.19.tgz", + "integrity": "sha512-e+Ebe0WT+9tbXmNKPIiC8YrWAHYwug3m6i4p3rZGGulfZri1jtI4HslT+OZnFf/OIHowWF71DTlHwXBP2SiA7A==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-android-arm64": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.2.19.tgz", + "integrity": "sha512-hOombrTJ+szt2ciEzS7oCA78lMPBgF5UMQWCJIyNfnrI7GLl8HYoFqCnpL2gcPOaXMqryGCU5ExdQKyDDcC+yA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-darwin-arm64": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-arm64/-/binding-darwin-arm64-1.2.19.tgz", + "integrity": "sha512-XoMA2pwCKGTQzUjPgtRwkedH4WmXhdIPKT6l6oOxd1PUbNodGI6DcBekgN7EC//+x3pfBYX/qL1gNmZAqivw5g==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-darwin-x64": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-darwin-x64/-/binding-darwin-x64-1.2.19.tgz", + "integrity": "sha512-zo8EsSSwMZCY/e+fRnGaX02YGgvJD0yvhNi/9hpGPA2MJ9ZF8dPCw75UGfpI6OpQ/myR/dIYmogRvqiZD0TrXg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-freebsd-x64": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-freebsd-x64/-/binding-freebsd-x64-1.2.19.tgz", + "integrity": "sha512-O8ISAOfI1nj7AuBPd30FSF47z7f7lzlk5poQVGgiikvQuGEBFYvW8ki+UEnT+YJPnNGjQzn304klt4O9FUE7mA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm-gnueabihf": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm-gnueabihf/-/binding-linux-arm-gnueabihf-1.2.19.tgz", + "integrity": "sha512-/lYCba5NO0yq4S0jGMH8QTBtkvQxoXjoQWzF5BcWp9MjB9jxVRD1GQDNofkVjcOj30DWyhLIN/4Oe60JKzaONw==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm64-gnu": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-gnu/-/binding-linux-arm64-gnu-1.2.19.tgz", + "integrity": "sha512-pm/apFMBnSbFb3O6nG5pHO1iqHhZrjGDFEjSm+ot9J17XXPvH9L90y5h+jgfHCE+Qdlsvy8qKEcU4VKxgjD+vA==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-arm64-musl": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-arm64-musl/-/binding-linux-arm64-musl-1.2.19.tgz", + "integrity": "sha512-K1SmQp3FFichn8oqrNIwvFoZ5wcvjC7goBzpaMNvLf9FZc+QB/QvLmnpJZgAAGHiD980tP8FZZnXk2K94rvlxg==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-ppc64-gnu": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-ppc64-gnu/-/binding-linux-ppc64-gnu-1.2.19.tgz", + "integrity": "sha512-I0xwD57jP/3A7+5UPZin2w8Y7XHEmEM5zqpYZOcQ45MlNW6tUJUziymV3yRr7rL4vwyfEcRsRksC4a7Kc08p5Q==", + "cpu": [ + "ppc64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-s390x-gnu": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-s390x-gnu/-/binding-linux-s390x-gnu-1.2.19.tgz", + "integrity": "sha512-BrtEHT24SNXj9HiXqy+s/kXiSiQGt6EKCPUlRirAoIioVxKGnbXBUEkbZASAei7iZJB0/Ynm+0JP00Ipx7AnSw==", + "cpu": [ + "s390x" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-x64-gnu": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-gnu/-/binding-linux-x64-gnu-1.2.19.tgz", + "integrity": "sha512-rm75/9DkHKeU2WnA8w4X94WGYgLlDCFCfkQC+4bguVJmC/jvDRv2B+2wLOYhyE0fVuv7//Ckk39OoOufyCu76Q==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-linux-x64-musl": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-linux-x64-musl/-/binding-linux-x64-musl-1.2.19.tgz", + "integrity": "sha512-irh/4+iYFM4GAzpluDErgjz89bj6NDtqqMAG/6O1LG38Ed3NpyebzCpcVNkFW8uhy+/3/BocUvnXDR33CXWe9A==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-openharmony-arm64": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-openharmony-arm64/-/binding-openharmony-arm64-1.2.19.tgz", + "integrity": "sha512-+KWTWNoPt+CfSq94CiceWu3yPE+QzkaG+phPyz9G60tmZLwfQkcA4AeksafzvJAw4pvg1mcd5a1TkUqVv0s4JA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-wasm32-wasi": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-wasm32-wasi/-/binding-wasm32-wasi-1.2.19.tgz", + "integrity": "sha512-7EH+skOsl5qpWnK0vzamgJFhOv1cwxQpsxm8tI883K9fur5c27p8q87fzEO6BbBPabA2/+s/zR63/pLc137iOg==", + "cpu": [ + "wasm32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "dependencies": { + "@emnapi/core": "2.0.0-beta.2", + "@emnapi/runtime": "2.0.0-beta.2", + "@napi-rs/wasm-runtime": "1.2.6" + }, + "engines": { + "node": "^20.19.0 || ^22.13.0 || >=23.5.0" + } + }, + "node_modules/@rolldown/binding-win32-arm64-msvc": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-arm64-msvc/-/binding-win32-arm64-msvc-1.2.19.tgz", + "integrity": "sha512-3Q1Yg1Q7tEvBWoZf5rFvG/GKZQPgwfru+p4wBajDfJFBs0SHCpL++dfTjW9gyAKd1T7ZpIYvdaUax7Pa/IhFVQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/binding-win32-x64-msvc": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/@rolldown/binding-win32-x64-msvc/-/binding-win32-x64-msvc-1.2.19.tgz", + "integrity": "sha512-y/sqRRc6d7hECzOFc5n3LSeqctmIp9mMjY1Kq4s14uLPd/LZ4z7i1zrW6fMtp2mPeuQIC4e6ULMcwQzMomqQag==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "peer": true, + "engines": { + "node": "^20.19.0 || >=22.12.0" + } + }, + "node_modules/@rolldown/pluginutils": { "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.1.tgz", - "integrity": "sha512-oOAWABowe8EAbMyWKM0tYDKi8Yaox52D+HWZhAIJqQXbqe0xI/GV7FhLWqlEKreMkfDjshR5FKgi3mnle0h6Eg==", - "license": "BSD-3-Clause" + "resolved": "https://registry.npmjs.org/@rolldown/pluginutils/-/pluginutils-1.1.1.tgz", + "integrity": "sha512-glFIJDvLNDtJhT9qrMFWLPbvS+skxgt4L0K8Ei2YtnhPysAJnsI7nyxSJxKj4ADeKX0OLjC4ntRkwpLOoS3rwA==", + "dev": true, + "license": "MIT", + "peer": true + }, + "node_modules/@tybys/wasm-util": { + "version": "0.10.5", + "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.5.tgz", + "integrity": "sha512-dOGOPxlaNV+G046mZzN+9C0dAcQZeSKcXiVaM0TYy/LM4ttTmgSBDxYfovcYI8Em3+eAbiAYpvWLOv8+ZVRJKA==", + "dev": true, + "license": "MIT", + "optional": true, + "peer": true, + "dependencies": { + "tslib": "^2.4.0" + } }, "node_modules/@types/body-parser": { "version": "1.19.6", @@ -741,6 +1171,17 @@ "@types/node": "*" } }, + "node_modules/@types/chai": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", + "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/deep-eql": "*", + "assertion-error": "^2.0.1" + } + }, "node_modules/@types/connect": { "version": "3.4.38", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", @@ -761,6 +1202,13 @@ "@types/node": "*" } }, + "node_modules/@types/deep-eql": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz", + "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/esrecurse": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/@types/esrecurse/-/esrecurse-4.3.1.tgz", @@ -774,8 +1222,7 @@ "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.9.tgz", "integrity": "sha512-GhdPgy1el4/ImP05X05Uw4cw2/M93BCUmnEvWZNStlCzEKME4Fkk+YpoA5OiHNQmoS7Cafb8Xa3Pya8m1Qrzeg==", "dev": true, - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/@types/express": { "version": "5.0.6", @@ -887,6 +1334,16 @@ "@types/node": "*" } }, + "node_modules/@types/yazl": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/@types/yazl/-/yazl-3.3.1.tgz", + "integrity": "sha512-DIWfCKpsTp6hE5BDBHV3+fIL/bLUF9Bv13iDrWnMlmhQpH67buNvI291ZauQ1xcccxK3FqQ9honnXpq4R8NMuQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "8.62.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.62.1.tgz", @@ -1117,6 +1574,44 @@ "url": "https://opencollective.com/typescript-eslint" } }, + "node_modules/@vitest/mocker": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-5.1.0.tgz", + "integrity": "sha512-5umB9/jlWcqVS6fsrFmv5Gdnpu6wAUio/lEOwAmvB7v+lFo/IW2B9FhAD0p19GCULTgMzLCdUmuCDCnAzWgppQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/trace-mapping": "0.3.31", + "@vitest/spy": "5.1.0", + "estree-walker": "^3.0.3", + "magic-string": "^1.4.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "msw": "^2.4.9 || ^3.0.0", + "vite": "^6.0.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "msw": { + "optional": true + }, + "vite": { + "optional": true + } + } + }, + "node_modules/@vitest/spy": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-5.1.0.tgz", + "integrity": "sha512-2DPO5OMHWKrBngC+fCmTQqemNF0gidRhp3lxbBmRhW+M1XJrfgPpqNqWVevXtn2f2ufD5ZaR1B6B641aAlcX5A==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://opencollective.com/vitest" + } + }, "node_modules/accepts": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz", @@ -1213,6 +1708,16 @@ "integrity": "sha512-klpgFSWLW1ZEs8svjfb7g4qWY0YS5imI82dTg+QahUvJ8YqAY0P10Uk8tTyh9ZGuYEZEMaeJYCF5BFuX552hsw==", "license": "MIT" }, + "node_modules/assertion-error": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", + "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + } + }, "node_modules/balanced-match": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", @@ -1424,6 +1929,16 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/chai": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/chai/-/chai-6.3.0.tgz", + "integrity": "sha512-XWAtwJ6OHO+tj0EKCs0Y2UamnyOxseZWltU4x2U2wh8g4AigdjwvtUjvLP2tqkA/avxHEtzxNaqGq/YGNwckKg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, "node_modules/concat-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-2.0.0.tgz", @@ -1555,6 +2070,17 @@ "node": ">= 0.8" } }, + "node_modules/detect-libc": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz", + "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==", + "dev": true, + "license": "Apache-2.0", + "peer": true, + "engines": { + "node": ">=8" + } + }, "node_modules/dotenv": { "version": "17.4.2", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.4.2.tgz", @@ -1623,6 +2149,13 @@ "node": ">= 0.4" } }, + "node_modules/es-module-lexer": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-2.3.2.tgz", + "integrity": "sha512-poHGpORABojJJucnV9KbOavETW8lBVnphkW77ER5/BQ5Fz7oXSoCNek7IH3vR5nRjdsEz926ibFYX8KtLQmdyw==", + "dev": true, + "license": "MIT" + }, "node_modules/es-object-atoms": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz", @@ -1848,6 +2381,16 @@ "node": ">=4.0" } }, + "node_modules/estree-walker": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", + "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.0" + } + }, "node_modules/esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", @@ -1868,6 +2411,16 @@ "node": ">= 0.6" } }, + "node_modules/expect-type": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.4.0.tgz", + "integrity": "sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/express": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/express/-/express-5.2.1.tgz", @@ -2496,40 +3049,325 @@ "safe-buffer": "^5.0.1" } }, - "node_modules/jws": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/jws/-/jws-4.0.1.tgz", - "integrity": "sha512-EKI/M/yqPncGUUh44xz0PxSidXFr/+r0pA70+gIYhjv+et7yxM+s29Y+VGDkovRofQem0fs7Uvf4+YmAdyRduA==", - "license": "MIT", - "dependencies": { - "jwa": "^2.0.1", - "safe-buffer": "^5.0.1" + "node_modules/jws": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/jws/-/jws-4.0.1.tgz", + "integrity": "sha512-EKI/M/yqPncGUUh44xz0PxSidXFr/+r0pA70+gIYhjv+et7yxM+s29Y+VGDkovRofQem0fs7Uvf4+YmAdyRduA==", + "license": "MIT", + "dependencies": { + "jwa": "^2.0.1", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/keyv": { + "version": "4.5.4", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", + "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "json-buffer": "3.0.1" + } + }, + "node_modules/levn": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", + "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "prelude-ls": "^1.2.1", + "type-check": "~0.4.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/lightningcss": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.33.0.tgz", + "integrity": "sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA==", + "dev": true, + "license": "MPL-2.0", + "peer": true, + "dependencies": { + "detect-libc": "^2.0.3" + }, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + }, + "optionalDependencies": { + "lightningcss-android-arm64": "1.33.0", + "lightningcss-darwin-arm64": "1.33.0", + "lightningcss-darwin-x64": "1.33.0", + "lightningcss-freebsd-x64": "1.33.0", + "lightningcss-linux-arm-gnueabihf": "1.33.0", + "lightningcss-linux-arm64-gnu": "1.33.0", + "lightningcss-linux-arm64-musl": "1.33.0", + "lightningcss-linux-x64-gnu": "1.33.0", + "lightningcss-linux-x64-musl": "1.33.0", + "lightningcss-win32-arm64-msvc": "1.33.0", + "lightningcss-win32-x64-msvc": "1.33.0" + } + }, + "node_modules/lightningcss-android-arm64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-android-arm64/-/lightningcss-android-arm64-1.33.0.tgz", + "integrity": "sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "android" + ], + "peer": true, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-darwin-arm64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.33.0.tgz", + "integrity": "sha512-Sciaz8eenNTKn9b3t7+xr0ipTp9YxKQY4npwQ3mrRuL0BAVHBLyZxofhaKBAVtzmtRZ/zTyo0/to4B1uWG/Djg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "peer": true, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-darwin-x64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.33.0.tgz", + "integrity": "sha512-Z5UPAxzrjlWNNyGy6i65cJzzvgJ5D3T6wMvs+gWpY9d7qRhANrxqAp6LhxIgZhWEw18RfJTGcRxjuLIBr+m8XQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "darwin" + ], + "peer": true, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-freebsd-x64": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.33.0.tgz", + "integrity": "sha512-QQM/Ti/hQajJwCY+RiWuCZ9sdtI/XQk7nDK5vC8kkdwixezOlDgvDx7+RT+QjK6FcFT4MpsuoBnHIo/O3StRRg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "freebsd" + ], + "peer": true, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm-gnueabihf": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.33.0.tgz", + "integrity": "sha512-N7FVBe6iS24MlM6R/4RBTxGhQheZGs7tiQ9U32UtF75NzP5Q7xWPRqLBCKxlRQRk3rY1jCIPLzx7WzOhuUIRLQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm64-gnu": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.33.0.tgz", + "integrity": "sha512-j2v/itmy4HlNxlc6voKXYgBqNi0Ng2LShg4z7GufpEgs05P+2suBVyi9I6YHq5uoVFx9ETin3eCEhLVyXGQnKg==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-arm64-musl": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.33.0.tgz", + "integrity": "sha512-yiO5ROMuYQgXbC60yjZU5CYSFZGKXL0HFATXt9mHJn1+zW55oCtMI9NfcVhYLMFDL7gV7oBPon/EmMMGg2OvtQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-x64-gnu": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.33.0.tgz", + "integrity": "sha512-ar+Ju7LmcN0Jo4FpL4hpFybwNG9/3A/Br5KW2n2jyODg3MEZXaDYADdemoNS+BDNfMgKvylJLj4S5tyRActuAg==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "glibc" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" + } + }, + "node_modules/lightningcss-linux-x64-musl": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.33.0.tgz", + "integrity": "sha512-RYiYbkokw0trfKqqzfF55lginwEPrD3OJDfTuJzFs1MK6iFnDenaz1fqLLtX4ITG3OktJQXOeTaw1awrBAlZPw==", + "cpu": [ + "x64" + ], + "dev": true, + "libc": [ + "musl" + ], + "license": "MPL-2.0", + "optional": true, + "os": [ + "linux" + ], + "peer": true, + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" } }, - "node_modules/keyv": { - "version": "4.5.4", - "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", - "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==", + "node_modules/lightningcss-win32-arm64-msvc": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.33.0.tgz", + "integrity": "sha512-1K+MPfLSFVpphzpdbfkhlWk6wBrTObBzS2T6db10PNOZgR9GoVsAWzwNyuhUYYbTp23j+4RrncfujZ4uAzXvwA==", + "cpu": [ + "arm64" + ], "dev": true, - "license": "MIT", + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], "peer": true, - "dependencies": { - "json-buffer": "3.0.1" + "engines": { + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" } }, - "node_modules/levn": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", - "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", + "node_modules/lightningcss-win32-x64-msvc": { + "version": "1.33.0", + "resolved": "https://registry.npmjs.org/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.33.0.tgz", + "integrity": "sha512-OlEICDx/Xl0FqSp4bry8zFnCvGpig3Gl4gCquvYwHuqJKEC1+n9NgDniFvqHGmMv1ZkqDJrDqKKSykTDX+ehuA==", + "cpu": [ + "x64" + ], "dev": true, - "license": "MIT", + "license": "MPL-2.0", + "optional": true, + "os": [ + "win32" + ], "peer": true, - "dependencies": { - "prelude-ls": "^1.2.1", - "type-check": "~0.4.0" - }, "engines": { - "node": ">= 0.8.0" + "node": ">= 12.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/parcel" } }, "node_modules/locate-path": { @@ -2555,6 +3393,16 @@ "integrity": "sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==", "license": "Apache-2.0" }, + "node_modules/magic-string": { + "version": "1.4.5", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-1.4.5.tgz", + "integrity": "sha512-oLLC2+YvQUfAa+vxoufE/yc1icb87M9iXIRqAoR/2EhE/8cb3SF/+Gi0c2By1B+5Vz2e2vQtUvHiu1+63Znh+w==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.6.0" + } + }, "node_modules/math-intrinsics": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", @@ -2647,6 +3495,26 @@ "url": "https://opencollective.com/express" } }, + "node_modules/nanoid": { + "version": "3.3.20", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.20.tgz", + "integrity": "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "peer": true, + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, "node_modules/natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", @@ -2722,6 +3590,20 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/obug": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/obug/-/obug-3.0.0.tgz", + "integrity": "sha512-5vvB5+W7ePv+p3uqxi+RcW1XAzLW0/hxt3/4X4Lc4qHudzOhmBiBwOY6DRob4WnanAEGvNcLjF+KNOufrUoEQw==", + "dev": true, + "funding": [ + "https://github.com/sponsors/sxzz", + "https://opencollective.com/debug" + ], + "license": "MIT", + "engines": { + "node": ">=12.20.0" + } + }, "node_modules/on-finished": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", @@ -2856,10 +3738,18 @@ "integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==", "license": "MIT" }, + "node_modules/picocolors": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", + "dev": true, + "license": "ISC", + "peer": true + }, "node_modules/picomatch": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.4.tgz", - "integrity": "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==", + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz", + "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==", "dev": true, "license": "MIT", "engines": { @@ -2869,6 +3759,36 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/postcss": { + "version": "8.5.33", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.33.tgz", + "integrity": "sha512-RVHEU9/Pp1Fnjr/MpAJsZoADukCKhfIi15OunEYiGktIkYLkPVvC1sioWolGDS7XByMTx9m/IGbro0Js13zhnQ==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "peer": true, + "dependencies": { + "nanoid": "^3.3.20", + "picocolors": "^1.1.1", + "source-map-js": "^1.2.2" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", @@ -2994,6 +3914,42 @@ "node": ">= 4" } }, + "node_modules/rolldown": { + "version": "1.2.19", + "resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.2.19.tgz", + "integrity": "sha512-QIiV1J9d0pzN4jeeTH4sjPy0AZ6cAy2cG0ExeoE1+U8Rvj+hR3gYkokx0YbeUNGlZqiQJJ2utcETe0oKXwzsuA==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "@oxc-project/types": "=0.156.0", + "@rolldown/pluginutils": "^1.0.0" + }, + "bin": { + "rolldown": "bin/cli.mjs" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "optionalDependencies": { + "@rolldown/binding-android-arm-eabi": "1.2.19", + "@rolldown/binding-android-arm64": "1.2.19", + "@rolldown/binding-darwin-arm64": "1.2.19", + "@rolldown/binding-darwin-x64": "1.2.19", + "@rolldown/binding-freebsd-x64": "1.2.19", + "@rolldown/binding-linux-arm-gnueabihf": "1.2.19", + "@rolldown/binding-linux-arm64-gnu": "1.2.19", + "@rolldown/binding-linux-arm64-musl": "1.2.19", + "@rolldown/binding-linux-ppc64-gnu": "1.2.19", + "@rolldown/binding-linux-s390x-gnu": "1.2.19", + "@rolldown/binding-linux-x64-gnu": "1.2.19", + "@rolldown/binding-linux-x64-musl": "1.2.19", + "@rolldown/binding-openharmony-arm64": "1.2.19", + "@rolldown/binding-wasm32-wasi": "1.2.19", + "@rolldown/binding-win32-arm64-msvc": "1.2.19", + "@rolldown/binding-win32-x64-msvc": "1.2.19" + } + }, "node_modules/router": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz", @@ -3222,6 +4178,17 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/source-map-js": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.4.tgz", + "integrity": "sha512-J7ZjMvHd9O1fcT/5V09QWaaSl2BbWx3F6O08spde82Namf9UB0GxRVIPiNbVsdKkoizHiSpTodo3vp2bAy91MA==", + "dev": true, + "license": "BSD-3-Clause", + "peer": true, + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/statuses": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", @@ -3231,6 +4198,13 @@ "node": ">= 0.8" } }, + "node_modules/std-env": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/std-env/-/std-env-4.3.0.tgz", + "integrity": "sha512-OtU/EgQ1kIm5KwqQpBC6ZEMXrZRui11w8zgfTWp8cdO9B8OaPsbA8bTHO2P+HNo1VlUTGMVBwPhydu6poeXiag==", + "dev": true, + "license": "MIT" + }, "node_modules/streamsearch": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", @@ -3248,6 +4222,26 @@ "safe-buffer": "~5.2.0" } }, + "node_modules/tinybench": { + "version": "6.2.4", + "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-6.2.4.tgz", + "integrity": "sha512-SQ52jEncXxbMCzJuY2A/jGIbbAu6NYsBWW7grz2pNE+EnzQdoGaoBfpk4qC/opE7qiUcGmGgaGIz5EoHdS1O9w==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=20.0.0" + } + }, + "node_modules/tinyexec": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.3.1.tgz", + "integrity": "sha512-GCvB3aoys96IuDFBMcTB46JOR6mdMtAToqwiW8JlWhsoh1mhHi/xn9ss/Dg7N555GiJyEt2qzoG/NHCwM6h1EA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, "node_modules/tinyglobby": { "version": "0.2.17", "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz", @@ -3287,6 +4281,15 @@ "typescript": ">=4.8.4" } }, + "node_modules/tslib": { + "version": "2.9.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.9.1.tgz", + "integrity": "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA==", + "dev": true, + "license": "0BSD", + "optional": true, + "peer": true + }, "node_modules/tsx": { "version": "4.22.4", "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.22.4.tgz", @@ -3343,7 +4346,6 @@ "version": "6.0.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz", "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==", - "dev": true, "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", @@ -3418,6 +4420,168 @@ "node": ">= 0.8" } }, + "node_modules/vite": { + "version": "8.3.8", + "resolved": "https://registry.npmjs.org/vite/-/vite-8.3.8.tgz", + "integrity": "sha512-LzOn3h9rG/0vhLdXrV4yJ4QFA9eEoqCl+Yx+kGJd7aB9w6nfNgVHKSYwLPZUHrz4ZGa+t+kXjV9itvcHDLQouA==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "lightningcss": "^1.33.0", + "picomatch": "^4.0.7", + "postcss": "^8.5.32", + "rolldown": "~1.2.18", + "tinyglobby": "^0.2.17" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + }, + "peerDependencies": { + "@types/node": "^20.19.0 || >=22.12.0", + "@vitejs/devtools": "^0.7.1 || ^0.8.0", + "esbuild": "^0.27.0 || ^0.28.0", + "jiti": ">=1.21.0", + "less": "^4.0.0", + "sass": "^1.70.0", + "sass-embedded": "^1.70.0", + "stylus": ">=0.54.8", + "sugarss": "^5.0.0", + "terser": "^5.16.0", + "tsx": "^4.8.1", + "yaml": "^2.4.2" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "@vitejs/devtools": { + "optional": true + }, + "esbuild": { + "optional": true + }, + "jiti": { + "optional": true + }, + "less": { + "optional": true + }, + "sass": { + "optional": true + }, + "sass-embedded": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + }, + "tsx": { + "optional": true + }, + "yaml": { + "optional": true + } + } + }, + "node_modules/vitest": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/vitest/-/vitest-5.1.0.tgz", + "integrity": "sha512-MzmNFnrwa8v8lF1bLxw3UJ4EREwVOVb75VqJZmUDRjJ6EluK/x9th7qTbaeDk41WxE1GxWqmTXcdsfobfH5sOA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/chai": "^5.2.2", + "@vitest/mocker": "5.1.0", + "chai": "^6.3.0", + "es-module-lexer": "^2.3.2", + "expect-type": "^1.4.0", + "magic-string": "^1.4.3", + "obug": "^3.0.0", + "picomatch": "^4.0.7", + "std-env": "^4.3.0", + "tinybench": "^6.2.2", + "tinyexec": "^1.3.1", + "tinyglobby": "^0.2.17", + "why-is-node-running": "3.2.1" + }, + "bin": { + "vitest": "vitest.mjs" + }, + "engines": { + "node": "^22.12.0 || ^24.0.0 || >=26.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@edge-runtime/vm": "*", + "@opentelemetry/api": "^1.9.0", + "@types/node": "^22.0.0 || >=24.0.0", + "@vitest/browser-playwright": "5.1.0", + "@vitest/browser-preview": "5.1.0", + "@vitest/browser-webdriverio": "^5.0.0-beta.5 || >=5.0.0", + "@vitest/coverage-istanbul": "5.1.0", + "@vitest/coverage-v8": "5.1.0", + "@vitest/ui": "5.1.0", + "happy-dom": "*", + "jsdom": "*", + "vite": "^6.4.0 || ^7.0.0 || ^8.0.0" + }, + "peerDependenciesMeta": { + "@edge-runtime/vm": { + "optional": true + }, + "@opentelemetry/api": { + "optional": true + }, + "@types/node": { + "optional": true + }, + "@vitest/browser-playwright": { + "optional": true + }, + "@vitest/browser-preview": { + "optional": true + }, + "@vitest/browser-webdriverio": { + "optional": true + }, + "@vitest/coverage-istanbul": { + "optional": true + }, + "@vitest/coverage-v8": { + "optional": true + }, + "@vitest/ui": { + "optional": true + }, + "happy-dom": { + "optional": true + }, + "jsdom": { + "optional": true + }, + "vite": { + "optional": false + } + } + }, "node_modules/web-streams-polyfill": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", @@ -3444,6 +4608,19 @@ "node": ">= 8" } }, + "node_modules/why-is-node-running": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-3.2.1.tgz", + "integrity": "sha512-Tb2FUhB4vUsGQlfSquQLYkApkuPAFQXGFzxWKHHumVz2dK+X1RUm/HnID4+TfIGYJ1kTcwOaCk/buYCEJr6YjQ==", + "dev": true, + "license": "MIT", + "bin": { + "why-is-node-running": "cli.js" + }, + "engines": { + "node": ">=20.11" + } + }, "node_modules/word-wrap": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", @@ -3492,6 +4669,26 @@ "fd-slicer": "~1.1.0" } }, + "node_modules/yazl": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/yazl/-/yazl-3.3.1.tgz", + "integrity": "sha512-BbETDVWG+VcMUle37k5Fqp//7SDOK2/1+T7X8TD96M3D9G8jK5VLUdQVdVjGi8im7FGkazX7kk5hkU8X4L5Bng==", + "dev": true, + "license": "MIT", + "dependencies": { + "buffer-crc32": "^1.0.0" + } + }, + "node_modules/yazl/node_modules/buffer-crc32": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-1.0.0.tgz", + "integrity": "sha512-Db1SbgBS/fg/392AblrMJk97KggmvYhr4pB5ZIMTWtaivCPMWLkmb7m21cJvpvgK+J3nsU2CmmixNBZx4vFj/w==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", diff --git a/apps/backend/package.json b/apps/backend/package.json index e00f31b..1137b20 100644 --- a/apps/backend/package.json +++ b/apps/backend/package.json @@ -5,15 +5,20 @@ "scripts": { "dev": "tsx watch src/server.ts", "build": "tsc", - "start": "node dist/server.js" + "start": "node dist/server.js", + "typecheck": "tsc -p tsconfig.check.json", + "test": "vitest run", + "eval": "tsx scripts/eval.ts" }, "devDependencies": { "@types/cors": "^2.8.19", "@types/multer": "^2.1.0", "@types/yauzl": "^2.10.3", + "@types/yazl": "^3.3.1", "tsx": "^4.22.4", - "typescript": "^6.0.3", - "typescript-eslint": "^8.62.1" + "typescript-eslint": "^8.62.1", + "vitest": "5.1.0", + "yazl": "^3.3.1" }, "dependencies": { "@google/genai": "^2.10.0", @@ -21,6 +26,7 @@ "dotenv": "^17.4.2", "express": "^5.2.1", "multer": "^2.2.0", + "typescript": "^6.0.3", "yauzl": "^2.10.0", "zod": "^4.4.3" } diff --git a/apps/backend/pnpm-lock.yaml b/apps/backend/pnpm-lock.yaml index 6d4480b..b97740d 100644 --- a/apps/backend/pnpm-lock.yaml +++ b/apps/backend/pnpm-lock.yaml @@ -23,6 +23,9 @@ importers: multer: specifier: ^2.2.0 version: 2.2.0 + typescript: + specifier: ^6.0.3 + version: 6.0.3 yauzl: specifier: ^2.10.0 version: 2.10.0 @@ -39,18 +42,33 @@ importers: '@types/yauzl': specifier: ^2.10.3 version: 2.10.3 + '@types/yazl': + specifier: ^3.3.1 + version: 3.3.1 tsx: specifier: ^4.22.4 version: 4.22.4 - typescript: - specifier: ^6.0.3 - version: 6.0.3 typescript-eslint: specifier: ^8.62.1 version: 8.62.1(eslint@10.6.0)(typescript@6.0.3) + vitest: + specifier: 5.1.0 + version: 5.1.0(@types/node@26.1.0)(vite@8.3.8(@types/node@26.1.0)(esbuild@0.28.1)(tsx@4.22.4)) + yazl: + specifier: ^3.3.1 + version: 3.3.1 packages: + '@emnapi/core@2.0.0-beta.2': + resolution: {integrity: sha512-MzCVoWtcg4Pm2B3je5mMvYMvj3MmBKw+fU7vbsJc9/iT8ip6/eYIHo/Dsm/mr+wsHB6SEyJDuxB09Yy6r/8+4A==} + + '@emnapi/runtime@2.0.0-beta.2': + resolution: {integrity: sha512-JcrSPzPvZuNZvJqPTF9Fw25LbOJ8avzFVlaf2grmH4Cku0oGP47tRgqPZadcfj3YoZMHkFVnCYFbQM8I+i5QEw==} + + '@emnapi/wasi-threads@2.2.0': + resolution: {integrity: sha512-JP7OYH38Q7+pyTAe14raZHLQIK7BDKbdwji+Xi3pcd/6QkJYQH3SX4wu6EplGrGJWRepoNzedfm0G3B9Z4e9Rw==} + '@esbuild/aix-ppc64@0.28.1': resolution: {integrity: sha512-Svl7tq8k/08+p6CXPpRjQ1fKX+1odH/BQbb48fV6fj3CWHhsoIOoY87w1oHXm0qEpkIK3ZfVgp0hed3XBXzXMQ==} engines: {node: '>=18'} @@ -266,6 +284,26 @@ packages: resolution: {integrity: sha512-bV0Tgo9K4hfPCek+aMAn81RppFKv2ySDQeMoSZuvTASywNTnVJCArCZE2FWqpvIatKu7VMRLWlR1EazvVhDyhQ==} engines: {node: '>=18.18'} + '@jridgewell/resolve-uri@3.1.3': + resolution: {integrity: sha512-lhTtjtoEArWBjismtfS761S9Hlyn+nIZqOZVYoZ1Xn82PMNMVnk+jj/NhC4fAXGTs7ydONcJiR5vyQBTMDu27g==} + engines: {node: '>=6.0.0'} + + '@jridgewell/sourcemap-codec@1.6.0': + resolution: {integrity: sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==} + + '@jridgewell/trace-mapping@0.3.31': + resolution: {integrity: sha512-zzNR+SdQSDJzc8joaeP8QQoCQr8NuYx2dIIytl1QeBEZHJ9uW6hebsrYgbz8hJwUQao3TWCMtmfV8Nu1twOLAw==} + + '@napi-rs/wasm-runtime@1.2.6': + resolution: {integrity: sha512-mRyDmEw9/fCDXCGfL1sbgIw/GUK0PVxRW4YwgPN61F3LQ+fSyoBFarJVzgGyhF6kRzEQZ0FejDqm4WLXSeqQmw==} + engines: {node: ^20.19.0 || ^22.13.0 || >=23.5.0} + peerDependencies: + '@emnapi/core': ^1.7.1 || 2.0.0-beta.2 + '@emnapi/runtime': ^1.7.1 || 2.0.0-beta.2 + + '@oxc-project/types@0.156.0': + resolution: {integrity: sha512-1Duyg48TdJNdyhEB8Xn1L36bT9Pv6GUtlKjHxOys8xkaF/rQq3XJE+bAurSK/AgIz5mGFsb77cn9Pb20+WCScw==} + '@protobufjs/aspromise@1.1.2': resolution: {integrity: sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==} @@ -293,15 +331,122 @@ packages: '@protobufjs/utf8@1.1.1': resolution: {integrity: sha512-oOAWABowe8EAbMyWKM0tYDKi8Yaox52D+HWZhAIJqQXbqe0xI/GV7FhLWqlEKreMkfDjshR5FKgi3mnle0h6Eg==} + '@rolldown/binding-android-arm-eabi@1.2.19': + resolution: {integrity: sha512-e+Ebe0WT+9tbXmNKPIiC8YrWAHYwug3m6i4p3rZGGulfZri1jtI4HslT+OZnFf/OIHowWF71DTlHwXBP2SiA7A==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm] + os: [android] + + '@rolldown/binding-android-arm64@1.2.19': + resolution: {integrity: sha512-hOombrTJ+szt2ciEzS7oCA78lMPBgF5UMQWCJIyNfnrI7GLl8HYoFqCnpL2gcPOaXMqryGCU5ExdQKyDDcC+yA==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [android] + + '@rolldown/binding-darwin-arm64@1.2.19': + resolution: {integrity: sha512-XoMA2pwCKGTQzUjPgtRwkedH4WmXhdIPKT6l6oOxd1PUbNodGI6DcBekgN7EC//+x3pfBYX/qL1gNmZAqivw5g==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [darwin] + + '@rolldown/binding-darwin-x64@1.2.19': + resolution: {integrity: sha512-zo8EsSSwMZCY/e+fRnGaX02YGgvJD0yvhNi/9hpGPA2MJ9ZF8dPCw75UGfpI6OpQ/myR/dIYmogRvqiZD0TrXg==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [darwin] + + '@rolldown/binding-freebsd-x64@1.2.19': + resolution: {integrity: sha512-O8ISAOfI1nj7AuBPd30FSF47z7f7lzlk5poQVGgiikvQuGEBFYvW8ki+UEnT+YJPnNGjQzn304klt4O9FUE7mA==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [freebsd] + + '@rolldown/binding-linux-arm-gnueabihf@1.2.19': + resolution: {integrity: sha512-/lYCba5NO0yq4S0jGMH8QTBtkvQxoXjoQWzF5BcWp9MjB9jxVRD1GQDNofkVjcOj30DWyhLIN/4Oe60JKzaONw==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm] + os: [linux] + + '@rolldown/binding-linux-arm64-gnu@1.2.19': + resolution: {integrity: sha512-pm/apFMBnSbFb3O6nG5pHO1iqHhZrjGDFEjSm+ot9J17XXPvH9L90y5h+jgfHCE+Qdlsvy8qKEcU4VKxgjD+vA==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [linux] + + '@rolldown/binding-linux-arm64-musl@1.2.19': + resolution: {integrity: sha512-K1SmQp3FFichn8oqrNIwvFoZ5wcvjC7goBzpaMNvLf9FZc+QB/QvLmnpJZgAAGHiD980tP8FZZnXk2K94rvlxg==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [linux] + + '@rolldown/binding-linux-ppc64-gnu@1.2.19': + resolution: {integrity: sha512-I0xwD57jP/3A7+5UPZin2w8Y7XHEmEM5zqpYZOcQ45MlNW6tUJUziymV3yRr7rL4vwyfEcRsRksC4a7Kc08p5Q==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [ppc64] + os: [linux] + + '@rolldown/binding-linux-s390x-gnu@1.2.19': + resolution: {integrity: sha512-BrtEHT24SNXj9HiXqy+s/kXiSiQGt6EKCPUlRirAoIioVxKGnbXBUEkbZASAei7iZJB0/Ynm+0JP00Ipx7AnSw==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [s390x] + os: [linux] + + '@rolldown/binding-linux-x64-gnu@1.2.19': + resolution: {integrity: sha512-rm75/9DkHKeU2WnA8w4X94WGYgLlDCFCfkQC+4bguVJmC/jvDRv2B+2wLOYhyE0fVuv7//Ckk39OoOufyCu76Q==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [linux] + + '@rolldown/binding-linux-x64-musl@1.2.19': + resolution: {integrity: sha512-irh/4+iYFM4GAzpluDErgjz89bj6NDtqqMAG/6O1LG38Ed3NpyebzCpcVNkFW8uhy+/3/BocUvnXDR33CXWe9A==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [linux] + + '@rolldown/binding-openharmony-arm64@1.2.19': + resolution: {integrity: sha512-+KWTWNoPt+CfSq94CiceWu3yPE+QzkaG+phPyz9G60tmZLwfQkcA4AeksafzvJAw4pvg1mcd5a1TkUqVv0s4JA==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [openharmony] + + '@rolldown/binding-wasm32-wasi@1.2.19': + resolution: {integrity: sha512-7EH+skOsl5qpWnK0vzamgJFhOv1cwxQpsxm8tI883K9fur5c27p8q87fzEO6BbBPabA2/+s/zR63/pLc137iOg==} + engines: {node: ^20.19.0 || ^22.13.0 || >=23.5.0} + cpu: [wasm32] + + '@rolldown/binding-win32-arm64-msvc@1.2.19': + resolution: {integrity: sha512-3Q1Yg1Q7tEvBWoZf5rFvG/GKZQPgwfru+p4wBajDfJFBs0SHCpL++dfTjW9gyAKd1T7ZpIYvdaUax7Pa/IhFVQ==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [arm64] + os: [win32] + + '@rolldown/binding-win32-x64-msvc@1.2.19': + resolution: {integrity: sha512-y/sqRRc6d7hECzOFc5n3LSeqctmIp9mMjY1Kq4s14uLPd/LZ4z7i1zrW6fMtp2mPeuQIC4e6ULMcwQzMomqQag==} + engines: {node: ^20.19.0 || >=22.12.0} + cpu: [x64] + os: [win32] + + '@rolldown/pluginutils@1.1.1': + resolution: {integrity: sha512-glFIJDvLNDtJhT9qrMFWLPbvS+skxgt4L0K8Ei2YtnhPysAJnsI7nyxSJxKj4ADeKX0OLjC4ntRkwpLOoS3rwA==} + + '@tybys/wasm-util@0.10.5': + resolution: {integrity: sha512-dOGOPxlaNV+G046mZzN+9C0dAcQZeSKcXiVaM0TYy/LM4ttTmgSBDxYfovcYI8Em3+eAbiAYpvWLOv8+ZVRJKA==} + '@types/body-parser@1.19.6': resolution: {integrity: sha512-HLFeCYgz89uk22N5Qg3dvGvsv46B8GLvKKo1zKG4NybA8U2DiEO3w9lqGg29t/tfLRJpJ6iQxnVw4OnB7MoM9g==} + '@types/chai@5.2.3': + resolution: {integrity: sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==} + '@types/connect@3.4.38': resolution: {integrity: sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==} '@types/cors@2.8.19': resolution: {integrity: sha512-mFNylyeyqN93lfe/9CSxOGREz8cpzAhH+E93xJ4xWQf62V8sQ/24reV2nyzUWM6H6Xji+GGHpkbLe7pVoUEskg==} + '@types/deep-eql@4.0.2': + resolution: {integrity: sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==} + '@types/esrecurse@4.3.1': resolution: {integrity: sha512-xJBAbDifo5hpffDBuHl0Y8ywswbiAp/Wi7Y/GtAgSlZyIABppyurxVueOPE8LUQOxdlgi6Zqce7uoEpqNTeiUw==} @@ -344,6 +489,9 @@ packages: '@types/yauzl@2.10.3': resolution: {integrity: sha512-oJoftv0LSuaDZE3Le4DbKX+KS9G36NzOeSap90UIK0yMA/NhKJhqlSGtNDORNRaIbQfzjXDrQa0ytJ6mNRGz/Q==} + '@types/yazl@3.3.1': + resolution: {integrity: sha512-DIWfCKpsTp6hE5BDBHV3+fIL/bLUF9Bv13iDrWnMlmhQpH67buNvI291ZauQ1xcccxK3FqQ9honnXpq4R8NMuQ==} + '@typescript-eslint/eslint-plugin@8.62.1': resolution: {integrity: sha512-4EQM77WgVNxj7OkL/5b/D/xZsw00G577+UriYTC7JF5opcF3T2AuoeY7ueLaZgSVjSgCS6yOAJB5bRGLPSJUzA==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} @@ -403,6 +551,20 @@ packages: resolution: {integrity: sha512-4g3BLxfdTMy8iZG0MaBkadnlRrCJ74cQiFbyEVMrkwIoqdyaXXQM22cotDvrl4x28wgIZ9rEJRoM+mmhSJpJ1g==} engines: {node: ^18.18.0 || ^20.9.0 || >=21.1.0} + '@vitest/mocker@5.1.0': + resolution: {integrity: sha512-5umB9/jlWcqVS6fsrFmv5Gdnpu6wAUio/lEOwAmvB7v+lFo/IW2B9FhAD0p19GCULTgMzLCdUmuCDCnAzWgppQ==} + peerDependencies: + msw: ^2.4.9 || ^3.0.0 + vite: ^6.0.0 || ^7.0.0 || ^8.0.0 + peerDependenciesMeta: + msw: + optional: true + vite: + optional: true + + '@vitest/spy@5.1.0': + resolution: {integrity: sha512-2DPO5OMHWKrBngC+fCmTQqemNF0gidRhp3lxbBmRhW+M1XJrfgPpqNqWVevXtn2f2ufD5ZaR1B6B641aAlcX5A==} + accepts@2.0.0: resolution: {integrity: sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==} engines: {node: '>= 0.6'} @@ -427,6 +589,10 @@ packages: append-field@1.0.0: resolution: {integrity: sha512-klpgFSWLW1ZEs8svjfb7g4qWY0YS5imI82dTg+QahUvJ8YqAY0P10Uk8tTyh9ZGuYEZEMaeJYCF5BFuX552hsw==} + assertion-error@2.0.1: + resolution: {integrity: sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==} + engines: {node: '>=12'} + balanced-match@4.0.4: resolution: {integrity: sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==} engines: {node: 18 || 20 || >=22} @@ -448,6 +614,10 @@ packages: buffer-crc32@0.2.13: resolution: {integrity: sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==} + buffer-crc32@1.0.0: + resolution: {integrity: sha512-Db1SbgBS/fg/392AblrMJk97KggmvYhr4pB5ZIMTWtaivCPMWLkmb7m21cJvpvgK+J3nsU2CmmixNBZx4vFj/w==} + engines: {node: '>=8.0.0'} + buffer-equal-constant-time@1.0.1: resolution: {integrity: sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==} @@ -470,6 +640,10 @@ packages: resolution: {integrity: sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==} engines: {node: '>= 0.4'} + chai@6.3.0: + resolution: {integrity: sha512-XWAtwJ6OHO+tj0EKCs0Y2UamnyOxseZWltU4x2U2wh8g4AigdjwvtUjvLP2tqkA/avxHEtzxNaqGq/YGNwckKg==} + engines: {node: '>=18'} + concat-stream@2.0.0: resolution: {integrity: sha512-MWufYdFw53ccGjCA+Ol7XJYpAlW6/prSMzuPOTRnJGcGzuhLn4Scrz7qf6o8bROZ514ltazcIFJZevcfbo0x7A==} engines: {'0': node >= 6.0} @@ -522,6 +696,10 @@ packages: resolution: {integrity: sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==} engines: {node: '>= 0.8'} + detect-libc@2.1.2: + resolution: {integrity: sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==} + engines: {node: '>=8'} + dotenv@17.4.2: resolution: {integrity: sha512-nI4U3TottKAcAD9LLud4Cb7b2QztQMUEfHbvhTH09bqXTxnSie8WnjPALV/WMCrJZ6UV/qHJ6L03OqO3LcdYZw==} engines: {node: '>=12'} @@ -548,6 +726,9 @@ packages: resolution: {integrity: sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==} engines: {node: '>= 0.4'} + es-module-lexer@2.3.2: + resolution: {integrity: sha512-poHGpORABojJJucnV9KbOavETW8lBVnphkW77ER5/BQ5Fz7oXSoCNek7IH3vR5nRjdsEz926ibFYX8KtLQmdyw==} + es-object-atoms@1.1.2: resolution: {integrity: sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==} engines: {node: '>= 0.4'} @@ -602,6 +783,9 @@ packages: resolution: {integrity: sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==} engines: {node: '>=4.0'} + estree-walker@3.0.3: + resolution: {integrity: sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==} + esutils@2.0.3: resolution: {integrity: sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==} engines: {node: '>=0.10.0'} @@ -610,6 +794,10 @@ packages: resolution: {integrity: sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==} engines: {node: '>= 0.6'} + expect-type@1.4.0: + resolution: {integrity: sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA==} + engines: {node: '>=12.0.0'} + express@5.2.1: resolution: {integrity: sha512-hIS4idWWai69NezIdRt2xFVofaF4j+6INOpJlVOLDO8zXGpUVEVzIYk12UUi2JzjEzWL3IOAxcTubgz9Po0yXw==} engines: {node: '>= 18'} @@ -791,6 +979,76 @@ packages: resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==} engines: {node: '>= 0.8.0'} + lightningcss-android-arm64@1.33.0: + resolution: {integrity: sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [android] + + lightningcss-darwin-arm64@1.33.0: + resolution: {integrity: sha512-Sciaz8eenNTKn9b3t7+xr0ipTp9YxKQY4npwQ3mrRuL0BAVHBLyZxofhaKBAVtzmtRZ/zTyo0/to4B1uWG/Djg==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [darwin] + + lightningcss-darwin-x64@1.33.0: + resolution: {integrity: sha512-Z5UPAxzrjlWNNyGy6i65cJzzvgJ5D3T6wMvs+gWpY9d7qRhANrxqAp6LhxIgZhWEw18RfJTGcRxjuLIBr+m8XQ==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [darwin] + + lightningcss-freebsd-x64@1.33.0: + resolution: {integrity: sha512-QQM/Ti/hQajJwCY+RiWuCZ9sdtI/XQk7nDK5vC8kkdwixezOlDgvDx7+RT+QjK6FcFT4MpsuoBnHIo/O3StRRg==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [freebsd] + + lightningcss-linux-arm-gnueabihf@1.33.0: + resolution: {integrity: sha512-N7FVBe6iS24MlM6R/4RBTxGhQheZGs7tiQ9U32UtF75NzP5Q7xWPRqLBCKxlRQRk3rY1jCIPLzx7WzOhuUIRLQ==} + engines: {node: '>= 12.0.0'} + cpu: [arm] + os: [linux] + + lightningcss-linux-arm64-gnu@1.33.0: + resolution: {integrity: sha512-j2v/itmy4HlNxlc6voKXYgBqNi0Ng2LShg4z7GufpEgs05P+2suBVyi9I6YHq5uoVFx9ETin3eCEhLVyXGQnKg==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [linux] + + lightningcss-linux-arm64-musl@1.33.0: + resolution: {integrity: sha512-yiO5ROMuYQgXbC60yjZU5CYSFZGKXL0HFATXt9mHJn1+zW55oCtMI9NfcVhYLMFDL7gV7oBPon/EmMMGg2OvtQ==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [linux] + + lightningcss-linux-x64-gnu@1.33.0: + resolution: {integrity: sha512-ar+Ju7LmcN0Jo4FpL4hpFybwNG9/3A/Br5KW2n2jyODg3MEZXaDYADdemoNS+BDNfMgKvylJLj4S5tyRActuAg==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [linux] + + lightningcss-linux-x64-musl@1.33.0: + resolution: {integrity: sha512-RYiYbkokw0trfKqqzfF55lginwEPrD3OJDfTuJzFs1MK6iFnDenaz1fqLLtX4ITG3OktJQXOeTaw1awrBAlZPw==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [linux] + + lightningcss-win32-arm64-msvc@1.33.0: + resolution: {integrity: sha512-1K+MPfLSFVpphzpdbfkhlWk6wBrTObBzS2T6db10PNOZgR9GoVsAWzwNyuhUYYbTp23j+4RrncfujZ4uAzXvwA==} + engines: {node: '>= 12.0.0'} + cpu: [arm64] + os: [win32] + + lightningcss-win32-x64-msvc@1.33.0: + resolution: {integrity: sha512-OlEICDx/Xl0FqSp4bry8zFnCvGpig3Gl4gCquvYwHuqJKEC1+n9NgDniFvqHGmMv1ZkqDJrDqKKSykTDX+ehuA==} + engines: {node: '>= 12.0.0'} + cpu: [x64] + os: [win32] + + lightningcss@1.33.0: + resolution: {integrity: sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA==} + engines: {node: '>= 12.0.0'} + locate-path@6.0.0: resolution: {integrity: sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==} engines: {node: '>=10'} @@ -798,6 +1056,9 @@ packages: long@5.3.2: resolution: {integrity: sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==} + magic-string@1.4.5: + resolution: {integrity: sha512-oLLC2+YvQUfAa+vxoufE/yc1icb87M9iXIRqAoR/2EhE/8cb3SF/+Gi0c2By1B+5Vz2e2vQtUvHiu1+63Znh+w==} + math-intrinsics@1.1.0: resolution: {integrity: sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==} engines: {node: '>= 0.4'} @@ -841,6 +1102,11 @@ packages: resolution: {integrity: sha512-6rdyFg2kLrMh9Jee7/BMPuV9lEAd7lLW2YUpF9/YxR7njyoUwwQ0ZPh3TaIY50Sw6vlyD2HW3wGOkTS4P79xrQ==} engines: {node: '>= 10.16.0'} + nanoid@3.3.20: + resolution: {integrity: sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==} + engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} + hasBin: true + natural-compare@1.4.0: resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==} @@ -865,6 +1131,10 @@ packages: resolution: {integrity: sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==} engines: {node: '>= 0.4'} + obug@3.0.0: + resolution: {integrity: sha512-5vvB5+W7ePv+p3uqxi+RcW1XAzLW0/hxt3/4X4Lc4qHudzOhmBiBwOY6DRob4WnanAEGvNcLjF+KNOufrUoEQw==} + engines: {node: '>=12.20.0'} + on-finished@2.4.1: resolution: {integrity: sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==} engines: {node: '>= 0.8'} @@ -906,10 +1176,17 @@ packages: pend@1.2.0: resolution: {integrity: sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==} - picomatch@4.0.4: - resolution: {integrity: sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==} + picocolors@1.1.1: + resolution: {integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==} + + picomatch@4.0.7: + resolution: {integrity: sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==} engines: {node: '>=12'} + postcss@8.5.33: + resolution: {integrity: sha512-RVHEU9/Pp1Fnjr/MpAJsZoADukCKhfIi15OunEYiGktIkYLkPVvC1sioWolGDS7XByMTx9m/IGbro0Js13zhnQ==} + engines: {node: ^10 || ^12 || >=14} + prelude-ls@1.2.1: resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==} engines: {node: '>= 0.8.0'} @@ -946,6 +1223,11 @@ packages: resolution: {integrity: sha512-XQBQ3I8W1Cge0Seh+6gjj03LbmRFWuoszgK9ooCpwYIrhhoO80pfq4cUkU5DkknwfOfFteRwlZ56PYOGYyFWdg==} engines: {node: '>= 4'} + rolldown@1.2.19: + resolution: {integrity: sha512-QIiV1J9d0pzN4jeeTH4sjPy0AZ6cAy2cG0ExeoE1+U8Rvj+hR3gYkokx0YbeUNGlZqiQJJ2utcETe0oKXwzsuA==} + engines: {node: ^20.19.0 || >=22.12.0} + hasBin: true + router@2.2.0: resolution: {integrity: sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==} engines: {node: '>= 18'} @@ -996,10 +1278,17 @@ packages: resolution: {integrity: sha512-6x6dK6zJdpTzF4sQeNYxwtvBzf6Eg4GtlesS94HOvTudUeyK2WXAaIfmDgsyslYrRBeFIlsi54AYsFGUuhmvrQ==} engines: {node: '>= 0.4'} + source-map-js@1.2.4: + resolution: {integrity: sha512-J7ZjMvHd9O1fcT/5V09QWaaSl2BbWx3F6O08spde82Namf9UB0GxRVIPiNbVsdKkoizHiSpTodo3vp2bAy91MA==} + engines: {node: '>=6.0.0'} + statuses@2.0.2: resolution: {integrity: sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==} engines: {node: '>= 0.8'} + std-env@4.3.0: + resolution: {integrity: sha512-OtU/EgQ1kIm5KwqQpBC6ZEMXrZRui11w8zgfTWp8cdO9B8OaPsbA8bTHO2P+HNo1VlUTGMVBwPhydu6poeXiag==} + streamsearch@1.1.0: resolution: {integrity: sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==} engines: {node: '>=10.0.0'} @@ -1007,6 +1296,14 @@ packages: string_decoder@1.3.0: resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==} + tinybench@6.2.4: + resolution: {integrity: sha512-SQ52jEncXxbMCzJuY2A/jGIbbAu6NYsBWW7grz2pNE+EnzQdoGaoBfpk4qC/opE7qiUcGmGgaGIz5EoHdS1O9w==} + engines: {node: '>=20.0.0'} + + tinyexec@1.3.1: + resolution: {integrity: sha512-GCvB3aoys96IuDFBMcTB46JOR6mdMtAToqwiW8JlWhsoh1mhHi/xn9ss/Dg7N555GiJyEt2qzoG/NHCwM6h1EA==} + engines: {node: '>=18'} + tinyglobby@0.2.17: resolution: {integrity: sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==} engines: {node: '>=12.0.0'} @@ -1021,6 +1318,9 @@ packages: peerDependencies: typescript: '>=4.8.4' + tslib@2.9.1: + resolution: {integrity: sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA==} + tsx@4.22.4: resolution: {integrity: sha512-X8EX+XV4QR5xCsrgxaED954zTDfY8KqlDtskKEL0cHhyS/P8b4IFOvGDQpsC9Q1XnLq915wEfwwY/zzskCtmhg==} engines: {node: '>=18.0.0'} @@ -1070,6 +1370,90 @@ packages: resolution: {integrity: sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==} engines: {node: '>= 0.8'} + vite@8.3.8: + resolution: {integrity: sha512-LzOn3h9rG/0vhLdXrV4yJ4QFA9eEoqCl+Yx+kGJd7aB9w6nfNgVHKSYwLPZUHrz4ZGa+t+kXjV9itvcHDLQouA==} + engines: {node: ^20.19.0 || >=22.12.0} + hasBin: true + peerDependencies: + '@types/node': ^20.19.0 || >=22.12.0 + '@vitejs/devtools': ^0.7.1 || ^0.8.0 + esbuild: ^0.27.0 || ^0.28.0 + jiti: '>=1.21.0' + less: ^4.0.0 + sass: ^1.70.0 + sass-embedded: ^1.70.0 + stylus: '>=0.54.8' + sugarss: ^5.0.0 + terser: ^5.16.0 + tsx: ^4.8.1 + yaml: ^2.4.2 + peerDependenciesMeta: + '@types/node': + optional: true + '@vitejs/devtools': + optional: true + esbuild: + optional: true + jiti: + optional: true + less: + optional: true + sass: + optional: true + sass-embedded: + optional: true + stylus: + optional: true + sugarss: + optional: true + terser: + optional: true + tsx: + optional: true + yaml: + optional: true + + vitest@5.1.0: + resolution: {integrity: sha512-MzmNFnrwa8v8lF1bLxw3UJ4EREwVOVb75VqJZmUDRjJ6EluK/x9th7qTbaeDk41WxE1GxWqmTXcdsfobfH5sOA==} + engines: {node: ^22.12.0 || ^24.0.0 || >=26.0.0} + hasBin: true + peerDependencies: + '@edge-runtime/vm': '*' + '@opentelemetry/api': ^1.9.0 + '@types/node': ^22.0.0 || >=24.0.0 + '@vitest/browser-playwright': 5.1.0 + '@vitest/browser-preview': 5.1.0 + '@vitest/browser-webdriverio': ^5.0.0-beta.5 || >=5.0.0 + '@vitest/coverage-istanbul': 5.1.0 + '@vitest/coverage-v8': 5.1.0 + '@vitest/ui': 5.1.0 + happy-dom: '*' + jsdom: '*' + vite: ^6.4.0 || ^7.0.0 || ^8.0.0 + peerDependenciesMeta: + '@edge-runtime/vm': + optional: true + '@opentelemetry/api': + optional: true + '@types/node': + optional: true + '@vitest/browser-playwright': + optional: true + '@vitest/browser-preview': + optional: true + '@vitest/browser-webdriverio': + optional: true + '@vitest/coverage-istanbul': + optional: true + '@vitest/coverage-v8': + optional: true + '@vitest/ui': + optional: true + happy-dom: + optional: true + jsdom: + optional: true + web-streams-polyfill@3.3.3: resolution: {integrity: sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==} engines: {node: '>= 8'} @@ -1079,6 +1463,11 @@ packages: engines: {node: '>= 8'} hasBin: true + why-is-node-running@3.2.1: + resolution: {integrity: sha512-Tb2FUhB4vUsGQlfSquQLYkApkuPAFQXGFzxWKHHumVz2dK+X1RUm/HnID4+TfIGYJ1kTcwOaCk/buYCEJr6YjQ==} + engines: {node: '>=20.11'} + hasBin: true + word-wrap@1.2.5: resolution: {integrity: sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==} engines: {node: '>=0.10.0'} @@ -1101,6 +1490,9 @@ packages: yauzl@2.10.0: resolution: {integrity: sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==} + yazl@3.3.1: + resolution: {integrity: sha512-BbETDVWG+VcMUle37k5Fqp//7SDOK2/1+T7X8TD96M3D9G8jK5VLUdQVdVjGi8im7FGkazX7kk5hkU8X4L5Bng==} + yocto-queue@0.1.0: resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} engines: {node: '>=10'} @@ -1110,6 +1502,22 @@ packages: snapshots: + '@emnapi/core@2.0.0-beta.2': + dependencies: + '@emnapi/wasi-threads': 2.2.0 + tslib: 2.9.1 + optional: true + + '@emnapi/runtime@2.0.0-beta.2': + dependencies: + tslib: 2.9.1 + optional: true + + '@emnapi/wasi-threads@2.2.0': + dependencies: + tslib: 2.9.1 + optional: true + '@esbuild/aix-ppc64@0.28.1': optional: true @@ -1245,6 +1653,24 @@ snapshots: '@humanwhocodes/retry@0.4.3': {} + '@jridgewell/resolve-uri@3.1.3': {} + + '@jridgewell/sourcemap-codec@1.6.0': {} + + '@jridgewell/trace-mapping@0.3.31': + dependencies: + '@jridgewell/resolve-uri': 3.1.3 + '@jridgewell/sourcemap-codec': 1.6.0 + + '@napi-rs/wasm-runtime@1.2.6(@emnapi/core@2.0.0-beta.2)(@emnapi/runtime@2.0.0-beta.2)': + dependencies: + '@emnapi/core': 2.0.0-beta.2 + '@emnapi/runtime': 2.0.0-beta.2 + '@tybys/wasm-util': 0.10.5 + optional: true + + '@oxc-project/types@0.156.0': {} + '@protobufjs/aspromise@1.1.2': {} '@protobufjs/base64@1.1.2': {} @@ -1265,11 +1691,75 @@ snapshots: '@protobufjs/utf8@1.1.1': {} + '@rolldown/binding-android-arm-eabi@1.2.19': + optional: true + + '@rolldown/binding-android-arm64@1.2.19': + optional: true + + '@rolldown/binding-darwin-arm64@1.2.19': + optional: true + + '@rolldown/binding-darwin-x64@1.2.19': + optional: true + + '@rolldown/binding-freebsd-x64@1.2.19': + optional: true + + '@rolldown/binding-linux-arm-gnueabihf@1.2.19': + optional: true + + '@rolldown/binding-linux-arm64-gnu@1.2.19': + optional: true + + '@rolldown/binding-linux-arm64-musl@1.2.19': + optional: true + + '@rolldown/binding-linux-ppc64-gnu@1.2.19': + optional: true + + '@rolldown/binding-linux-s390x-gnu@1.2.19': + optional: true + + '@rolldown/binding-linux-x64-gnu@1.2.19': + optional: true + + '@rolldown/binding-linux-x64-musl@1.2.19': + optional: true + + '@rolldown/binding-openharmony-arm64@1.2.19': + optional: true + + '@rolldown/binding-wasm32-wasi@1.2.19': + dependencies: + '@emnapi/core': 2.0.0-beta.2 + '@emnapi/runtime': 2.0.0-beta.2 + '@napi-rs/wasm-runtime': 1.2.6(@emnapi/core@2.0.0-beta.2)(@emnapi/runtime@2.0.0-beta.2) + optional: true + + '@rolldown/binding-win32-arm64-msvc@1.2.19': + optional: true + + '@rolldown/binding-win32-x64-msvc@1.2.19': + optional: true + + '@rolldown/pluginutils@1.1.1': {} + + '@tybys/wasm-util@0.10.5': + dependencies: + tslib: 2.9.1 + optional: true + '@types/body-parser@1.19.6': dependencies: '@types/connect': 3.4.38 '@types/node': 26.1.0 + '@types/chai@5.2.3': + dependencies: + '@types/deep-eql': 4.0.2 + assertion-error: 2.0.1 + '@types/connect@3.4.38': dependencies: '@types/node': 26.1.0 @@ -1278,6 +1768,8 @@ snapshots: dependencies: '@types/node': 26.1.0 + '@types/deep-eql@4.0.2': {} + '@types/esrecurse@4.3.1': {} '@types/estree@1.0.9': {} @@ -1326,6 +1818,10 @@ snapshots: dependencies: '@types/node': 26.1.0 + '@types/yazl@3.3.1': + dependencies: + '@types/node': 26.1.0 + '@typescript-eslint/eslint-plugin@8.62.1(@typescript-eslint/parser@8.62.1(eslint@10.6.0)(typescript@6.0.3))(eslint@10.6.0)(typescript@6.0.3)': dependencies: '@eslint-community/regexpp': 4.12.2 @@ -1417,6 +1913,17 @@ snapshots: '@typescript-eslint/types': 8.62.1 eslint-visitor-keys: 5.0.1 + '@vitest/mocker@5.1.0(vite@8.3.8(@types/node@26.1.0)(esbuild@0.28.1)(tsx@4.22.4))': + dependencies: + '@jridgewell/trace-mapping': 0.3.31 + '@vitest/spy': 5.1.0 + estree-walker: 3.0.3 + magic-string: 1.4.5 + optionalDependencies: + vite: 8.3.8(@types/node@26.1.0)(esbuild@0.28.1)(tsx@4.22.4) + + '@vitest/spy@5.1.0': {} + accepts@2.0.0: dependencies: mime-types: 3.0.2 @@ -1439,6 +1946,8 @@ snapshots: append-field@1.0.0: {} + assertion-error@2.0.1: {} + balanced-match@4.0.4: {} base64-js@1.5.1: {} @@ -1465,6 +1974,8 @@ snapshots: buffer-crc32@0.2.13: {} + buffer-crc32@1.0.0: {} + buffer-equal-constant-time@1.0.1: {} buffer-from@1.1.2: {} @@ -1485,6 +1996,8 @@ snapshots: call-bind-apply-helpers: 1.0.2 get-intrinsic: 1.3.0 + chai@6.3.0: {} + concat-stream@2.0.0: dependencies: buffer-from: 1.1.2 @@ -1523,6 +2036,8 @@ snapshots: depd@2.0.0: {} + detect-libc@2.1.2: {} + dotenv@17.4.2: {} dunder-proto@1.0.1: @@ -1543,6 +2058,8 @@ snapshots: es-errors@1.3.0: {} + es-module-lexer@2.3.2: {} + es-object-atoms@1.1.2: dependencies: es-errors: 1.3.0 @@ -1642,10 +2159,16 @@ snapshots: estraverse@5.3.0: {} + estree-walker@3.0.3: + dependencies: + '@types/estree': 1.0.9 + esutils@2.0.3: {} etag@1.8.1: {} + expect-type@1.4.0: {} + express@5.2.1: dependencies: accepts: 2.0.0 @@ -1691,9 +2214,9 @@ snapshots: dependencies: pend: 1.2.0 - fdir@6.5.0(picomatch@4.0.4): + fdir@6.5.0(picomatch@4.0.7): optionalDependencies: - picomatch: 4.0.4 + picomatch: 4.0.7 fetch-blob@3.2.0: dependencies: @@ -1868,12 +2391,65 @@ snapshots: prelude-ls: 1.2.1 type-check: 0.4.0 + lightningcss-android-arm64@1.33.0: + optional: true + + lightningcss-darwin-arm64@1.33.0: + optional: true + + lightningcss-darwin-x64@1.33.0: + optional: true + + lightningcss-freebsd-x64@1.33.0: + optional: true + + lightningcss-linux-arm-gnueabihf@1.33.0: + optional: true + + lightningcss-linux-arm64-gnu@1.33.0: + optional: true + + lightningcss-linux-arm64-musl@1.33.0: + optional: true + + lightningcss-linux-x64-gnu@1.33.0: + optional: true + + lightningcss-linux-x64-musl@1.33.0: + optional: true + + lightningcss-win32-arm64-msvc@1.33.0: + optional: true + + lightningcss-win32-x64-msvc@1.33.0: + optional: true + + lightningcss@1.33.0: + dependencies: + detect-libc: 2.1.2 + optionalDependencies: + lightningcss-android-arm64: 1.33.0 + lightningcss-darwin-arm64: 1.33.0 + lightningcss-darwin-x64: 1.33.0 + lightningcss-freebsd-x64: 1.33.0 + lightningcss-linux-arm-gnueabihf: 1.33.0 + lightningcss-linux-arm64-gnu: 1.33.0 + lightningcss-linux-arm64-musl: 1.33.0 + lightningcss-linux-x64-gnu: 1.33.0 + lightningcss-linux-x64-musl: 1.33.0 + lightningcss-win32-arm64-msvc: 1.33.0 + lightningcss-win32-x64-msvc: 1.33.0 + locate-path@6.0.0: dependencies: p-locate: 5.0.0 long@5.3.2: {} + magic-string@1.4.5: + dependencies: + '@jridgewell/sourcemap-codec': 1.6.0 + math-intrinsics@1.1.0: {} media-typer@0.3.0: {} @@ -1907,6 +2483,8 @@ snapshots: concat-stream: 2.0.0 type-is: 1.6.18 + nanoid@3.3.20: {} + natural-compare@1.4.0: {} negotiator@1.0.0: {} @@ -1923,6 +2501,8 @@ snapshots: object-inspect@1.13.4: {} + obug@3.0.0: {} + on-finished@2.4.1: dependencies: ee-first: 1.1.1 @@ -1963,7 +2543,15 @@ snapshots: pend@1.2.0: {} - picomatch@4.0.4: {} + picocolors@1.1.1: {} + + picomatch@4.0.7: {} + + postcss@8.5.33: + dependencies: + nanoid: 3.3.20 + picocolors: 1.1.1 + source-map-js: 1.2.4 prelude-ls@1.2.1: {} @@ -2010,6 +2598,28 @@ snapshots: retry@0.13.1: {} + rolldown@1.2.19: + dependencies: + '@oxc-project/types': 0.156.0 + '@rolldown/pluginutils': 1.1.1 + optionalDependencies: + '@rolldown/binding-android-arm-eabi': 1.2.19 + '@rolldown/binding-android-arm64': 1.2.19 + '@rolldown/binding-darwin-arm64': 1.2.19 + '@rolldown/binding-darwin-x64': 1.2.19 + '@rolldown/binding-freebsd-x64': 1.2.19 + '@rolldown/binding-linux-arm-gnueabihf': 1.2.19 + '@rolldown/binding-linux-arm64-gnu': 1.2.19 + '@rolldown/binding-linux-arm64-musl': 1.2.19 + '@rolldown/binding-linux-ppc64-gnu': 1.2.19 + '@rolldown/binding-linux-s390x-gnu': 1.2.19 + '@rolldown/binding-linux-x64-gnu': 1.2.19 + '@rolldown/binding-linux-x64-musl': 1.2.19 + '@rolldown/binding-openharmony-arm64': 1.2.19 + '@rolldown/binding-wasm32-wasi': 1.2.19 + '@rolldown/binding-win32-arm64-msvc': 1.2.19 + '@rolldown/binding-win32-x64-msvc': 1.2.19 + router@2.2.0: dependencies: debug: 4.4.3 @@ -2087,18 +2697,26 @@ snapshots: side-channel-map: 1.0.1 side-channel-weakmap: 1.0.2 + source-map-js@1.2.4: {} + statuses@2.0.2: {} + std-env@4.3.0: {} + streamsearch@1.1.0: {} string_decoder@1.3.0: dependencies: safe-buffer: 5.2.1 + tinybench@6.2.4: {} + + tinyexec@1.3.1: {} + tinyglobby@0.2.17: dependencies: - fdir: 6.5.0(picomatch@4.0.4) - picomatch: 4.0.4 + fdir: 6.5.0(picomatch@4.0.7) + picomatch: 4.0.7 toidentifier@1.0.1: {} @@ -2106,6 +2724,9 @@ snapshots: dependencies: typescript: 6.0.3 + tslib@2.9.1: + optional: true + tsx@4.22.4: dependencies: esbuild: 0.28.1 @@ -2154,12 +2775,48 @@ snapshots: vary@1.1.2: {} + vite@8.3.8(@types/node@26.1.0)(esbuild@0.28.1)(tsx@4.22.4): + dependencies: + lightningcss: 1.33.0 + picomatch: 4.0.7 + postcss: 8.5.33 + rolldown: 1.2.19 + tinyglobby: 0.2.17 + optionalDependencies: + '@types/node': 26.1.0 + esbuild: 0.28.1 + fsevents: 2.3.3 + tsx: 4.22.4 + + vitest@5.1.0(@types/node@26.1.0)(vite@8.3.8(@types/node@26.1.0)(esbuild@0.28.1)(tsx@4.22.4)): + dependencies: + '@types/chai': 5.2.3 + '@vitest/mocker': 5.1.0(vite@8.3.8(@types/node@26.1.0)(esbuild@0.28.1)(tsx@4.22.4)) + chai: 6.3.0 + es-module-lexer: 2.3.2 + expect-type: 1.4.0 + magic-string: 1.4.5 + obug: 3.0.0 + picomatch: 4.0.7 + std-env: 4.3.0 + tinybench: 6.2.4 + tinyexec: 1.3.1 + tinyglobby: 0.2.17 + vite: 8.3.8(@types/node@26.1.0)(esbuild@0.28.1)(tsx@4.22.4) + why-is-node-running: 3.2.1 + optionalDependencies: + '@types/node': 26.1.0 + transitivePeerDependencies: + - msw + web-streams-polyfill@3.3.3: {} which@2.0.2: dependencies: isexe: 2.0.0 + why-is-node-running@3.2.1: {} + word-wrap@1.2.5: {} wrappy@1.0.2: {} @@ -2171,6 +2828,10 @@ snapshots: buffer-crc32: 0.2.13 fd-slicer: 1.1.0 + yazl@3.3.1: + dependencies: + buffer-crc32: 1.0.0 + yocto-queue@0.1.0: {} zod@4.4.3: {} diff --git a/apps/backend/scripts/eval.ts b/apps/backend/scripts/eval.ts new file mode 100644 index 0000000..7a7e432 --- /dev/null +++ b/apps/backend/scripts/eval.ts @@ -0,0 +1,180 @@ +/** + * Runs the real analysis pipeline several times on the same ZIP(s) + * and reports how much the results vary between runs. + * + * Calls the real Gemini API (costs money): runs are sequential. + * + * npx tsx scripts/eval.ts [--runs 3] repo1.zip [repo2.zip ...] + * + * Optional: GEMINI_TEMPERATURE=0.2 npx tsx scripts/eval.ts ... + * Results are also written to eval-results/.json. + */ +import fs from "node:fs/promises"; +import os from "node:os"; +import path from "node:path"; + +import { processRepository } from "../src/repository/repository-processor.service.js"; +import { analyzeRepository } from "../src/ai/analysis/ai-analysis.service.js"; +import { JobLogger } from "../src/logger/logger.service.js"; +import { env } from "../src/config/env.js"; +import type { JobContext } from "../src/jobs/job.types.js"; + +interface RunResult { + repository: string; + run: number; + ok: boolean; + error?: string; + durationMs?: number; + folderStructure?: number; + codeQuality?: number; + resume?: number; + strengths?: number; + weaknesses?: number; + improvements?: number; + citations?: number; + citationsVerified?: number; + citationsDropped?: number; + promptTokens?: number; + outputTokens?: number; + repaired?: boolean; + weaknessTitles?: string[]; +} + +function parseArgs(argv: string[]) { + let runs = 3; + const zips: string[] = []; + + for (let i = 0; i < argv.length; i++) { + if (argv[i] === "--runs") { + runs = Number(argv[++i]); + } else { + zips.push(argv[i]); + } + } + + if (zips.length === 0 || !Number.isInteger(runs) || runs < 1) { + console.error("Usage: npx tsx scripts/eval.ts [--runs 3] repo.zip [more.zip ...]"); + process.exit(1); + } + + return { runs, zips }; +} + +async function runOnce(zip: string, run: number): Promise { + const repository = path.basename(zip); + const dir = await fs.mkdtemp(path.join(os.tmpdir(), "eval-")); + const job: JobContext = { + id: `eval-${run}`, + logger: new JobLogger(`eval-${repository}-${run}`), + setStage: () => {}, + }; + + try { + // processRepository extracts from the ZIP but does not delete it. + const metadata = await processRepository(path.resolve(zip), dir, job); + const { report, trace } = await analyzeRepository({ metadata }, job); + + return { + repository, + run, + ok: true, + durationMs: trace.durationMs, + folderStructure: report.folderStructure.score, + codeQuality: report.codeQuality.score, + resume: report.resumeFeedback.score, + strengths: report.strengths.length, + weaknesses: report.weaknesses.length, + improvements: report.improvements.length, + citations: trace.citations.total, + citationsVerified: trace.citations.verified, + citationsDropped: trace.citations.dropped, + promptTokens: trace.promptTokens, + outputTokens: trace.outputTokens, + repaired: trace.repaired, + weaknessTitles: report.weaknesses.map((w) => w.title), + }; + } catch (error) { + return { + repository, + run, + ok: false, + error: error instanceof Error ? error.message : String(error), + }; + } finally { + await fs.rm(dir, { recursive: true, force: true }); + } +} + +function summarize(values: number[]): string { + if (values.length === 0) return "-"; + + const mean = values.reduce((a, b) => a + b, 0) / values.length; + const spread = Math.max(...values) - Math.min(...values); + + return `${mean.toFixed(1)} (${Math.min(...values)}–${Math.max(...values)}, spread ${spread})`; +} + +async function main() { + const { runs, zips } = parseArgs(process.argv.slice(2)); + + console.log( + `Model ${env.GEMINI_MODEL}, temperature ${env.GEMINI_TEMPERATURE ?? "default"}, ${runs} run(s) per repository\n`, + ); + + const results: RunResult[] = []; + + for (const zip of zips) { + for (let run = 1; run <= runs; run++) { + process.stdout.write(`${path.basename(zip)} run ${run}/${runs}... `); + const result = await runOnce(zip, run); + results.push(result); + console.log( + result.ok + ? `scores ${result.folderStructure}/${result.codeQuality}/${result.resume}, ${result.citationsVerified}/${result.citations} citations verified, ${((result.durationMs ?? 0) / 1000).toFixed(0)}s` + : `FAILED: ${result.error}`, + ); + } + } + + console.log("\n=== Summary (mean, range, spread) ==="); + + for (const zip of zips) { + const repo = path.basename(zip); + const ok = results.filter((r) => r.repository === repo && r.ok); + const pick = (key: keyof RunResult) => ok.map((r) => r[key] as number); + + console.log(`\n${repo}: ${ok.length}/${runs} runs succeeded`); + console.log(` Folder structure score: ${summarize(pick("folderStructure"))}`); + console.log(` Code quality score: ${summarize(pick("codeQuality"))}`); + console.log(` Resume score: ${summarize(pick("resume"))}`); + console.log(` Weaknesses found: ${summarize(pick("weaknesses"))}`); + console.log(` Citations verified: ${summarize(pick("citationsVerified"))} of ${summarize(pick("citations"))}`); + console.log(` Citations dropped: ${summarize(pick("citationsDropped"))}`); + console.log(` Repaired responses: ${ok.filter((r) => r.repaired).length}`); + + // Weakness titles that appear in every run are the stable findings. + const titleCounts = new Map(); + for (const r of ok) { + for (const title of new Set(r.weaknessTitles?.map((t) => t.toLowerCase()))) { + titleCounts.set(title, (titleCounts.get(title) ?? 0) + 1); + } + } + const stable = [...titleCounts].filter(([, n]) => n === ok.length).map(([t]) => t); + console.log(` Weaknesses in every run: ${stable.length ? stable.join("; ") : "none (titles vary)"}`); + } + + const outDir = path.join(process.cwd(), "eval-results"); + await fs.mkdir(outDir, { recursive: true }); + const outFile = path.join(outDir, `${new Date().toISOString().replace(/:/g, "-")}.json`); + await fs.writeFile( + outFile, + JSON.stringify( + { model: env.GEMINI_MODEL, temperature: env.GEMINI_TEMPERATURE ?? null, runs, results }, + null, + 2, + ), + ); + console.log(`\nSaved ${outFile}`); +} + +await main(); diff --git a/apps/backend/src/ai/analysis/ai-analysis.service.ts b/apps/backend/src/ai/analysis/ai-analysis.service.ts index b04d034..16fe22f 100644 --- a/apps/backend/src/ai/analysis/ai-analysis.service.ts +++ b/apps/backend/src/ai/analysis/ai-analysis.service.ts @@ -3,14 +3,15 @@ import { buildAnalysisContext } from "../context/context.service.js"; import { generateContent } from "../gemini/gemini.client.js"; import { cleanJson } from "../parser/json-cleaner.js"; import { parseJson } from "../parser/json-parser.js"; -import { validateEngineeringReport } from "../parser/schema-validator.js"; +import { validateModelReport } from "../parser/schema-validator.js"; +import { groundReport } from "../grounding/grounding.service.js"; import { buildPrompt } from "../prompt/prompt.builder.js"; import { repairResponse } from "../repair/repair.service.js"; import { buildMarkdown } from "../report/markdown.service.js"; import { buildGenerationTrace } from "../trace/trace.service.js"; import { env } from "../../config/env.js"; -import type { EngineeringReport } from "../report/report.types.js"; +import type { ModelReport } from "../report/report.types.js"; import type { JobContext } from "../../jobs/job.types.js"; import type { AnalysisRequest, @@ -32,8 +33,8 @@ const BUDGET_RESERVE_CHARS = 20_000; * Cleans, parses and validates a raw model response. * Throws on invalid JSON or schema mismatch. */ -function toReport(rawResponse: string): EngineeringReport { - return validateEngineeringReport( +function toReport(rawResponse: string): ModelReport { + return validateModelReport( parseJson(cleanJson(rawResponse)), ); } @@ -108,14 +109,14 @@ export async function analyzeRepository( job.setStage("VALIDATING_RESPONSE"); - let report: EngineeringReport; + let modelReport: ModelReport; let finalResponse = generation.text; let promptTokens = generation.promptTokens; let outputTokens = generation.outputTokens; let repairAttempts = 0; try { - report = toReport(generation.text); + modelReport = toReport(generation.text); } catch (validationError) { // Covers both invalid JSON and schema mismatches. await job.logger.warn( @@ -134,9 +135,17 @@ export async function analyzeRepository( promptTokens = addTokens(promptTokens, repair.promptTokens); outputTokens = addTokens(outputTokens, repair.outputTokens); - report = toReport(finalResponse); + modelReport = toReport(finalResponse); } + // Remove invented citations; attach real code to valid ones. + const { report, stats: citations } = groundReport( + modelReport, + context.files.files, + ); + + await job.logger.info("Citations checked", citations); + await job.logger.validatedReport(report); job.setStage("GENERATING_MARKDOWN"); @@ -154,6 +163,7 @@ export async function analyzeRepository( outputTokens, filesIncluded: context.files.files.length, filesAvailable: context.files.totalFiles, + citations, repaired: repairAttempts > 0, repairAttempts, }); diff --git a/apps/backend/src/ai/context/context.service.ts b/apps/backend/src/ai/context/context.service.ts index b54ddc4..3f07572 100644 --- a/apps/backend/src/ai/context/context.service.ts +++ b/apps/backend/src/ai/context/context.service.ts @@ -11,6 +11,7 @@ import type { FileContext, } from "./context.types.js"; import { rankFiles } from "./file-ranking.js"; +import { MAX_FILE_CONTENT_CHARS } from "../../constants/repository.js"; /** * Approximate prompt characters used by a file section's header @@ -18,6 +19,11 @@ import { rankFiles } from "./file-ranking.js"; */ const FILE_SECTION_OVERHEAD_CHARS = 120; +/** + * Characters added per line by the " 42| " line-number prefix. + */ +const LINE_NUMBER_OVERHEAD_CHARS = 7; + const EXCLUDED_FILES = new Set([ "LICENSE", "LICENSE.md", @@ -112,12 +118,28 @@ function getLanguage(filePath: string): string { } } +/** + * Shortens long files for the prompt, cutting at a line break so + * every line the model sees is complete and citable. + */ +function truncateAtLine(content: string, maxChars: number): string { + if (content.length <= maxChars) { + return content; + } + + const cut = content.lastIndexOf("\n", maxChars); + + return content.slice(0, cut > 0 ? cut : maxChars); +} + function toContextFile(file: RepositoryFile): ContextFile { + const content = truncateAtLine(file.content, MAX_FILE_CONTENT_CHARS); + return { path: file.relativePath, language: getLanguage(file.relativePath), - content: file.content, - truncated: file.truncated, + content, + truncated: content.length < file.content.length, }; } @@ -156,13 +178,18 @@ function selectFiles( let remaining = fileCharBudget; for (const file of ranked) { + const contextFile = toContextFile(file); + + const lineCount = contextFile.content.split("\n").length; + const cost = - file.content.length + + contextFile.content.length + + lineCount * LINE_NUMBER_OVERHEAD_CHARS + file.relativePath.length + FILE_SECTION_OVERHEAD_CHARS; if (cost <= remaining) { - included.push(toContextFile(file)); + included.push(contextFile); remaining -= cost; } else { omittedFiles.push(file.relativePath); diff --git a/apps/backend/src/ai/context/file-ranking.ts b/apps/backend/src/ai/context/file-ranking.ts index 69b3684..d23c8a2 100644 --- a/apps/backend/src/ai/context/file-ranking.ts +++ b/apps/backend/src/ai/context/file-ranking.ts @@ -7,12 +7,13 @@ import type { RepositoryFile } from "../../types/repository.js"; * so the most informative files fit into the prompt budget first. * * Tiers (lower is better): - * 0 root README, manifests and build/deploy config - * 1 entry points (index/main/app/server/...) near the root - * 2 a few test files (enough to judge testing practice) - * 3 other source files, most-imported first - * 4 remaining tests - * 5 docs, styles, markup and data files + * 0 root README (explains what the project is) + * 1 manifests, build/deploy config and CI workflows + * 2 entry points (index/main/app/server/...) near the root + * 3 a few test files (enough to judge testing practice) + * 4 other source files, most-imported first + * 5 remaining tests + * 6 docs, styles, markup and data files * * Import counts come from a lightweight regex scan of relative * imports in JS/TS and Python. Other languages fall back to @@ -176,32 +177,35 @@ export function rankFiles(files: RepositoryFile[]): RepositoryFile[] { const extension = path.extname(file.name).toLowerCase(); const depth = depthOf(file.relativePath); + if (depth === 0 && /^readme(\.|$)/i.test(file.name)) { + return 0; + } + if ( (depth <= 2 && MANIFEST_NAMES.has(file.name)) || - (depth === 0 && /^readme(\.|$)/i.test(file.name)) || isWorkflowFile(file.relativePath) ) { - return 0; + return 1; } if (!CODE_EXTENSIONS.has(extension)) { - return 5; + return 6; } if (isTestPath(file.relativePath)) { if (earlyTests < MAX_EARLY_TESTS) { earlyTests++; - return 2; + return 3; } - return 4; + return 5; } if (depth <= 3 && ENTRY_STEMS.has(stemOf(file.name).toLowerCase())) { - return 1; + return 2; } - return 3; + return 4; }; // Deterministic input order so "first N tests" is stable. diff --git a/apps/backend/src/ai/gemini/gemini.client.ts b/apps/backend/src/ai/gemini/gemini.client.ts index 17c39f7..db2b3fb 100644 --- a/apps/backend/src/ai/gemini/gemini.client.ts +++ b/apps/backend/src/ai/gemini/gemini.client.ts @@ -49,6 +49,7 @@ export async function generateContent( prompt.responseMimeType, responseJsonSchema: prompt.responseJsonSchema, + temperature: env.GEMINI_TEMPERATURE, }, }); diff --git a/apps/backend/src/ai/grounding/grounding.service.ts b/apps/backend/src/ai/grounding/grounding.service.ts new file mode 100644 index 0000000..e86e0bc --- /dev/null +++ b/apps/backend/src/ai/grounding/grounding.service.ts @@ -0,0 +1,273 @@ +import type { ContextFile } from "../context/context.types.js"; +import type { + EngineeringReport, + EvidenceReference, + ModelReport, +} from "../report/report.types.js"; + +/** + * Lines of context shown above and below a cited line. + */ +const SNIPPET_RADIUS = 2; + +const MAX_SNIPPET_LINE_CHARS = 300; + +/** + * How far a cited line may be moved to reach the code it describes. + */ +const SNAP_RADIUS = 5; + +export interface GroundingStats { + /** Citations the model produced. */ + total: number; + /** File and line exist in what the model was shown; snippet attached. */ + verified: number; + /** Of the verified, how many were moved to the line holding the quoted code. */ + adjusted: number; + /** File exists, but the line was missing or out of range (line removed). */ + fileOnly: number; + /** File not found among the files shown to the model (citation removed). */ + dropped: number; +} + +interface ShownFile { + path: string; + lines: string[]; +} + +type ModelEvidence = ModelReport["strengths"][number]["evidence"][number]; + +/** + * Resolves a path written by the model to a file it was shown. + */ +class PathResolver { + private readonly byPath = new Map(); + + constructor(files: ContextFile[]) { + for (const file of files) { + this.byPath.set(file.path.replaceAll("\\", "/"), { + path: file.path, + lines: file.content.split(/\r?\n/), + }); + } + } + + resolve(rawPath: string): ShownFile | undefined { + const normalized = rawPath + .trim() + .replace(/^`+|`+$/g, "") + .replaceAll("\\", "/") + .replace(/^\.?\//, ""); + + if (!normalized) { + return undefined; + } + + const exact = this.byPath.get(normalized); + + if (exact) { + return exact; + } + + // The model sometimes prefixes the repository name or a parent + // folder ("myrepo/src/app.ts"): drop leading segments. + const segments = normalized.split("/"); + + for (let i = 1; i < segments.length; i++) { + const candidate = this.byPath.get(segments.slice(i).join("/")); + + if (candidate) { + return candidate; + } + } + + // Or it shortens the path ("app.ts" for "src/app.ts"): accept a + // suffix match only when it is unambiguous. + const suffixMatches = [...this.byPath.entries()].filter(([path]) => + path.endsWith(`/${normalized}`), + ); + + return suffixMatches.length === 1 ? suffixMatches[0][1] : undefined; + } +} + +/** + * Splits "src/app.ts:42" into a path and a line number. + */ +function splitEmbeddedLine( + file: string, + line: number | undefined, +): { file: string; line: number | undefined } { + const match = file.match(/^(.*?):(\d+)(?:-\d+)?$/); + + if (match && line === undefined) { + return { file: match[1], line: Number(match[2]) }; + } + + return { file: match ? match[1] : file, line }; +} + +/** + * Text the description quotes from the code: `backticked code`, or a + * 'quoted phrase' / "quoted phrase" (matched by its first 24 chars). + */ +function quotedCode(description: string): string[] { + const code = [...description.matchAll(/`([^`]{3,80})`/g)].map((match) => + match[1].replace(/\(\)$/, "").trim(), + ); + + const phrases = [ + ...description.matchAll(/(?:^|[\s:(])['"]([^'"]{8,200})['"]/g), + ].map((match) => match[1].trim().slice(0, 24)); + + return [...code, ...phrases].filter((token) => token.length >= 3); +} + +/** + * Moves a cited line to the nearest line (within SNAP_RADIUS) that + * contains code quoted in the description, if the cited line does not. + * Models are often off by a few lines. + */ +function snapToQuotedCode( + lines: string[], + line: number, + description: string, +): number { + const tokens = quotedCode(description); + + const matches = (lineNumber: number) => + tokens.some((token) => lines[lineNumber - 1]?.includes(token)); + + if (tokens.length === 0 || matches(line)) { + return line; + } + + for (let distance = 1; distance <= SNAP_RADIUS; distance++) { + for (const candidate of [line - distance, line + distance]) { + if (candidate >= 1 && candidate <= lines.length && matches(candidate)) { + return candidate; + } + } + } + + return line; +} + +function buildSnippet( + lines: string[], + line: number, +): EvidenceReference["snippet"] { + const start = Math.max(1, line - SNIPPET_RADIUS); + const end = Math.min(lines.length, line + SNIPPET_RADIUS); + + return { + startLine: start, + lines: lines + .slice(start - 1, end) + .map((text) => + text.length > MAX_SNIPPET_LINE_CHARS + ? `${text.slice(0, MAX_SNIPPET_LINE_CHARS)}…` + : text, + ), + }; +} + +/** + * Checks every citation in the model's report against the files the + * model was actually shown: + * + * - unknown files are removed (they would be hallucinated references) + * - out-of-range lines are removed, keeping the file reference + * - valid lines get a snippet of the real code around them + * - paths are rewritten to the exact repository path + */ +export function groundReport( + report: ModelReport, + shownFiles: ContextFile[], +): { report: EngineeringReport; stats: GroundingStats } { + const resolver = new PathResolver(shownFiles); + + const stats: GroundingStats = { + total: 0, + verified: 0, + adjusted: 0, + fileOnly: 0, + dropped: 0, + }; + + const groundEvidence = ( + evidence: ModelEvidence[], + ): EvidenceReference[] => { + const result: EvidenceReference[] = []; + const seen = new Set(); + + for (const item of evidence) { + const { file, line } = splitEmbeddedLine(item.file, item.line); + const shown = resolver.resolve(file); + + if (!shown) { + stats.dropped++; + continue; + } + + const inRange = + line !== undefined && + Number.isInteger(line) && + line >= 1 && + line <= shown.lines.length; + + const validLine = inRange + ? snapToQuotedCode(shown.lines, line, item.description) + : undefined; + + const key = `${shown.path}:${validLine ?? ""}:${item.description}`; + + if (seen.has(key)) { + continue; + } + + seen.add(key); + + if (validLine === undefined) { + stats.fileOnly++; + result.push({ file: shown.path, description: item.description }); + continue; + } + + stats.verified++; + + if (validLine !== line) { + stats.adjusted++; + } + result.push({ + file: shown.path, + line: validLine, + description: item.description, + snippet: buildSnippet(shown.lines, validLine), + }); + } + + return result; + }; + + const grounded: EngineeringReport = { + ...report, + strengths: report.strengths.map((finding) => ({ + ...finding, + evidence: groundEvidence(finding.evidence), + })), + weaknesses: report.weaknesses.map((finding) => ({ + ...finding, + evidence: groundEvidence(finding.evidence), + })), + improvements: report.improvements.map((improvement) => ({ + ...improvement, + evidence: groundEvidence(improvement.evidence), + })), + }; + + // Exact duplicates are merged silently and not counted. + stats.total = stats.verified + stats.fileOnly + stats.dropped; + + return { report: grounded, stats }; +} diff --git a/apps/backend/src/ai/parser/schema-validator.ts b/apps/backend/src/ai/parser/schema-validator.ts index b7c350b..4c9fd26 100644 --- a/apps/backend/src/ai/parser/schema-validator.ts +++ b/apps/backend/src/ai/parser/schema-validator.ts @@ -1,12 +1,10 @@ -import { engineeringReportSchema } from "../report/report.schema.js"; +import { modelReportSchema } from "../report/report.schema.js"; -import type { EngineeringReport } from "../report/report.types.js"; +import type { ModelReport } from "../report/report.types.js"; /** - * Validates an EngineeringReport. Throws a ZodError when invalid. + * Validates the model's report. Throws a ZodError when invalid. */ -export function validateEngineeringReport( - data: unknown, -): EngineeringReport { - return engineeringReportSchema.parse(data); +export function validateModelReport(data: unknown): ModelReport { + return modelReportSchema.parse(data); } diff --git a/apps/backend/src/ai/prompt/prompt.builder.ts b/apps/backend/src/ai/prompt/prompt.builder.ts index 74fa45c..2e2350e 100644 --- a/apps/backend/src/ai/prompt/prompt.builder.ts +++ b/apps/backend/src/ai/prompt/prompt.builder.ts @@ -2,7 +2,6 @@ import type { AnalysisContext, ContextFile } from "../context/context.types.js"; import type { PromptSpec } from "./prompt.types.js"; import { SYSTEM_INSTRUCTION, ANALYSIS_TASK, REPORT_REQUIREMENTS } from "./prompt.constants.js"; import { ENGINEERING_REPORT_JSON_SCHEMA } from "../report/report.json-schema.js"; -import { MAX_FILE_CONTENT_CHARS } from "../../constants/repository.js"; /** * Objective repository measurements. @@ -24,8 +23,6 @@ function buildMetricsSection( return [ "## Repository Metrics", "", - `(Line counts cover at most the first ${MAX_FILE_CONTENT_CHARS} characters of each file.)`, - "", `Lines: ${code.totalLinesOfCode} total, ${code.sourceLinesOfCode} source, ${code.commentLines} comment, ${code.blankLines} blank`, "", "Languages by lines:", @@ -57,10 +54,10 @@ function buildStaticAnalysisSection( return [ "## Static Analysis", "", - "These counts come from lightweight pattern matching and are approximate.", - "Verify against the source files before citing a specific number.", + "Function, TypeScript and logging counts come from parsing JavaScript/TypeScript files (syntax only).", + "Test and duplicate counts are based on file names and are approximate.", "", - `Functions (JavaScript/TypeScript only): ${functions.totalFunctions} detected, average ${functions.averageFunctionLength} lines, longest ${functions.longestFunctionLines} lines, ${functions.functionsOver50Lines} over 50 lines, ${functions.functionsOver100Lines} over 100 lines`, + `Functions and methods with a block body (JavaScript/TypeScript only): ${functions.totalFunctions}, average ${functions.averageFunctionLength} lines, longest ${functions.longestFunctionLines} lines, ${functions.functionsOver50Lines} over 50 lines, ${functions.functionsOver100Lines} over 100 lines`, "", `TypeScript: ${typescript.anyUsages} "any", ${typescript.typeAssertions} type assertions (excluding "as const"), ${typescript.tsIgnoreCount} @ts-ignore, ${typescript.eslintDisableCount} eslint-disable`, "", @@ -187,6 +184,19 @@ function buildStructureSection(context: AnalysisContext): string { /** * Formats a single source file. */ +/** + * Prefixes every line with its 1-based number (" 42| code"), so the + * model can cite exact lines instead of counting them. + */ +function numberLines(content: string): string { + const lines = content.split(/\r?\n/); + const width = String(lines.length).length; + + return lines + .map((line, index) => `${String(index + 1).padStart(width)}| ${line}`) + .join("\n"); +} + function buildFileSection(file: ContextFile): string { return [ "===== FILE =====", @@ -194,11 +204,11 @@ function buildFileSection(file: ContextFile): string { `Language: ${file.language}`, ...(file.truncated ? [ - `Note: truncated to the first ${MAX_FILE_CONTENT_CHARS} characters; the rest of this file is not shown.`, + `Note: only the first ${file.content.split("\n").length} lines are shown (the file is longer). Do not cite lines beyond them.`, ] : []), "", - file.content.trim(), + numberLines(file.content), "===== END FILE =====", ].join("\n"); } @@ -280,6 +290,8 @@ function buildUserPrompt(context: AnalysisContext): string { "Return one JSON object that follows the response schema.", "All scores are integers from 0 to 10.", "Only cite files and line numbers from the Source Files section below.", + 'Each source line is prefixed with its line number ("42| "). Cite that number; the prefix is not part of the code.', + "Use the exact path from the Path: line. Never cite section names (such as Repository Metrics) as files.", "Files listed under Files Not Included were not shown to you: you may mention", "that they exist, but do not describe or cite their contents.", ].join("\n"), diff --git a/apps/backend/src/ai/prompt/prompt.constants.ts b/apps/backend/src/ai/prompt/prompt.constants.ts index 3ba96ce..416eb59 100644 --- a/apps/backend/src/ai/prompt/prompt.constants.ts +++ b/apps/backend/src/ai/prompt/prompt.constants.ts @@ -55,8 +55,9 @@ Perform a professional engineering review of the supplied repository. The repository has already been analyzed. Repository Metrics are exact measurements of the supplied files. -Static Analysis and Repository Evidence are heuristic pattern matches: -use them as leads and confirm them against the source files. +Static Analysis and Repository Evidence come from parsing JavaScript/TypeScript +and from file-name conventions: use them as leads and confirm them against +the source files before relying on them. The source files are the final authority on implementation details. diff --git a/apps/backend/src/ai/report/markdown.service.ts b/apps/backend/src/ai/report/markdown.service.ts index 1f0ca05..4100b20 100644 --- a/apps/backend/src/ai/report/markdown.service.ts +++ b/apps/backend/src/ai/report/markdown.service.ts @@ -1,10 +1,41 @@ import type { EngineeringReport, + EvidenceReference, Finding, Improvement, InterviewQuestion, } from "./report.types.js"; +/** + * Formats checked citations, with the real code where available. + */ +function formatEvidence(evidence: EvidenceReference[]): string { + if (evidence.length === 0) { + return ""; + } + + const items = evidence.map((item) => { + const location = item.line ? `${item.file}:${item.line}` : item.file; + const header = `- \`${location}\` — ${item.description}`; + + if (!item.snippet) { + return header; + } + + const code = item.snippet.lines + .map((text, index) => { + const lineNumber = item.snippet!.startLine + index; + const marker = lineNumber === item.line ? ">" : " "; + return `${marker} ${String(lineNumber).padStart(4)} | ${text}`; + }) + .join("\n"); + + return `${header}\n\n \`\`\`\n${code.replace(/^/gm, " ")}\n \`\`\``; + }); + + return ["", "**Evidence**", "", ...items].join("\n"); +} + /** * Formats a bullet list. */ @@ -28,21 +59,7 @@ function formatFindings( return findings .map((finding) => { - const evidence = - finding.evidence.length === 0 - ? "" - : [ - "", - "**Evidence**", - ...finding.evidence.map( - (item) => - `- ${item.file}${ - item.line - ? `:${item.line}` - : "" - } — ${item.description}`, - ), - ].join("\n"); + const evidence = formatEvidence(finding.evidence); return [ `### ${finding.title}`, @@ -66,21 +83,7 @@ function formatImprovements( return improvements .map((item) => { - const evidence = - item.evidence.length === 0 - ? "" - : [ - "", - "**Evidence**", - ...item.evidence.map( - (e) => - `- ${e.file}${ - e.line - ? `:${e.line}` - : "" - } — ${e.description}`, - ), - ].join("\n"); + const evidence = formatEvidence(item.evidence); return [ `## ${item.title}`, diff --git a/apps/backend/src/ai/report/report.json-schema.ts b/apps/backend/src/ai/report/report.json-schema.ts index 3d678df..fbb63c2 100644 --- a/apps/backend/src/ai/report/report.json-schema.ts +++ b/apps/backend/src/ai/report/report.json-schema.ts @@ -1,6 +1,6 @@ import { z } from "zod"; -import { engineeringReportSchema } from "./report.schema.js"; +import { modelReportSchema } from "./report.schema.js"; /** * JSON Schema for Gemini structured output, generated from the Zod @@ -9,7 +9,7 @@ import { engineeringReportSchema } from "./report.schema.js"; * Gemini does not need it. */ const { $schema: _ignored, ...jsonSchema } = z.toJSONSchema( - engineeringReportSchema, + modelReportSchema, { io: "input" }, ); diff --git a/apps/backend/src/ai/report/report.schema.ts b/apps/backend/src/ai/report/report.schema.ts index 15b8c96..be7907a 100644 --- a/apps/backend/src/ai/report/report.schema.ts +++ b/apps/backend/src/ai/report/report.schema.ts @@ -10,36 +10,55 @@ const scoreSchema = z .max(10) .transform((value) => Math.round(value)); -const evidenceReferenceSchema = z.object({ +/** + * A citation as the model writes it. + */ +const modelEvidenceSchema = z.object({ file: z.string(), line: z.number().optional(), description: z.string(), }); -const findingSchema = z.object({ - title: z.string(), - description: z.string(), - evidence: z.array(evidenceReferenceSchema), +/** + * Lines of real code around a cited line, added by the backend + * after checking the citation (never written by the model). + */ +const evidenceSnippetSchema = z.object({ + startLine: z.number(), + lines: z.array(z.string()), }); -const improvementSchema = z.object({ - title: z.string(), - priority: z.enum([ - "High", - "Medium", - "Low", - ]), - category: z.string(), - problem: z.string(), - recommendation: z.string(), - expectedImpact: z.string(), - evidence: z.array( - evidenceReferenceSchema, - ), +/** + * A citation in the final report: checked against the repository. + * `file` is the real repository path; `line` and `snippet` are present + * only when the cited line exists in what the model was shown. + */ +const evidenceReferenceSchema = modelEvidenceSchema.extend({ + snippet: evidenceSnippetSchema.optional(), }); -export const engineeringReportSchema = - z.object({ +/** + * Builds the report schema around a given citation schema, so the + * model's output and the final report share every other field. + */ +function buildReportSchema(evidence: Evidence) { + const findingSchema = z.object({ + title: z.string(), + description: z.string(), + evidence: z.array(evidence), + }); + + const improvementSchema = z.object({ + title: z.string(), + priority: z.enum(["High", "Medium", "Low"]), + category: z.string(), + problem: z.string(), + recommendation: z.string(), + expectedImpact: z.string(), + evidence: z.array(evidence), + }); + + return z.object({ summary: z.object({ purpose: z.string(), description: z.string(), @@ -50,9 +69,7 @@ export const engineeringReportSchema = frameworks: z.array(z.string()), databases: z.array(z.string()), tools: z.array(z.string()), - infrastructure: z.array( - z.string(), - ), + infrastructure: z.array(z.string()), }), architecture: z.object({ @@ -67,71 +84,65 @@ export const engineeringReportSchema = score: scoreSchema, positives: z.array(z.string()), negatives: z.array(z.string()), - recommendations: z.array( - z.string(), - ), + recommendations: z.array(z.string()), }), codeQuality: z.object({ score: scoreSchema, positives: z.array(z.string()), negatives: z.array(z.string()), - recommendations: z.array( - z.string(), - ), + recommendations: z.array(z.string()), }), - strengths: z.array( - findingSchema, - ), + strengths: z.array(findingSchema), - weaknesses: z.array( - findingSchema, - ), + weaknesses: z.array(findingSchema), - improvements: z.array( - improvementSchema, - ), + improvements: z.array(improvementSchema), resumeFeedback: z.object({ score: scoreSchema, summary: z.string(), strengths: z.array(z.string()), - improvements: z.array( - z.string(), - ), - bestResumeBullets: z.array( - z.string(), - ), + improvements: z.array(z.string()), + bestResumeBullets: z.array(z.string()), }), interviewQuestions: z.array( z.object({ question: z.string(), - difficulty: z.enum([ - "Easy", - "Medium", - "Hard", - ]), + difficulty: z.enum(["Easy", "Medium", "Hard"]), category: z.string(), reason: z.string(), - expectedAnswer: - z.string(), + expectedAnswer: z.string(), }), ), }); +} + +/** + * What the model must return (also sent to Gemini as JSON Schema). + */ +export const modelReportSchema = buildReportSchema(modelEvidenceSchema); + +/** + * The final report sent to the frontend, with checked citations. + */ +export const engineeringReportSchema = buildReportSchema( + evidenceReferenceSchema, +); + +export type ModelReport = z.infer; + +export type EngineeringReport = z.infer; -export type EngineeringReport = z.infer< - typeof engineeringReportSchema ->; +export type EvidenceReference = z.infer; -export type EvidenceReference = z.infer< - typeof evidenceReferenceSchema ->; +export type EvidenceSnippet = z.infer; -export type Finding = z.infer; +export type Finding = EngineeringReport["strengths"][number]; -export type Improvement = z.infer; +export type Improvement = EngineeringReport["improvements"][number]; export type InterviewQuestion = - EngineeringReport["interviewQuestions"][number]; \ No newline at end of file + EngineeringReport["interviewQuestions"][number]; diff --git a/apps/backend/src/ai/report/report.types.ts b/apps/backend/src/ai/report/report.types.ts index 6959395..8b3dd18 100644 --- a/apps/backend/src/ai/report/report.types.ts +++ b/apps/backend/src/ai/report/report.types.ts @@ -5,7 +5,9 @@ export type { EngineeringReport, EvidenceReference, + EvidenceSnippet, Finding, Improvement, InterviewQuestion, + ModelReport, } from "./report.schema.js"; diff --git a/apps/backend/src/ai/trace/trace.types.ts b/apps/backend/src/ai/trace/trace.types.ts index 659b111..63b9946 100644 --- a/apps/backend/src/ai/trace/trace.types.ts +++ b/apps/backend/src/ai/trace/trace.types.ts @@ -1,3 +1,5 @@ +import type { GroundingStats } from "../grounding/grounding.service.js"; + export interface GenerationTrace { startedAt: string; finishedAt: string; @@ -21,6 +23,11 @@ export interface GenerationTrace { filesIncluded: number; filesAvailable: number; + /** + * Result of checking the model's citations against the repository. + */ + citations: GroundingStats; + repaired: boolean; repairAttempts: number; } diff --git a/apps/backend/src/config/env.ts b/apps/backend/src/config/env.ts index 46255f9..1e22f13 100644 --- a/apps/backend/src/config/env.ts +++ b/apps/backend/src/config/env.ts @@ -20,6 +20,11 @@ const envSchema = z.object({ * ranked by importance and added until this budget is reached. */ MAX_PROMPT_TOKENS: z.coerce.number().int().min(10_000).default(150_000), + /** + * Optional sampling temperature (0-2). Lower values make repeated + * reviews of the same repository more consistent. Unset = model default. + */ + GEMINI_TEMPERATURE: z.coerce.number().min(0).max(2).optional(), SAVE_DEBUG_ARTIFACTS: z .enum(["true", "false"]) .default("false") diff --git a/apps/backend/src/repository/evidence/evidence.service.ts b/apps/backend/src/repository/evidence/evidence.service.ts index 3de9a97..651ca95 100644 --- a/apps/backend/src/repository/evidence/evidence.service.ts +++ b/apps/backend/src/repository/evidence/evidence.service.ts @@ -3,9 +3,7 @@ import type { RepositoryFile } from "../../types/repository.js"; import type { RepositoryEvidence } from "./evidence.types.js"; import { buildAnnotationEvidence } from "../static-analysis/todo-evidence.js"; -import { buildFunctionEvidence } from "./function-evidence.js"; -import { buildLoggingEvidence } from "./logging-evidence.js"; -import { buildTypeScriptEvidence } from "./typescript-evidence.js"; +import type { SourceFacts } from "../static-analysis/source-facts.js"; /** * Builds complete repository evidence. @@ -16,23 +14,13 @@ import { buildTypeScriptEvidence } from "./typescript-evidence.js"; */ export function buildRepositoryEvidence( files: RepositoryFile[], + facts: SourceFacts, ): RepositoryEvidence { - const functions = - buildFunctionEvidence(files); - - const logging = - buildLoggingEvidence(files); - - const typescript = - buildTypeScriptEvidence(files); - - const annotations = - buildAnnotationEvidence(files); - return { - functions, - logging, - typescript, - annotations, + // Longest first: the prompt shows the top entries. + functions: [...facts.functions].sort((a, b) => b.length - a.length), + logging: facts.logging, + typescript: facts.typescript, + annotations: buildAnnotationEvidence(files), }; -} \ No newline at end of file +} diff --git a/apps/backend/src/repository/evidence/evidence.types.ts b/apps/backend/src/repository/evidence/evidence.types.ts index 7068abb..7f9b92f 100644 --- a/apps/backend/src/repository/evidence/evidence.types.ts +++ b/apps/backend/src/repository/evidence/evidence.types.ts @@ -1,4 +1,7 @@ -import type { TypeScriptPatternType } from "../static-analysis/typescript-patterns.js"; +import type { + LoggingType, + TypeScriptIssueType, +} from "../static-analysis/source-facts.js"; /** * Base location inside a repository. @@ -22,12 +25,7 @@ export interface FunctionEvidence extends SourceLocation { * Evidence for logging statements. */ export interface LoggingEvidence extends SourceLocation { - type: - | "console.log" - | "console.error" - | "console.warn" - | "debugger" - | "process.exit"; + type: LoggingType; } /** @@ -35,7 +33,7 @@ export interface LoggingEvidence extends SourceLocation { */ export interface TypeScriptEvidence extends SourceLocation { - type: TypeScriptPatternType; + type: TypeScriptIssueType; } /** diff --git a/apps/backend/src/repository/evidence/function-evidence.ts b/apps/backend/src/repository/evidence/function-evidence.ts deleted file mode 100644 index 2f241ef..0000000 --- a/apps/backend/src/repository/evidence/function-evidence.ts +++ /dev/null @@ -1,174 +0,0 @@ -import path from "node:path"; - -import type { RepositoryFile } from "../../types/repository.js"; -import type { FunctionEvidence } from "./evidence.types.js"; - -const SUPPORTED_EXTENSIONS = new Set([ - ".ts", - ".tsx", - ".js", - ".jsx", -]); - -/** - * Attempts to extract a function name from a line. - */ -function extractFunctionName( - line: string, -): string { - const trimmed = line.trim(); - - let match = - trimmed.match( - /^export\s+default\s+function\s+([A-Za-z0-9_$]+)/, - ) ?? - trimmed.match( - /^export\s+function\s+([A-Za-z0-9_$]+)/, - ) ?? - trimmed.match( - /^async\s+function\s+([A-Za-z0-9_$]+)/, - ) ?? - trimmed.match( - /^function\s+([A-Za-z0-9_$]+)/, - ); - - if (match) { - return match[1]; - } - - match = - trimmed.match( - /^const\s+([A-Za-z0-9_$]+)\s*=\s*/, - ) ?? - trimmed.match( - /^let\s+([A-Za-z0-9_$]+)\s*=\s*/, - ) ?? - trimmed.match( - /^var\s+([A-Za-z0-9_$]+)\s*=\s*/, - ); - - if (match) { - return match[1]; - } - - return "anonymous"; -} - -/** - * Determines whether a line probably starts a function. - */ -function isFunctionStart( - line: string, -): boolean { - const trimmed = line.trim(); - - return ( - /^function\s+/.test(trimmed) || - /^export\s+function/.test(trimmed) || - /^export\s+default\s+function/.test(trimmed) || - /^async\s+function/.test(trimmed) || - /^const\s+\w+\s*=.*=>/.test(trimmed) || - /^let\s+\w+\s*=.*=>/.test(trimmed) || - /^var\s+\w+\s*=.*=>/.test(trimmed) - ); -} - -/** - * Extracts approximate function locations. - */ -export function buildFunctionEvidence( - files: RepositoryFile[], -): FunctionEvidence[] { - const evidence: FunctionEvidence[] = []; - - for (const file of files) { - const extension = path - .extname(file.relativePath) - .toLowerCase(); - - if ( - !SUPPORTED_EXTENSIONS.has(extension) - ) { - continue; - } - - const lines = - file.content.split(/\r?\n/); - - let insideFunction = false; - - let braceDepth = 0; - - let startLine = 0; - - let length = 0; - - let name = "anonymous"; - - for ( - let index = 0; - index < lines.length; - index++ - ) { - const line = lines[index]; - - if ( - !insideFunction && - isFunctionStart(line) - ) { - insideFunction = true; - - startLine = index + 1; - - length = 1; - - name = - extractFunctionName(line); - - braceDepth = - (line.match(/\{/g)?.length ?? - 0) - - (line.match(/\}/g)?.length ?? - 0); - - continue; - } - - if (!insideFunction) { - continue; - } - - length++; - - braceDepth += - line.match(/\{/g)?.length ?? - 0; - - braceDepth -= - line.match(/\}/g)?.length ?? - 0; - - if (braceDepth <= 0) { - evidence.push({ - file: file.relativePath, - - line: startLine, - - name, - - length, - }); - - insideFunction = false; - - braceDepth = 0; - - length = 0; - } - } - } - - return evidence.sort( - (a, b) => b.length - a.length, - ); -} \ No newline at end of file diff --git a/apps/backend/src/repository/evidence/logging-evidence.ts b/apps/backend/src/repository/evidence/logging-evidence.ts deleted file mode 100644 index 353926a..0000000 --- a/apps/backend/src/repository/evidence/logging-evidence.ts +++ /dev/null @@ -1,82 +0,0 @@ -import path from "node:path"; - -import type { RepositoryFile } from "../../types/repository.js"; -import type { LoggingEvidence } from "./evidence.types.js"; - -const SUPPORTED_EXTENSIONS = new Set([ - ".ts", - ".tsx", - ".js", - ".jsx", -]); - -interface Pattern { - type: LoggingEvidence["type"]; - regex: RegExp; -} - -const PATTERNS: Pattern[] = [ - { - type: "console.log", - regex: /\bconsole\.log\s*\(/, - }, - { - type: "console.error", - regex: /\bconsole\.error\s*\(/, - }, - { - type: "console.warn", - regex: /\bconsole\.warn\s*\(/, - }, - { - type: "debugger", - regex: /\bdebugger\b/, - }, - { - type: "process.exit", - regex: /\bprocess\.exit\s*\(/, - }, -]; - -/** - * Extracts logging/debugging statements with their locations. - */ -export function buildLoggingEvidence( - files: RepositoryFile[], -): LoggingEvidence[] { - const evidence: LoggingEvidence[] = []; - - for (const file of files) { - const extension = path - .extname(file.relativePath) - .toLowerCase(); - - if (!SUPPORTED_EXTENSIONS.has(extension)) { - continue; - } - - const lines = file.content.split(/\r?\n/); - - for ( - let index = 0; - index < lines.length; - index++ - ) { - const line = lines[index]; - - for (const pattern of PATTERNS) { - if (!pattern.regex.test(line)) { - continue; - } - - evidence.push({ - file: file.relativePath, - line: index + 1, - type: pattern.type, - }); - } - } - } - - return evidence; -} \ No newline at end of file diff --git a/apps/backend/src/repository/evidence/typescript-evidence.ts b/apps/backend/src/repository/evidence/typescript-evidence.ts deleted file mode 100644 index 7534a6c..0000000 --- a/apps/backend/src/repository/evidence/typescript-evidence.ts +++ /dev/null @@ -1,49 +0,0 @@ -import path from "node:path"; - -import type { RepositoryFile } from "../../types/repository.js"; -import type { TypeScriptEvidence } from "./evidence.types.js"; -import { matchTypeScriptLine } from "../static-analysis/typescript-patterns.js"; - -const SUPPORTED_EXTENSIONS = new Set([ - ".ts", - ".tsx", -]); - -/** - * Extracts TypeScript-specific evidence from the repository. - */ -export function buildTypeScriptEvidence( - files: RepositoryFile[], -): TypeScriptEvidence[] { - const evidence: TypeScriptEvidence[] = []; - - for (const file of files) { - const extension = path - .extname(file.relativePath) - .toLowerCase(); - - if (!SUPPORTED_EXTENSIONS.has(extension)) { - continue; - } - - const lines = file.content.split(/\r?\n/); - - for ( - let index = 0; - index < lines.length; - index++ - ) { - const line = lines[index]; - - for (const type of matchTypeScriptLine(line)) { - evidence.push({ - file: file.relativePath, - line: index + 1, - type, - }); - } - } - } - - return evidence; -} \ No newline at end of file diff --git a/apps/backend/src/repository/metadata/metadata.service.ts b/apps/backend/src/repository/metadata/metadata.service.ts index ff8ecd2..d7eb708 100644 --- a/apps/backend/src/repository/metadata/metadata.service.ts +++ b/apps/backend/src/repository/metadata/metadata.service.ts @@ -2,6 +2,7 @@ import path from "node:path"; import { buildRepositoryMetrics } from "../metrics/metrics.service.js"; import { buildStaticAnalysis } from "../static-analysis/analysis.service.js"; import { buildRepositoryEvidence } from "../evidence/evidence.service.js"; +import { extractSourceFacts } from "../static-analysis/source-facts.js"; import type { RepositoryContent, @@ -195,12 +196,12 @@ export function buildRepositoryMetadata( ); - const staticAnalysis = buildStaticAnalysis(repository.files); + // One parse of every JS/TS file feeds both the counts and the locations. + const sourceFacts = extractSourceFacts(repository.files); - const evidence = - buildRepositoryEvidence( - repository.files, - ); + const staticAnalysis = buildStaticAnalysis(repository.files, sourceFacts); + + const evidence = buildRepositoryEvidence(repository.files, sourceFacts); return { repositoryName, diff --git a/apps/backend/src/repository/reader/reader.service.ts b/apps/backend/src/repository/reader/reader.service.ts index d3c4681..5b662ff 100644 --- a/apps/backend/src/repository/reader/reader.service.ts +++ b/apps/backend/src/repository/reader/reader.service.ts @@ -1,35 +1,24 @@ import fs from "node:fs/promises"; -import { - MAX_FILE_CONTENT_CHARS, -} from "../../constants/repository.js"; - import type { FilteredRepository, RepositoryContent, RepositoryFile, } from "../../types/repository.js"; +/** + * Reads the full content of every analyzable file. Files are at most + * MAX_FILE_SIZE_BYTES (filtering), so metrics and analyzers see whole + * files. Shortening for the prompt happens later, in the AI context. + */ async function readRepositoryFile( file: FilteredRepository["files"][number], ): Promise { - const rawContent = await fs.readFile( - file.absolutePath, - "utf8", - ); - - const truncated = - rawContent.length > MAX_FILE_CONTENT_CHARS; - - const content = truncated - ? rawContent.slice(0, MAX_FILE_CONTENT_CHARS) - : rawContent; + const content = await fs.readFile(file.absolutePath, "utf8"); return { ...file, content, - size: file.size, - truncated, }; } @@ -44,4 +33,4 @@ export async function readRepository( rootPath: repository.rootPath, files, }; -} \ No newline at end of file +} diff --git a/apps/backend/src/repository/static-analysis/analysis.service.ts b/apps/backend/src/repository/static-analysis/analysis.service.ts index 7e85bf1..86fd3af 100644 --- a/apps/backend/src/repository/static-analysis/analysis.service.ts +++ b/apps/backend/src/repository/static-analysis/analysis.service.ts @@ -1,6 +1,7 @@ import type { RepositoryFile } from "../../types/repository.js"; import type { StaticAnalysis } from "./analysis.types.js"; +import type { SourceFacts } from "./source-facts.js"; import { buildDuplicateAnalysis } from "./duplicate-analysis.js"; import { buildFunctionAnalysis } from "./function-analysis.js"; @@ -16,15 +17,13 @@ import { buildTypeScriptAnalysis } from "./typescript-analysis.js"; */ export function buildStaticAnalysis( files: RepositoryFile[], + facts: SourceFacts, ): StaticAnalysis { - const functions = - buildFunctionAnalysis(files); + const functions = buildFunctionAnalysis(facts); - const typescript = - buildTypeScriptAnalysis(files); + const typescript = buildTypeScriptAnalysis(facts); - const logging = - buildLoggingAnalysis(files); + const logging = buildLoggingAnalysis(facts); const tests = buildTestAnalysis(files); diff --git a/apps/backend/src/repository/static-analysis/function-analysis.ts b/apps/backend/src/repository/static-analysis/function-analysis.ts index 07c3482..8df9ce7 100644 --- a/apps/backend/src/repository/static-analysis/function-analysis.ts +++ b/apps/backend/src/repository/static-analysis/function-analysis.ts @@ -1,148 +1,24 @@ -import path from "node:path"; - -import type { RepositoryFile } from "../../types/repository.js"; import type { FunctionAnalysis } from "./analysis.types.js"; - -const SUPPORTED_EXTENSIONS = new Set([ - ".ts", - ".tsx", - ".js", - ".jsx", -]); +import type { SourceFacts } from "./source-facts.js"; /** - * Very lightweight heuristic that determines whether - * a line looks like a function declaration. + * Function statistics for JavaScript/TypeScript, from parsed source. + * Counts functions and methods with a block body (one-line arrow + * callbacks such as `x => x.id` are not counted). */ -function looksLikeFunction(line: string): boolean { - const trimmed = line.trim(); - - return ( - /^function\s+\w+/.test(trimmed) || - /^\w+\s*\([^)]*\)\s*\{?$/.test(trimmed) || - /^\w+\s*=\s*\([^)]*\)\s*=>/.test(trimmed) || - /^\w+\s*:\s*\([^)]*\)\s*=>/.test(trimmed) || - /^export\s+function/.test(trimmed) || - /^export\s+default\s+function/.test(trimmed) || - /^async\s+function/.test(trimmed) - ); -} - -/** - * Computes the approximate size of a function by tracking braces. - */ -function measureFunctions( - content: string, -): number[] { - const lines = content.split(/\r?\n/); - - const lengths: number[] = []; - - let insideFunction = false; - - let braceDepth = 0; - - let currentLength = 0; - - for (const line of lines) { - if (!insideFunction && looksLikeFunction(line)) { - insideFunction = true; - currentLength = 1; - - braceDepth = - (line.match(/\{/g)?.length ?? 0) - - (line.match(/\}/g)?.length ?? 0); - - continue; - } - - if (!insideFunction) { - continue; - } - - currentLength++; - - braceDepth += - (line.match(/\{/g)?.length ?? 0); - - braceDepth -= - (line.match(/\}/g)?.length ?? 0); +export function buildFunctionAnalysis(facts: SourceFacts): FunctionAnalysis { + const lengths = facts.functions.map((fn) => fn.length); - if (braceDepth <= 0) { - lengths.push(currentLength); - - insideFunction = false; - - currentLength = 0; - - braceDepth = 0; - } - } - - return lengths; -} - -/** - * Performs repository-wide function analysis. - */ -export function buildFunctionAnalysis( - files: RepositoryFile[], -): FunctionAnalysis { - const functionLengths: number[] = []; - - for (const file of files) { - const extension = path.extname( - file.relativePath, - ); - - if ( - !SUPPORTED_EXTENSIONS.has( - extension.toLowerCase(), - ) - ) { - continue; - } - - functionLengths.push( - ...measureFunctions(file.content), - ); - } - - const totalFunctions = - functionLengths.length; - - const longestFunctionLines = - functionLengths.length === 0 - ? 0 - : Math.max(...functionLengths); - - const averageFunctionLength = - functionLengths.length === 0 - ? 0 - : Number( - ( - functionLengths.reduce( - (sum, value) => sum + value, - 0, - ) / functionLengths.length - ).toFixed(1), - ); - - const functionsOver50Lines = - functionLengths.filter( - (length) => length > 50, - ).length; - - const functionsOver100Lines = - functionLengths.filter( - (length) => length > 100, - ).length; + const total = lengths.length; return { - totalFunctions, - averageFunctionLength, - longestFunctionLines, - functionsOver50Lines, - functionsOver100Lines, + totalFunctions: total, + averageFunctionLength: + total === 0 + ? 0 + : Number((lengths.reduce((sum, n) => sum + n, 0) / total).toFixed(1)), + longestFunctionLines: total === 0 ? 0 : Math.max(...lengths), + functionsOver50Lines: lengths.filter((n) => n > 50).length, + functionsOver100Lines: lengths.filter((n) => n > 100).length, }; -} \ No newline at end of file +} diff --git a/apps/backend/src/repository/static-analysis/logging-analysis.ts b/apps/backend/src/repository/static-analysis/logging-analysis.ts index 06a499f..9ccbd1a 100644 --- a/apps/backend/src/repository/static-analysis/logging-analysis.ts +++ b/apps/backend/src/repository/static-analysis/logging-analysis.ts @@ -1,89 +1,15 @@ -import path from "node:path"; - -import type { RepositoryFile } from "../../types/repository.js"; import type { LoggingAnalysis } from "./analysis.types.js"; +import type { SourceFacts } from "./source-facts.js"; -const SUPPORTED_EXTENSIONS = new Set([ - ".ts", - ".tsx", - ".js", - ".jsx", -]); - -interface Counters { - consoleLogCount: number; - consoleErrorCount: number; - consoleWarnCount: number; - debuggerCount: number; - processExitCount: number; -} - -/** - * Counts regex matches inside text. - */ -function countMatches( - text: string, - regex: RegExp, -): number { - return text.match(regex)?.length ?? 0; -} - -/** - * Performs repository-wide logging analysis. - */ -export function buildLoggingAnalysis( - files: RepositoryFile[], -): LoggingAnalysis { - const counters: Counters = { - consoleLogCount: 0, - consoleErrorCount: 0, - consoleWarnCount: 0, - debuggerCount: 0, - processExitCount: 0, - }; - - for (const file of files) { - const extension = path.extname( - file.relativePath, - ).toLowerCase(); - - if (!SUPPORTED_EXTENSIONS.has(extension)) { - continue; - } - - const content = file.content; - - counters.consoleLogCount += countMatches( - content, - /\bconsole\.log\s*\(/g, - ); - - counters.consoleErrorCount += countMatches( - content, - /\bconsole\.error\s*\(/g, - ); - - counters.consoleWarnCount += countMatches( - content, - /\bconsole\.warn\s*\(/g, - ); - - counters.debuggerCount += countMatches( - content, - /\bdebugger\b/g, - ); - - counters.processExitCount += countMatches( - content, - /\bprocess\.exit\s*\(/g, - ); - } +export function buildLoggingAnalysis(facts: SourceFacts): LoggingAnalysis { + const count = (type: SourceFacts["logging"][number]["type"]) => + facts.logging.filter((fact) => fact.type === type).length; return { - consoleLogCount: counters.consoleLogCount, - consoleErrorCount: counters.consoleErrorCount, - consoleWarnCount: counters.consoleWarnCount, - debuggerCount: counters.debuggerCount, - processExitCount: counters.processExitCount, + consoleLogCount: count("console.log"), + consoleErrorCount: count("console.error"), + consoleWarnCount: count("console.warn"), + debuggerCount: count("debugger"), + processExitCount: count("process.exit"), }; -} \ No newline at end of file +} diff --git a/apps/backend/src/repository/static-analysis/source-facts.ts b/apps/backend/src/repository/static-analysis/source-facts.ts new file mode 100644 index 0000000..7b528f5 --- /dev/null +++ b/apps/backend/src/repository/static-analysis/source-facts.ts @@ -0,0 +1,242 @@ +import path from "node:path"; +import ts from "typescript"; + +import type { RepositoryFile } from "../../types/repository.js"; + +/** + * Facts extracted from JavaScript/TypeScript files with the + * TypeScript compiler's parser (syntax only, no type checking). + * Static analysis counts and evidence locations are both derived + * from these facts, so they always agree. + */ + +export interface FunctionFact { + file: string; + line: number; + name: string; + length: number; +} + +export type TypeScriptIssueType = + | "any" + | "type-assertion" + | "ts-ignore" + | "eslint-disable"; + +export type LoggingType = + | "console.log" + | "console.error" + | "console.warn" + | "debugger" + | "process.exit"; + +export interface LocatedFact { + file: string; + line: number; + type: Type; +} + +export interface SourceFacts { + /** Files that were parsed (JS/TS family). */ + parsedFiles: number; + functions: FunctionFact[]; + typescript: LocatedFact[]; + logging: LocatedFact[]; +} + +const SCRIPT_KINDS: Record = { + ".ts": ts.ScriptKind.TS, + ".tsx": ts.ScriptKind.TSX, + ".js": ts.ScriptKind.JS, + ".jsx": ts.ScriptKind.JSX, + ".mjs": ts.ScriptKind.JS, + ".cjs": ts.ScriptKind.JS, +}; + +const CONSOLE_METHODS: Record = { + log: "console.log", + info: "console.log", + debug: "console.log", + error: "console.error", + warn: "console.warn", +}; + +const SUPPRESSION_COMMENT = + /(\/\/|\/\*|^\s*\*).*?(@ts-ignore|@ts-nocheck|eslint-disable)/; + +function functionName(node: ts.FunctionLikeDeclaration): string { + if (node.name && ts.isIdentifier(node.name)) { + return node.name.text; + } + + if (node.name && ts.isPropertyName(node.name)) { + return node.name.getText(); + } + + if (ts.isConstructorDeclaration(node)) { + return "constructor"; + } + + const parent = node.parent; + + if ( + (ts.isVariableDeclaration(parent) || + ts.isPropertyAssignment(parent) || + ts.isPropertyDeclaration(parent)) && + ts.isIdentifier(parent.name) + ) { + return parent.name.text; + } + + if (ts.isExportAssignment(parent)) { + return "default"; + } + + return "anonymous"; +} + +function isFunctionWithBlockBody( + node: ts.Node, +): node is ts.FunctionLikeDeclaration { + return ( + (ts.isFunctionDeclaration(node) || + ts.isFunctionExpression(node) || + ts.isArrowFunction(node) || + ts.isMethodDeclaration(node) || + ts.isConstructorDeclaration(node) || + ts.isGetAccessorDeclaration(node) || + ts.isSetAccessorDeclaration(node)) && + node.body !== undefined && + ts.isBlock(node.body) + ); +} + +/** + * `x as const` narrows a literal; it is not an unsafe cast. + */ +function isAsConst(node: ts.AsExpression): boolean { + return ( + ts.isTypeReferenceNode(node.type) && + ts.isIdentifier(node.type.typeName) && + node.type.typeName.text === "const" + ); +} + +function analyzeFile(file: RepositoryFile, facts: SourceFacts): void { + const extension = path.extname(file.name).toLowerCase(); + const scriptKind = SCRIPT_KINDS[extension]; + + if (scriptKind === undefined) { + return; + } + + facts.parsedFiles++; + + const source = ts.createSourceFile( + file.relativePath, + file.content, + ts.ScriptTarget.Latest, + true, + scriptKind, + ); + + const lineOf = (position: number) => + source.getLineAndCharacterOfPosition(position).line + 1; + + const visit = (node: ts.Node): void => { + if (isFunctionWithBlockBody(node)) { + const start = lineOf(node.getStart(source)); + const end = lineOf(node.getEnd()); + + facts.functions.push({ + file: file.relativePath, + line: start, + name: functionName(node), + length: end - start + 1, + }); + } + + if (node.kind === ts.SyntaxKind.AnyKeyword) { + facts.typescript.push({ + file: file.relativePath, + line: lineOf(node.getStart(source)), + type: "any", + }); + } + + if ( + (ts.isAsExpression(node) && !isAsConst(node)) || + ts.isTypeAssertionExpression(node) + ) { + facts.typescript.push({ + file: file.relativePath, + line: lineOf(node.getStart(source)), + type: "type-assertion", + }); + } + + if (ts.isDebuggerStatement(node)) { + facts.logging.push({ + file: file.relativePath, + line: lineOf(node.getStart(source)), + type: "debugger", + }); + } + + if ( + ts.isCallExpression(node) && + ts.isPropertyAccessExpression(node.expression) && + ts.isIdentifier(node.expression.expression) + ) { + const object = node.expression.expression.text; + const method = node.expression.name.text; + + const type = + object === "console" + ? CONSOLE_METHODS[method] + : object === "process" && method === "exit" + ? "process.exit" + : undefined; + + if (type) { + facts.logging.push({ + file: file.relativePath, + line: lineOf(node.getStart(source)), + type, + }); + } + } + + ts.forEachChild(node, visit); + }; + + visit(source); + + // Suppression comments are not part of the syntax tree. + file.content.split(/\r?\n/).forEach((text, index) => { + const match = text.match(SUPPRESSION_COMMENT); + + if (match) { + facts.typescript.push({ + file: file.relativePath, + line: index + 1, + type: match[2] === "eslint-disable" ? "eslint-disable" : "ts-ignore", + }); + } + }); +} + +export function extractSourceFacts(files: RepositoryFile[]): SourceFacts { + const facts: SourceFacts = { + parsedFiles: 0, + functions: [], + typescript: [], + logging: [], + }; + + for (const file of files) { + analyzeFile(file, facts); + } + + return facts; +} diff --git a/apps/backend/src/repository/static-analysis/typescript-analysis.ts b/apps/backend/src/repository/static-analysis/typescript-analysis.ts index 5108ba8..cd21a27 100644 --- a/apps/backend/src/repository/static-analysis/typescript-analysis.ts +++ b/apps/backend/src/repository/static-analysis/typescript-analysis.ts @@ -1,52 +1,16 @@ -import path from "node:path"; - -import type { RepositoryFile } from "../../types/repository.js"; import type { TypeScriptAnalysis } from "./analysis.types.js"; -import { matchTypeScriptLine } from "./typescript-patterns.js"; - -const SUPPORTED_EXTENSIONS = new Set([ - ".ts", - ".tsx", -]); +import type { SourceFacts } from "./source-facts.js"; export function buildTypeScriptAnalysis( - files: RepositoryFile[], + facts: SourceFacts, ): TypeScriptAnalysis { - const counters: TypeScriptAnalysis = { - anyUsages: 0, - typeAssertions: 0, - tsIgnoreCount: 0, - eslintDisableCount: 0, - }; - - for (const file of files) { - const extension = path.extname( - file.relativePath, - ).toLowerCase(); + const count = (type: SourceFacts["typescript"][number]["type"]) => + facts.typescript.filter((fact) => fact.type === type).length; - if (!SUPPORTED_EXTENSIONS.has(extension)) { - continue; - } - - for (const line of file.content.split(/\r?\n/)) { - for (const match of matchTypeScriptLine(line)) { - switch (match) { - case "any": - counters.anyUsages++; - break; - case "type-assertion": - counters.typeAssertions++; - break; - case "ts-ignore": - counters.tsIgnoreCount++; - break; - case "eslint-disable": - counters.eslintDisableCount++; - break; - } - } - } - } - - return counters; + return { + anyUsages: count("any"), + typeAssertions: count("type-assertion"), + tsIgnoreCount: count("ts-ignore"), + eslintDisableCount: count("eslint-disable"), + }; } diff --git a/apps/backend/src/repository/static-analysis/typescript-patterns.ts b/apps/backend/src/repository/static-analysis/typescript-patterns.ts deleted file mode 100644 index 11cb02b..0000000 --- a/apps/backend/src/repository/static-analysis/typescript-patterns.ts +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Line-level TypeScript patterns shared by the static analysis - * (counts) and the evidence builder (locations). - * - * These are heuristics, not a parser. They aim to avoid the most - * common false positives: - * - the English word "any" in comments or strings - * - `as` in import/export aliases (`import * as fs`, `{ a as b }`) - * - `as const`, which is a safe literal narrowing, not an unsafe cast - */ -export type TypeScriptPatternType = - | "any" - | "type-assertion" - | "ts-ignore" - | "eslint-disable"; - -const ANY_TYPE = /(:\s*any\b|\bas\s+any\b|,)])/; - -const TYPE_ASSERTION = /\bas\s+(?!const\b)[A-Za-z_${[(]/; - -const IMPORT_EXPORT_LINE = /^\s*(import|export\s*(\*|\{))/; - -const COMMENT_LINE = /^\s*(\/\/|\*|\/\*)/; - -export function matchTypeScriptLine( - line: string, -): TypeScriptPatternType[] { - const matches: TypeScriptPatternType[] = []; - - if (/@ts-ignore/.test(line)) { - matches.push("ts-ignore"); - } - - if (/eslint-disable/.test(line)) { - matches.push("eslint-disable"); - } - - if (COMMENT_LINE.test(line)) { - return matches; - } - - if (ANY_TYPE.test(line)) { - matches.push("any"); - } - - if ( - !IMPORT_EXPORT_LINE.test(line) && - TYPE_ASSERTION.test(line) - ) { - matches.push("type-assertion"); - } - - return matches; -} diff --git a/apps/backend/src/types/repository.ts b/apps/backend/src/types/repository.ts index 9e7a639..7b8495e 100644 --- a/apps/backend/src/types/repository.ts +++ b/apps/backend/src/types/repository.ts @@ -24,7 +24,6 @@ export interface RepositoryTree { export interface RepositoryFile extends RepositoryEntry { content: string; size: number; - truncated: boolean; } export interface IgnoredRepositoryFile extends RepositoryEntry { diff --git a/apps/backend/test/analysis-pipeline.test.ts b/apps/backend/test/analysis-pipeline.test.ts new file mode 100644 index 0000000..1b7ecbc --- /dev/null +++ b/apps/backend/test/analysis-pipeline.test.ts @@ -0,0 +1,124 @@ +import fs from "node:fs/promises"; +import { describe, expect, it, vi } from "vitest"; + +import { createZip, tempDir } from "./helpers/zip.js"; +import type { PromptSpec } from "../src/ai/prompt/prompt.types.js"; + +vi.mock("../src/ai/gemini/gemini.client.js", () => ({ + generateContent: vi.fn(), +})); + +const { generateContent } = await import("../src/ai/gemini/gemini.client.js"); +const { processRepository } = await import( + "../src/repository/repository-processor.service.js" +); +const { analyzeRepository } = await import( + "../src/ai/analysis/ai-analysis.service.js" +); +const { JobLogger } = await import("../src/logger/logger.service.js"); + +const mockedGenerate = vi.mocked(generateContent); + +function modelReport() { + const section = { score: 6.6, positives: [], negatives: [], recommendations: [] }; + + return { + summary: { purpose: "Demo", description: "A demo repository." }, + technologyStack: { languages: ["TypeScript"], frameworks: [], databases: [], tools: [], infrastructure: [] }, + architecture: { summary: "s", strengths: [], weaknesses: [], scalability: "x", maintainability: "y" }, + folderStructure: section, + codeQuality: section, + strengths: [], + weaknesses: [ + { + title: "Unsafe exit", + description: "Calls process.exit", + evidence: [ + { file: "src/index.ts", line: 2, description: "Uses `process.exit`" }, + { file: "Repository Metrics", description: "not a file" }, + ], + }, + ], + improvements: [], + resumeFeedback: { score: 7, summary: "s", strengths: [], improvements: [], bestResumeBullets: [] }, + interviewQuestions: [], + }; +} + +async function runPipeline() { + const zip = await createZip([ + { name: "demo/package.json", content: '{"dependencies":{"express":"^5"}}' }, + { name: "demo/src/index.ts", content: "const port = 5000;\nprocess.exit(1);\n" }, + ]); + const dir = await tempDir(); + const stages: string[] = []; + const job = { + id: "test", + logger: new JobLogger("test"), + setStage: (stage: string) => stages.push(stage), + }; + + try { + const metadata = await processRepository(zip, dir, job as never); + const result = await analyzeRepository({ metadata }, job as never); + + return { result, stages }; + } finally { + await fs.rm(dir, { recursive: true, force: true }); + } +} + +describe("analysis pipeline", () => { + it("repairs invalid JSON, rounds scores and checks citations", async () => { + mockedGenerate.mockReset(); + mockedGenerate + .mockResolvedValueOnce({ text: "{ not json", promptTokens: 100, outputTokens: 5 }) + .mockResolvedValueOnce({ + text: JSON.stringify(modelReport()), + promptTokens: 50, + outputTokens: 40, + }); + + const { result, stages } = await runPipeline(); + + expect(mockedGenerate).toHaveBeenCalledTimes(2); + expect(result.trace.repaired).toBe(true); + expect(result.trace.promptTokens).toBe(150); + expect(result.report.codeQuality.score).toBe(7); + + // The invented "Repository Metrics" citation is removed; + // the real one gets the actual code. + const evidence = result.report.weaknesses[0].evidence; + expect(evidence).toHaveLength(1); + expect(evidence[0]).toMatchObject({ file: "src/index.ts", line: 2 }); + expect(evidence[0].snippet?.lines).toContain("process.exit(1);"); + expect(result.trace.citations).toMatchObject({ total: 2, verified: 1, dropped: 1 }); + + expect(stages).toEqual([ + "EXTRACTING", + "READING_REPOSITORY", + "STATIC_ANALYSIS", + "BUILDING_AI_CONTEXT", + "AI_REVIEW", + "VALIDATING_RESPONSE", + "GENERATING_MARKDOWN", + ]); + }); + + it("sends numbered source lines and the response schema to Gemini", async () => { + mockedGenerate.mockReset(); + mockedGenerate.mockResolvedValue({ text: JSON.stringify(modelReport()) }); + + await runPipeline(); + + const prompt = mockedGenerate.mock.calls[0][0] as PromptSpec; + + expect(prompt.userInstruction).toContain("Showing 2 of 2 analyzable files"); + expect(prompt.userInstruction).toContain("2| process.exit(1);"); + expect(prompt.userInstruction).toContain("process.exit"); + expect(prompt.responseJsonSchema).toMatchObject({ + type: "object", + required: expect.arrayContaining(["summary", "weaknesses"]), + }); + }); +}); diff --git a/apps/backend/test/extraction.test.ts b/apps/backend/test/extraction.test.ts new file mode 100644 index 0000000..6a753f0 --- /dev/null +++ b/apps/backend/test/extraction.test.ts @@ -0,0 +1,126 @@ +import fs from "node:fs/promises"; +import path from "node:path"; +import { describe, expect, it, vi } from "vitest"; + +import { createZip, listFiles, renameEntryInPlace, tempDir } from "./helpers/zip.js"; + +// Small limits so the zip-bomb and entry-count tests stay fast. +vi.mock("../src/constants/upload.js", () => ({ + MAX_UPLOAD_SIZE: 500 * 1024 * 1024, + MAX_ANALYZABLE_SIZE: 50 * 1024 * 1024, + MAX_EXTRACTED_SIZE: 1024 * 1024, + MAX_EXTRACTED_ENTRIES: 20, +})); + +const { extractRepositoryArchive } = await import( + "../src/repository/extraction/extraction.service.js" +); +const { InvalidArchiveError } = await import( + "../src/repository/errors/InvalidArchiveError.js" +); +const { RepositoryTooLargeError } = await import( + "../src/repository/errors/RepositoryTooLargeError.js" +); + +describe("extractRepositoryArchive", () => { + it("returns the single top-level folder as the repository root", async () => { + const zip = await createZip([ + { name: "repo/README.md", content: "# hi" }, + { name: "repo/src/index.ts", content: "export {};" }, + ]); + const dir = await tempDir(); + + const root = await extractRepositoryArchive(zip, dir); + + expect(root).toBe(path.join(dir, "repo")); + expect(await listFiles(root)).toEqual(["README.md", "src/index.ts"]); + }); + + it("keeps the extraction folder as root when there are top-level files", async () => { + const zip = await createZip([ + { name: "README.md", content: "# hi" }, + { name: "src/index.ts", content: "export {};" }, + ]); + const dir = await tempDir(); + + expect(await extractRepositoryArchive(zip, dir)).toBe(path.resolve(dir)); + }); + + it("skips symlinks so the archive cannot point at server files", async () => { + const zip = await createZip([ + { name: "repo/src/index.ts", content: "export {};" }, + { name: "repo/src/leak.ts", symlinkTo: "/etc/passwd" }, + ]); + const dir = await tempDir(); + + const root = await extractRepositoryArchive(zip, dir); + const files = await listFiles(root); + + expect(files).toEqual(["src/index.ts"]); + }); + + it("never writes ignored directories such as node_modules and .git", async () => { + const zip = await createZip([ + { name: "repo/src/index.ts", content: "export {};" }, + { name: "repo/node_modules/react/index.js", content: "x" }, + { name: "repo/.git/config", content: "x" }, + { name: "repo/packages/a/dist/out.js", content: "x" }, + ]); + const dir = await tempDir(); + + const root = await extractRepositoryArchive(zip, dir); + + expect(await listFiles(root)).toEqual(["src/index.ts"]); + }); + + it("rejects path traversal entries", async () => { + const zip = await createZip([ + { name: "repo/a.ts", content: "x" }, + { name: "aa/evil.ts", content: "pwned" }, + ]); + await renameEntryInPlace(zip, "aa/evil.ts", "../evil.ts"); + const dir = await tempDir(); + + await expect(extractRepositoryArchive(zip, dir)).rejects.toBeInstanceOf( + InvalidArchiveError, + ); + await expect( + fs.stat(path.join(dir, "..", "evil.ts")), + ).rejects.toThrow(); + }); + + it("stops zip bombs at the extracted-size limit", async () => { + const zip = await createZip([ + { name: "repo/big.txt", content: Buffer.alloc(2 * 1024 * 1024) }, + ]); + const dir = await tempDir(); + + await expect(extractRepositoryArchive(zip, dir)).rejects.toBeInstanceOf( + RepositoryTooLargeError, + ); + }); + + it("rejects archives with too many files", async () => { + const zip = await createZip( + Array.from({ length: 25 }, (_, i) => ({ + name: `repo/f${i}.ts`, + content: "x", + })), + ); + const dir = await tempDir(); + + await expect(extractRepositoryArchive(zip, dir)).rejects.toBeInstanceOf( + InvalidArchiveError, + ); + }); + + it("rejects files that are not ZIP archives", async () => { + const dir = await tempDir(); + const fake = path.join(dir, "fake.zip"); + await fs.writeFile(fake, "not a zip"); + + await expect( + extractRepositoryArchive(fake, path.join(dir, "out")), + ).rejects.toBeInstanceOf(InvalidArchiveError); + }); +}); diff --git a/apps/backend/test/file-ranking.test.ts b/apps/backend/test/file-ranking.test.ts new file mode 100644 index 0000000..3627050 --- /dev/null +++ b/apps/backend/test/file-ranking.test.ts @@ -0,0 +1,55 @@ +import { describe, expect, it } from "vitest"; + +import { rankFiles } from "../src/ai/context/file-ranking.js"; +import type { RepositoryFile } from "../src/types/repository.js"; + +function file(relativePath: string, content = ""): RepositoryFile { + return { + id: relativePath, + name: relativePath.split("/").pop()!, + relativePath, + absolutePath: `/repo/${relativePath}`, + type: "file", + size: content.length, + content, + }; +} + +describe("rankFiles", () => { + it("orders manifests, entry points, early tests, then most-imported source", () => { + const ranked = rankFiles([ + file("docs/guide.md"), + file("src/feature-a.ts", "import { util } from './lib/util.js';"), + file("src/feature-b.ts", "import { util } from './lib/util';"), + file("src/lib/util.ts"), + file("src/lonely.ts"), + file("src/server.ts", "import './feature-a.js';"), + file("src/feature-a.test.ts"), + file("package.json", "{}"), + file("README.md", "# hi"), + ]).map((f) => f.relativePath); + + expect(ranked).toEqual([ + "README.md", + "package.json", + "src/server.ts", + "src/feature-a.test.ts", + "src/lib/util.ts", // imported twice + "src/feature-a.ts", // imported once + "src/lonely.ts", // not imported: smaller file first + "src/feature-b.ts", + "docs/guide.md", + ]); + }); + + it("resolves relative Python imports", () => { + const ranked = rankFiles([ + file("pkg/a.py"), + file("pkg/models.py"), + file("pkg/views.py", "from .models import User\n"), + file("pkg/api.py", "from .models import User\n"), + ]).map((f) => f.relativePath); + + expect(ranked[0]).toBe("pkg/models.py"); + }); +}); diff --git a/apps/backend/test/filtering.test.ts b/apps/backend/test/filtering.test.ts new file mode 100644 index 0000000..233c58b --- /dev/null +++ b/apps/backend/test/filtering.test.ts @@ -0,0 +1,93 @@ +import { describe, expect, it } from "vitest"; + +import { filterRepository } from "../src/repository/filtering/filtering.service.js"; +import { InvalidArchiveError } from "../src/repository/errors/InvalidArchiveError.js"; +import type { RepositoryEntry, RepositoryTree } from "../src/types/repository.js"; + +function tree(paths: Array): RepositoryTree { + const files: RepositoryEntry[] = paths.map((entry) => { + const [relativePath, size] = + typeof entry === "string" ? [entry, 100] : entry; + + return { + id: relativePath, + name: relativePath.split("/").pop()!, + relativePath, + absolutePath: `/repo/${relativePath}`, + type: "file", + size, + }; + }); + + return { + rootPath: "/repo", + files, + directories: [], + totalFiles: files.length, + totalDirectories: 0, + }; +} + +function kept(paths: Array): string[] { + return filterRepository(tree(paths)).files.map((file) => file.relativePath); +} + +function reasons(paths: string[]): Record { + return Object.fromEntries( + filterRepository(tree([...paths, "src/keep.ts"])).ignoredFiles.map( + (file) => [file.relativePath, file.reason], + ), + ); +} + +describe("filterRepository", () => { + it("never reads secret files", () => { + expect( + reasons([".env", ".env.local", "config/.env.production", "keys/server.pem", ".npmrc"]), + ).toEqual({ + ".env": "sensitive", + ".env.local": "sensitive", + "config/.env.production": "sensitive", + "keys/server.pem": "sensitive", + ".npmrc": "sensitive", + }); + }); + + it("keeps env templates, which document configuration", () => { + expect(kept([".env.example", ".env.sample"])).toEqual([ + ".env.example", + ".env.sample", + ]); + }); + + it("skips lockfiles and minified files", () => { + expect( + reasons(["package-lock.json", "yarn.lock", "go.sum", "public/app.min.js"]), + ).toEqual({ + "package-lock.json": "generated", + "yarn.lock": "generated", + "go.sum": "generated", + "public/app.min.js": "generated", + }); + }); + + it("only analyzes known text files", () => { + expect(kept(["src/a.ts", "Dockerfile", "logo.svg", "font.woff2", "data.bin"])).toEqual([ + "src/a.ts", + "Dockerfile", + ]); + }); + + it("skips files over the per-file size limit", () => { + expect(kept([["src/huge.ts", 10 * 1024 * 1024], "src/ok.ts"])).toEqual([ + "src/ok.ts", + ]); + }); + + it("fails clearly when nothing is left to analyze", () => { + expect(() => filterRepository(tree(["logo.png", ".env"]))).toThrow( + InvalidArchiveError, + ); + expect(() => filterRepository(tree([]))).toThrow(/empty/); + }); +}); diff --git a/apps/backend/test/grounding.test.ts b/apps/backend/test/grounding.test.ts new file mode 100644 index 0000000..61b0b40 --- /dev/null +++ b/apps/backend/test/grounding.test.ts @@ -0,0 +1,124 @@ +import { describe, expect, it } from "vitest"; + +import { groundReport } from "../src/ai/grounding/grounding.service.js"; +import type { ContextFile } from "../src/ai/context/context.types.js"; +import type { ModelReport } from "../src/ai/report/report.types.js"; + +const files: ContextFile[] = [ + { + path: "src/routes/analyze.ts", + language: "TypeScript", + truncated: false, + content: [ + "import { Router } from 'express';", + "", + "const router = Router();", + "", + "router.post('/analyze', (req, res) => {", + " if (jobStore.runningCount() >= MAX) {", + " return res.status(429).end();", + " }", + "});", + ].join("\n"), + }, + { + path: "src/server.ts", + language: "TypeScript", + truncated: false, + content: "app.listen(5000);", + }, +]; + +type Evidence = ModelReport["strengths"][number]["evidence"]; + +function reportWith(evidence: Evidence): ModelReport { + const empty = { score: 7, positives: [], negatives: [], recommendations: [] }; + + return { + summary: { purpose: "", description: "" }, + technologyStack: { languages: [], frameworks: [], databases: [], tools: [], infrastructure: [] }, + architecture: { summary: "", strengths: [], weaknesses: [], scalability: "", maintainability: "" }, + folderStructure: empty, + codeQuality: empty, + strengths: [{ title: "t", description: "d", evidence }], + weaknesses: [], + improvements: [], + resumeFeedback: { score: 7, summary: "", strengths: [], improvements: [], bestResumeBullets: [] }, + interviewQuestions: [], + }; +} + +function ground(evidence: Evidence) { + const { report, stats } = groundReport(reportWith(evidence), files); + return { evidence: report.strengths[0].evidence, stats }; +} + +describe("groundReport", () => { + it("drops citations of files the model was not shown", () => { + const { evidence, stats } = ground([ + { file: "Repository Metrics", description: "section name" }, + { file: "src/missing.ts", line: 3, description: "invented" }, + ]); + + expect(evidence).toEqual([]); + expect(stats).toMatchObject({ total: 2, dropped: 2 }); + }); + + it("attaches the real code around a valid line", () => { + const { evidence, stats } = ground([ + { file: "src/routes/analyze.ts", line: 3, description: "router" }, + ]); + + expect(evidence[0].snippet).toEqual({ + startLine: 1, + lines: [ + "import { Router } from 'express';", + "", + "const router = Router();", + "", + "router.post('/analyze', (req, res) => {", + ], + }); + expect(stats.verified).toBe(1); + }); + + it("keeps the file but removes an out-of-range line", () => { + const { evidence, stats } = ground([ + { file: "src/server.ts", line: 99, description: "too far" }, + ]); + + expect(evidence).toEqual([{ file: "src/server.ts", description: "too far" }]); + expect(stats.fileOnly).toBe(1); + }); + + it("moves an off-by-a-few line to the code quoted in the description", () => { + const { evidence, stats } = ground([ + { + file: "src/routes/analyze.ts", + line: 8, + description: "Checks `jobStore.runningCount()` against the cap", + }, + ]); + + expect(evidence[0].line).toBe(6); + expect(stats.adjusted).toBe(1); + }); + + it("normalizes paths the model writes differently", () => { + const { evidence } = ground([ + { file: "./src/server.ts", description: "dot slash" }, + { file: "myrepo/src/server.ts", description: "repo prefix" }, + { file: "server.ts", description: "unique suffix" }, + { file: "src/routes/analyze.ts:5", description: "embedded line" }, + { file: "`src\\server.ts`", description: "backticks and backslash" }, + ]); + + expect(evidence.map((item) => [item.file, item.line])).toEqual([ + ["src/server.ts", undefined], + ["src/server.ts", undefined], + ["src/server.ts", undefined], + ["src/routes/analyze.ts", 5], + ["src/server.ts", undefined], + ]); + }); +}); diff --git a/apps/backend/test/helpers/zip.ts b/apps/backend/test/helpers/zip.ts new file mode 100644 index 0000000..74b2bcc --- /dev/null +++ b/apps/backend/test/helpers/zip.ts @@ -0,0 +1,92 @@ +import fs from "node:fs/promises"; +import os from "node:os"; +import path from "node:path"; +import yazl from "yazl"; + +export interface ZipEntry { + name: string; + content?: string | Buffer; + /** Create a symlink pointing at this target instead of a file. */ + symlinkTo?: string; +} + +/** + * Builds a ZIP in a temp directory and returns its path. + */ +export async function createZip(entries: ZipEntry[]): Promise { + const zip = new yazl.ZipFile(); + + for (const entry of entries) { + if (entry.symlinkTo !== undefined) { + zip.addBuffer(Buffer.from(entry.symlinkTo), entry.name, { + mode: 0o120777, + }); + } else { + zip.addBuffer(Buffer.from(entry.content ?? ""), entry.name); + } + } + + zip.end(); + + const chunks: Buffer[] = []; + + for await (const chunk of zip.outputStream) { + chunks.push(chunk as Buffer); + } + + const dir = await fs.mkdtemp(path.join(os.tmpdir(), "zip-test-")); + const file = path.join(dir, "repo.zip"); + + await fs.writeFile(file, Buffer.concat(chunks)); + + return file; +} + +/** + * Rewrites an entry name inside a ZIP's raw bytes (local header and + * central directory). Used to create names yazl refuses to write, + * such as "../evil.ts". Both names must have the same length. + */ +export async function renameEntryInPlace( + zipPath: string, + from: string, + to: string, +): Promise { + if (from.length !== to.length) { + throw new Error("Names must have the same length."); + } + + const bytes = await fs.readFile(zipPath); + const search = Buffer.from(from); + const replacement = Buffer.from(to); + + let index = bytes.indexOf(search); + + while (index !== -1) { + replacement.copy(bytes, index); + index = bytes.indexOf(search, index + search.length); + } + + await fs.writeFile(zipPath, bytes); +} + +export async function tempDir(): Promise { + return fs.mkdtemp(path.join(os.tmpdir(), "extract-test-")); +} + +export async function listFiles(root: string): Promise { + const entries = await fs.readdir(root, { + recursive: true, + withFileTypes: true, + }); + + return entries + .filter((entry) => entry.isFile() || entry.isSymbolicLink()) + .map((entry) => + path + .relative(root, path.join(entry.parentPath, entry.name)) + .split(path.sep) + .join("/"), + ) + .sort(); +} diff --git a/apps/backend/test/job-store.test.ts b/apps/backend/test/job-store.test.ts new file mode 100644 index 0000000..f6a9709 --- /dev/null +++ b/apps/backend/test/job-store.test.ts @@ -0,0 +1,63 @@ +import { describe, expect, it } from "vitest"; + +import { jobStore } from "../src/jobs/job.store.js"; + +const report = {} as never; + +describe("jobStore", () => { + it("keeps each job's progress separate", () => { + const a = jobStore.create(); + const b = jobStore.create(); + + jobStore.setStage(a.id, "AI_REVIEW"); + + expect(jobStore.get(a.id)?.progress.stage).toBe("AI_REVIEW"); + expect(jobStore.get(b.id)?.progress.stage).toBe("UPLOADING"); + }); + + it("notifies subscribers until they unsubscribe", () => { + const job = jobStore.create(); + const stages: string[] = []; + + const unsubscribe = jobStore.subscribe(job.id, (current) => + stages.push(current.progress.stage), + ); + + jobStore.setStage(job.id, "EXTRACTING"); + unsubscribe(); + jobStore.setStage(job.id, "READING_REPOSITORY"); + + expect(stages).toEqual(["EXTRACTING"]); + }); + + it("does not change a job after it has finished", () => { + const job = jobStore.create(); + + jobStore.complete(job.id, { report, markdown: "# done" }); + jobStore.fail(job.id, { + status: 500, + body: { success: false, error: "X", message: "late failure" }, + }); + jobStore.setStage(job.id, "AI_REVIEW"); + + const current = jobStore.get(job.id); + + expect(current?.status).toBe("completed"); + expect(current?.progress.stage).toBe("COMPLETED"); + expect(current?.error).toBeUndefined(); + }); + + it("counts only running jobs", () => { + const before = jobStore.runningCount(); + const job = jobStore.create(); + + expect(jobStore.runningCount()).toBe(before + 1); + + jobStore.fail(job.id, { + status: 400, + body: { success: false, error: "X", message: "failed" }, + }); + + expect(jobStore.runningCount()).toBe(before); + }); +}); diff --git a/apps/backend/test/source-facts.test.ts b/apps/backend/test/source-facts.test.ts new file mode 100644 index 0000000..bd736f3 --- /dev/null +++ b/apps/backend/test/source-facts.test.ts @@ -0,0 +1,102 @@ +import { describe, expect, it } from "vitest"; + +import { extractSourceFacts } from "../src/repository/static-analysis/source-facts.js"; +import type { RepositoryFile } from "../src/types/repository.js"; + +function file(relativePath: string, content: string): RepositoryFile { + return { + id: relativePath, + name: relativePath.split("/").pop()!, + relativePath, + absolutePath: `/repo/${relativePath}`, + type: "file", + size: content.length, + content, + }; +} + +describe("extractSourceFacts", () => { + it("counts real `any` types and unsafe assertions only", () => { + const facts = extractSourceFacts([ + file( + "src/a.ts", + [ + "import * as fs from 'fs';", + "import { a as b } from './x';", + "// any comment about any thing", + "const s = 'works with any input';", + "const c = [1, 2] as const;", + "let x: any = 1;", + "const y = value as Foo;", + "const z = other;", + "// @ts-ignore", + "/* eslint-disable no-console */", + ].join("\n"), + ), + ]); + + expect(facts.typescript).toEqual([ + { file: "src/a.ts", line: 6, type: "any" }, + { file: "src/a.ts", line: 7, type: "type-assertion" }, + { file: "src/a.ts", line: 8, type: "type-assertion" }, + { file: "src/a.ts", line: 9, type: "ts-ignore" }, + { file: "src/a.ts", line: 10, type: "eslint-disable" }, + ]); + }); + + it("measures functions with their real names and lengths", () => { + const facts = extractSourceFacts([ + file( + "src/b.ts", + [ + "export function first() {", // 1 + " const text = '{ not a brace }';", // 2 + " return text;", // 3 + "}", // 4 + "const second = async () => {", // 5 + " return 1;", // 6 + "};", // 7 + "class C {", // 8 + " method() {", // 9 + " [1].map((x) => x * 2);", // 10 (expression arrow: not counted) + " }", // 11 + "}", // 12 + ].join("\n"), + ), + ]); + + expect(facts.functions).toEqual([ + { file: "src/b.ts", line: 1, name: "first", length: 4 }, + { file: "src/b.ts", line: 5, name: "second", length: 3 }, + { file: "src/b.ts", line: 9, name: "method", length: 3 }, + ]); + }); + + it("finds console calls, debugger and process.exit, not mentions in strings", () => { + const facts = extractSourceFacts([ + file( + "src/c.js", + [ + "console.log('a');", + "const msg = 'console.log(\"not a call\")';", + "console.error(err);", + "debugger;", + "process.exit(1);", + ].join("\n"), + ), + ]); + + expect(facts.logging.map((fact) => [fact.line, fact.type])).toEqual([ + [1, "console.log"], + [3, "console.error"], + [4, "debugger"], + [5, "process.exit"], + ]); + }); + + it("ignores non-JS/TS files", () => { + const facts = extractSourceFacts([file("main.py", "def f():\n pass\n")]); + + expect(facts.parsedFiles).toBe(0); + }); +}); diff --git a/apps/backend/tsconfig.check.json b/apps/backend/tsconfig.check.json new file mode 100644 index 0000000..67eb222 --- /dev/null +++ b/apps/backend/tsconfig.check.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": true, + "rootDir": "." + }, + "include": ["src", "test", "scripts", "vitest.config.ts"] +} diff --git a/apps/backend/vitest.config.ts b/apps/backend/vitest.config.ts new file mode 100644 index 0000000..497c740 --- /dev/null +++ b/apps/backend/vitest.config.ts @@ -0,0 +1,23 @@ +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; +import { defineConfig } from "vitest/config"; + +// Temp ZIPs, extraction folders and job logs created by tests go here, +// not next to real analysis logs. +const testTmpDir = path.join(os.tmpdir(), "repoinsight-tests"); + +fs.rmSync(testTmpDir, { recursive: true, force: true }); +fs.mkdirSync(testTmpDir, { recursive: true }); + +export default defineConfig({ + test: { + include: ["test/**/*.test.ts"], + env: { + // env.ts requires a key at import time; tests never call Gemini. + GEMINI_API_KEY: "test-key", + SAVE_DEBUG_ARTIFACTS: "false", + TMPDIR: testTmpDir, + }, + }, +}); diff --git a/apps/frontend/src/components/report/EvidenceList.tsx b/apps/frontend/src/components/report/EvidenceList.tsx new file mode 100644 index 0000000..5485982 --- /dev/null +++ b/apps/frontend/src/components/report/EvidenceList.tsx @@ -0,0 +1,75 @@ +import { FileCode } from "lucide-react"; + +import type { EvidenceReference } from "../../types/report"; + +interface Props { + evidence: EvidenceReference[]; +} + +/** + * Citations checked by the backend. Entries with a snippet show the + * real code around the cited line; the cited line is highlighted. + */ +export default function EvidenceList({ evidence }: Props) { + if (evidence.length === 0) { + return null; + } + + return ( +
    + {evidence.map((item, index) => { + const location = item.line ? `${item.file}:${item.line}` : item.file; + + const label = ( + + + {location} + + {item.description} + + ); + + if (!item.snippet) { + return ( +
  • + + {label} +
  • + ); + } + + const { startLine, lines } = item.snippet; + + return ( +
  • +
    + + + {label} + + +
    +                {lines.map((text, lineIndex) => {
    +                  const lineNumber = startLine + lineIndex;
    +                  const cited = lineNumber === item.line;
    +
    +                  return (
    +                    
    + + {lineNumber} + + {text} +
    + ); + })} +
    +
    +
  • + ); + })} +
+ ); +} diff --git a/apps/frontend/src/components/report/ImprovementCard.tsx b/apps/frontend/src/components/report/ImprovementCard.tsx index 452e202..c0ea8c9 100644 --- a/apps/frontend/src/components/report/ImprovementCard.tsx +++ b/apps/frontend/src/components/report/ImprovementCard.tsx @@ -4,6 +4,9 @@ import { Wrench, } from "lucide-react"; +import type { EvidenceReference } from "../../types/report"; +import EvidenceList from "./EvidenceList"; + interface Props { title: string; priority: string; @@ -11,6 +14,7 @@ interface Props { problem: string; recommendation: string; expectedImpact: string; + evidence: EvidenceReference[]; } export default function ImprovementCard({ @@ -20,6 +24,7 @@ export default function ImprovementCard({ problem, recommendation, expectedImpact, + evidence, }: Props) { const priorityColor = priority === "High" @@ -95,6 +100,8 @@ export default function ImprovementCard({ + + diff --git a/apps/frontend/src/components/report/StrengthsCard.tsx b/apps/frontend/src/components/report/StrengthsCard.tsx index 92f2136..6ac2408 100644 --- a/apps/frontend/src/components/report/StrengthsCard.tsx +++ b/apps/frontend/src/components/report/StrengthsCard.tsx @@ -1,5 +1,6 @@ import type { EngineeringReport } from "../../types/report"; import SectionCard from "./SectionCard"; +import EvidenceList from "./EvidenceList"; interface Props { report: EngineeringReport; @@ -16,6 +17,8 @@ export default function StrengthsCard({ {item.title}

{item.description}

+ + ))} diff --git a/apps/frontend/src/components/report/WeaknessesCard.tsx b/apps/frontend/src/components/report/WeaknessesCard.tsx index 162fd58..d75f885 100644 --- a/apps/frontend/src/components/report/WeaknessesCard.tsx +++ b/apps/frontend/src/components/report/WeaknessesCard.tsx @@ -1,5 +1,6 @@ import type { EngineeringReport } from "../../types/report"; import SectionCard from "./SectionCard"; +import EvidenceList from "./EvidenceList"; interface Props { report: EngineeringReport; @@ -16,6 +17,8 @@ export default function WeaknessesCard({ {item.title}

{item.description}

+ + ))} diff --git a/apps/frontend/src/types/report.schema.generated.ts b/apps/frontend/src/types/report.schema.generated.ts index 53c53c4..c56cc68 100644 --- a/apps/frontend/src/types/report.schema.generated.ts +++ b/apps/frontend/src/types/report.schema.generated.ts @@ -14,36 +14,55 @@ const scoreSchema = z .max(10) .transform((value) => Math.round(value)); -const evidenceReferenceSchema = z.object({ +/** + * A citation as the model writes it. + */ +const modelEvidenceSchema = z.object({ file: z.string(), line: z.number().optional(), description: z.string(), }); -const findingSchema = z.object({ - title: z.string(), - description: z.string(), - evidence: z.array(evidenceReferenceSchema), +/** + * Lines of real code around a cited line, added by the backend + * after checking the citation (never written by the model). + */ +const evidenceSnippetSchema = z.object({ + startLine: z.number(), + lines: z.array(z.string()), }); -const improvementSchema = z.object({ - title: z.string(), - priority: z.enum([ - "High", - "Medium", - "Low", - ]), - category: z.string(), - problem: z.string(), - recommendation: z.string(), - expectedImpact: z.string(), - evidence: z.array( - evidenceReferenceSchema, - ), +/** + * A citation in the final report: checked against the repository. + * `file` is the real repository path; `line` and `snippet` are present + * only when the cited line exists in what the model was shown. + */ +const evidenceReferenceSchema = modelEvidenceSchema.extend({ + snippet: evidenceSnippetSchema.optional(), }); -export const engineeringReportSchema = - z.object({ +/** + * Builds the report schema around a given citation schema, so the + * model's output and the final report share every other field. + */ +function buildReportSchema(evidence: Evidence) { + const findingSchema = z.object({ + title: z.string(), + description: z.string(), + evidence: z.array(evidence), + }); + + const improvementSchema = z.object({ + title: z.string(), + priority: z.enum(["High", "Medium", "Low"]), + category: z.string(), + problem: z.string(), + recommendation: z.string(), + expectedImpact: z.string(), + evidence: z.array(evidence), + }); + + return z.object({ summary: z.object({ purpose: z.string(), description: z.string(), @@ -54,9 +73,7 @@ export const engineeringReportSchema = frameworks: z.array(z.string()), databases: z.array(z.string()), tools: z.array(z.string()), - infrastructure: z.array( - z.string(), - ), + infrastructure: z.array(z.string()), }), architecture: z.object({ @@ -71,71 +88,65 @@ export const engineeringReportSchema = score: scoreSchema, positives: z.array(z.string()), negatives: z.array(z.string()), - recommendations: z.array( - z.string(), - ), + recommendations: z.array(z.string()), }), codeQuality: z.object({ score: scoreSchema, positives: z.array(z.string()), negatives: z.array(z.string()), - recommendations: z.array( - z.string(), - ), + recommendations: z.array(z.string()), }), - strengths: z.array( - findingSchema, - ), + strengths: z.array(findingSchema), - weaknesses: z.array( - findingSchema, - ), + weaknesses: z.array(findingSchema), - improvements: z.array( - improvementSchema, - ), + improvements: z.array(improvementSchema), resumeFeedback: z.object({ score: scoreSchema, summary: z.string(), strengths: z.array(z.string()), - improvements: z.array( - z.string(), - ), - bestResumeBullets: z.array( - z.string(), - ), + improvements: z.array(z.string()), + bestResumeBullets: z.array(z.string()), }), interviewQuestions: z.array( z.object({ question: z.string(), - difficulty: z.enum([ - "Easy", - "Medium", - "Hard", - ]), + difficulty: z.enum(["Easy", "Medium", "Hard"]), category: z.string(), reason: z.string(), - expectedAnswer: - z.string(), + expectedAnswer: z.string(), }), ), }); +} + +/** + * What the model must return (also sent to Gemini as JSON Schema). + */ +export const modelReportSchema = buildReportSchema(modelEvidenceSchema); + +/** + * The final report sent to the frontend, with checked citations. + */ +export const engineeringReportSchema = buildReportSchema( + evidenceReferenceSchema, +); + +export type ModelReport = z.infer; + +export type EngineeringReport = z.infer; -export type EngineeringReport = z.infer< - typeof engineeringReportSchema ->; +export type EvidenceReference = z.infer; -export type EvidenceReference = z.infer< - typeof evidenceReferenceSchema ->; +export type EvidenceSnippet = z.infer; -export type Finding = z.infer; +export type Finding = EngineeringReport["strengths"][number]; -export type Improvement = z.infer; +export type Improvement = EngineeringReport["improvements"][number]; export type InterviewQuestion = - EngineeringReport["interviewQuestions"][number]; \ No newline at end of file + EngineeringReport["interviewQuestions"][number];