Skip to content
Closed
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
2 changes: 1 addition & 1 deletion tests/auto-restart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ test("performSelfRestart: port taken over by another bili instance → parent ex
}
});

test("performSelfRestart: a replacement that survives SIGTERM is escalated loudly (#3044)", { timeout: 30_000 }, async () => {
test("performSelfRestart: a replacement that survives SIGTERM is escalated loudly (#3044)", { timeout: 30_000, skip: process.platform === "win32" ? "POSIX-only: Windows terminates on SIGTERM uncatchably, so a SIGTERM-surviving stub cannot be modeled (was a w24 CI red, #3182 family)" : false }, async () => {
const { server, port } = await startServer();
const { log, entries } = makeLog();
const record: SpawnRecord = {};
Expand Down
63 changes: 62 additions & 1 deletion tests/claude-native.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,12 @@ test("hook e2e: an occupied stable port fails loud — never port-hops", { timeo
// claude model call on the dead original port (found live on the
// host of issue #964: two test listeners on 48787/48788).
const squatter = net.createServer();
// #3182 family (w22-3 CI red): the hook's probe of the port holder gets
// abruptly reset by this foreign listener; without a connection handler
// the accepted socket's ECONNRESET was unhandled and crashed the test
// process. Kill every connection eagerly — hostile squatter, and no
// stray socket events.
squatter.on("connection", (c) => c.destroy());
squatter.listen(0, "127.0.0.1");
await once(squatter, "listening");
const port = (squatter.address() as net.AddressInfo).port;
Expand Down Expand Up @@ -1562,14 +1568,22 @@ test("watcher route: shared proxies take watcher registrations, daemons refuse (
// for lifecycle-less LANE'd squatters (unit-tested in launcher.test.ts) and
// for non-bili listeners (spawn EADDRINUSE). Linux-only like the other hook
// e2es (fake claude walks /proc).
test("hook e2e: manual `bili start` on the pinned port is attached, not refused (#1322/#1335/#1660)", { timeout: 180_000, skip: LIVE_E2E ? process.platform !== "linux" : liveSkip }, async () => {
// #2877 (#3212): the LANEd-hook DEFAULT flipped to own-lane — riding a
// lane-less daemon is now OPT-IN. This scenario pins the documented restore
// path (native.attachPolicy=global-fallback); the sibling test below pins
// the new default (fail fast + actionable remedy).
test("hook e2e: manual `bili start` on the pinned port is attached via global-fallback opt-in (#1322/#1335/#1660/#2877)", { timeout: 180_000, skip: LIVE_E2E ? process.platform !== "linux" : liveSkip }, async () => {
const distCli = path.resolve(import.meta.dirname, "..", "dist", "index.js");
const distScript = path.resolve(import.meta.dirname, "..", "dist", "claude-native-bootstrap.js");
ensureDistBuilt(distCli);
ensureDistBuilt(distScript);
const home = fs.mkdtempSync(path.join(os.tmpdir(), "bili-claude-squatter-"));
const xdg = { home, config: path.join(home, "cfg"), state: path.join(home, "state"), cache: path.join(home, "cache"), data: path.join(home, "data") };
fs.mkdirSync(path.join(home, "tmp"), { recursive: true });
// The documented #2877 restore path: opt back into riding lane-less daemons.
const cfgDir = path.join(xdg.config, "billion-context");
fs.mkdirSync(cfgDir, { recursive: true });
fs.writeFileSync(path.join(cfgDir, "billion-context.json"), JSON.stringify({ native: { attachPolicy: "global-fallback" } }));
const port = await freePort();
const instanceFile = path.join(xdg.state, "billion-context", "proxy-origin");
const baseEnv = {
Expand Down Expand Up @@ -1644,6 +1658,53 @@ test("hook e2e: manual `bili start` on the pinned port is attached, not refused
}
});

// #2877 (#3212): the sibling of the global-fallback scenario above. Under the
// NEW default (own-lane) a lane-less manual daemon on the pinned port must NOT
// be ridden: the hook fails fast with an actionable remedy, stays non-fatal to
// claude (exit 0), leaves the user's daemon untouched and never port-hops.
// This is the exact failure shape #3212's stale e2e caught in CI — pre-#2877
// it attached, post-#2877 it refuses; pinning both sides keeps the flip honest.
test("hook e2e: default own-lane policy fails fast on a lane-less pinned-port daemon (#2877/#3212)", { timeout: 180_000, skip: LIVE_E2E ? process.platform !== "linux" : liveSkip }, async () => {
const distCli = path.resolve(import.meta.dirname, "..", "dist", "index.js");
const distScript = path.resolve(import.meta.dirname, "..", "dist", "claude-native-bootstrap.js");
ensureDistBuilt(distCli);
ensureDistBuilt(distScript);
const home = fs.mkdtempSync(path.join(os.tmpdir(), "bili-claude-ownlane-"));
const xdg = { home, config: path.join(home, "cfg"), state: path.join(home, "state"), cache: path.join(home, "cache"), data: path.join(home, "data") };
fs.mkdirSync(path.join(home, "tmp"), { recursive: true });
// NO config file: whatever the hook sees here IS the shipped default.
const port = await freePort();
const instanceFile = path.join(xdg.state, "billion-context", "proxy-origin");
const baseEnv = {
PATH: process.env.PATH ?? "/usr/bin:/bin",
HOME: xdg.home,
XDG_CONFIG_HOME: xdg.config,
XDG_STATE_HOME: xdg.state,
XDG_CACHE_HOME: xdg.cache,
XDG_DATA_HOME: xdg.data,
NO_COLOR: "1",
};
const squatter = spawnProxy(distCli, port, baseEnv);
try {
assert.ok(await waitForPort(port, 60_000), "squatter daemon up on the stable port");
assert.ok(
await waitForProxyVisible(port, instanceFile, 60_000),
"squatter fully visible to the attach machinery (health + identity record, #1903)",
);
const nextWasFree = !(await canConnect(port + 1));
const r = await runHook(distScript, port, xdg);
assert.equal(r.code, 0, "the hook stays non-fatal for claude even when its proxy cannot start");
assert.match(r.stderr, /bring-up failed/, "fail-fast is loud");
assert.match(r.stderr, /lifecycle-less bili proxy/, "the refusal names the lane-less occupant");
assert.match(r.stderr, /attachExternal/, "the remedy is actionable (attachExternal opt-in)");
assert.ok(await canConnect(port), "the user's daemon survives untouched");
assert.equal(nextWasFree, !(await canConnect(port + 1)), "nothing may have port-hopped behind the refusal");
} finally {
if (squatter > 1) killPid(squatter);
await rmHome(home);
}
});

function spawnProxy(distCli: string, port: number, env: NodeJS.ProcessEnv): number {
const child = spawn(process.execPath, [distCli, "start", "--host", "127.0.0.1", "--port", String(port)], { env, stdio: "ignore" });
return child.pid ?? 0;
Expand Down
Loading
Loading