You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by da...@apache.org on 2026/06/04 22:46:34 UTC
(causeway) 15/42: CAUSEWAY-4010: archives command import rework and proposes replay result mapping
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch CAUSEWAY-4010
in repository https://gitbox.apache.org/repos/asf/causeway.git
commit 988db33cfaefe0a3bc2b7f602e1c0bec08dfd0d8
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Thu Jun 4 14:30:01 2026 +0100
CAUSEWAY-4010: archives command import rework and proposes replay result mapping
---
.../.openspec.yaml | 0
.../design.md | 0
.../proposal.md | 0
.../specs/command-export-yaml-result/spec.md | 0
.../tasks.md | 0
.../.openspec.yaml | 0
.../changes/notify-replay-result-mapping/design.md | 50 ++++++++++++++++++++++
.../notify-replay-result-mapping/proposal.md | 28 ++++++++++++
.../specs/command-replay-result-mapping/spec.md | 39 +++++++++++++++++
.../changes/notify-replay-result-mapping/tasks.md | 21 +++++++++
openspec/specs/command-export-yaml-result/spec.md | 32 +++++++++++---
11 files changed, 165 insertions(+), 5 deletions(-)
diff --git a/openspec/changes/rework-command-import-manager/.openspec.yaml b/openspec/changes/archive/2026-06-04-rework-command-import-manager/.openspec.yaml
similarity index 100%
copy from openspec/changes/rework-command-import-manager/.openspec.yaml
copy to openspec/changes/archive/2026-06-04-rework-command-import-manager/.openspec.yaml
diff --git a/openspec/changes/rework-command-import-manager/design.md b/openspec/changes/archive/2026-06-04-rework-command-import-manager/design.md
similarity index 100%
rename from openspec/changes/rework-command-import-manager/design.md
rename to openspec/changes/archive/2026-06-04-rework-command-import-manager/design.md
diff --git a/openspec/changes/rework-command-import-manager/proposal.md b/openspec/changes/archive/2026-06-04-rework-command-import-manager/proposal.md
similarity index 100%
rename from openspec/changes/rework-command-import-manager/proposal.md
rename to openspec/changes/archive/2026-06-04-rework-command-import-manager/proposal.md
diff --git a/openspec/changes/rework-command-import-manager/specs/command-export-yaml-result/spec.md b/openspec/changes/archive/2026-06-04-rework-command-import-manager/specs/command-export-yaml-result/spec.md
similarity index 100%
rename from openspec/changes/rework-command-import-manager/specs/command-export-yaml-result/spec.md
rename to openspec/changes/archive/2026-06-04-rework-command-import-manager/specs/command-export-yaml-result/spec.md
diff --git a/openspec/changes/rework-command-import-manager/tasks.md b/openspec/changes/archive/2026-06-04-rework-command-import-manager/tasks.md
similarity index 100%
rename from openspec/changes/rework-command-import-manager/tasks.md
rename to openspec/changes/archive/2026-06-04-rework-command-import-manager/tasks.md
diff --git a/openspec/changes/rework-command-import-manager/.openspec.yaml b/openspec/changes/notify-replay-result-mapping/.openspec.yaml
similarity index 100%
rename from openspec/changes/rework-command-import-manager/.openspec.yaml
rename to openspec/changes/notify-replay-result-mapping/.openspec.yaml
diff --git a/openspec/changes/notify-replay-result-mapping/design.md b/openspec/changes/notify-replay-result-mapping/design.md
new file mode 100644
index 00000000000..f095286dd6e
--- /dev/null
+++ b/openspec/changes/notify-replay-result-mapping/design.md
@@ -0,0 +1,50 @@
+## Context
+
+Command replay imports can now store the recorded returned object bookmark on the replay `CommandLogEntry`.
+During replay, `CommandExecutorService#executeCommand(...)` returns the actual result bookmark produced by executing the command in the target environment.
+
+Those bookmarks can differ when replay creates a new object or resolves to an environment-specific instance.
+Applications that maintain cross-environment references need a supported SPI to observe the mapping from the recorded bookmark to the actual bookmark.
+
+## Goals / Non-Goals
+
+**Goals:**
+
+- Introduce a public SPI for replay result mapping notifications.
+- Notify the SPI after successful replay when both recorded and actual result bookmarks are known.
+- Pass bookmarks as bookmark values and avoid resolving domain objects inside the replay infrastructure.
+- Keep replay state handling and existing replay success behavior intact.
+
+**Non-Goals:**
+
+- Do not persist a generic mapping table in the command log extension.
+- Do not transform future replay commands using mappings in this change.
+- Do not require applications to implement the SPI.
+- Do not notify the SPI for failed replay attempts.
+
+## Decisions
+
+- Add an SPI interface in the command log applib replay package or an adjacent SPI package.
+ The SPI should expose a method such as `onReplayResultMapped(Bookmark recordedResult, Bookmark actualResult, CommandLogEntry commandLogEntry)` or an equivalent event object.
+ Alternative considered: publish a domain event, but an SPI is clearer for application services that need deterministic post-replay callbacks.
+
+- Invoke the SPI from `ReplayableCommand` after replay execution succeeds and before or during the existing replay success handling transaction.
+ This location already has access to the imported command log entry and the actual bookmark returned by `CommandExecutorService`.
+ Alternative considered: hook into `CommandLogEntry` persistence, but that layer cannot distinguish imported recorded results from actual replay results without additional context.
+
+- Only notify when both recorded and actual bookmarks are non-null.
+ The mapping is only meaningful when there is a recorded returned object and replay produced an actual returned object.
+ Alternative considered: notify for null values as well, but that pushes non-mapping cases onto every application implementation.
+
+- Allow notification when the recorded and actual bookmarks are equal.
+ Equality can be useful for auditing and keeps the SPI semantics simple: successful replay produced a known pair.
+ Alternative considered: suppress equal pairs, but that hides successful correlation from applications that want a complete replay result stream.
+
+- Provide a no-op default implementation if module registration requires a concrete bean.
+ This keeps the extension opt-in for applications and avoids changing behavior when no application SPI is present.
+
+## Risks / Trade-offs
+
+- [Risk] SPI exceptions could interfere with replay success state updates → Catch and record SPI failures as replay failures only if the implementation policy explicitly requires it; otherwise log and keep replay success behavior stable.
+- [Risk] Applications may expect bookmarks to resolve to objects → Document that the SPI receives bookmarks only and object lookup is the application's responsibility.
+- [Risk] Multiple SPI implementations may exist → Invoke all discovered implementations in a deterministic order if the framework supplies a list, or document single-bean semantics if only one service is injected.
diff --git a/openspec/changes/notify-replay-result-mapping/proposal.md b/openspec/changes/notify-replay-result-mapping/proposal.md
new file mode 100644
index 00000000000..1896d1623ab
--- /dev/null
+++ b/openspec/changes/notify-replay-result-mapping/proposal.md
@@ -0,0 +1,28 @@
+## Why
+
+Command replay can legitimately create a different domain object than the object recorded during export/import.
+Applications need an explicit extension point so they can learn that the recorded result bookmark, such as `demoInvoice:1`, now corresponds to the actual replay result bookmark, such as `demoInvoice:2`.
+
+## What Changes
+
+- Add an SPI that is invoked after a successful command replay when both recorded and actual result bookmarks are available.
+- Provide the SPI with the recorded returned object bookmark from the imported `CommandLogEntry` and the actual bookmark returned by replay execution.
+- Invoke the SPI only after replay succeeds, and avoid invoking it for failed replay attempts.
+- Do not require either bookmark to resolve to a live domain object before notifying the SPI.
+
+## Capabilities
+
+### New Capabilities
+
+- `command-replay-result-mapping`: Allows applications to observe mappings from recorded replay result bookmarks to actual replay result bookmarks.
+
+### Modified Capabilities
+
+- None.
+
+## Impact
+
+- Affects command replay success handling in `ReplayableCommand`.
+- Adds a command log replay SPI type for application-provided mapping handlers.
+- Adds module registration for the default/no-op SPI implementation if required.
+- Adds tests for SPI invocation, non-invocation, and bookmark values.
diff --git a/openspec/changes/notify-replay-result-mapping/specs/command-replay-result-mapping/spec.md b/openspec/changes/notify-replay-result-mapping/specs/command-replay-result-mapping/spec.md
new file mode 100644
index 00000000000..97ff0ea95cc
--- /dev/null
+++ b/openspec/changes/notify-replay-result-mapping/specs/command-replay-result-mapping/spec.md
@@ -0,0 +1,39 @@
+## ADDED Requirements
+
+### Requirement: Replay result mapping SPI is notified after successful replay
+The system SHALL provide an SPI that applications can implement to receive replay result bookmark mappings.
+After a command replay succeeds, the system SHALL notify the SPI when the imported command log entry has a recorded returned object bookmark and replay execution returns an actual result bookmark.
+The notification SHALL include the recorded returned object bookmark and the actual replay result bookmark.
+
+#### Scenario: Successful replay produces a different result bookmark
+- **WHEN** command replay succeeds for an imported command whose recorded result bookmark is `demoInvoice:1`
+- **AND** replay execution returns actual result bookmark `demoInvoice:2`
+- **THEN** the system notifies the replay result mapping SPI with recorded bookmark `demoInvoice:1` and actual bookmark `demoInvoice:2`
+
+#### Scenario: Successful replay produces the same result bookmark
+- **WHEN** command replay succeeds for an imported command whose recorded result bookmark is `demoInvoice:1`
+- **AND** replay execution returns actual result bookmark `demoInvoice:1`
+- **THEN** the system notifies the replay result mapping SPI with recorded bookmark `demoInvoice:1` and actual bookmark `demoInvoice:1`
+
+### Requirement: Replay result mapping SPI is not notified when mapping data is unavailable
+The system MUST NOT notify the replay result mapping SPI unless replay succeeds and both recorded and actual result bookmarks are available.
+
+#### Scenario: Replay fails
+- **WHEN** command replay fails for an imported command whose recorded result bookmark is available
+- **THEN** the system does not notify the replay result mapping SPI
+
+#### Scenario: Recorded result is absent
+- **WHEN** command replay succeeds for an imported command whose recorded result bookmark is absent
+- **THEN** the system does not notify the replay result mapping SPI
+
+#### Scenario: Actual result is absent
+- **WHEN** command replay succeeds for an imported command whose recorded result bookmark is available
+- **AND** replay execution does not return an actual result bookmark
+- **THEN** the system does not notify the replay result mapping SPI
+
+### Requirement: Replay result mapping SPI uses bookmarks without resolving objects
+The system SHALL pass recorded and actual result bookmarks to the replay result mapping SPI without requiring those bookmarks to resolve to live domain objects.
+
+#### Scenario: Recorded object is not resolvable
+- **WHEN** command replay succeeds and the recorded result bookmark does not resolve to a local domain object
+- **THEN** the system can still notify the replay result mapping SPI with the recorded bookmark and actual bookmark
diff --git a/openspec/changes/notify-replay-result-mapping/tasks.md b/openspec/changes/notify-replay-result-mapping/tasks.md
new file mode 100644
index 00000000000..7fbd7e328a3
--- /dev/null
+++ b/openspec/changes/notify-replay-result-mapping/tasks.md
@@ -0,0 +1,21 @@
+## 1. SPI Definition
+
+- [ ] 1.1 Add a replay result mapping SPI interface that accepts the recorded result bookmark, actual result bookmark, and replayed `CommandLogEntry` context.
+- [ ] 1.2 Add a no-op/default SPI implementation or optional injection strategy so replay works when applications do not provide an implementation.
+- [ ] 1.3 Register the SPI or default implementation with the command log applib module if required.
+
+## 2. Replay Integration
+
+- [ ] 2.1 Update `ReplayableCommand#tryReplay` success handling to retain the actual replay result bookmark.
+- [ ] 2.2 Read the recorded result bookmark from the imported replay `CommandLogEntry`.
+- [ ] 2.3 Notify the SPI after successful replay when both recorded and actual result bookmarks are non-null.
+- [ ] 2.4 Do not notify the SPI for failed replay attempts, missing recorded bookmarks, or missing actual bookmarks.
+- [ ] 2.5 Keep existing replay state and analysis updates unchanged.
+
+## 3. Tests
+
+- [ ] 3.1 Add tests that a successful replay with different recorded and actual result bookmarks notifies the SPI with both values.
+- [ ] 3.2 Add tests that a successful replay with equal recorded and actual result bookmarks still notifies the SPI.
+- [ ] 3.3 Add tests that failed replay attempts do not notify the SPI.
+- [ ] 3.4 Add tests that missing recorded or actual result bookmarks do not notify the SPI.
+- [ ] 3.5 Run focused command replay tests.
diff --git a/openspec/specs/command-export-yaml-result/spec.md b/openspec/specs/command-export-yaml-result/spec.md
index 3ef77f38469..b1c0cb24bc1 100644
--- a/openspec/specs/command-export-yaml-result/spec.md
+++ b/openspec/specs/command-export-yaml-result/spec.md
@@ -1,4 +1,8 @@
-## ADDED Requirements
+## Purpose
+
+Define command export YAML and replay import compatibility for command DTOs and returned object metadata.
+
+## Requirements
### Requirement: Exported command YAML includes returned object metadata
The system SHALL include returned object metadata for each exported command whose underlying `CommandLogEntry` has a non-null returned object bookmark.
@@ -14,12 +18,30 @@ The returned object metadata SHALL contain `logicalTypeName` and `id` fields der
### Requirement: Exported command YAML remains replay compatible
The system SHALL preserve the command DTO data required by command replay import when adding returned object metadata to exported YAML.
-Existing YAML exports that contain only command DTO data MUST remain importable.
+Command replay import SHALL first attempt to read the input as a multi-document stream of `CommandExportDto` values.
+If that fails, command replay import SHALL fall back to reading the input as a multi-document stream of `CommandDto` values.
+Command replay import MUST NOT support a single YAML list of `CommandDto` values.
-#### Scenario: Import legacy command DTO YAML
-- **WHEN** command replay import receives a YAML file using the legacy command DTO-only export shape
+#### Scenario: Import legacy multi-document command DTO YAML
+- **WHEN** command replay import receives a YAML file using the legacy multi-document `CommandDto` export shape
- **THEN** the system imports the command DTOs as before
#### Scenario: Import YAML with returned object metadata
- **WHEN** command replay import receives a YAML file generated with returned object metadata
-- **THEN** the system imports the command DTOs needed for replay and does not require the returned object metadata to resolve to an object
+- **THEN** the system imports the command DTOs needed for replay and stores the returned object metadata as the corresponding command log result when present
+
+#### Scenario: Reject command DTO list YAML
+- **WHEN** command replay import receives a YAML file containing a single list of `CommandDto` values
+- **THEN** the system rejects the import instead of importing the list entries
+
+### Requirement: Imported command export YAML stores returned object result
+The system SHALL store returned object metadata from each imported `CommandExportDto` as the result bookmark of the corresponding replay `CommandLogEntry`.
+The system MUST NOT require the returned object bookmark to resolve to an existing domain object during import.
+
+#### Scenario: Import command export with returned object
+- **WHEN** command replay import receives a multi-document YAML file containing a `CommandExportDto` whose `returnedObject` has `logicalTypeName` and `id`
+- **THEN** the system persists the embedded command DTO for replay and sets the created `CommandLogEntry` result bookmark from that returned object metadata
+
+#### Scenario: Import command export without returned object
+- **WHEN** command replay import receives a multi-document YAML file containing a `CommandExportDto` without `returnedObject`
+- **THEN** the system persists the embedded command DTO for replay and leaves the created `CommandLogEntry` result bookmark unset