Skip to content

fix(auth): allow contact user search scope - #1946

Merged
deepcoldy merged 2 commits into
deepcoldy:masterfrom
chengweiv5:fix/contact-user-search-scope
Oct 15, 2026
Merged

deepcoldy merged 2 commits into
deepcoldy:masterfrom
chengweiv5:fix/contact-user-search-scope

Conversation

@chengweiv5

@chengweiv5 chengweiv5 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • add the valid contact:user:search user scope to the Lark scope catalog
  • generalize the existing Base authorization regression test to cover user scopes
  • verify catalog acceptance, typo rejection, IPC auth-request forwarding, and stale-turn protection
  • repair the slash-route test fixture so success and worker-send failure paths reach the intended worker IPC code

Background

lark-cli contact +search-user --as user requires contact:user:search, but Botmux rejected that valid scope as unknown_scopes before an authorization URL could be created.

The first CI run also exposed a pre-existing test-fixture gap: sendWorkerSessionInput resolves the owning bot before dispatching IPC, while ipc-slash-route.test.ts did not register a bot. That made success cases return 502 and made the worker-send failure case pass for the wrong reason. The fixture now supplies the owning bot config.

Validation

  • targeted authorization tests: 490/490 passed before review
  • independent review rerun: 124/124 passed
  • slash route fixture: Vitest 11/11 and Bun 11/11 passed
  • deployment smoke regression: 8/8 passed
  • full build passed
  • latest CI run: 9/9 checks passed
  • git diff --check passed

@chengweiv5

Copy link
Copy Markdown
Contributor Author

Temporarily closing and reopening to retrigger CI after an environment-sensitive systemd/tmux integration flake; no additional code change.

@chengweiv5 chengweiv5 closed this Oct 15, 2026
@chengweiv5 chengweiv5 reopened this Oct 15, 2026
@deepcoldy

Copy link
Copy Markdown
Owner

首审意见:0 P0 / 0 P1 / 0 P2,可直接合入

改动

  1. src/setup/lark-scopes.json:user 桶新增一行 contact:user:search(130 项,仍保持字母序、无重复,未误入 tenant 桶)。
  2. 测试:原 lark-base-scope-authorization.test.ts 泛化为 lark-user-scope-authorization.test.ts,新增该 scope 的目录接受、拼写错误拒绝、IPC auth-request 转发与 stale-turn 保护用例。
  3. test/ipc-slash-route.test.ts:补齐 owning bot fixture。

正确性核验

  • scope 名与官方文档逐字一致:开放平台「搜索用户」GET /open-apis/search/v1/user(contact-v3/user/search-users)原文要求 contact:user:search(desc「搜索用户」),且注意事项明确「仅支持通过用户身份(user_access_token)调用」——放入 user 桶、不放 tenant 桶是正确的;官方 larksuite/cli 的 scope 注册表也收录同名 scope。
  • 不污染普通登录授权面:/login 默认只申请 DEFAULT_SCOPES(im:message:readonly / im:resource / offline_access),manifest 仅用于名校验与 setup 导入,新 scope 只在显式 /login --scope contact:user:search 或 lark-cli auth-request 按需授权时出现,与既有 Base/文档评论 scope 的模式一致。
  • 两个生产闸门(IPC auth-request 与 /login --scope)都走同一个 isKnownLarkUserScope,一处修复同时覆盖两条入口。
  • 测试绑定断言到位:IPC 用例校验了转发的 scope 数组与 caller openId,stale turn 仍 403、错名仍 400 且不发起授权。

验证记录(基于最新 master bc1c8a7 本地 rebase,零冲突;rebase 树 == merge-tree 树 3e7e606)

  • vitest:两个改动文件 19/19;连带 setup/verify-permissions、open-platform-automation 共 217/217;user-token 三套件 47/47。
  • bun test:两个改动文件 19/19。
  • tsc --noEmit 0 错;bun run build 通过;git diff --check 干净。
  • 变异核验:
    • 从 manifest 拔掉 contact:user:search → 恰好 2 个新用例失败(目录断言 + IPC 200→400),测试有牙。
    • 在本 PR 首个 commit(修复前的基底代码)上移除 fixture 的 bot mock → 复现 2 个 slash 用例失败(success 路径 502),与本 PR 首次 CI 失败签名一致,fixture 修复针对的是真实缺口。
  • CI:head a284262 最新一次 9/9 全部 completed/success(build、bun-binary 三平台、bun-test、test 三分片)。此前一次唯一失败是 session-scope-lifecycle.integration 的真实 tmux/systemd 环境 flake(11177 测中仅 1 例),与本 PR 文件无交集,重跑后全绿。

P3(非阻断,可不改)

  1. 合入目标为当前 master 后,bc1c8a739 已把 sendWorkerSessionInput 调整为先判消息形态、inject_command 不再经 getBot——该 fixture mock 在 rebase 后的新基上对现有 11 个用例不再是必要条件(移除后仍 11/11),但作为「活跃注册 bot」的代表性 fixture 保留是合理的,也为日后该路由出现 term_action 等形态兜底,建议保留。
  2. fixture 注释「sendWorkerSessionInput resolves the session CLI through the owning bot before it dispatches worker IPC」在 bc1c8a7 之后略不精确(如今仅 codex 的 Ctrl+C/ESC term_action 会查 bot),方便时可顺手改为「message shapes that resolve the session CLI (e.g. codex cancel)」之类的表述。

整体是最小且正确的目录修复,测试覆盖了接受/拒绝/转发/turn 绑定四个面。

@deepcoldy
deepcoldy merged commit 2af23f7 into deepcoldy:master Oct 15, 2026
16 of 18 checks passed
@deepcoldy

Copy link
Copy Markdown
Owner

复审:0 P0 / 0 P1 / 0 P2,建议合入

对首审结论做了独立复核,重点放在「首审说对的地方我能否推翻」。

同步状态

  • upstream/master 现为 bc1c8a739;作者远端 head a284262(2 commit)未变,与 PR headRefOid 一致,无 force-push。
  • 本地 rebase 结果树 == git merge-tree --write-tree upstream/master a284262 结果树,均为 3e7e606;git diff a284262..HEAD -- <3 文件> 为空,逐字等价。

逐项复核

1. lark-scopes.json(+1 行)

  • user 桶 130 项、tenant 桶 170 项,两桶各自保持字母序、无重复;新行只落在 user 桶,未误入 tenant。
  • scope 名与身份类型独立核实:larksuite/cli 上游源码 shortcuts/contact/contact_search_user.go 写死 Scopes: []string{"contact:user:search"}、AuthTypes: []string{"user"},调用 /open-apis/contact/v3/users/search(+search-user 官方描述即「requires --as user」)。已安装的 v1.0.98 官方二进制里同样含该 scope 的注册表条目。只放 user 桶是正确的。
  • 不污染普通 /login:DEFAULT_SCOPES(src/utils/user-token.ts)未动,新 scope 只经显式 --scope / auth-request 出现。
  • 不触发启动自检自动补权限:该名字不在 BOTMUX_REQUIRED_SCOPES 与任何 *_FEATURE_SCOPES 中,故 filterScopeManifest 链路不会因此多发一次 scope/update。影响面限于 (a) isKnownLarkUserScope 闸门、(b) setup --create-app 导入整份 manifest —— 与 fix(setup): 补齐 Base 用户权限 base:app:create / bitable:app #1506(base:app:create/bitable:app)同一类改动。
  • 自动驳回名单测试不受影响(新名字不在该名单内)。

2. test/lark-user-scope-authorization.test.ts(重命名 + 4 类新用例)

  • 变异有牙:仅从 manifest 删除新增行 → 恰好 2 例转红(isKnownLarkUserScope 断言 false + IPC 路由由 200 变 400 unknown_scopes),其余 6 例不受影响。有咬合力,非空跑。
  • 旧文件名的引用已全仓清干净(无残留 import / CI 配置引用)。

3. test/ipc-slash-route.test.ts(fixture)

  • 变异复现:切到 PR 首个 commit d5126b4b6(无 fixture)跑该文件 → 11 例中 2 例失败,均为 expected 502 to be 200,与首次 CI 失败签名一致;加上 fixture 后 11/11。
  • 关于首审 P3①:在当前 head 上临时回退 bc1c8a739(把 getBot 挪回 sendWorkerSessionInput 最前),fixture 在位的这 19 例仍全绿 —— 说明 fixture 确实是「代表性 + 兜底」,对 11 个现有 inject_command 用例已非必需。但它是有意义的回归护栏:它把路由夹具固定成「已注册 bot」的真实形态,别人日后若再把 registry 查找挪到无条件路径上,这组用例会立刻抓到,而不是又变成 502 假绿。建议保留。

独立跑过的验证

  • npx vitest run --project unit test/ipc-slash-route.test.ts test/lark-user-scope-authorization.test.ts → 19/19
  • bun test <同两文件>(bun 1.4.2)→ 19 pass / 0 fail
  • 连带:test/transfer-input-gate-wiring.test.ts + test/command-handler.test.ts + 上述两文件 → 462/462
  • manifest 一致性:test/setup-verify-permissions.test.ts + test/scope-optional-autofix.test.ts + test/setup-open-platform-automation.test.ts → 223/223
  • npx tsc --noEmit → 0 错;bun run build → 绿(含 audit-dist / audit-embedded-assets)
  • git diff --check → 干净
  • 全量 vitest run --project unit 有 58 例红,但按文件抽样到 upstream/master 复跑(bc1c8a739,本 PR 改动为零的先验点)得到同样的红(3 failed / 8 tests),确认是与本 PR 无交集的既有/环境型失败(隔离、插件 sandbox、sqlite 等),不是本改动引入。

非阻断余项(沿用首审,均不要求本 PR 处理)

  • P3:getBot fixture 注释「resolves the session CLI through the owning bot before it dispatches worker IPC」对现代码略不精确(bc1c8a739 后只有 term_action 走该查找);顺手改成条件式表述更准。
  • P3:如需更强护栏,可补一条直接断言「未注册 bot + inject_command 不应 502」的用例,把 bc1c8a739 修复本身也钉住(目前它只被夹具间接覆盖)。
  • 该 scope 只在按需授权入口生效,尚未在真实租户走通 contact +search-user --as user 的全链路;合入后在飞书里实测一次更稳(非合入前置条件)。

@chengweiv5
chengweiv5 deleted the fix/contact-user-search-scope branch October 16, 2026 08:10
@github-actions

Copy link
Copy Markdown

🚀 Released in v3.45.0

deepcoldy added a commit to Hyperzsb/botmux that referenced this pull request Oct 20, 2026
合并最新 master(含 deepcoldy#1606/deepcoldy#1911/deepcoldy#1941/deepcoldy#1946/deepcoldy#1961/deepcoldy#2042 等按人鉴权演进)。
语义冲突处理:
- bytedcli 身份同时携带五区域 cloudJwts 与 codeJwt(后者派生 codebase 同伴工具),
  mintByteCloudUserJwts 一次返回,去掉外层重复 mint。
- larkdev 平台凭据源暂不支持:grant client 端拒绝、toIdentity 收窄,platform 模式
  fail-closed、auto 模式回落本地个人 HOME 五区域 mint。
- lark-cli 个人 app 两步授权的拒绝文案按 stage 区分(app-setup vs user-login),
  ByteCloud 家族(bytedcli/larkdev)统一 provider 文案、空 HOME 与 502/409 守卫。
- 沙箱 lark-cli HOME 物化在 publishOne/publishDelegated 叠加 sessionSandbox 透传。
- session-tmp 采用 master 新短路径布局(8 字符 profile+sid hash),根目录强制
  deny 与本 PR 快照 carve 不受布局变化影响(seal 的是整个 session-tmp 根)。
- dashboard scope 加购/auth-status 取 master(绑定会话走 bot 应用,个人 app 首次
  授权走 turn 发布路径,不经此 IPC);删除被 deepcoldy#1946 改名的旧 scope 测试文件。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants