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:
@@ -63,6 +63,17 @@ export class OrderLoadError extends Error {
|
||||
|
||||
export interface FetchedOrder {
|
||||
commands: OrderCommand[];
|
||||
// Per-command status keyed by cmdId. Populated from the engine's
|
||||
// stored order so a returning player sees the same per-command
|
||||
// verdict (applied / rejected) the previous submission produced —
|
||||
// not a synthetic "applied" derived from the local cache.
|
||||
statuses: Map<string, "applied" | "rejected">;
|
||||
// Per-command engine-formatted error code/message, keyed by cmdId.
|
||||
// Both maps carry an entry for every loaded command; the value is
|
||||
// null when the command was applied (no error). The message lets
|
||||
// the UI surface the rejection reason without a code → text catalog.
|
||||
errorCodes: Map<string, number | null>;
|
||||
errorMessages: Map<string, string | null>;
|
||||
updatedAt: number;
|
||||
}
|
||||
|
||||
@@ -119,7 +130,13 @@ function decodeResponse(payload: Uint8Array): FetchedOrder {
|
||||
const buffer = new ByteBuffer(payload);
|
||||
const response = UserGamesOrderGetResponse.getRootAsUserGamesOrderGetResponse(buffer);
|
||||
if (!response.found()) {
|
||||
return { commands: [], updatedAt: 0 };
|
||||
return {
|
||||
commands: [],
|
||||
statuses: new Map(),
|
||||
errorCodes: new Map(),
|
||||
errorMessages: new Map(),
|
||||
updatedAt: 0,
|
||||
};
|
||||
}
|
||||
const order = response.order();
|
||||
if (order === null) {
|
||||
@@ -130,6 +147,9 @@ function decodeResponse(payload: Uint8Array): FetchedOrder {
|
||||
);
|
||||
}
|
||||
const commands: OrderCommand[] = [];
|
||||
const statuses = new Map<string, "applied" | "rejected">();
|
||||
const errorCodes = new Map<string, number | null>();
|
||||
const errorMessages = new Map<string, string | null>();
|
||||
const length = order.commandsLength();
|
||||
for (let i = 0; i < length; i++) {
|
||||
const item = order.commands(i);
|
||||
@@ -137,9 +157,20 @@ function decodeResponse(payload: Uint8Array): FetchedOrder {
|
||||
const cmd = decodeCommand(item);
|
||||
if (cmd === null) continue;
|
||||
commands.push(cmd);
|
||||
// The engine echoes `cmd_applied = false` only when the order
|
||||
// was rejected per-command; missing / true both mean applied.
|
||||
const applied = item.cmdApplied();
|
||||
statuses.set(cmd.id, applied === false ? "rejected" : "applied");
|
||||
const code = item.cmdErrorCode();
|
||||
errorCodes.set(cmd.id, code === null ? null : Number(code));
|
||||
const msg = item.cmdErrorMessage();
|
||||
errorMessages.set(cmd.id, msg === null ? null : msg);
|
||||
}
|
||||
return {
|
||||
commands,
|
||||
statuses,
|
||||
errorCodes,
|
||||
errorMessages,
|
||||
updatedAt: Number(order.updatedAt()),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user