5cb70d702b
- Session sync leaves a transcript alone while hooks feed its session live (active, newest event a hook's, touched within DASHBOARD_SYNC_LIVE_HOOK_MS, default 5 min) and catches it up once quiet; a hook-created session (which importSession skips anyway) is only snapshotted, never parsed. - Hook writer keeps a per-transcript mark (applied after commit): an unchanged TranscriptCache result skips token/compaction/API-error/turn writes, a grown one walks only the entries after the last one handled. - Codex usage: one stamp query per pass instead of one row per journal; between full passes (first + every 5 min) only the newest day folders and journals written in the last hour are statted; fork parents resolved from the table or a full walk. - Cursor/Antigravity polls back off to 60 s after idle passes (server/lib/backoff-poll.js); lane sync runs only while another dashboard shares the data dir (checked every 30 s).
43 lines
1.5 KiB
JavaScript
43 lines
1.5 KiB
JavaScript
/**
|
|
* @file Tests server/lib/backoff-poll.js — the poll that runs at its base pace
|
|
* while passes find work (or fail) and slows to its idle pace after a pass
|
|
* that resolved `false`, returning to the base pace once work shows up again.
|
|
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
|
*/
|
|
|
|
const { describe, it } = require("node:test");
|
|
const assert = require("node:assert/strict");
|
|
const { startBackoffPoll, idleDefault } = require("../lib/backoff-poll");
|
|
|
|
const wait = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
|
|
describe("startBackoffPoll", () => {
|
|
it("slows down after idle passes and speeds up again on work", async () => {
|
|
const answers = [true, false, false, true, "x"];
|
|
const at = [];
|
|
const t0 = Date.now();
|
|
const poll = startBackoffPoll(
|
|
() => {
|
|
at.push(Date.now() - t0);
|
|
const a = answers.shift();
|
|
if (a === "x") throw new Error("boom");
|
|
return a;
|
|
},
|
|
{ baseMs: 10, idleMs: 80 }
|
|
);
|
|
await wait(260);
|
|
poll.stop();
|
|
assert.ok(at.length >= 5, `ran ${at.length} times`);
|
|
const gaps = at.slice(1).map((t, i) => t - at[i]);
|
|
assert.ok(gaps[0] < 60, "work → base pace");
|
|
assert.ok(gaps[1] >= 75, "idle → idle pace");
|
|
assert.ok(gaps[2] >= 75, "still idle");
|
|
assert.ok(gaps[3] < 60, "work again → base pace");
|
|
});
|
|
|
|
it("idles at a minute by default, never faster than the base pace", () => {
|
|
assert.equal(idleDefault(15_000), 60_000);
|
|
assert.equal(idleDefault(120_000), 120_000);
|
|
});
|
|
});
|