feat(tests): FoodFiles v2 SQL diff validator#9
Open
stackbilt-admin wants to merge 1 commit intomainfrom
Open
Conversation
Closes #1. Opens the generator-accuracy feedback loop by diffing generateSQL() output against the actual migration files for each FoodFiles v2 contract. What this adds - tests/foodfiles-sql-diff.test.ts: vitest test that walks every *.contract.ts under apps/api/src/contracts/, dynamically imports it, runs generateSQL(), parses the result, and structurally diffs it against the CREATE TABLE statement from apps/api/db/migrations/. - vitest.config.ts: adds @stackbilt/contracts → src/index.ts alias so FoodFiles contract files can resolve their import of this package at test time without a published build. What the diff checks (per contract → migration) - Column-name set parity - SQLite type parity - NOT NULL parity - DEFAULT-value presence parity What it intentionally skips (will gate contracts#2/#3) - Index shape, foreign keys, CHECK constraints — generator v0.1 doesn't emit these consistently yet. Known drifts Initial run surfaces 6 NOT NULL drifts across MealPlan and PantryItem contracts. These are encoded in a KNOWN_DRIFTS allowlist so CI is green today; fixes to contract or migration should remove entries, so regressions re-fail the test. Each known drift is logged at test runtime for visibility. CI behavior - Test suite auto-skips when FOODFILES_PATH doesn't resolve to a directory containing apps/api/src/contracts. CI without FoodFiles checked out stays green; local runs set FOODFILES_PATH to opt in. Usage FOODFILES_PATH=../foodfilesapi_v2 npx vitest run tests/foodfiles-sql-diff.test.ts Co-Authored-By: Claude Opus 4.6 (1M context) <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.
Summary
Closes #1. Opens the generator-accuracy feedback loop by diffing `generateSQL()` output against actual migration files for each FoodFiles v2 contract.
What this adds
What the diff checks
Initial run results
7 contracts scanned, 6 real drifts caught on first execution — exactly the signal the issue asked for:
These are encoded in a `KNOWN_DRIFTS` allowlist so CI stays green today. Fixing a drift removes its entry → regressions re-fail the test.
CI behavior
Auto-skips when `FOODFILES_PATH` doesn't resolve to a directory containing `apps/api/src/contracts`. CI without FoodFiles checked out stays green; local runs opt in via env var.
Usage
```bash
FOODFILES_PATH=../foodfilesapi_v2 npx vitest run tests/foodfiles-sql-diff.test.ts
```
Test plan
Closes #1
🤖 Generated with Claude Code