Skip to content

fix(plugin-form): a create form offers a state_machine select only its initialStates - #27969

Merged
objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/project-thread-mfxh2r
Oct 30, 2026
Merged

objectstack-fleet[bot] merged 4 commits into
mainfrom
claude/project-thread-mfxh2r

Conversation

@objectstack-fleet

@objectstack-fleet objectstack-fleet Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

domain:ui#3 · os-bill · session_01Utp6CaJoinvGQSbHeDaWBe

Requested by Bill · project thread

维护者速读

  • 改了什么:新建表单里受 state_machine 管辖的下拉字段,现在只列出该状态机声明的 initialStates(如 showcase 项目只给「Planned」),与编辑表单已有的「只给可达状态」走同一道字段门。
  • 为什么改:服务端新建时只接受 initialStates,表单却列出全部选项,用户选别的值点保存才收到 invalid_initial_state 拒绝;按分诊「先改平台」裁定,在表单层修好,所有应用的新建表单一起受益。
  • 风险与回滚:只收窄选项列表、不改写任何值;没有声明 initialStates 的状态机、warning 级或仅 update 的规则保持全部选项;回滚即 revert 本 PR。
  • 先看:ui/packages/plugin-form/src/stateMachineOptions.ts(create 分支与「打开值保留」规则)、ui/packages/core/src/validation/validators/state-machine-next-values.ts(新 helper)、ui/packages/plugin-form/src/ObjectForm.tsx(gateFields 下移以拿到打开值)。
  • 两分钟验证:pnpm --dir ui exec vitest run packages/plugin-form/src/__tests__/stateMachineCreateSelect-27763.test.tsx,预期 6 条全绿(主从表单、平铺表单、新建对话框都只给 planned)。
  • 需要你做的:无,席位落地。

Fixes #27763

Clause-②: no
Metadata-protocol: none

What changes

  • @object-ui/core gains stateMachineInitialValues(objectSchema, fieldName) beside stateMachineNextValues: the values a new record may be created in, read from the same served validations with the same rule reading (blocking severity: 'error', active, events covering the write, absent keys read as the spec default). It returns null when no applicable rule declares initialStates, which is exactly where the server's insert check is a no-op. The two helpers now share one rule predicate, so there is still one reading of a machine.
  • narrowStateMachineOptions (the pass inside gateFormFields, which every form layout draws through) gains a create arm: on mode: 'create' a select governed by such a machine keeps only its initialStates. The edit arm is unchanged.
  • The value a create form OPENS with (openingValues: the seeded default: true option or the caller's pre-fill) stays offered even when it lies outside initialStates, so the form never silently drops a value it was handed; the server's refusal stays the one that names it. Every layout passes the values it opens with: ObjectForm (its gate step moves below finalDefaultValues for that), ModalForm, DrawerForm, TabbedForm, WizardForm.
  • The master-detail form needs no path of its own: its header is an ObjectForm, so it draws through the same gate (measured: the master-detail test below goes red under the ablation with the others).
  • When no field narrows, the pass returns the very array it was handed, as before.
  • The behaviour is written down in ui/packages/plugin-form/README.md and content/docs/frontend/plugins/plugin-form.mdx (neither described the edit-side narrowing before).

Why

showcase_project's project_status_flow declares initialStates: ['planned'], and the server refuses any other initial status with invalid_initial_state. The "New Project + Tasks" create form offered all five statuses, so four of them were dead ends. The triage ruled platform first: the form stops offering what the server refuses, for every app, and the showcase page stays as it is as the proof. examples/app-showcase/** is untouched.

Tests

  • ui/packages/core/src/validation/__tests__/state-machine-next-values.test.ts: stateMachineInitialValues (package-root export, declared states, absent events, no or empty initialStates, warning / inactive / update-only rules, another field, intersection of two rules).
  • ui/packages/plugin-form/src/stateMachineOptions.test.ts: the create arm on both option carriers, the opening value kept, the persisted record ignored on create, the no-initialStates control, the edit control, a view form, and through gateFormFields.
  • ui/packages/plugin-form/src/__tests__/stateMachineCreateSelect-27763.test.tsx (DOM, read off the native select Radix renders): the showcase master-detail create form, the flat in-page create form and the console create dialog each offer only planned; a caller's pre-fill outside initialStates stays offered; CONTROL: no initialStates keeps every option; CONTROL: an edit form still narrows from the stored value.
  • ui/e2e/live/master-detail.spec.ts: one new case opens the status select on the live showcase page and asserts planned is offered and the four refused states are not. The existing cases are unchanged apart from one comment.
Ablation (one-shot, on the committed tree)

Via scripts/ablation-replace.mjs under the verify lock; @object-ui/core and the plugin-form sources resolve to src/ through the ui vitest alias, so no dist rebuild sits in the path.

  1. Create arm off (if (mode === 'create') { replaced so it never matches): 8 failed, 16 passed of the two files. Red: the 4 create-arm unit cases and the 4 DOM create cases (master-detail, flat, dialog, pre-fill). Green: both CONTROLs and every edit case. Restored: blob equals HEAD, git diff HEAD empty.
  2. Opening value dropped (return initial && opening !== null ? new Set([...initial, opening]) : initial; replaced by return initial;): 2 failed, 22 passed. Red: exactly the two pre-fill cases. Restored the same way.

Acceptance notes

  • Seeded default: the showcase status field's default: true option is planned, which is inside initialStates, so the master-detail form opens on a legal value. A seeded default outside initialStates would stay offered (the opening-value rule) and the server would refuse it on save; no showcase object has one today.
  • The master-detail child rows (showcase_task) are not narrowed on create: task_status_flow is update-only and declares no initialStates, so the server does not police their insert either.
  • Create surfaces outside the form gate (a grid's inline new row, a board's quick-create) are not changed here; this PR covers the form layouts that draw through gateFormFields. Filed by the seat as Grid inline new row and board quick-create offer every option of a state_machine field that declares initialStates #27976.
  • Mode: the create arm keys on mode: 'create', the value every create form in the console and the showcase page declares. A form that declares no mode keeps every option, as before.
  • The live e2e case is measured by CI's Live E2E UI job, not locally.

Verification

Local readings. Tests and type check ran on 5c360f28; the head 54cb3d7d adds only the README and docs-page text on top of it. The gate union ran on 54cb3d7d.

  • Targeted: the four state-machine test files, 48 passed (48).
  • Affected packages: pnpm --dir ui exec vitest run packages/plugin-form/ packages/core/, Test Files 432 passed (432), Tests 6533 passed, 28 skipped.
  • Type check: pnpm --filter @object-ui/core --filter @object-ui/plugin-form run type-check, both Done, VERDICT command-exit 0.
  • Derived gates (node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack, 66 families, among them node scripts/check-sdui-manifest.mjs and pnpm --dir ui exec vitest run scripts/ at 169 files passed): every one exit 0. --ran reconciliation: "66 derived famil(ies) accounted for — 66 run, 0 NOT-MEASURED". check:skill-examples first refused with exit 3 (its prerequisite, a built @objectstack/client-react, was missing; nothing measured), then ran exit 0 after that build.
  • pnpm --dir ui run check:new-line-citations: 0 new citations.
  • Every other family is CI's run on this PR.

Human Minimum

  • 1. Schemas start as Zod; packages/spec holds no runtime logic. (packages/spec untouched.)
  • 2. Every name I added uses the casing for its kind.
  • 3. No formatter ran; pnpm lint is CI's run.
  • 4. One issue, one branch off an up-to-date main, one pull request.
  • 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset.
  • 6. packages/spec touched: n/a.
  • 7. No hand edits to content/docs/references/, packages/*/CHANGELOG.md or content/docs/releases/.
  • 8. Title, body and comments are in English.
  • The Before Submitting list in CONTRIBUTING.md is done.

Generated by Claude Code

… initialStates

A select governed by a blocking state_machine that declares initialStates
now keeps only those values on a create form, through the same field gate
every layout draws through. The value the form opens with stays offered.
@object-ui/core gains stateMachineInitialValues beside stateMachineNextValues.

Claude-Session: https://claude.ai/code/session_01Utp6CaJoinvGQSbHeDaWBe
Co-authored-by: Claude <noreply@anthropic.com>
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:ui#3 · os-bill · session_01Utp6CaJoinvGQSbHeDaWBe

席位核对

ACCEPT · head 54cb3d7d9d62d0708154de6abf8b8a51ba4ed94e · 2026-10-30T06:08Z

  • Shape: draft → main, Fixes #27763. Clause-②: no and Metadata-protocol: none match the claim. The change is ui-only (@object-ui/core, @object-ui/plugin-form), so no contract review is owed.
  • Ruling (triage 04:00Z, platform first): the create form offers a governed select only its initialStates, and the showcase page is untouched. examples/app-showcase/** is not in the diff, and the page stays as the proof: the live e2e case on the master-detail form expects planned only.
  • Premise, measured:
  • Read: SimpleObjectForm's gateFields moved below finalDefaultValues. No early return lies between the two positions, so hook order holds. gateFields is only called during render, so its per-render identity costs nothing.
  • Tests: targeted 48/48; core + plugin-form 432 files / 6533 passed. Two ablations: the create arm off turns 8 red with controls green, and dropping opening-value retention turns 2 red. Both restored. Live E2E UI is green on the head.
  • Gates (check-runs on the head): 51 success, 8 skipped, 0 failure; mergeable_state clean. check-governed-merges --pr 27969: NOT governed, 595 changed lines.
  • Accepted deviations:
    • plugin-form README and the docs page were updated (ui/AGENTS.md ✨ Set up Copilot instructions #2).
    • Three early commits carry the seat's session in Claude-Session. This has no effect on the tree.
    • The PR line-2 link names the card thread.
  • Out of scope, filed by the seat: Grid inline new row and board quick-create offer every option of a state_machine field that declares initialStates #27976 covers the grid's inline new row and a board's quick-create, which still offer every option.
  • Landing: non-governed, all checks green, mergeable_state clean ⇒ the seat lands it (pr_ready + automerge_enable).

Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/l tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

1 participant