Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017eEAG8HD3mm8gsKXgk8uU8
52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
// Warmup is scheduled after the save returns. It does not wait for the engine.
|
|
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import { consultWarmBodyFromColumns, scheduleConsultPacketWarm } from "../src/lib/consult-packet-warm.ts";
|
|
|
|
const columns = {
|
|
birth_date: "1901-01-01",
|
|
reported_birth_time: "12:30",
|
|
latitude: 1,
|
|
longitude: 2,
|
|
timezone_offset: 8,
|
|
ayanamsa: "raman",
|
|
};
|
|
|
|
test("a saved chart becomes a warm request and the caller does not wait", () => {
|
|
const body = consultWarmBodyFromColumns(columns);
|
|
assert.equal(body?.consult_card_warm_only, true);
|
|
assert.equal(body?.minute, 30);
|
|
assert.equal(consultWarmBodyFromColumns({ birth_date: "1901-01-01" }), null);
|
|
let started = false;
|
|
const finished = false;
|
|
const pending = new Promise<Response>(() => {});
|
|
const scheduled = scheduleConsultPacketWarm(columns, {
|
|
after: (task) => { void task(); },
|
|
fetch: () => {
|
|
started = true;
|
|
return pending;
|
|
},
|
|
apiBase: "http://127.0.0.1:9",
|
|
});
|
|
assert.equal(scheduled, true);
|
|
assert.equal(started, true);
|
|
assert.equal(finished, false);
|
|
});
|
|
|
|
test("a warm that cannot be scheduled does not break the save (BUG-1305)", () => {
|
|
// Default deps use Next `after`, which throws outside a request scope.
|
|
assert.equal(scheduleConsultPacketWarm(columns), false);
|
|
let fetched = false;
|
|
const scheduled = scheduleConsultPacketWarm(columns, {
|
|
after: () => { throw new Error("outside a request scope"); },
|
|
fetch: () => {
|
|
fetched = true;
|
|
return Promise.resolve(new Response(null));
|
|
},
|
|
apiBase: "http://127.0.0.1:9",
|
|
});
|
|
assert.equal(scheduled, false);
|
|
assert.equal(fetched, false);
|
|
});
|