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

Put back an asset's earlier words: each asset keeps its last five versions and one tap restores one #56

opened this

Merged 32d 10h ago, live in production

Each asset now keeps its last five versions, and one tap restores one. The full suite passes (215 tests, 0 fail). bun x tsc --noEmit did not run because the repo has no tsconfig and bun x tsc printed only its help text.

Notes

opened this

Each asset now keeps its last five versions, and one tap restores one. The full suite passes (215 tests, 0 fail). bun x tsc --noEmit did not run because the repo has no tsconfig and bun x tsc printed only its help text. scripts/gate.ts and scripts/fast.ts are not in this clone. I did not start the app.

What changed

  • Table and migration: src/db.ts has a forward-only migration adding asset_version (words, who replaced them, when, why). It cascades with the listing, so removing a listing removes its versions. I wrote it with IF NOT EXISTS, as one entry.
  • Saving: every save of an asset keeps the words it replaces, and the newest five per asset stay (keepWords in src/actions.ts). A save with the same words keeps nothing. The reasons are "edited", "suggestion used", "rewrite in Bold/Warm/Classic", "facts changed" and "restored".
  • restoreAsset:
    • It asks permit for listing update, so no contract cell changed.
    • It saves through the same path as an edit, so the words are checked again, audited, and approval is cleared. Restoring is itself undoable.
    • A seen value that no longer matches the asset gives 409, as approval does.
  • Page: under each asset's box, <details> reads "Earlier versions (n)". It lists when, by whom, why, and the first line. Each entry has a Restore form (a plain POST, no JavaScript) that only people who may edit see. Readers see the list without Restore.
  • Other doors:
    • MCP has restore_asset and list_versions, which the issue didn't ask for, so an agent can find the version ids.
    • The JSON API takes { kind, restore, seen? } on PATCH /api/listings/:id.
    • In the terminal, v restores the newest earlier words of the asset under the cursor.
    • contract/openapi.json is re-emitted.
  • Walkthrough: README gains step 6, "Put back your MLS words". The later steps are renumbered, and src/walkthrough.test.ts walks the new step.
  • Tests: src/versions.test.ts covers the sixth save dropping the oldest, restore bringing the words back and clearing approval, a reader and an anonymous visitor being refused, and a stale seen giving a conflict. It also covers the version list on the page, versions going with the listing, and the MCP and terminal doors.

Two existing tests changed.

  • src/server.test.ts lists the two new tools.
  • src/sample.test.ts re-ran "the last migration" to test the sample-approval migration. Mine is now last, so the test re-runs from the sample migration on instead. Mine is safe to run again.

What I chose not to do

  • No "undo" for the status-post toggling in markStatus, which has no person to credit. It keeps no versions.
  • No new CSS classes.

Merge order: #34 also adds a migration, so whichever lands second takes the next version number. Mine is the 18th entry in migrations.

To try it: on a listing, edit the MLS box and press Save, or press Rewrite all. Then open "Earlier versions (1)" under the box and press Restore. The words come back unapproved.

Closes #39

3 earlier comments · 1 event
commented

Each asset now keeps its last five versions, and one tap restores one. The full suite passes (215 tests, 0 fail). bun x tsc --noEmit did not run because the repo has no tsconfig and bun x tsc printed only its help text. scripts/gate.ts and scripts/fast.ts are not in this clone. I did not start the app.

What changed

  • Table and migration: src/db.ts has a forward-only migration adding asset_version (words, who replaced them, when, why). It cascades with the listing, so removing a listing removes its versions. I wrote it with IF NOT EXISTS, as one entry.
  • Saving: every save of an asset keeps the words it replaces, and the newest five per asset stay (keepWords in src/actions.ts). A save with the same words keeps nothing. The reasons are "edited", "suggestion used", "rewrite in Bold/Warm/Classic", "facts changed" and "restored".
  • restoreAsset:
    • It asks permit for listing update, so no contract cell changed.
    • It saves through the same path as an edit, so the words are checked again, audited, and approval is cleared. Restoring is itself undoable.
    • A seen value that no longer matches the asset gives 409, as approval does.
  • Page: under each asset's box, <details> reads "Earlier versions (n)". It lists when, by whom, why, and the first line. Each entry has a Restore form (a plain POST, no JavaScript) that only people who may edit see. Readers see the list without Restore.
  • Other doors:
    • MCP has restore_asset and list_versions, which the issue didn't ask for, so an agent can find the version ids.
    • The JSON API takes { kind, restore, seen? } on PATCH /api/listings/:id.
    • In the terminal, v restores the newest earlier words of the asset under the cursor.
    • contract/openapi.json is re-emitted.
  • Walkthrough: README gains step 6, "Put back your MLS words". The later steps are renumbered, and src/walkthrough.test.ts walks the new step.
  • Tests: src/versions.test.ts covers the sixth save dropping the oldest, restore bringing the words back and clearing approval, a reader and an anonymous visitor being refused, and a stale seen giving a conflict. It also covers the version list on the page, versions going with the listing, and the MCP and terminal doors.

Two existing tests changed.

  • src/server.test.ts lists the two new tools.
  • src/sample.test.ts re-ran "the last migration" to test the sample-approval migration. Mine is now last, so the test re-runs from the sample migration on instead. Mine is safe to run again.

What I chose not to do

  • No "undo" for the status-post toggling in markStatus, which has no person to credit. It keeps no versions.
  • No new CSS classes.

Merge order: #34 also adds a migration, so whichever lands second takes the next version number. Mine is the 18th entry in migrations.

To try it: on a listing, edit the MLS box and press Save, or press Rewrite all. Then open "Earlier versions (1)" under the box and press Restore. The words come back unapproved.

the crew's run was interrupted: restart, resumes on the next pass — cancelled
commented

Each asset keeps its last five versions and one tap restores one; this push narrows who can see the list and rebuilds the terminal's version.

The forge showed one "changes requested" review but no text for it, so I worked from the uncommitted changes you'd left on the branch. If the review asked for something else, tell me.

What changed in this push

  • Earlier versions are for editors only. listVersions now asks permit for listing update instead of read. The page hides the "Earlier versions" list from readers, and the MCP list_versions tool refuses them. They hold drafts and words taken out on purpose, which the property page never shows a reader. No contract.json cell changed.
  • Terminal: v now opens a numbered list of that asset's earlier versions, and 1 to 5 puts one back. It no longer restores the newest version blindly.
  • MCP: restore_asset takes an optional seen, the same stale-page check the web form and JSON API already have.
  • Saves with no identity: keepWords stores no id or name for an anonymous saver.
  • Tests:
    • New: contract.test.ts checks restore and list against the update cell at the action, the tool and the version list.
    • New: versions.test.ts covers the page form over HTTP, JSON PATCH with restore (403 for another person, 409 for a stale seen), the terminal list and number, and readers seeing nothing.
    • Fixed: the suite hit the per-user write rate limit (429) when my HTTP tests shared user ids with other test files, so my tests now use their own ids.
  • Docs: the README walkthrough says who sees the list and how the terminal and MCP reach it. docs/design/areas/versions.md is added.

Checks: the full suite passes (218 tests, 0 fail). The type check did not run because the repo has no tsconfig.json. scripts/gate.ts and scripts/fast.ts aren't in this clone, and scripts/design-lint.ts doesn't exist, so I ran the repo's scripts/lint-design.ts and it printed nothing. I did not start the app.

Not done: no undo for status-post toggling, and no new CSS classes.

Merge order: #34 also adds a migration. Whichever lands second takes the next version number; mine is the 18th entry.

To try it:

  • On a listing you own, edit the MLS box and press Save.
  • Open "Earlier versions (1)" under the box and press Restore. The words come back unapproved.
  • In the terminal, press v on an asset, then its number.

Closes #39

🤖 Generated with Claude Code

commented

The eight a11y failures were most likely the shared write rate limit, and I've pushed a fix. I did not reproduce the failure here. The full suite passed locally before and after, so the cause is a diagnosis, not a confirmed failure.

All the test files run in one process and share one rate-limit bucket per user id. The a11y suite signs in as u1 and does one write (it flags one asset). The server and other suites also write as u1, and my earlier extra restore steps in the walkthrough test used u1 too. On the deploy's run order, that probably used up u1's budget of 20 writes. The a11y write would then get a 429 instead of a 303, and every a11y test that needs that flagged asset would fail.

src/walkthrough.test.ts now signs in as walk-realtor and src/a11y.test.ts as a11y-admin, so neither shares a budget with other suites. Only test files changed. The full suite passes locally (218 tests, 0 fail).

The pull description from my last message still stands.

commented

I merged main into the branch and pushed it. All five conflicts are resolved and the full suite passes (224 tests, 0 fail). I did not run the type check, since the repo has no tsconfig.json.

  • src/db.ts: main's coming-soon status rebuild now comes first and my asset_version migration after it. The rebuild drops and recreates listing, which would cascade away version rows if mine ran first. My migration is IF NOT EXISTS, so it is safe on any database.
  • src/comingsoon.test.ts: this test assumed the rebuild was the last migration. It now replays everything before the rebuild, found by its CREATE TABLE listing_old, instead of "all but the last". The test was wrong about ordering, not the code.
  • src/sample.test.ts: I kept my version, which re-runs from the sample-approval migration onward. That range now includes the rebuild, which main says re-runs harmlessly.
  • src/routes.ts: the PATCH summary now has both the "put an earlier version back" and "coming soon" wording.
  • README.md: main's "Coming soon" filter wording is kept, and the walkthrough steps stay numbered after my new step 6.
  • contract/openapi.json: re-emitted with bun run contract:emit rather than merged by hand.
Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs