fix(order): surface rejection reason, keep sync green, hydrate verdicts
Tests · UI / test (push) Has been cancelled
Tests · Go / test (push) Successful in 2m3s
Tests · Go / test (pull_request) Successful in 2m5s
Tests · Integration / integration (pull_request) Successful in 1m44s
Tests · UI / test (pull_request) Failing after 4m28s
Tests · UI / test (push) Has been cancelled
Tests · Go / test (push) Successful in 2m3s
Tests · Go / test (pull_request) Successful in 2m5s
Tests · Integration / integration (pull_request) Successful in 1m44s
Tests · UI / test (pull_request) Failing after 4m28s
Three issues surfaced once the per-command rejection from the previous commit actually reached the UI: 1. Sync banner falsely red. `OrderDraftStore.runSync` flipped `syncStatus = "error"` whenever any command was rejected and advertised a Retry button. A per-command rejection is a player-correctable state — the round trip succeeded, the engine just refused that command — so the retry can't help. Keep `syncStatus = "synced"` on `success`; the red row highlight is the visible cue. 2. Rejection reason missing. Add `cmd_error_message: string` to `CommandItem` in `pkg/schema/fbs/order.fbs` (appended last to preserve existing slot offsets) and regenerate the Go + TS stubs for that one type. Plumb the message through `CommandMeta`, `Controller.applyCommand`'s `m.Result(code, message)` call, the Go transcoder, the UI decoders in `submit.ts` / `order-load.ts`, and the `OrderDraftStore.errorMessages` map. `order-tab.svelte` renders it as an italic danger-coloured line under rejected commands, with new CSS for `.error-reason`. 3. Verdict lost on navigation. `order-load.ts.decodeCommand` never read `cmdApplied`/`cmdErrorCode`, so `hydrateFromServer` fell back to a blanket "applied" status — a previously-rejected command came back green after a lobby → game round trip. Extend the fetch decoder to populate `statuses`/`errorCodes`/ `errorMessages` maps and have `hydrateFromServer` use them. Engine-side persistence already records the verdict on disk — verified against the live `0000/order/<id>.json`. `flatbuffers@25` elides default-int8/int64 fields on write; the Go transcoder force-slots `cmd_applied=false` / `cmd_error_code=0` already, the new test fixtures flip `builder.forceDefaults(true)` to mirror that behaviour so the round trip survives. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -174,11 +174,25 @@ export function recordingClient(
|
||||
* decode a realistic payload without standing up a full mock
|
||||
* gateway.
|
||||
*/
|
||||
/**
|
||||
* FakeFetchStatus carries the per-command result fields the engine
|
||||
* would echo on `user.games.order.get` (cmdApplied / cmdErrorCode /
|
||||
* cmdErrorMessage). The helper omits each set only when the
|
||||
* corresponding pointer is `undefined`, mimicking the engine's
|
||||
* `omitempty` semantics.
|
||||
*/
|
||||
export interface FakeFetchStatus {
|
||||
applied?: boolean;
|
||||
errorCode?: number;
|
||||
errorMessage?: string;
|
||||
}
|
||||
|
||||
export function fakeFetchClient(
|
||||
gameId: string,
|
||||
commands: OrderCommand[],
|
||||
updatedAt: number,
|
||||
found = true,
|
||||
statuses?: Record<string, FakeFetchStatus>,
|
||||
): { client: GalaxyClient } {
|
||||
const client: GalaxyClient = {
|
||||
async executeCommand(messageType: string) {
|
||||
@@ -187,7 +201,7 @@ export function fakeFetchClient(
|
||||
}
|
||||
return {
|
||||
resultCode: "ok",
|
||||
payloadBytes: encodeOrderGet(gameId, commands, updatedAt, found),
|
||||
payloadBytes: encodeOrderGet(gameId, commands, updatedAt, found, statuses ?? {}),
|
||||
};
|
||||
},
|
||||
} as unknown as GalaxyClient;
|
||||
@@ -200,6 +214,10 @@ function encodeApplied(
|
||||
applied: boolean,
|
||||
): Uint8Array {
|
||||
const builder = new Builder(256);
|
||||
// See `encodeOrderGet` — flatbuffers@25 elides `cmd_applied=false`
|
||||
// against its int8 default; mirror the Go transcoder's force-slot
|
||||
// behaviour so the boolean survives the round trip in tests.
|
||||
builder.forceDefaults(true);
|
||||
const itemOffsets = cmdIds.map((id) => {
|
||||
const cmdIdOffset = builder.createString(id);
|
||||
const nameOffset = builder.createString("ignored");
|
||||
@@ -235,8 +253,15 @@ function encodeOrderGet(
|
||||
commands: OrderCommand[],
|
||||
updatedAt: number,
|
||||
found: boolean,
|
||||
statuses: Record<string, FakeFetchStatus>,
|
||||
): Uint8Array {
|
||||
const builder = new Builder(256);
|
||||
// flatbuffers@25 elides fields equal to their generated default; the
|
||||
// Go transcoder works around this via explicit `Slot()` calls.
|
||||
// Mirror that behaviour here so `cmd_applied=false` and
|
||||
// `cmd_error_code=0` round-trip through the helper instead of being
|
||||
// silently dropped.
|
||||
builder.forceDefaults(true);
|
||||
|
||||
let orderOffset = 0;
|
||||
if (found) {
|
||||
@@ -246,6 +271,11 @@ function encodeOrderGet(
|
||||
}
|
||||
const cmdIdOffset = builder.createString(cmd.id);
|
||||
const nameOffset = builder.createString(cmd.name);
|
||||
const status = statuses[cmd.id] ?? {};
|
||||
const errMsgOffset =
|
||||
status.errorMessage !== undefined
|
||||
? builder.createString(status.errorMessage)
|
||||
: 0;
|
||||
const inner = CommandPlanetRename.createCommandPlanetRename(
|
||||
builder,
|
||||
BigInt(cmd.planetNumber),
|
||||
@@ -253,8 +283,17 @@ function encodeOrderGet(
|
||||
);
|
||||
CommandItem.startCommandItem(builder);
|
||||
CommandItem.addCmdId(builder, cmdIdOffset);
|
||||
if (status.applied !== undefined) {
|
||||
CommandItem.addCmdApplied(builder, status.applied);
|
||||
}
|
||||
if (status.errorCode !== undefined) {
|
||||
CommandItem.addCmdErrorCode(builder, BigInt(status.errorCode));
|
||||
}
|
||||
CommandItem.addPayloadType(builder, CommandPayload.CommandPlanetRename);
|
||||
CommandItem.addPayload(builder, inner);
|
||||
if (errMsgOffset !== 0) {
|
||||
CommandItem.addCmdErrorMessage(builder, errMsgOffset);
|
||||
}
|
||||
return CommandItem.endCommandItem(builder);
|
||||
});
|
||||
const commandsVec = UserGamesOrder.createCommandsVector(builder, itemOffsets);
|
||||
|
||||
Reference in New Issue
Block a user