fix(ui): сохранить snapshot speed при неизвестном исходе записи
This commit is contained in:
1 parent
f408afba20
commit
96fa910804
8 files changed
+57
-4
No files matched your search
@@ -0,0 +1,19 @@
|
||||
import assert from "node:assert/strict"
|
||||
import { test } from "node:test"
|
||||
import { ApiClientError } from "../shared/api/http-client"
|
||||
import { isSpeedPersistenceUnknown } from "./speed-persistence-outcome"
|
||||
|
||||
test("matching unknown persistence receipt preserves the confirmed snapshot", () => {
|
||||
assert.equal(isSpeedPersistenceUnknown(new ApiClientError("unknown", 502, { outcome: "unknown", runId: "current" }), "current"), true)
|
||||
})
|
||||
|
||||
test("other operations, malformed responses and ordinary failures cannot masquerade as unknown persistence", () => {
|
||||
for (const error of [
|
||||
Error("unknown"),
|
||||
new ApiClientError("unknown", 502, { outcome: "unknown", runId: "other" }),
|
||||
new ApiClientError("unknown", 502, { outcome: "unknown" }),
|
||||
new ApiClientError("unknown", 502, { outcome: "failed", runId: "current" }),
|
||||
new ApiClientError("forbidden", 403, { outcome: "unknown", runId: "current" }),
|
||||
new ApiClientError("bad body", 502, null),
|
||||
]) assert.equal(isSpeedPersistenceUnknown(error, "current"), false)
|
||||
})
|
||||
@@ -0,0 +1,9 @@
|
||||
import { ApiClientError } from "@/shared/api/http-client"
|
||||
|
||||
/** Preserve the last confirmed snapshot only for this operation's explicit unknown receipt. */
|
||||
export function isSpeedPersistenceUnknown(error: unknown, runId: string): boolean {
|
||||
if (!(error instanceof ApiClientError) || error.status !== 502) return false
|
||||
if (!error.payload || typeof error.payload !== "object") return false
|
||||
const payload = error.payload as { outcome?: unknown; runId?: unknown }
|
||||
return payload.outcome === "unknown" && payload.runId === runId
|
||||
}
|
||||
Reference in new issue
Block a user