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).
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
Reference in New Issue
Block a user