Template tests assume core comes from the monorepo source and fail in a scaffolded workspace

未关闭
#8,331 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
领域
testing, tooling

调研方向

Start with the template Vitest configs and the failing specs named in the report: server/mcp-provider-schemas.spec.ts, server/plugins/identity-sso.spec.ts, and server/actions/connection-permissions.spec.ts. Check how they resolve @agent-native/core and mock paths in both the monorepo and a scaffolded workspace; the report also identifies 94 test files across 13 templates that reference ../packages/core/. Done means the affected template tests pass in a workspace created from packed packages as well as in the monorepo.

由索引模型根据 Issue 内容生成。

描述

Environment: multi-app workspace (chat and dispatch) created with agent-native create, core 0.220.0 installed from npm, apps synced to @agent-native/[email protected] with agent-native template sync, vitest 4.1.12, Node 24.20. The code is unchanged on main at 3a7038f2ea.

What happens: pnpm test in the apps:

  • chat and dispatch: server/mcp-provider-schemas.spec.ts fails before running any test:
    FAIL  server/mcp-provider-schemas.spec.ts > Chat MCP catalogs
    Error: Cannot find module '.../apps/chat/actions/hello' imported from .../apps/chat/.generated/actions-registry.ts
    
  • dispatch: 3 of the 41 tests in server/plugins/identity-sso.spec.ts fail with TypeError: Cannot read properties of undefined (reading 'headers').
  • dispatch: all 13 tests in server/actions/connection-permissions.spec.ts fail with relation "org_members" does not exist.

Why: in the monorepo the templates depend on "@agent-native/core": "workspace:*", so core resolves to packages/core, outside node_modules, and I believe Vitest transforms it like project code. In a scaffolded workspace core lives in node_modules, so Vitest externalizes it and Node loads it directly. Adding test.server.deps.inline: [/@agent-native[\\/]core/] to the app's Vitest config makes the first two failures go away. Then:

  1. loadTemplateMcpConformance (packages/core/src/mcp/provider-schema-conformance.ts:570) loads .generated/actions-registry.ts through the default loader, a native import() (:492). The registry imports actions without extensions (../actions/hello), which Node's ESM resolver rejects. Sixteen templates have this spec.
  2. identity-sso.spec.ts mocks h3 and @agent-native/core/* subpaths. My guess is that, with core externalized, those mocks don't reach the imports made from inside core.
  3. connection-permissions.spec.ts mocks ../../../../packages/core/dist/db/client.js, a path that only exists in the monorepo. In a workspace the mock never applies and the test reaches a database without the tables. calendar (calendar-mcp-writes.spec.ts) and factory (operation-executor-priming.spec.ts, operation-executor.core.spec.ts) mock the same kind of path. More broadly, git grep finds 94 test files in 13 templates that reference ../packages/core/ paths. I haven't checked them one by one, but any that mocks or imports through such a path should break the same way in a workspace.

Workaround:

  • For (1) alone, inline just the loader in the app's vitest.config.ts; with it, all 15 test files in chat pass:
    test: {
      server: {
        deps: {
          inline: [
            /@agent-native[\\/]core[\\/]dist[\\/](testing|mcp[\\/]provider-schema-conformance)\.js$/,
          ],
        },
      },
    },
    
  • Inlining all of core (/@agent-native[\\/]core/) also fixes (2). (3) has no config workaround.

Possible fix:

  • Have the templates' vitest.config.ts inline @agent-native/core, so the tests run the same way in the monorepo and in a workspace.
  • Mock core internals through a path that resolves in both layouts instead of ../../../../packages/core/....
  • Running the template tests in a workspace scaffolded from the packed packages would catch this class of bug, along with #8239 (happy-dom resolved only through the monorepo, fixed in #8279).
主要语言
TypeScript
星标
7.7k
派生
706
平均合并
1 天 11 小时
30 天内合并 PR
790

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

BuilderIO/agent-native 的其他 Issue

查看 BuilderIO/agent-native 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。