Skip to content

feat(runtime): /auth /ai 两域 handler 体抽出 — ADR-0076 D11 步骤③ PR-7 (#2462)#3551

Merged
os-zhuang merged 2 commits into
mainfrom
feat/d11-step3-extract-auth-mcp-ai
Jul 27, 2026
Merged

feat(runtime): /auth /ai 两域 handler 体抽出 — ADR-0076 D11 步骤③ PR-7 (#2462)#3551
os-zhuang merged 2 commits into
mainfrom
feat/d11-step3-extract-auth-mcp-ai

Conversation

@os-zhuang

Copy link
Copy Markdown
Contributor

动机(#2462 D11 步骤③,系列第七刀)

抽出 /auth(better-auth 服务桥 + MSW/浏览器 mock fallback,浏览器安全 randomUUID 包装随唯一消费方走)和 /ai(分派 AI 插件缓存在 kernel 上的 __aiRoutes 路由表,逐路由 auth 契约强制 + actor 透传)。

关键点

  • /ai 接收完整 cleanPath(旧分支整传、matcher 内部拼回 /api/v1)——原样保真。
  • DomainHandlerDeps 扩两个惰性成员:isAuthRequired()(requireAuth 字段初始化晚于 deps 对象,TS2729 抓到的构造顺序陷阱——惰性读取绕开)+ getRegisteredAiRoutes()
  • /mcp 有意排除:调查发现 buildMcpBridge 耦合 action 执行家族(callData/actionPermissionError/invokeBusinessAction 等,正是 handleActions 的 helper 群)——MCP 家族整体归 /actions /meta /data 深耦合批。

验证

接缝套件 42 测试(新增 5:auth 服务桥 / mock sign-up / ai agents 空列表非 404 / ai 404 / kernel 路由表分派含 params+actor);runtime 全量 647 绿;conformance 41 绿;闭包 --force 含 DTS 绿。

关联 #2462(D11 步骤③ PR-7)。机械批至此收官;剩余全部为深耦合批:/actions /meta /data /mcp /graphql(共享 action 执行 + env 解析状态设施,需单独设计 deps 形态)。

🤖 Generated with Claude Code

…076 D11 step ③ PR-7 (#2462)

- domains/auth.ts: better-auth service bridge + the MSW/browser mock
  fallback; the local browser-safe randomUUID wrapper moves with its
  only consumer.
- domains/ai.ts: dispatches the AI plugin's kernel-cached __aiRoutes
  table, enforcing each route's declared auth contract and threading
  the resolved actor. Receives the FULL cleanPath (legacy branch passed
  cleanPath whole; the matcher re-prefixes /api/v1) — preserved.
- DomainHandlerDeps grows isAuthRequired() (lazily read — the
  requireAuth field initializes AFTER the deps object, a construction-
  order trap TS2729 caught) and getRegisteredAiRoutes().
- /mcp deliberately EXCLUDED: buildMcpBridge couples to the
  action-execution family (callData/actionPermissionError/
  invokeBusinessAction/…), so the whole MCP family goes with the
  /actions /meta /data deep-coupling batch.

Verified: seam suite 42 tests, runtime 647 green, http-conformance 41
green, dependent closure builds with DTS (--force).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectstack Ready Ready Preview, Comment Jul 27, 2026 5:41am
spec Building Building Preview, Comment Jul 27, 2026 5:41am

Request Review

@github-actions github-actions Bot added documentation Improvements or additions to documentation tests tooling size/l labels Jul 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/runtime.

17 hand-written doc(s) reference the affected code and may need an implementation-accuracy re-verification:

  • content/docs/api/index.mdx (via @objectstack/runtime)
  • content/docs/api/wire-format.mdx (via @objectstack/runtime)
  • content/docs/automation/hook-bodies.mdx (via @objectstack/runtime)
  • content/docs/concepts/north-star.mdx (via packages/runtime)
  • content/docs/data-modeling/drivers.mdx (via @objectstack/runtime)
  • content/docs/deployment/index.mdx (via @objectstack/runtime)
  • content/docs/deployment/production-readiness.mdx (via @objectstack/runtime)
  • content/docs/deployment/single-project-mode.mdx (via @objectstack/runtime)
  • content/docs/deployment/vercel.mdx (via @objectstack/runtime)
  • content/docs/getting-started/your-first-project.mdx (via @objectstack/runtime)
  • content/docs/permissions/authentication.mdx (via @objectstack/runtime)
  • content/docs/permissions/authorization.mdx (via packages/runtime)
  • content/docs/plugins/packages.mdx (via @objectstack/runtime)
  • content/docs/protocol/kernel/http-protocol.mdx (via @objectstack/runtime)
  • content/docs/protocol/kernel/index.mdx (via @objectstack/runtime)
  • content/docs/protocol/kernel/lifecycle.mdx (via @objectstack/runtime)
  • content/docs/releases/implementation-status.mdx (via @objectstack/runtime)

Advisory only. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs origin/main → pass the list as args.docs.

Comment thread packages/runtime/src/domains/auth.ts Fixed
Comment thread packages/runtime/src/domains/auth.ts Fixed
…js/insecure-randomness)

The extraction made the legacy Math.random() RFC4122 fallback "changed
code" and CodeQL flagged it (the ids feed mock session tokens). Prefer
crypto.randomUUID, fall back to crypto.getRandomValues-built v4; the
no-crypto-at-all branch (ancient runtimes, mock-only) avoids
Math.random too.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@os-zhuang
os-zhuang merged commit 6163393 into main Jul 27, 2026
16 checks passed
@os-zhuang
os-zhuang deleted the feat/d11-step3-extract-auth-mcp-ai branch July 27, 2026 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/l tests tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants