Files
yetone a90b7aa41d workbuddy 0.2.21: the sign-in page opens at the desktop's version, so 企业微信 shows (shenyebuwu)
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).
2026-11-05 12:24:27 +08:00

43 lines
1.6 KiB
JavaScript

// 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)
})