fix(game): #59 — per-command rejection on PUT /api/v1/order
Validation of a player's order now applies every command against a transient game-state snapshot and records the per-command outcome (cmdApplied, cmdErrorCode) in each command's meta. The order is persisted even when some commands are rejected, and the response is 202 + UserGamesOrder so clients can surface the partial failure without the chain collapsing into "downstream service is unavailable". Pkg/error consts are reshelved onto three explicit ranges with a package doc and helpers (IsInternalCode/IsInputCode/IsGameStateCode): 1xxx internal/server (500/501), 2xxx structural input (400), 3xxx game-state per-command rejection (400 when escaping HTTP, otherwise recorded as cmdErrorCode). Two pre-existing typos fixed mechanically (ErrBeakGroupNumberNotEnough -> ErrBreakGroupNumberNotEnough, ErrRaceExinct -> ErrRaceExtinct) along with all callsites. Engine errorResponse maps *GenericError by shelf rather than mapping everything to 500. The Quit-not-last structural check in Controller.ValidateOrder is preserved and its type assertion fixed (was a value assertion against a pointer-typed command, so the check silently never fired). Backend, gateway and UI are unchanged — they were already correct on the 202 path; only the engine collapsing per-command rejection into 500 was needed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -31,7 +31,7 @@ func TestShipClassCreate(t *testing.T) {
|
||||
e.GenericErrorText(e.ErrInputUnknownRace))
|
||||
assert.ErrorContains(t,
|
||||
g.ShipClassCreate(Race_Extinct.Name, "Drone", 1, 0, 0, 0, 0),
|
||||
e.GenericErrorText(e.ErrRaceExinct))
|
||||
e.GenericErrorText(e.ErrRaceExtinct))
|
||||
assert.ErrorContains(t,
|
||||
g.ShipClassCreate(Race_0.Name, BadEntityName, 1, 0, 0, 0, 0),
|
||||
e.GenericErrorText(e.ErrInputEntityTypeNameInvalid))
|
||||
@@ -109,7 +109,7 @@ func TestShipClassMerge(t *testing.T) {
|
||||
e.GenericErrorText(e.ErrInputEntityNotExists))
|
||||
assert.ErrorContains(t,
|
||||
g.ShipClassMerge(Race_Extinct.Name, "Spy", "Drone"),
|
||||
e.GenericErrorText(e.ErrRaceExinct))
|
||||
e.GenericErrorText(e.ErrRaceExtinct))
|
||||
assert.ErrorContains(t,
|
||||
g.ShipClassMerge(Race_0.Name, "Spy", "Spy"),
|
||||
e.GenericErrorText(e.ErrInputEntityTypeNameEquality))
|
||||
@@ -134,7 +134,7 @@ func TestShipClassRemove(t *testing.T) {
|
||||
e.GenericErrorText(e.ErrInputUnknownRace))
|
||||
assert.ErrorContains(t,
|
||||
g.ShipClassRemove(Race_Extinct.Name, Race_0_Freighter),
|
||||
e.GenericErrorText(e.ErrRaceExinct))
|
||||
e.GenericErrorText(e.ErrRaceExtinct))
|
||||
assert.ErrorContains(t,
|
||||
g.ShipClassRemove(Race_0.Name, "Elephant"),
|
||||
e.GenericErrorText(e.ErrInputEntityNotExists))
|
||||
|
||||
Reference in New Issue
Block a user