inkstone 0.1.1: the fake-browser test deletes its 59 MB build, and the wait test fails when the title is read off Windows

Two of #824's three points, in the same 0.1.1 as #825.

1. fake-browser.test.mjs compiled a ~59 MB fake Chromium into a new
   $TMPDIR folder every run and never removed it. afterAll now removes
   that folder with the profile.
2. "off Windows the login wait ends on process exit, never on a title"
   passed with the Windows-only title check turned on for every OS:
   the title read starts after 5 s and windowTitleOf returns "" off
   Windows anyway. waitForConsoleWindow takes titleOf and settleMs
   (defaults: windowTitleOf, 5000, the same as before), and a new test
   gives it a title that shows the console at once: on darwin and linux
   the wait times out with the title never read; on win32 the same
   title ends it with "console", so the check is not empty.

Not done: point 3, the comment line that appears twice in the shared
opencode2 adapter, is in every package's copy, not inkstone's alone.
#824 stays open for it.

Run on mote (macOS) through mote-run, HOME=$(mktemp -d), at this tree:
- packages/inkstone: bun test: 71 pass, 0 fail.
- bun scripts/check.mjs inkstone: ✓ registry.json, ✓ inkstone.
- repo root bun test: 6755 pass, 20 skip, 0 fail across 489 files.
  (A first root run with TMPDIR also moved had 20 devin reds from
  devin's own HOME-under-tmpdir guard; that was the run's setup, and the
  rerun with HOME only is the record.)
- inkstone-fake-browser-* folders in mote's $TMPDIR: 6 before the root
  run, 6 after.

Broken by hand, each on mote:
- canReadTitle = true on every OS: the new test is red (Expected
  "timeout", Received "console"); the old test still passes.
- fakeDir left out of afterAll's cleanup: fake-browser.test.mjs passes
  and the folder count goes 6 to 7.

Not tried: the cleanup on Windows (rmSync with retries, in a try).

Refs #824
This commit is contained in:
yetone
2026-11-07 16:05:41 +08:00
parent 3ae528f031
commit 02aae692bc
3 changed files with 36 additions and 6 deletions
+22
View File
@@ -116,3 +116,25 @@ test('off Windows the login wait ends on process exit, never on a title', async
}
})
test('the window title is read on Windows only, even when it already shows the console (#824)', async () => {
const { spawn } = await import('node:child_process')
const child = spawn(process.execPath, ['-e', 'setInterval(() => {}, 10000)'], { stdio: 'ignore' })
try {
// a title that would end the wait at once, if anything read it
let reads = 0
const titleOf = () => {
reads += 1
return '书生·端砚 Intern InkStone'
}
for (const platform of ['darwin', 'linux']) {
reads = 0
expect(await waitForConsoleWindow(child, { platform, titleOf, settleMs: 0, timeoutMs: 200, pollMs: 20 })).toBe('timeout')
expect(reads).toBe(0)
}
// the same title does end it on Windows, so the check above is not empty
expect(await waitForConsoleWindow(child, { platform: 'win32', titleOf, settleMs: 0, timeoutMs: 2000, pollMs: 20 })).toBe('console')
} finally {
try { child.kill() } catch {}
}
})
+9 -4
View File
@@ -13,13 +13,15 @@ import { renewSilently } from "./lib/browser.mjs"
import { fakeInkStone, json, ok, fail } from "./fake.mjs"
let fakeExe = ""
let fakeDir = ""
let profile = ""
const savedEnv = {}
let f
beforeAll(() => {
// compile the fake browser once (bun build --compile takes under a second)
const out = join(mkdtempSync(join(tmpdir(), "inkstone-fake-browser-")), process.platform === "win32" ? "fake-chrome.exe" : "fake-chrome")
fakeDir = mkdtempSync(join(tmpdir(), "inkstone-fake-browser-"))
const out = join(fakeDir, process.platform === "win32" ? "fake-chrome.exe" : "fake-chrome")
const entry = join(import.meta.dir, "testdata/fake-browser.mjs")
execSync(`${JSON.stringify(process.execPath)} build --compile ${JSON.stringify(entry)} --outfile ${JSON.stringify(out)}`, { stdio: "pipe" })
fakeExe = out
@@ -42,9 +44,12 @@ afterAll(() => {
if (value === undefined) delete process.env[key]
else process.env[key] = value
}
try {
rmSync(profile, { recursive: true, force: true })
} catch {}
// the compiled fake is ~59 MB: never leave it behind (#824)
for (const dir of [profile, fakeDir]) {
try {
if (dir) rmSync(dir, { recursive: true, force: true, maxRetries: 5, retryDelay: 200 })
} catch {}
}
})
afterEach(() => {
+5 -2
View File
@@ -531,7 +531,10 @@ export async function closeWindowGracefully(child, { timeoutMs = 15_000, log = (
* 登录窗口的完成等待。可测试:`platform` 参数让非 Windows 的"只认进程退出"
* 行为在任何宿主上都能被验证。
*/
export async function waitForConsoleWindow(child, { timeoutMs = 8 * 60_000, pollMs = 1000, signal, log = () => {}, platform = process.platform } = {}) {
export async function waitForConsoleWindow(
child,
{ timeoutMs = 8 * 60_000, pollMs = 1000, signal, log = () => {}, platform = process.platform, titleOf = windowTitleOf, settleMs = 5000 } = {},
) {
const deadline = Date.now() + timeoutMs
const started = Date.now()
// 窗口标题只能靠 Windows 的 Get-Process 读;别的平台就以“用户关掉窗口”
@@ -546,7 +549,7 @@ export async function waitForConsoleWindow(child, { timeoutMs = 8 * 60_000, poll
continue
}
// 只看我们自己的窗口;并且给它至少 5 秒,控制台标题在跳转 SSO 前会闪一下。
const title = Date.now() - started > 5000 ? windowTitleOf(child.pid) : ""
const title = Date.now() - started >= settleMs ? titleOf(child.pid) : ""
if (title && /Intern InkStone|端砚/i.test(title) && !/用户认证|登录/i.test(title)) {
hits += 1
if (hits >= 2) return "console"