check / check (push) Waiting to run
src/retry.ts exports UNATTENDED_RETRY_OPTIONS beside the unchanged default: 10 attempts, a 1 s base delay and a 60 s cap, so a request that keeps failing waits at most 243 s before it gives up. bin/quak.ts loads the backup's session with them, so its refresh, ML data and downloads all use them; every other command keeps the default. What is retried and the backoff formula are unchanged. Model: opus-5-5
72 lines
2.4 KiB
TypeScript
72 lines
2.4 KiB
TypeScript
/**
|
|
* Tests for the retry options `bin/quak.ts` loads the saved session with:
|
|
* `quak backup` gets the unattended ones, every other command the default.
|
|
*
|
|
* Each test runs `bin/quak.ts`, as the smoke test does, with its session loader
|
|
* replaced by one that records the options it is given and reports no session,
|
|
* so the command stops before it makes any request.
|
|
*/
|
|
|
|
import { mkdtempSync, rmSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { afterAll, afterEach, describe, expect, it, vi } from "vitest";
|
|
import type { ApiClientOptions } from "../../src/api/client.js";
|
|
import { UNATTENDED_RETRY_OPTIONS } from "../../src/retry.js";
|
|
|
|
const loaded = vi.hoisted(() => [] as (ApiClientOptions | undefined)[]);
|
|
|
|
vi.mock("../../src/cli-session.js", () => ({
|
|
loadSession: (_path: string, apiOptions?: ApiClientOptions) => {
|
|
loaded.push(apiOptions);
|
|
return null;
|
|
},
|
|
}));
|
|
|
|
const argv = process.argv;
|
|
const dir = mkdtempSync(join(tmpdir(), "quak-bin-test-"));
|
|
|
|
// Run `quak <args>` to completion. The "Not logged in" message and the exit
|
|
// are swallowed.
|
|
const quak = async (...args: string[]): Promise<void> => {
|
|
vi.spyOn(process.stderr, "write").mockImplementation(() => true);
|
|
vi.spyOn(process, "exit").mockImplementation(() => undefined as never);
|
|
process.argv = ["node", "quak", ...args];
|
|
vi.resetModules();
|
|
await import("../../bin/quak.js");
|
|
};
|
|
|
|
afterEach(() => {
|
|
process.argv = argv;
|
|
loaded.length = 0;
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
afterAll(() => {
|
|
rmSync(dir, { recursive: true, force: true });
|
|
});
|
|
|
|
describe("bin/quak.ts session loading", () => {
|
|
it("loads the session for backup with the unattended retry options", async () => {
|
|
await quak("backup", dir);
|
|
// `vi.resetModules()` gave `bin/quak.ts` its own copy of
|
|
// `src/retry.ts`, whose `sleep` is a different function, so the
|
|
// options are compared by their numbers.
|
|
const { attempts, baseDelayMs, maxDelayMs } = UNATTENDED_RETRY_OPTIONS;
|
|
expect(loaded).toEqual([
|
|
{
|
|
retry: expect.objectContaining({
|
|
attempts,
|
|
baseDelayMs,
|
|
maxDelayMs,
|
|
}),
|
|
},
|
|
]);
|
|
});
|
|
|
|
it("loads the session for another command with the default options", async () => {
|
|
await quak("collections");
|
|
expect(loaded).toEqual([undefined]);
|
|
});
|
|
});
|