Skip to content

fix(lark): recognize international Lark setup URL - #8871

Merged
huangruiteng merged 4 commits into
loopx-project:mainfrom
mojunzi:codex/fix-lark-international-setup-url
Nov 18, 2026
Merged

huangruiteng merged 4 commits into
loopx-project:mainfrom
mojunzi:codex/fix-lark-international-setup-url

Conversation

@mojunzi

@mojunzi mojunzi commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Thank you for reviewing. This PR fixes a small but user-visible gap in the Lark App setup flow for international Lark.

Goal And Delivered Outcome

  • Outcome basis / optional anchor: Self-contained reproduced defect; no separate issue was opened.
  • Goal/source and gap: lark-cli 1.0.99 emits open.larksuite.com/page/cli?... for --brand lark, but LoopX's Lark App setup only accepted Feishu hosts, so the verification URL was dropped and the Dashboard stayed at "starting", leaving the operator to run the CLI just to obtain the authorization link.
  • Observable before → after: Before, the international Lark authorization URL was not detected, the browser was never opened, and the setup stayed at "starting". After, the URL is exposed as verification_url and opens through the existing Dashboard flow, with the real lark-cli URL shape covered by a regression test.
  • Issue/task and intended base: No issue; intended base is loopx-project/loopx:main.

Author Declaration

  • Written by: Tencent Hy4 Flash via Pi coding agent

Implemented against

  • Specification and revision: No written specification; the request in this PR is the basis.
  • Criteria:
Criterion (spec clause) Disposition Symbol / path Test or command
Recognize the official international Lark authorization host implemented loopx/extensions/lark/app_setup.py tests/extensions/test_lark_app_setup.py
  • Self-check before submission: The Agent-context config-init refusal is intentionally out of scope because it needs a product decision between --force-init and config bind.

Scope And Continuation

  • Completed scope and remaining work: This defect is complete within this scope; no remaining work is needed for it.
  • Slice boundary / successor: N/A; no follow-up is needed for this defect.

Validation

  • Tested revision: d46ce84
  • Run state: finished
  • Input classes: synthetic, public_fixture
Check kind Result Public-safe evidence / limitation
unit passed tests/extensions/test_lark_app_setup.py; 6 passed.
static passed ruff and git diff origin/main...HEAD --check passed.
static failed A pre-existing mypy error at interaction_contract.py:1453 was reproduced on the same head and is unrelated to the changed files.
integration passed Lark-focused canary smokes and catalog canaries passed.
integration failed Two risk-profile smokes fail only when the checkout path contains spaces; the exact same head passes in a no-space worktree.
real_entrypoint not_run Not run because it would require completing a provider-side Lark authorization and browser flow.
manual not_run No user-visible layout change was introduced.
  • Coverage and gaps: The changed path is the host-matching constant consumed by LarkAppSetupManager, and the regression test supplies the real lark-cli 1.0.99 URL shape. Real provider authorization was not run and is disclosed above.

Frontend / Visual Evidence

  • UI impact: none
  • Before: N/A
  • After: N/A
  • First viewport and preview: N/A; no frontend diff was introduced.
  • States and viewports shown: N/A
  • Source data: none
  • Attention review: N/A; no UI change was introduced.
  • Craft review: N/A; no UI change was introduced.

Type of Change

  • Bug fix
  • Test update

LoopX Area

  • Capability or extension

Technical Direction

  • Operator surface and IM integration

Shared-authority RFC fixture impact

  • N/A

Boundary Checklist

  • Neither the diff nor this PR body discloses private state, credentials, raw traces, verifier output, internal links or local machine paths.
  • I did not duplicate maintainer-owned benchmark work.
  • I kept the change scoped to the reproduced defect.
  • No paired English/Chinese RFC was changed.
  • I marked UI impact as none because no frontend or visual change was introduced.
  • The commit includes a DCO Signed-off-by trailer.

Copilot AI balanced review requested due to automatic review settings November 16, 2026 15:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

lark-cli emits open.larksuite.com for --brand lark, but the app setup manager only accepted Feishu hosts. The verification URL was dropped, so Dashboard stayed at starting and the operator had to run the CLI to obtain the link. Add the official host and cover the real URL shape with a focused regression test.

Signed-off-by: Xiang-Player <wanghank00@gmail.com>
@mojunzi
mojunzi force-pushed the codex/fix-lark-international-setup-url branch from d46ce84 to 1ed6643 Compare November 16, 2026 16:14
@mojunzi

mojunzi commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio update

@mergify

mergify Bot commented Nov 17, 2026

Copy link
Copy Markdown

update

✅ Branch has been successfully updated

@mojunzi

mojunzi commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio refresh

@mergify

mergify Bot commented Nov 17, 2026

Copy link
Copy Markdown

refresh

✅ Pull request refreshed

@mojunzi

mojunzi commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Validation note (local results from the PR body, tested revision d46ce84): the Lark regression unit tests pass (6 passed), ruff and git diff --check pass, and the Lark-focused canary smokes pass.

Two non-blocking caveats in that validation, both unrelated to the two changed files:

  • a pre-existing mypy error at interaction_contract.py:1453, reproduced on the same head;
  • two risk-profile smokes that fail only when the checkout path contains spaces; the same head passes in a no-space worktree.

real_entrypoint and manual were not run (provider-side Lark authorization would be required; no UI change), as disclosed in the PR body. Remote CI results are tracked in the checks tab.

@mojunzi

mojunzi commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio update

@mergify

mergify Bot commented Nov 17, 2026

Copy link
Copy Markdown

update

❌ GitHub refused to update workflow files

Details

GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/ark-turn.yml without workflows permission
GitHub only lets Mergify write to .github/workflows/ with the workflows permission. An organization owner can accept Mergify's pending permissions at https://dashboard.mergify.com/orgs/loopx-project/repositories.

@mojunzi

mojunzi commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

@Mergifyio refresh

@mergify

mergify Bot commented Nov 17, 2026

Copy link
Copy Markdown

refresh

✅ Pull request refreshed

Signed-off-by: Wang, Xiang-Han <wanghank00@gmail.com>
A checkout path containing spaces reaches import.meta.url as %20 in
URL.pathname. The stdio relay fixture then spawns a script path that does
not exist and all four relay tests time out. fileURLToPath preserves the
real path on every checkout.

Signed-off-by: Wang, Xiang-Han <wanghank00@gmail.com>

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent | Gemini | Google | self_reported

动机 / Motivation

在 Dashboard 中选择国际版 Lark 创建新应用的运维或个人工作区用户,在执行 Lark App 初始化引导流程时触发该问题。修改前 lark-cli 输出 https://open.larksuite.com/page/cli?... 授权链接时会被正则静默丢弃,界面长期停留在 starting;修改后 LarkAppSetupManager 能捕获该 URL 并写入 verification_url,由 Dashboard 正常拉起浏览器完成授权。国际版 Lark 初始化时 setup.verification_url 正确返回 open.larksuite.com 授权链接且状态流转至 waiting_for_feishu 并在校验后转为 ready。本次修改不更改国内飞书或 larkoffice 既有流程,也不改造 bot_scopes.py 权限申请链接生成器和 Agent 配置初始化拒绝策略。

改动思路 / Approach

将国际版授权域名精确纳入既有静态白名单并在唯一消费路径中匹配,无需引入新状态、新接口或动态域名解析器,保持最小且可逆的所有权边界。本 PR 边界限定在 Lark 初始化授权 URL 识别、对应回归测试及附带的 stdio 测试路径解码修复,不改动 bot_scopes.py 权限域名或前端状态枚举。

具体来看,LarkAppSetupManager 在 loopx/chat_lark_api.py 与 loopx/chat_server.py 中作为唯一初始化会话管理器,通过后台 _watch 线程逐行读取 lark-cli config init 输出。正则 OFFICIAL_SETUP_URL_PATTERN 将域名白名单严格锚定在 https:// 与 /page/(?:cli|launcher)\? 之间,确保 urlparse(matched).hostname 仅能命中明确列举的官方域名,既不会因为子域名、后缀拼接或 @ userinfo 造成钓鱼链接注入,也完全保留既有 open.feishu.cn、open.larkoffice.com 和前端 waiting_for_feishu 轮询契约。

具体改动 / Changes

本次审查目标为 exact head 2db06716b28a56d8baf1ddbc71334f4dfe339356(基于 d25e044c8c2aa3d862fb868eea93b58c901b07cc),无独立书面 RFC 规范,以已复现的 lark-cli --brand lark 缺陷作为交付判定依据。

关键代码讲解

  • loopx/extensions/lark/app_setup.py — _OFFICIAL_SETUP_HOSTS / OFFICIAL_SETUP_URL_PATTERN(L21-30):在 _OFFICIAL_SETUP_HOSTS 中补充 "open.larksuite.com"。由于 OFFICIAL_SETUP_URL_PATTERN 通过 re.escape(host) 拼接在 https:// 之后并紧跟 /page/(?:cli|launcher)\?,属于精确整域名锚定而非宽松子串匹配,能直接拒绝 open.larksuite.com.evil.com、evil.open.larksuite.com、user@open.larksuite.com、非标准端口与 http://。
  • loopx/extensions/lark/app_setup.py — LarkAppSetupManager._watch(L158-186):消费 OFFICIAL_SETUP_URL_PATTERN.search(str(line)),在非终态时写入 setup.verification_url 并流转至 waiting_for_feishu,进程退出码为 0 且 profile_verifier 通过后转为 ready。
  • tests/extensions/test_lark_app_setup.py — test_setup_accepts_the_international_lark_authorization_host(L128-154):使用 lark-cli 1.0.99 真实输出格式验证 brand="lark" 下 verification_url 与 status="ready" 完整闭环。
  • tests/control_plane_ts/host_stdio_bridge.test.ts — bridge(L10-12):将 new URL(...).pathname 改为 fileURLToPath(new URL(...)),修复工作树路径含空格时 %20 导致 spawn 找不到脚本的问题,与仓库其余 TypeScript 测试用法一致。

对主干的风险 / Risks

无阻塞性缺陷(No blocking findings)。 针对最关键的 URL 欺骗与回归风险,我在本地对该 head 执行了正反例探测与完整本地门禁验证,所有关键路径均为 PASS:

  1. 域名解析与防欺骗验证(PASS):本地构造 13 组正反测试输入(含 open.larksuite.com.evil.com、evil.open.larksuite.com、user@open.larksuite.com、:8443 端口、http://、缺省 query、openxlarksuitexcom 等)验证 OFFICIAL_SETUP_URL_PATTERN 与 urlparse().hostname,全部符合预期,且基线 d25e044c8c 对 open.larksuite.com 返回 False、当前 head 返回 True 并在 Feishu 上保持 True。
  2. 非阻塞建议(P3):tests/control_plane_ts/host_stdio_bridge.test.ts 的空格路径测试修复属于与 Lark 无关的顺带提交,且 PR 正文 Tested revision 仍停留在早期提交 d46ce84;另外 tests/extensions/test_lark_app_setup.py 尚未补充负向域名欺骗单测用例,且 bot_scopes.py 的 _OFFICIAL_SCOPE_APPLY_HOSTS 仍未包含 open.larksuite.com(若后续国际版缺失权限跳转需单独评估)。以上均不影响当前修改的正确性与安全性。
  3. 远端 CI 诊断说明:PR 远端检查中 DCO、loopx-core、postgresql-authority、build 通过,但 kernel-static-checks、stage2c-correctness-e2e、checks、pytest 显示失败且分支 BEHIND main。在当前精确 head 2db06716b28a56d8baf1ddbc71334f4dfe339356 本地复现所有对应静态检查(ruff check、test_stage2c_dependency_lock.py、test_top_level_module_budget.py、默认 mypy 17 文件、canary premerge --tier quick、public_boundary_scan)与 72 个 Lark 单测及 4 个 stdio bridge TS 测试全部通过(仅直接对 test_lark_app_setup.py 单独运行 mypy 时会命中既有的 cli_resolution.py/contract.py/_FakeProcess 类型注解旧债,不涉及本 PR 新增代码)。合入前仍需由维护者处理分支更新及 merge readiness 检查。

我的整体评价 / Verdict

  • Long-horizon 影响:preserved — 保留既有状态机、锁保护及终态清理语义,国际版 Lark 与飞书走同一生命周期路径。
  • User-experience 影响:improved — 国际版 Lark 初始化不再卡死在 starting,可直接获取并打开官方授权链接;visual_review 为 not_applicable(未改动前端展示层,已核对 lark-settings-page.tsx 消费 verification_url 逻辑)。
  • 可观测语义 / 代码体积 / 比例性 / 隔离与权威性:observable_semantics 为 intentional_change_validated(基线 d25e044c8c 到 head 2db06716b2 行为对比已验证),code_volume 为 necessary(兼容性保留 retain),change_proportionality 为 proportionate,default_off_isolation 与 authority_semantics 为 not_applicable,semantic_alignment 为 not_applicable(semantic-vocabulary-drift-smoke.py 通过,未引入或修改共享词表)。
  • 本地验证汇总(head 2db06716b28a56d8baf1ddbc71334f4dfe339356):
    • pytest tests/extensions/test_lark_app_setup.py tests/extensions/test_lark_bot_scopes.py tests/extensions/test_lark_cli_resolution.py tests/test_contract_credential_pattern_precision.py: PASS(72 passed,含 test_lark_app_setup.py 6 passed)
    • node --test tests/control_plane_ts/host_stdio_bridge.test.ts: PASS(4 passed)
    • ruff check(改动文件及 tests loopx/canary loopx/control_plane loopx/domain_packs loopx/presentation): PASS
    • pytest tests/test_stage2c_dependency_lock.py tests/architecture/test_top_level_module_budget.py: PASS(7 passed)
    • mypy(仓库默认 17 源文件): PASS
    • loopx check --scan-path ...: PASS(3 files clean, 0 errors)
    • loopx canary premerge --tier quick --from-git-diff --git-diff-base origin/main: PASS(selected=2, failures=0, check_rfc_bilingual.py ok)
    • 真实在线 lark-cli 浏览器 OAuth 登录流程:UNVERIFIED(需真实 provider 侧交互授权)。

英文简短结论

English verdict: APPROVE PR #8871 at head 2db0671; the international Lark setup host allowlist and space-path stdio test fix are minimal, safe against host spoofing, and verified by 72 Python tests, 4 Node tests, ruff, default mypy, public boundary scan, and canary premerge quick, with remote CI/BEHIND status left to the separate merge-readiness gate.

@huangruiteng
huangruiteng merged commit 5457d9f into loopx-project:main Nov 18, 2026
32 of 37 checks passed
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.

4 participants