From 82afc36ad30639a19ea9b0caee6d2b848ba8a41e Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 21 Oct 2026 07:39:22 +0800 Subject: [PATCH] devin: identity.test waits for macOS's first-run check of its fake CLI before the tests (#268) Cause: the fake devin CLI is a shell script written when the file loads, and macOS checks a new executable the first time it runs (com.apple. provenance; ~0.3s on an idle machine, measured, the second run 0.01s). The first test that runs the CLI ("when Devin can't tell, ...") paid that check inside its 30s bound, and on a loaded machine the check took longer. Its CLI then outlived it and wrote "auth status" into the one shared cli.log, which the next tests read as their own call list. Now beforeAll runs the fake once and waits for it to exit (the state, not a duration; a 10-minute hook bound only so a broken exec can't hang the run), so no test's time holds the check. Each test's runs go to a log of its own (FAKE_LOG), so a run a test left behind can't land in the next test's list. Run on macOS arm64, bun 1.4.2: - Injected: the fake slept 35s on its first run only (a slow first-run check). origin/main's test: red, "when Devin can't tell" timed out after 30000ms, as in the issue. With this change: 11 pass, 0 fail (35.6s). - Loaded: 6 parallel loops of 10 fresh `bun test packages/devin/identity.test.mjs` (each a new script, so each pays the check) at load average ~55: 0 of 60 runs failed; earlier 8 x 15: 0 of 120. (--rerun-each doesn't apply: the plugin's per-key caches outlive a rerun, red on origin/main too.) - `HOME=$(mktemp -d) bun test` from the root: 1920 pass, 0 fail. `bun scripts/check.mjs`: ok. Test-only, no version bump. --- packages/devin/identity.test.mjs | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/packages/devin/identity.test.mjs b/packages/devin/identity.test.mjs index f4323cf..994332a 100644 --- a/packages/devin/identity.test.mjs +++ b/packages/devin/identity.test.mjs @@ -4,7 +4,8 @@ // browser sign-in after its own account, and "Add another Devin account" // replaced the first account's key with the second's (#17). Its model list // is the CLI's own account's there too, so it isn't taken for the key's. -import { afterAll, afterEach, beforeEach, expect, test } from "bun:test" +import { afterAll, afterEach, beforeAll, beforeEach, expect, test } from "bun:test" +import { spawn } from "node:child_process" import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs" import { tmpdir } from "node:os" import { join } from "node:path" @@ -14,16 +15,19 @@ const real = globalThis.fetch const env = { ...process.env } const tmp = mkdtempSync(join(tmpdir(), "devin-identity-")) const bin = join(tmp, "bin") -const log = join(tmp, "cli.log") mkdirSync(bin) +// each test's CLI runs go to a log of its own: a run a test left behind +// can't land in the next test's list +let log = "" +let logs = 0 // a devin CLI signed in as a@x.dev: `auth status` reads the data folder it // is given when FAKE_HONOURS is set, and its own (as on Windows) when not; -// `models list` lists one family, and every run is logged +// `models list` lists one family, and every run is logged in FAKE_LOG writeFileSync( join(bin, "devin"), `#!/bin/sh -echo "$*" >> "${log}" +echo "$*" >> "$FAKE_LOG" if [ "$1" = auth ]; then if [ -n "$FAKE_HONOURS" ]; then f="$XDG_DATA_HOME/devin/credentials.toml"; else f="${tmp}/own/devin/credentials.toml"; fi printf 'Logged in (via Devin).\\n\\nCredentials:\\n File: %s\\n\\nUser:\\n Email: %s\\n\\nAccount:\\n Tier: Devin Pro\\n' "$f" "${"$"}{FAKE_EMAIL:-a@x.dev}" @@ -34,17 +38,27 @@ echo '{"families":[{"family_uid":"cli-only","family_label":"CLI Only","variants" ) chmodSync(join(bin, "devin"), 0o755) +// macOS checks a script the first time it is run, and a loaded machine can +// keep that check past any one test's bound (#268): the check is waited +// for here, by running the fake once, so no test's time holds it +beforeAll(async () => { + if (process.platform === "win32") return + const p = spawn(join(bin, "devin"), ["--version"], { env: { ...process.env, FAKE_LOG: "/dev/null" }, stdio: "ignore" }) + await new Promise((resolve, reject) => p.on("error", reject).on("close", resolve)) +}, 10 * 60_000) + beforeEach(() => { + log = join(tmp, `cli-${++logs}.log`) + process.env.FAKE_LOG = log process.env.PATH = bin + ":" + env.PATH process.env.XDG_CACHE_HOME = join(tmp, "cache") delete process.env.FAKE_HONOURS delete process.env.FAKE_EMAIL - rmSync(log, { force: true }) asked.length = 0 }) afterEach(() => { globalThis.fetch = real - for (const k of ["PATH", "XDG_CACHE_HOME", "FAKE_HONOURS", "FAKE_EMAIL"]) env[k] === undefined ? delete process.env[k] : (process.env[k] = env[k]) + for (const k of ["PATH", "XDG_CACHE_HOME", "FAKE_HONOURS", "FAKE_EMAIL", "FAKE_LOG"]) env[k] === undefined ? delete process.env[k] : (process.env[k] = env[k]) }) afterAll(() => rmSync(tmp, { recursive: true, force: true })) @@ -67,8 +81,8 @@ const statusOf = (email, tier) => Response.json({ userStatus: { name: email.split("@")[0], email, teamsTier: tier, planStatus: { planInfo: { planName: "Pro" } } } }) const unix = process.platform !== "win32" -// a script just written can take seconds to start the first time (macOS -// checks it) +// runCLI's own bound: the fake answers at once once beforeAll has had it +// checked const SLOW = 30_000 test.if(unix)("a second account is named as Devin names its key, not as the CLI's own account", async () => {