Skip to content

Commit 6ea4085

Browse files
Merge pull request #578 from corbitsdev/cl-5759-test-files-are-outside-the-typecheck-scope-so-deleted-fields
Bring test files and fixtures into typecheck scope
2 parents 555867f + 7b45f0b commit 6ea4085

30 files changed

Lines changed: 220 additions & 95 deletions

evals/capability/lib.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,8 @@ describe("resolveRequestedProviderModel", () => {
667667
expect(requested).toEqual({ provider: raw.provider, model: raw.model });
668668

669669
const fallback = detectProviderFallback({
670-
requestedProvider: requested.provider,
671-
requestedModel: requested.model,
670+
...(requested.provider !== undefined ? { requestedProvider: requested.provider } : {}),
671+
...(requested.model !== undefined ? { requestedModel: requested.model } : {}),
672672
resolvedProvider: cell!.provider,
673673
resolvedModel: cell!.model,
674674
});
@@ -695,7 +695,7 @@ describe("resolveRequestedProviderModel", () => {
695695
{},
696696
{ provider: "(default)", model: "(default)" },
697697
);
698-
expect(requested).toEqual({ provider: undefined, model: undefined });
698+
expect(requested).toEqual({});
699699
});
700700
});
701701

evals/capability/lib.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,11 @@ export function resolveRequestedProviderModel(
477477
): { provider?: string; model?: string } {
478478
const requested = (v?: string): string | undefined =>
479479
v === undefined || v === "(default)" ? undefined : v;
480+
const provider = variant.provider ?? requested(labels.provider);
481+
const model = variant.model ?? requested(labels.model);
480482
return {
481-
provider: variant.provider ?? requested(labels.provider),
482-
model: variant.model ?? requested(labels.model),
483+
...(provider !== undefined ? { provider } : {}),
484+
...(model !== undefined ? { model } : {}),
483485
};
484486
}
485487

scripts/eval-capability.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { join } from "node:path";
55
import { execFile } from "node:child_process";
66
import { promisify } from "node:util";
77

8-
import { initEvalGitRepo, mapPool, parseArgs, buildEvalDiagnostics } from "./eval-capability.ts";
9-
import type { Config } from "../src/config/index.ts";
8+
import { initEvalGitRepo, mapPool, parseArgs, buildEvalDiagnostics } from "./eval-capability.js";
9+
import type { Config } from "../src/config/index.js";
1010

1111
const execFileAsync = promisify(execFile);
1212

scripts/eval-capability.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,20 @@ export function parseArgs(argv: readonly string[]): CliOptions {
257257
return opts;
258258
}
259259

260+
// exactOptionalPropertyTypes forbids passing an explicit `undefined` for an
261+
// optional field, so build the fallback object with the key present only
262+
// when the CLI option was actually given.
263+
function providerModelFallback(opts: CliOptions): { provider?: string; model?: string } {
264+
return {
265+
...(opts.provider !== undefined ? { provider: opts.provider } : {}),
266+
...(opts.model !== undefined ? { model: opts.model } : {}),
267+
};
268+
}
269+
260270
function requireExplicitModelPair(opts: CliOptions): void {
261271
const matrix = opts.matrix?.trim();
262272
if (matrix !== undefined && matrix.length > 0) {
263-
parseMatrix(matrix, {
264-
provider: opts.provider,
265-
model: opts.model,
266-
});
273+
parseMatrix(matrix, providerModelFallback(opts));
267274
return;
268275
}
269276
if (!opts.provider && !opts.model) {
@@ -705,8 +712,8 @@ async function runCase(
705712
const resolvedProvider = execResult.provider ?? config.providerName ?? labels.provider;
706713
const resolvedModel = execResult.model ?? config.model ?? labels.model;
707714
providerFallback = detectProviderFallback({
708-
requestedProvider: requested.provider,
709-
requestedModel: requested.model,
715+
...(requested.provider !== undefined ? { requestedProvider: requested.provider } : {}),
716+
...(requested.model !== undefined ? { requestedModel: requested.model } : {}),
710717
resolvedProvider,
711718
resolvedModel,
712719
});
@@ -852,10 +859,7 @@ async function main(): Promise<number> {
852859
}
853860
const all = await loadEvalCases(CASES_ROOT);
854861
const selected = filterCases(all, opts.caseSelector);
855-
const variants = parseMatrix(opts.matrix, {
856-
provider: opts.provider,
857-
model: opts.model,
858-
});
862+
const variants = parseMatrix(opts.matrix, providerModelFallback(opts));
859863
const plan = expandMatrix(selected, variants);
860864

861865
console.log(

scripts/eval-public-swe-one.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, test } from "bun:test";
22

3-
import { parseArgs } from "./eval-public-swe-one.ts";
3+
import { parseArgs } from "./eval-public-swe-one.js";
44

55
describe("parseArgs", () => {
66
test("--help does not require provider or model", () => {

src/cost/pricing-fetcher.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ export interface PricingCache {
2727
export interface PricingFetcherOptions {
2828
cachePath?: string;
2929
endpoint?: string;
30-
fetchImpl?: typeof fetch;
30+
// The plain call signature, not `typeof fetch` — `typeof fetch` also carries
31+
// static members (e.g. `preconnect`) that a test double has no reason to implement.
32+
fetchImpl?: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
3133
fetchTimeoutMs?: number;
3234
now?: () => number;
3335
refreshIntervalMs?: number;

tests/fixtures/plugins/implement-feature/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { implementFeature } from "./workflows/implement-feature.js";
2-
import type { CommandPlugin } from "../../../src/tui/commands/registry.js";
3-
import type { WorkflowPlugin } from "../../../src/workflows/definition.js";
2+
import type { CommandPlugin } from "../../../../../src/tui/commands/registry.js";
3+
import type { WorkflowPlugin } from "../../../../../src/workflows/definition.js";
44

55
export const workflowPlugin: WorkflowPlugin = {
66
workflows: [implementFeature],

tests/fixtures/plugins/implement-feature/src/workflows/implement-feature.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Workflow } from "../../../../src/workflows/definition.js";
1+
import type { Workflow } from "../../../../../../src/workflows/definition.js";
22

33
export const implementFeature: Workflow = {
44
name: "implement-feature",

tests/integration/vendored-carry.test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ describe("integration — vendored feature carry", () => {
7575

7676
const requests = session.harness.scenario.matchedRequests();
7777
expect(requests.length).toBeGreaterThan(0);
78-
const bodies = await Promise.all(requests.map((r) => r.clone().text()));
78+
// HarnessRequest resolves to a body-less fallback shape under this project's
79+
// DOM-less lib config, even though it carries a real body at runtime; cast
80+
// through the Fetch Request shape to read it.
81+
const bodies = await Promise.all(
82+
requests.map((r) => (r.clone() as unknown as Request).text()),
83+
);
7984
expect(bodies.some((b) => b.includes(TRANSFORM_MARKER))).toBe(true);
8085
} finally {
8186
await closeIntegrationSession(session);
@@ -148,7 +153,12 @@ describe("integration — vendored feature carry", () => {
148153

149154
const requests = harness.scenario.matchedRequests();
150155
expect(requests.length).toBeGreaterThan(0);
151-
const bodies = await Promise.all(requests.map((r) => r.clone().text()));
156+
// HarnessRequest resolves to a body-less fallback shape under this project's
157+
// DOM-less lib config, even though it carries a real body at runtime; cast
158+
// through the Fetch Request shape to read it.
159+
const bodies = await Promise.all(
160+
requests.map((r) => (r.clone() as unknown as Request).text()),
161+
);
152162
expect(bodies.some((b) => b.includes(NUDGE_MARKER))).toBe(true);
153163

154164
// Prompt-only: the nudge must not be persisted.

tests/unit/codex-session.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe("getValidCodexToken", () => {
5252
await withHome(async (home) => {
5353
globalThis.fetch = (() => {
5454
throw new Error("should not be called");
55-
}) as typeof fetch;
55+
}) as unknown as typeof fetch;
5656
await saveCodexProfile(
5757
{
5858
name: "p",
@@ -69,7 +69,7 @@ describe("getValidCodexToken", () => {
6969
await withHome(async (home) => {
7070
globalThis.fetch = (() => {
7171
throw new Error("should not be called");
72-
}) as typeof fetch;
72+
}) as unknown as typeof fetch;
7373
await saveCodexProfile(
7474
{
7575
name: "p",
@@ -97,7 +97,7 @@ describe("getValidCodexToken", () => {
9797
status: 200,
9898
headers: { "content-type": "application/json" },
9999
},
100-
)) as typeof fetch;
100+
)) as unknown as typeof fetch;
101101
const token = await getValidCodexToken("p", 5_000, home);
102102
expect(token.access).toBe("fresh");
103103
const stored = await loadCodexProfile("p", home);
@@ -122,7 +122,8 @@ describe("getValidCodexToken", () => {
122122
{ name: "p", createdAt: 0, tokens: { access: "old", refresh: "bad", expiresAt: 1_000 } },
123123
home,
124124
);
125-
globalThis.fetch = (async () => new Response("revoked", { status: 400 })) as typeof fetch;
125+
globalThis.fetch = (async () =>
126+
new Response("revoked", { status: 400 })) as unknown as typeof fetch;
126127
const err = await getValidCodexToken("p", 5_000, home).catch((e: unknown) => e);
127128
expect(err).toBeInstanceOf(CodexAuthError);
128129
expect((err as CodexAuthError).reason).toBe("refresh-failed");

0 commit comments

Comments
 (0)