Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/client/test/client-version.test.ts?version=85&format=json
92 linespinch 100%Last change pinch in version 68, 1 version changed it

You're reading version 85. The newest is 318, and 1 version since then changed this file. Go to the newestCompare with 318

1// An npm install of abso says when npm has a later version, asking npm at most
2// once a day. The registry here is a stand-in that counts how often it is asked.
3
4import assert from "node:assert/strict";
5import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
6import { createServer, type Server } from "node:http";
7import type { AddressInfo } from "node:net";
8import { tmpdir } from "node:os";
9import { join } from "node:path";
10import { after, before, beforeEach, describe, it } from "node:test";
11import { newerClientNote } from "../src/client-version.ts";
13const DAY = 24 * 60 * 60 * 1000;
14const stamp = globalThis as { __ABSO_PACKAGE_VERSION__?: string };
15let registry: Server;
16let registryUrl: string;
17let latest = "0.67.0";
18let asked = 0;
19let home: string;
21before(async () => {
22 registry = createServer((_req, res) => {
23 asked++;
24 res
25 .writeHead(200, { "content-type": "application/json" })
26 .end(JSON.stringify({ name: "@abso-cli/abso", version: latest }));
27 });
28 await new Promise<void>((done) => registry.listen(0, "127.0.0.1", done));
29 registryUrl = `http://127.0.0.1:${(registry.address() as AddressInfo).port}/@abso-cli/abso/latest`;
30});
31after(() => {
32 registry.close();
33 delete stamp.__ABSO_PACKAGE_VERSION__;
34});
35beforeEach(() => {
36 home = mkdtempSync(join(tmpdir(), "abso-test-home-"));
37 asked = 0;
38 latest = "0.67.0";
39});
41describe("newerClientNote for the npm package", () => {
42 it("says so when npm has a later version, and asks npm once a day", async () => {
43 stamp.__ABSO_PACKAGE_VERSION__ = "0.66.0";
44 const now = 1_000_000_000_000;
45 const note = await newerClientNote("http://unused.test", { home, registry: registryUrl, now });
46 assert.equal(note, "abso 0.67.0 is out and this is 0.66.0: npm install -g @abso-cli/abso updates it.");
47 assert.equal(asked, 1);
48 assert.ok(existsSync(join(home, ".abso", "npm-latest.json")));
50 latest = "0.68.0";
51 const kept = await newerClientNote("http://unused.test", { home, registry: registryUrl, now: now + DAY - 1 });
52 assert.match(kept ?? "", /^abso 0\.67\.0 is out/, "within a day the kept answer is used");
53 assert.equal(asked, 1);
55 const fresh = await newerClientNote("http://unused.test", { home, registry: registryUrl, now: now + DAY });
56 assert.match(fresh ?? "", /^abso 0\.68\.0 is out/);
57 assert.equal(asked, 2);
58 rmSync(home, { recursive: true, force: true });
59 });
61 it("says nothing when this is npm's latest or later, and compares numbers, not text", async () => {
62 stamp.__ABSO_PACKAGE_VERSION__ = "0.67.0";
63 assert.equal(await newerClientNote("http://unused.test", { home, registry: registryUrl, now: 1 }), undefined);
64 rmSync(home, { recursive: true, force: true });
66 home = mkdtempSync(join(tmpdir(), "abso-test-home-"));
67 stamp.__ABSO_PACKAGE_VERSION__ = "0.100.0";
68 latest = "0.99.0";
69 assert.equal(await newerClientNote("http://unused.test", { home, registry: registryUrl, now: 1 }), undefined);
70 rmSync(home, { recursive: true, force: true });
71 });
73 it("says nothing when npm can't be asked, and keeps no answer", async () => {
74 stamp.__ABSO_PACKAGE_VERSION__ = "0.66.0";
75 const note = await newerClientNote("http://unused.test", { home, registry: "http://127.0.0.1:1/latest", now: 1 });
76 assert.equal(note, undefined);
77 assert.equal(existsSync(join(home, ".abso", "npm-latest.json")), false);
78 rmSync(home, { recursive: true, force: true });
79 });
81 it("asks npm again when the kept answer isn't JSON, and keeps the new one", async () => {
82 stamp.__ABSO_PACKAGE_VERSION__ = "0.66.0";
83 const file = join(home, ".abso", "npm-latest.json");
84 mkdirSync(join(home, ".abso"), { recursive: true });
85 writeFileSync(file, "not json");
86 const note = await newerClientNote("http://unused.test", { home, registry: registryUrl, now: 5 });
87 assert.match(note ?? "", /^abso 0\.67\.0 is out/);
88 assert.equal(asked, 1);
89 assert.deepEqual(JSON.parse(readFileSync(file, "utf8")), { checked: 5, latest: "0.67.0" });
90 rmSync(home, { recursive: true, force: true });
91 });
92});