Parity PR 3: the *_api entry points, the policy slice, store cases (#4) #13

Closed
mercurius wants to merge 0 commits from mercurius/4-pr3-entry-points into main
Member

Purpose (feature): phoenix's commands enter through the same *_api entry points as mcl-bookclub's. The LiveView calls them instead of minting ids inline, the plan_party policy lives in its own slice and builds its command first, and every slice has store cases. This is PR 3 of #4, the entry-point, policy and store-case part of gap table H.3. The evoq_command_handler adoption follows in PR 3b, stacked on this one.

Refs #4

What changes (in commit order)

  1. 7f9ed6b, the 9 *_api entry points, one per slice folder, mirroring E's <slice>_api.erl.
    • Each builds the typed command and hands it to the desk.
    • Initiate, register, procure and start mint their id when the params bring none (E mints when the key is absent).
    • admin_live.ex calls them. A blank id field is left out of the params, so the api mints it. The club-name enrichment stays in the admin, as in E's mcl_bookclub_admin.erl:100-108.
    • test/admin_api_test.exs: one store case per entry point, plus empty-params refusals.
  2. 8655afa, the policy slice.
    • on_member_registered_v1_maybe_plan_party/ is its own folder, as in E.
    • It builds PlanPartyV1 before dispatching (E :52-62).
    • It logs a structured map (E :65-67).
    • interested_in/0 reads MemberRegisteredV1.event_type().
    • New store test: the 5th registration plans a party, 4 plan none, and a refused party is logged while the count goes on.
  3. cad2eb3, store cases for member register/unregister, book procure/retire and reading start/finish, the §F rows. Each covers its own stream, a second command refused, the lifecycle guard, an unborn stream refused, and a rejected stream id never reaching the store.

Closes gap rows: §B all 9 "API missing"; §C policy; §F register/unregister, procure/retire, start/finish, policy and admin API entry points.

Not closed here: H.3's "the handlers' dispatch/1 takes the built command and stamps the timestamp" and §B's 9 handler "dispatch shape" rows. They belong to PR 3b (#14).

Where it differs from mcl-bookclub, and why

  1. The api hands the desk a built command, but the desks still take params here, so dispatch/1 runs the struct back through new/1. Every new/1 reads fields by key, so it is accepted. PR 3b makes dispatch/1 take the built command through :evoq_command_handler. Splitting there kept each PR within one review.
  2. The policy store test stops the policy child, and calls handle_event/4 directly. It calls it with registrations dispatched to the real store and read back, instead of starting E's subscription. It stops HostBookclub.Application's own policy child while it runs and restarts it in on_exit. That child hears every registration from every test module, and it would plan parties of its own.
  3. Desks still read state fields directly. PR 2 added no getters.

Checks (msi00, CI image @sha256:8219e637…, at this tip cad2eb3)

  • deps, format --check-formatted, compile --warnings-as-errors, credo --strict, dialyzer: all rc 0
  • mix test: host_bookclub 165, project 7, query 11, phoenix 18, web 7; 0 failures

Mutants killed:

  • an api that no longer mints: 5 AdminApiTest cases
  • the policy planning on the 4th registration: "four registrations plan nothing"
Purpose (feature): phoenix's commands enter through the same `*_api` entry points as mcl-bookclub's. The LiveView calls them instead of minting ids inline, the plan_party policy lives in its own slice and builds its command first, and every slice has store cases. This is PR 3 of #4, the entry-point, policy and store-case part of gap table H.3. The evoq_command_handler adoption follows in PR 3b, stacked on this one. Refs #4 ## What changes (in commit order) 1. **7f9ed6b, the 9 `*_api` entry points**, one per slice folder, mirroring E's `<slice>_api.erl`. - Each builds the typed command and hands it to the desk. - Initiate, register, procure and start mint their id when the params bring none (E mints when the key is absent). - `admin_live.ex` calls them. A blank id field is left out of the params, so the api mints it. The club-name enrichment stays in the admin, as in E's `mcl_bookclub_admin.erl:100-108`. - `test/admin_api_test.exs`: one store case per entry point, plus empty-params refusals. 2. **8655afa, the policy slice.** - `on_member_registered_v1_maybe_plan_party/` is its own folder, as in E. - It builds `PlanPartyV1` before dispatching (E :52-62). - It logs a structured map (E :65-67). - `interested_in/0` reads `MemberRegisteredV1.event_type()`. - New store test: the 5th registration plans a party, 4 plan none, and a refused party is logged while the count goes on. 3. **cad2eb3, store cases** for member register/unregister, book procure/retire and reading start/finish, the §F rows. Each covers its own stream, a second command refused, the lifecycle guard, an unborn stream refused, and a rejected stream id never reaching the store. Closes gap rows: §B all 9 "API missing"; §C policy; §F register/unregister, procure/retire, start/finish, policy and admin API entry points. Not closed here: H.3's "the handlers' `dispatch/1` takes the built command and stamps the timestamp" and §B's 9 handler "dispatch shape" rows. They belong to PR 3b (#14). ## Where it differs from mcl-bookclub, and why 1. **The api hands the desk a built command, but the desks still take params here**, so `dispatch/1` runs the struct back through `new/1`. Every `new/1` reads fields by key, so it is accepted. PR 3b makes `dispatch/1` take the built command through `:evoq_command_handler`. Splitting there kept each PR within one review. 2. **The policy store test stops the policy child, and calls `handle_event/4` directly.** It calls it with registrations dispatched to the real store and read back, instead of starting E's subscription. It stops `HostBookclub.Application`'s own policy child while it runs and restarts it in `on_exit`. That child hears every registration from every test module, and it would plan parties of its own. 3. **Desks still read state fields directly.** PR 2 added no getters. ## Checks (msi00, CI image @sha256:8219e637…, at this tip cad2eb3) - deps, `format --check-formatted`, compile `--warnings-as-errors`, credo `--strict`, dialyzer: all rc 0 - mix test: host_bookclub 165, project 7, query 11, phoenix 18, web 7; 0 failures Mutants killed: - an api that no longer mints: 5 AdminApiTest cases - the policy planning on the 4th registration: "four registrations plan nothing"
Each command slice gets its entry point, as in mcl-bookclub: params in,
the typed command built, the desk's dispatch out. The four that start a
stream (club, member, book, reading) mint the id when the caller brings
none. The LiveView now leaves a blank id out and hands its params to the
entry point, keeping the club-name enrichment in the admin, where the
Erlang admin keeps it. admin_api_test rehearses every task against the
real store.
The policy builds plan_party_v1 before it dispatches and logs a refused
party as a structured report, as mcl-bookclub's does. Its store test
shows the fifth registration plans a party, four plan none, and a
refused party is logged while the count carries on.
Store cases for the member, book and reading slices
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 4s
c4 model / c4-model (pull_request) Successful in 0s
ci / gates (OTP 28.4.3 / Elixir 1.18.4) (pull_request) Successful in 6m18s
c4 model / c4-model-1 (push) Successful in 5s
c4 model / c4-model (push) Successful in 0s
ci / gates (OTP 28.4.3 / Elixir 1.18.4) (push) Successful in 6m3s
cad2eb3948
Ported from mcl-bookclub's register_member, procure_book and
start_reading store tests: each birth on its own stream, the second
birth refused, the self-contained end event, the lifecycle guard, the
unborn refusal, and a rejected stream id that never reaches the store.
Member

Landed by fast-forward: main is cad2eb3948 (from cbe8061c), PASS r=1, CI 6176, 6177. This repository does not allow the manually-merged style, so the PR is closed by hand.

Landed by fast-forward: main is cad2eb3948f4b7e32fdfdfba7917284e2ebb35d8 (from cbe8061c), PASS r=1, CI 6176, 6177. This repository does not allow the manually-merged style, so the PR is closed by hand.
terra closed this pull request 2026-12-01 07:39:50 +00:00
All checks were successful
c4 model / c4-model-1 (pull_request) Successful in 4s
c4 model / c4-model (pull_request) Successful in 0s
ci / gates (OTP 28.4.3 / Elixir 1.18.4) (pull_request) Successful in 6m18s
c4 model / c4-model-1 (push) Successful in 5s
c4 model / c4-model (push) Successful in 0s
ci / gates (OTP 28.4.3 / Elixir 1.18.4) (push) Successful in 6m3s

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
macula-services/mcl-bookclub-phoenix!13
No description provided.