The wizard serialized the whole accumulating form state into a `snapshot` hidden field (pr-str EDN + custom readers), decoded it every request, and merged step-params back in. For this single-step modal the snapshot is pure redundancy: every value is either in the entity or the live posted form. Remove it: - render: EditWizard.render-wizard renders a plain form -- no snapshot / edit-path / current-step hidden fields; a single `db/id` hidden rides in the form instead. - middleware: wrap-derive-state rebuilds :multi-form-state per request from the entity (loaded by the db/id hidden) overlaid with the live step-params, replacing wrap-init-multi-form-state + wrap-entity. The ~34 :snapshot reads are unchanged -- :snapshot is now a derived map, not a round-tripped blob. - editable fields (accounts, vendor, memo, approval, action, mode, amount-mode) come ONLY from the posted form (absent = cleared) so removing all account rows doesn't resurrect the entity's persisted accounts; only entity-only fields (db/id, client, amount, ...) come from the entity. - delete the dead initial-edit-wizard-state and render-account-grid-body. - e2e: make removeAllAccounts re-query each iteration (whole-form swaps stale a captured row index) and restore the percentage test to type-then-add ordering. Scorecard: snapshot EDN round-trip + custom readers + merge-multi-form-state -> gone (snapshot-field renders 0). Verified on a fresh server: full suite 38 pass / 1 unrelated fail, swap 6/6, transaction-edit 8/8 -- same green as before, snapshot removed.
3.6 KiB
Quality scorecard (the ratchet)
Cheap to measure (grep -c, wc -l, clj-kondo), recorded before/after each
migration in the commit message and in the results table below. No metric may regress
for the touched modal without a written exception in gotchas.md. These are directional
evidence, not targets to game — always paired with the e2e parity gate.
Heuristics
| # | Heuristic | Measure | Target |
|---|---|---|---|
| 1 | Faked cursor positions (not cursors themselves) | grep -cE 'with-cursor|MapCursor\.' re-roots + grep -c 'defn.*-no-cursor' |
→ 0 (top-rooted cursors are fine) |
| 2 | Implicit state merges (snapshot/cursor) | count merge sites | → 0 (forms); explicit put-step only (wizards) |
| 3 | Branching complexity | clj-kondo, or count cond/condp/case/nested if + max depth |
net ↓ |
| 4 | Lines of code | wc -l on the modal's file(s) |
net ↓ |
| 5 | Reuse / cross-form similarity | cookbook components reused; duplicated-block count | reuse ↑, dup ↓ |
| 6 | Route count | count routes for the modal | → 2 (+1 for add-row) |
| 7 | OOB swaps | grep -c hx-swap-oob |
→ 0 unless a justified disjoint-region case is documented |
| 8 | Attribute consistency | mixed :x-/"x-" encodings in migrated template |
→ 0 |
How to measure (copy/paste)
F=src/clj/auto_ap/ssr/<modal>.clj
echo "LOC $(wc -l < $F)"
echo "no-cursor twins $(grep -c 'defn.*-no-cursor' $F)"
echo "faked-cursor roots $(grep -cE 'with-cursor|MapCursor\.' $F)"
echo "snapshot merges $(grep -c ':multi-form-state :snapshot' $F)"
echo "branch forms $(grep -cE '\(cond |\(condp |\(case |\(when-not ' $F)"
echo "hx-swap-oob $(grep -c 'hx-swap-oob' $F)"
echo "mixed string hx- $(grep -cE '\"hx-[a-z]' $F)"
# route count: count this modal's entries in src/cljc/auto_ap/routes/*.cljc
Results
Each migration appends one row (after-numbers), referencing the before in the diff.
| Phase | Modal | LOC | Routes | no-cursor twins | faked roots | snapshot merges | OOB | mixed hx- | cookbook reused / added |
|---|---|---|---|---|---|---|---|---|---|
| 1 (baseline) | Transaction Edit transaction/edit.clj |
1608 | ~12 | 1 | 2 | ~75 | 0 | 8 | — / seeded 7 entries |
| 2 | Transaction Edit transaction/edit.clj |
1584 | ~5 | 0 | 0 | 0 round-trip | 0 | 8 | — / 0 |
Phase 2 progress. Achieved with parity held (swap spec 6/6, transaction-edit spec 8/8, full suite 38 pass / 1 unrelated fail / 0 skip, up from 30/2/7):
- deleted the dead
*-no-cursor*twin (no-cursor 1→0);- de-faked the simple-mode cursor (faked roots 2→0) via explicit data + explicit field names (
account-field-name) + explicit error lookup — the render-fn rewrite thewith-field-defaultshortcut couldn't do;- collapsed the 5 manual-coding operation routes into one
edit-form-changeddispatcher (routes ~12→~5; the operations are now pureapply-*fns);- fixed a real production bug (
:mode→ 500 on every advanced manual save);- greened
transaction-edit.spec.ts(8/8) and matured the skill.Still open for this modal — the wizard→plain-form rewrite (one interdependent effort): remove the snapshot round-trip (~75 merges → 0; this also fixes the operations-drop-live-values bug in
gotchas.md), drop themm/ModalWizardStepprotocol, and Selmer-convert the shared interactive components (com/typeahead/com/select). Mixed stringhx-attrs (8) clear as those components move to Selmer templates.