Skip to content

harness: tsc fails on cli.ts gateway-header cast (x-api-key: null → Record<string, string>) #1

Closed

Description

@pdettori

Summary

pnpm exec tsc --noEmit in harness/ fails with one error in the env-gated gateway-bridge code:

src/cli.ts(79,26): error TS2352: Conversion of type '{ Authorization: string; "x-api-key": null; }' to type 'Record<string, string>' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
  Property '"x-api-key"' is incompatible with index signature.

The offending block (harness/src/cli.ts, ~lines 78-83):

headers: {
  ...baseModel.headers,
  Authorization: `Bearer ${gatewayToken}`,
  "x-api-key": null,
} as Record<string, string>,

The "x-api-key": null is intentional — it deletes the default x-api-key header via Pi's mergeHeaders (the same pattern Pi's cloudflare path uses), so the gateway sees Authorization: Bearer instead. The problem is only the type assertion: null isn't assignable to a Record<string, string> index signature, so the as Record<string, string> cast is rejected.

Provenance

  • Pre-existing — introduced by the M1-era gateway bridge commit feat(harness): env-gated Bearer gateway bridge for headless smoke (ANTHROPIC_BASE_URL/AUTH_TOKEN). Not introduced by M2.
  • It became visible during M2 (Task 9) because the harness previously had no tsconfig.json; a minimal one was added to wire @sh/k8s-sandbox, which makes tsc --noEmit runnable. The harness runs via tsx + vitest, so this error does not affect runtime or the test suite today.

Impact

Harmless at runtime, but harness will fail any future CI typecheck gate (tsc --noEmit).

Suggested fix

Type the header map to allow header deletion rather than force-casting. Either:

headers: {
  ...baseModel.headers,
  Authorization: `Bearer ${gatewayToken}`,
  "x-api-key": null,
} as Record<string, string | null>,

(matching what Pi's mergeHeaders accepts — null means "delete this header"), or, if the surrounding type strictly requires Record<string, string>, as unknown as Record<string, string> with a short comment.

Prefer the string | null form since it is type-honest about the deletion semantics.


Assisted-By: Claude Code

Activity

  1. pdettori commented on Jun 29, 2026

    @pdettori
    MemberAuthor

    Resolved — this was fixed by #6 (merged 2026-06-26).

    The gateway-bridge code was refactored out of harness/src/cli.ts into harness/src/run-turn.ts. The offending cast is gone; lines 122–123 now read:

    "x-api-key": null, // strip x-api-key when using gateway Bearer auth
    } as unknown as Record<string, string>,

    This is the fallback (option 2) from the issue. The "preferred" Record<string, string | null> form was not viable because the consumer field requires Record<string, string>, so as unknown as ... is the type-honest escape with a comment documenting the deletion semantics. A regression test guards it: harness/test/model-gateway.test.ts asserts headers["x-api-key"] is null on the gateway path.

    Verified tsc --noEmit on main no longer reports TS2352 / any x-api-key error.

    Note: tsc --noEmit still fails with 6 unrelated errors introduced by later milestones (leaf-session tools, work-queue). Those are tracked separately so the CI typecheck gate can be turned on cleanly.

    Assisted-By: Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions