From a90b7aa41d6a5d186a625ecff0959c12de900c19 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 5 Nov 2026 12:24:27 +0800 Subject: [PATCH] =?UTF-8?q?workbuddy=200.2.21:=20the=20sign-in=20page=20op?= =?UTF-8?q?ens=20at=20the=20desktop's=20version,=20so=20=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=20shows=20(shenyebuwu)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit shenyebuwu (Discord #general) signs in to WorkBuddy with 企业微信 (WeCom), and the plugin's sign-in page offered no WeCom entry. The plugin opened www.workbuddy.cn/login with version=2.0.0. WorkBuddy desktop opens the same /v2/plugin/auth/state page with version set to its own app version (openAuthUrl: version = CLIENT_INFO_PLUGIN_VERSION, which the desktop sets to the app's version; read from WorkBuddy.app's app.asar). The login page's signin-callback chunk shows WeCom to platform workbuddy only at version >= "5.8.0" (Le/tn, Jt="5.8.0"), so 2.0.0 hid it. The page now opens with site.app (5.9.3, the version the requests already carry), for both builds, as the desktop does. Run (mote, bun 1.4.2, HOME=$(mktemp -d)): packages/workbuddy bun test, 321 pass 0 fail; bun scripts/check.mjs workbuddy ok. Broken by hand: version put back to "2.0.0", wecom.test.mjs 3 of 3 red. Real page (Playwright Chromium on mote, a fresh state from copilot.tencent.com): version=2.0.0 lists 微信 手机号 SSO QQ 邮箱; version=5.9.3 lists 企业微信 too. Not tried: a real WeCom sign-in to the end (no WeCom account, no credentials entered); the WorkBuddy AI page with WeCom (its gate is the China platform's only). --- packages/workbuddy/index.mjs | 8 ++++-- packages/workbuddy/package.json | 2 +- packages/workbuddy/wecom.test.mjs | 42 +++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 packages/workbuddy/wecom.test.mjs diff --git a/packages/workbuddy/index.mjs b/packages/workbuddy/index.mjs index a227ea4..c916595 100644 --- a/packages/workbuddy/index.mjs +++ b/packages/workbuddy/index.mjs @@ -15,7 +15,6 @@ import { homedir } from "node:os" import { isAbsolute, join } from "node:path" import { gzipSync } from "node:zlib" -const APP_VERSION = "2.0.0" // the version WorkBuddy's sign-in page is opened with const POLL_MS = 1000 const SIGN_IN_MS = 5 * 60 * 1000 const EARLY_MS = 60 * 1000 // a token this close to its end is refreshed before a request @@ -1755,7 +1754,12 @@ async function browserSignIn(site) { if (!state?.state || !state?.authUrl) throw new Error(`${site.name} gave no sign-in page`) const url = new URL(state.authUrl) if (url.protocol !== "https:") throw new Error(`${site.name}'s sign-in page isn't https`) - url.searchParams.set("version", APP_VERSION) + // the desktop app's own version, as WorkBuddy desktop opens it + // (openAuthUrl: version = CLIENT_INFO_PLUGIN_VERSION, the app's version). + // The China build's page hides 企业微信 (WeCom) for a version under 5.8.0 + // (its signin-callback chunk: platform workbuddy and version >= "5.8.0"), + // so the 2.0.0 sent before offered no WeCom sign-in (shenyebuwu on Discord) + url.searchParams.set("version", site.app) url.searchParams.set("loginSessionId", hex()) return { url: url.toString(), diff --git a/packages/workbuddy/package.json b/packages/workbuddy/package.json index d5e01ad..64f3e0b 100644 --- a/packages/workbuddy/package.json +++ b/packages/workbuddy/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-workbuddy-auth", - "version": "0.2.20", + "version": "0.2.21", "description": "OpenCode provider plugins for WorkBuddy's plans: WorkBuddy (CodeBuddy, copilot.tencent.com) and WorkBuddy AI (www.workbuddy.ai)", "type": "module", "main": "./opencode.mjs", diff --git a/packages/workbuddy/wecom.test.mjs b/packages/workbuddy/wecom.test.mjs new file mode 100644 index 0000000..7c67266 --- /dev/null +++ b/packages/workbuddy/wecom.test.mjs @@ -0,0 +1,42 @@ +// The sign-in page is opened with the desktop app's version, as WorkBuddy +// desktop opens it. WorkBuddy's China login page (www.workbuddy.cn/login) +// shows 企业微信 (WeCom) only to platform workbuddy at version 5.8.0 or +// later, so a lower version leaves a WeCom user no way to sign in +// (shenyebuwu on Discord). +import { afterEach, expect, test } from "bun:test" +import { _internal } from "./index.mjs" + +const real = globalThis.fetch +afterEach(() => (globalThis.fetch = real)) + +const opened = async (id) => { + globalThis.fetch = async (url) => { + const u = new URL(String(url)) + const data = u.pathname.endsWith("/auth/state") + ? { state: "s", authUrl: `https://www.workbuddy.cn/login?platform=${id}&state=s` } + : {} + return new Response(JSON.stringify({ code: 0, data })) + } + return new URL((await _internal.browserSignIn(_internal.SITES[id])).url) +} + +// the page's own check (signin-callback: en(version, "5.8.0")) +const atLeast = (v, min) => { + const a = v.split(".").map(Number), b = min.split(".").map(Number) + for (let i = 0; i < 3; i++) if (a[i] !== b[i]) return a[i] > b[i] + return true +} + +for (const id of ["workbuddy", "workbuddy-ai"]) { + test(`${id}'s sign-in page is opened with the desktop app's version`, async () => { + const url = await opened(id) + expect(url.searchParams.get("version")).toBe(_internal.SITES[id].app) + expect(url.searchParams.get("platform")).toBe(id) + expect(url.searchParams.get("state")).toBe("s") + }) +} + +test("the China build's page is opened at a version that shows WeCom", async () => { + const url = await opened("workbuddy") + expect(atLeast(url.searchParams.get("version"), "5.8.0")).toBe(true) +})