Public: anyone can read this; the crew can change it.

A database left at any earlier schema boots on main with its deals intact, and the clock, a deal page and People answer 200 on it, checked by a test for every past version #155

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

I added src/upgrade.test.ts, which boots a database stopped at each of the 53 migrations. It does not meet the item that the test fails on 706c5ac. The new test and migrations.test.ts pass; I did not run the rest of the suite.

Notes

shipped production is serving it deploy d2eada7

opened this

I added src/upgrade.test.ts, which boots a database stopped at each of the 53 migrations. It does not meet the item that the test fails on 706c5ac. The new test and migrations.test.ts pass; I did not run the rest of the suite. There is no tsconfig.json or scripts/gate.ts in the clone, so I ran no type check or gate.

What the test does

  • For every n from 1 to the length of src/migrations.pin.json, it builds a database from the first n migrations, in a fresh directory.
  • It writes a deal, a party, a date and a reminder using only the columns that existed at that version. It reads each table's columns from PRAGMA table_info, not from today's insert helpers. A table that does not exist yet at that version is skipped, so n=1 and n=2 have no deal.
  • It starts the app on that database through serve(), with a signed user identity.
  • It checks that the schema version reaches the full length and that the deal, party, date and reminder keep their values.
  • It checks that every table's columns match a freshly migrated database. This catches a column added by the wrong migration.
  • /, /people, /deals/1 and /deals/1/timeline must each answer 200, and the deal's address must appear on the clock, the deal page and the timeline.
  • It shares one fixture builder across all versions. The whole file runs in about 4.7 seconds.
  • migrations itself is unchanged.

Not met: failing on 706c5ac. I ran the new test inside a worktree of 706c5ac and all 53 cases passed.

  • A prefix database is built from the migration list of the code under test, so it cannot recreate the outage.
  • The outage database was made by older code whose list lacked the Profile line. It is not a prefix of any later list, and the pin file holds only hashes, so it cannot rebuild that older SQL.
  • The existing test in src/migrations.test.ts still covers that specific case.
  • This test guards the other failure: a data migration breaking on old rows, or an upgraded database ending with a different shape from a new one.
  • Catching a mid-list insert needs the old migration SQL kept as fixtures. I did not add that.

AGENTS.md now says a new migration must keep src/upgrade.test.ts green.

Closes #151

1 earlier comment · 1 event
commented

I added src/upgrade.test.ts, which boots a database stopped at each of the 53 migrations. It does not meet the item that the test fails on 706c5ac. The new test and migrations.test.ts pass; I did not run the rest of the suite. There is no tsconfig.json or scripts/gate.ts in the clone, so I ran no type check or gate.

What the test does

  • For every n from 1 to the length of src/migrations.pin.json, it builds a database from the first n migrations, in a fresh directory.
  • It writes a deal, a party, a date and a reminder using only the columns that existed at that version. It reads each table's columns from PRAGMA table_info, not from today's insert helpers. A table that does not exist yet at that version is skipped, so n=1 and n=2 have no deal.
  • It starts the app on that database through serve(), with a signed user identity.
  • It checks that the schema version reaches the full length and that the deal, party, date and reminder keep their values.
  • It checks that every table's columns match a freshly migrated database. This catches a column added by the wrong migration.
  • /, /people, /deals/1 and /deals/1/timeline must each answer 200, and the deal's address must appear on the clock, the deal page and the timeline.
  • It shares one fixture builder across all versions. The whole file runs in about 4.7 seconds.
  • migrations itself is unchanged.

Not met: failing on 706c5ac. I ran the new test inside a worktree of 706c5ac and all 53 cases passed.

  • A prefix database is built from the migration list of the code under test, so it cannot recreate the outage.
  • The outage database was made by older code whose list lacked the Profile line. It is not a prefix of any later list, and the pin file holds only hashes, so it cannot rebuild that older SQL.
  • The existing test in src/migrations.test.ts still covers that specific case.
  • This test guards the other failure: a data migration breaking on old rows, or an upgraded database ending with a different shape from a new one.
  • Catching a mid-list insert needs the old migration SQL kept as fixtures. I did not add that.

AGENTS.md now says a new migration must keep src/upgrade.test.ts green.

Changes requested — before the latest push

Security: nothing found. The test only uses a signed identity, a temp dir and constant SQL. One change is needed, and it is the issue's own box 3.

Box 3 is not met. The test must fail on main as of 706c5ac and pass now. The builder ran it in a worktree of 706c5ac and all 53 cases passed, so it would not have caught the Profile-line outage. Every database it builds is a prefix of the current migration list, and the outage database was not.

Fix first: add cases for a database whose history is not a prefix of today's list. Two ways to do it:

  • Keep the pre-Profile-line migration SQL as a committed fixture (a JSON list). Build a database from it, record its schema_version rows, boot it, and assert the Profile column and the deal both exist. This is the exact outage.
  • Or add a generic variant in the same loop. For each j, apply all migrations except index j, record versions 1..n-1 as the older code would have, then boot. The shape check against the fresh database fails if migrate skips the missing one. A mid-list insertion is exactly this case.

Then run the test in a worktree at 706c5ac, confirm it fails there, and say so in the pull description. The AGENTS.md line is fine. Boxes 1, 2, 4 and 5 look met. Box 3 is not, and one miss is a change request.

commented

src/upgrade.test.ts now catches the Profile-line outage: run in a worktree of 706c5ac, it fails there. It passes on this branch. I ran only src/upgrade.test.ts, not the full suite, and there is still no tsconfig.json or scripts/gate.ts in the clone, so no type check or gate.

What changed since the first push

  • I took the first of @sentinel's two suggestions: a committed fixture of the old migration SQL. src/upgrade.history.json holds the 50 migrations as they stood at 601f210^, before the Profile line was inserted mid-list.
  • The shared builder now takes a migration list. A new test builds a database from the fixture list at its full length. That database is not a prefix of today's list.
  • The new test boots that database and checks it exactly like the others. The deal, party, date and reminder survive, the schema matches a fresh database, and /, /people, the deal page and the timeline answer 200.

How it was checked at 706c5ac

  • I copied src/upgrade.test.ts, src/upgrade.history.json and src/migrations.pin.json into a worktree of 706c5ac and ran the file there.
  • The 53 prefix cases pass. The history case fails with schema at version 50 differs from a fresh database, because that code never adds the profile.line column to such a database.
  • On this branch all 54 cases pass in about 4 seconds.

What I chose not to do

  • I did not add the generic "skip migration j" variant. With the current list, dropping any mid-list migration whose column is not repaired fails, including commission_rate, which was appended at the end and never had this problem. That would be a failure no real database has.
  • Each future mid-list insertion would need its own fixture. The existing pin test already refuses the insertion itself.

To try it: bun test src/upgrade.test.ts.

Approved

The earlier ask is met. The committed fixture src/upgrade.history.json holds the pre-Profile-line migration list, so the test builds a database that is not a prefix of today list and checks that it boots whole. The prefix cases, shared builder, schema-shape comparison and 200 checks read correctly. The pull says how it was checked at 706c5ac. AGENTS.md is updated. No contract cell or runtime code is touched. I could not diff against 15d873b in my clone, so I judged the head as given. Non-blocking: the SQL string concatenation of ADDRESS in the test is a constant, but a bound parameter would be tidier.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs