Repository navigation
Commit b53e70f
feat(showcase): a paid invoice declares closedStates; the three paid-invoice line hooks are removed (ADR-0162 item 3) (#38917)
Fixes #37771
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
用户能看到什么变化:示例应用里已付款的发票,普通用户改表头、删整张、改/加/挪/删明细,现在一律被系统拒绝并提示「记录已关闭」;以前表头和明细的大部分字段其实能改,整张也能删。
-
为什么做:单据关闭态锁定的最后一块:用发票上的一行声明替掉示例应用里三段手写的拦截代码,作为平台这项能力的运行证明,也给其他应用一个照抄的样例。
- 出错会怎样:只影响示例应用里已付款的发票;最坏是示例里有人本来想改已付款发票被拦住;去掉这一行声明即可恢复旧行为。
- 要你做什么:无。
## What changes
- `examples/app-showcase/src/data/objects/invoice.object.ts`: the
invoice declares `closedStates: { status: ['paid'] }` (ADR-0162 D1). The
comments that named the hooks, and the `tax_rate` and line-field
comments, now say what the server does. The `readonlyWhen` predicates
and the `userActions` gating stay, because the console renders from
them.
- `examples/app-showcase/src/data/hooks/index.ts`: the three
paid-invoice line hooks (`showcase_guard_paid_invoice_line_add` /
`_move` / `_remove`), their shared prelude and the three exported
sentences (`PAID_INVOICE_LINE_ADD_REFUSAL`, `_REMOVE_`, `_MOVE_`) are
deleted. `allHooks` now holds five hooks.
- `examples/app-showcase/test/paid-invoice-line-lock.test.ts`: the same
harness, now asserting the platform's lock (`code` `RECORD_LOCKED`,
`status` 409, `reason` `record_closed` / `master_closed`, `lockReason`
`closed_state`) where it asserted the three app sentences. It adds the
outcomes that change by design: editing the paid header, deleting the
paid invoice, editing a line (both a field with `readonlyWhen` and
fields without it). A system write is shown to be unbound. The REVERSE
block now drops `closedStates` from the invoice instead of unbinding
hooks. Per AGENTS.md, a new pin for a component with a shared harness
file goes into that file, so this card adds no new test file.
- `examples/app-showcase/test/approval-resume-relation-expand.test.ts`
(claim amendment 1): its kernel now registers a minimal `job` service
ahead of the approvals plugin. An approval on an object that declares
`closedStates` opens only on a host with a job service (ADR-0162
Execution item 8), and without one the invoice sign-off's first request
was refused.
- Dogfood tests that pinned a caller write on a paid showcase invoice or
its lines, each edited only at those pins:
-
`packages/qa/dogfood/test/invoice-conditional-rules-server.dogfood.test.ts`:
a `tax_rate` PATCH on the paid INV-1003 now answers `409 RECORD_LOCKED`
instead of 200. The re-read still shows the value unchanged, and the
draft control is unchanged.
-
`packages/qa/dogfood/test/showcase-readonly-when-parent.dogfood.test.ts`:
the paid line and paid header PATCHes now answer `409 RECORD_LOCKED`,
and the frozen values still survive. A field `readonlyWhen` leaves open
no longer lands. The mixed `updateMany` reports the locked row as a
`RECORD_LOCKED` failure while the open row lands (now under
`continueOnError`). The header comment names where the field-level strip
and the dropped-fields header stay pinned.
-
`packages/qa/dogfood/test/showcase-crud-persona-matrix.dogfood.test.ts`:
a comment that named the removed hooks (no behaviour change).
- `docs/qa/platform-checklist/areas/records-forms.json`: the item
`records-forms.object-hook-lifecycle` (revision 13 to 14, with a history
entry) names the five seeded hooks. It also says the showcase seeds no
`beforeDelete` hook, and drops the guards from `automated.ref`. No
clause changed.
- No changeset: `@objectstack/example-showcase` and
`@objectstack/dogfood` are private, and nothing else is published
(`skip-changeset`).
## Dogfood record
The showcase was booted in this container from this worktree: `pnpm
--filter @objectstack/example-showcase dev -- --fresh -p 38771`, with a
fresh seed each time. BEFORE was taken on `origin/main` `ac97540f75`,
AFTER on this branch. The caller is the seeded admin
`admin@objectos.ai`, an ordinary user session (`role: user`), not a
system context. All writes went over REST at `/api/v1/data/*`.
| Write | Before (main) | After (this branch) |
|---|---|---|
| 1 header PATCH `{region, tax_rate}` on paid INV-1003 | 200; stored:
region amer to emea, tax_rate 8 to 8 (stripped) | 409 `RECORD_LOCKED`
"Invoice 'INV-1003' is closed, so it and its lines can no longer be
changed or deleted"; stored: region amer, tax_rate 8 |
| 2 DELETE paid INV-1005 | 200; the row is gone | 409 `RECORD_LOCKED`
"Invoice 'INV-1005' is closed, so it and its lines can no longer be
changed or deleted"; the row is still there |
| 3a line PATCH `{description, position, service_start}` under paid
INV-1003 | 200; stored: description to "edited after payment", position
0 to 7, service_start null to 09:30:00 | 409 `RECORD_LOCKED` "This
Invoice is closed, so it and its lines can no longer be changed or
deleted"; nothing changed |
| 3b line PATCH `{quantity, unit_price, description}` under paid
INV-1003 | 200; quantity 6 and unit_price 49.99 stripped, description
lands | 409 `RECORD_LOCKED` (same sentence); nothing changed |
| 4a POST a line under paid INV-1003 | 400 `HOOK_ABORTED` "This invoice
is paid, so its lines are locked: a line cannot be added to it." | 409
`RECORD_LOCKED` "This Invoice is closed, so it and its lines can no
longer be changed or deleted" |
| 4b move a draft line onto paid INV-1003 | 400 `HOOK_ABORTED` "A paid
invoice's lines are locked: a line cannot be moved onto or off a paid
invoice." | 409 `RECORD_LOCKED` (same sentence) |
| 4c move the paid line off INV-1003 | 400 `HOOK_ABORTED` (the move
sentence) | 409 `RECORD_LOCKED` (same sentence) |
| 4d DELETE the paid line of INV-1003 | 400 `HOOK_ABORTED` "This invoice
is paid, so its lines are locked: a line cannot be removed from it." |
409 `RECORD_LOCKED` (same sentence) |
| control: draft INV-1004 PATCH `{tax_rate}` | 200 | 200 |
After rows 1-4, INV-1003 still totals 299.94 with its one line, both
before and after.
**Seed:** `Seeds: com.example.showcase 141 rows` on both boots. On the
AFTER boot the paid INV-1003 carries its seeded line (total 299.94), so
the seed loads finished invoices as a system write, which ADR-0162 D5
leaves unbound. No seed file changed.
**Flows, checked in the running app** (the submitter is the seeded
persona `phone.demo@example.com` holding `showcase_contributor`; the
approver is the dev admin holding the finance / legal / manager
positions; the readings were identical before and after):
- `showcase_invoice_signoff`, approve path. The submitter flips INV-1004
draft to sent (200), and a request opens `pending`. A caller edit while
it is pending lands (200; `lockRecord: false`, and `sent` is not
closed). The admin approves (200), the request ends `approved`, and the
run ends `completed`. A caller edit after the run lands (200), so no
hold is left on the record.
- `showcase_invoice_signoff`, reject path (INV-1002). The reject is 200,
the request ends `rejected`, the run's system `flag_held` write puts the
invoice back to `draft`, and the run ends `completed`. A caller edit
afterwards lands.
- `showcase_release_signoff` (a `map` over two `showcase_task` records).
It triggers and pauses, each task's request opens and is approved, and
the run ends `completed`. `showcase_task` declares no `closedStates`,
and the map is not under a record.
- ADR-0162 item 7 and item 8 refuse none of these on this host. The
sign-off mirrors no status onto the invoice, and the host runs a `job`
service. The no-job-service case is the one that breaks a test, see
Acceptance notes.
## Tests
<details><summary>Local runs at head b50ff46</summary>
- `pnpm --filter @objectstack/example-showcase exec vitest run
--maxWorkers=2 test/paid-invoice-line-lock.test.ts`: 16/16 passed.
- `pnpm --filter @objectstack/example-showcase exec vitest run
--maxWorkers=2 test/approval-resume-relation-expand.test.ts`: 12/12
passed. Before the job service was added (5be97d0) it was 9/12.
- `pnpm --filter @objectstack/example-showcase exec vitest run
--maxWorkers=2` (the whole showcase suite): 49 files, 551/551 passed.
- `pnpm --filter @objectstack/dogfood exec vitest run --maxWorkers=2`
over every dogfood test file that names `showcase_invoice` (24 files),
plus `authz-conformance`, `controlled-by-parent`,
`owner-anchor-and-bulk-writes` and `flow-runas`: before the dogfood
edits, exactly the two files above were red (1 + 6 tests). After them,
`invoice-conditional-rules-server` and `showcase-readonly-when-parent`
pass 11/11, and the rest passed unedited.
- `pnpm --filter @objectstack/example-showcase typecheck`, `pnpm
--filter @objectstack/dogfood typecheck`: exit 0. Both tsconfigs include
their `test/` trees.
- `node scripts/check-platform-checklist.mjs --changed-from
origin/main`: OK, 11 anchors judged, 0 lost.
- `node scripts/pm/dispatch-gates.mjs --commands` at b50ff46 (the same
64 as at 5be97d0): 61 run, 60 exit 0, and `check:adr-symbol-anchors`
exit 1 (routed separately, see Acceptance notes). NOT MEASURED locally:
`check-plugin-teardown-shape --self-test` exit 3 (shallow clone; its
fixture is pinned to a commit), `check:dual-build-cjs-loads` exit 3
(needs a full build), `check:query-options-erasure` exit 124 at 5be97d0
(240 s local cap). CI ran the last one green at b50ff46.
</details>
## Acceptance notes
- The sign-off test's missing job service is fixed in this PR (claim
amendment 1), see What changes.
- **The ADR anchor repair was routed separately, to #38919, and has
landed.** ADR-0162 lines 77 and 718 anchored the hook symbols this PR
deletes; PR #38936 re-anchored them to the hooks file and merged at
2026-12-01T16:28Z. This branch merged `main` at 45e4457 (head
4262a3e), and `check:adr-symbol-anchors` and `Lint & Repo Gates` are
green there.
- The liveness row `object.closedStates` in
`packages/spec/liveness/object.json` is already `live`, with its own
runtime proof (`packages/qa/dogfood/test/closed-state-lock.test.ts`).
The card's last Done-when box was met by the key's own card, so this PR
does not move the row.
- **Checklist drift outside the surface, carried by #38987** (review
follow-ups of this PR, L1 S1 7318788194):
`records-forms.conditional-rules-header` acceptance[2] still says a
`tax_rate` PATCH on the paid INV-1003 answers 200 and is discarded (it
now answers 409 and is refused), and `access-security.write-path-guards`
acceptance[5] and its `automated.ref` still expect `droppedFields` /
`readonly_when` on the paid invoice, where this PR re-points those pins
in `showcase-readonly-when-parent.dogfood.test.ts` to `RECORD_LOCKED`.
Not edited here.
- The console's master-detail save puts the header first (ADR-0162 D4
names it, and Execution item 4 is its own card). In the showcase, a save
that edits lines and sets `paid` in one batch would meet a closed header
on the line writes. This was not driven here.
## Verification
Read first:
1. `examples/app-showcase/src/data/objects/invoice.object.ts`: the
`closedStates` block. It is the whole runtime change.
2.
`packages/qa/dogfood/test/showcase-readonly-when-parent.dogfood.test.ts`:
the re-pointed pins, especially the `updateMany` case, which now runs
under `continueOnError`.
3. `examples/app-showcase/test/paid-invoice-line-lock.test.ts`: the
`expectRecordLocked` assertion set, and the REVERSE block.
Two-minute check: boot the showcase, sign in as `admin@objectos.ai`, and
`PATCH /api/v1/data/showcase_invoice/INVOICE_ID` (the id of INV-1003)
with `{"region":"emea"}`. You should get `409` with `code`
`RECORD_LOCKED`, and the region unchanged on re-read.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01WGufzhKEbEnW8pwZRgK2gJ)_
<!-- signed: repo:objectstack@os-support-ai · os-support-ai ·
session_01WGufzhKEbEnW8pwZRgK2gJ -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 670bc89 commit b53e70f
8 files changed
Lines changed: 206 additions & 214 deletions
File tree
- docs/qa/platform-checklist/areas
- examples/app-showcase
- src/data
- hooks
- objects
- test
- packages/qa/dogfood/test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4553 | 4553 | | |
4554 | 4554 | | |
4555 | 4555 | | |
4556 | | - | |
| 4556 | + | |
4557 | 4557 | | |
4558 | 4558 | | |
4559 | 4559 | | |
| |||
4562 | 4562 | | |
4563 | 4563 | | |
4564 | 4564 | | |
4565 | | - | |
| 4565 | + | |
4566 | 4566 | | |
4567 | 4567 | | |
4568 | 4568 | | |
4569 | 4569 | | |
4570 | 4570 | | |
4571 | 4571 | | |
4572 | 4572 | | |
4573 | | - | |
| 4573 | + | |
4574 | 4574 | | |
4575 | 4575 | | |
4576 | 4576 | | |
| |||
4581 | 4581 | | |
4582 | 4582 | | |
4583 | 4583 | | |
4584 | | - | |
| 4584 | + | |
4585 | 4585 | | |
4586 | 4586 | | |
4587 | 4587 | | |
| |||
4686 | 4686 | | |
4687 | 4687 | | |
4688 | 4688 | | |
4689 | | - | |
| 4689 | + | |
4690 | 4690 | | |
4691 | 4691 | | |
4692 | 4692 | | |
| |||
4774 | 4774 | | |
4775 | 4775 | | |
4776 | 4776 | | |
| 4777 | + | |
| 4778 | + | |
| 4779 | + | |
| 4780 | + | |
| 4781 | + | |
| 4782 | + | |
4777 | 4783 | | |
4778 | 4784 | | |
4779 | 4785 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
132 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
| |||
161 | 162 | | |
162 | 163 | | |
163 | 164 | | |
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 | 165 | | |
281 | 166 | | |
282 | 167 | | |
283 | 168 | | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | 169 | | |
288 | 170 | | |
289 | 171 | | |
0 commit comments