feat(#279): cross-language contract test — backend client ↔ AI service Pydantic schemas#332
Merged
kilodesodiq-arch merged 2 commits intoJul 19, 2026
Conversation
…service schemas Implements issue ChainForgee#279 (backlog item ChainForgee#71). New files: - app/backend/scripts/openapi-validate.ts Shared helpers to fetch the AI service OpenAPI document, resolve $refs, and structurally validate a plain object against a schema. Also runnable as a standalone CLI for quick spec drift checks. - app/backend/test/contract/ai-service.contract.spec.ts Contract test that: • Obtains the AI service OpenAPI spec (live fetch when AI_SERVICE_URL is set; falls back to an embedded snapshot so CI always runs). • Asserts all six v1 endpoints the backend depends on exist in the spec. • Verifies provider_preference and TaskStatus enum values. • Checks required fields on every response schema against the TypeScript interfaces the backend compiles against. • Validates real AI service fixture payloads (app/ai-service/fixtures/) against those schemas — catching enum drift or missing fields before they reach production. • Compile-time type guards ensure backend interfaces stay in sync with the schema shapes (fails the build on shape divergence).
Contributor
|
Hi 👋 Appreciate this PR! The CI is flagging a failing check — could you take a peek at the failed job and push a fix? Happy to help if you need a hand 🙏 |
ESLint rule @typescript-eslint/no-unused-vars (error) was failing CI: 'SchemaObject' is defined but never used. Allowed unused vars must match /^_/u SchemaObject was imported but never referenced in the test file. Removing it is the clean fix — it can be re-added with an _ prefix if it becomes needed in future.
Contributor
Author
Done. |
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
Closes #279
Adds the contract test layer described in issue #279 (backlog item #71) to catch JSON schema drift between the NestJS backend client and the FastAPI AI service Pydantic schemas before it reaches production.
Changes
app/backend/scripts/openapi-validate.ts(new)Shared utility and standalone CLI that:
$refpointers within the documentRun standalone to check spec drift without tests:
app/backend/test/contract/ai-service.contract.spec.ts(new)Contract test suite with five assertion groups:
openapiversion string,info,components.schemasprovider_preferencevalues (auto/test/openai/groq);TaskStatuslifecycle valuesrequired[]array matches the TypeScript interfaces the backend compiles againstapp/ai-service/fixtures/*.jsonpayloads are validated against the declared schemasverification/erroron humanitarian response)Live vs CI mode — when
AI_SERVICE_URLis set the spec is fetched live; otherwise the test falls back silently to an embedded snapshot so CI runs without a live AI service.Compile-time type guards — TypeScript
assertsfunctions for all five response interfaces cause a build failure if the backend's internal types drift from the schema shapes.How to run
Files affected
app/backend/scripts/openapi-validate.ts— newapp/backend/test/contract/ai-service.contract.spec.ts— new