From f7defe4f45957b9cc094e9965091156709a764e9 Mon Sep 17 00:00:00 2001 From: audit Date: Thu, 12 Nov 2026 17:42:51 +0800 Subject: [PATCH] feat(dingtalk): offer signing in to another organization while connected dws keeps one account per organization and user and signs in to another one with the same `auth login`, but the connected section only offered sign-out. It now also offers signing in to another organization through the existing `sign-in` operation; the check that follows shows the account dws reports as current. The Web E2E's stand-in dws makes a second organization's account current after its second sign-in, and the READMEs say that choosing among saved accounts stays with `dws profile switch` in the terminal. --- apps/web/tests/dingtalk-connection.e2e.ts | 27 ++++++++++++++----- packages/connector/dingtalk/README.i18n.yaml | 8 +++--- packages/connector/dingtalk/README.md | 4 +-- packages/connector/dingtalk/README.zh.md | 4 +-- packages/connector/dingtalk/src/locales.ts | 8 ++++++ .../connector/dingtalk/src/presentation.ts | 14 +++++----- .../dingtalk/tests/presentation.spec.ts | 14 ++++++---- 7 files changed, 54 insertions(+), 25 deletions(-) diff --git a/apps/web/tests/dingtalk-connection.e2e.ts b/apps/web/tests/dingtalk-connection.e2e.ts index 56a37ecaf4..d9927eaf08 100644 --- a/apps/web/tests/dingtalk-connection.e2e.ts +++ b/apps/web/tests/dingtalk-connection.e2e.ts @@ -16,20 +16,26 @@ const authUrl = (attempt: number) => `${AUTH_PAGE}?e2e=${String(attempt)}&state= // The stand-in keeps its sign-in in state.json beside itself. auth login prints a // new authorization link alone on an indented stderr line for each attempt and -// waits until the test marks the page visited; auth logout accepts only the -// signed-in account's profile. +// waits until the test marks the page visited; its second successful sign-in +// makes a second organization's account current, as the stand-in's own rule; +// auth logout accepts only the current account's profile. const DWS = `#!/usr/bin/env node const { existsSync, readFileSync, writeFileSync } = require('node:fs') const { join } = require('node:path') const dir = __dirname const statePath = join(dir, 'state.json') -const state = existsSync(statePath) ? JSON.parse(readFileSync(statePath, 'utf8')) : { signedIn: false, attempts: 0 } +const state = existsSync(statePath) ? JSON.parse(readFileSync(statePath, 'utf8')) : { signedIn: false, attempts: 0, logins: 0 } +const ACCOUNTS = [ + { corp_id: 'corp-e2e', corp_name: 'E2E 组织', user_id: 'user-e2e', user_name: 'E2E 用户' }, + { corp_id: 'corp-e2e-2', corp_name: '第二个 E2E 组织', user_id: 'user-e2e-2', user_name: '第二个 E2E 用户' }, +] +const current = () => ACCOUNTS[Math.min(state.logins, ACCOUNTS.length) - 1] const save = () => { writeFileSync(statePath, JSON.stringify(state)) } const json = (value) => JSON.stringify(value, null, 2) + '\\n' switch (process.argv.slice(2).join(' ')) { case 'auth status --format json': process.stdout.write(json(state.signedIn - ? { success: true, authenticated: true, corp_id: 'corp-e2e', corp_name: 'E2E 组织', user_id: 'user-e2e', user_name: 'E2E 用户' } + ? { success: true, authenticated: true, ...current() } : { success: true, authenticated: false, message: '未登录' })) break case 'auth login --no-browser --format json': { @@ -44,13 +50,14 @@ switch (process.argv.slice(2).join(' ')) { process.exitCode = 2 } else { state.signedIn = true + state.logins += 1 save() process.stdout.write(json({ success: true, message: '登录成功' })) } }, 50) break } - case 'auth logout --profile corp-e2e:user-e2e': + case state.signedIn ? 'auth logout --profile ' + current().corp_id + ':' + current().user_id : 'auth logout': state.signedIn = false save() process.stdout.write('[OK] 已清除认证信息\\n') @@ -102,7 +109,7 @@ describe.skipIf(process.platform === 'win32')('web e2e: DingTalk plugin account' if (binDir !== undefined) await rm(binDir, { recursive: true, force: true }) }) - it('reports a failed sign-in without its output, connects on retry, and signs out after confirmation', async () => { + it('reports a failed sign-in without its output, connects on retry, signs in to another organization, and signs out after confirmation', async () => { onTestFailed(() => saveFailureShot(page, 'web-e2e-dingtalk-connection')) await page.getByRole('navigation', { name: '全局面板' }).getByRole('button', { name: '插件', exact: true }).click() const panel = page.locator('[data-plugin-panel]') @@ -128,6 +135,14 @@ describe.skipIf(process.platform === 'win32')('web e2e: DingTalk plugin account' await section.getByText('已登录为 E2E 组织 的 E2E 用户。可以在对话中直接请 Agent 使用钉钉。', { exact: true }).waitFor({ timeout: 10_000 }) await page.getByText('钉钉已连接', { exact: true }).waitFor({ timeout: 10_000 }) + // Signing in again while connected adds another organization's account; the section shows the account dws then reports. + await rm(join(binDir, 'auth-visited')) + await section.getByRole('button', { name: '登录其他组织', exact: true }).click() + await expect.poll(() => section.getAttribute('data-connector-account'), { timeout: 20_000 }).toBe('connecting') + await expect.poll(() => section.getAttribute('data-connector-account'), { timeout: 20_000 }).toBe('connected') + expect(opened.map(popup => popup.url())).toEqual([authUrl(1), authUrl(2), authUrl(3)]) + await section.getByText('已登录为 第二个 E2E 组织 的 第二个 E2E 用户。可以在对话中直接请 Agent 使用钉钉。', { exact: true }).waitFor({ timeout: 10_000 }) + await section.getByRole('button', { name: '退出登录', exact: true }).click() const dialog = page.getByRole('dialog', { name: '退出钉钉登录?' }) await dialog.getByRole('button', { name: '退出登录', exact: true }).click() diff --git a/packages/connector/dingtalk/README.i18n.yaml b/packages/connector/dingtalk/README.i18n.yaml index 92cc4dcb30..04b9f292ea 100644 --- a/packages/connector/dingtalk/README.i18n.yaml +++ b/packages/connector/dingtalk/README.i18n.yaml @@ -24,8 +24,8 @@ en: d68b9188466daf73 zh: 28b8525daf958bd6 /deepseek-ai-dsh-dingtalk/use-this-package/account-operations: - en: 0f1b4943717669b5 - zh: 9ac457c359bdbc84 + en: 265eb53ad3bce84f + zh: bbd01a50493bfa18 /deepseek-ai-dsh-dingtalk/use-this-package/configure: en: 8a86cbd82f43547e zh: 6c5d6c2cc414c03e @@ -81,8 +81,8 @@ en: 2cd0ec39868022b9 zh: 21eaed1a363a3416 /deepseek-ai-dsh-dingtalk/known-limitations-and-deferred-work: - en: 9f372cd16caa49b5 - zh: 11eb1388d87fc06d + en: d3b6d8f31649afea + zh: 61afb4308c4eddc0 /deepseek-ai-dsh-dingtalk/known-limitations-and-deferred-work/dev-note: en: 7267122aef746a1c zh: a5f28e38bd85d44f diff --git a/packages/connector/dingtalk/README.md b/packages/connector/dingtalk/README.md index 1f2e257428..c65a37fe7a 100644 --- a/packages/connector/dingtalk/README.md +++ b/packages/connector/dingtalk/README.md @@ -52,7 +52,7 @@ The Plugins page drives these operations through the connector account registry, | Operation | Effect | |---|---| | `check` | Downloads dws and its skills while either is missing, then checks the account again; each browser that opens the Web app starts one when no operation runs | -| `sign-in` | Runs `auth login --no-browser --format json`, waits for the user to authorize in a browser on this computer, then checks that dws reports the account signed in | +| `sign-in` | Runs `auth login --no-browser --format json`, waits for the user to authorize in a browser on this computer, then checks that dws reports the account signed in. The connected section offers it again as signing in to another organization: dws keeps one account per organization and user, so authorizing with another account adds it, and authorizing with the current one refreshes it; the check then shows the account dws reports as current | | `sign-out` | After the user confirms, runs `auth logout --profile :` for the account the last check found, which also signs it out of the user's own terminal, then checks again | | Cancel | Cancels a sign-in while it waits for authorization, or a check while it downloads, and waits for the command or download to stop; other steps are ignored | @@ -167,7 +167,7 @@ The system prompt does not change; finishing the installation, loading or unload - Only macOS and Windows x64 are supported. The pinned Linux archives are unverified, and the release's Windows arm64 archive is not pinned. - Commands must run on this Host. When a composition runs them elsewhere, such as over SSH, the plugin still loads, and each command that runs `dws` fails because the path does not exist there. -- The plugin uses the CLI's default configuration. Signing in or out from DSH affects the user's own terminal and other programs that run dws on this computer, and there is no DSH-private account or account picker. +- The plugin uses the CLI's default configuration. Signing in or out from DSH affects the user's own terminal and other programs that run dws on this computer, and there is no DSH-private account. The page shows only the account dws reports as current and offers no picker among the saved accounts; `dws profile switch` in the terminal changes the current account. - Sign-in from the plugin page needs a browser on the computer that runs DSH, because the CLI's authorization callback listens on `127.0.0.1`. - The plugin sets no `DWS_CHANNEL`, and it is unverified with organizations that restrict CLI access to registered channels. - Unless `binDir` and `skillsDir` are both set, the first check needs network access to GitHub or Gitee, and the `dingtalk` skill is absent until it succeeds; the Gitee mirror can lag a release by days. Download sources must send `Content-Length`. diff --git a/packages/connector/dingtalk/README.zh.md b/packages/connector/dingtalk/README.zh.md index 6dd8604cff..1c96909578 100644 --- a/packages/connector/dingtalk/README.zh.md +++ b/packages/connector/dingtalk/README.zh.md @@ -52,7 +52,7 @@ dsh plugin --profile web remove @deepseek-ai/dsh-dingtalk | 操作 | 效果 | |---|---| | `check` | dws 或其技能缺失时先下载,再重新检查账号;没有操作运行时,每个打开 Web 应用的浏览器会触发一次 | -| `sign-in` | 运行 `auth login --no-browser --format json`,等待用户在这台电脑的浏览器中授权,然后检查 dws 是否报告该账号已登录 | +| `sign-in` | 运行 `auth login --no-browser --format json`,等待用户在这台电脑的浏览器中授权,然后检查 dws 是否报告该账号已登录。已连接的区块以“登录其他组织”再次提供它:dws 按组织和用户各保存一个账号,用另一个账号授权会新增该账号,用当前账号授权只刷新它;随后的检查显示 dws 报告为当前的账号 | | `sign-out` | 用户确认后,对最近一次检查发现的账号运行 `auth logout --profile :`,这也会让用户自己的终端退出该账号,然后重新检查 | | 取消 | 在登录等待授权时取消它,或在检查下载时取消下载,并等待命令或下载停止;其他步骤会被忽略 | @@ -167,7 +167,7 @@ Scripts in the DingTalk skill call `dws` by name; start only the commands that r - 仅支持 macOS 和 Windows x64。固定的 Linux 归档未经验证,release 中的 Windows arm64 归档没有固定。 - 命令必须在本 Host 上运行。组合把命令放到别处运行(例如通过 SSH)时,插件仍会加载,但每条运行 `dws` 的命令都会因为那里没有这个路径而失败。 -- 插件使用 CLI 的默认配置。在 DSH 中登录或退出登录会影响用户自己的终端,以及这台电脑上其他运行 dws 的程序,没有 DSH 专用的账号,也没有账号选择。 +- 插件使用 CLI 的默认配置。在 DSH 中登录或退出登录会影响用户自己的终端,以及这台电脑上其他运行 dws 的程序,没有 DSH 专用的账号。页面只显示 dws 报告为当前的账号,不提供在已保存账号之间选择;在终端执行 `dws profile switch` 可以更换当前账号。 - 从插件页面登录需要运行 DSH 的这台电脑上的浏览器,因为 CLI 的授权回调监听 `127.0.0.1`。 - 插件不设置 `DWS_CHANNEL`,在只允许已登记渠道访问 CLI 的组织中未经验证。 - 除非同时设置了 `binDir` 和 `skillsDir`,第一次检查需要能访问 GitHub 或 Gitee,成功之前没有 `dingtalk` skill;Gitee 镜像可能比 release 晚几天。下载源必须发送 `Content-Length`。 diff --git a/packages/connector/dingtalk/src/locales.ts b/packages/connector/dingtalk/src/locales.ts index d6f73b3d2c..ad38cc1390 100644 --- a/packages/connector/dingtalk/src/locales.ts +++ b/packages/connector/dingtalk/src/locales.ts @@ -26,6 +26,7 @@ export const zh = { 'action.open': '打开授权页面', 'action.cancel': '取消', 'action.signOut': '退出登录', + 'action.addAccount': '登录其他组织', 'action.retry': '重试', 'badge.connected': '已连接', 'badge.disconnected': '未连接', @@ -67,6 +68,7 @@ export const en: Record = { 'action.open': 'Open authorization page', 'action.cancel': 'Cancel', 'action.signOut': 'Sign out', + 'action.addAccount': 'Sign in to another organization', 'action.retry': 'Retry', 'badge.connected': 'Connected', 'badge.disconnected': 'Not connected', @@ -105,6 +107,7 @@ export const ja: Record = { 'action.open': '認可ページを開く', 'action.cancel': 'キャンセル', 'action.signOut': 'サインアウト', + 'action.addAccount': '別の組織にログイン', 'action.retry': '再試行', 'badge.connected': '接続済み', 'badge.disconnected': '未接続', @@ -143,6 +146,7 @@ export const es: Record = { 'action.open': 'Abrir página de autorización', 'action.cancel': 'Cancelar', 'action.signOut': 'Cerrar sesión', + 'action.addAccount': 'Iniciar sesión en otra organización', 'action.retry': 'Reintentar', 'badge.connected': 'Conectado', 'badge.disconnected': 'No conectado', @@ -181,6 +185,7 @@ export const fr: Record = { 'action.open': 'Ouvrir la page d’autorisation', 'action.cancel': 'Annuler', 'action.signOut': 'Se déconnecter', + 'action.addAccount': 'Se connecter à une autre organisation', 'action.retry': 'Réessayer', 'badge.connected': 'Connecté', 'badge.disconnected': 'Non connecté', @@ -219,6 +224,7 @@ export const de: Record = { 'action.open': 'Autorisierungsseite öffnen', 'action.cancel': 'Abbrechen', 'action.signOut': 'Abmelden', + 'action.addAccount': 'Bei einer anderen Organisation anmelden', 'action.retry': 'Erneut versuchen', 'badge.connected': 'Verbunden', 'badge.disconnected': 'Nicht verbunden', @@ -257,6 +263,7 @@ export const ru: Record = { 'action.open': 'Открыть страницу авторизации', 'action.cancel': 'Отмена', 'action.signOut': 'Выйти', + 'action.addAccount': 'Войти в другую организацию', 'action.retry': 'Повторить', 'badge.connected': 'Подключено', 'badge.disconnected': 'Не подключено', @@ -295,6 +302,7 @@ export const pt: Record = { 'action.open': 'Abrir página de autorização', 'action.cancel': 'Cancelar', 'action.signOut': 'Sair', + 'action.addAccount': 'Entrar em outra organização', 'action.retry': 'Tentar novamente', 'badge.connected': 'Conectado', 'badge.disconnected': 'Não conectado', diff --git a/packages/connector/dingtalk/src/presentation.ts b/packages/connector/dingtalk/src/presentation.ts index ffa2c650dc..2385092027 100644 --- a/packages/connector/dingtalk/src/presentation.ts +++ b/packages/connector/dingtalk/src/presentation.ts @@ -96,17 +96,19 @@ export function presentAccount(view: DingtalkState): ConnectorAccountDisplay { buttons: [{ label: text('action.connect'), command: SIGN_IN, variant: 'primary' }], connect: SIGN_IN, detail: text('detail.disconnected'), notes: [], ...failure, } - /* jscpd:ignore-start -- CLI app plugins that sign out offer the same confirmed sign-out button. */ case 'connected': return { phase: 'connected', status: text('status.connected'), badge: text('badge.connected'), - buttons: [{ - label: text('action.signOut'), command: SIGN_OUT, - confirm: { title: text('signOut.title'), body: text('signOut.body'), label: text('action.signOut') }, - }], + buttons: [ + // dws keeps several accounts; another sign-in adds one and makes it the current account. + { label: text('action.addAccount'), command: SIGN_IN }, + { + label: text('action.signOut'), command: SIGN_OUT, + confirm: { title: text('signOut.title'), body: text('signOut.body'), label: text('action.signOut') }, + }, + ], detail: connectedDetail(account), notes: [], ...failure, } - /* jscpd:ignore-end */ /* v8 ignore next -- closed account state union */ default: return assertNever(account) } diff --git a/packages/connector/dingtalk/tests/presentation.spec.ts b/packages/connector/dingtalk/tests/presentation.spec.ts index 1b295fb5c9..6b6bfbfc4e 100644 --- a/packages/connector/dingtalk/tests/presentation.spec.ts +++ b/packages/connector/dingtalk/tests/presentation.spec.ts @@ -57,13 +57,17 @@ it.each<[string, DingtalkState['account'], string]>([ expect(zhOf(presentAccount({ account }).detail)).toBe(detail) }) -it('asks before signing out', () => { +it('offers another sign-in while connected and asks before signing out', () => { let shown = presentAccount(CONNECTED) expect(shown).toMatchObject({ phase: 'connected', status: say('status.connected'), badge: say('badge.connected') }) - expect(shown.buttons).toMatchObject([{ - label: say('action.signOut'), command: SIGN_OUT, - confirm: { title: say('signOut.title'), body: say('signOut.body'), label: say('action.signOut') }, - }]) + expect(shown.buttons).toMatchObject([ + { label: say('action.addAccount'), command: SIGN_IN }, + { + label: say('action.signOut'), command: SIGN_OUT, + confirm: { title: say('signOut.title'), body: say('signOut.body'), label: say('action.signOut') }, + }, + ]) + expect(shown.buttons[0]).not.toHaveProperty('confirm') shown = presentAccount({ ...CONNECTED, operation: { id: OP, kind: 'sign-out', phase: 'signing-out', cancellable: false } }) expect(shown).toMatchObject({ status: say('step.signing-out'), buttons: [] }) })