{"file":"client/test/client-version.test.ts","version":318,"total":95,"from":1,"to":95,"lines":[{"n":1,"text":"// An npm install of abso says when npm has a later version, asking npm at most","atom":"a643","author":"pinch","version":68},{"n":2,"text":"// once a day. The registry here is a stand-in that counts how often it is asked.","atom":"a643","author":"pinch","version":68},{"n":3,"text":"","atom":"a643","author":"pinch","version":68},{"n":4,"text":"import assert from \"node:assert/strict\";","atom":"a643","author":"pinch","version":68},{"n":5,"text":"import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";","atom":"a643","author":"pinch","version":68},{"n":6,"text":"import { createServer, type Server } from \"node:http\";","atom":"a643","author":"pinch","version":68},{"n":7,"text":"import type { AddressInfo } from \"node:net\";","atom":"a643","author":"pinch","version":68},{"n":8,"text":"import { tmpdir } from \"node:os\";","atom":"a643","author":"pinch","version":68},{"n":9,"text":"import { join } from \"node:path\";","atom":"a643","author":"pinch","version":68},{"n":10,"text":"import { after, before, beforeEach, describe, it } from \"node:test\";","atom":"a643","author":"pinch","version":68},{"n":11,"text":"import { newerClientNote } from \"../src/client-version.ts\";","atom":"a643","author":"pinch","version":68},{"n":12,"text":"","atom":"a643","author":"pinch","version":68},{"n":13,"text":"const DAY = 24 * 60 * 60 * 1000;","atom":"a643","author":"pinch","version":68},{"n":14,"text":"const stamp = globalThis as { __ABSO_PACKAGE_VERSION__?: string };","atom":"a643","author":"pinch","version":68},{"n":15,"text":"let registry: Server;","atom":"a643","author":"pinch","version":68},{"n":16,"text":"let registryUrl: string;","atom":"a643","author":"pinch","version":68},{"n":17,"text":"let latest = \"0.67.0\";","atom":"a643","author":"pinch","version":68},{"n":18,"text":"let asked = 0;","atom":"a643","author":"pinch","version":68},{"n":19,"text":"let home: string;","atom":"a643","author":"pinch","version":68},{"n":20,"text":"","atom":"a643","author":"pinch","version":68},{"n":21,"text":"before(async () => {","atom":"a643","author":"pinch","version":68},{"n":22,"text":"\tregistry = createServer((_req, res) => {","atom":"a643","author":"pinch","version":68},{"n":23,"text":"\t\tasked++;","atom":"a643","author":"pinch","version":68},{"n":24,"text":"\t\tres","atom":"a643","author":"pinch","version":68},{"n":25,"text":"\t\t\t.writeHead(200, { \"content-type\": \"application/json\" })","atom":"a643","author":"pinch","version":68},{"n":26,"text":"\t\t\t.end(JSON.stringify({ name: \"@abso-cli/abso\", version: latest }));","atom":"a643","author":"pinch","version":68},{"n":27,"text":"\t});","atom":"a643","author":"pinch","version":68},{"n":28,"text":"\t// As fake-server.ts: never close an idle kept-alive connection, or under load the client can reuse one as it closes","atom":"a823","author":"infra-pipeline","version":99},{"n":29,"text":"\t// and fail with ECONNRESET (abso 410).","atom":"a823","author":"infra-pipeline","version":99},{"n":30,"text":"\tregistry.keepAliveTimeout = 0;","atom":"a823","author":"infra-pipeline","version":99},{"n":31,"text":"\tawait new Promise<void>((done) => registry.listen(0, \"127.0.0.1\", done));","atom":"a643","author":"pinch","version":68},{"n":32,"text":"\tregistryUrl = `http://127.0.0.1:${(registry.address() as AddressInfo).port}/@abso-cli/abso/latest`;","atom":"a643","author":"pinch","version":68},{"n":33,"text":"});","atom":"a643","author":"pinch","version":68},{"n":34,"text":"after(() => {","atom":"a643","author":"pinch","version":68},{"n":35,"text":"\tregistry.close();","atom":"a643","author":"pinch","version":68},{"n":36,"text":"\tdelete stamp.__ABSO_PACKAGE_VERSION__;","atom":"a643","author":"pinch","version":68},{"n":37,"text":"});","atom":"a643","author":"pinch","version":68},{"n":38,"text":"beforeEach(() => {","atom":"a643","author":"pinch","version":68},{"n":39,"text":"\thome = mkdtempSync(join(tmpdir(), \"abso-test-home-\"));","atom":"a643","author":"pinch","version":68},{"n":40,"text":"\tasked = 0;","atom":"a643","author":"pinch","version":68},{"n":41,"text":"\tlatest = \"0.67.0\";","atom":"a643","author":"pinch","version":68},{"n":42,"text":"});","atom":"a643","author":"pinch","version":68},{"n":43,"text":"","atom":"a643","author":"pinch","version":68},{"n":44,"text":"describe(\"newerClientNote for the npm package\", () => {","atom":"a643","author":"pinch","version":68},{"n":45,"text":"\tit(\"says so when npm has a later version, and asks npm once a day\", async () => {","atom":"a643","author":"pinch","version":68},{"n":46,"text":"\t\tstamp.__ABSO_PACKAGE_VERSION__ = \"0.66.0\";","atom":"a643","author":"pinch","version":68},{"n":47,"text":"\t\tconst now = 1_000_000_000_000;","atom":"a643","author":"pinch","version":68},{"n":48,"text":"\t\tconst note = await newerClientNote(\"http://unused.test\", { home, registry: registryUrl, now });","atom":"a643","author":"pinch","version":68},{"n":49,"text":"\t\tassert.equal(note, \"abso 0.67.0 is out and this is 0.66.0: npm install -g @abso-cli/abso updates it.\");","atom":"a643","author":"pinch","version":68},{"n":50,"text":"\t\tassert.equal(asked, 1);","atom":"a643","author":"pinch","version":68},{"n":51,"text":"\t\tassert.ok(existsSync(join(home, \".abso\", \"npm-latest.json\")));","atom":"a643","author":"pinch","version":68},{"n":52,"text":"","atom":"a643","author":"pinch","version":68},{"n":53,"text":"\t\tlatest = \"0.68.0\";","atom":"a643","author":"pinch","version":68},{"n":54,"text":"\t\tconst kept = await newerClientNote(\"http://unused.test\", { home, registry: registryUrl, now: now + DAY - 1 });","atom":"a643","author":"pinch","version":68},{"n":55,"text":"\t\tassert.match(kept ?? \"\", /^abso 0\\.67\\.0 is out/, \"within a day the kept answer is used\");","atom":"a643","author":"pinch","version":68},{"n":56,"text":"\t\tassert.equal(asked, 1);","atom":"a643","author":"pinch","version":68},{"n":57,"text":"","atom":"a643","author":"pinch","version":68},{"n":58,"text":"\t\tconst fresh = await newerClientNote(\"http://unused.test\", { home, registry: registryUrl, now: now + DAY });","atom":"a643","author":"pinch","version":68},{"n":59,"text":"\t\tassert.match(fresh ?? \"\", /^abso 0\\.68\\.0 is out/);","atom":"a643","author":"pinch","version":68},{"n":60,"text":"\t\tassert.equal(asked, 2);","atom":"a643","author":"pinch","version":68},{"n":61,"text":"\t\trmSync(home, { recursive: true, force: true });","atom":"a643","author":"pinch","version":68},{"n":62,"text":"\t});","atom":"a643","author":"pinch","version":68},{"n":63,"text":"","atom":"a643","author":"pinch","version":68},{"n":64,"text":"\tit(\"says nothing when this is npm's latest or later, and compares numbers, not text\", async () => {","atom":"a643","author":"pinch","version":68},{"n":65,"text":"\t\tstamp.__ABSO_PACKAGE_VERSION__ = \"0.67.0\";","atom":"a643","author":"pinch","version":68},{"n":66,"text":"\t\tassert.equal(await newerClientNote(\"http://unused.test\", { home, registry: registryUrl, now: 1 }), undefined);","atom":"a643","author":"pinch","version":68},{"n":67,"text":"\t\trmSync(home, { recursive: true, force: true });","atom":"a643","author":"pinch","version":68},{"n":68,"text":"","atom":"a643","author":"pinch","version":68},{"n":69,"text":"\t\thome = mkdtempSync(join(tmpdir(), \"abso-test-home-\"));","atom":"a643","author":"pinch","version":68},{"n":70,"text":"\t\tstamp.__ABSO_PACKAGE_VERSION__ = \"0.100.0\";","atom":"a643","author":"pinch","version":68},{"n":71,"text":"\t\tlatest = \"0.99.0\";","atom":"a643","author":"pinch","version":68},{"n":72,"text":"\t\tassert.equal(await newerClientNote(\"http://unused.test\", { home, registry: registryUrl, now: 1 }), undefined);","atom":"a643","author":"pinch","version":68},{"n":73,"text":"\t\trmSync(home, { recursive: true, force: true });","atom":"a643","author":"pinch","version":68},{"n":74,"text":"\t});","atom":"a643","author":"pinch","version":68},{"n":75,"text":"","atom":"a643","author":"pinch","version":68},{"n":76,"text":"\tit(\"says nothing when npm can't be asked, and keeps no answer\", async () => {","atom":"a643","author":"pinch","version":68},{"n":77,"text":"\t\tstamp.__ABSO_PACKAGE_VERSION__ = \"0.66.0\";","atom":"a643","author":"pinch","version":68},{"n":78,"text":"\t\tconst note = await newerClientNote(\"http://unused.test\", { home, registry: \"http://127.0.0.1:1/latest\", now: 1 });","atom":"a643","author":"pinch","version":68},{"n":79,"text":"\t\tassert.equal(note, undefined);","atom":"a643","author":"pinch","version":68},{"n":80,"text":"\t\tassert.equal(existsSync(join(home, \".abso\", \"npm-latest.json\")), false);","atom":"a643","author":"pinch","version":68},{"n":81,"text":"\t\trmSync(home, { recursive: true, force: true });","atom":"a643","author":"pinch","version":68},{"n":82,"text":"\t});","atom":"a643","author":"pinch","version":68},{"n":83,"text":"","atom":"a643","author":"pinch","version":68},{"n":84,"text":"\tit(\"asks npm again when the kept answer isn't JSON, and keeps the new one\", async () => {","atom":"a643","author":"pinch","version":68},{"n":85,"text":"\t\tstamp.__ABSO_PACKAGE_VERSION__ = \"0.66.0\";","atom":"a643","author":"pinch","version":68},{"n":86,"text":"\t\tconst file = join(home, \".abso\", \"npm-latest.json\");","atom":"a643","author":"pinch","version":68},{"n":87,"text":"\t\tmkdirSync(join(home, \".abso\"), { recursive: true });","atom":"a643","author":"pinch","version":68},{"n":88,"text":"\t\twriteFileSync(file, \"not json\");","atom":"a643","author":"pinch","version":68},{"n":89,"text":"\t\tconst note = await newerClientNote(\"http://unused.test\", { home, registry: registryUrl, now: 5 });","atom":"a643","author":"pinch","version":68},{"n":90,"text":"\t\tassert.match(note ?? \"\", /^abso 0\\.67\\.0 is out/);","atom":"a643","author":"pinch","version":68},{"n":91,"text":"\t\tassert.equal(asked, 1);","atom":"a643","author":"pinch","version":68},{"n":92,"text":"\t\tassert.deepEqual(JSON.parse(readFileSync(file, \"utf8\")), { checked: 5, latest: \"0.67.0\" });","atom":"a643","author":"pinch","version":68},{"n":93,"text":"\t\trmSync(home, { recursive: true, force: true });","atom":"a643","author":"pinch","version":68},{"n":94,"text":"\t});","atom":"a643","author":"pinch","version":68},{"n":95,"text":"});","atom":"a643","author":"pinch","version":68}],"atoms":[{"atom":"a643","author":"pinch","message":"","time":1791605781239,"timeIso":"2026-10-10T04:16:21.239Z","publish":{"draft":null,"version":68,"agent":"pinch","message":"An npm install of abso says when npm has a later version: status and --version add 'abso X is out and this is Y: npm install -g @abso-cli/abso updates it.' npm is asked at most once a day, and its answer is kept in ~/.abso/npm-latest.json. A copy bundled for a server still compares commits with that server. newerCommitNote is now newerClientNote.","time":1791606091384,"timeIso":"2026-10-10T04:21:31.384Z"}},{"atom":"a823","author":"infra-pipeline","message":"","time":1791650650965,"timeIso":"2026-10-10T16:44:10.965Z","publish":{"draft":null,"version":99,"agent":"infra-pipeline","message":"Test servers keep idle connections open (abso 410): issues.test.ts, attach.test.ts and client-version.test.ts set keepAliveTimeout = 0, as fake-server.ts already does. Under a full check's load, 'waiting --asked' took 6.3 s and its next call reused a kept-alive socket just as Node's default 5 s timeout closed it: ECONNRESET. Tests only.","time":1791650651433,"timeIso":"2026-10-10T16:44:11.433Z"}}]}