Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): ignore colocated tests during agent discovery (#3733)

Matan Kushnerfdf136461d13
diff --git a/.changeset/colocated-agent-tests.md b/.changeset/colocated-agent-tests.md
new file mode 100644
index 000000000..6abcebb08
--- /dev/null
+++ b/.changeset/colocated-agent-tests.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Ignore JavaScript and TypeScript `*.test.*`/`*.spec.*` modules and `__tests__/` directories during agent discovery.
diff --git a/docs/reference/agent-files.md b/docs/reference/agent-files.md
index 4e89f969e..2e0de262a 100644
--- a/docs/reference/agent-files.md
+++ b/docs/reference/agent-files.md
@@ -64,6 +64,22 @@ Paths below are relative to the agent directory. Root agents can use every path;
| `schedules/` | Recurring jobs | No | `defineSchedule` modules or Markdown prompts with `cron` frontmatter; recursive nesting is supported. |
| `subagents/` | Specialist child agents | Yes | Local directories or remote-agent definitions; nested subagents are supported. |
+## Colocated tests
+
+eve ignores JavaScript and TypeScript modules named `*.test.*` or `*.spec.*`,
+along with `__tests__/` directories, during automatic discovery and when choosing
+extension runtime entries.
+
+```text
+agent/tools/
+├── get_weather.ts # registered as get_weather
+├── get_weather.test.ts # excluded from discovery
+└── __tests__/ # excluded from discovery
+ └── fixtures.json
+```
+
+Explicit imports, sandbox workspace files, and packaged skill resources are unaffected.
+
## Files available in the sandbox
Agent source files are not automatically available to shell commands. Put files to copy into the sandbox's `/workspace/` under `agent/sandbox/workspace/`. Skill runtime files are seeded separately under `$HOME/.agents/skills/`, with `/workspace/skills/` as a fallback. See [Sandboxes](/docs/sandbox) and [Skills](/docs/skills).
diff --git a/e2e/fixtures/agent-tools/agent/tools/dynamic-schema-validation.test.ts b/e2e/fixtures/agent-tools/agent/tools/dynamic-schema-validation.test.ts
new file mode 100644
index 000000000..c1935da5d
--- /dev/null
+++ b/e2e/fixtures/agent-tools/agent/tools/dynamic-schema-validation.test.ts
@@ -0,0 +1,4 @@
+// The schema-validation eval must boot and call the neighboring tool without loading this file.
+throw new Error("Colocated tests must not be loaded as agent tools.");
+
+export {};
diff --git a/packages/eve/src/discover/agent.integration.test.ts b/packages/eve/src/discover/agent.integration.test.ts
index a794dd6dc..c92f93cd0 100644
--- a/packages/eve/src/discover/agent.integration.test.ts
+++ b/packages/eve/src/discover/agent.integration.test.ts
@@ -55,6 +55,47 @@ const EXTENSION_COMPATIBILITY_MANIFEST = JSON.stringify({
* here against an in-memory {@link buildMemoryAgentProject} tree.
*/
describe("discoverAgent (memory)", () => {
+ it.each(["agent", "extension"] as const)(
+ "excludes colocated tests from %s definitions and local subagents",
+ async (role) => {
+ const agentFiles: Record<string, string> = {
+ "instructions.md": "Help Alice check the weather.",
+ "tools/weather.ts": "export default {};",
+ "tools/nested/weather.mjs": "export default {};",
+ "subagents/researcher/agent.ts": "export default {};",
+ "subagents/researcher/tools/weather.ts": "export default {};",
+ };
+ const baseline = await discoverAgent({ ...buildMemoryAgentProject({ agentFiles }), role });
+ expect(baseline.diagnostics).toEqual([]);
+
+ for (const directory of [
+ "tools",
+ "hooks",
+ "channels",
+ "connections",
+ "skills",
+ "schedules",
+ "instructions",
+ "memory",
+ "lib",
+ "extensions",
+ "subagents",
+ "tools/nested",
+ "subagents/researcher/tools",
+ ]) {
+ for (const extension of ["ts", "mts", "cts", "js", "mjs", "cjs"]) {
+ agentFiles[`${directory}/weather.test.${extension}`] = "throw new Error('test module');";
+ agentFiles[`${directory}/weather.spec.${extension}`] = "throw new Error('spec module');";
+ }
+ agentFiles[`${directory}/__tests__/fixture.json`] = "{}";
+ agentFiles[`${directory}/__tests__/weather.ts`] = "throw new Error('test directory');";
+ }
+
+ const result = await discoverAgent({ ...buildMemoryAgentProject({ agentFiles }), role });
+ expect(result).toEqual(baseline);
+ },
+ );
+
it("discovers flat and named memory slots with path-derived identities", async () => {
const flat = buildMemoryAgentProject({
agentFiles: { "instructions.md": "Remember.", "memory.ts": "export default {};" },
diff --git a/packages/eve/src/discover/filesystem.test.ts b/packages/eve/src/discover/filesystem.test.ts
index b1092cad1..dcda3fa3b 100644
--- a/packages/eve/src/discover/filesystem.test.ts
+++ b/packages/eve/src/discover/filesystem.test.ts
@@ -5,8 +5,35 @@ import {
getSupportedModuleBaseName,
isGeneratedSourceMapFileName,
isTypeScriptDeclarationFileName,
+ isAuthoredTestPath,
} from "./filesystem.js";
+describe("isAuthoredTestPath", () => {
+ it.each(["ts", "cts", "mts", "js", "cjs", "mjs"])(
+ "recognizes test modules ending in .%s",
+ (extension) => {
+ expect(isAuthoredTestPath(`tools/weather.test.${extension}`)).toBe(true);
+ expect(isAuthoredTestPath(`tools/weather.spec.${extension}`)).toBe(true);
+ expect(isAuthoredTestPath(`tools/weather.${extension}`)).toBe(false);
+ },
+ );
+
+ it("reserves only exact test directories and module suffixes", () => {
+ expect(isAuthoredTestPath("__tests__")).toBe(true);
+ expect(isAuthoredTestPath("tools/__tests__/fixture.json")).toBe(true);
+ expect(isAuthoredTestPath("tools\\__tests__\\weather.ts")).toBe(true);
+ for (const path of [
+ "tools/tests/weather.ts",
+ "tools/test-weather.ts",
+ "skills/test.md",
+ "skills/weather.test.md",
+ "tools/__tests__extra/weather.ts",
+ ]) {
+ expect(isAuthoredTestPath(path)).toBe(false);
+ }
+ });
+});
+
describe("getSupportedModuleBaseName", () => {
it("does not discover TypeScript declaration files as authored modules", () => {
expect(getSupportedModuleBaseName("echo.d.ts")).toBeNull();
diff --git a/packages/eve/src/discover/filesystem.ts b/packages/eve/src/discover/filesystem.ts
index 0288fe7f0..6c244b758 100644
--- a/packages/eve/src/discover/filesystem.ts
+++ b/packages/eve/src/discover/filesystem.ts
@@ -409,6 +409,11 @@ export function isTypeScriptDeclarationFileName(name: string): boolean {
return /\.d\.(?:cts|mts|ts)$/.test(name);
}
+/** Identifies colocated tests to omit from automatic agent source discovery. */
+export function isAuthoredTestPath(path: string): boolean {
+ return /(?:^|[/\\])__tests__(?:[/\\]|$)/.test(path) || /\.(?:test|spec)\.[cm]?[jt]s$/.test(path);
+}
+
/** Returns whether a filename is a source map for a generated module or declaration. */
export function isGeneratedSourceMapFileName(name: string): boolean {
if (!name.endsWith(".map")) return false;
diff --git a/packages/eve/src/discover/grammar.ts b/packages/eve/src/discover/grammar.ts
index fc5266bec..b53de9609 100644
--- a/packages/eve/src/discover/grammar.ts
+++ b/packages/eve/src/discover/grammar.ts
@@ -9,7 +9,11 @@ import {
createDiscoverWarningDiagnostic,
type DiscoverDiagnostic,
} from "#discover/diagnostics.js";
-import { type DirectoryEntryType, getDirectoryEntryType } from "#discover/filesystem.js";
+import {
+ type DirectoryEntryType,
+ getDirectoryEntryType,
+ isAuthoredTestPath,
+} from "#discover/filesystem.js";
import { type InstructionsSourceRef, createModuleSourceRef } from "#discover/manifest.js";
import { discoverMarkdownSource } from "#discover/markdown.js";
import { discoverNamedSourceDirectory } from "#discover/named-source-directory.js";
@@ -165,13 +169,16 @@ export const DISCOVER_UNSUPPORTED_DIRECTORY = "discover/unsupported-directory";
export type StringDirent = Dirent<string>;
/**
- * Reads one directory through `source` and returns its entries sorted by name.
+ * Reads sorted agent source entries, excluding colocated tests unless reading resources.
*/
export async function readSortedDirectoryEntries(
source: ProjectSource,
directoryPath: string,
+ options: { readonly includeTests?: boolean } = {},
): Promise<ProjectSourceEntry[]> {
- const entries = [...(await source.readDirectory(directoryPath))];
+ const entries = (await source.readDirectory(directoryPath)).filter(
+ (entry) => options.includeTests || !isAuthoredTestPath(entry.name),
+ );
entries.sort((left, right) => left.name.localeCompare(right.name));
diff --git a/packages/eve/src/discover/sandbox.integration.test.ts b/packages/eve/src/discover/sandbox.integration.test.ts
index 53236040a..273e82796 100644
--- a/packages/eve/src/discover/sandbox.integration.test.ts
+++ b/packages/eve/src/discover/sandbox.integration.test.ts
@@ -74,6 +74,8 @@ describe("discoverSandboxSource (memory)", () => {
const project = buildMemoryAgentProject({
agentFiles: {
"sandbox/workspace/notes.md": "seed",
+ "sandbox/workspace/check.test.ts": "test resource",
+ "sandbox/workspace/__tests__/check.ts": "test resource",
},
});
@@ -88,7 +90,11 @@ describe("discoverSandboxSource (memory)", () => {
expect(result.sandbox).toBeNull();
expect(result.sandboxWorkspace).not.toBeNull();
expect(result.sandboxWorkspace?.logicalPath).toBe("sandbox/workspace");
- expect(result.sandboxWorkspace?.rootEntries).toEqual(["notes.md"]);
+ expect(result.sandboxWorkspace?.rootEntries).toEqual([
+ "__tests__/",
+ "check.test.ts",
+ "notes.md",
+ ]);
});
it("discovers both a sandbox module and a workspace folder", async () => {
diff --git a/packages/eve/src/discover/sandbox.ts b/packages/eve/src/discover/sandbox.ts
index 04627c756..4910e6744 100644
--- a/packages/eve/src/discover/sandbox.ts
+++ b/packages/eve/src/discover/sandbox.ts
@@ -253,7 +253,7 @@ async function collectWorkspaceRootEntries(
source: ProjectSource,
workspacePath: string,
): Promise<readonly string[]> {
- const entries = await readSortedDirectoryEntries(source, workspacePath);
+ const entries = await readSortedDirectoryEntries(source, workspacePath, { includeTests: true });
const rendered: string[] = [];
for (const entry of entries) {
diff --git a/packages/eve/src/internal/instrumentation-layout.integration.test.ts b/packages/eve/src/internal/instrumentation-layout.integration.test.ts
index f8b636584..011d54ad1 100644
--- a/packages/eve/src/internal/instrumentation-layout.integration.test.ts
+++ b/packages/eve/src/internal/instrumentation-layout.integration.test.ts
@@ -45,6 +45,8 @@ describe("resolveInstrumentationLayout", () => {
it("ignores files that are not instrumentation modules", () => {
const otel = writeInstrumentationProvider("otel.ts");
writeInstrumentationProvider("README.md");
+ writeInstrumentationProvider("otel.test.ts");
+ writeInstrumentationProvider("otel.spec.mts");
expect(resolveInstrumentationLayout({ agentRoot }).modulePathsBySlot).toEqual({ otel });
});
diff --git a/packages/eve/src/internal/instrumentation-layout.ts b/packages/eve/src/internal/instrumentation-layout.ts
index 205a1f736..a000f9c13 100644
--- a/packages/eve/src/internal/instrumentation-layout.ts
+++ b/packages/eve/src/internal/instrumentation-layout.ts
@@ -1,6 +1,8 @@
import { existsSync, readdirSync, statSync } from "node:fs";
import { join } from "node:path";
+import { isAuthoredTestPath } from "#discover/filesystem.js";
+
const INSTRUMENTATION_EXTENSIONS = [".ts", ".mts", ".js", ".mjs"] as const;
const INSTRUMENTATION_DIRECTORY = "instrumentation";
@@ -52,7 +54,7 @@ function collectInstrumentationProviderModules(
const modulePathsBySlot = new Map<string, string>();
for (const entry of readdirSync(directoryPath, { withFileTypes: true })) {
- if (!entry.isFile()) continue;
+ if (!entry.isFile() || isAuthoredTestPath(entry.name)) continue;
const extension = INSTRUMENTATION_EXTENSIONS.find((candidate) =>
entry.name.endsWith(candidate),
diff --git a/packages/eve/src/internal/nitro/host/build-extension.scenario.test.ts b/packages/eve/src/internal/nitro/host/build-extension.scenario.test.ts
index fa508319f..26ec553b8 100644
--- a/packages/eve/src/internal/nitro/host/build-extension.scenario.test.ts
+++ b/packages/eve/src/internal/nitro/host/build-extension.scenario.test.ts
@@ -1,4 +1,4 @@
-import { mkdir, mkdtemp, readFile, rm, symlink, writeFile } from "node:fs/promises";
+import { mkdir, mkdtemp, readFile, readdir, rm, symlink, writeFile } from "node:fs/promises";
import { createRequire } from "node:module";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
@@ -64,6 +64,47 @@ async function createExtensionPackage(pkg?: Record<string, unknown>): Promise<st
}
describe("extension build output", () => {
+ it.each([true, false])(
+ "omits test runtime entries with authored tsconfig=%s",
+ async (hasTsConfig) => {
+ const root = await createExtensionPackage();
+ if (!hasTsConfig) await rm(join(root, "tsconfig.json"));
+ const files = {
+ "tools/crm_search.test.ts": hasTsConfig
+ ? 'throw new Error("test executed"); export {};'
+ : 'describe("crm", () => { it("works", () => { expect(1).toBe(1); }); });',
+ "lib/client.spec.ts": 'throw new Error("spec executed"); export {};',
+ "lib/state.test.ts":
+ 'import { defineState } from "eve/context"; export const state = defineState("test", () => 0);',
+ "tools/__tests__/setup.ts": 'throw new Error("test setup executed"); export {};',
+ "tools/__tests__/_manifest.json": "{}",
+ "skills/checks/SKILL.md":
+ "---\nname: checks\ndescription: Run checks.\n---\nRun the checks.",
+ "skills/checks/scripts/check.test.ts":
+ 'import { defineState } from "eve/context"; defineState("resource-test", () => 0);',
+ };
+ for (const [path, content] of Object.entries(files)) {
+ await mkdir(dirname(join(root, "extension", path)), { recursive: true });
+ await writeFile(join(root, "extension", path), content);
+ }
+ const config = await tryReadExtensionBuildConfig(root);
+ const outDir = await buildExtensionPackage(root, config!);
+ const emitted = await readdir(join(outDir, "extension"), { recursive: true });
+ expect(emitted.filter((path) => path.endsWith(".mjs")).sort()).toEqual([
+ "extension.mjs",
+ join("tools", "crm_search.mjs"),
+ ]);
+ expect(emitted).toContain(join("skills", "checks", "scripts", "check.test.ts"));
+ expect(emitted.includes(join("tools", "crm_search.test.d.ts"))).toBe(hasTsConfig);
+ expect(emitted.includes(join("tools", "__tests__", "setup.d.ts"))).toBe(hasTsConfig);
+ const manifestPath = join(outDir, "extension", "_manifest.json");
+ expect(
+ parseExtensionCompatibilityManifest(await readFile(manifestPath, "utf8"), manifestPath)
+ .requires,
+ ).not.toHaveProperty("state");
+ },
+ );
+
it("emits an agent-shaped runnable distribution and thin package entrypoints", async () => {
const root = await createExtensionPackage();
const config = await tryReadExtensionBuildConfig(root);
@@ -83,6 +124,40 @@ describe("extension build output", () => {
);
});
+ it("retains explicitly imported test modules without a tsconfig", async () => {
+ const root = await createExtensionPackage();
+ await rm(join(root, "tsconfig.json"));
+ await mkdir(join(root, "extension", "lib", "__tests__"), { recursive: true });
+ await writeFile(
+ join(root, "extension", "lib", "__tests__", "value.ts"),
+ 'import { defineState } from "eve/context"; export const state = defineState("value", () => 0); export const value = "imported value";',
+ );
+ await writeFile(
+ join(root, "extension", "tools", "crm_search.ts"),
+ [
+ 'import { state, value } from "../lib/__tests__/value";',
+ 'export default { description: "Search the CRM.", async execute() { return { value, hasState: state !== undefined }; } };',
+ ].join("\n"),
+ );
+ const config = await tryReadExtensionBuildConfig(root);
+ const outDir = await buildExtensionPackage(root, config!);
+ const tool = await import(
+ pathToFileURL(join(outDir, "extension", "tools", "crm_search.mjs")).href
+ );
+ await expect(tool.default.execute()).resolves.toEqual({
+ value: "imported value",
+ hasState: true,
+ });
+ expect(
+ await readFile(join(outDir, "extension", "lib", "__tests__", "value.d.ts"), "utf8"),
+ ).toContain("imported value");
+ const manifestPath = join(outDir, "extension", "_manifest.json");
+ expect(
+ parseExtensionCompatibilityManifest(await readFile(manifestPath, "utf8"), manifestPath)
+ .requires.state,
+ ).toBe(EXTENSION_CAPABILITY_VERSIONS.state);
+ });
+
it.each([
["static re-export", 'export { evaluate as assess } from "eve/ai";'],
[
@@ -413,6 +488,27 @@ export default defineHook({ events: { "turn.started": async () => {
).rejects.toMatchObject({ code: "ENOENT" });
});
+ it("preserves test files inside subagent sandbox workspaces", async () => {
+ const root = await createExtensionPackage();
+ const subagentRoot = join(root, "extension", "subagents", "researcher");
+ const workspaceFiles = {
+ "check.test.js": 'describe("workspace", () => {});',
+ "__tests__/fixture.json": '{"value":"workspace fixture"}',
+ };
+ for (const [path, content] of Object.entries(workspaceFiles)) {
+ const filePath = join(subagentRoot, "sandbox", "workspace", path);
+ await mkdir(dirname(filePath), { recursive: true });
+ await writeFile(filePath, content);
+ }
+ await writeFile(join(subagentRoot, "agent.ts"), 'export default { description: "Research." };');
+ const config = await tryReadExtensionBuildConfig(root);
+ const outDir = await buildExtensionPackage(root, config!);
+ const workspace = join(outDir, "extension", "subagents", "researcher", "sandbox", "workspace");
+ for (const [path, content] of Object.entries(workspaceFiles)) {
+ await expect(readFile(join(workspace, path), "utf8")).resolves.toBe(content);
+ }
+ });
+
it("sanitizes kebab-case tool names into valid export bindings", async () => {
const root = await createExtensionPackage();
await writeFile(
diff --git a/packages/eve/src/internal/nitro/host/build-extension.ts b/packages/eve/src/internal/nitro/host/build-extension.ts
index 0f7d45b91..a1410640e 100644
--- a/packages/eve/src/internal/nitro/host/build-extension.ts
+++ b/packages/eve/src/internal/nitro/host/build-extension.ts
@@ -92,6 +92,7 @@ export async function buildExtensionPackage(
: { build: { externalDependencies: config.externalDependencies } }),
requires: await deriveExtensionCapabilityRequirements({
runtimeImports,
+ runtimeRoot: stagedOutDir,
declarationModule,
manifest,
packageName: config.packageName,
diff --git a/packages/eve/src/internal/nitro/host/extension-capability-requirements.ts b/packages/eve/src/internal/nitro/host/extension-capability-requirements.ts
index 76d911461..262c8c8af 100644
--- a/packages/eve/src/internal/nitro/host/extension-capability-requirements.ts
+++ b/packages/eve/src/internal/nitro/host/extension-capability-requirements.ts
@@ -22,6 +22,7 @@ export async function deriveExtensionCapabilityRequirements(input: {
readonly packageName: string;
readonly runtimeDependencies: readonly string[];
readonly runtimeImports: readonly string[];
+ readonly runtimeRoot: string;
readonly shortName: string;
readonly sourceRoot: string;
}): Promise<ExtensionCapabilityRequirements> {
@@ -64,7 +65,7 @@ export async function deriveExtensionCapabilityRequirements(input: {
loadAuthoredModuleNamespace(join(input.sourceRoot, input.declarationModule.logicalPath), {
externalDependencies: input.runtimeDependencies,
}),
- extensionUsesState(input.sourceRoot),
+ extensionUsesState(input.runtimeRoot),
]);
if (tools.length > 0) required.add("tool");
diff --git a/packages/eve/src/internal/nitro/host/extension-declarations.ts b/packages/eve/src/internal/nitro/host/extension-declarations.ts
index b2b65e93c..8ee770644 100644
--- a/packages/eve/src/internal/nitro/host/extension-declarations.ts
+++ b/packages/eve/src/internal/nitro/host/extension-declarations.ts
@@ -4,7 +4,10 @@ import { createRequire } from "node:module";
import { dirname, join, relative } from "node:path";
import { promisify } from "node:util";
-import { SUPPORTED_AUTHORED_MODULE_FILE_EXTENSIONS } from "#discover/filesystem.js";
+import {
+ isAuthoredTestPath,
+ SUPPORTED_AUTHORED_MODULE_FILE_EXTENSIONS,
+} from "#discover/filesystem.js";
/**
* Emits declarations for an extension source tree using the extension's own
@@ -121,6 +124,7 @@ function declarationLogicalPath(logicalPath: string): string {
async function collectDeclarationInputs(directory: string): Promise<string[]> {
const paths: string[] = [];
for (const entry of await readdir(directory, { withFileTypes: true })) {
+ if (isAuthoredTestPath(entry.name)) continue;
const entryPath = join(directory, entry.name);
if (entry.isDirectory()) {
paths.push(...(await collectDeclarationInputs(entryPath)));
diff --git a/packages/eve/src/internal/nitro/host/extension-distribution.ts b/packages/eve/src/internal/nitro/host/extension-distribution.ts
index e4a29532d..3900424ad 100644
--- a/packages/eve/src/internal/nitro/host/extension-distribution.ts
+++ b/packages/eve/src/internal/nitro/host/extension-distribution.ts
@@ -2,7 +2,10 @@ import { cp, mkdir, readdir, rename, writeFile } from "node:fs/promises";
import { dirname, join, relative } from "node:path";
import { EXTENSION_COMPATIBILITY_MANIFEST_FILENAME } from "#compiler/extension-compatibility.js";
-import { SUPPORTED_AUTHORED_MODULE_FILE_EXTENSIONS } from "#discover/filesystem.js";
+import {
+ isAuthoredTestPath,
+ SUPPORTED_AUTHORED_MODULE_FILE_EXTENSIONS,
+} from "#discover/filesystem.js";
import type { AgentSourceManifest } from "#discover/manifest.js";
import {
bundleExtensionDistributionGraph,
@@ -24,14 +27,14 @@ export async function emitExtensionDistribution(input: {
readonly stagedOutDir: string;
readonly transactionRoot: string;
}): Promise<readonly string[]> {
- const sourceFiles = await collectExtensionSourceFiles(input.sourceRoot);
- const skillPackageRoots = input.manifest.skills
- .filter((skill) => skill.sourceKind === "skill-package")
- .map((skill) => relative(input.sourceRoot, skill.rootPath).replaceAll("\\", "/"));
+ const resourceRoots = collectExtensionResourceRoots(input.manifest).map((root) =>
+ relative(input.sourceRoot, root).replaceAll("\\", "/"),
+ );
+ const sourceFiles = await collectExtensionSourceFiles(input.sourceRoot, resourceRoots);
const moduleFiles = sourceFiles.filter(
(file) =>
isAuthoredModule(file.logicalPath) &&
- !skillPackageRoots.some((root) => file.logicalPath.startsWith(`${root}/`)),
+ !resourceRoots.some((root) => file.logicalPath.startsWith(`${root}/`)),
);
await copyDistributionDataFiles({
files: sourceFiles,
@@ -77,6 +80,16 @@ export async function emitExtensionDistribution(input: {
return emitted.imports;
}
+function collectExtensionResourceRoots(manifest: AgentSourceManifest): string[] {
+ return [
+ ...manifest.sandboxWorkspaces.map((workspace) => workspace.sourcePath),
+ ...manifest.skills.flatMap((skill) =>
+ skill.sourceKind === "skill-package" ? [skill.rootPath] : [],
+ ),
+ ...manifest.subagents.flatMap((subagent) => collectExtensionResourceRoots(subagent.manifest)),
+ ];
+}
+
/**
* Thrown when publishing failed and the prior output could not be moved back.
* The prior output survives at {@link preservedOutputPath}; callers must not
@@ -131,15 +144,21 @@ interface ExtensionSourceFile {
async function collectExtensionSourceFiles(
sourceRoot: string,
+ resourceRoots: readonly string[],
directory = sourceRoot,
): Promise<ExtensionSourceFile[]> {
const files: ExtensionSourceFile[] = [];
for (const entry of await readdir(directory, { withFileTypes: true })) {
const absolutePath = join(directory, entry.name);
+ const logicalPath = relative(sourceRoot, absolutePath).replaceAll("\\", "/");
+ if (
+ isAuthoredTestPath(logicalPath) &&
+ !resourceRoots.some((root) => logicalPath.startsWith(`${root}/`))
+ )
+ continue;
if (entry.isDirectory()) {
- files.push(...(await collectExtensionSourceFiles(sourceRoot, absolutePath)));
+ files.push(...(await collectExtensionSourceFiles(sourceRoot, resourceRoots, absolutePath)));
} else if (entry.isFile()) {
- const logicalPath = relative(sourceRoot, absolutePath).replaceAll("\\", "/");
if (logicalPath === EXTENSION_COMPATIBILITY_MANIFEST_FILENAME) {
throw new Error(
`The extension source cannot contain "${EXTENSION_COMPATIBILITY_MANIFEST_FILENAME}"; eve reserves it for generated compatibility metadata.`,
diff --git a/packages/eve/src/internal/nitro/host/extension-state-usage.ts b/packages/eve/src/internal/nitro/host/extension-state-usage.ts
index 11c4e6bb1..e070e65c7 100644
--- a/packages/eve/src/internal/nitro/host/extension-state-usage.ts
+++ b/packages/eve/src/internal/nitro/host/extension-state-usage.ts
@@ -1,20 +1,23 @@
import { readFile, readdir } from "node:fs/promises";
import { dirname, join, resolve } from "node:path";
-import { SUPPORTED_AUTHORED_MODULE_FILE_EXTENSIONS } from "#discover/filesystem.js";
+import {
+ isAuthoredTestPath,
+ SUPPORTED_AUTHORED_MODULE_FILE_EXTENSIONS,
+} from "#discover/filesystem.js";
import { parseWithNitroRolldownAst } from "#internal/bundler/nitro-rolldown.js";
const STATE_MODULE = "eve/context";
const STATE_EXPORT = "defineState";
/**
- * Detects whether an authored extension tree calls `defineState` from
+ * Detects whether emitted extension modules call `defineState` from
* `eve/context`. Usage is followed through local re-export barrels — aliased
* re-exports, `export *`, and import-then-re-export chains — so indirect
* usage still stamps the `state` capability requirement.
*/
-export async function extensionUsesState(sourceRoot: string): Promise<boolean> {
- const modulePaths = await collectAuthoredModules(sourceRoot);
+export async function extensionUsesState(runtimeRoot: string): Promise<boolean> {
+ const modulePaths = await collectRuntimeModules(runtimeRoot);
const sources = new Map<string, string>();
for (const modulePath of modulePaths) {
sources.set(modulePath, await readFile(modulePath, "utf8"));
@@ -93,12 +96,13 @@ interface ModuleStateShape {
readonly calledMembers: Map<string, Set<string>>;
}
-async function collectAuthoredModules(directory: string): Promise<string[]> {
+async function collectRuntimeModules(directory: string): Promise<string[]> {
const modules: string[] = [];
for (const entry of await readdir(directory, { withFileTypes: true })) {
+ if (isAuthoredTestPath(entry.name)) continue;
const path = join(directory, entry.name);
if (entry.isDirectory()) {
- modules.push(...(await collectAuthoredModules(path)));
+ modules.push(...(await collectRuntimeModules(path)));
} else if (
entry.isFile() &&
!/\.d\.[cm]?ts$/.test(entry.name) &&