Repository navigation
feat: typed reads, request log, self-tests, published contracts and hermetic CI - #13
Open
VincentJerico wants to merge 6 commits into
Open
VincentJerico wants to merge 6 commits into
VincentJerico wants to merge 6 commits into
Conversation
… typed Tests no longer read the untyped value res.json() returns. readJson parses, checks the contract and throws a ContractError listing every broken field path, so every body read doubles as a contract check. The matcher shares the same issue formatting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The request fixture records method, URL, params, status, duration and both bodies (token and password redacted, long bodies truncated) and attaches them as api-calls.json on failure, or always with API_LOG=always. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n can fail A new offline 'selftest' project runs against a local stub server, so it needs no API. Each planted bug was checked: a matcher that always passes, a cleanup that ignores leaks and a recorder that leaks passwords each fail exactly one self-test. The API suite is now the 'api' project. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…emas A self-test fails when a contract changes and its published file doesn't (compared as parsed JSON, so formatting can't break it), or when a file outlives its contract. npm run schemas:update regenerates them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… drift Pushes and PRs run the API suite against mwinteringham/restfulbooker as a service container, so results don't depend on the shared public demo. The weekly schedule (or a manual run with live: true) tests the live API, and a failed weekly run opens or comments on a 'Contract drift' issue. The quality job now runs the offline self-tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…CI layers Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What & why
Takes the framework from a solid starter to something I'd defend in a senior SDET interview: typed reads, failures that explain themselves, gates proven able to fail, hermetic CI and contract drift alerts. One commit per feature.
src/http/readJson.ts):readJson(res, Schema)parses the body, validates it against its contract and returns a typed value, or throws aContractErrorlisting every broken field with the status and URL. All tests now use it instead of the untypedres.json(), so every body a test reads is also a contract check.src/http/recorder.ts): therequestfixture records every call (method, URL, query, status, duration, both bodies) and attaches it asapi-calls.jsonwhen a test fails. Tokens and passwords are redacted;API_LOG=alwaysattaches it to passing tests too.tests/selftest/, newselftestproject): a local stub server proves the matcher,readJson,cleanup()and log redaction each fail when they should. The API suite is now theapiproject.docs/schemas/*.schema.json): the five Zod response contracts exported as JSON Schema (draft 2020-12). A self-test fails if a contract changes without its file being regenerated (npm run schemas:update), or if a file outlives its contract.mwinteringham/restfulbookeras a Docker service container;live: true, tests the live API;api-calls.jsonentry.How it was tested
Node 22.23.4 locally:
npm run lint,format:check,typecheck: pass.npm test: 32 passed (15 self-tests + 17 API tests against the live API).npm run test:apiagainst Restful-Booker in Docker (BASE_URL=http://localhost:3001): 17 passed.cleanup()that ignores leaks;Not yet proven: the drift-issue job. It only runs when a scheduled live run fails, and testing it would open a real issue on this public repo, so I haven't triggered it. The
ghcommands it uses are standard (issue list/issue create/issue comment) and need onlyissues: write.🤖 Generated with Claude Code