Skip to content

Merge owner-declared surfaces by base URL when the spec locator misses - #77

Open
TaltonFiggins wants to merge 1 commit into
UsefulSoftwareCo:mainfrom
TaltonFiggins:fix/declared-surface-url-fallback
Open

Merge owner-declared surfaces by base URL when the spec locator misses#77
TaltonFiggins wants to merge 1 commit into
UsefulSoftwareCo:mainfrom
TaltonFiggins:fix/declared-surface-url-fallback

Conversation

@TaltonFiggins

Copy link
Copy Markdown

Problem

mergeDeclared (src/lib/discover.ts) folds an owner's /.well-known/integrations.json surface into the discovered result only when surfaceLocator matches. That locator prefers spec over url:

http|https://api.example.com/v1/openapi.json   ← declared (url + spec)
http|https://api.example.com/v1                ← discovered (url only)

Same API, two keys, so the declared surface is appended instead of merged and the domain page shows it twice: one row tagged discovered, one declared. The reverse also happens when discovery recorded a spec and the owner declared only the base URL.

Seen live on modem.dev today: "Modem API" rendered twice until we removed the spec URL from our declaration purely to force the match. That is the wrong incentive for owners, since the declaration is the place we want the spec.

Fix

Add a secondary index keyed by type|url in mergeDeclared and fall back to it when the primary locator lookup misses. mergeDeclaredSurface already copies spec/docs/url onto the surviving row when missing, so the merged row ends up with the spec either way. Surfaces without a url (spec-only, CLI, package-only) behave exactly as before.

preserveSlugs in the worker keys on the same locator, so slug continuity across re-runs is unchanged by this.

Tests

Three cases in src/lib/discover.test.ts:

  • declared url + spec folds into a discovered url-only row, keeps the spec, basis becomes declared
  • declared url-only folds into a discovered row that knows the spec (GraphQL introspection, which skips the network spec validation)
  • a declared surface with a different base URL is still added

bun test src/lib/discover.test.ts: 10 pass. Full bun test at the repo root: everything green except the 8 cli/ tests, which need cd cli && bun run build plus network and run in their own CI job. tsc --noEmit: no errors in the touched files.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BR5Ajen32HMbwJXaHDrhX1

mergeDeclared matched a declared surface to a discovered one only by
surfaceLocator, which prefers `spec` over `url`. An owner declaration
that names both url and spec therefore never matched the LLM-discovered
surface for the same API when discovery had recorded only the base URL
(and vice versa), and the domain page rendered the API twice: one row
"discovered", one "declared".

Add a secondary index keyed by `type|url` and fall back to it when the
primary locator lookup misses. mergeDeclaredSurface then fills the
missing spec/docs on the surviving row as before.

Seen on modem.dev: declared "Modem API" (url + spec) and discovered
"Modem API" (url only) both rendered until the declaration dropped its
spec URL to force a match.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BR5Ajen32HMbwJXaHDrhX1
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