client/launch.mjs follow-ups from review: reads the commit in a git worktree too (.git as a file, following gitdir and commondir; info/exclude in the shared folder); a stale lock is renamed aside before it's removed, and put back if it turns out to be live, so two runs can't both take it over; the README says to point it at a checkout nobody edits in; the tests remove their temporary folders. Version 42 of shared· speed· Oct 9 (2026-10-09 12:57 UTC) · Not checked
Version 41 · Files at version 42
3 files, 94 lines added, 14 removed.
--- a/client/README.md
+++ b/client/README.md
@@ -27,6 +27,9 @@
27 27 It never changes the command's output or exit code, and writes its own notices 28 28 to `~/.abso/launcher.log`. 30 + Point it at a clone or worktree that nobody edits in. The bundle is keyed on 31 + the commit, so changes that aren't committed don't run until the next commit. 30 33 ## Setting up a folder 32 35 Folders and machines set up before abso had its name keep working: the older --- a/client/launch.mjs
+++ b/client/launch.mjs
@@ -24,7 +24,7 @@
24 24 import { appendFileSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs"; 25 25 import { createRequire } from "node:module"; 26 26 import { homedir } from "node:os"; 27 − import { dirname, join } from "node:path";
27 + import { dirname, join, resolve } from "node:path"; 28 28 import { fileURLToPath, pathToFileURL } from "node:url"; 30 30 const repo = dirname(dirname(fileURLToPath(import.meta.url))); @@ -38,29 +38,69 @@
38 38 /** Set by the bundle's first line: an error after it came from the command, so it's never run again. */ 39 39 const STARTED = "__absoBundleStarted"; 42 + * The checkout's git folders: its own (HEAD) and the shared one (refs, info/exclude). They are the same 43 + * folder in a plain clone; in a worktree .git is a file naming its own folder, which names the shared one. 45 + function gitDirs(root = repo) { 46 + const dot = join(root, ".git"); 48 + if (statSync(dot).isDirectory()) return { own: dot, common: dot }; 51 + readFileSync(dot, "utf8") 53 + .replace(/^gitdir:\s*/, ""), 57 + common = resolve(own, readFileSync(join(own, "commondir"), "utf8").trim()); 59 + return { own, common }; 41 65 /** The checkout's commit, read from .git without running git; undefined if it can't be read. */ 42 66 function headCommit(root = repo) { 67 + const dirs = gitDirs(root); 68 + if (!dirs) return undefined; 44 − const head = readFileSync(join(root, ".git", "HEAD"), "utf8").trim();
70 + const head = readFileSync(join(dirs.own, "HEAD"), "utf8").trim(); 45 71 if (!head.startsWith("ref:")) return head; 46 72 const ref = head.slice(4).trim(); 47 − try {
48 − return readFileSync(join(root, ".git", ...ref.split("/")), "utf8").trim();
49 − } catch {
50 − const line = readFileSync(join(root, ".git", "packed-refs"), "utf8")
51 − .split("\n")
52 − .find((l) => l.endsWith(` ${ref}`));
53 − return line?.split(" ")[0];
73 + for (const dir of [dirs.own, dirs.common]) { 75 + return readFileSync(join(dir, ...ref.split("/")), "utf8").trim(); 78 + const line = readFileSync(join(dirs.common, "packed-refs"), "utf8") 80 + .find((l) => l.endsWith(` ${ref}`)); 81 + return line?.split(" ")[0]; 60 − /** Runs fn under a lock folder; a lock older than 10 minutes is a dead run's and is cleared. */
88 + * Runs fn under a lock folder, or not at all when another run holds it. A lock older than 10 minutes is a 89 + * dead run's: it is renamed aside before it's removed, so of two runs that find it stale only one takes it 90 + * over, and one that renamed away a lock taken over a moment ago puts it back. 61 92 function locked(lock, fn) { 93 + const stale = (path) => Date.now() - statSync(path).mtimeMs > 10 * 60 * 1000; 63 − if (Date.now() - statSync(lock).mtimeMs > 10 * 60 * 1000) rmSync(lock, { recursive: true, force: true });
96 + const aside = `${lock}.${process.pid}.stale`; 97 + renameSync(lock, aside); 98 + if (stale(aside)) rmSync(aside, { recursive: true, force: true }); 100 + renameSync(aside, lock); @@ -124,7 +164,7 @@
127 − const exclude = join(repo, ".git", "info", "exclude");
167 + const exclude = join(gitDirs()?.common ?? join(repo, ".git"), "info", "exclude"); 129 169 if (!readFileSync(exclude, "utf8").split(/\r?\n/).includes("client/dist/")) 130 170 appendFileSync(exclude, "\nclient/dist/\n"); --- a/client/test/launch.test.ts
+++ b/client/test/launch.test.ts
@@ -3,16 +3,31 @@
4 4 import assert from "node:assert/strict"; 5 5 import { execFileSync, spawnSync } from "node:child_process"; 6 − import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
7 17 import { tmpdir } from "node:os"; 8 18 import { join } from "node:path"; 9 − import { describe, it } from "node:test";
19 + import { after, describe, it } from "node:test"; 11 21 const LAUNCH = new URL("../launch.mjs", import.meta.url); 22 + const roots: string[] = []; 24 + for (const root of roots) rmSync(root, { recursive: true, force: true }); 13 27 /** A checkout on main with one commit, launch.mjs and a stand-in client/abso.ts that names itself. */ 14 28 function checkout(): { repo: string; home: string; head: string } { 15 29 const root = mkdtempSync(join(tmpdir(), "abso-launch-")); 16 31 const repo = join(root, "repo"); 17 32 const home = join(root, "home"); 18 33 mkdirSync(join(repo, "client"), { recursive: true }); @@ -127,6 +142,28 @@
127 142 assert.equal(existsSync(lock), true); 145 + it("takes over a lock a dead run left behind, and removes it after", () => { 146 + const c = checkout(); 147 + const lock = join(c.home, ".abso", "client-update.lock"); 149 + const old = new Date(Date.now() - 11 * 60 * 1000); 150 + utimesSync(lock, old, old); 151 + assert.equal(launch(c, [], { ABSO_LAUNCH_UPDATE: "1" }).status, 0); 153 + readdirSync(join(c.home, ".abso")).filter((f) => f.includes("lock")), 158 + it("reads the commit in a git worktree, where .git is a file", () => { 159 + const c = checkout(); 160 + const wt = join(c.repo, "..", "wt"); 161 + execFileSync("git", ["-C", c.repo, "worktree", "add", "-q", "--detach", wt, "HEAD"]); 162 + bundle(wt, NAMES_ITSELF, c.head); 163 + const r = launch({ repo: wt, home: c.home }, ["status"]); 164 + assert.match(r.stdout, /^bundle /); 130 167 it("keeps the background step quiet when it can't fetch or build", () => { 131 168 const c = checkout(); 132 169 const r = launch(c, [], { ABSO_LAUNCH_UPDATE: "1" });