Public: anyone can read this; the crew can change it.
An agent fixes a typo in a deal's address from its page, and the clock, timeline, calendar file and every new reminder carry the new address #45
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/42-an-agent-fixes-a-typo-in-a-deal-s-addres → main 3 commits fork 2 threads · 2 unresolved
14 files
changed +188
−15
README.md +5 −1
| @@ -105,7 +105,11 @@ Signed out, `/` shows what deal-clock does, three short points, a still picture | ||
| 105 | 105 | upcoming or overdue, with no controls. Print it with your browser's print |
| 106 | 106 | to hand to a buyer or seller. In the terminal, open the deal with o and press |
| 107 | 107 | t; over MCP, an agent asks for the `client_timeline` tool. |
| 108 | 14. **Put the samples back.** After the walk-through, an admin taps Sample | |
| 108 | 14. **Fix an address.** On a deal's page, Edit address corrects a typo in | |
| 109 | place: the clock, the client timeline, the calendar file and unsent drafts | |
| 110 | carry the new address, and reminders already sent keep their words. In the | |
| 111 | terminal open the deal and press A; over MCP, the `update_address` tool. | |
| 112 | 15. **Put the samples back.** After the walk-through, an admin taps Sample | |
| 109 | 113 | deals below the clock, then Restore the sample deals and confirms: the four |
| 110 | 114 | samples return as they were, dated from today, and the deals you opened are |
| 111 | 115 | left alone. Only an admin sees it. In the terminal press R; over MCP, the `restore_samples` tool. |
docs/TECHNICAL.md +1 −1
| @@ -52,7 +52,7 @@ marked sent, as JSON — call it each morning as a signed-in account (a | ||
| 52 | 52 | stranger gets 401; it sends nothing and changes nothing). `GET /deals/:id/ics` is a deal's calendar file. The JSON API is |
| 53 | 53 | `/api/deals`, described at `/openapi.json`; the same operations are MCP |
| 54 | 54 | tools at `POST /mcp` (`list_deals`, `get_deal`, `client_timeline`, `reminders_today`, `this_week`, |
| 55 | `open_deal`, `add_date`, `add_party`, `edit_party`, `remove_party`, | |
| 55 | `open_deal`, `add_date`, `update_address`, `add_party`, `edit_party`, `remove_party`, | |
| 56 | 56 | `remove_date` — custom dates only — `remove_deal` — its author or an admin — |
| 57 | 57 | `mark_done` — with `done: false` to |
| 58 | 58 | reopen a date — `move_date`, `send_reminder`, `restore_samples` — admin only: puts the |
src/db.test.ts +3 −1
| @@ -93,7 +93,7 @@ test("the migration that accepts the late moment keeps the rows of the old schem | ||
| 93 | 93 | const dir = mkdtempSync(join(tmpdir(), "app-db-late-")); |
| 94 | 94 | const raw = new Database(join(dir, "app.db")); |
| 95 | 95 | raw.exec("PRAGMA foreign_keys = ON"); |
| 96 | const last = migrations.length - 1; | |
| 96 | const last = migrations.findIndex((sql) => sql.includes("CREATE TABLE reminder_new")); | |
| 97 | 97 | raw.exec("CREATE TABLE schema_version (version INTEGER PRIMARY KEY, applied_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')))"); |
| 98 | 98 | migrations.slice(0, last).forEach((sql, i) => { |
| 99 | 99 | raw.exec(sql); |
| @@ -110,4 +110,6 @@ test("the migration that accepts the late moment keeps the rows of the old schem | ||
| 110 | 110 | expect(raw.query("SELECT moment, reason FROM reminder_declined").all()).toEqual([{ moment: "day_of", reason: "Spoke by phone" }]); |
| 111 | 111 | raw.exec("INSERT INTO reminder (deal_id, deadline_id, party_id, label, party_name, moment, due, by_name) VALUES (1, 1, 1, 'I', 'Ann', 'late', '2026-01-10', 'D')"); |
| 112 | 112 | expect(migrate(raw)).toBe(migrations.length); |
| 113 | // The migrations after it ran too: sample deals are keyed by the address they were written with. | |
| 114 | expect(raw.query("SELECT count(*) AS n FROM sample_deal").get()).toEqual({ n: 0 }); | |
| 113 | 115 | }); |
src/db.ts +8
| @@ -198,6 +198,14 @@ export const migrations: string[] = [ | ||
| 198 | 198 | DROP TABLE reminder_declined; |
| 199 | 199 | ALTER TABLE reminder_declined_new RENAME TO reminder_declined; |
| 200 | 200 | CREATE INDEX reminder_declined_deal ON reminder_declined (deal_id)`, |
| 201 | // Which sample a sample deal is, by the address it was written with, so | |
| 202 | // correcting its address does not make it look like a deal a person opened. | |
| 203 | // Removing the deal removes the row. | |
| 204 | `CREATE TABLE IF NOT EXISTS sample_deal ( | |
| 205 | deal_id INTEGER PRIMARY KEY REFERENCES deal (id) ON DELETE CASCADE, | |
| 206 | sample TEXT NOT NULL | |
| 207 | ); | |
| 208 | INSERT OR IGNORE INTO sample_deal (deal_id, sample) SELECT id, address FROM deal WHERE author_id = 'sample'`, | |
| 201 | 209 | ]; |
| 202 | 210 | |
| 203 | 211 | export function openDb(dir = dataDir): Database { |
src/deals.test.ts +25
| @@ -21,6 +21,7 @@ import { | ||
| 21 | 21 | moveDeadline, |
| 22 | 22 | removeDeadline, |
| 23 | 23 | removeParty, |
| 24 | updateDeal, | |
| 24 | 25 | sendReminder, |
| 25 | 26 | undoDecline, |
| 26 | 27 | type DealView, |
| @@ -491,3 +492,27 @@ test("pending: an overdue follow-up stays listed while unsent; the earlier momen | ||
| 491 | 492 | expect(markDone(db, alice, { id: inspection.id, done: true }).ok).toBe(true); |
| 492 | 493 | expect(mine(fresh(deal.id)).filter((r) => pending(r, day))).toEqual([]); |
| 493 | 494 | }); |
| 495 | ||
| 496 | test("correcting an address rewrites the drafts not yet sent and leaves the words of a sent reminder as approved", () => { | |
| 497 | const deal = open({ address: "40 Typo Rd" }); | |
| 498 | const inspection = due(deal, "inspection"); | |
| 499 | const buyer = drafts(deal, agent).find((r) => r.deadline_id === inspection.id && r.moment === "before" && r.party_role === "buyer")!; | |
| 500 | expect(buyer.body).toContain("40 Typo Rd"); | |
| 501 | expect(sendReminder(db, alice, { deadlineId: inspection.id, partyId: buyer.party_id, moment: "before" }).ok).toBe(true); | |
| 502 | ||
| 503 | expect(updateDeal(db, bob, { id: deal.id, address: "40 Typo Road, Unit 1" }).ok).toBe(true); | |
| 504 | const after = fresh(deal.id); | |
| 505 | const all = drafts(after, agent).filter((r) => r.deadline_id === inspection.id); | |
| 506 | const sent = all.filter((r) => r.sent_at !== null); | |
| 507 | const unsent = all.filter((r) => r.sent_at === null); | |
| 508 | expect(sent.length).toBe(1); | |
| 509 | expect(unsent.length).toBeGreaterThan(0); | |
| 510 | for (const r of unsent) { | |
| 511 | expect(r.body).toContain("40 Typo Road, Unit 1"); | |
| 512 | expect(r.subject).toContain("40 Typo Road, Unit 1"); | |
| 513 | } | |
| 514 | expect(sent[0]!.body).toContain("for 40 Typo Rd is"); | |
| 515 | expect(sent[0]!.body).not.toContain("Unit 1"); | |
| 516 | expect(after.sent[0]!.body).toContain("40 Typo Rd"); | |
| 517 | expect(after.sent[0]!.subject).not.toContain("Unit 1"); | |
| 518 | }); |
src/mcp.ts +11
| @@ -16,6 +16,7 @@ import { | ||
| 16 | 16 | createDeal, |
| 17 | 17 | deleteDeal, |
| 18 | 18 | editParty, |
| 19 | updateDeal, | |
| 19 | 20 | getDeal, |
| 20 | 21 | listDeals, |
| 21 | 22 | markDone, |
| @@ -226,6 +227,16 @@ export const tools: readonly Tool[] = [ | ||
| 226 | 227 | run: (db, who, a) => |
| 227 | 228 | addDeadline(db, who, { dealId: Number(a.deal_id), label: a.label, due: a.due, owes: a.owes, what: a.details }), |
| 228 | 229 | }, |
| 230 | { | |
| 231 | name: "update_address", | |
| 232 | description: "Correct a deal's address (3 to 200 characters). The clock, timeline, calendar file and unsent drafts carry the new address; reminders already sent keep their words.", | |
| 233 | inputSchema: { | |
| 234 | type: "object", | |
| 235 | properties: { deal_id: { type: "integer" }, address: { type: "string", minLength: 3, maxLength: 200 } }, | |
| 236 | required: ["deal_id", "address"], | |
| 237 | }, | |
| 238 | run: (db, who, a) => updateDeal(db, who, { id: Number(a.deal_id), address: a.address }), | |
| 239 | }, | |
| 229 | 240 | { |
| 230 | 241 | name: "add_party", |
| 231 | 242 | description: "Add a party (lender, title company, the other agent…) to a deal.", |
src/pages/deal.ts +13 −1
| @@ -53,10 +53,21 @@ export function dealPage(input: { | ||
| 53 | 53 | deal: DealView; |
| 54 | 54 | on: string; |
| 55 | 55 | notice?: string | undefined; |
| 56 | /** An address that was refused: what was typed and why, to show beside the field. */ | |
| 57 | problem?: { readonly value: string; readonly message: string } | undefined; | |
| 56 | 58 | }): string { |
| 57 | const { who, deal, on, notice } = input; | |
| 59 | const { who, deal, on, notice, problem } = input; | |
| 58 | 60 | const path = `/deals/${deal.id}`; |
| 59 | 61 | const may = canChange(who, deal); |
| 62 | const editAddress = may | |
| 63 | ? `<details class="address-edit"${problem === undefined ? "" : " open"}> | |
| 64 | <summary class="button button-quiet button-small">Edit address</summary> | |
| 65 | <form class="stack" method="post" action="${path}/address"> | |
| 66 | <label>Property address<input class="input" name="address" required minlength="3" maxlength="200" autocomplete="off" value="${escape(problem?.value ?? deal.address)}"${problem === undefined ? "" : ` aria-invalid="true" aria-describedby="address-why"`}>${problem === undefined ? "" : `<span class="field-error" id="address-why" role="alert">${escape(problem.message)}</span>`}</label> | |
| 67 | <button class="button">Save address</button> | |
| 68 | </form> | |
| 69 | </details>` | |
| 70 | : ""; | |
| 60 | 71 | const dates = deal.deadlines |
| 61 | 72 | .map( |
| 62 | 73 | (d) => `<li class="date-row"> |
| @@ -109,6 +120,7 @@ export function dealPage(input: { | ||
| 109 | 120 | <div> |
| 110 | 121 | <h1>${escape(deal.address)}</h1> |
| 111 | 122 | <p class="summary">${deal.closed ? `<b>Closed on ${escape(spoken(closedOn(deal)))}</b> · ` : ""}Under contract ${escape(spoken(deal.contract_date))} · closes ${escape(spoken(deal.closing))}, ${escape(relative(deal.closing, on))}${deal.business_days ? " · business days" : ""}</p> |
| 123 | ${editAddress} | |
| 112 | 124 | </div> |
| 113 | 125 | <div class="row"><a class="button button-quiet" href="${path}/timeline">Client timeline</a> <a class="button button-quiet" href="${path}/ics" download>Add to calendar</a></div> |
| 114 | 126 | </section> |
src/restore.test.ts +16 −1
| @@ -5,7 +5,8 @@ import { join } from "node:path"; | ||
| 5 | 5 | import { restoreSamples } from "./actions.ts"; |
| 6 | 6 | import { addDays, today } from "./dates.ts"; |
| 7 | 7 | import { openDb } from "./db.ts"; |
| 8 | import { addParty, createDeal, listDeals, markDone, moveDeadline, type DealView } from "./deals.ts"; | |
| 8 | import { addParty, createDeal, listDeals, markDone, moveDeadline, updateDeal, type DealView } from "./deals.ts"; | |
| 9 | import { refresh } from "./sample.ts"; | |
| 9 | 10 | import type { Who } from "./who.ts"; |
| 10 | 11 | |
| 11 | 12 | const db = openDb(mkdtempSync(join(tmpdir(), "app-restore-"))); |
| @@ -79,3 +80,17 @@ test("only an admin may restore: the table's delete cell on a sample row, and a | ||
| 79 | 80 | ]); |
| 80 | 81 | expect(restoreSamples(db, root).ok).toBe(true); |
| 81 | 82 | }); |
| 83 | ||
| 84 | test("a sample whose address was corrected is still that sample: it moves with the others and restore leaves four", () => { | |
| 85 | restoreSamples(db, root); | |
| 86 | const orchard = sample("Orchard Row"); | |
| 87 | expect(updateDeal(db, alice, { id: orchard.id, address: "9 Orchard Row, Unit 2" }).ok).toBe(true); | |
| 88 | const closing = orchard.closing; | |
| 89 | refresh(db, addDays(on, 5)); | |
| 90 | const moved = samples().find((d) => d.id === orchard.id)!; | |
| 91 | expect(moved.address).toBe("9 Orchard Row, Unit 2"); | |
| 92 | expect(moved.closing).toBe(addDays(closing, 5)); | |
| 93 | restoreSamples(db, root); | |
| 94 | expect(samples().length).toBe(4); | |
| 95 | expect(samples().filter((d) => d.address.includes("Orchard Row")).map((d) => d.address)).toEqual(["9 Orchard Row"]); | |
| 96 | }); |
src/routes.ts +15
| @@ -462,6 +462,21 @@ export const routes: readonly Route[] = [ | ||
| 462 | 462 | path: "/samples/restore", |
| 463 | 463 | handle: (c) => done(restoreSamples(c.db, c.who), "/", "Sample deals restored."), |
| 464 | 464 | }, |
| 465 | { | |
| 466 | method: "POST", | |
| 467 | path: "/deals/:id/address", | |
| 468 | handle: async (c) => { | |
| 469 | const f = await form(c); | |
| 470 | if (f instanceof Response) return f; | |
| 471 | const id = Number(c.params.id); | |
| 472 | const saved = updateDeal(c.db, c.who, { id, address: f.address }); | |
| 473 | if (saved.ok) return back("Address corrected.", `/deals/${id}`); | |
| 474 | if (saved.error !== "invalid" || f.address === undefined) return back(saved.message, `/deals/${id}`); | |
| 475 | const found = getDeal(c.db, c.who, { id }); | |
| 476 | if (!found.ok) return back(found.message, `/deals/${id}`); | |
| 477 | return html(dealPage({ who: c.who, deal: found.value, on: today(), problem: { value: f.address, message: saved.message } }), STATUS.invalid); | |
| 478 | }, | |
| 479 | }, | |
| 465 | 480 | { |
| 466 | 481 | method: "POST", |
| 467 | 482 | path: "/deals/:id/delete", |
src/sample.test.ts +2 −2
| @@ -34,7 +34,7 @@ test("every date of a sample moves by the days since its anchor, together", () = | ||
| 34 | 34 | |
| 35 | 35 | test("a sample a person changed is not untouched", () => { |
| 36 | 36 | const state = { |
| 37 | address: "9 Orchard Row", | |
| 37 | sample: "9 Orchard Row", | |
| 38 | 38 | parties: 3, // lender, title, other agent |
| 39 | 39 | customs: 1, |
| 40 | 40 | reminders: 0, |
| @@ -46,7 +46,7 @@ test("a sample a person changed is not untouched", () => { | ||
| 46 | 46 | expect(isUntouched({ ...state, parties: 4 }, "2026-10-01")).toBe(false); |
| 47 | 47 | expect(isUntouched({ ...state, moveAuthors: ["Sample data", "Ana"] }, "2026-10-01")).toBe(false); |
| 48 | 48 | expect(isUntouched({ ...state, doneAts: ["2026-09-30T17:00:00.000Z", "2026-10-02T08:00:00.000Z", null] }, "2026-10-01")).toBe(false); |
| 49 | expect(isUntouched({ ...state, address: "Mine" }, "2026-10-01")).toBe(false); | |
| 49 | expect(isUntouched({ ...state, sample: null }, "2026-10-01")).toBe(false); | |
| 50 | 50 | }); |
| 51 | 51 | |
| 52 | 52 | test("the sample deals hold an overdue date with its follow-up waiting", () => { |
src/sample.ts +7 −5
| @@ -123,7 +123,8 @@ export function shiftSample(dates: SampleDates, anchor: string, on: string): Sam | ||
| 123 | 123 | |
| 124 | 124 | /** What a person could have changed in a sample deal, as plain data; `parties` leaves out the buyer and seller. */ |
| 125 | 125 | export interface SampleState { |
| 126 | readonly address: string; | |
| 126 | /** The address the sample was written with (not its address now); null for a deal that is not one. */ | |
| 127 | readonly sample: string | null; | |
| 127 | 128 | readonly parties: number; |
| 128 | 129 | readonly customs: number; |
| 129 | 130 | readonly reminders: number; |
| @@ -133,7 +134,7 @@ export interface SampleState { | ||
| 133 | 134 | |
| 134 | 135 | /** Is this deal still exactly as `seed` wrote it, anchored to `anchor`? */ |
| 135 | 136 | export function isUntouched(state: SampleState, anchor: string): boolean { |
| 136 | const s = SAMPLES.find((x) => x.address === state.address); | |
| 137 | const s = SAMPLES.find((x) => x.address === state.sample); | |
| 137 | 138 | if (s === undefined) return false; |
| 138 | 139 | const marker = `${addDays(anchor, -1)}${DONE_TIME}`; |
| 139 | 140 | return ( |
| @@ -158,8 +159,8 @@ export function refresh(db: Database, on = today()): void { | ||
| 158 | 159 | const row = db.query<{ value: string }, []>("SELECT value FROM app_meta WHERE key = 'sample_anchor'").get(); |
| 159 | 160 | if (row === null || daysBetween(row.value, on) <= 0) return; |
| 160 | 161 | const anchor = row.value; |
| 161 | const deals = db.query<{ id: number; address: string; contract_date: string }, [string]>( | |
| 162 | "SELECT id, address, contract_date FROM deal WHERE author_id = ?1", | |
| 162 | const deals = db.query<{ id: number; sample: string | null; contract_date: string }, [string]>( | |
| 163 | "SELECT d.id, s.sample, d.contract_date FROM deal d LEFT JOIN sample_deal s ON s.deal_id = d.id WHERE d.author_id = ?1", | |
| 163 | 164 | ).all(SAMPLE.id); |
| 164 | 165 | for (const deal of deals) { |
| 165 | 166 | const deadlines = db.query<{ id: number; kind: string; due: string; done_at: string | null }, [number]>( |
| @@ -175,7 +176,7 @@ export function refresh(db: Database, on = today()): void { | ||
| 175 | 176 | "SELECT count(*) AS n FROM reminder WHERE deal_id = ?1 AND sample = 0", |
| 176 | 177 | ).get(deal.id)!.n; |
| 177 | 178 | const state: SampleState = { |
| 178 | address: deal.address, | |
| 179 | sample: deal.sample, | |
| 179 | 180 | parties, |
| 180 | 181 | customs: deadlines.filter((d) => d.kind === "custom").length, |
| 181 | 182 | reminders, |
| @@ -215,6 +216,7 @@ function writeSamples(db: Database, on: string): void { | ||
| 215 | 216 | lengths: { ...DEFAULT_LENGTHS, ...s.lengths }, |
| 216 | 217 | businessDays: false, |
| 217 | 218 | }); |
| 219 | db.query("INSERT INTO sample_deal (deal_id, sample) VALUES (?1, ?2)").run(deal.id, s.address); | |
| 218 | 220 | for (const [role, name, contact] of s.parties) |
| 219 | 221 | db.query("INSERT INTO party (deal_id, role, name, contact) VALUES (?1, ?2, ?3, ?4)").run(deal.id, role, name, contact); |
| 220 | 222 | for (const kind of s.done ?? []) |
src/server.test.ts +49
| @@ -175,6 +175,7 @@ test("the MCP server lists the tools and calls them as the caller", async () => | ||
| 175 | 175 | "undo_decline_reminder", |
| 176 | 176 | "open_deal", |
| 177 | 177 | "add_date", |
| 178 | "update_address", | |
| 178 | 179 | "add_party", |
| 179 | 180 | "edit_party", |
| 180 | 181 | "remove_party", |
| @@ -984,6 +985,54 @@ test("a Find narrows This week, today's reminders and the Closed card, and a mis | ||
| 984 | 985 | expect(section(miss, "week")).toBe(""); |
| 985 | 986 | }); |
outdated
No test for drafts/sent reminders, sample-deal editing, a non-owner post, or an exact anon status. |
||
| 986 | 987 | |
| 988 | test("an address is corrected from the deal page and every surface carries it; a short one is refused; a viewer who may not update gets no form", async () => { | |
| 989 | const made = await api("/api/deals", { method: "POST", ...jsonBody({ address: "12 Elm St", buyer: "Bo Buyer", seller: "Su Seller", contract_date: "2027-03-01", closing_date: "2027-04-05" }) }, mia); | |
| 990 | const deal = (await made.json()) as { id: number }; | |
| 991 | const post = (address: string, who: Record<string, string> = mia) => { | |
| 992 | const body = new FormData(); | |
| 993 | body.set("address", address); | |
| 994 | return api(`/deals/${deal.id}/address`, { method: "POST", body, redirect: "manual" }, who); | |
| 995 | }; | |
| 996 | const page = await (await api(`/deals/${deal.id}`, {}, mia)).text(); | |
| 997 | expect(page).toContain(`action="/deals/${deal.id}/address"`); | |
| 998 | expect(page).toContain("Edit address"); | |
| 999 | ||
| 1000 | const bad = await post("<b"); | |
| 1001 | expect(bad.status).toBe(422); | |
| 1002 | const badPage = await bad.text(); | |
| 1003 | expect(badPage).toContain("The address is 3 to 200 characters."); | |
| 1004 | expect(badPage).toContain('value="<b"'); | |
| 1005 | expect(await (await api(`/deals/${deal.id}`, {}, mia)).text()).toContain("<h1>12 Elm St</h1>"); | |
| 1006 | ||
| 1007 | const good = await post("12 Elm Street, Unit 4"); | |
| 1008 | expect(good.status).toBe(303); | |
| 1009 | expect(good.headers.get("location")).toBe(`/deals/${deal.id}`); | |
| 1010 | expect(await (await api("/", {}, mia)).text()).toContain("12 Elm Street, Unit 4"); | |
| 1011 | expect(await (await api(`/deals/${deal.id}/timeline`, {}, mia)).text()).toContain("12 Elm Street, Unit 4"); | |
| 1012 | const ics = await (await api(`/deals/${deal.id}/ics`, {}, mia)).text(); | |
| 1013 | expect(ics).toContain("12 Elm Street\\, Unit 4"); | |
| 1014 | expect(ics).not.toContain("12 Elm St\r"); | |
| 1015 | ||
| 1016 | expect(await (await fetch(`${base}/deals/${deal.id}`)).text()).not.toContain("/address"); | |
| 1017 | const anon = await fetch(`${base}/deals/${deal.id}/address`, { method: "POST", body: new URLSearchParams({ address: "Nope Street" }), redirect: "manual" }); | |
| 1018 | expect(anon.status).toBe(303); | |
| 1019 | expect(anon.headers.get("set-cookie")).toContain("Sign%20in"); | |
| 1020 | expect(await (await api(`/deals/${deal.id}`, {}, mia)).text()).toContain("12 Elm Street, Unit 4"); | |
| 1021 | const cross = await api(`/deals/${deal.id}/address`, { method: "POST", body: new URLSearchParams({ address: "Evil Street" }), redirect: "manual", headers: { origin: "https://evil.example", "sec-fetch-site": "cross-site" } }, mia); | |
| 1022 | expect(cross.status).toBe(403); | |
| 1023 | }); | |
| 1024 | ||
| 1025 | test("update_address over MCP corrects the address; a short one changes nothing", async () => { | |
| 1026 | const made = await api("/api/deals", { method: "POST", ...jsonBody({ address: "8 Mcp Ln", buyer: "Bo Buyer", seller: "Su Seller", contract_date: "2027-03-01", closing_date: "2027-04-05" }) }, mia); | |
| 1027 | const deal = (await made.json()) as { id: number }; | |
| 1028 | const call = (args: unknown, who = {}) => rpc({ jsonrpc: "2.0", id: 4, method: "tools/call", params: { name: "update_address", arguments: args } }, who); | |
| 1029 | const shown = async () => ((await (await api(`/api/deals/${deal.id}`, {}, mia)).json()) as { address: string }).address; | |
| 1030 | expect((await call({ deal_id: deal.id, address: "ab" }, mia)).result.isError).toBe(true); | |
| 1031 | expect(await shown()).toBe("8 Mcp Ln"); | |
| 1032 | expect((await call({ deal_id: deal.id, address: "8 Mcp Lane" }, mia)).result.isError).toBeUndefined(); | |
| 1033 | expect(await shown()).toBe("8 Mcp Lane"); | |
| 1034 | }); | |
| 1035 | ||
| 987 | 1036 | test("an agent finds a deal by name over MCP and GET /api/deals?q=, with one refusal for a bad query", async () => { |
| 988 | 1037 | const alice = as("u-namefind", "nina"); |
| 989 | 1038 | const call = async (args: unknown) => |
src/terminal.test.ts +25
| @@ -432,3 +432,28 @@ test("/ finds a deal and narrows dates, week and reminders to it; / then enter c | ||
| 432 | 432 | expect(all).toContain("9 Oak Ln"); |
| 433 | 433 | expect(all).not.toContain("Finding"); |
| 434 | 434 | }); |
| 435 | ||
| 436 | test("A corrects the address of the open deal; a too-short one is refused and nothing changes", () => { | |
| 437 | const own = createDeal(db, alice, { address: "3 Oak St", buyer: "Bea Buyer", seller: "Sid Seller", contractDate: today(), closingDate: addDays(today(), 30) }); | |
| 438 | if (!own.ok) throw new Error(own.message); | |
| 439 | const read = () => { | |
| 440 | const got = getDeal(db, alice, { id: own.value.id }); | |
| 441 | if (!got.ok) throw new Error(got.message); | |
| 442 | return got.value.address; | |
| 443 | }; | |
| 444 | const t = terminal(db, alice, context); | |
| 445 | goTo(t, "Closing — 3 Oak St"); | |
| 446 | t.press("o"); | |
| 447 | press(t, "A", "ab\r"); | |
| 448 | expect(read()).toBe("3 Oak St"); | |
| 449 | expect(lines(t).join("\n")).toContain("3 to 200 characters"); | |
| 450 | press(t, "A", "3 Oak Street, Unit 2\r"); | |
| 451 | expect(read()).toBe("3 Oak Street, Unit 2"); | |
| 452 | expect(lines(t).join("\n")).toContain("Address is now 3 Oak Street, Unit 2."); | |
| 453 | }); | |
| 454 | ||
| 455 | test("a signed-out terminal is not asked for an address", () => { | |
| 456 | const t = terminal(db, { role: "anon" }, context); | |
| 457 | t.press("A"); | |
| 458 | expect(deal().address).toBe("12 Elm St"); | |
| 459 | }); |
src/terminal.ts +8 −3
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | * week the open dates overdue or due in the next seven days, by day |
| 8 | 8 | * reminders what goes out today; enter reads a draft, e edits its words, s sends it |
| 9 | 9 | * timeline a deal's dates as a client would get them (t on a deal) |
| 10 | * deal one deal's dates and parties; a adds a date, p a party, D removes it | |
| 10 | * deal one deal's dates and parties; a adds a date, p a party, A corrects the address, D removes it | |
| 11 | 11 | * |
| 12 | 12 | * On a date (dates or deal view): x marks it done, u reopens it, m moves it |
| 13 | 13 | * (a new date, then the reason). o or enter opens its deal; n opens a new |
| @@ -23,6 +23,7 @@ import { | ||
| 23 | 23 | addDeadline, |
| 24 | 24 | addParty, |
| 25 | 25 | editParty, |
| 26 | updateDeal, | |
| 26 | 27 | BODY_MAX, |
| 27 | 28 | canChange, |
| 28 | 29 | createDeal, |
| @@ -177,9 +178,13 @@ export function terminal( | ||
| 177 | 178 | |
| 178 | 179 | function onDeal(key: string): boolean { |
| 179 | 180 | const deal = openDeal(); |
| 180 | if (deal === undefined || !["a", "p", "D", "e", "X"].includes(key)) return false; | |
| 181 | if (deal === undefined || !["a", "p", "D", "e", "X", "A"].includes(key)) return false; | |
| 181 | 182 | const party = deal.parties[cursor - deal.deadlines.length]; |
| 182 | 183 | const date = deal.deadlines[cursor]; |
| 184 | if (key === "A") | |
| 185 | ask(deal, [`Address (now ${deal.address})`], ([address]) => | |
| 186 | report(updateDeal(db, me, { id: deal.id, address }), `Address is now ${address!.trim()}.`), | |
| 187 | ); | |
| 183 | 188 | if (key === "e") { |
| 184 | 189 | if (party === undefined) said = "Move to a party to edit it."; |
| 185 | 190 | else |
| @@ -531,7 +536,7 @@ export function terminal( | ||
| 531 | 536 | : view === "timeline" |
| 532 | 537 | ? "b back to the deal · d dates · q quit" |
| 533 | 538 | : view === "deal" |
| 534 | ? "j/k move · t client timeline · s messages · x done · u reopen · m move · a add date · p add party · e edit party · X remove date/party · D remove deal · b back · q quit" | |
| 539 | ? "j/k move · t client timeline · s messages · x done · u reopen · m move · a add date · p add party · e edit party · A edit address · X remove date/party · D remove deal · b back · q quit" | |
| 535 | 540 | : `j/k move · x done · u reopen · m move · o open deal · n new deal · c check dates · / find · R restore samples · h ${showDone ? "hide" : "show"} done · w this week · r reminders · q quit`; |
| 536 | 541 | lines.push(dim(me.role === "anon" ? `${keys} · sign in with a key the forge knows to change anything` : keys)); |
| 537 | 542 | } |
new above
offline
Route is fine (goes through updateDeal/permit), but the same action is missing from tty.ts and MCP.