Fix download endpoint returning wrong artifact for unmatched platform#47
Merged
shwetank-dev merged 6 commits intomainfrom Mar 17, 2026
Merged
Fix download endpoint returning wrong artifact for unmatched platform#47shwetank-dev merged 6 commits intomainfrom
shwetank-dev merged 6 commits intomainfrom
Conversation
Add seed data for two MCPB packages alongside existing skill seeds: - @nimblebraininc/echo: 9 versions (including prereleases), python server - @nimblebraininc/nationalparks: 6 versions, node server with user config Includes manifest helpers, version upserts, and download counts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The registry had duplicated schema files in src/schemas/generated/ that mirrored the shared package. This caused maintenance burden and version drift. Import directly from @nimblebrain/mpak-schemas instead and delete the generated copies. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace hand-written JSON Schema querystring with BundleSearchParamsSchema, use Fastify generics for type-safe request access, type the response as BundleSearchResponse, and replace runtime clamping with schema validation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Register errorHandler in test setup for 422 parity with production - Replace clamping test with schema validation rejection tests - Add tests for defaults, type filter, enum validation, q length, limit boundary, and has_more pagination - Seed artifacts for echo (universal) and nationalparks (multi-platform) - Create placeholder .mcpb files on disk for local download testing Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add resolveArtifact helper to enforce platform selection rules: - Both os and arch required together (400 if only one provided) - Exact platform match when both specified (404 if no match) - Universal any/any artifact when no platform params (404 if none) - Invalid enum values rejected at schema level (422) Previously the endpoint fell back to artifacts[0] when no match was found, silently serving a wrong-platform artifact (e.g. darwin-arm64 when linux-arm64 was requested). Fixes #28. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
Author
mgoldsborough
approved these changes
Mar 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #28 — the bundle download endpoint (
/v1/bundles/@:scope/:package/versions/:version/download) was silently serving a wrong-platform artifact when the requestedos/archdidn't match any available artifact. For example, requestingos=linux&arch=arm64for a bundle that only haddarwin-arm64would return thedarwin-arm64artifact with a 200 instead of a 404.Root cause
The artifact selection logic defaulted to
artifacts[0]and never cleared that default when platform params were provided but didn't match:Fix:
resolveArtifacthelperReplaced the inline logic with a
resolveArtifact(artifacts, os?, arch?)function that enforces these rules:osnorarchany/anyexistsosnorarchany/anyos/archosandarchosandarchZod schema validation
BundleDownloadParamsSchemato@nimblebrain/mpak-schemaswith enum validation (os: darwin/linux/win32,arch: x64/arm64)BundleVersionPathParamsSchemainapps/registry/src/schemas/bundles.tsfor path paramstoJsonSchema()callsastype castsOther changes in this branch
@nimblebrain/mpak-schemaspackageBundleSearchParamsSchema)echowith universal artifacts,nationalparkswith multi-platform artifacts)Test plan
pnpm --filter @nimblebrain/mpak-registry typecheck— passespnpm --filter @nimblebrain/mpak-registry lint— passespnpm --filter @nimblebrain/mpak-registry test— 93 tests pass (7 new download tests)curl 'localhost:3200/v1/bundles/@nimblebraininc/nationalparks/versions/latest/download?os=linux&arch=arm64'→ 404curl 'localhost:3200/v1/bundles/@nimblebraininc/nationalparks/versions/latest/download?os=foo&arch=bar'→ 422curl 'localhost:3200/v1/bundles/@nimblebraininc/nationalparks/versions/latest/download?os=darwin&arch=arm64'→ 200curl 'localhost:3200/v1/bundles/@nimblebraininc/echo/versions/latest/download'→ 200 (universal)curl 'localhost:3200/v1/bundles/@nimblebraininc/nationalparks/versions/latest/download'→ 404 (no universal)curl 'localhost:3200/v1/bundles/@nimblebraininc/echo/versions/latest/download?os=linux'→ 400 (missing arch)🤖 Generated with Claude Code