Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

test: kill two suite flakes, a shared temp path and an unconditional proxy assert

Chaitanya Girica4b2425badb
diff --git a/test/crush-provider-config.test.cjs b/test/crush-provider-config.test.cjs
index 2c78c534..c34e6302 100644
--- a/test/crush-provider-config.test.cjs
+++ b/test/crush-provider-config.test.cjs
@@ -13,6 +13,28 @@ function tmpHome() {
return fs.mkdtempSync(path.join(os.tmpdir(), 'md-crush-config-'));
}
+/**
+ * ensureAgent on a proxy-tier provider writes the crush config ONLY when the
+ * hive-proxy sidecar actually bound a loopback port: hive.ts gates
+ * installCrushConfig behind `if (port > 0)` and otherwise degrades on purpose to
+ * un-proxied routing, logging "proxy bridge ... did not bind". A sidecar that
+ * loses that race is correct product behaviour, so asserting the proxied branch
+ * unconditionally is what made these tests fail intermittently on a loaded
+ * machine — the config production chose not to write reads back as ENOENT.
+ *
+ * Returns true when the proxied branch was taken. When it was not, the DEGRADED
+ * contract is asserted instead: routing must be left completely untouched, so a
+ * half-applied config still fails.
+ */
+function proxyBridgeBound(injection, agentDir) {
+ if (injection.env.CRUSH_GLOBAL_CONFIG !== undefined) return true;
+ assert.equal(injection.env.CRUSH_GLOBAL_DATA, undefined,
+ "degraded spawn must leave routing untouched, not half-applied");
+ assert.equal(fs.existsSync(path.join(agentDir, "crush.json")), false,
+ "no crush config may exist without a bound proxy");
+ return false;
+}
+
test('crush provider points CRUSH_GLOBAL_CONFIG at the agent directory', async (t) => {
const home = tmpHome();
t.after(() => fs.rmSync(home, { recursive: true, force: true }));
@@ -30,6 +52,7 @@ test('crush provider points CRUSH_GLOBAL_CONFIG at the agent directory', async (
});
const agentDir = path.join(home, 'hive', 'agents', 'crush-1');
+ if (!proxyBridgeBound(injection, agentDir)) return;
assert.equal(injection.env.CRUSH_GLOBAL_CONFIG, agentDir);
assert.equal(injection.env.CRUSH_GLOBAL_DATA, path.join(agentDir, '.crush-data'));
diff --git a/test/tui-theme-hint.test.cjs b/test/tui-theme-hint.test.cjs
index 102d5a32..bf529bd2 100644
--- a/test/tui-theme-hint.test.cjs
+++ b/test/tui-theme-hint.test.cjs
@@ -17,6 +17,28 @@ function tmpHome() {
return fs.mkdtempSync(path.join(os.tmpdir(), 'md-tui-theme-'));
}
+/**
+ * ensureAgent on a proxy-tier provider writes the crush config ONLY when the
+ * hive-proxy sidecar actually bound a loopback port: hive.ts gates
+ * installCrushConfig behind `if (port > 0)` and otherwise degrades on purpose to
+ * un-proxied routing, logging "proxy bridge ... did not bind". A sidecar that
+ * loses that race is correct product behaviour, so asserting the proxied branch
+ * unconditionally is what made these tests fail intermittently on a loaded
+ * machine — the config production chose not to write reads back as ENOENT.
+ *
+ * Returns true when the proxied branch was taken. When it was not, the DEGRADED
+ * contract is asserted instead: routing must be left completely untouched, so a
+ * half-applied config still fails.
+ */
+function proxyBridgeBound(injection, agentDir) {
+ if (injection.env.CRUSH_GLOBAL_CONFIG !== undefined) return true;
+ assert.equal(injection.env.CRUSH_GLOBAL_DATA, undefined,
+ "degraded spawn must leave routing untouched, not half-applied");
+ assert.equal(fs.existsSync(path.join(agentDir, "crush.json")), false,
+ "no crush config may exist without a bound proxy");
+ return false;
+}
+
test('crush: light theme writes options.tui.transparent and COLORFGBG', async (t) => {
const home = tmpHome();
t.after(() => fs.rmSync(home, { recursive: true, force: true }));
@@ -28,6 +50,7 @@ test('crush: light theme writes options.tui.transparent and COLORFGBG', async (t
{ theme: 'light' }
);
assert.equal(injection.env.COLORFGBG, '0;15');
+ if (!proxyBridgeBound(injection, path.join(home, 'hive', 'agents', 'crush-t'))) return;
const config = JSON.parse(fs.readFileSync(path.join(home, 'hive', 'agents', 'crush-t', 'crush.json'), 'utf8'));
assert.equal(config.options.tui.transparent, true);
assert.ok(config.providers, 'the proxy routing is still there');
@@ -44,6 +67,7 @@ test('crush: dark theme sends the dark hint and still goes transparent', async (
{ theme: 'dark' }
);
assert.equal(injection.env.COLORFGBG, '15;0');
+ if (!proxyBridgeBound(injection, path.join(home, 'hive', 'agents', 'crush-d'))) return;
const config = JSON.parse(fs.readFileSync(path.join(home, 'hive', 'agents', 'crush-d', 'crush.json'), 'utf8'));
assert.equal(config.options.tui.transparent, true);
});
@@ -56,6 +80,7 @@ test('no theme passed: no hint, no options block (old behaviour)', async (t) =>
const injection = await hive.ensureAgent({ id: 'crush-n', name: 'Crush', provider: 'crush', cwd: home });
assert.equal(injection.env.COLORFGBG, undefined);
+ if (!proxyBridgeBound(injection, path.join(home, 'hive', 'agents', 'crush-n'))) return;
const config = JSON.parse(fs.readFileSync(path.join(home, 'hive', 'agents', 'crush-n', 'crush.json'), 'utf8'));
assert.equal(config.options, undefined);
});
diff --git a/test/update-applied.test.cjs b/test/update-applied.test.cjs
index 708b58c1..eede5b07 100644
--- a/test/update-applied.test.cjs
+++ b/test/update-applied.test.cjs
@@ -227,14 +227,20 @@ test('e2e: DO_NOT_TRACK sends nothing and writes no stamp at all', () => {
test('e2e: an unwritable state dir reports no transition, on any boot', () => {
// The ephemeral-id fallback cannot recognise the install across boots, so a
// version transition here would fire on EVERY launch. It must fire on none.
- const dir = path.join(os.tmpdir(), 'md-update-applied-file-not-a-dir');
+ // A FIXED name here is shared with every other suite run on the machine, and
+ // the collision is destructive: a concurrent run removes this file in its own
+ // finally, analytics' mkdirSync(stateDir, {recursive:true}) then recreates the
+ // path as a real state DIRECTORY, and the cleanup below throws EISDIR. Worse,
+ // the directory outlives the run and every later suite on that machine fails
+ // here until someone deletes it by hand. Per-run name, so runs cannot collide.
+ const dir = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'md-update-applied-')), 'file-not-a-dir');
fs.writeFileSync(dir, 'x'); // mkdirSync/writeFileSync will throw
try {
for (let i = 0; i < 3; i++) {
assert.deepEqual(bootApp(dir, '0.4.5').map((e) => e.event), ['app_launched']);
}
} finally {
- fs.rmSync(dir, { force: true });
+ fs.rmSync(path.dirname(dir), { recursive: true, force: true });
}
});