Repository navigation
Validate published errors against API-owned response contracts - #1038
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
2 issues found and verified against the latest diff
Confidence score: 3/5
getAuthenticatedAccountId.tsreturns raw error messages in 401 responses, which can expose database details to callers. Return a generic message instead.published-docs.jsonis 285 lines and exceeds the 100-line style limit. Split it into smaller, cohesive fixtures.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="lib/auth/getAuthenticatedAccountId.ts">
<violation number="1" location="lib/auth/getAuthenticatedAccountId.ts:48">
P2: The catch branch returns raw `error.message` in the 401 body. A DB failure during account provisioning (for example, `insertAccount` rethrowing `Failed to insert account: <Postgres message>`) is exposed to the caller. This predates the PR, but the touched line still carries it. Log the full error (already done) and return a generic message for non-auth failures, or add a test asserting internal error text is not returned.</violation>
</file>
<file name="lib/contracts/fixtures/published-docs.json">
<violation number="1" location="lib/contracts/fixtures/published-docs.json:6">
P2: Custom agent: **Enforce Clear Code Style and Maintainability Practices**
This fixture is now 285 lines, well above the rule’s 100-line limit. Split its response-schema data and other cohesive fixture sections into smaller files.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| headers: getCorsHeaders(), | ||
| }, | ||
| ); | ||
| return messageErrorResponse(message, 401); |
There was a problem hiding this comment.
P2: The catch branch returns raw error.message in the 401 body. A DB failure during account provisioning (for example, insertAccount rethrowing Failed to insert account: <Postgres message>) is exposed to the caller. This predates the PR, but the touched line still carries it. Log the full error (already done) and return a generic message for non-auth failures, or add a test asserting internal error text is not returned.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/auth/getAuthenticatedAccountId.ts, line 48:
<comment>The catch branch returns raw `error.message` in the 401 body. A DB failure during account provisioning (for example, `insertAccount` rethrowing `Failed to insert account: <Postgres message>`) is exposed to the caller. This predates the PR, but the touched line still carries it. Log the full error (already done) and return a generic message for non-auth failures, or add a test asserting internal error text is not returned.</comment>
<file context>
@@ -57,15 +45,6 @@ export async function getAuthenticatedAccountId(
- headers: getCorsHeaders(),
- },
- );
+ return messageErrorResponse(message, 401);
}
}
</file context>
| "responseEvidence": "Selected route exports use real request, response and authentication code under dependency mocks. No live provider, customer or hosted route is exercised.", | ||
| "sourceRepository": "recoupable/marketing", | ||
| "apiResponseSchemaSha256": "f65397b0466feee5a4d6d2c1b49dcfaa50b419e281e0dcd8ec58bbbb0ee41237", | ||
| "responseSchemas": [ |
There was a problem hiding this comment.
P2: Custom agent: Enforce Clear Code Style and Maintainability Practices
This fixture is now 285 lines, well above the rule’s 100-line limit. Split its response-schema data and other cohesive fixture sections into smaller files.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/contracts/fixtures/published-docs.json, line 6:
<comment>This fixture is now 285 lines, well above the rule’s 100-line limit. Split its response-schema data and other cohesive fixture sections into smaller files.</comment>
<file context>
@@ -1,13 +1,152 @@
+ "responseEvidence": "Selected route exports use real request, response and authentication code under dependency mocks. No live provider, customer or hosted route is exercised.",
"sourceRepository": "recoupable/marketing",
+ "apiResponseSchemaSha256": "f65397b0466feee5a4d6d2c1b49dcfaa50b419e281e0dcd8ec58bbbb0ee41237",
+ "responseSchemas": [
+ {
+ "specification": "releases.json",
</file context>
There was a problem hiding this comment.
All reported issues were addressed across 18 files
Architecture diagram
sequenceDiagram
participant Client as API Client
participant Next as Next.js Route (Artist/Project)
participant Auth as Auth Helpers (validateAuthContext/getAuth)
participant Schemas as Zod Response Schemas
participant Contract as Contract Fixture/OpenAPI Artifact
participant CI as CI Pipeline
Note over Client,CI: Response Contract Validation & Publishing Flow
Client->>Next: GET /api/artists/{id}/profile
Next->>Auth: validateAuthContext()
alt Missing/invalid auth
Auth->>Auth: errorResponse() or messageErrorResponse()
Auth-->>Next: 401/403 response
Next-->>Client: JSON {status, error|message}
else Valid auth
Auth-->>Next: accountId
alt Artist not found
Next->>Next: errorResponse("Artist not found", 404)
Next-->>Client: JSON {status, error}
else Artist found
Next-->>Client: Artist data
end
end
Client->>Next: GET /api/projects/{projectId}
Next->>Auth: validateAuthContext() / getApiKeyAccountId()
Auth->>Schemas: NEW: Use typed constructors (errorResponse, messageErrorResponse)
Schemas-->>Auth: Type-safe response body
Auth-->>Next: 401 response (either envelope)
Next-->>Client: JSON {status, error|message}
Note over Schemas,Contract: Contract Generation & Verification
Schemas->>Contract: Generate OpenAPI artifact (z.toJSONSchema)
Contract->>Contract: Freeze schemas, statuses, source hashes
CI->>Contract: typecheck:response-contracts + tests
Contract-->>CI: Validate responses match published schemas
alt Response matches contract
CI-->>CI: PASS
else Response violates contract
CI-->>CI: FAIL (schema mismatch)
end
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 6 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Requires human review: Auto-approval blocked by 2 unresolved issues from previous reviews.
View guided diff | Turn on auto-fix | Re-trigger cubic
Projects authentication can return
{status, message}, while the published 401 schema requirederror. This preserves the existing wire behavior, derives the shared error schemas from API-owned Zod types, and validates selected published schemas against actual Artist Profile and Project GET exports. Shared auth helpers now use typed response constructors. Projects' authentication union is limited to 401; its 400, 404 and 500 responses still requireerror.Merge this API change before recoupable/marketing#175, then the generated copy recoupable/docs#376. Marketing pins API
4dd3a1debfed685930cbb50e83d9a08e3ecc5818; the API fixture records Marketing source-file hashes rather than a circular commit pin. The cohesive generated schema artifact and existing shared fixture remain single files so the pinned export/check boundary stays atomic.Validation: 105 focused contract/auth/project/networking/artist tests and strict response type checks pass; changed TypeScript lint passes and repository lint/format/OAuth compatibility CI are green. Tests reject the historical Artist schema and missing producer fields. The distinct project/account fixture rejects swapped access arguments. All 28 published error responses across seven Projects operations accept message-only bodies only at 401. Deliberately dropping resolver required-fields or exporter method identity still exports fixtures but makes the API contract gate fail; restoring the code passes. Profile, project-access and credential dependencies are mocked in local route tests.
On the exact Vercel deployment for
dcd8022ceecc0cea09a61c0791ad9444ee0c7814, a Projects GET without credentials returned the expected 401{status, error}, and malformedAuthorization: invalid-tokenreturned the expected 401{status, message}. The auth helpers, response constructors, access function, handlers and route exports remain byte-identical to that observed revision. No valid identity, customer access or paid operation was used.Scope note: the existing token-verification catch can return a caught
Error.messageto the caller. That behavior predates this change and is deliberately preserved; sanitization requires a separately scoped compatibility/security change and is not claimed fixed here.