refactor(shared): split runResult out of runSubmit (RB-17)
runSubmit did two things at once: fold a call into a Result, and mint an Idempotency-Key for it. Five call sites are reads and had no business minting one — brief.adapter.ts:load, org-template.adapter.ts :list/:load, and stamdata.adapter.ts:list/:load. stamdata.adapter.ts's own docstring already said "Both endpoints are reads … There is no write method" while both called runSubmit; that mismatch is the sharpest evidence, and the reason the baseline's original "~13 mutations" count (derived from the helper's name, not the code) was wrong by five in one direction. Split submit.ts in place: runResult is the try/catch + problemDetail fold with no mint; runSubmit is runResult wrapping withIdempotencyKey. Zero behaviour change for the 8 real mutations (brief save/submit/approve/reject/send/reset, org-template save/publish/rollback) — same fold, same mint, same timing. The five reads now run the fold with no pendingIdempotencyKey touched. submit.spec.ts asserts the split behaviourally via currentIdempotencyKey() (two reads inside the same call agree only when a key was minted and reused) rather than mocking a relative import, matching this repo's existing vitest convention. Verified red without the fix by temporarily reintroducing the mint into runResult. ApplicationsStore.cancel/AdminCasesStore.delete (RB-20) and FeatureFlagStore.set are out of scope and untouched — the latter already calls runSubmit correctly. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,7 +20,7 @@ tested where._
|
||||
|
||||
Every bullet below is a real test name from the suite — an `it()` title (frontend) or a test
|
||||
method name (backend), read as a sentence. Nothing here is hand-written prose: this page
|
||||
**is** the suite, reshaped for a business reader. 440 frontend behaviours across
|
||||
**is** the suite, reshaped for a business reader. 445 frontend behaviours across
|
||||
9 contexts; 231 backend behaviours across 39 test
|
||||
classes.
|
||||
|
||||
@@ -800,11 +800,19 @@ classes.
|
||||
|
||||
- leaves an unrelated endpoint untouched
|
||||
|
||||
#### runResult
|
||||
|
||||
- folds a resolved call into ok(value)
|
||||
- maps a ProblemDetails rejection to err(detail)
|
||||
- falls back when the rejection has no detail
|
||||
- mints no Idempotency-Key — the read fold
|
||||
|
||||
#### runSubmit
|
||||
|
||||
- folds a resolved call into ok(value)
|
||||
- maps a ProblemDetails rejection to err(detail)
|
||||
- falls back when the rejection has no detail
|
||||
- mints exactly one Idempotency-Key for the whole call — the write fold
|
||||
|
||||
#### satisfaction helpers
|
||||
|
||||
|
||||
Reference in New Issue
Block a user