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

The sample deals stay sensible when the app boots across a month or year end, pinned by a test #256

Merged opened this

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

Merged

The sample deals now land only on business days, whatever day the app boots. A new test boots them on Dec 28, Jan 31, Feb 28, Feb 29 and Dec 31. Date math was wrong, and this fixes it in src/sample.ts and src/dates.ts.

Notes

shipped production is serving it deploy d2eada7

opened this

The sample deals now land only on business days, whatever day the app boots. A new test boots them on Dec 28, Jan 31, Feb 28, Feb 29 and Dec 31. Date math was wrong, and this fixes it in src/sample.ts and src/dates.ts.

The tests that open a database or start the server pass (616 of 616), including the new ones. I did not run bun x tsc --noEmit or bun scripts/gate.ts: the clone has no tsconfig.json and no scripts/gate.ts. I did not run the rest of the suite or scripts/design-lint.ts, because the change touches nothing in src/web/.

What was wrong. The samples counted calendar days from the boot day, so they could land on weekends or federal holidays on any day of the year, not just at month or year ends. Dec 28 gave 18 such dates and Feb 29, 2028 gave 25.

What changed

  • src/dates.ts: new previousBusinessDay.
  • src/sample.ts: a new onBusinessDay(date, on, closing) moves every deadline, the contract date, the custom dates and the moved date onto a business day.

- Past dates step back, so overdue stays overdue. A past date that stepping back would carry into the previous year steps forward instead. That keeps the three deals closed this year inside the year in January. - Future dates step back when they stay ahead of today, and a closing steps forward. This keeps the walkthrough from landing on or after the closing, which order.page.test.ts flags. - 58 Larkspur Way, the anniversary sample, steps back and is finished on the anniversary day. Its note still waits in Review, and the book still counts it as closed last year.

  • src/sample.test.ts: one test per boot day, asserting the following.

- Eight deals: the app writes eight, because 58 Larkspur Way is counted apart. - Business days: every contract, closing and deadline falls on one. - Four open: the same four are open. - Closed in the year: the closed ones closed before the boot day and in its year. - One overdue: Harbor View's inspection is the only overdue open date. - Alder Lane: it closes within a week. - Book: the book counts three closed this year. - These check shape, not exact days.

Two existing tests changed, because they were wrong rather than the code

  • db.test.ts: it expected the moved appraisal exactly two days out, which can be a holiday (Nov 11, Veterans Day). It now expects a business day within three days of that.
  • waiting.test.ts: it sends one message per waiting reminder and tripped the 429 rate limit when rolling put more dates due today. It now resets the limit each pass, since it isn't testing the limit.

Not done

  • refresh() still shifts by whole days. A long-running database whose samples move forward later can drift onto a weekend. The issue was about boot, so I left it.
  • The README says "seven" samples, and the app writes eight. The eighth is the anniversary sample, so I left the wording alone.

To try it, run bun test src/sample.test.ts, or boot the app on a fresh data directory and open /.

🤖 Generated with Claude Code

Closes #254

1 earlier comment · 1 event
commented

The sample deals now land only on business days, whatever day the app boots. A new test boots them on Dec 28, Jan 31, Feb 28, Feb 29 and Dec 31. Date math was wrong, and this fixes it in src/sample.ts and src/dates.ts.

The tests that open a database or start the server pass (616 of 616), including the new ones. I did not run bun x tsc --noEmit or bun scripts/gate.ts: the clone has no tsconfig.json and no scripts/gate.ts. I did not run the rest of the suite or scripts/design-lint.ts, because the change touches nothing in src/web/.

What was wrong. The samples counted calendar days from the boot day, so they could land on weekends or federal holidays on any day of the year, not just at month or year ends. Dec 28 gave 18 such dates and Feb 29, 2028 gave 25.

What changed

  • src/dates.ts: new previousBusinessDay.
  • src/sample.ts: a new onBusinessDay(date, on, closing) moves every deadline, the contract date, the custom dates and the moved date onto a business day.

- Past dates step back, so overdue stays overdue. A past date that stepping back would carry into the previous year steps forward instead. That keeps the three deals closed this year inside the year in January. - Future dates step back when they stay ahead of today, and a closing steps forward. This keeps the walkthrough from landing on or after the closing, which order.page.test.ts flags. - 58 Larkspur Way, the anniversary sample, steps back and is finished on the anniversary day. Its note still waits in Review, and the book still counts it as closed last year.

  • src/sample.test.ts: one test per boot day, asserting the following.

- Eight deals: the app writes eight, because 58 Larkspur Way is counted apart. - Business days: every contract, closing and deadline falls on one. - Four open: the same four are open. - Closed in the year: the closed ones closed before the boot day and in its year. - One overdue: Harbor View's inspection is the only overdue open date. - Alder Lane: it closes within a week. - Book: the book counts three closed this year. - These check shape, not exact days.

Two existing tests changed, because they were wrong rather than the code

  • db.test.ts: it expected the moved appraisal exactly two days out, which can be a holiday (Nov 11, Veterans Day). It now expects a business day within three days of that.
  • waiting.test.ts: it sends one message per waiting reminder and tripped the 429 rate limit when rolling put more dates due today. It now resets the limit each pass, since it isn't testing the limit.

Not done

  • refresh() still shifts by whole days. A long-running database whose samples move forward later can drift onto a weekend. The issue was about boot, so I left it.
  • The README says "seven" samples, and the app writes eight. The eighth is the anniversary sample, so I left the wording alone.

To try it, run bun test src/sample.test.ts, or boot the app on a fresh data directory and open /.

🤖 Generated with Claude Code

Changes requested — before the latest push

No security findings. Three things to fix in one round:

  1. Box 2 is not met. You found that refresh() still shifts the samples by whole days, so a long-running database can drift onto a weekend or holiday, and you left it. The issue says any date math found wrong is fixed in src/sample.ts or src/dates.ts. Fix refresh() to go through onBusinessDay, and add a test that refreshes across a weekend.
  2. The README tour must hold, and it does not. The README says seven deals and the new test asserts eight. Either word the README so it matches what the app writes, or have the test assert the README's number. The README is part of the claim in box 1.
  3. Two tests were weakened or are muddled.

- In db.test.ts the exact appraisal date became 'a business day within 3 days'. Pin it exactly instead: compute the expected day with nextBusinessDay or onBusinessDay and expect that. - In sample.test.ts both branches of the closed-deal loop assert the same closing < on. Collapse them. The test also admits the closed samples, where the box says no sample is already closed. State plainly which are expected to be closed.

commented

This round makes refresh() keep sample dates on business days, fixes the README count, and tightens the two tests you flagged. The tests that open a database or start the server pass, 617 of 617. Nothing else was run: the clone has no tsconfig.json, scripts/gate.ts or scripts/fast.ts, and I did not run the rest of the suite.

1. refresh() now keeps dates on business days.

  • After shifting by whole days, every deadline, the contract date and the moved-date rows go back through onBusinessDay. onBusinessDay is now exported. The anniversary sample's dates step back, as at first boot.
  • A finished date is re-stamped against its rolled due day, so a rolled date never reads late. The anniversary sample's closing keeps its anniversary day.
  • Sample reminders other than the check-in take their due from the rolled deadline.
  • New test: the samples are seeded, then refreshed daily for 40 days across weekends and holidays. Every deadline and contract date stays a business day, the moved-date rows do too, and the count of finished dates and of closed deals does not change.
  • Each roll starts from the date already rolled, so a refreshed database can sit a day or two off one booted fresh on the same day. I did not rebuild each date from its original offset.

2. README.

  • The app writes eight samples, so the README now says eight: four open, three closed this year, and 58 Larkspur Way, closed a year ago, with its anniversary note waiting in Review. It also says no sample date falls on a weekend or holiday.
  • docs/TECHNICAL.md and the restore descriptions in src/actions.ts and src/mcp.ts said "seven" and now say eight.
  • The sample test asserts eight, so test and README agree.

3. Tests.

  • db.test.ts: the appraisal date is pinned exactly again. The test seeds 30 days back and refreshes to today, so the expected date is rolled at seed, carried 30 days, then rolled again. The closing and inspection dates use the same helper.
  • sample.test.ts: the closed-deal loop names the four expected closed samples (Mill Pond, Cedar Heights, Saltmarsh, Larkspur). The closing < on assertion is now written once, and the same-year check applies only to the first three.
  • I read "no sample is already closed" as "the four open samples are not closed", since the four old ones are closed by design. If you meant otherwise, say so.

Not done. When the anniversary falls where stepping back crosses a year, 58 Larkspur Way's closing due can land a day or two before its finished day. I chose that so it stays closed last year in the book.

🤖 Generated with Claude Code

Approved

Earlier asks are met: refresh() now keeps dates on business days, the README and docs say eight samples, and the db.test appraisal date is pinned exactly again. I read the diff only, because the clone is at main and does not have the head commit, so I could not run the new tests. The change adds no door and loosens no contract cell. Non-blocking: src/db.test.ts imports from ./sample.ts twice, so merge the onBusinessDay import into the seed import.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs