# Specialist Report — agent-feature (GET .../files/biggest) Spec: `docs/specs/20260617-123442-agent-feature.md` ## Summary Adds a read-only endpoint **`GET /api/v2/projects/{projectId}/files/biggest`** that returns the full metadata for the largest non-soft-deleted file (by `FileSizeBytes`) in a project. - Returns **200** with the file metadata when the project has files. - Returns **200** with a `null` body when the project exists but has no files. - Returns **404** when the project does not exist. - Returns **400** for an invalid `projectId`, **401** unauthenticated, **403** without `IMAGE_VIEW`. The spec listed `src/api/v2/projects/files/...`; in this repo the established resource for project files is `projectfiles`, so the change was applied there (the `files` resource does not exist). ## Files changed | File | Change | |------|--------| | `src/api/v2/projects/projectfiles/projectfiles.routes.ts` | New `GET /biggest` route (registered **before** `/:fileReferenceId` so it is not shadowed) + Swagger doc. Wired `validateBiggestFileRequest` → `hasRolesOrProjectAccess([], [IMAGE_VIEW])` → `getBiggestFile`. | | `src/api/v2/projects/projectfiles/projectfiles.controller.ts` | New `getBiggestFile` handler mapping the DB row to the JSON shape (mirrors `getFile`), returning `200 null` when no row. | | `src/api/v2/projects/projectfiles/projectfiles.validator.ts` | New `validateBiggestFileRequest` (validates `projectId`). | | `src/services/projectfiles.service.ts` | New `getBiggestProjectFile` calling `xyz."fn_GetBiggestFile"($1)`; returns `null` on empty, maps "No project found" → `NotFoundError`, else `DatabaseError`. | | `test/unit/services/projectfiles.service.spec.ts` | Unit tests for `getBiggestProjectFile` (row / null / NotFound / DatabaseError). | | `test/unit/api/v2/projects/projectfiles/projectfiles.controller.spec.ts` | **(this revision)** Added controller unit tests for `getBiggestFile` (200 metadata / 200 null / 404 / 500). | | `test/e2e/api/projectfiles.e2e.spec.ts` | E2E coverage for the new endpoint (200 metadata, 200 null, 404, 400, 401, 403). | ## Revision addressed ("fix the tests") The reviewer asked to fix the tests. On inspection: - **Unit + controller + service tests all pass** (`1654 passing`). - The original implementation added service-level and e2e tests but **omitted the controller-level unit test** for `getBiggestFile`, even though the sibling handlers (`getFile`, `uploadFile`) have controller unit tests and CLAUDE.md requires a unit test for every behavior change. **Fixed** by adding a `getBiggestFile` describe block to `projectfiles.controller.spec.ts` (4 cases), now passing. - Verified the e2e `expect(response.body).to.be.null` assertion is correct for `res.json(null)` (empirically: chai-http parses the `null` JSON body to `null`, so the assertion passes — the codebase's `.to.be.empty` pattern would *fail* on a primitive `null`, so `.to.be.null` is right). ## Tests run - `npx mocha test/unit/**/*.spec.ts` → **1654 passing**. - Targeted: `projectfiles.controller.spec.ts` (15 passing, incl. 4 new) and `projectfiles.service.spec.ts` (20 passing). - ESLint on the new test code: clean. (Two pre-existing `no-unused-expressions` errors remain on lines 286/316 of the controller spec — original `uploadFile` tests using `.calledOnce`/`.called` property assertions; not introduced by this change and left untouched.) - **E2E not run locally**: the e2e harness needs infra not present here (missing `test/e2e/auth/certs/private.key`, Postgres/mock stack). The pipeline runs e2e itself. ## Deviations / open questions for the reviewer 1. **`fn_GetBiggestFile` is a new DB function** that lives in the external database repo (`${DATABASE_REPO_PATH}/PostgreSQLDatabase`, mounted via `docker/docker-compose.yml`), not in api2. Per the spec ("no schema changes"; file list contains no SQL) it was **not** added here. ⚠️ The e2e tests for `/biggest` will only pass once `fn_GetBiggestFile` exists in the database repo / e2e schema. If it is not yet deployed there, those e2e cases will 500. Please confirm the DB function has been (or will be) added in the database repo before merge. 2. Resource naming: implemented on `projectfiles` (the real resource) rather than the spec's non-existent `files` path. Flagging in case the spec intended a separate resource.