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
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ WebApi/Controllers/CakesController.cs
WebApi/Filters/ApiExceptionFilterAttribute.cs
```

And in the after twin it is `src/after/LayerCake.Slices/Features/PublishCake.cs`, shown here in full apart from the usings and the 201 response record:
And in the after twin it is `src/after/LayerCake.Slices/Cakes/PublishCake.cs`, shown here in full apart from the usings and the 201 response record:

```csharp
public record PublishCake(string? Name, string? Description, decimal Price);
Expand Down Expand Up @@ -218,9 +218,10 @@ src/
LayerCake.WebApi/ controllers, exception filter, Program.cs (port 42010)
after/
LayerCake.Slices/ the vertical-slice twin (port 42020)
Features/ one file per feature: PublishCake.cs, ValidateCoupon.cs, PlaceOrder.cs, ...
Cakes/ Coupons/ Orders/ Marten documents
SeedData.cs, Program.cs
Cakes/ Cake.cs (the Marten document) plus one file per feature: PublishCake.cs, BrowseCakes.cs, GetCake.cs
Coupons/ Coupon.cs, CouponValidation.cs (THE shared rule), ValidateCoupon.cs
Orders/ Order.cs, BakerTask.cs, PlaceOrder.cs, NotifyBaker.cs, GetOrder.cs, GetBakerTasks.cs
Ping.cs, SeedData.cs, Program.cs
frontend/index.html the static demo page
monitor/LayerCake.CritterWatch/ the optional monitoring console (port 42030)
tests/
Expand Down
1 change: 1 addition & 0 deletions docs/build-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ Running record of decisions made during build sessions: anything a later session
- **2026-09-05** Hardening after the skeptic-review follow-up: the unique index on cake name was invisible to the suite (the 409 scenario passes on the application check alone, so deleting the index on either twin stayed green). Added one shared scenario, `database_refuses_duplicate_cake_name_behind_the_api`: each twin subclass inserts a second "Chocolate Stout" straight through its persistence (before: `LayerCakeDbContext`, after: a Marten lightweight session), and the base class asserts a PostgreSQL unique violation (SQL state 23505) somewhere in the exception chain. Not a concurrency test; the direct insert is a deterministic stand-in for the lost race. Verified it bites: with the Marten `UniqueIndex` line commented out the after twin fails while the before twin passes. Suite 54/54 (27 scenarios x 2). Twin line counts unchanged (1,733 / 699); README scenario counts updated to match.
- **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.
2 changes: 2 additions & 0 deletions docs/critter-stack-audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ Each item is a defensible divergence or a judgment call. Listed roughly by how m

**Status 2026-09-05, first pass:** B1 done (`NotifyBakerHandler` returns `Store<BakerTask>`). B5 done (`tests/LayerCake.Slices.Tests`, 15 facts, no host). B9 checked: the console really does run a 6.29.1/6.30.0 Wolverine mix, but pinning down to 6.29.1 does not compile because the official quickstart's `ProcessInParallelWithNativeAcks()` is a 6.30 API; the mix is what JasperFx's own sample expects, re-verified live, reasoning on the console csproj. B2, B3, B4, B6, B7, B8, B10, B11 remain open. Details in `docs/build-log.md`.

**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.

### 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
20 changes: 11 additions & 9 deletions docs/file-inventory.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ Before twin, scaffold files edited (4):
After twin (5 files created):
- src/after/LayerCake.Slices/Cakes/Cake.cs
- src/after/LayerCake.Slices/Cakes/SeedData.cs (moved to the project root in slice 002; see below)
- src/after/LayerCake.Slices/Features/PublishCake.cs
- src/after/LayerCake.Slices/Features/BrowseCakes.cs
- src/after/LayerCake.Slices/Features/GetCake.cs
- src/after/LayerCake.Slices/Cakes/PublishCake.cs
- src/after/LayerCake.Slices/Cakes/BrowseCakes.cs
- src/after/LayerCake.Slices/Cakes/GetCake.cs

After twin, scaffold files edited (1):
- src/after/LayerCake.Slices/Program.cs (explicit camelCase serialization, seed on startup)
Expand Down Expand Up @@ -86,8 +86,8 @@ Before twin, scaffold files edited (4):

After twin (3 files created):
- src/after/LayerCake.Slices/Coupons/Coupon.cs
- src/after/LayerCake.Slices/Features/Coupons/CouponValidation.cs
- src/after/LayerCake.Slices/Features/ValidateCoupon.cs
- src/after/LayerCake.Slices/Coupons/CouponValidation.cs
- src/after/LayerCake.Slices/Coupons/ValidateCoupon.cs

After twin, files edited (2):
- src/after/LayerCake.Slices/SeedData.cs (moved from Cakes/ to project root and extended: it now seeds two modules)
Expand Down Expand Up @@ -138,10 +138,10 @@ Before twin, scaffold/earlier-slice files edited (6):
After twin (6 files created):
- src/after/LayerCake.Slices/Orders/Order.cs
- src/after/LayerCake.Slices/Orders/BakerTask.cs
- src/after/LayerCake.Slices/Features/PlaceOrder.cs
- src/after/LayerCake.Slices/Features/NotifyBakerHandler.cs
- src/after/LayerCake.Slices/Features/GetOrder.cs
- src/after/LayerCake.Slices/Features/GetBakerTasks.cs
- src/after/LayerCake.Slices/Orders/PlaceOrder.cs
- src/after/LayerCake.Slices/Orders/NotifyBaker.cs
- src/after/LayerCake.Slices/Orders/GetOrder.cs
- src/after/LayerCake.Slices/Orders/GetBakerTasks.cs

After twin, files edited: none.

Expand All @@ -165,3 +165,5 @@ Whole-twin line counts re-run 2026-09-04 (same method): before twin 1,733 (was 1
Whole-twin line counts re-run 2026-09-05 (same method): before twin 1,733 (unchanged), after twin 706 (was 699). After +7: `opts.Policies.UseDurableLocalQueues()` and its comment in `Program.cs`, so the cascaded `NotifyBaker` is a real outbox message (see `docs/critter-stack-audit.md`, A1). Non-blank: before 1,432 (unchanged), after 585 (was 579). Test-fixture change (`TwinHosts.cs`) is outside both counts.

Whole-twin line counts re-run 2026-09-05 after Audit Tier B first pass (same method): after twin 706 raw / 585 non-blank (unchanged; the `NotifyBakerHandler` rewrite to a pure `Store<BakerTask>` return is net zero), before twin 1,733 / 1,432 (unchanged). New project `tests/LayerCake.Slices.Tests` (4 files) is a test project and belongs to neither twin's count.

Whole-twin line counts re-run 2026-09-05 after Audit Tier B second pass (same method): after twin 695 raw / 574 non-blank (was 706 / 585). The -11 is exactly the `using` lines made redundant when the slices moved from `Features/` into `Cakes/`, `Coupons/`, `Orders/` and took those namespaces. The per-slice paths above were rewritten to the new locations in the same change; file count per slice is unchanged. Before twin 1,733 / 1,432 (unchanged).
6 changes: 3 additions & 3 deletions docs/slices/001-publish-browse-cakes.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ When done, append the actual file list and count to `docs/file-inventory.md`.

## After twin — expected shape

- `Features/PublishCake.cs`: `PublishCake` positional record command + static `PublishCakeEndpoint` with `ValidateAsync` (duplicate name → 409 `ProblemDetails`, else `WolverineContinue.NoProblems`) and `[WolverinePost("/cakes")]` returning `CreationResponse`. Marten `IDocumentSession.Store`; `AutoApplyTransactions` commits (never call `SaveChangesAsync`).
- `Features/BrowseCakes.cs`: `[WolverineGet("/cakes")]`, expression-bodied, `IQuerySession`.
- `Features/GetCake.cs`: `[WolverineGet("/cakes/{id}")]` with `[Entity(Required = true)]` for the automatic 404.
- `Cakes/PublishCake.cs`: `PublishCake` positional record command + static `PublishCakeEndpoint` with `ValidateAsync` (duplicate name → 409 `ProblemDetails`, else `WolverineContinue.NoProblems`) and `[WolverinePost("/cakes")]` returning `CreationResponse`. Marten `IDocumentSession.Store`; `AutoApplyTransactions` commits (never call `SaveChangesAsync`).
- `Cakes/BrowseCakes.cs`: `[WolverineGet("/cakes")]`, expression-bodied, `IQuerySession`.
- `Cakes/GetCake.cs`: `[WolverineGet("/cakes/{id}")]` with `[Entity(Required = true)]` for the automatic 404.
- `Cakes/Cake.cs` (or beside the features): Marten document, plain mutable class with `{ get; set; }`, never a record.

Follow the `csharp-critter-style` skill (auto-activates). Show-the-pure-part-first matters for slides: keep the endpoint body free of incidental noise.
Expand Down
4 changes: 2 additions & 2 deletions docs/slices/002-validate-coupon.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ No coupon-definition endpoint. Coupons enter the system via seed data only.

ONE function evaluates a coupon to its status. Two call sites: this endpoint and PlaceOrder's guard chain (003). It must be deliberately, visibly shared, not duplicated and not buried:

- After twin: e.g., `Features/Coupons/CouponValidation.cs`, a small pure static function `(Coupon?, DateTimeOffset now) -> CouponStatus`. The endpoint and the PlaceOrder guard both call it. Pure and clock-parameterized so tests need no time mocking.
- After twin: e.g., `Coupons/CouponValidation.cs`, a small pure static function `(Coupon?, DateTimeOffset now) -> CouponStatus`. The endpoint and the PlaceOrder guard both call it. Pure and clock-parameterized so tests need no time mocking.
- Before twin: the idiomatic equivalent, e.g., a `CouponService`/domain service consulted by both the query handler and (later) the order command handler, behind its interface, with the same status enum.

## Before twin — REQUIRED structure
Expand All @@ -38,7 +38,7 @@ Same earnestness rules as slice 001 (see its anti-shortcut list). Expected eleme

## After twin — expected shape

- `Features/ValidateCoupon.cs`: `[WolverineGet("/coupons/{code}")]`, `IQuerySession`, calls the shared function, returns the envelope record.
- `Coupons/ValidateCoupon.cs`: `[WolverineGet("/coupons/{code}")]`, `IQuerySession`, calls the shared function, returns the envelope record.
- `Coupons/Coupon.cs`: Marten document, mutable class: `Code` (identity, uppercase), `PercentOff`, `StartsAt`, `ExpiresAt`.

## Shared contract scenarios
Expand Down
8 changes: 4 additions & 4 deletions docs/slices/003-place-order.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ Same earnestness rules as slice 001. Expected elements: `Domain/Entities/Order.c

## After twin — expected shape

- `Features/PlaceOrder.cs`: `PlaceOrder` record + static endpoint. Guards as `Validate`/`ValidateAsync` returning `ProblemDetails` / `WolverineContinue.NoProblems`, in the contract's order, reusing `CouponValidation` from 002. The endpoint method stays pure-ish: compute totals (ideally a small pure decide function that slides can show alone), `Store` the `Order` document, and RETURN the `NotifyBaker` message as a cascaded value (tuple with the response). Never send via an injected bus; never `SaveChangesAsync`. The outbox (Marten integration + `AutoApplyTransactions`) makes store-and-send atomic; say so in one comment, because that is the A-Frame beat.
- `Features/NotifyBakerHandler.cs`: `NotifyBaker` record + handler that stores the `BakerTask` document.
- `Features/GetOrder.cs`: `[WolverineGet("/orders/{id}")]` with `[Entity(Required = true)]`.
- `Features/GetBakerTasks.cs`: `IQuerySession` read with the optional filter.
- `Orders/PlaceOrder.cs`: `PlaceOrder` record + static endpoint. Guards as `Validate`/`ValidateAsync` returning `ProblemDetails` / `WolverineContinue.NoProblems`, in the contract's order, reusing `CouponValidation` from 002. The endpoint method stays pure-ish: compute totals (ideally a small pure decide function that slides can show alone), `Store` the `Order` document, and RETURN the `NotifyBaker` message as a cascaded value (tuple with the response). Never send via an injected bus; never `SaveChangesAsync`. The outbox (Marten integration + `AutoApplyTransactions`) makes store-and-send atomic; say so in one comment, because that is the A-Frame beat.
- `Orders/NotifyBaker.cs`: `NotifyBaker` record + handler that stores the `BakerTask` document.
- `Orders/GetOrder.cs`: `[WolverineGet("/orders/{id}")]` with `[Entity(Required = true)]`.
- `Orders/GetBakerTasks.cs`: `IQuerySession` read with the optional filter.
- Documents: `Orders/Order.cs` (+ line type), `Orders/BakerTask.cs`, mutable classes.

## Shared contract scenarios
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using LayerCake.Slices.Cakes;
using Marten;
using Wolverine.Http;

namespace LayerCake.Slices.Features;
namespace LayerCake.Slices.Cakes;

public static class BrowseCakesEndpoint
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using LayerCake.Slices.Cakes;
using Wolverine.Http;
using Wolverine.Persistence;

namespace LayerCake.Slices.Features;
namespace LayerCake.Slices.Cakes;

public static class GetCakeEndpoint
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System.Reflection;
using LayerCake.Slices.Cakes;
using Marten;
using Microsoft.AspNetCore.Http.Metadata;
using Microsoft.AspNetCore.Mvc;
using Wolverine.Http;

namespace LayerCake.Slices.Features;
namespace LayerCake.Slices.Cakes;

public record PublishCake(string? Name, string? Description, decimal Price);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Text.Json.Serialization;
using LayerCake.Slices.Coupons;

namespace LayerCake.Slices.Features.Coupons;
namespace LayerCake.Slices.Coupons;

/// <summary>
/// The four possible answers to "is this coupon any good right now?".
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System.Text.Json.Serialization;
using LayerCake.Slices.Coupons;
using LayerCake.Slices.Features.Coupons;
using Marten;
using Wolverine.Http;

namespace LayerCake.Slices.Features;
namespace LayerCake.Slices.Coupons;

/// <summary>
/// The always-200 discriminated envelope. percentOff appears only when the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using LayerCake.Slices.Orders;
using Marten;
using Wolverine.Http;

namespace LayerCake.Slices.Features;
namespace LayerCake.Slices.Orders;

/// <summary>
/// One item on the bakers' to-do list as the wire sees it (no document id;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using LayerCake.Slices.Orders;
using Wolverine.Http;
using Wolverine.Persistence;

namespace LayerCake.Slices.Features;
namespace LayerCake.Slices.Orders;

public static class GetOrderEndpoint
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using LayerCake.Slices.Orders;
using Wolverine.Persistence;

namespace LayerCake.Slices.Features;
namespace LayerCake.Slices.Orders;

public record NotifyBaker(Guid OrderId, string Summary);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
using System.Text.Json.Serialization;
using LayerCake.Slices.Cakes;
using LayerCake.Slices.Coupons;
using LayerCake.Slices.Features.Coupons;
using LayerCake.Slices.Orders;
using Marten;
using Microsoft.AspNetCore.Http.Metadata;
using Microsoft.AspNetCore.Mvc;
using Wolverine.Http;

namespace LayerCake.Slices.Features;
namespace LayerCake.Slices.Orders;

public record PlaceOrder(List<PlaceOrderLine>? Lines, string? CouponCode);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Wolverine.Http;

namespace LayerCake.Slices.Features;
namespace LayerCake.Slices;

/// <summary>
/// Smoke endpoint from the scaffold, kept on purpose: the suite and the demo
Expand Down
1 change: 0 additions & 1 deletion tests/LayerCake.Slices.Tests/CouponValidationTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using LayerCake.Slices.Coupons;
using LayerCake.Slices.Features.Coupons;
using Shouldly;
using Xunit;

Expand Down
Loading