Repository navigation
Commit 2f8383f
fix(metadata-protocol): a package duplicate withdraws a copied flow action whose target flow it did not write (#38738)
<!-- claude-projects-attribution: {"github_login":"os-steve"} -->
_Requested by **Steve** · [project
thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9RgRdwG1S43a4gfYWB4Ytyp)_
Fixes #38685
Clause-②: no
Metadata-protocol: none
## 维护者速读
-
用户能看到什么变化:搭建者复制一个软件包时,若某个流程没能复制过去,复制出来的、要运行这个流程的操作、页面按钮、带这类按钮的对象以及提到它的翻译包也一并撤回并在失败清单里写明原因,不再留下一点就报"找不到流程"的坏条目。
- 为什么做:接着上一轮"复制软件包时流程互相调用要跟着改名"的修复,当时只撤回了调用失败流程的流程,漏了操作和其它引用流程的地方。
-
出错会怎样:最坏是复制时多撤回了某个本可保留的条目(例如整个翻译包,或整个对象而指向它的视图仍留着),它会出现在失败清单里,修好源头流程后再复制一次即可恢复,不影响源软件包。
- 要你做什么:请读下方 Acceptance notes 里的三条边界行为,确认它们符合预期。
## What changes
`duplicatePackage`
(`packages/metadata-protocol/src/protocol-package-commits.ts`) already
points every flow reference in a copied item at the copy's flow. Its
post-loop close (from #38595) took back only copied FLOWS whose planned
callee was not written. A copied flow action whose `target` names such a
flow (case a), or one withdrawn transitively (case b: action, then
parent, then child), stayed in `copied[]`, stored targeting a flow that
exists nowhere, and answered 404 "flow not found" at run time.
- **One predicate, shared with the rename engine**
(`package-namespace-rename.ts`). The site resolution the rename's walk
used inline (object sites, the derived index's `flow` sites, the `name`
of an entry under a site, and the hand-written `target` beside a
`'flow'` executor in `type` / `actionType`) moves to one module-level
function, `referenceSiteAt`, which `deepRewrite` now calls (same
precedence, same answers: the rename's behaviour is unchanged, and its
tests are green). A new export, `flowReferencesOf(item)`, walks an item
with that same resolver and answers every flow name it holds at a flow
reference site, with the path. It is internal: the package's `index.ts`
does not re-export it.
- **The close covers every copied caller.** The copy loop records, for
every copied item (not only flows), the planned flows it names:
subflow/map callees as before (`plannedCalleesOf` stays), plus every
`flowReferencesOf` hit that is a key of `planFlowSources`. A withdrawn
item gets the same undo as before (the address read before the write,
`undoBatchRowWrite`), leaves `copied[]`, and is reported in `failed[]`
naming the flow and the site. Flows keep today's text ("calls flow 'X'
through a subflow or map step"); a `target` site reads "runs flow 'X'
through its flow action `target`" (with the path at depth); any other
site reads "names flow 'X' at its flow reference `PATH`". The
BatchRowHealError and undo-failed branches stay.
- Only a withdrawn FLOW makes its own callers go (transitive close as
before); a withdrawn action, page, object or translation does not enter
`notWritten`, so a flow that happens to share its name is not affected.
- A withdrawn item that is also a written object row is removed from the
object settle's list, so the settle never judges or undoes it a second
time. **NOT MEASURED:** no test pins this line. The package's duplicate
tests run on a partial engine double, where `canJudgeBatchObjects` is
false, so `writtenObjects` stays empty and the settle never runs;
replacing the splice with a no-op leaves every test green (L1 ablation,
comment 7275739965). Pinning it needs a judging-registry engine double
and its ledger row, which is outside this card.
- No refusal is added at any door (case d stays out of scope), and the
import leg (`importUnmanagedPackage` + `targetNamespace`) is untouched.
## Tests
All pins live in
`packages/metadata-protocol/src/package-namespace-rename-flow-refs-38595.test.ts`,
as one new top-level `describe` ("duplicatePackage withdraws a copied
flow action whose target flow it did not write (#38685)") that reuses
that file's harness and engine doubles (the real save door and copy door
over a row-keeping stub engine). No new test file, and the engine-double
ledger is untouched.
- a. the action's target flow fails: the action is withdrawn, not in
`copied[]`, in `failed[]` naming `crm2_child` and the `target` site,
nothing stored at its address.
- b. transitive (action, then parent, then child, child fails): the
action goes with the parent, its error naming `crm2_parent` and "was
withdrawn".
- c. CONTROL: nothing fails, so the action and its flow are both copied
and the target resolves.
- CONTROL: two `modal` actions whose `target` spells the failed flow
(source spelling and copy spelling) stay copied.
- A page whose `action:button` block runs the failed flow (`actionType:
'flow'`, at `regions[0].components[0].properties.target`) is withdrawn;
a `url` button page beside it stays (CONTROL).
- (i) a translation bundle whose `flows` key names the failed flow is
withdrawn whole (error names `flows.crm2_child`; no translation row is
stored).
- (ii) an object whose inline `actions[0]` runs the failed flow is
withdrawn whole; (iii) its list view, which names the object, stays
copied and stored with `object: 'crm2_lead'`.
**Forced change to an existing pin.** In the same file, "a caller whose
planned callee fails is withdrawn with it" now expects `failed[]` to be
`['action/crm_run_child', 'flow/crm_child', 'flow/crm_parent']`. Its
fixture (`callerBody`) carries the flow action `crm_run_child` targeting
`crm_child`, the flow that fails, so the old two-flow list pinned the
gap itself: it passed only because that action stayed copied, running a
flow that exists nowhere. Under the ablation below it goes red with the
new pins.
Ablation (`scripts/ablation-replace.mjs`, anchor `for (const ref of
flowReferencesOf(body)) {` replaced with an empty iterable): 6 red (the
forced pin, a, b, the page case, (i), and (ii) with (iii)), 11 green
(both CONTROLs and the pre-existing #38595 pins); restore proven (blob
== HEAD, `git diff HEAD` empty). (iii) is a preservation pin: it holds
with or without the fix, and is red under the ablation only through
(ii)'s assertions in the same case.
## Acceptance notes
Three edges of "every flow reference site", for the L1 reviewer and the
maintainer to read:
- **(i) A translation bundle goes whole.** A translation's `flows` keys
are a flow reference site the rename rewrites, so a copied bundle that
labels a planned flow the copy did not write is taken back whole, with
every other label in it (objects, fields, views), not trimmed of the one
key. It is reported in `failed[]` naming the flow; fixing that flow and
duplicating again brings the bundle back.
- **(ii) An object goes whole.** A copied object whose inline action has
`type: 'flow'` and a `target` naming such a flow is taken back whole:
its row is put back, it leaves `copied[]`, and it is dropped from the
object settle (that splice is NOT MEASURED; see above).
- **(iii) Referrers of a withdrawn object stay as they are.** Items that
name that object (its views, other items pointing at `crm2_lead`) are
not cascaded: they stay copied and stored, naming an object the copy no
longer holds. This is the same behaviour as today when the object settle
refuses a copied object; no new cascade is introduced here.
- Out of scope, as triaged: the action save door does not judge a flow
`target` (case d), so a direct publish of a flow action naming no flow
is still stored.
## Verification
Read first (by risk):
1. `packages/metadata-protocol/src/package-namespace-rename.ts`
`referenceSiteAt` (around L187) and the `siteOf` call in `deepRewrite`
(around L600 and L657): the rename's own site resolution, moved; it must
answer exactly what the inline code did.
2. `packages/metadata-protocol/src/protocol-package-commits.ts` the
post-loop close (around L770 to L825): the per-site reason text, the
object-settle splice, and `notWritten` growing on flows only.
3. `plannedCallsOf` (around L524) and its use at L645: which copied
items record a planned call.
Two-minute check: `pnpm --filter @objectstack/metadata-protocol exec
vitest run src/package-namespace-rename-flow-refs-38595.test.ts` shows
17 passed.
Gap before the fix, re-measured on `80ddfb5050` with the seat's probe: 4
passed (the probe pins the gap), e.g. case a answered `copied` holding
`action/crm2_run`, `failed` only `flow/crm_child`, the stored action
targeting `crm2_child`, no such flow anywhere.
All readings below are on head `a4bd4b7775` (origin/main `95ffacc2c5`
merged in with a merge commit).
<details><summary>Package tests and typecheck</summary>
- `pnpm --filter @objectstack/metadata-protocol typecheck` (tsc
--noEmit): exit 0.
- `pnpm --filter @objectstack/metadata-protocol test`: VERDICT
command-exit 0; Test Files 376 passed, 9 skipped (385); Tests 23807
passed, 45 skipped (23852).
- `src/package-namespace-rename-flow-refs-38595.test.ts` alone: 17
passed.
</details>
<details><summary>Ablation</summary>
- Mutation landed: anchor 1 to 0, blob 6ab27da to 91cb7c0b1fcf.
- Run of the 38595 file: 6 failed, 11 passed (17).
- Restored: blob == HEAD (6ab27da), `git diff HEAD` empty.
</details>
<details><summary>Derived gate families (dispatch-gates --commands,
69)</summary>
- 67 exit 0, `pnpm check:engine-double-contract` among them.
- `pnpm check:dual-build-cjs-loads`, `pnpm check:lean-entry-closure`:
exit 3, PREREQUISITE NOT MET (no full build in this container), NOT
MEASURED locally; CI runs them.
- `dispatch-gates --ran`: 69 derived, 67 run, 2 NOT-MEASURED (recorded
exit 3).
- `node scripts/pm/overlap-check.mjs`: VERDICT clean, exit 0 (against
origin/main 95ffacc, 0 PR heads).
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01ADHkmQJUGAAa5rz9Yi2DvW)_
<!-- signed: repo:objectstack#3 · os-steve ·
session_01ADHkmQJUGAAa5rz9Yi2DvW -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent f782a12 commit 2f8383f
4 files changed
Lines changed: 319 additions & 38 deletions
File tree
- .changeset
- packages/metadata-protocol/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
379 | 379 | | |
380 | 380 | | |
381 | 381 | | |
| 382 | + | |
| 383 | + | |
382 | 384 | | |
383 | | - | |
| 385 | + | |
384 | 386 | | |
385 | 387 | | |
386 | 388 | | |
| |||
413 | 415 | | |
414 | 416 | | |
415 | 417 | | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
0 commit comments