Skip to content

refactor(api): extend #206 type-safety to replication (#359 batch 4)#380

Merged
brandonrc merged 1 commit intomainfrom
harden/359-type-safety-replication
May 9, 2026
Merged

refactor(api): extend #206 type-safety to replication (#359 batch 4)#380
brandonrc merged 1 commit intomainfrom
harden/359-type-safety-replication

Conversation

@brandonrc
Copy link
Copy Markdown
Contributor

Summary

Closes #359 (partial — batch 4). Same playbook as batches 1-3 (PRs #376/#377/#379) for src/lib/api/replication.ts. 11 as never removed; zero retained casts. Also drops 4 dead fields from local types (api_key/sync_filter/updated_at on PeerInstance, source_peer_id on PeerConnection) — all declared but unpopulated and unread.

Acceptance criteria

  • No uncommented as unknown as / as never in changed files
  • All tests pass (2068/2068)
  • New code coverage on changed lines ≥ 80%

Test plan

  • npm test — 2068/2068
  • npm run lint — 0 errors
  • npm run build — succeeds (TypeScript checked, Next prerender clean)

Remaining

dependency-track / promotion (medium); sbom / security / sso (large) — to be split across subsequent PRs to keep review tractable.

🤖 Generated with Claude Code

…batch 4)

Apply the #206 playbook to replication.ts. 11 `as never` casts removed.

src/lib/api/replication.ts:
  + adaptPeerInstance / adaptPeerInstanceList — narrowEnum the
    PeerStatus union ("online" | "offline" | "syncing" | "degraded"),
    normalize SDK's `?: string | null` to local type's `: string | null`
  + adaptPeerConnection — coerce optional latency_ms /
    bandwidth_estimate_bps (`?: number | null`) to `0` so the connection
    table doesn't render "undefined ms"
  + adaptIdentity — explicit field forwarding
  + adaptRegisterRequest / adaptAssignRequest — explicit field
    forwarding so a future local-type addition surfaces at typecheck
  + assertData on every successful read

Type honesty:
  - Dropped api_key, sync_filter, updated_at from PeerInstance — three
    fields declared on the local type pre-#359, never populated by the
    SDK, and never read by any consumer (grep -rn '\.api_key\|...'
    against src/ returns hits only on form state, not PeerInstance).
  - Dropped source_peer_id from PeerConnection (same reasoning).

Tests rewritten with realistic SDK fixtures (typed as Sdk* for compile-
time drift detection) and assertions on adapter output. New regression
tests for: empty response body, status enum fallback, undefined→null
nullable normalization, register-body shape, assign-body shape,
latency/bandwidth → 0 coercion.

CHANGELOG entry under [Unreleased] / Changed.

Closes #359 (partial — batch 4 of N). Remaining: dependency-track,
promotion (medium), sbom, security, sso (large).
@brandonrc brandonrc requested a review from a team as a code owner May 9, 2026 19:20
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 9, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@brandonrc brandonrc merged commit 2df01e5 into main May 9, 2026
18 checks passed
@brandonrc brandonrc deleted the harden/359-type-safety-replication branch May 9, 2026 19:30
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.

Extend #206 type-safety hardening to remaining lib/api modules

1 participant