Skip to content

refactor(AP-128): import shared routeContractById in api, upload, content#180

Merged
isuttell merged 2 commits into
mainfrom
cursor/import-route-contract-by-id-c96e
Jun 3, 2026
Merged

refactor(AP-128): import shared routeContractById in api, upload, content#180
isuttell merged 2 commits into
mainfrom
cursor/import-route-contract-by-id-c96e

Conversation

@isuttell

@isuttell isuttell commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Removes three duplicate local contractById helpers and routes all three Workers through the shared routeContractById export from @agent-paste/contracts.

Changes

  • api (route-contracts.ts): Re-exports routeContractById as contractById; aliases RouteContractById for existing ContractById type usage.
  • upload / content: Replace local lookup implementations with const contractById = routeContractById near module setup (content now gets the same Extract<> narrowing as api/upload).
  • test: Expect the shared error message (Unknown route contract: …) for missing ids.

Verification

  • pnpm verify
  • pnpm test:coverage

Linear Issue: AP-128

Open in Web Open in Cursor 

Replace three local contractById implementations with the typed export
from @agent-paste/contracts so route contract narrowing stays consistent
across Workers.

Co-authored-by: Isaac Suttell <isaac@isaacsuttell.com>
@linear-code

linear-code Bot commented Jun 3, 2026

Copy link
Copy Markdown
AP-128 Import shared routeContractById instead of three local copies

Parent: AP-126. Architecture review finding #4. No hot seam — fully parallel-safe; good first/warm-up ticket.

Outcome

The three Workers resolve a Route Contract by id through the single exported routeContractById from @agent-paste/contracts instead of three slightly-different local copies, so the typed narrowing is consistent across api, upload, and content.

Context docs

Problem

packages/contracts/src/routes/registry.ts:565-571 already exports a typed routeContractById<Id>(id). But each Worker re-implements its own contractById: apps/api/src/route-contracts.ts:9-15, apps/upload/src/index.ts:628-634, apps/content/src/index.ts:382-388. The copies drift — content's loses the Extract<...> narrowing the others have. Pure pass-throughs that fail the deletion test (the behavior already exists in the shared export).

Likely files / packages

  • apps/api/src/route-contracts.ts
  • apps/upload/src/index.ts
  • apps/content/src/index.ts
  • packages/contracts/src/routes/registry.ts (import source; no change expected)

In scope

  • Delete the three local contractById functions; import routeContractById from @agent-paste/contracts.
  • Re-export under the existing local name per app if there are many call sites, to keep the diff small.
  • Ensure content gets the same typed narrowing as api/upload.

Out of scope

  • Any change to the shared routeContractById signature or the contracts registry structure.

Acceptance criteria

  • No local contractById/equivalent route-contract-by-id lookup remains in the three apps.
  • All three import the shared function; types still compile with the same (or stronger) narrowing.

Required checks

pnpm verify + pnpm test:coverage green. pnpm typecheck confirms the narrowing.

Security / data / operational invariants

None — pure internal refactor, no behavior change.

Dependencies / blockers

None. Parallel-safe with all other AP-126 slices.

Review in Linear

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1834de9e-1a14-45fb-b2b7-ea08014fb74d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/import-route-contract-by-id-c96e

Comment @coderabbitai help to get the list of available commands and usage tips.

Adds contracts-package tests for the shared lookup so branch coverage
stays above the 80% global threshold after removing local copies.

Co-authored-by: Isaac Suttell <isaac@isaacsuttell.com>
@isuttell isuttell marked this pull request as ready for review June 3, 2026 00:51
@isuttell isuttell merged commit 64721d1 into main Jun 3, 2026
5 checks passed
@isuttell isuttell deleted the cursor/import-route-contract-by-id-c96e branch June 3, 2026 00:51
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown

agent-paste PR preview resources were cleaned up. The shared Preview GitHub Environment is retained for future preview deploys.

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.

2 participants