Skip to content

Commit cbacc96

Browse files
os-litantclaude
andauthored
test(rest): pay down 17 of the test-typecheck ledger's 37 errors (#12625)
Two annotation-only classes, both repaired in the form this package's already-green test files use: - TS18048 x13, all in `export-integration.test.ts`: `getRoutes().find()` is `Route | undefined`, so every `route.handler(...)` below read as possibly-undefined. Asserted non-null at the two lookup sites rather than at the thirteen call sites. `!` erases, so no call receives a different value than it did before. - TS7006 x4: `ReturnType<typeof vi.spyOn>` leaves `mock.calls` untyped, so each `.map`/`.filter` callback parameter was implicitly `any`. Annotated `unknown[]`, the form `rest-5xx-status-passthrough.test.ts` already uses. Ledger regenerated, not hand-edited: four entries reach zero and are deleted, `export-integration.test.ts` re-records 17 -> 4. 37 -> 20 errors across 13 -> 9 files. No number is raised. The remaining 20 are NOT repaired, on purpose: they need a fixture's data or a producer's signature changed, not an annotation. Claude-Session: https://claude.ai/code/session_01UjujZN219uFzBhSYfMykCd Co-authored-by: Claude <noreply@anthropic.com>
1 parent 0043c92 commit cbacc96

6 files changed

Lines changed: 16 additions & 11 deletions

packages/rest/src/analytics-read-scope-refusal-envelope.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ describe('[#5367] POST /analytics/dataset/query — a read-scope failure is a 50
222222
// …and it is in the LOG, which is now its only destination. Asserted rather
223223
// than assumed: "withheld" is only acceptable because the operator still
224224
// has the whole thing.
225-
const logged = logSpy.mock.calls.map((args) => args.map(String).join(' ')).join('\n');
225+
const logged = logSpy.mock.calls.map((args: unknown[]) => args.map(String).join(' ')).join('\n');
226226
expect(logged).toMatch(/Analytics dataset query error/);
227227
expect(logged).toContain('read-scope-sql');
228228
expect(logged).toContain(c.secret);

packages/rest/src/export-integration.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,17 @@ async function boot() {
144144
const rest = new RestServer(createMockServer() as any, protocol as any, { api: { requireAuth: false } } as any);
145145
(rest as any).resolveExecCtx = async () => ({ userId: 'test-user' });
146146
rest.registerRoutes();
147+
// [#12573] `Array.prototype.find` is `Route | undefined`, so every
148+
// `route.handler(...)` below read as possibly-undefined (TS18048 x13).
149+
// Asserted non-null HERE, once, rather than at each call site: the
150+
// lookup either finds the registered route or the boot is broken, and
151+
// `registerRoutes()` two lines up is what guarantees it. Same form the
152+
// green siblings in this package already use (e.g.
153+
// `analytics-dataset-where-gate.test.ts`). Type-level only — `!` erases,
154+
// so no call below receives a different value than it did before.
147155
const route = rest.getRoutes().find(
148156
(r: any) => r.method === 'GET' && r.path === '/api/v1/data/:object/export',
149-
);
157+
)!;
150158
return { engine, protocol, route };
151159
}
152160

@@ -394,9 +402,10 @@ describe('export route — FLS column projection via getReadableFields (#3547)',
394402
);
395403
(rest as any).resolveExecCtx = async () => ({ userId: 'test-user' });
396404
rest.registerRoutes();
405+
// [#12573] Non-null for the same reason as `boot()` above.
397406
const route = rest.getRoutes().find(
398407
(r: any) => r.method === 'GET' && r.path === '/api/v1/data/:object/export',
399-
);
408+
)!;
400409
return { engine, route };
401410
}
402411

packages/rest/src/rest-expected-error-logging.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ async function callDataList(rest: any, object: string) {
110110
let errorSpy: ReturnType<typeof vi.spyOn>;
111111

112112
/** Only the "[REST] Unhandled error" channel — other console.error noise is not this test's business. */
113-
const unhandledLogs = () => errorSpy.mock.calls.filter((c) => c[0] === '[REST] Unhandled error:');
113+
const unhandledLogs = () => errorSpy.mock.calls.filter((c: unknown[]) => c[0] === '[REST] Unhandled error:');
114114

115115
beforeEach(() => { errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); });
116116
afterEach(() => { errorSpy.mockRestore(); });

packages/rest/src/rest-meta-outage-vs-miss.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ let errorSpy: ReturnType<typeof vi.spyOn>;
9595
beforeEach(() => { errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); });
9696
afterEach(() => { errorSpy.mockRestore(); });
9797

98-
const loggedText = () => errorSpy.mock.calls.map((c) => JSON.stringify(c.map(String))).join('\n');
98+
const loggedText = () => errorSpy.mock.calls.map((c: unknown[]) => JSON.stringify(c.map(String))).join('\n');
9999

100100
describe('[#5532] an unreadable metadata store reaches the client as a retryable 503', () => {
101101
it('503 + SERVICE_UNAVAILABLE, and the prose is withheld', async () => {

packages/rest/src/rest-unclassified-fault-status.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ beforeEach(() => { errorSpy = vi.spyOn(console, 'error').mockImplementation(() =
118118
afterEach(() => { errorSpy.mockRestore(); });
119119

120120
/** Everything the error channel printed, flattened for substring searching. */
121-
const loggedText = () => errorSpy.mock.calls.map((c) => JSON.stringify(c.map(String))).join('\n');
121+
const loggedText = () => errorSpy.mock.calls.map((c: unknown[]) => JSON.stringify(c.map(String))).join('\n');
122122

123123
// ---------------------------------------------------------------------------
124124
// The unit: mapDataError's terminal branch

packages/rest/test-typecheck-debt.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
{
22
"_comment": "Per-file tsc error debt of the @objectstack/rest TEST layer (#5286). `tsconfig.test.json` compiles `src/**/*.test.ts` — which `tsconfig.json` excludes and therefore no gate ever read — and every file below still carries errors from before that gate existed, almost all of them fixture literals annotated with a schema OUTPUT type (`z.infer`) while holding an authored INPUT literal. EXACT ratchet, judged by re-running tsc: a file that gains errors is red, a file that loses them is red until its number is re-recorded, a file that reaches zero is red until its entry is deleted, and a file NOT listed here may have no errors at all. Regenerate with: pnpm --filter @objectstack/rest gen:test-typecheck-debt",
33
"entries": {
4-
"src/analytics-read-scope-refusal-envelope.test.ts": 1,
5-
"src/export-integration.test.ts": 17,
4+
"src/export-integration.test.ts": 4,
65
"src/import-dryrun-parity.test.ts": 1,
76
"src/import-integration.test.ts": 3,
87
"src/import-job-integration.test.ts": 2,
98
"src/meta-public-book-grant.test.ts": 1,
109
"src/rest-batch-size-cap.test.ts": 1,
11-
"src/rest-expected-error-logging.test.ts": 1,
12-
"src/rest-meta-outage-vs-miss.test.ts": 1,
1310
"src/rest-meta-save-receipt-envelope.test.ts": 3,
14-
"src/rest-unclassified-fault-status.test.ts": 1,
1511
"src/rest-write-response-formula.test.ts": 1,
1612
"src/rest.test.ts": 4
1713
}

0 commit comments

Comments
 (0)