From 29ceed20c9cdfcac53e2695681302caec574c68d Mon Sep 17 00:00:00 2001 From: yetone Date: Mon, 9 Nov 2026 06:12:13 +0800 Subject: [PATCH] doubao-work: test the sign-in and the app start on every OS c1ed1b51's publish run went red on ubuntu: the sign-in test read the real binary(), which is "" off macOS, so the callback said "macOS only". Its App test spawned /bin/sh, which Windows doesn't have. Both passed on mote (macOS) only. createPlugin takes appBinary (default binary()), and the sign-in test gives each case: a Mac path signs in, "" says macOS only. A new test holds binary() per platform and DOUBAO_WORK_APP. The App test uses a file it makes. Run: bun test packages/doubao-work, 25 pass on mote (temp HOME, as CI), wsl-run (Ubuntu 24.04) and win-run (Windows 11). bun scripts/check.mjs ok. --- packages/doubao-work/doubao-work.test.mjs | 30 +++++++++++++++++++---- packages/doubao-work/index.mjs | 4 +-- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/packages/doubao-work/doubao-work.test.mjs b/packages/doubao-work/doubao-work.test.mjs index 4f0b617..75eb01a 100644 --- a/packages/doubao-work/doubao-work.test.mjs +++ b/packages/doubao-work/doubao-work.test.mjs @@ -3,7 +3,7 @@ import fs from "node:fs" import os from "node:os" import path from "node:path" import { App, Page } from "./cdp.mjs" -import { Doubao, NEW_TASK, CLOUD, READ, STATE, owns, usageOf } from "./doubao.mjs" +import { Doubao, NEW_TASK, CLOUD, READ, STATE, binary, owns, usageOf } from "./doubao.mjs" import { Streamer, sse, completion } from "./openai.mjs" import { flatten, parse, heldFrom } from "./prompt.mjs" import { _internal as I } from "./index.mjs" @@ -141,6 +141,21 @@ test("usageOf adds Doubao's prompt counts", () => { expect(usageOf("nope")).toBe(0) }) +test("the app is found on macOS only, or where DOUBAO_WORK_APP says", () => { + const was = process.env.DOUBAO_WORK_APP + delete process.env.DOUBAO_WORK_APP + try { + expect(binary("darwin")).toBe("/Applications/Doubao.app/Contents/MacOS/Doubao") + expect(binary("linux")).toBe("") + expect(binary("win32")).toBe("") + process.env.DOUBAO_WORK_APP = "/opt/doubao" + expect(binary("linux")).toBe("/opt/doubao") + } finally { + if (was === undefined) delete process.env.DOUBAO_WORK_APP + else process.env.DOUBAO_WORK_APP = was + } +}) + test("owns knows Doubao's chat page", () => { expect(owns([{ url: "doubao://doubao-chat/chat" }])).toBe(true) expect(owns([{ url: "chrome://newtab" }, { url: "https://doubao-chat/chat" }])).toBe(false) @@ -232,10 +247,12 @@ test("App reuses its own running app and never drives a port someone else took", const dir = fs.mkdtempSync(path.join(os.tmpdir(), "dw-")) try { fs.writeFileSync(path.join(dir, "port"), "4567") + const bin = path.join(dir, "app") + fs.writeFileSync(bin, "") const spawned = [] const mk = (pages) => new App({ - binary: "/bin/sh", + binary: bin, dataDir: dir, owns, spawn: (...a) => { spawned.push(a); return { unref() {} } }, @@ -334,11 +351,14 @@ test("the plugin passes a sign-out on for re-sign-in and other failures as HTTP }) test("sign-in waits for the Doubao window's account", async () => { - const ok = I.createPlugin({ doubao: { waitSignedIn: async () => ({ signedIn: true, name: "yetone" }) } }) + const mac = () => "/Applications/Doubao.app/Contents/MacOS/Doubao" + const ok = I.createPlugin({ appBinary: mac, doubao: { waitSignedIn: async () => ({ signedIn: true, name: "yetone" }) } }) const r = await (await ok.auth.methods[0].authorize()).callback() expect(r).toMatchObject({ type: "success", accountId: "豆包工作 · yetone" }) - const late = I.createPlugin({ doubao: { waitSignedIn: async () => null } }) - expect(await (await late.auth.methods[0].authorize()).callback()).toMatchObject({ type: "failed" }) + const late = I.createPlugin({ appBinary: mac, doubao: { waitSignedIn: async () => null } }) + expect(await (await late.auth.methods[0].authorize()).callback()).toMatchObject({ type: "failed", error: expect.stringContaining("五分钟") }) + const linux = I.createPlugin({ appBinary: () => "", doubao: { waitSignedIn: async () => ({ signedIn: true, name: "x" }) } }) + expect(await (await linux.auth.methods[0].authorize()).callback()).toMatchObject({ type: "failed", error: expect.stringContaining("macOS") }) }) test("an abort between two polls stops the ask too", async () => { diff --git a/packages/doubao-work/index.mjs b/packages/doubao-work/index.mjs index bcbb087..0161926 100644 --- a/packages/doubao-work/index.mjs +++ b/packages/doubao-work/index.mjs @@ -22,7 +22,7 @@ function models() { return out } -export function createPlugin({ doubao = new Doubao(), newId } = {}) { +export function createPlugin({ doubao = new Doubao(), newId, appBinary = binary } = {}) { const failed = (e) => { if (e?.signIn) throw e if (e?.name === "AbortError" || e?.name === "TimeoutError") throw e @@ -46,7 +46,7 @@ export function createPlugin({ doubao = new Doubao(), newId } = {}) { method: "auto", instructions: "将打开一个单独的豆包窗口(不影响你平时用的豆包)。请在其中登录,登录后回到这里。", callback: async () => { - if (!binary()) return { type: "failed", error: "豆包工作插件目前只支持 macOS 上的豆包桌面版。" } + if (!appBinary()) return { type: "failed", error: "豆包工作插件目前只支持 macOS 上的豆包桌面版。" } let s try { s = await doubao.waitSignedIn()