chore(cleanup): purge /command residuals — fakeEngine, canon golden, openapi #75

Merged
developer merged 1 commits from feature/post-command-cleanup into development 2026-05-30 17:54:47 +00:00
11 changed files with 67 additions and 63 deletions
+10 -10
View File
@@ -29,8 +29,8 @@ func TestGetBattleValidation(t *testing.T) {
{"Invalid uuid", "0", invalidId, http.StatusBadRequest},
} {
t.Run(tc.description, func(t *testing.T) {
e := &dummyExecutor{}
r := setupRouterExecutor(e)
e := &fakeEngine{}
r := setupRouterEngine(e)
w := httptest.NewRecorder()
path := fmt.Sprintf("/api/v1/battle/%s/%s", tc.turn, tc.battleID)
@@ -81,11 +81,11 @@ func TestGetBattleFound(t *testing.T) {
{Attacker: 0, AttackerShipClass: 10, Defender: 1, DefenderShipClass: 20, Destroyed: true},
},
}
e := &dummyExecutor{
e := &fakeEngine{
FetchBattleResult: stored,
FetchBattleOK: true,
}
r := setupRouterExecutor(e)
r := setupRouterEngine(e)
w := httptest.NewRecorder()
path := fmt.Sprintf("/api/v1/battle/%d/%s", 7, id.String())
@@ -111,11 +111,11 @@ func TestGetBattleFound(t *testing.T) {
func TestGetBattleTurnZero(t *testing.T) {
id := uuid.New()
e := &dummyExecutor{
e := &fakeEngine{
FetchBattleResult: &report.BattleReport{ID: id},
FetchBattleOK: true,
}
r := setupRouterExecutor(e)
r := setupRouterEngine(e)
w := httptest.NewRecorder()
req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/battle/0/%s", id.String()), nil)
@@ -128,8 +128,8 @@ func TestGetBattleTurnZero(t *testing.T) {
func TestGetBattleNotFound(t *testing.T) {
id := uuid.New()
e := &dummyExecutor{FetchBattleOK: false}
r := setupRouterExecutor(e)
e := &fakeEngine{FetchBattleOK: false}
r := setupRouterEngine(e)
w := httptest.NewRecorder()
req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/battle/3/%s", id.String()), nil)
@@ -141,8 +141,8 @@ func TestGetBattleNotFound(t *testing.T) {
}
func TestGetBattleEngineError(t *testing.T) {
e := &dummyExecutor{FetchBattleErr: errors.New("engine boom")}
r := setupRouterExecutor(e)
e := &fakeEngine{FetchBattleErr: errors.New("engine boom")}
r := setupRouterEngine(e)
w := httptest.NewRecorder()
req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/battle/3/%s", uuid.NewString()), nil)
+23 -23
View File
@@ -68,8 +68,8 @@ func TestOrderRaceQuit(t *testing.T) {
payload = &rest.Command{
Actor: commandDefaultActor,
}
exec := &dummyExecutor{}
emptyRouter := setupRouterExecutor(exec)
exec := &fakeEngine{}
emptyRouter := setupRouterEngine(exec)
w = httptest.NewRecorder()
req, _ = http.NewRequest(apiCommandMethod, apiOrderPath, asBody(payload))
@@ -927,8 +927,8 @@ func TestOrderPlanetRouteRemove(t *testing.T) {
}
func TestMultipleCommandOrder(t *testing.T) {
e := newExecutor()
r := setupRouterExecutor(e)
e := newFakeEngine()
r := setupRouterEngine(e)
payload := &rest.Command{
Actor: commandDefaultActor,
@@ -951,11 +951,11 @@ func TestMultipleCommandOrder(t *testing.T) {
assert.Equal(t, commandNoErrorsStatus, w.Code, w.Body)
assert.Equal(t, 2, e.(*dummyExecutor).CommandsExecuted)
assert.Equal(t, 2, e.(*fakeEngine).CommandsExecuted)
}
func TestPutOrderResponseBody(t *testing.T) {
e := &dummyExecutor{
e := &fakeEngine{
ValidateOrderResult: &order.UserGamesOrder{
GameID: uuid.New(),
UpdatedAt: 1700,
@@ -967,7 +967,7 @@ func TestPutOrderResponseBody(t *testing.T) {
},
},
}
r := setupRouterExecutor(e)
r := setupRouterEngine(e)
payload := &rest.Command{
Actor: commandDefaultActor,
@@ -997,8 +997,8 @@ func TestPutOrderResponseBody(t *testing.T) {
}
func TestPutOrderEngineError(t *testing.T) {
e := &dummyExecutor{ValidateOrderErr: errors.New("engine boom")}
r := setupRouterExecutor(e)
e := &fakeEngine{ValidateOrderErr: errors.New("engine boom")}
r := setupRouterEngine(e)
payload := &rest.Command{
Actor: commandDefaultActor,
@@ -1054,8 +1054,8 @@ func TestPutOrderPerCommandRejection(t *testing.T) {
},
},
}
executor := &dummyExecutor{ValidateOrderResult: result}
r := setupRouterExecutor(executor)
executor := &fakeEngine{ValidateOrderResult: result}
r := setupRouterEngine(executor)
payload := &rest.Command{
Actor: commandDefaultActor,
@@ -1112,8 +1112,8 @@ func TestPutOrderPerCommandRejection(t *testing.T) {
// *GenericError on the input shelf, which must map to HTTP 400 with
// the `{"generic_error","code"}` envelope rather than 500.
func TestPutOrderStructuralRejection(t *testing.T) {
executor := &dummyExecutor{ValidateOrderErr: e.NewQuitCommandFollowedByCommandError()}
r := setupRouterExecutor(executor)
executor := &fakeEngine{ValidateOrderErr: e.NewQuitCommandFollowedByCommandError()}
r := setupRouterEngine(executor)
payload := &rest.Command{
Actor: commandDefaultActor,
@@ -1152,8 +1152,8 @@ func TestGetOrderQueryValidation(t *testing.T) {
{"Non-numeric turn", "?player=Race_01&turn=abc", http.StatusBadRequest},
} {
t.Run(tc.description, func(t *testing.T) {
e := &dummyExecutor{}
r := setupRouterExecutor(e)
e := &fakeEngine{}
r := setupRouterEngine(e)
w := httptest.NewRecorder()
req, _ := http.NewRequest(http.MethodGet, apiOrderPath+tc.query, nil)
@@ -1176,11 +1176,11 @@ func TestGetOrderFound(t *testing.T) {
},
},
}
e := &dummyExecutor{
e := &fakeEngine{
FetchOrderResult: stored,
FetchOrderOK: true,
}
r := setupRouterExecutor(e)
r := setupRouterEngine(e)
w := httptest.NewRecorder()
req, _ := http.NewRequest(http.MethodGet, apiOrderPath+"?player=Race_01&turn=3", nil)
@@ -1202,11 +1202,11 @@ func TestGetOrderFound(t *testing.T) {
}
func TestGetOrderTurnDefaultsToZero(t *testing.T) {
e := &dummyExecutor{
e := &fakeEngine{
FetchOrderResult: &order.UserGamesOrder{GameID: uuid.New(), UpdatedAt: 1, Commands: []order.DecodableCommand{}},
FetchOrderOK: true,
}
r := setupRouterExecutor(e)
r := setupRouterEngine(e)
w := httptest.NewRecorder()
req, _ := http.NewRequest(http.MethodGet, apiOrderPath+"?player=Race_01", nil)
@@ -1217,8 +1217,8 @@ func TestGetOrderTurnDefaultsToZero(t *testing.T) {
}
func TestGetOrderNotFound(t *testing.T) {
e := &dummyExecutor{FetchOrderOK: false}
r := setupRouterExecutor(e)
e := &fakeEngine{FetchOrderOK: false}
r := setupRouterEngine(e)
w := httptest.NewRecorder()
req, _ := http.NewRequest(http.MethodGet, apiOrderPath+"?player=Race_01&turn=2", nil)
@@ -1231,8 +1231,8 @@ func TestGetOrderNotFound(t *testing.T) {
}
func TestGetOrderEngineError(t *testing.T) {
e := &dummyExecutor{FetchOrderErr: errors.New("engine boom")}
r := setupRouterExecutor(e)
e := &fakeEngine{FetchOrderErr: errors.New("engine boom")}
r := setupRouterEngine(e)
w := httptest.NewRecorder()
req, _ := http.NewRequest(http.MethodGet, apiOrderPath+"?player=Race_01&turn=0", nil)
+13 -13
View File
@@ -31,7 +31,7 @@ func id() string {
return uuid.New().String()
}
type dummyExecutor struct {
type fakeEngine struct {
CommandsExecuted int
// ValidateOrderResult, when non-nil, is returned from ValidateOrder.
@@ -55,7 +55,7 @@ type dummyExecutor struct {
FetchBattleErr error
}
func (e *dummyExecutor) ValidateOrder(actor string, cmd ...order.DecodableCommand) (*order.UserGamesOrder, error) {
func (e *fakeEngine) ValidateOrder(actor string, cmd ...order.DecodableCommand) (*order.UserGamesOrder, error) {
e.CommandsExecuted = len(cmd)
if e.ValidateOrderErr != nil {
return nil, e.ValidateOrderErr
@@ -70,48 +70,48 @@ func (e *dummyExecutor) ValidateOrder(actor string, cmd ...order.DecodableComman
}, nil
}
func (e *dummyExecutor) FetchOrder(actor string, turn uint) (*order.UserGamesOrder, bool, error) {
func (e *fakeEngine) FetchOrder(actor string, turn uint) (*order.UserGamesOrder, bool, error) {
e.FetchOrderActor = actor
e.FetchOrderTurn = turn
return e.FetchOrderResult, e.FetchOrderOK, e.FetchOrderErr
}
func (e *dummyExecutor) FetchBattle(turn uint, ID uuid.UUID) (*report.BattleReport, bool, error) {
func (e *fakeEngine) FetchBattle(turn uint, ID uuid.UUID) (*report.BattleReport, bool, error) {
e.FetchBattleTurn = turn
e.FetchBattleID = ID
return e.FetchBattleResult, e.FetchBattleOK, e.FetchBattleErr
}
func (e *dummyExecutor) GenerateGame(gameID uuid.UUID, races []string) (game.State, error) {
func (e *fakeEngine) GenerateGame(gameID uuid.UUID, races []string) (game.State, error) {
return game.State{ID: gameID}, nil
}
func (e *dummyExecutor) GenerateTurn() (game.State, error) {
func (e *fakeEngine) GenerateTurn() (game.State, error) {
return game.State{}, nil
}
func (e *dummyExecutor) BanishRace(raceName string) error {
func (e *fakeEngine) BanishRace(raceName string) error {
return nil
}
func (e *dummyExecutor) GameState() (game.State, error) {
func (e *fakeEngine) GameState() (game.State, error) {
return game.State{}, nil
}
func (e *dummyExecutor) LoadReport(actor string, turn uint) (*report.Report, error) {
func (e *fakeEngine) LoadReport(actor string, turn uint) (*report.Report, error) {
return &report.Report{}, nil
}
func setupRouter() *gin.Engine {
return setupRouterExecutor(newExecutor())
return setupRouterEngine(newFakeEngine())
}
func setupRouterExecutor(e handler.Engine) *gin.Engine {
func setupRouterEngine(e handler.Engine) *gin.Engine {
return router.SetupRouter(e)
}
func newExecutor() handler.Engine {
return &dummyExecutor{}
func newFakeEngine() handler.Engine {
return &fakeEngine{}
}
// newService builds a real controller.Service backed by a storage directory,
+9 -6
View File
@@ -436,21 +436,24 @@ components:
CommandRequest:
type: object
description: |
Batch command payload. `actor` identifies the race submitting the commands.
Each element of `cmd` is a polymorphic command object discriminated by the
`@type` field. At least one command is required.
Order payload for `PUT /api/v1/order`. `actor` identifies the race
submitting the order. Each element of `cmd` is a polymorphic command
object discriminated by the `@type` field. An empty `cmd` array is
valid: it clears the player's stored order for the turn (equivalent to
removing every command).
required:
- actor
- cmd
properties:
actor:
type: string
description: Race name of the actor submitting the commands. Must be non-blank.
description: Race name of the actor submitting the order. Must be non-blank.
minLength: 1
cmd:
type: array
description: One or more commands to execute in order.
minItems: 1
description: >-
The player's commands, applied in submission order at turn
generation. May be empty to clear the stored order.
items:
$ref: "#/components/schemas/Command"
UserGamesOrder:
+2 -1
View File
@@ -275,7 +275,8 @@ func TestGameOpenAPISpecFreezesCommandRequest(t *testing.T) {
cmdSchema := schema.Value.Properties["cmd"]
require.NotNil(t, cmdSchema, "CommandRequest.cmd schema must exist")
require.Equal(t, uint64(1), cmdSchema.Value.MinItems, "CommandRequest.cmd minItems must be 1")
require.Zero(t, cmdSchema.Value.MinItems,
"CommandRequest.cmd must allow an empty batch — an empty order clears the player's stored order")
}
func TestGameOpenAPISpecFreezesGetBattleOperation(t *testing.T) {
+2 -2
View File
@@ -469,7 +469,7 @@ Acceptance criteria:
- canonical-bytes output matches gateway-side output byte-for-byte
for the three Phase-3 message types (`user.account.get`,
`lobby.my.games.list`, `user.games.command`);
`lobby.my.games.list`, `user.games.order`);
- a request signed by `ui/core` is accepted by the gateway's own
verifier in a unit test (`TestParityRequestSignedByUICoreAcceptedByGateway`);
- a response signed by `gateway/authn`'s `Ed25519ResponseSigner` is
@@ -648,7 +648,7 @@ Acceptance criteria (met):
KB measured);
- `WasmCore.signRequest` produces canonical bytes byte-for-byte
identical to the gateway-side fixtures for three message types
(`request_user_account_get`, `request_user_games_command`,
(`request_user_account_get`, `request_user_games_order`,
`request_lobby_my_games_list`);
- `WasmCore` exposes the same `Core` TypeScript types future
`WailsCore` and `CapacitorCore` adapters will satisfy.
+1 -1
View File
@@ -130,7 +130,7 @@ The `canon` test suite combines:
- byte-equality on golden JSON fixtures under
`canon/testdata/` for three request types
(`user.account.get`, `lobby.my.games.list`,
`user.games.command`), one response (`ok`), and one event
`user.games.order`), one response (`ok`), and one event
(`gateway.server_time`);
- mutation tests proving every signed field is bound into the
signature;
+2 -2
View File
@@ -71,7 +71,7 @@ func TestBuildRequestSigningInputChangesWhenSignedFieldChanges(t *testing.T) {
base := canon.RequestSigningFields{
ProtocolVersion: "v1",
DeviceSessionID: "device-session-123",
MessageType: "user.games.command",
MessageType: "user.games.order",
TimestampMS: 123456789,
RequestID: "request-123",
PayloadHash: sha256Sum([]byte("payload")),
@@ -143,7 +143,7 @@ func TestRequestCanonicalBytesFixtures(t *testing.T) {
fixtures := []string{
"request_user_account_get.json",
"request_lobby_my_games_list.json",
"request_user_games_command.json",
"request_user_games_order.json",
}
for _, name := range fixtures {
+1 -1
View File
@@ -22,7 +22,7 @@ func TestVerifyRequestSignature(t *testing.T) {
fields := canon.RequestSigningFields{
ProtocolVersion: "v1",
DeviceSessionID: "device-session-123",
MessageType: "user.games.command",
MessageType: "user.games.order",
TimestampMS: 123456789,
RequestID: "request-123",
PayloadHash: sha256Sum([]byte("payload")),
@@ -1,13 +1,13 @@
{
"message_type": "user.games.command",
"message_type": "user.games.order",
"protocol_version": "v1",
"device_session_id": "device-session-1",
"timestamp_ms": 1700000001000,
"request_id": "req-games-1",
"payload": "games-payload",
"payload_hash_hex": "a8322c99bf424939cd3a1e5a41b5edb67e567bff87c49e8ff229be60976960e0",
"expected_canonical_bytes_hex": "1167616c6178792d726571756573742d7631027631106465766963652d73657373696f6e2d3112757365722e67616d65732e636f6d6d616e640000018bcfe56be80b7265712d67616d65732d3120a8322c99bf424939cd3a1e5a41b5edb67e567bff87c49e8ff229be60976960e0",
"expected_canonical_bytes_hex": "1167616c6178792d726571756573742d7631027631106465766963652d73657373696f6e2d3110757365722e67616d65732e6f726465720000018bcfe56be80b7265712d67616d65732d3120a8322c99bf424939cd3a1e5a41b5edb67e567bff87c49e8ff229be60976960e0",
"private_key_seed_hex": "0303030303030303030303030303030303030303030303030303030303030303",
"public_key_base64": "7UkoxijRwsbq6QM4kFmVYSlZJzpcY/k2NsFGFKyHN9E=",
"expected_signature_hex": "262d5480451560d9b2ca96468b0e962e4288eabb4dff29dbc66c491a37dd92b779d2b89853083a695317f8535e49c402dcfd49a11fd2926f3af42ceb745e2b0a"
"expected_signature_hex": "b4a9a1eb2eb67777469d87ed7c513afd89f0c0a96ca9e0d945cd327830c11a7834ac073f6a872d8121cd7674b9491399a0256210292615bd424d11d0db37200c"
}
@@ -79,7 +79,7 @@ beforeAll(async () => {
describe("WasmCore canon parity with gateway fixtures", () => {
test.each([
"request_user_account_get.json",
"request_user_games_command.json",
"request_user_games_order.json",
"request_lobby_my_games_list.json",
])("%s — canonical bytes byte-for-byte equal", (name) => {
const fixture = readJson<RequestFixture>(name);