Repository navigation
Commit bedb96e
test(dogfood): a home field added to an object that already holds rows migrates as add_columns and the recompute fills it (multi-currency M2-4) (#30186)
<!-- claude-projects-attribution: {"github_login":"os-bill"} -->
_Requested by **Bill** · [project
thread](https://claude.ai/code/project/chan_016iMXWSZDzqWRWvWzdNo8wg?thread=cmsg_016iMXWSZDzqWRWvWzdNo8wgAYW6ez2s1gqUykrnhwXqEv)_
epic:#8345#1 · os-bill · session_01Utp6CZWjnSeed8H4dMjt9d
Fixes #27194
Ruling-ref: 6465431966
Clause-②: no — one new test file under `packages/qa/dogfood/test/`; no
export, schema, route or accepted value changes
Metadata-protocol: none
## 维护者速读
- **改了什么:** 只加一个证明测试(无产品代码):存量对象先以 `record` 模式写入 4 行,再补一行 `homeAmount`
指针和两个字段,走 `os migrate apply` 同一条延迟 DDL 路径加列,然后跑 `recomputeHomeAmounts`
回填。
- **为什么改:** 证明 R1 期间建的对象升级到 R2 只需加一行指针:加列是普通 `add_columns`,回填就是 M2-3
的重算,不需要新门。
- **风险与回滚:** 无产品风险,测试卡。回滚即撤 PR。
- **先看:**
`packages/qa/dogfood/test/home-amount-added-to-existing-object.test.ts`。
- **两分钟验证:** `OS_TEST_POSTGRES_URL=… npx vitest run
test/home-amount-added-to-existing-object.test.ts`(在
`packages/qa/dogfood`,6 条,SQLite×2 + PG);跳过重算或跳过加列,各自变红。
- **需要您做的:** 无。
## What changes
One proving test,
`packages/qa/dogfood/test/home-amount-added-to-existing-object.test.ts`,
on three cells: better-sqlite3 (file), sqlite-wasm (file), PostgreSQL
(one schema, named skip without `OS_TEST_POSTGRES_URL`). Each boot is
its own engine and its own driver over the same database, as two
processes are.
1. **Before.** An object whose amount is `currencyMode: 'record'` with
no `homeAmount` and no home field. Four rows written through the engine:
USD 10,000 (2026-03-15), USD 1,500 (2026-04-15), CNY 12.345, SEK 500 (no
SEK rate row).
2. **The upgrade boot, as `os migrate apply` runs it.** The amount gains
`currencyConfig.homeAmount: { field: 'amount_home', rateDate:
'invoice_date', rateField: 'amount_rate' }` and the two author-declared
readonly fields it names (D8 rule 2). The driver boots with
`setDeferredDdl(true)` (the plan/apply deferral). Pinned:
- `previewDeferredSchemaWork()` for the object is exactly `[{ kind:
'add_columns', columns: ['amount_home', 'amount_rate'] }]`, and nothing
for any other table (no in-place work);
- `detectManagedDrift()` has no entry for the object;
- `flushDeferredSchemaDdl()` performs that same entry, and a plan after
it is `[]`;
- all four rows are still there with their amount and code unchanged,
and an empty home field and rate.
3. **The recompute** (`recomputeHomeAmounts`, behind `os migrate
recompute-home-amounts`, PR #30183):
- dry run: 4 amounts, 3 changed, 1 skipped, nothing written;
- apply: the column read back holds the ADR's figures (USD 10,000 at
0.1389 → 71994.24; USD 1,500 at 0.15 → 10000; CNY 12.345 at rate 1 →
12.35), each equal to a fresh write of the same row after the upgrade;
- the SEK row is listed (`rate_missing`, SEK, 2026-03-15) and skipped,
its home field and rate stay blank, the run is not complete
(`homeAmountRecomputeComplete` false), and a fresh write of that row is
refused `ERR_EXCHANGE_RATE_MISSING`;
- a re-run changes nothing and still lists the one row.
**Finding: the add-column path is ordinary.** No refusal, no flag, no
data loss: the two columns are a plain `add_columns` entry, as for any
field added to an existing object. Nothing in the migrate path changed.
The in-memory driver has no add-column path (it is schemaless), so it
has no cell here; the recompute's in-memory face is
`packages/objectql/src/engine-home-amount-projection.test.ts`.
## Why
ADR-0144 D5: a home field added to an object that already holds rows is
filled by "an explicit recompute operation" (the recompute's own header
names this case). #27194's task asks for the proof that the R1-to-R2
upgrade is one pointer line, the ordinary migration and the recompute,
with nothing new in the product.
## Verification
- The file: 6/6 passed on all three cells (PostgreSQL 16, local,
`OS_TEST_POSTGRES_URL` set).
- Ablation, through `scripts/ablation-replace.mjs` (each mutation
landed, anchor 1 → 0, file restored after):
- recompute skipped (`apply` forced to `false`): 3 failed, one per cell,
on the column read back: expected `{ home: 71994.24, rate: 0.1389 }`,
received `{ home: null, rate: null }`;
- home field declared without the column migration (the flush replaced
by a preview and the deferral disarmed): 6 failed. The plan still lists
the `add_columns` entry, and the recompute's apply writes nothing: its
report carries one `failures` entry per row, `no such column:
amount_home` (SQLite).
- `npx tsc --noEmit -p packages/qa/dogfood`: 0 errors. `eslint` on the
file: exit 0.
- `dispatch-gates --commands`: 51 commands, exit codes captured before
any pipe: 49 exit 0; `check-plugin-teardown-shape --self-test` exited 3
on the shallow clone and exit 0 after fetching its pinned fixture
commit; `pnpm check:dual-build-cjs-loads` exit 3, NOT MEASURED (it reads
every package's `dist/`; this worktree built only the test's closure),
left to CI.
No changeset: a test file in a private package releases nothing
(`skip-changeset`).
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
(spec not touched)
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; eslint passes on the changed file (whole-repo
`pnpm lint` left to CI).
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset: n/a, nothing
publishes; both declaration lines are filled in here.
- [x] 6. `packages/spec` touched: n/a.
- [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.
- [x] The *Before Submitting* list in CONTRIBUTING.md is done.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01Utp6CaGBD59SYKhNDMRa8h
<!-- signed: epic:#8345#1 · os-bill · session_01Utp6CZWjnSeed8H4dMjt9d
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 474c030 commit bedb96e
1 file changed
Lines changed: 283 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 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 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
0 commit comments