-**Broker and wire (2.x):** embedded Artemis (CORE and OpenWire) with an external-broker switch, in-memory `WireLog`, route-side capture, and a broker plugin that records unconsumed messages.
-**Stores (3.x):** spec store, production and planning inventories, health transitions from `Resource.deriveHealth()`.
-**CatalogEmulator (4.x):** resource-spec and resource catalog queues; writes to placeholder ids are marked.
-**OsomDriver (5.x):** controller and consumer detection (`ControllerRegistry`), production and planning CREATE/UPDATE/DELETE with OSOM's headers, a `dryRun` preview, and `NO_CONSUMER` fail-fast. The request timeout goes on the endpoint URI because the camel-jms starter overrides the component setting.
-**PlanningEmulator (6.x):**`PLANNING.RESOURCE.CREATEORUPDATE` following OSOM's handler, `HealthResolver` (headers, then body, then status), `EstimateParser` (absent vs zero, invalid values kept raw), and `WaitLoopService` (`RUNNING` / `CONVERGED` / `TIMED_OUT`).
-**REST API (7.x):**`ReadApi`, `WriteApi`, typed errors `{code, message}` via `ApiErrors`, and case-insensitive enum parameters.
-**Validation (8.x):**
-`EndToEndIT` runs through REST against `StubGController`.
-`scripts/walkthrough.sh` runs design §10 steps 1 to 6 using only curl.
## Verification
-`mvn -o test`: 104 tests, all passing.
- Live run against the unchanged `gcontroller`, started from its classes with `java @argfile` because its Spring Boot 4.2.0-M2 Maven plugin can't be resolved offline. `scripts/walkthrough.sh` printed **PASS**:
- 10 specs registered, with consumers on all six queues.
- Production create reached UP with 6 `status.*` characteristics.
- Planning create went HELD → UP about 220 ms apart, with creation and operation estimates, and there was no catalog write for the placeholder.
- Planning delete reached GONE with a teardown estimate.
## Decisions
The seven open points are now settled in the plan:
- The model jar is 1.5.0-SNAPSHOT.
- Unconsumed-message detection works with the embedded broker only.
- Side-effect attribution uses the "between request and reply, or targets a placeholder" rule.
- The preview is the `dryRun` flag.
-`initialCharacteristics` holds the "before" values.
-`triggerServiceActionQueue` is recorded only.
- Defaults: 250 ms poll interval, `TIMED_OUT`, 10 s write-back timeout, plain-JS UI.
Changes for .changelog/20261002_2254_contract-checker.md: 34 added lines, 0 removed lines.
Original line number
Diff line number
Diff line
# ContractChecker and contract rules (Phase 2, tasks 9.1–9.4)
## What was done
-**Framework** (`checks/`): `Rule`, `RuleContext`, `ContractChecker`, `ViolationStore`, and the `model/Violation` class.
- The checker subscribes to the EventBus and sends each wire message to the rules once, even when it is merged again later. It also forwards health transitions, wait-loop outcomes and spec writes.
- Time-based rules run on a timer, `harness.checks.tick-interval` (default 250 ms).
- A rule that throws an exception is logged and skipped; the others keep running.
- Each violation links to the wire message that caused it and is published as a `violation` event. Identical findings are recorded only once.
-**Rules** (`checks/rules/`):
| Rule | What it checks |
|---|---|
| `HEALTH_DECLARED` | Every production or planning report carries operationalState and administrativeState, as a header or in the body. `estimateOnly` callbacks are exempt. |
| `REPLY_WELLFORMED` | Replies to CREATE/UPDATE/DELETE are a `Resource` JSON object or null. |
| `SPEC_COMPLETE` | Each spec has a name, category and version, and every characteristic has a valueType. |
| `PLANNING_PROGRESSION` | A planning request that runs out its wait budget is flagged. A create that converged without reporting HELD before UP is flagged. |
| `PLANNING_NO_SIDE_EFFECTS` | No catalog write targets a placeholder id. No catalog write happens while a simulation request is still open (until its reply arrives or the request times out). |
| `ACK_UUID_TARGETED` | Follow-up callbacks for the same service order and resource name use the uuid the harness acknowledged. |
| `ESTIMATE_SHAPE` | Estimate values parse as numbers. Each estimate's phase fits the request (create: creation and operation; update: operation; delete: teardown). No operation estimate is sent unless the request gave an operation window. |
| `PRODUCTION_WRITEBACK` | After a production request, a `CATALOG.*.RESOURCE` write arrives within `checks.writeback-timeout` and the resource ends at UP, UP or GONE. |
-**API changes:**
- New `GET /api/violations?rule=&resourceId=` endpoint (`ChecksApi`).
-`/api/status` now includes `counts.violations`.
-`POST /api/reset` now also clears the checker.
## Verification
-`ContractCheckerTest` (4 tests): a violation is recorded once and linked to its message, duplicates are dropped, filters work, a failing rule does not stop the checker, and reset clears everything.
-`RulesTest` (10 tests): a passing and a failing case for each rule, including the write-back timeout.
-`EndToEndIT`: the production and planning flows against the stub controller now also assert that `/api/violations` is empty.
-`events/EventStream`: one bounded queue (`harness.events.client-queue-size`) and one sender thread per client. A heartbeat is sent first and then every `harness.events.heartbeat` (default 15s). A client that falls behind is sent an `overflow` event (`{dropped, queueSize}`) and disconnected; it never blocks the publisher.
-`GET /api/events?types=a,b` (`api/EventsApi`): `text/event-stream`. The event name is the event type, the id is the event's seq, and the data is the whole `HarnessEvent` as JSON. Heartbeats are sent as the comment `hb`.
- Tests:
-`EventStreamTest`: order, type filter, heartbeats, overflow, close.
-`EventsApiIT`: during a planning create, events arrive in order (PENDING → HELD → UP), the wait loop converges, and the controller queue comes before the callback queue.
## Fault injection (11.x)
-`model/FaultRule`:
-`queue`, `type` (DELAY, ERROR_REPLY, MALFORMED_REPLY, NO_REPLY; parsing ignores case and accepts `-`), `delayMs`, `probability`, `remaining`.
- Read-only `id`, `createdAt`, `hits`.
-`faults/FaultStore`: validates rules and picks one per request.
- Each served route registers its queue, and a rule for any other queue is rejected with `UNKNOWN_QUEUE`.
- Other bad values are rejected with `INVALID_FAULT`.
- The first matching rule that wins its probability roll is applied, and `remaining` is decremented. The rule is removed when `remaining` reaches 0.
-`wire/ServedRouteBuilder` applies the fault before the handler, so faulted requests have no side effects:
-`delayMs` is applied first, if set.
- DELAY: the request is then served normally.
- ERROR_REPLY: the body is `null` and the `X-Harness-Error` header is set.
- MALFORMED_REPLY: the body is truncated JSON.
- NO_REPLY: the exchange is switched to InOnly, so Camel sends no reply and the caller times out.
- The request's wire message gets `fault` = the type (`WireLog.markFault(id, fault)`).
-`FaultInjectionIT`: REST CRUD and validation (unknown queue gives 400 UNKNOWN_QUEUE; unknown type gives 400 BAD_REQUEST). Each fault type is tested on `CATALOG.GET.RESOURCESPEC_BY_ID` through an OpenWire client:
- DELAY: the reply comes back at least 650 ms late.
- ERROR_REPLY: the body is `null`.
- MALFORMED_REPLY: the body is not valid JSON.
- NO_REPLY: the client times out.
- Each test checks the wire `fault` field and that the rule stops after `remaining` uses.
-`DeploymentRequest.waitBudget`: a per-request override of `harness.planning.wait-budget`, used by `settings.waitBudget`.
## Changed
-`EventBus`:
- Every listener now gets events in `seq` order. Events are numbered and queued under a short lock, and one thread drains the queue without holding a lock.
- This fixes intermittent out-of-order ids on the SSE stream seen in `EventsApiIT`.
- Holding a lock while listeners ran would have risked a deadlock with `ContractChecker.tick()`; the drainer avoids that.
- Test `StubGController`:
- New `omitHealthHeaders` switch for the negative path.
- Planning creates now echo `status.nodeCount`.
## Tests
-`ScenarioParserTest` (4 tests):
- The §8 example parses.
- JSON input and durations.
- 19 malformed cases.
-`ScenarioRunnerIT` (6 tests):
- The §8 scenario passes against the stub (regression for 12.4).
- Production action and message steps.
- Failing expectations, each with its message, including a `within` timeout.
-`stopOnFailure` and `fault` steps.
- Async run API, `scenario` events, 404 and 400.
-**12.5 negative path:** with no health headers, the run reports `HEALTH_DECLARED` and `PLANNING_PROGRESSION` violations, the wait loop ends `TIMED_OUT`, and the RunReport is `FAILED`.
- Full suite: 144 tests, 0 failures.
## Not done
- 12.5 asks for one manual repeat against `gcontroller` with `ResourceRepoService.putHealth` disabled. It needs a modified gcontroller build and has not been done.