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
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Ports (live demo only; Alba self-hosts in tests): before twin `42010`, after twi
Write C# a JasperFx maintainer would recognize. Distilled from the author's `csharp-critter-style` skill (mmo-reconnect) and CritterStackSamples:

- One command + its validator + its endpoint per file, named after the command (`PublishCake.cs`).
- Commands verb-first imperative records (`PublishCake`); events past-tense (`CakePublished`); endpoint classes `<VerbNoun>Endpoint`, static, with static methods.
- Commands verb-first imperative records (`PublishCake`, `NotifyBaker`); events, if any ever exist here, past-tense (`CakePublished`); HTTP response bodies are noun phrases (`PublishedCake`, `PlacedOrder`) so a tuple like `(PlacedOrder, NotifyBaker)` reads as response-plus-command at a glance. **Never suffix a type with a role word such as `Response`, `Request`, `Event`, or `Message`** when it can be avoided; name the type for what it is (Erik's call, 2026-09-05: without the layers, the labels are not needed). Endpoint classes `<VerbNoun>Endpoint`, static, with static methods.
- Marten documents: plain mutable classes with `{ get; set; }`, never records. Commands/queries: positional records.
- Inject `IDocumentSession`/`IQuerySession` as method parameters, not constructors. `IQuerySession` for pure reads.
- File-scoped namespaces, top-level `Program.cs`, Allman braces, `var` when apparent, collection expressions for empty defaults, no `#region`, no primary constructors on handler classes.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public static class PublishCakeEndpoint
}

[WolverinePost("/cakes")]
public static CakePublished Post(PublishCake command, IDocumentSession session)
public static PublishedCake Post(PublishCake command, IDocumentSession session)
{
var cake = new Cake
{
Expand All @@ -160,7 +160,7 @@ public static class PublishCakeEndpoint
// AutoApplyTransactions commits this; no SaveChangesAsync in handlers.
session.Store(cake);

return new CakePublished(cake.Id, cake.Name, cake.Description, cake.Price, cake.PublishedAt);
return new PublishedCake(cake.Id, cake.Name, cake.Description, cake.Price, cake.PublishedAt);
}
}
```
Expand Down
1 change: 1 addition & 0 deletions docs/build-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ Running record of decisions made during build sessions: anything a later session
- **2026-09-05** Critter Stack practices audit against the refreshed JasperFx skills (`docs/critter-stack-audit.md`). Two "act" items shipped this session; the rest are recorded there as discussion items. (1) **The outbox claim was not true.** `NotifyBaker` cascades to a conventional local queue, and local queues are in-memory unless marked durable, so `IntegrateWithWolverine()` + `AutoApplyTransactions()` only gave "hold until commit", not "survives a crash between commit and handler". Added `opts.Policies.UseDurableLocalQueues()` to the after twin's `UseWolverine` block: the envelope is now written in the same Marten transaction as the order and replayed at least once, which is what README, `docs/slices/003`, CLAUDE.md, and the `PlaceOrder.Post` comment already said. `dotnet run -- describe` shows the local queues in `Durable` mode (only Wolverine's own `agents` queue stays buffered). Note for anyone running `wolverine-diagnostics describe-routing` on `NotifyBaker`: it prints "No routes found" because it does not count conventional local routing; the local handler is listed right above and the baker-task scenario proves delivery. (2) **After-twin test fixture now runs in solo mode**: `AfterHostFixture` adds `services.DisableAllExternalWolverineTransports()` and `services.RunWolverineInSoloMode()`, the baseline every JasperFx testing skill uses; no node registration or leader election per sequential host, and stubbing is safe because the twin uses local routing only. Suite 54/54, 0 build warnings. Line counts re-recorded in `docs/file-inventory.md`: after twin 706 raw / 585 non-blank (+7 / +6), before twin unchanged.
- **2026-09-05** Audit Tier B, first pass (B1, B5, B9 from `docs/critter-stack-audit.md`). (B1) `NotifyBakerHandler` is now a pure function: `Handle(NotifyBaker) => Storage.Store(new BakerTask {...})` returning `Store<BakerTask>` (Wolverine.Persistence), no `IDocumentSession`, no await; the transactional middleware executes the upsert after `Handle` returns. Same identity-upsert idempotency, now unit-testable by inspecting the returned value. (B5) New project `tests/LayerCake.Slices.Tests` (xUnit + Shouldly, no Alba, no Testcontainers): 15 facts calling `PlaceOrderEndpoint.Decide`, `PlaceOrderEndpoint.Validate`, `CouponValidation.Evaluate`, and `NotifyBakerHandler.Handle` directly, including a ToEven half-cent rounding case and a `ReferenceEquals(WolverineContinue.NoProblems)` happy-path check. Runs in ~50 ms. Deliberately after-twin-only: the contract suite stays the shared proof, this is the "pure functions, no mocks" exhibit the before twin cannot match. Added to `LayerCake.slnx`; `dotnet test` now runs both projects (15 + 54). (B9) `dotnet list package --include-transitive` on the console shows a real in-process mix: CritterWatch 1.0.1 pulls WolverineFx.Http/.Marten/.Postgresql/.SignalR at 6.29.1 while the direct refs follow the 6.30.0 pin. Tried the skill's remedy (`VersionOverride="6.29.1"` on the console's two direct refs): it unifies every package but does NOT compile, because `ProcessInParallelWithNativeAcks()` from the official 1.0 quickstart is a 6.30 API. Reverted. Conclusion: the 6.29.1/6.30.0 mix is the pairing JasperFx's own quickstart requires; the skill's "must equal the compiled-against version" rule is stricter than their shipped sample. Re-verified live at 6.30.0 with today's changes: console 200 on 42030, zero exceptions in its log, `critterwatch` queue 1 consumer / 0 backlog, `layercake-control` 1 consumer with the console holding a sender to it (it knows the service), after twin 200 on `/ping`, `POST /orders` 201 and the baker task present via the durable local queue and the new handler. `after.wolverine_incoming_envelopes` and friends confirmed present on the compose database. Reasoning recorded as a comment on the console csproj. Suite 54/54 + 15/15, 0 warnings. Line counts: after twin 706 raw / 585 non-blank (unchanged; the handler rewrite is net zero), before twin unchanged.
- **2026-09-05** Audit Tier B, second pass (B3 + B4 from `docs/critter-stack-audit.md`). The flat `Features/` folder is gone: slices now live beside their documents in the bounded-context folders the style skill prefers (`Cakes/` holds `Cake.cs` + `PublishCake.cs`, `BrowseCakes.cs`, `GetCake.cs`; `Coupons/` holds `Coupon.cs` + `CouponValidation.cs`, `ValidateCoupon.cs`; `Orders/` holds `Order.cs`, `BakerTask.cs` + `PlaceOrder.cs`, `NotifyBaker.cs`, `GetOrder.cs`, `GetBakerTasks.cs`), `Ping.cs` sits at the project root with `SeedData.cs` and `Program.cs`, and `NotifyBakerHandler.cs` is renamed `NotifyBaker.cs` after the message it carries (style rule 1). Namespaces follow the folders (`LayerCake.Slices.Cakes` / `.Coupons` / `.Orders`; the `LayerCake.Slices.Features` and `.Features.Coupons` namespaces no longer exist), which made eleven `using` lines redundant and removed them. All moves via `git mv`, so history follows the files. No behaviour change; routes, contract, and file count unchanged. Paths updated in README (tour tree and the PublishCake pointer), `docs/file-inventory.md`, and the three slice specs; `openspec/changes/archive/` left as the historical record it is. Unit-test usings updated. Suite 54/54 + 15/15, 0 warnings. Line counts: after twin 695 raw / 574 non-blank (was 706 / 585; the eleven dropped usings), before twin unchanged.
- **2026-09-05** Audit Tier B, third pass (B2). The two HTTP response records were named like events (`CakePublished`, `OrderPlaced`) while being neither events nor messages; the repo has no events at all (state-stored by design) and exactly one message, the command `NotifyBaker`. Renamed to noun phrases, `PublishedCake` and `PlacedOrder`, so `(PlacedOrder, NotifyBaker)` reads as response-plus-command at a glance and past tense stays reserved for events. The JasperFx sample style (`TodoCreationResponse`) was considered and declined: **Erik's standing rule, now in CLAUDE.md, is no role-word suffixes on type names (`Response`, `Request`, `Event`, `Message`, and the like) when avoidable; without the layers, the labels are not needed.** Rename only: routes, JSON shape, and contract untouched (the contract suite deserializes into its own records and never names these types). README code excerpt updated. A suffix scan of the whole solution found the after twin otherwise clean except `BakerTaskItem` in `GetBakerTasks.cs` (flagged, not changed); the before twin's `Command`/`Query`/`Dto`/`Request` suffixes are the Clean Architecture exhibit and stay by non-negotiable 1; the contract suite's private `CakeItem`/`OrderEnvelope`/`CouponEnvelope`/`BakerTaskItem` records are test-local deserialization shapes. Suite 54/54 + 15/15, 0 warnings. Line counts unchanged (after twin 695 raw / 574 non-blank).
2 changes: 2 additions & 0 deletions docs/critter-stack-audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Each item is a defensible divergence or a judgment call. Listed roughly by how m

**Status 2026-09-05, second pass:** B3 and B4 done. `Features/` is gone; slices live in `Cakes/`, `Coupons/`, `Orders/` beside their documents with matching namespaces, `Ping.cs` at the project root, `NotifyBakerHandler.cs` renamed `NotifyBaker.cs`. Eleven redundant usings dropped (after twin 695 raw / 574 non-blank). B2, B6, B7, B8, B10, B11 remain open.

**Status 2026-09-05, third pass:** B2 done. The two HTTP response records are now noun phrases, `PublishedCake` and `PlacedOrder`, so the past-tense event convention is reserved for events (of which this repo has none; `NotifyBaker` is the only message and it is a command). `Response`/`Request` suffixes were considered and rejected as a standing rule, now in CLAUDE.md. B6, B7, B8, B10, B11 remain open.

### B1. `NotifyBakerHandler` could be a pure function

Current shape injects `IDocumentSession` and calls `session.Store(...)`. The declarative-persistence skill's stated preference for a simple write is a storage-action return:
Expand Down
8 changes: 4 additions & 4 deletions src/after/LayerCake.Slices/Cakes/PublishCake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public record PublishCake(string? Name, string? Description, decimal Price);
/// type write its own status code and Location header, like Wolverine's
/// CreationResponse but without serializing an extra url field into the body.
/// </summary>
public record CakePublished(Guid Id, string Name, string Description, decimal Price, DateTimeOffset PublishedAt)
public record PublishedCake(Guid Id, string Name, string Description, decimal Price, DateTimeOffset PublishedAt)
: IHttpAware
{
public static void PopulateMetadata(MethodInfo method, EndpointBuilder builder)
=> builder.Metadata.Add(new ProducesResponseTypeMetadata(201, typeof(CakePublished), ["application/json"]));
=> builder.Metadata.Add(new ProducesResponseTypeMetadata(201, typeof(PublishedCake), ["application/json"]));

void IHttpAware.Apply(HttpContext context)
{
Expand Down Expand Up @@ -54,7 +54,7 @@ public static async Task<ProblemDetails> ValidateAsync(
}

[WolverinePost("/cakes")]
public static CakePublished Post(PublishCake command, IDocumentSession session)
public static PublishedCake Post(PublishCake command, IDocumentSession session)
{
var cake = new Cake
{
Expand All @@ -68,6 +68,6 @@ public static CakePublished Post(PublishCake command, IDocumentSession session)
// AutoApplyTransactions commits this; no SaveChangesAsync in handlers.
session.Store(cake);

return new CakePublished(cake.Id, cake.Name, cake.Description, cake.Price, cake.PublishedAt);
return new PublishedCake(cake.Id, cake.Name, cake.Description, cake.Price, cake.PublishedAt);
}
}
12 changes: 6 additions & 6 deletions src/after/LayerCake.Slices/Orders/PlaceOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public record PlaceOrderData(IReadOnlyList<Cake> Cakes, Coupon? Coupon);
/// <summary>
/// 201 response for a freshly placed order, mirroring the stored document.
/// IHttpAware writes the status code and Location header itself (same
/// pattern as CakePublished in slice 001).
/// pattern as PublishedCake in slice 001).
/// </summary>
public record OrderPlaced(
public record PlacedOrder(
Guid Id,
List<OrderLine> Lines,
decimal Subtotal,
Expand All @@ -35,11 +35,11 @@ public record OrderPlaced(
string? CouponCode,
DateTimeOffset PlacedAt) : IHttpAware
{
public static OrderPlaced From(Order order)
public static PlacedOrder From(Order order)
=> new(order.Id, order.Lines, order.Subtotal, order.Discount, order.Total, order.CouponCode, order.PlacedAt);

public static void PopulateMetadata(MethodInfo method, EndpointBuilder builder)
=> builder.Metadata.Add(new ProducesResponseTypeMetadata(201, typeof(OrderPlaced), ["application/json"]));
=> builder.Metadata.Add(new ProducesResponseTypeMetadata(201, typeof(PlacedOrder), ["application/json"]));

void IHttpAware.Apply(HttpContext context)
{
Expand Down Expand Up @@ -123,7 +123,7 @@ public static ProblemDetails Validate(PlaceOrder command, PlaceOrderData data)
}

[WolverinePost("/orders")]
public static (OrderPlaced, NotifyBaker) Post(PlaceOrder command, PlaceOrderData data, IDocumentSession session)
public static (PlacedOrder, NotifyBaker) Post(PlaceOrder command, PlaceOrderData data, IDocumentSession session)
{
var order = Decide(command.Lines!, data.Cakes, data.Coupon, DateTimeOffset.UtcNow);

Expand All @@ -135,7 +135,7 @@ public static (OrderPlaced, NotifyBaker) Post(PlaceOrder command, PlaceOrderData
// baker task, no baker task without an order.
var summary = string.Join(", ", order.Lines.Select(l => $"{l.Quantity}x {l.Name}"));

return (OrderPlaced.From(order), new NotifyBaker(order.Id, summary));
return (PlacedOrder.From(order), new NotifyBaker(order.Id, summary));
}

// The whole pricing model, pure: lines + cakes + optional coupon in,
Expand Down