Skip to content
This repository was archived by the owner on Jul 24, 2026. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/launch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,43 @@ describe("discoverSmalltalkDir (fresh-install hook discovery, no SMALLTALK_DIR n
});
});

describe("discoverSmalltalkDir on a PACKAGED layout (repo under <pkg>/lib/smalltalk)", () => {
const saved = process.env["SMALLTALK_DIR"];
afterEach(() => {
if (saved === undefined) delete process.env["SMALLTALK_DIR"];
else process.env["SMALLTALK_DIR"] = saved;
});

// Nix (and any packager that installs the repo under lib/) puts `st` at <pkg>/bin/st while the repo lives
// at <pkg>/lib/smalltalk — so the bin/st -> grandparent assumption lands one level ABOVE the hooks.
it("finds the hooks under <candidate>/lib/smalltalk, not just at the candidate root", () => {
const pkg = mkdtempSync(join(tmpdir(), "convoy-sm-pkg-"));
try {
const repo = join(pkg, "lib", "smalltalk");
mkdirSync(join(repo, "examples", "claude-code", "hooks"), { recursive: true });
writeFileSync(join(repo, "examples", "claude-code", "hooks", "session-start.sh"), "#!/bin/sh\n");
process.env["SMALLTALK_DIR"] = pkg; // the package root — hooks are one level down
expect(discoverSmalltalkDir()).toBe(repo);
} finally {
rmSync(pkg, { recursive: true, force: true });
}
});

it("still prefers the candidate root when the hooks are there (checkout layout wins)", () => {
const dir = mkdtempSync(join(tmpdir(), "convoy-sm-both-"));
try {
for (const base of [dir, join(dir, "lib", "smalltalk")]) {
mkdirSync(join(base, "examples", "claude-code", "hooks"), { recursive: true });
writeFileSync(join(base, "examples", "claude-code", "hooks", "session-start.sh"), "#!/bin/sh\n");
}
process.env["SMALLTALK_DIR"] = dir;
expect(discoverSmalltalkDir()).toBe(dir);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
});

describe("discoverSmalltalkDir via ST_BIN (the off-PATH hooks discovery — Johannes false-negative)", () => {
const savedSt = process.env["SMALLTALK_DIR"];
const savedBin = process.env["ST_BIN"];
Expand Down
11 changes: 10 additions & 1 deletion src/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,16 @@ export function discoverSmalltalkDir(): string | null {
if (fromPath) candidates.push(fromPath);
}
candidates.push(join(dirname(dirname(fileURLToPath(import.meta.url))), "..", "smalltalk"));
for (const c of candidates) if (hasHooks(c)) return c;
// Each candidate is tried BOTH as the repo root and as `<candidate>/lib/smalltalk`. A packaged install
// (Nix, and any packager that installs the repo under `lib/`) puts `st` at `<pkg>/bin/st` while the repo
// itself lives at `<pkg>/lib/smalltalk` — so the `<smalltalk>/bin/st` → grandparent assumption lands on
// `<pkg>`, one level ABOVE the hooks. Without this the hooks ship in the package but are undiscoverable,
// and `doctor` reports a blocking "smalltalk hooks NOT found" on a correct install.
for (const c of candidates) {
if (hasHooks(c)) return c;
const packaged = join(c, "lib", "smalltalk");
if (hasHooks(packaged)) return packaged;
}
return null;
}

Expand Down