Release agent@1.1.1: stats during jobs, its real version

Stats go every minute on their own timer, also while a job runs (before,
a 30-minute install made the Hub alert that the server was down). The
version constant said 1.0.1 in 1.1.0; a test keeps it equal to
package.json now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 19:03:19 +02:00
co-authored by Claude Opus 5.5
parent 2aab5918f7
commit 43189c599a
7 changed files with 70 additions and 10 deletions
+9
View File
@@ -49,3 +49,12 @@ describe("crosscode arguments for each job", () => {
expect(crosscodeArgs(parsed({ type: "update-agent", args: { version: "agent@1.0.1" } }))).toBeNull();
});
});
describe("the agent's version", () => {
it("is the one in package.json (it's what the Hub shows and compares)", () => {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const pkg = require("../package.json") as { version: string };
// eslint-disable-next-line @typescript-eslint/no-require-imports
expect((require("../src/stats") as { AGENT_VERSION: string }).AGENT_VERSION).toBe(pkg.version);
});
});
+26
View File
@@ -42,6 +42,32 @@ function make(jobs: unknown[], run: jest.Mock<ReturnType<Run>, Parameters<Run>>
const reports = (posts: { path: string; body: unknown }[]) => posts.filter((p) => p.path === "/api/agent/v1/report").map((p) => p.body as agent.AgentReport);
describe("the agent loop", () => {
it("keeps sending stats while a long job runs, so the Hub doesn't think it's down", async () => {
jest.useFakeTimers();
try {
let finish!: () => void;
const longRun = jest.fn<ReturnType<Run>, Parameters<Run>>(() => new Promise<RunResult>((resolve) => { finish = () => resolve(ok()); }));
const h = fakeHub([job()]);
const a = new Agent({ config, keys: { ed25519Pem: serverKeys.ed25519.privateKeyPem, x25519Pem: serverKeys.x25519.privateKeyPem }, hub: h.hub, seen: new SeenJobs(path.join(state, `seen-${Math.random()}.json`)), run: longRun, now: () => NOW, stats: async () => ({}) as agent.AgentStats });
const running = a.start();
await jest.advanceTimersByTimeAsync(10);
expect(longRun).toHaveBeenCalledTimes(1);
// 20 minutes of a job: a stats post every minute all the way through.
await jest.advanceTimersByTimeAsync(20 * 60 * 1000);
const stats = h.posts.filter((p) => p.path === "/api/agent/v1/stats").length;
expect(stats).toBeGreaterThanOrEqual(20);
expect(reports(h.posts)).toHaveLength(0);
finish();
await jest.advanceTimersByTimeAsync(10);
expect(reports(h.posts)).toHaveLength(1);
a.stop();
await jest.advanceTimersByTimeAsync(60 * 1000);
await running;
} finally {
jest.useRealTimers();
}
});
it("runs a valid job once and reports it", async () => {
const j = job();
const { a, run, posts } = make([j, j]);