Skip to content

feat(setup): --reuse-credentials skips browser authorization while keeping every platform check - #222

Open
itswl wants to merge 2 commits into
eddiearc:mainfrom
itswl:feat/setup-reuse-credentials
Open

itswl wants to merge 2 commits into
eddiearc:mainfrom
itswl:feat/setup-reuse-credentials

Conversation

@itswl

@itswl itswl commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

What

Re-running larkin setup for an already-authorized app always required another platform authorization (QR / confirmation page), even though the bot credential was already on disk. The registration entry only had three paths — --from-cli-profile + LARKIN_SETUP_APP_SECRET, the Lark /page/cli QR flow, and the Feishu authorization page — with no branch that reuses stored credentials. Filed as #221; this implements direction 1.

Change

  • src/setup/bot-register.ts: new --reuse-credentials branch. It loads the selected Agent's credential through loadValidatedBotCredential (the same validator other flows use) and feeds it into the existing post-authorization pipeline exactly as if it had just been returned by the platform. Everything downstream is unchanged:
  • src/app/setup.ts: flag passthrough plus help text.
  • test/integration/setup/setup-reuse-credentials.test.mjs: four cases — reuse skips the authorization page and still fails closed on a denied scope (the injected registerApp throws if the QR path is ever taken, and the injected QR generator writes a marker file that the test asserts is absent), a green path that completes the whole flow (bot identity, grants, visibility, bind, result file) with the authorization page never requested, a missing credential fails with a clear message before any authorization, and an explicit tenant contradiction aborts before writing.

Note on the interactive runtime prompt: with --runtime omitted, the run still shows the existing-agent prompt (已有 Agent:claude/default。直接回车保留;输入 c 才修改), so the stored runtime is kept on Enter; pass --runtime to skip the prompt entirely. This PR lands ahead of maintainer alignment on #221 — happy to adjust the shape, split it, or park it.

Validation

  • bun test test/integration/setup/setup-reuse-credentials.test.mjs → 4 pass / 0 fail
  • bun test test/unit/setup/ test/unit/app/setup-cli.test.mjs test/integration/setup/ → 79 pass / 1 skip / 1 fail. The failure (setup-single-root.test.mjs: "a clean shell build emits loadable setup-binding.mjs with the pure planning export") is environmental on this machine: it performs a full clean build inside bun's default 5 s test timeout, and a clean build measures ~11.4 s here. Unrelated to this change.
  • bun run build ✅ · bun run typecheck ✅ · bun run licenses:check ✅ · bun run publication:check:tree
  • bun run test:integration (CI pre-check on this branch) → 182 pass / 18 skip / 7 fail. All 7 failures are clean-build / build-graph / hook-timeout cases that reproduce on unmodified main in this environment — a clean build measures ~11.4 s here while the affected tests budget 5 s.
  • bun run test:unit → 895 pass / 1 skip / 1 fail. The single failure is the pre-existing environmental three-Agent live acceptance is opt-in, hermetic by default, and fixture-verifiable, which also fails on unmodified main here. (An earlier run under heavy concurrent load showed extra timeout failures in process-spawning tests; each of those files passes in isolation — 37 pass / 0 fail — so they were load artifacts, not regressions.)

Refs #221

🤖 Generated with Claude Code

@eddiearc eddiearc left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

HOLD(Fable 5.1 审合)— 等 #221 Owner 定案 + 两处改动

实现方向 1 很稳:跳过授权页,但 Bot 身份、grant_status 门禁、订阅 reconcile、写盘与同 App 绑定全保留;缺凭证 / --tenant 冲突 / 与 --from-cli-profile 互斥都有 fail-fast。集成测质量高。

合前必须:

  1. Owner 对齐 #221(flag vs 自动复用等)
  2. resolveSelectedTenant() 在 reuse 分支之前仍会弹「选择平台」——reuse 检查应挪到 prompt 前
  3. help 文案写明 reuse 不会重跑 registerApp / LARKIN_REGISTER_ADDONS

缺 version bump;与 #226 有 import 行冲突。

@eddiearc

Copy link
Copy Markdown
Owner

Maintainer follow-up — HOLD

实现质量不错(保留 bot 身份 / grant 门禁 / reconcile / 写盘),但 先等 #221 产品定案,再合。

合前还请改:

  1. --reuse-credentials 时,先读存量凭证并推断 tenant,不要先弹「选择平台」再静默覆盖
  2. --from-cli-profile 等互斥检查放到交互之前。
  3. help 写明:reuse 不会重跑 registerApp / LARKIN_REGISTER_ADDONS
  4. 补上 public larkin setup 入口测(现在多半直接打 bot-register)。

这是 setup 便利性功能,不是本轮 runtime 修复的前置。

Re-running setup for an already-authorized app always required another
platform authorization. --reuse-credentials reuses the selected Agent's
stored bot credential instead: it skips the QR/authorization page but
keeps every downstream platform check unchanged — bot identity
verification, the required-scope grant_status gate, comment-subscription
reconciliation and the same-App-ID binding all still run and fail closed.

The flag refuses to start when no valid stored credential exists, and
rejects an explicit --tenant that contradicts the stored tenant before
any write.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@itswl
itswl force-pushed the feat/setup-reuse-credentials branch from 13c8347 to 993a4c0 Compare September 14, 2026 01:50
@itswl

itswl commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

四条已改(head 993a4c0,已 rebase 到最新 main;HOLD 我们理解——等 #221 产品定案后再请审):

  1. tenant 改为取自存量凭证--reuse-credentials 时先读 bots/<App ID>.jsonloadValidatedBotCredential)并由其推断租户,不再弹「选择平台」;显式 --tenant 与之冲突时在任何写入前中止,非法值同样先拒。
  2. 互斥检查前置--reuse-credentials × --from-cli-profile 在任何交互之前失败(bot-register 内前置,公共入口 setup.ts 另加一道早退)。
  3. help 已写明:不重跑 registerApp / LARKIN_REGISTER_ADDONS,且租户来自存量凭证而非询问。
  4. 补了 public 入口测setup --reuse-credentials --from-cli-profile x(非 TTY)→ 断言在接触 lark-cli 之前就失败。

验证:setup-cli + setup-reuse-credentials 两个测试文件 10 pass / 0 fail;build / typecheck 通过。

@eddiearc

Copy link
Copy Markdown
Owner

复看 head 993a4c0:上次四条代码改动都到位了。

  1. ✅ reuse 先读存量凭证推断 tenant,不弹「选择平台」
  2. ✅ 与 --from-cli-profile 互斥前置(setup + bot-register)
  3. ✅ help 写明不重跑 registerApp / ADDONS、租户来自存量凭证
  4. ✅ 公共入口测已补

仍 HOLD:等 #221 产品定案(要不要这个 flag / 是否默认自动复用)。代码侧就绪后即可再叫合。

Re-running setup for an already-authorized app always required another
platform authorization. --reuse-credentials reuses the selected Agent's
stored bot credential instead: it skips the QR/authorization page and
does not re-run registerApp or the LARKIN_REGISTER_ADDONS grant request,
but keeps every downstream platform check unchanged — bot identity
verification, the required-scope grant_status gate, comment-subscription
reconciliation and the same-App-ID binding all still run and fail closed.

The tenant is inferred from the stored credential before any interaction
(no platform prompt that a later step could silently override), flag
exclusivity is checked before any interaction, an explicit --tenant that
contradicts the stored tenant aborts before any write, and the public
`larkin setup` entry is covered by a test.

Bumps the package patch version (0.5.9 -> 0.5.10) per the Owner policy.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@itswl
itswl force-pushed the feat/setup-reuse-credentials branch from 993a4c0 to 6a3807a Compare September 14, 2026 14:15
@itswl

itswl commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

package.json 已按 Owner 政策补 bump(0.5.9 → 0.5.10,head 6a3807a);代码侧维持上轮结论,继续 HOLD 等 #221 定案。

@itswl

itswl commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

source-checks 失败排查(head 6a3807a

失败项只有 test/e2e/pi-prompt-preflight-recovery-mock-e2e.test.mjsproduction RuntimeHost RPC events manual success plus exact second overflow fallback once without duplicate delivery(2 s waitUntil 超时;21 pass / 1 fail);Windows gate 与 standalone artifact 均通过。

应属 CI 时序抖动,烦请重跑一次。

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