{"draft":null,"from":2,"to":318,"files":[{"path":"client/test/install.test.ts","added":143,"removed":7,"diff":"--- a/client/test/install.test.ts\n+++ b/client/test/install.test.ts\n@@ -24,7 +24,19 @@\n import { after, describe, it } from \"node:test\";\n import { Api } from \"../src/api.ts\";\n import { clientVersion, headCommit } from \"../src/client-version.ts\";\n-import { installMod, type ModSpec, modsBehindText, rollbackMod, versionFor, versionReport } from \"../src/install.ts\";\n+import {\n+\tAVCS_MOD,\n+\thookCommand,\n+\tinstallerCommand,\n+\tinstallMod,\n+\tkeptModCommit,\n+\ttype ModSpec,\n+\tmodsBehindText,\n+\tretireOldMod,\n+\trollbackMod,\n+\tversionFor,\n+\tversionReport,\n+} from \"../src/install.ts\";\n import { main } from \"../src/main.ts\";\n \n const hasGit = spawnSync(\"git\", [\"--version\"]).status === 0;\n@@ -103,6 +115,28 @@\n \t\t);\n \t});\n \n+\tit(\"stamps the command that runs this client's abso hook, where stamp.ts has a HOOK_COMMAND line\", () => {\n+\t\tconst spec = source({\n+\t\t\t\"hooks/stamp.ts\":\n+\t\t\t\t\"export const STAMP: string | undefined = undefined\\nexport const HOOK_COMMAND: readonly string[] | undefined = undefined\\n\",\n+\t\t});\n+\t\tconst target = join(temp(), \"avcs\");\n+\t\tinstallMod(spec, {\n+\t\t\ttarget,\n+\t\t\tcheck: pass,\n+\t\t\tcommit: \"702c616\",\n+\t\t\thookCommand: [\"C:\\\\node.exe\", \"C:\\\\abso\\\\client\\\\abso.ts\", \"hook\"],\n+\t\t});\n+\t\tassert.equal(\n+\t\t\tread(target, \"hooks/stamp.ts\"),\n+\t\t\t\"export const STAMP: string | undefined = '0.1.0+702c616'\\n\" +\n+\t\t\t\t'export const HOOK_COMMAND: readonly string[] | undefined = [\"C:\\\\\\\\node.exe\",\"C:\\\\\\\\abso\\\\\\\\client\\\\\\\\abso.ts\",\"hook\"]\\n',\n+\t\t);\n+\t\t// By default, this checkout's own: the node running it and client/abso.ts.\n+\t\tassert.deepEqual(hookCommand().slice(0, 1), [process.execPath]);\n+\t\tassert.match(hookCommand()[1]!, /client[\\\\/]abso\\.ts$/);\n+\t});\n+\n \tit(\"moves the files in by rename, what the hook imports first and plugin.json last\", () => {\n \t\tconst spec = source();\n \t\tconst target = join(temp(), \"avcs\");\n@@ -292,6 +326,77 @@\n \t\t// Outside a git checkout there is no commit to add.\n \t\tassert.equal(versionFor(spec, null), \"0.1.0\");\n \t});\n+\n+\tit(\"keeps the mod's commit between runs, and asks git again when the checkout or a file moves, or a file is too new to trust\", {\n+\t\tskip: !hasGit,\n+\t}, () => {\n+\t\tconst spec = source();\n+\t\tconst home = temp();\n+\t\tconst kept = join(home, \".abso\", \"mod-commits.json\");\n+\t\tconst git = (...args: string[]) =>\n+\t\t\tspawnSync(\"git\", [\"-c\", \"user.name=t\", \"-c\", \"user.email=t@t\", \"-C\", spec.from, ...args], {\n+\t\t\t\tencoding: \"utf8\",\n+\t\t\t}).stdout.trim();\n+\t\t// Every mod file minutes old, so a kept answer can be trusted. Each call sets a whole minute earlier\n+\t\t// than the last: git's own index compares times by the second, and a same-size edit given the time\n+\t\t// git last saw would look unchanged to git itself.\n+\t\tlet minutes = 0;\n+\t\tconst age = () => {\n+\t\t\tminutes += 1;\n+\t\t\tconst old = new Date(Date.now() - minutes * 60_000);\n+\t\t\tfor (const rel of FILES) utimesSync(at(spec.from, rel), old, old);\n+\t\t};\n+\t\t// Swaps every kept answer for a made-up one: what comes back says whether git ran.\n+\t\tconst plant = () => {\n+\t\t\tconst file = JSON.parse(readFileSync(kept, \"utf8\"));\n+\t\t\tfor (const k of Object.keys(file.mods)) file.mods[k].commit = \"fffffff\";\n+\t\t\twriteFileSync(kept, JSON.stringify(file));\n+\t\t};\n+\t\t// Not a git checkout yet: no commit, and nothing kept.\n+\t\tassert.equal(keptModCommit(spec, home), null);\n+\t\tassert.equal(existsSync(kept), false);\n+\t\tgit(\"init\", \"-q\");\n+\t\tgit(\"add\", \".\");\n+\t\tgit(\"commit\", \"-q\", \"-m\", \"mod\");\n+\t\tconst mod = git(\"rev-parse\", \"--short=7\", \"HEAD\");\n+\t\tage();\n+\t\tassert.equal(keptModCommit(spec, home), mod);\n+\t\tplant();\n+\t\tassert.equal(keptModCommit(spec, home), \"fffffff\", \"a kept answer is used while nothing moved\");\n+\n+\t\t// A file changed in the same moment the answer was kept is never trusted, even when its size and time match.\n+\t\t// A time a minute ahead stays too new however long the run takes.\n+\t\twrite(spec.from, \"src/core.ts\", \"export const core = 2\\n\");\n+\t\tconst soon = new Date(Date.now() + 60_000);\n+\t\tutimesSync(at(spec.from, \"src/core.ts\"), soon, soon);\n+\t\tassert.equal(keptModCommit(spec, home), `${mod}.dirty`);\n+\t\tplant();\n+\t\tassert.equal(keptModCommit(spec, home), `${mod}.dirty`, \"too new to trust: git runs again\");\n+\n+\t\t// An edit that keeps the size, with its time set back a minute, still isn't the time that was kept.\n+\t\tage();\n+\t\tassert.equal(keptModCommit(spec, home), `${mod}.dirty`);\n+\t\tplant();\n+\t\twrite(spec.from, \"src/core.ts\", \"export const core = 3\\n\");\n+\t\tage();\n+\t\tassert.equal(keptModCommit(spec, home), `${mod}.dirty`);\n+\n+\t\t// A commit moves the checkout.\n+\t\tgit(\"commit\", \"-q\", \"-am\", \"core\");\n+\t\tage();\n+\t\tconst next = git(\"rev-parse\", \"--short=7\", \"HEAD\");\n+\t\tassert.equal(keptModCommit(spec, home), next);\n+\t\tplant();\n+\t\tgit(\"commit\", \"-q\", \"--allow-empty\", \"-m\", \"empty\");\n+\t\tassert.equal(keptModCommit(spec, home), next, \"a new commit asks git again\");\n+\n+\t\t// A file it can't read, or doesn't know the format of, is the same as none.\n+\t\tplant();\n+\t\twriteFileSync(kept, JSON.stringify({ format: 2, mods: JSON.parse(readFileSync(kept, \"utf8\")).mods }));\n+\t\tassert.equal(keptModCommit(spec, home), next);\n+\t\twriteFileSync(kept, \"not json\");\n+\t\tassert.equal(keptModCommit(spec, home), next);\n+\t});\n });\n \n describe(\"which client this is\", () => {\n@@ -335,7 +440,7 @@\n \t\tconst config = temp();\n \t\tconst spec = source();\n \t\tinstallMod(spec, {\n-\t\t\ttarget: join(config, \"skills\", \"avcs\"),\n+\t\t\ttarget: join(config, \"skills\", \"abso-hooks\"),\n \t\t\tcheck: pass,\n \t\t\tcommit: \"aaaaaaa\",\n \t\t\tnow: new Date(\"2026-10-05T04:30:00Z\"),\n@@ -346,9 +451,10 @@\n \t\tassert.equal(client, `abso ${clientVersion()} (${dirname(import.meta.dirname)})`);\n \t\tassert.match(\n \t\t\tmod!,\n-\t\t\t/^the avcs mod: 0\\.1\\.0\\+aaaaaaa in .*skills[\\\\/]avcs, installed 2026-10-05 04:30 UTC; this client has 0\\.1\\.0(\\+[0-9a-f]{7}(\\.dirty)?)?: node client\\/install-mod\\.ts installs it$/,\n+\t\t\t/^the abso-hooks mod: 0\\.1\\.0\\+aaaaaaa in .*skills[\\\\/]abso-hooks, installed 2026-10-05 04:30 UTC; this client has 0.2.0(\\+[0-9a-f]{7}(\\.dirty)?)?: /,\n \t\t);\n-\t\tassert.equal(view, \"the avcs-view mod: not installed (node client/install-view.ts)\");\n+\t\tassert.ok(mod!.endsWith(`: ${installerCommand(\"install-mod.ts\")} installs it`), mod);\n+\t\tassert.equal(view, `the abso-view mod: not installed (${installerCommand(\"install-view.ts\")})`);\n \t\tconst json = JSON.parse(\n \t\t\t(await main([\"--version\", \"--json\"], { cwd: config, env: { CLAUDE_CONFIG_DIR: config }, write: () => {} }))\n \t\t\t\t.stdout,\n@@ -357,12 +463,35 @@\n \t\tassert.equal(json.mods[0].version, \"0.1.0+aaaaaaa\");\n \t});\n \n+\tit(\"moves the old avcs mod folder out of the skills folder, not deleting it, once abso-hooks is in\", () => {\n+\t\tconst config = temp();\n+\t\tconst old = join(config, \"skills\", \"avcs\");\n+\t\twrite(old, \".claude-plugin/plugin.json\", '{\"name\":\"avcs\",\"version\":\"0.1.0\"}');\n+\t\tconst home = temp();\n+\t\tconst was = process.env.USERPROFILE;\n+\t\tconst was2 = process.env.HOME;\n+\t\tprocess.env.USERPROFILE = home;\n+\t\tprocess.env.HOME = home;\n+\t\ttry {\n+\t\t\tconst to = retireOldMod(AVCS_MOD, { CLAUDE_CONFIG_DIR: config });\n+\t\t\tassert.ok(to?.startsWith(join(home, \".abso\", \"retired-mods\")));\n+\t\t\tassert.equal(existsSync(old), false);\n+\t\t\tassert.equal(existsSync(join(to!, \".claude-plugin\", \"plugin.json\")), true);\n+\t\t\tassert.equal(retireOldMod(AVCS_MOD, { CLAUDE_CONFIG_DIR: config }), undefined);\n+\t\t} finally {\n+\t\t\tif (was === undefined) delete process.env.USERPROFILE;\n+\t\t\telse process.env.USERPROFILE = was;\n+\t\t\tif (was2 === undefined) delete process.env.HOME;\n+\t\t\telse process.env.HOME = was2;\n+\t\t}\n+\t});\n+\n \tit(\"status says when an installed mod is behind this client, where the client knows its commit (abso issue 41)\", () => {\n \t\tconst config = temp();\n \t\tconst env = { CLAUDE_CONFIG_DIR: config };\n \t\tassert.deepEqual(modsBehindText(env), [], \"nothing installed, nothing to say\");\n \t\tinstallMod(source(), {\n-\t\t\ttarget: join(config, \"skills\", \"avcs\"),\n+\t\t\ttarget: join(config, \"skills\", \"abso-hooks\"),\n \t\t\tcheck: pass,\n \t\t\tcommit: \"aaaaaaa\",\n \t\t\tnow: new Date(\"2026-10-05T04:30:00Z\"),\n@@ -370,7 +499,7 @@\n \t\tconst current = (versionReport(env).json.mods as { current: string }[])[0]!.current;\n \t\tif (/\\+[0-9a-f]{7}$/.test(current))\n \t\t\tassert.deepEqual(modsBehindText(env), [\n-\t\t\t\t`The avcs mod installed on this machine is 0.1.0+aaaaaaa, and this client has ${current}: node client/install-mod.ts installs it (new chats load it).`,\n+\t\t\t\t`The ${AVCS_MOD.name} mod installed on this machine is 0.1.0+aaaaaaa, and this client has ${current}: ${installerCommand(\"install-mod.ts\")} installs it (new chats load it).`,\n \t\t\t]);\n \t\t// A client outside git (an abso folder, a box) can't tell, so it says nothing.\n \t\telse assert.deepEqual(modsBehindText(env), []);\n@@ -383,7 +512,14 @@\n \t\t\tagent: \"a\",\n \t\t\ttoken: \"t\",\n \t\t} as ConstructorParameters<typeof Api>[0]).headers(\"application/json\");\n-\t\tassert.equal(headers[\"x-avcs-client\"], `abso-cli/${clientVersion()}`);\n+\t\tassert.equal(headers[\"x-abso-client\"], `abso-cli/${clientVersion()}`);\n \t\tassert.match(clientVersion(), /^\\d+\\.\\d+\\.\\d+(\\+[0-9a-f]{7})?$/);\n \t});\n+\n+\tit(\"the npm package's client gives the package's version\", () => {\n+\t\tconst url = new URL(\"../src/client-version.ts\", import.meta.url).href;\n+\t\tconst script = `globalThis.__ABSO_PACKAGE_VERSION__ = \"0.58.0\"; const m = await import(${JSON.stringify(url)}); console.log(m.clientVersion());`;\n+\t\tconst r = spawnSync(process.execPath, [\"--input-type=module\", \"-e\", script], { encoding: \"utf8\" });\n+\t\tassert.equal(r.stdout.trim(), \"0.58.0\", r.stderr);\n+\t});\n });"}],"unmatched":[]}