Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ Thumbs.db
## Local environment
*.local.json
.env

## Wolverine codegen output (the after twin runs Dynamic codegen; a `codegen write`
## capture lands here and would be compiled into the project if kept)
src/after/LayerCake.Slices/Internal/Generated/
33 changes: 20 additions & 13 deletions CLAUDE.md

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions LayerCake.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
<Folder Name="/monitor/">
<Project Path="src/monitor/LayerCake.CritterWatch/LayerCake.CritterWatch.csproj" />
</Folder>
<Folder Name="/tendr/">
<Project Path="src/tendr/Tendr/Tendr.csproj" />
</Folder>
<Folder Name="/tests/">
<Project Path="tests/LayerCake.ContractTests/LayerCake.ContractTests.csproj" />
<Project Path="tests/LayerCake.Slices.Tests/LayerCake.Slices.Tests.csproj" />
<Project Path="tests/Tendr.Tests/Tendr.Tests.csproj" />
</Folder>
<Folder Name="/solution items/">
<File Path="README.md" />
Expand All @@ -34,5 +38,6 @@
<File Path="docs/slices/001-publish-browse-cakes.md" />
<File Path="docs/slices/002-validate-coupon.md" />
<File Path="docs/slices/003-place-order.md" />
<File Path="docs/slices/005-pay-with-tendr.md" />
</Folder>
</Solution>
50 changes: 32 additions & 18 deletions README.md

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions docs/build-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,20 @@ Running record of decisions made during build sessions: anything a later session
- **Counts.** Before twin untouched at 2,140 raw / 1,775 non-blank. After twin 844 / 707, up from the Marten twin's 703 / 581. Per-slice file counts for the after twin are unchanged, path for path. Full breakdown, including the file-by-file delta and the DbContext-caller list slide 4.2 needs, in `docs/file-inventory.md` (2026-09-09 section).
- **Two shared test files were edited, both twin bindings and no scenario.** `tests/LayerCake.ContractTests/TwinHosts.cs` (the after fixture wipes tables and re-seeds through the DbContext instead of `CleanAllMartenDataAsync`) and `CakeScenarios.cs` (`AfterTwinCakes.InsertCakeDirectlyAsync` inserts through the DbContext instead of a Marten session). Both files also gained `AfterDb` / `BeforeDb` using-aliases, because both twins now have a type called `LayerCakeDbContext`. No assertion, no scenario name and no abstract member changed; the 27 scenarios are the same 27.
- **For Erik**: (a) the scorecard ratio moves from about 3.0x to about 2.5x and slide 4.4 has to say the new number; (b) slide 4.2's DbContext-caller count is 9 methods in 7 files, or 8 in 6 if seeding is excluded as non-feature code, and the inventory lists both; (c) the `[Transactional]` attribute and the three-line redelivery check on `AddBakerTask` are new honest costs that the Marten version did not pay, and the outbox slide can either own them in a sentence or not mention them; (d) `openspec/specs/` was not touched: no built behaviour changed, the HTTP contract is byte-identical and all 54 scenarios are unchanged, so the archived specs still describe what ships.
- **2026-09-14** **Slice 005, pay with Tendr, built end to end** (change `slice-005-pay-with-tendr`, spec `docs/slices/005-pay-with-tendr.md`, hand-off from the talk side dated the same day). The first v1.1 item after KCDC: both twins authorize an optional card with Tendr, a fake vendor host in `src/tendr/Tendr`, on PlaceOrder's load leg. Decisions made inside the hand-off's fences, and what was verified rather than assumed:
- **Ordering, verified on the generated code.** Wolverine 6.30.0 discovers middleware by the names `Before`, `BeforeAsync`, `Load`, `LoadAsync`, `Validate`, `ValidateAsync` (plus the `After`/`Finally` pairs), read out of `Wolverine.dll`; `AuthorizeAsync` is not one of them, so it carries `[WolverineBefore]`. With that, `codegen preview` shows `POST_orders` calling `LoadAsync`, `Validate(command, data)`, `AuthorizeAsync`, `Validate(payment)`, `Post` in declaration order. The `Validate(Payment?)` overload is found by name. Negative check (reverted): moving the three-guard `Validate` below `AuthorizeAsync` reorders the generated calls the same way and turns `place_order_with_bad_coupon_and_declining_card_returns_422_without_calling_tendr` red on the after twin only.
- **`Post` keeps `PlaceOrder command` as its first parameter**, unused, with a comment. Wolverine.Http takes the request body's type from the endpoint method's own parameters; with `Post(Order, Payment?, LayerCakeDbContext)` nothing reads the body and codegen fails with `UnResolvableVariableException` for `PlaceOrder`. `PlacedOrder.From(order)` keeps its one-argument signature because `Order` now carries a computed `Payment`, which also lets `GetOrder.cs` stay untouched.
- **`opts.CodeGeneration.AlwaysUseServiceLocationFor<TendrClient>()`** in `Program.cs`, inside `UseWolverine`. A typed `HttpClient` is registered by `IHttpClientFactory` as an opaque factory lambda, and Wolverine 6's `ServiceLocationPolicy.NotAllowed` refuses it at codegen (`InvalidServiceLocationException ... 'opaque' lambda factory with the Transient lifetime`). Allow-listing the one type is the documented escape hatch; the global policy is untouched.
- **The after twin's 503 comes from guard four.** Run once before any catch existed, the outage scenario got a bare `500` with an empty body on the after twin (the exception rolls the transaction back and escapes to ASP.NET Core) while the before twin already answered `503`. So `AuthorizeAsync` catches `HttpRequestException` and `TaskCanceledException` and returns a `Payment` with status `unavailable`, and `Validate(Payment?)` maps it to the 503 problem. The before twin gets there the textbook way: the adapter translates to `PaymentUnavailableException`, the filter maps it. Same detail on both: `The payment service did not answer.`
- **The after twin's schema migration dropped `after.orders` on the first live start.** `PaymentStatus` went in as `NOT NULL` with no default, and Weasel (`UseEntityFrameworkCoreWolverineManagedMigrations` + `AddResourceSetupOnStartup`) answered with `DROP TABLE IF EXISTS after.orders CASCADE` and a fresh `CREATE TABLE`. The compose database lost its one after-twin order, the test order from the 2026-09-09 live run (its baker task, cakes and coupons survived). Reproduced in a throwaway `postgres:17` container with the pre-slice table and one row, then fixed with `HasDefaultValue("atPickup")` on the column: Weasel then emits `alter table after.orders add column "PaymentStatus" character varying(20) NOT NULL DEFAULT 'atPickup'`, the row survives and reads back with no `payment`. The before twin never had the problem: its generated migration `AddOrderPayment` adds `PaymentStatus integer NOT NULL DEFAULT 0` and `PaymentAuthorizationId uuid NULL` and nothing else. The compose database's `after.orders` was recreated before the fix, so its column has no database default (Weasel does not add a default to an existing column); harmless for the new code, which always writes the value.
- **Tendr under test: `WebApplicationFactory<TendrApi>` on Kestrel** at `127.0.0.1:0`, the address read from `IServerAddressesFeature`, against the twin collection's own PostgreSQL container (schema `tendr`), so no new container. Three things had to be found. (1) Tendr's `Program.cs` ends in `RunJasperFxCommands`, which only runs the host a test factory built when `JasperFxEnvironment.AutoStartHost` is true; Alba sets it for the twins, so a Tendr started first sat unstarted with no addresses. The fixture sets it. (2) Wolverine and JasperFx each pin the application assembly process-wide to the first Critter Stack host that builds (`WolverineOptions.RememberedApplicationAssembly`, `JasperFxOptions.RememberedApplicationAssembly`, GH-3521), and the pinned assembly joins discovery before `ConfigureWolverine` extensions run, so the after twin tried to map Tendr's `GetAuthorizationEndpoint` and failed with `Could not determine a matching persistence service for entity Tendr.Authorizations.Authorization`. `tests/LayerCake.ContractTests/WolverineHostGate.cs` builds every Wolverine host one at a time with both statics set to its own assembly; the before twin, not a Wolverine host, bypasses it. (3) xUnit 2 collection fixtures cannot take each other, so `TendrHostFixture` is started lazily by the first twin host fixture in the collection. Tendr's data is never reset: every order id, and so every idempotency key, is fresh.
- **New scenarios live in `PaymentScenarios.cs` and `PaymentOutageScenarios.cs`, not `OrderScenarios.cs`.** `tests/LayerCake.ContractTests.Marten` binds `OrderScenarios` to the Marten twin, which has no card path and no Tendr. A separate class keeps every existing scenario file byte-identical and both experiments green without touching them. The declined-card scenario finds the would-be order id as the one new authorization Tendr holds (the idempotency key is the order id), asserts `GET /orders/{that id}` is 404, and watches the baker board for a one-second absence window (the presence polls stay 250 ms / 5 s); a full five-second absence window per scenario would have added seconds to the live run.
- **Before twin additions beyond the hand-off's file list:** `Domain/Enums/PaymentStatus.cs` (a Domain status is an enum, like `CouponStatus`; stored as an integer by convention, `AtPickup` = 0, so `OrderConfiguration.cs` needed no edit) and `Application/Orders/PaymentDto.cs` (its own file, like `OrderLineDto.cs`). `OrdersController` documents 402 and 503 as it already documents 400 and 422. 11 created / 8 edited; 9 created without the two.
- **No package added or bumped.** The before twin's Infrastructure project gains `<FrameworkReference Include="Microsoft.AspNetCore.App" />` for `AddHttpClient`, which is the shared framework, not a package. That made the slice 004 comment in `DependencyInjection.cs` ("the section binder lives in a package this project does not reference") false, so it was reworded; both options classes stay bound by hand.
- **Card data.** Neither twin stores or logs the number: the handler and `AuthorizeAsync` pass it straight to the client, the filter logs only the transport exception, and no pipeline behavior logs requests. Tendr's stored events carry the last four digits only; `tests/Tendr.Tests` asserts the full number is absent from the serialized events.
- **The untracked `src/after/LayerCake.Slices/Internal/Generated/` capture (from the 4.4 slide's `codegen write`) broke the build** the moment `PlaceOrder`'s signature changed, because the project compiles every `.cs` under it. It was moved out of the project (it is regenerable exactly with `codegen write` at `3fb503d`) and the path is now in `.gitignore`. Worth remembering: a kept capture has to live outside the project folder.
- **Results.** Root `dotnet test`: `LayerCake.ContractTests` 70/70 (35 scenarios x 2: the 27 unchanged plus 6 payment and 2 outage), `LayerCake.Slices.Tests` 19/19 (15 unchanged plus 4 guard-four facts), `Tendr.Tests` 19/19 (13 scenarios, 6 test-card cases); 0 build warnings. Wall-clock on this machine: 15.8 s and 16.6 s warm, 28.1 s cold after `dotnet clean`; `main` at `3fb503d` measured the same session on the same machine: 11.1 to 12.1 s warm, 20.1 s cold. So the live moment grows by about 5 s warm. `tests/Tendr.Tests` in the slnx costs one more PostgreSQL container but no measurable wall-clock (15.0 s and 16.9 s with it removed from the slnx). Experiments re-run and undisturbed: Marten 27/27 and 15/15, template 6/10 with the same four reds. Negative check (reverted): removing the decline throw from the before twin's handler turns exactly its two 402 scenarios red.
- **Live run** against the compose stack, the twins on 42010 and 42120 (42020 was occupied, see below) and Tendr on 42040: approved card 201 with `payment` on both twins and on the read-back, one baker task each, Tendr holding 6,120 cents and `4242`; declined card 402 problem+json with `Card declined: card_declined.` on both; Tendr stopped, a card order 503 in 12 to 33 ms on both and an order without a card still 201; a listener that accepts and never answers, 503 after 2.10 s (before) and 2.23 s (after), which is the two-second timeout. The demo page, driven headless: Pay now with `0002` and `9995` shows the 402 detail on both twins, `4242` shows "approved by card", pickup shows "at pickup".
- **Out of scope, noted not changed:** `LayerCake.slnx`'s solution items list `docs/slices/001-003` but not 004 (005 was added with this slice).
- **For Erik**: (a) `Post`'s signature on the slide is `Post(PlaceOrder command, Order order, Payment? payment, LayerCakeDbContext db)`, with the unused command and its comment, not the hand-off's three-parameter form; (b) the after twin pays for the typed client with `[WolverineBefore]` on the rung and `AlwaysUseServiceLocationFor<TendrClient>()` in `Program.cs`, two honest lines a slide can own or skip; (c) on the after twin the EF Core transaction is already open when `AuthorizeAsync` calls Tendr (Wolverine's EF middleware begins it before the first rung), so a connection and transaction are held for up to the two-second timeout, where the before twin opens its transaction only inside `SaveChangesAsync`; changing the transaction mode is a talk-content call and was not tried; (d) hand-off section 1 says `dotnet test` must not grow by a container and section 6 puts `tests/Tendr.Tests` (with its own Testcontainers PostgreSQL) in the slnx; it is in the slnx as section 6 says, it costs a container and no wall-clock, and dropping it from the slnx is one line; (e) the before twin count is 11 / 8 with the enum and the payment DTO, 9 / 8 without; (f) the "no migrations folder" decision of 2026-09-09 has a cost this slice found: a new NOT NULL column needs a database default, or the startup migration drops the table; (g) a `LayerCake.Slices` process started 2026-09-09 12:51 with `dotnet run --no-build --urls http://localhost:42020` is still running on 42020 with pre-slice code; stop it before a live run.
- **2026-09-14** **Slice 005's optional step: Wolverine's HTTP transport, green on the pinned 6.30.0, as its own commit.** Verified before writing code: the `V6.30.0` tag's `docs/guide/http/transport.md` documents inline request/reply (`InvokeAsync<T>` routed to the receiver's `/_wolverine/invoke`, the reply read straight off the HTTP response), and a routed call takes `HttpEndpoint.InvokeRemoteAsync`. What changed: Tendr's `Program.cs` maps `MapWolverineHttpTransportEndpoints()` beside the REST endpoints; `AuthorizeCard.cs` gains `AuthorizeCardHandler`, a thin message handler, because the REST method's header-bound key and `IResult` return do not fit a message. The handler uses the envelope id as the idempotency key and calls the endpoint's `Invalid` and `Start`, which were extracted from `Validate` and `Post` so the rules exist once; Tendr's 13 scenarios stayed green through the refactor. `tests/Tendr.Tests/HttpTransportFacts.cs` holds the one fact: a plain Wolverine sender host with `PublishMessage<AuthorizeCard>().ToHttpEndpoint(...)` calls `InvokeAsync<CardAuthorization>` and gets an approval, and Tendr's own store holds that authorization afterwards; no `HttpClient` call in the test. Three findings: (1) **on 6.30.0 the HTTP transport only resolves `https://` URLs**: `HttpTransport` declares `https` with `http` as an alternate, but `TransportCollection` registers and looks transports up by primary protocol only, so an `http://` endpoint throws `Unknown Transport scheme 'http'`. Wolverine's `insecure_http_uri_4200` test first appears at `V6.34.0`; no bump, so the fact serves its Kestrel Tendr over HTTPS with a self-signed certificate generated in the test and tells the transport's named client (`HttpTransport.HttpClientName`) to accept it, which needs no dev certificate on the machine or in CI. (2) The sender also needs `services.AddWolverineHttp()`, which registers `IWolverineHttpTransportClient`. (3) The sender sets `opts.ApplicationAssembly` explicitly, for the same process-wide pinning reason as the contract suite's gate. Negative check (reverted): commenting out `MapWolverineHttpTransportEndpoints()` turns the fact red with `WolverineRequestReplyException: Inline HTTP request/reply to https://127.0.0.1:.../_wolverine/invoke failed with status code 404`. Root `dotnet test`: 70/70, 19/19, `Tendr.Tests` 20/20, 0 warnings, 14.4 s and 16.0 s warm. Twins untouched (2,405 / 1,000); Tendr is 305 / 251.
Loading