54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { decideChunkRecovery } from "../../src/application/use-cases/decide-chunk-recovery.js";
|
|
|
|
function memoryStorage() {
|
|
/** @type {unknown} */
|
|
let value;
|
|
return /** @type {import("../../src/application/ports/storage-port.js").StoragePort} */ ({
|
|
read: () => ({ ok: /** @type {const} */ (true), value }),
|
|
write: (_key, next) => {
|
|
value = next;
|
|
return { ok: /** @type {const} */ (true) };
|
|
},
|
|
remove: () => ({ ok: /** @type {const} */ (true) }),
|
|
});
|
|
}
|
|
|
|
describe("controlled chunk recovery", () => {
|
|
it("records the release pair before allowing one reload", () => {
|
|
const storage = memoryStorage();
|
|
const input = {
|
|
failureKind: "CHUNK_LOAD_FAILURE",
|
|
manifestLoaded: true,
|
|
currentBuildId: "build-a",
|
|
activeReleaseId: "release-b",
|
|
storage,
|
|
};
|
|
expect(decideChunkRecovery(input)).toEqual({
|
|
action: "reload-once",
|
|
releasePair: "build-a->release-b",
|
|
});
|
|
expect(decideChunkRecovery(input)).toEqual({
|
|
action: "support",
|
|
reason: "reload-already-attempted",
|
|
});
|
|
});
|
|
|
|
it.each([
|
|
[{ failureKind: "SERVER_FAILURE" }, "not-recoverable"],
|
|
[{ manifestLoaded: false }, "manifest-unavailable"],
|
|
[{ activeReleaseId: "build-a" }, "same-release"],
|
|
])("stops when a recovery invariant fails: %#", (override, reason) => {
|
|
const result = decideChunkRecovery({
|
|
failureKind: "DEPLOY_MISMATCH",
|
|
manifestLoaded: true,
|
|
currentBuildId: "build-a",
|
|
activeReleaseId: "release-b",
|
|
storage: memoryStorage(),
|
|
...override,
|
|
});
|
|
expect(result).toEqual({ action: "support", reason });
|
|
});
|
|
});
|