You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a7292a5
Browse filesBrowse the repository at this point in the historyBrowse files
fix(units): raise the blank-unit debt of a unitField re-pointed at a new field; name unused code-keyed mapping entries; say what a capped walk did not judge (#37268)
repo:objectstack#7 · os-alice · session_011y7As5bdhV5T4N9vpjmZzH
Part of #35885
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
管理员在一次保存里把某个数量字段的单位改指向一个新建字段时,保存会先被拦下,提示所有存量行将缺单位并给出补写办法;单位换算工具的报告会点出没被用上的映射条目,只扫了部分行时也会明说其余行未判定。用户的数据本身不变。
- 属于"计量单位"标准里单位换算回填这一块的收尾,替转换大表或改表结构的运维人员补上三个提示缺口。
- 若判断有误,管理员只会多看到一次可强制跳过的拦截提示,或报告里多一两行说明;不改任何已存数据,可以直接撤回。
- 无
## What changes
Three follow-up gaps of the unit-code backfill door (ADR-0158 R1), each
inside the claim's file surface:
1. **A `unitField` re-pointed at a new field raises its blank-unit
debt.** `detectDestructiveObjectChanges` now raises 409
`DESTRUCTIVE_CHANGE` with `unit_mode_to_record` on a stored
`record`-mode quantity whose `unitField` is re-pointed at a field that
held no stored unit before the save (new in it, or unstored before it).
The message names the re-point, the blank beside every stored quantity,
and the `""` entry of the unit-code run, CLI and REST. It reads no row
and `force: true` lifts it. The once-only rule of
`newlyDeclaredUnitCodeFieldsOf` is kept: a re-point onto a stored text
field still raises `unit_code_field_declared` alone (it names the
quantity), and a re-point onto a field that already was a unit code
field still raises nothing (the `currency_field_repointed` sibling, out
of R1). **Code choice:** the existing `unit_mode_to_record`, not a new
`unit_field_repointed`. The debt is the same blank-unit debt, the spec's
`issues[].code` describe text lists the codes and stays unchanged, and a
new code would be a `packages/spec` edit outside the claim.
2. **N3, unused code-keyed mapping entries are named.** A value stored
as a unit code (`member`, `retired`, `other-dimension`) that is also a
mapping key no row used now carries `unusedEntry` (the code that entry
names) in the report, and the printed report adds one line per such
entry. An entry that some row did use, for example in another
organization where the text is not a unit, is not named.
3. **N4, a truncated walk says what it did not judge. Shape chosen:
report, not refusal, to match the currency twin.**
`record-currency-backfill.ts` writes over a walk the `maxRecords` cap
cut short and reports it. The unit backfill now does the same thing in
the same words: the printed report says the rows past the cap were not
judged, so any of them may hold a value with no mapping entry, and that
an apply run wrote only the rows it examined. An unscoped run also gets
the currency report's line that the organization check saw only the rows
examined. The CLI prints these lines from the shared formatter, so no
`packages/cli` edit was needed. Refusing apply over a truncated preview
would be a narrowing the currency twin does not have.
The module header of `unit-code-backfill.ts` is amended. "One run
converts the whole field or nothing" now holds over the rows the run
examines.
**Read first** (by risk):
1. `packages/metadata-protocol/src/protocol-write-face.ts`, the new
re-point branch ahead of the `unit_mode_to_record` switch branch. The
risk is the predicate: `prevUnitField !== unitField` and
`!prevUnitCodeFields.has(unitField)`, with the `declaredUnitCodeFields`
gate shared with the switch branch.
2. `packages/objectql/src/protocol-destructive-unit-mode.test.ts`, the
new pin and the widened once-only `it.each` loop, which now also checks
re-points.
3. `packages/objectql/src/unit-code-backfill.ts`, the `unusedEntry` pass
after the walk and the truncated lines in the formatter.
## Tests
Readings taken on head `0237272ee3f` (final commit; base `d62f9e9c05a`).
- New pin: a stored record-mode quantity re-pointed at a new field gets
409 `DESTRUCTIVE_CHANGE` / `unit_mode_to_record`, asserting `code` and
`status`. The test checks the message, reads no row, and confirms
`force: true` lifts it. The once-only `it.each` gains two re-point
cases, and its debt loop now covers re-points as well as switches.
- New pins in `unit-code-backfill.test.ts`: `unusedEntry` and its report
line, and an apply run capped at 2 rows. That run writes the 2 rows it
examined, leaves the unseen unmatched rows as stored, prints the
not-judged line, and the uncapped run is still refused
`VALIDATION_ERROR` / 400.
<details><summary>Package tests and typecheck</summary>
- `pnpm --filter @objectstack/objectql --filter
@objectstack/metadata-protocol typecheck`, then each package's `pnpm
test`, under the verify lock: `VERDICT command-exit 0`.
- metadata-protocol: `Test Files 370 passed | 9 skipped (379)`, `Tests
23417 passed | 45 skipped (23462)`.
- objectql: `Test Files 638 passed (638)`, `Tests 14428 passed (14428)`.
- Targeted run before that: `Test Files 3 passed (3)`, `Tests 75 passed
(75)`, for the destructive-unit-mode, unit-code backfill and
record-currency backfill test files.
</details>
<details><summary>Ablations (one per fix, through
scripts/ablation-replace.mjs; each restored, blob equals HEAD and git
diff HEAD is empty)</summary>
- A1, the re-point predicate: `prevUnitField !== unitField` was changed
to a never-true comparison. metadata-protocol was rebuilt, and
`ablation-dist-preflight` found the marker present in 2 built files.
Result: 3 failed, 21 passed, namely the new pin and the two new
`it.each` re-point cases. Restore leg: rebuilt, and the marker is absent
from all 24 built files.
- A2, the `unusedEntry` assignment was removed. Result: 1 failed, 28
passed, the new N3 pin.
- A3, the truncated wording was blanked. Result: 1 failed, 28 passed,
the new N4 pin.
</details>
<details><summary>Gates</summary>
- Derived with `node scripts/pm/dispatch-gates.mjs --commands --repo
objectstack-ai/objectstack` (69 families). Each one was run locally,
with its exit code captured before any pipe.
- 68 exited 0. `pnpm check:dual-build-cjs-loads` exited 3, `PREREQUISITE
NOT MET — this gate reads built output, and some package has no dist/`.
That is NOT MEASURED, because a full `pnpm build` was not run. CI's
`Lint & Repo Gates` measures it.
- `--ran` reconciliation: `69 derived, 69 run, 0 NOT-MEASURED, 0 UNRUN`.
The runner's NOT-MEASURED claim is corrected by the dual-build line
above.
- The PR check-runs are read by the seat (no CI polling here).
</details>
## Acceptance notes
- **ADR-0158 amendment not in this PR.** The card's Done-when asks for
Open item 9's trailing note and Open item 12 to be amended.
`docs/adr/**` is outside the claim's file surface and is a governed Tier
H path, which would make this code PR Tier H. So this PR says `Part of`,
and the amendment is left to the owning seat as its own ADR-note PR.
Proposed text: in Open item 9, replace the sentence carried by the card
with "A `unitField` re-pointed onto a field new in the same save, or
unstored before it, raises `unit_mode_to_record` on the quantity, for
the blanks beside it; one re-pointed onto a field that already was a
unit code field raises nothing in R1 (the sibling of
`currency_field_repointed`)". In Open item 12's Dry-run-and-apply point,
replace "A preview cut short at its row limit is reported as truncated"
with "A walk cut short at its row limit judges only the rows it
examined: an apply run writes those, and the report says that the rows
past the limit were not judged, as the currency backfill's does; a
mapping entry whose key is stored as a unit code and that no row used is
named in the report".
- The `unit_mode_to_record` describe in the spec (`issues[].code`) and
the generated protocol reference are unchanged: the code list did not
move.
- `packages/cli` untouched: the CLI prints the formatter's lines. Its
own `unit-codes` tests were not run locally (the package's public face
is additive, an optional field); CI's `Test Core` runs them.
## Verification
Run `pnpm --filter @objectstack/objectql exec vitest run --maxWorkers=2
src/protocol-destructive-unit-mode.test.ts
src/unit-code-backfill.test.ts` after building metadata-protocol. Expect
every test to pass, including the three new pins named above.
---
_Generated by [Claude
Code](https://claude.ai/code/session_011y7As5bdhV5T4N9vpjmZzH)_
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(units): a `unitField` re-pointed at a new field raises its blank-unit debt; the unit-code backfill names unused mapping entries and says what a capped walk did not judge
7
+
8
+
Clause-②: no
9
+
Metadata-protocol: none
10
+
11
+
- A metadata save that re-points a stored `record`-mode quantity's `unitConfig.unitField` at a field that held no stored unit before the save (new in it, or unstored before it) is now answered 409 `DESTRUCTIVE_CHANGE` with `unit_mode_to_record` on the quantity: every stored row then holds its quantity beside a blank unit, and is refused at its next quantity edit until it holds a unit code. The finding names the `""` mapping entry of `os migrate unit-codes` that writes those blanks, reads no row, and is lifted by `force: true`. A re-point onto a stored text field still raises `unit_code_field_declared` alone, and a re-point onto a field that already was a unit code field still raises nothing.
12
+
-`os migrate unit-codes` and `POST /api/v1/meta/_migrate-unit-codes`: a mapping entry whose key the rows store as a unit code, which is never rewritten, and that no row used is now named, as `unusedEntry` on that value in the report and as a line of the printed report.
13
+
- When the walk stops at `maxRecords`, the printed report now says that the rows past the cap were not judged, so any of them may hold a value with no mapping entry, and that an apply run wrote the rows examined only, as the record-currency backfill's report does; an unscoped run also says its organization check saw only the rows examined. An apply run over such a walk still writes the rows it examined, as before.
Copy file name to clipboardExpand all lines: packages/objectql/src/protocol-destructive-unit-mode.test.ts
+30-5Lines changed: 30 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,9 @@ import { unitCodeSources } from './validation/unit-code-membership.js';
19
19
* blanks beside it, whatever its `unitField`'s history (already a unit code
20
20
* field, or new in the same save), unless the same save raises
21
21
* `unit_code_field_declared` on that `unitField`: that finding names the
22
-
* quantity, the blanks and the `""` entry, so each debt is reported once. The
22
+
* quantity, the blanks and the `""` entry, so each debt is reported once. So
23
+
* does a stored `record`-mode quantity whose `unitField` is re-pointed at a
24
+
* field that held no stored unit (new in the save, or unstored before it). The
23
25
* save is answered with the 409 `DESTRUCTIVE_CHANGE`, whose finding names the
24
26
* conversion run, CLI and REST; `force: true` lifts it. It reads no row.
25
27
*/
@@ -172,6 +174,22 @@ describe('ObjectStackProtocolImplementation - unit_code_field_declared and unit_
172
174
readNoRow('mat_gross');
173
175
});
174
176
177
+
it("a stored record-mode quantity's unitField re-pointed at a field NEW in the same save raises unit_mode_to_record on the quantity, reading no row",async()=>{
178
+
// Every stored row now holds its quantity beside a blank 'gross_uom': the same blank debt as a switch to 'record'.
]asArray<[string,Record<string,unknown>]>)('on %s, the fields raised are those unitCodeSources newly names over a stored field, and each switched quantity\'s blanks are named once (%#)',async(object,next)=>{
0 commit comments