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

After a demo, one Restore the sample deals action brings back the four sample deals exactly as the README describes, leaving every real deal untouched #40

Merged opened this

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

Merged

One Restore the sample deals action now puts the four samples back for the next demo, and the page, the terminal and the MCP tool all call it. The affected test files pass; the full suite is left to the forge's check on this push. bun x tsc --noEmit couldn't run because the repo has no tsconfig.json.

Notes

shipped production is serving it deploy d2eada7

opened this

One Restore the sample deals action now puts the four samples back for the next demo, and the page, the terminal and the MCP tool all call it. The affected test files pass; the full suite is left to the forge's check on this push. bun x tsc --noEmit couldn't run because the repo has no tsconfig.json. bun scripts/design-lint.ts doesn't exist here, so I ran scripts/lint-design.ts, which printed nothing.

What changed

  • Action: restoreSamples(db, who) in src/actions.ts is the one action. The page, the terminal and the MCP tool all call it. It is audited and emits deal.changed.
  • Delete and rewrite: restore() in src/sample.ts runs in one immediate transaction. It deletes WHERE author_id = 'sample', which is the only selector, then writes the four samples anchored to today. Dates, moves, parties and reminders go with their deals by cascade.
  • Shared writer: seed and restore now share one writeSamples. seed still checks the seeded guard. Restore overwrites the seeded and sample_anchor rows (INSERT OR REPLACE), so the guard stays set and the anchor is today.
  • Page: a "Sample deals" card under the clock, shown to signed-in people only. It uses a no-JS <details> confirm: "Restore the sample deals" opens a note and a "Yes, restore them" button. I avoided an inline confirm() because of the CSP. POST /samples/restore goes through the normal same-origin door and answers with the notice "Sample deals restored."
  • Terminal and MCP: R on the dates or week view asks you to type yes. The MCP tool is restore_samples.
  • Docs: README step 14 explains how to put the samples back; docs/TECHNICAL.md names the tool.

Tests (src/restore.test.ts, plus additions to src/server.test.ts and src/terminal.test.ts)

  • A person's deal is byte-for-byte identical after a restore.
  • The README walk-through holds again: Harbor View's inspection is red, Alder Lane closes this week, Orchard Row's appraisal shows its move, and Juniper Court is all ahead.
  • Restoring twice gives the same result as once, with four samples and a single seeded row.
  • A signed-out request is refused and changes nothing.
  • A cross-site POST gets a 403.
  • The terminal restores on yes and keeps everything on no.

Policy: no cell in contract.json is loosened. Restore asks permit(who, "deal", "create"), since it creates deals, so any signed-in user may restore. The table's delete cell is author, and the sample identity is the author of the samples, so a user couldn't remove them through remove_deal. If you'd rather limit restore to admins, that would need a new role or resource.

Not done:

  • The restore control is not in the Closed list area.
  • docs/VISION.md does not exist in this clone, so I didn't read it.

To try it: open a sample's date and mark it done, tap Sample deals, then Restore the sample deals, then Yes, restore them. The red Harbor View inspection is back.

🤖 Generated with Claude Code

Closes #34

2 earlier comments · 1 event
commented

One Restore the sample deals action now puts the four samples back for the next demo, and the page, the terminal and the MCP tool all call it. The affected test files pass; the full suite is left to the forge's check on this push. bun x tsc --noEmit couldn't run because the repo has no tsconfig.json. bun scripts/design-lint.ts doesn't exist here, so I ran scripts/lint-design.ts, which printed nothing.

What changed

  • Action: restoreSamples(db, who) in src/actions.ts is the one action. The page, the terminal and the MCP tool all call it. It is audited and emits deal.changed.
  • Delete and rewrite: restore() in src/sample.ts runs in one immediate transaction. It deletes WHERE author_id = 'sample', which is the only selector, then writes the four samples anchored to today. Dates, moves, parties and reminders go with their deals by cascade.
  • Shared writer: seed and restore now share one writeSamples. seed still checks the seeded guard. Restore overwrites the seeded and sample_anchor rows (INSERT OR REPLACE), so the guard stays set and the anchor is today.
  • Page: a "Sample deals" card under the clock, shown to signed-in people only. It uses a no-JS <details> confirm: "Restore the sample deals" opens a note and a "Yes, restore them" button. I avoided an inline confirm() because of the CSP. POST /samples/restore goes through the normal same-origin door and answers with the notice "Sample deals restored."
  • Terminal and MCP: R on the dates or week view asks you to type yes. The MCP tool is restore_samples.
  • Docs: README step 14 explains how to put the samples back; docs/TECHNICAL.md names the tool.

Tests (src/restore.test.ts, plus additions to src/server.test.ts and src/terminal.test.ts)

  • A person's deal is byte-for-byte identical after a restore.
  • The README walk-through holds again: Harbor View's inspection is red, Alder Lane closes this week, Orchard Row's appraisal shows its move, and Juniper Court is all ahead.
  • Restoring twice gives the same result as once, with four samples and a single seeded row.
  • A signed-out request is refused and changes nothing.
  • A cross-site POST gets a 403.
  • The terminal restores on yes and keeps everything on no.

Policy: no cell in contract.json is loosened. Restore asks permit(who, "deal", "create"), since it creates deals, so any signed-in user may restore. The table's delete cell is author, and the sample identity is the author of the samples, so a user couldn't remove them through remove_deal. If you'd rather limit restore to admins, that would need a new role or resource.

Not done:

  • The restore control is not in the Closed list area.
  • docs/VISION.md does not exist in this clone, so I didn't read it.

To try it: open a sample's date and mark it done, tap Sample deals, then Restore the sample deals, then Yes, restore them. The red Harbor View inspection is back.

🤖 Generated with Claude Code

commented

Both preview failures are fixed and pushed. The full local bun test now passes: 127 tests, 0 failures. I haven't seen the forge's check on the new push yet.

  • the print rules are scoped to the timeline page: my .confirm summary CSS sat after the @media print block, so the test read it as an unscoped print rule. I moved it above the print block in static/app.css.
  • an allowed change and a refused one each leave a row (429): this one passed when run alone and in my full local run, so I haven't reproduced it. My guess is the new restore test in src/server.test.ts made POSTs as u1, the same person audit.test.ts uses, and used up their rate-limit budget. That test now uses its own person, u-restore.

Because I couldn't reproduce the 429, the second fix is a likely cause, not a confirmed one. If the check fails on that test again, it is something else.

Changes requested — before the latest push

Restore works as described, but these need fixing in one round:

  1. Contract (high). restoreSamples deletes deals (DELETE FROM deal WHERE author_id = sample) but asks permit(who, "deal", "create") and audits as create. The deal delete cell is author, and the sample identity is the author, so before this pull no user could remove a sample deal. Now any signed-in user can, which loosens a cell without the issue asking for it. Gate the destructive part on the cell it exercises: ask permit for delete as well, or restrict restore to admin. If you want a new door, add its row. The audit row should say what was done.
  2. No row in src/contract.test.ts for the new door (page POST, MCP restore_samples, terminal R). Add one, covering anon refused, user and admin as decided in item 1.
  3. MCP has no behaviour test. server.test.ts only checks the tool is listed. Add a call as a signed-in caller and as anon, and check the refusal changes nothing.
  4. static/app.css. The .confirm rules were inserted between the /* On paper: ... */ comment and its @media print block, so the comment now describes the wrong rule. Put the comment back directly above the print block.
  5. Tidy. The body of writeSamples in src/sample.ts was not re-indented after it was extracted. The restore_samples clause in docs/TECHNICAL.md makes that sentence one very long line; wrap it. The restoreSamples import in src/terminal.ts should sit with the other relative imports, not between them.
commented

All five review items are fixed and pushed. The full local bun test passes (130 tests, 0 failures). I haven't seen the forge's check on this push yet.

Policy change. Restore is now admin-only. mayRestore in src/actions.ts asks permit for deal delete on a row the sample identity authored, and for deal create. The delete cell only lets an author or an admin through, and a user is not the author of sample deals, so only an admin passes. No cell in contract.json changed, and no signed-in user can remove sample deals who couldn't before. The audit row now says delete, with a refusal recorded as the same verb.

Other doors.

  • The page card and the terminal R key both ask mayRestore, so non-admins don't see the control, and R tells them "Only an admin may restore the sample deals."
  • The MCP tool refuses a non-admin with the same message.
  • README step 14 now says only an admin sees the control.
  • Wording changes: the MCP tool is described in docs/TECHNICAL.md as admin only, and its sentence is wrapped.

Tests.

  • src/contract.test.ts has a new test that acts as every identity the contract names and checks mayRestore and restoreSamples against the table's delete-on-a-sample-row and create cells. Anon and user are refused, admin is allowed.
  • src/server.test.ts calls restore_samples as anon, as a user and as an admin. The refusals leave the four sample deals unchanged, and the admin call leaves an ok delete row in /api/audit. The page test checks that a user doesn't see the card.
  • src/restore.test.ts checks the refusals leave the demo edits in place and that the audit rows read delete with signin_required and forbidden.
  • src/terminal.test.ts checks that R is refused to a user.
  • The server tests use their own non-admin person, rita, so they don't use up alice's rate limit. That exhaustion was what broke /tick after my first attempt.

Tidy. The /* On paper … */ comment is back directly above @media print, with the .confirm rules moved above it. The restoreSamples import in src/terminal.ts now sits with the other relative imports. writeSamples in src/sample.ts was already indented correctly.

Not a defect. Sample deal ids can be reused after a restore, because SQLite reuses the highest rowid once all sample rows are deleted. I didn't change the schema, so the test checks the audit trail instead of comparing ids.

Approved

Earlier asks are met: restore is admin-only through permit (delete on a sample-authored row plus create), with no cell in contract.json loosened. The page card, the terminal R key and the restore_samples MCP tool all ask mayRestore. The contract test covers every identity. The refusals are audited and leave the data unchanged. The POST goes through the same-origin door, and restore runs in one immediate transaction that deletes only author_id=sample. The README and TECHNICAL docs are updated, and the preview answers 200. Non-blocking: the README step 14 last line is long and could be wrapped.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs