feat: add contract test suite for sdk-to-spec conformance#18
Open
omermorad wants to merge 17 commits into
Open
feat: add contract test suite for sdk-to-spec conformance#18omermorad wants to merge 17 commits into
omermorad wants to merge 17 commits into
Conversation
SDK Contract Tests Coverage39/0 tests passed across 12 test files Code Coverage (v8, source-mapped)${COVERAGE_TABLE}
OpenAPI Endpoint Coverage${OPENAPI_TABLE} |
Run SDK methods against a Prism mock server (with --errors) to validate that each public method maps to the correct route, sends spec-valid requests, and deserializes responses without throwing. Tests use a request-capture harness (custom fetch) to assert HTTP method and path per call. A prism-sentinel test verifies that Prism's --errors flag is actively enforcing the spec. A coverage guardrail introspects the SDK client and fails if any public method lacks a test. Spec is fetched from Gateway at test time via gh CLI, removing the need for a Docker image or cross-repo artifact. 13 tests currently fail due to spec issues (missing required fields, enum mismatches, undocumented routes), not SDK bugs. These are real conformance findings that need spec fixes.
- Use absolute path to prism binary instead of npx (ensures it resolves from contract-tests/node_modules regardless of cwd) - Add @nimble-way/nimble-js as workspace:* dependency so pnpm links the built SDK into the contract-tests workspace - Use pnpm --filter to run vitest in the correct workspace context - Apply SDK prettier formatting (printWidth 110, 2-space indent)
CI starts ghcr.io/nimbleway/sdk-mock-server (Prism + spec) as a container, then runs tests against it. setup.ts detects if Prism is already running (Docker case) or starts it locally (dev case with fetched spec).
24a716c to
a2bcbcf
Compare
…from CI ESLint: add contract-tests/ to the override that disables no-restricted-imports, since it legitimately imports @nimble-way/nimble-js as a workspace dependency. CI: replace Docker-based Prism with fetch-spec + local Prism startup via setup.ts. The sdk-mock-server image does not exist yet (Gateway PR #122 not merged), and the old sdk-contract-tests image does not work with the entrypoint override.
…po in CI The GITHUB_TOKEN cannot access the internal Gateway repo (404). Bundle the spec directly so CI does not need cross-repo access. Developers can update the spec by running: pnpm --filter sdk-contract-tests run fetch-spec
…c bugs All failures are OpenAPI spec conformance issues, not test bugs: - shared batch schema leaks search_engine as required for non-SERP endpoints - response schemas missing required fields (status_url, _query, url, parsing) - type/enum mismatches (next_cursor, crawl status, api_type) - media endpoint only declares binary content type - agent.publish and domain-knowledge.getDriver routes not in public spec Using test.fails so CI passes green. When a spec fix lands and the bundled spec is updated, any fixed test will flip to unexpected-pass, signaling it should be converted back to a normal test. Also excludes contract-tests/spec/ from prettier (bundled YAML).
davidr-nimble
approved these changes
May 12, 2026
Gateway PR #122 merged, ghcr.io/nimbleway/sdk-mock-server:latest is now available. CI pulls the image and runs Prism in Docker instead of starting it locally.
Replace manual process spawn and Docker CLI steps with testcontainers. It handles image pull, container lifecycle, port mapping, and cleanup. CI no longer needs manual docker run/stop steps; testcontainers in setup.ts manages everything. GHCR login is kept for pulling the private image.
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
contract-tests/workspace with vitest-based contract tests validating every public SDK method against the OpenAPI spec--errorsflag is actively enforcing the spectest.failsso CI stays green; they auto-flip when spec fixes landArchitecture
Test plan
--errorsenforcement is active