Repository navigation
Commit e9fb098
test(scenarios): walk the working-day calendar once in the run-date oracle (#34104)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9KP2AnyfX9ZJYh48bUsyqbo)_
Fixes #34081
Clause-②: no
Metadata-protocol: none
## 维护者速读
- 改了什么:只改 `packages/qa/scenarios/test/runner/run-date.test.ts` 的工作日
oracle。它仍然逐日走日历(独立于实现的 `workingDayNumber` 算术),但只走一次,走成 1960–2040
的工作日序号表;`walkShift`/`walkCount`/`onOrBefore`/`onOrAfter` 改为查表。
- 为什么改:原 oracle 每张卡、每个日期叶子、每个运行日都从头逐日走,2028 三个运行日离卡的今天约 380 个工作日,在 CI
上每例 5.4–7.0 s,超过 vitest 默认 5000 ms,把合并队列里的 PR 踢出去。
- 风险与回滚:只动测试文件,产品代码不变。超时、跳过、RUN_DATES、卡片数量都没动。回滚即 revert 本 PR。
- 先看:测试文件第 48 行起的 oracle 段(逐日走的 `step*` 保留,下面是一次建表的 `calendar()`
和查表函数),以及新加的自检用例 `the calendar walked once reads the same as stepping
through it…`。
- 两分钟验证:`pnpm --filter @objectstack/scenarios exec vitest run
--reporter=verbose test/runner/run-date.test.ts`,35 项全过,2028 三例本地约
330–360 ms(修前约 1 s)。
- 需要你做的:无,席位落地。
## What changes
The oracle of `every dated card, rebased onto each run date` read each
moved date by stepping through the calendar one day at a time, from
scratch, for every date leaf of every card on every run date. The step
count grows with the distance from the card's `asOf` to the run date, so
the three 2028 run dates (about 380 working days out) were the slowest:
about 1 s each locally and 5.4–7.0 s on CI runners, past vitest's 5000
ms default.
The fix keeps the same reading and takes the walk once:
- `calendar()` steps from 1960-01-01 to 2040-12-31 a day at a time with
`shiftDate(d, 1)` and the test's own `weekday`/`isWorking`, the same
primitives the stepping oracle used. It numbers the working days in
order and records, for every calendar day, the number of the working day
on or before it. It is built lazily on first use.
- `onOrBefore`, `onOrAfter`, `walkCount` and `walkShift` read that
table. They keep the stepping semantics, including the edges: a weekend
`d` moved forward counts from the Friday before it and moved back from
the Monday after it, `n = 0` returns `d` as given, and a time suffix is
carried through. A date or result outside the walked range throws
instead of reading `undefined`.
- The stepping walkers stay, renamed `stepOnOrBefore`, `stepOnOrAfter`,
`stepCount` and `stepShift`. They are now the reference for a new
self-check.
- The implementation's `workingDayNumber` arithmetic is still not used
by the oracle, and run-date.ts's functions are not swapped in for it.
Nothing else changed. The per-test timeout, RUN_DATES (all nine), the
cards and the assertions of every existing case are the same.
## Tests
- **New:** `whole working days > the calendar walked once reads the same
as stepping through it, across the epoch week, a year end and a leap
day`. It compares table against stepping walk on:
- every day within ±7 of 1970-01-01, 2026-12-31 and 2028-02-29, weekends
included, plus two dates with a time suffix: `onOrBefore`/`onOrAfter`,
and `walkShift` by −6, −1, 0, 1 and 6;
- long hops: 1969-12-31 +7, 2026-09-30 +380, 2027-01-01 −380, 2028-02-26
(a Saturday) −260, 2028-02-29 +260;
- `walkCount` both ways over the epoch week, 2026-09-30 ↔ 2028-03-31,
2028-03-04 ↔ 2026-12-26 and 2028-02-26 ↔ 2028-03-04, with weekend
endpoints;
- the two ends of the walked range, which throw.
- **Changed by the fix:** none. Every existing case reads the four
helpers by the same names and gets the same answers.
## Verification
Per-case times of `every dated card, rebased onto each run date`,
`--reporter=verbose`, local, `--maxWorkers=2`, through `os-verify-lock`:
| run date | before (main `63db7240a`) | after (this head) | ablation:
stepping walk put back |
|---|---|---|---|
| 2026-11-15 | 433 ms | 394 ms | 455 ms |
| 2026-11-30 | 432 ms | 395 ms | 426 ms |
| 2026-12-31 | 451 ms | 362 ms | 571 ms |
| 2027-01-01 | 475 ms | 374 ms | 474 ms |
| 2027-02-28 | 554 ms | 348 ms | 585 ms |
| 2027-03-01 | 612 ms | 333 ms | 528 ms |
| **2028-02-28** | **971 ms** | **334 ms** | **1027 ms** |
| **2028-02-29** | **1001 ms** | **357 ms** | **966 ms** |
| **2028-03-31** | **1119 ms** | **327 ms** | **1050 ms** |
| file `tests` total | 6.40 s | 3.62 s | 6.52 s |
- After the fix the nine cases are flat at 327–395 ms; the cost no
longer grows with the run date's distance. The rest is the rebase and
seed reads themselves. At the CI-to-local ratio the card's numbers imply
(5.4–7.0 s against about 1.0 s, so roughly 5.5–6.3×), the 2028 cases
come to about 2.0–2.3 s against the 5000 ms default.
- The calendar table is built inside the first working-day case, which
takes 61 ms in total.
- **Ablation**, through `scripts/ablation-replace.mjs`: `walkCount`
pointed back at `stepCount` and `walkShift` at `stepShift`, both
mutations landed (anchor 1 → 0, blob changed). The 2028 cases go back to
1027/966/1050 ms. The one red is the new self-check's out-of-range
assertion, which the unbounded stepping walk cannot meet, as expected.
All other 34 pass. Restored, `git diff HEAD` empty.
Local subset at head `8dd3edfc0a`, derived by `node
scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` on this diff:
- `dispatch-gates --ran`: 48 derived, 48 run, 0 NOT-MEASURED. One first
answered exit 3 (prerequisite not met) and was re-run after the
prerequisite was built: `pnpm check:dual-build-cjs-loads` after a full
`pnpm build` (119/119 tasks), exit 0. All others exit 0 on the first
run.
- `packages/qa/scenarios`: `pnpm build` exit 0; `vitest run` 34 files,
884 tests, exit 0; `tsc --noEmit -p tsconfig.json` (includes `test/**`)
exit 0.
- `pnpm exec eslint packages/qa/scenarios/test/runner/run-date.test.ts`:
exit 0.
- CI families are read off this PR's check runs by the seat.
Full record: `/mnt/project-files/devx-seat1/34081-gates-ran.txt`.
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(not touched)
- [x] 2. Every name I added uses the casing for its kind. (`calendar`,
`numberOf`, `dayOf`, `stepShift`, `stepCount`, `stepOnOrBefore`,
`stepOnOrAfter`: camelCase; `CALENDAR`: constant)
- [x] 3. No formatter ran; `pnpm lint` passes. (eslint on the one
touched file: exit 0; the repo-wide run is CI's)
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset. (test-only,
nothing publishes: `skip-changeset`)
- [x] 6. `packages/spec` touched: its generated artifacts are
regenerated and committed. (not touched)
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English. (the 维护者速读 block is
the seat's required Chinese summary)
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
---
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01ADHkmRWUrXgua6hAwuKweu
<!-- signed: domain:devx#2 · os-steve · session_01ADHkmQTVjryTSkqydKVS6z
-->
Co-authored-by: Claude <noreply@anthropic.com>1 parent 86350e1 commit e9fb098
1 file changed
Lines changed: 69 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
62 | | - | |
63 | | - | |
| 64 | + | |
| 65 | + | |
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
| |||
69 | 71 | | |
70 | 72 | | |
71 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
72 | 113 | | |
73 | 114 | | |
74 | 115 | | |
| |||
156 | 197 | | |
157 | 198 | | |
158 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
159 | 219 | | |
160 | 220 | | |
161 | 221 | | |
| |||
0 commit comments