Skip to content

fix(link-legacy-key): validate response with Zod and add fetch timeout#2

Open
matmilbury wants to merge 1 commit intofeature/legacy-key-migrationfrom
fix/link-legacy-key-review-fixes
Open

fix(link-legacy-key): validate response with Zod and add fetch timeout#2
matmilbury wants to merge 1 commit intofeature/legacy-key-migrationfrom
fix/link-legacy-key-review-fixes

Conversation

@matmilbury
Copy link
Copy Markdown
Contributor

Summary

Addresses two issues from code review of #1:

  • Replace as LinkResult cast with Zod schema parsingres.json() returns external data from mcp-gateway. Casting with as bypasses runtime validation; if the response shape drifts, the code silently takes the wrong branch. Now uses LinkResultSchema.parse() which throws a clear error on malformed responses.
  • Add AbortSignal.timeout(10s) to the fetch call — Without a timeout, a misbehaving mcp-gateway (accepts TCP, never responds) hangs eterna login indefinitely. The 10s timeout ensures the CLI falls through to the existing warning path.

Also adds zod as a production dependency and creates src/auth/validation.ts for the schema (per CLAUDE.md: "Define schemas in validation.ts").

Test plan

  • Run eterna login with ETERNA_MCP_KEY set — verify link succeeds and prints "Legacy account linked"
  • Run eterna login with ETERNA_MCP_KEY set against a non-JSON-returning endpoint — verify Zod parse error is caught gracefully
  • Run eterna login with ETERNA_MCP_URL pointing to a blackhole (accepts TCP, never responds) — verify timeout after ~10s with warning message
  • npm run typecheck passes
  • npm run build passes

🤖 Generated with Claude Code

Replace `as LinkResult` cast on the mcp-gateway response with Zod schema
parsing to catch malformed responses at runtime instead of silently
proceeding with wrong data. Add AbortSignal.timeout(10s) to the fetch
call to prevent the login command from hanging indefinitely if
mcp-gateway accepts TCP but never responds.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant