@vitest-agent/mcp 6.3.2 → 6.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +40 -0
- package/package.json +7 -7
- package/tools/help.js +1 -1
- package/tools/history.js +42 -5
- package/tools/run-tests.js +21 -11
- package/tsdoc-metadata.json +1 -1
- package/version.js +1 -1
package/index.d.ts
CHANGED
|
@@ -1118,6 +1118,9 @@ export declare const handleHelp: () => Effect.Effect<HelpResultType>;
|
|
|
1118
1118
|
*/
|
|
1119
1119
|
export declare const TestHistoryResult: Schema.Struct<{
|
|
1120
1120
|
readonly project: Schema.String;
|
|
1121
|
+
readonly worktree: Schema.NullOr<Schema.String>;
|
|
1122
|
+
readonly totalTests: Schema.Finite;
|
|
1123
|
+
readonly truncated: Schema.Boolean;
|
|
1121
1124
|
readonly hasData: Schema.Boolean;
|
|
1122
1125
|
readonly history: Schema.Struct<{
|
|
1123
1126
|
readonly project: Schema.String;
|
|
@@ -1128,8 +1131,11 @@ export declare const TestHistoryResult: Schema.Struct<{
|
|
|
1128
1131
|
readonly runs: Schema.$Array<Schema.Struct<{
|
|
1129
1132
|
readonly timestamp: Schema.String;
|
|
1130
1133
|
readonly state: Schema.Literals<readonly ["passed", "failed"]>;
|
|
1134
|
+
readonly branch: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
1135
|
+
readonly worktreeDir: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
1131
1136
|
}>>;
|
|
1132
1137
|
}>>;
|
|
1138
|
+
readonly totalTests: Schema.optionalKey<Schema.Finite>;
|
|
1133
1139
|
}>;
|
|
1134
1140
|
readonly flaky: Schema.$Array<Schema.Struct<{
|
|
1135
1141
|
readonly fullName: Schema.String;
|
|
@@ -1210,6 +1216,9 @@ export declare const TestHistoryInput: Schema.Struct<{
|
|
|
1210
1216
|
readonly testName: Schema.optionalKey<Schema.String>;
|
|
1211
1217
|
readonly modulePath: Schema.optionalKey<Schema.String>;
|
|
1212
1218
|
readonly limit: Schema.optionalKey<Schema.Int>;
|
|
1219
|
+
readonly maxTests: Schema.optionalKey<Schema.Int>;
|
|
1220
|
+
readonly worktree: Schema.optionalKey<Schema.String>;
|
|
1221
|
+
readonly _callerCwd: Schema.optionalKey<Schema.String>;
|
|
1213
1222
|
}>;
|
|
1214
1223
|
/**
|
|
1215
1224
|
* The decoded {@link TestHistoryInput}.
|
|
@@ -1234,9 +1243,15 @@ export declare const testHistoryTool: Tool.Tool<"test_history", {
|
|
|
1234
1243
|
readonly testName: Schema.optionalKey<Schema.String>;
|
|
1235
1244
|
readonly modulePath: Schema.optionalKey<Schema.String>;
|
|
1236
1245
|
readonly limit: Schema.optionalKey<Schema.Int>;
|
|
1246
|
+
readonly maxTests: Schema.optionalKey<Schema.Int>;
|
|
1247
|
+
readonly worktree: Schema.optionalKey<Schema.String>;
|
|
1248
|
+
readonly _callerCwd: Schema.optionalKey<Schema.String>;
|
|
1237
1249
|
}>;
|
|
1238
1250
|
readonly success: Schema.Struct<{
|
|
1239
1251
|
readonly project: Schema.String;
|
|
1252
|
+
readonly worktree: Schema.NullOr<Schema.String>;
|
|
1253
|
+
readonly totalTests: Schema.Finite;
|
|
1254
|
+
readonly truncated: Schema.Boolean;
|
|
1240
1255
|
readonly hasData: Schema.Boolean;
|
|
1241
1256
|
readonly history: Schema.Struct<{
|
|
1242
1257
|
readonly project: Schema.String;
|
|
@@ -1247,8 +1262,11 @@ export declare const testHistoryTool: Tool.Tool<"test_history", {
|
|
|
1247
1262
|
readonly runs: Schema.$Array<Schema.Struct<{
|
|
1248
1263
|
readonly timestamp: Schema.String;
|
|
1249
1264
|
readonly state: Schema.Literals<readonly ["passed", "failed"]>;
|
|
1265
|
+
readonly branch: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
1266
|
+
readonly worktreeDir: Schema.optionalKey<Schema.NullOr<Schema.String>>;
|
|
1250
1267
|
}>>;
|
|
1251
1268
|
}>>;
|
|
1269
|
+
readonly totalTests: Schema.optionalKey<Schema.Finite>;
|
|
1252
1270
|
}>;
|
|
1253
1271
|
readonly flaky: Schema.$Array<Schema.Struct<{
|
|
1254
1272
|
readonly fullName: Schema.String;
|
|
@@ -1813,6 +1831,7 @@ export declare const RunTestsResult: Schema.Union<readonly [Schema.Struct<{
|
|
|
1813
1831
|
}>, Schema.Struct<{
|
|
1814
1832
|
readonly kind: Schema.Literal<"timeout">;
|
|
1815
1833
|
readonly timeoutSeconds: Schema.Number;
|
|
1834
|
+
readonly message: Schema.String;
|
|
1816
1835
|
}>, Schema.Struct<{
|
|
1817
1836
|
readonly kind: Schema.Literal<"error">;
|
|
1818
1837
|
readonly message: Schema.String;
|
|
@@ -2189,6 +2208,7 @@ export declare const runTestsTool: Tool.Tool<"run_tests", {
|
|
|
2189
2208
|
}>, Schema.Struct<{
|
|
2190
2209
|
readonly kind: Schema.Literal<"timeout">;
|
|
2191
2210
|
readonly timeoutSeconds: Schema.Number;
|
|
2211
|
+
readonly message: Schema.String;
|
|
2192
2212
|
}>, Schema.Struct<{
|
|
2193
2213
|
readonly kind: Schema.Literal<"error">;
|
|
2194
2214
|
readonly message: Schema.String;
|
|
@@ -3669,6 +3689,7 @@ export declare const Kit: Toolkit.Toolkit<{
|
|
|
3669
3689
|
}>, import("effect/Schema").Struct<{
|
|
3670
3690
|
readonly kind: import("effect/Schema").Literal<"timeout">;
|
|
3671
3691
|
readonly timeoutSeconds: import("effect/Schema").Number;
|
|
3692
|
+
readonly message: import("effect/Schema").String;
|
|
3672
3693
|
}>, import("effect/Schema").Struct<{
|
|
3673
3694
|
readonly kind: import("effect/Schema").Literal<"error">;
|
|
3674
3695
|
readonly message: import("effect/Schema").String;
|
|
@@ -4535,9 +4556,15 @@ export declare const Kit: Toolkit.Toolkit<{
|
|
|
4535
4556
|
readonly testName: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
4536
4557
|
readonly modulePath: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
4537
4558
|
readonly limit: import("effect/Schema").optionalKey<import("effect/Schema").Int>;
|
|
4559
|
+
readonly maxTests: import("effect/Schema").optionalKey<import("effect/Schema").Int>;
|
|
4560
|
+
readonly worktree: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
4561
|
+
readonly _callerCwd: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
4538
4562
|
}>;
|
|
4539
4563
|
readonly success: import("effect/Schema").Struct<{
|
|
4540
4564
|
readonly project: import("effect/Schema").String;
|
|
4565
|
+
readonly worktree: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
4566
|
+
readonly totalTests: import("effect/Schema").Finite;
|
|
4567
|
+
readonly truncated: import("effect/Schema").Boolean;
|
|
4541
4568
|
readonly hasData: import("effect/Schema").Boolean;
|
|
4542
4569
|
readonly history: import("effect/Schema").Struct<{
|
|
4543
4570
|
readonly project: import("effect/Schema").String;
|
|
@@ -4548,8 +4575,11 @@ export declare const Kit: Toolkit.Toolkit<{
|
|
|
4548
4575
|
readonly runs: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
4549
4576
|
readonly timestamp: import("effect/Schema").String;
|
|
4550
4577
|
readonly state: import("effect/Schema").Literals<readonly ["passed", "failed"]>;
|
|
4578
|
+
readonly branch: import("effect/Schema").optionalKey<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
4579
|
+
readonly worktreeDir: import("effect/Schema").optionalKey<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
4551
4580
|
}>>;
|
|
4552
4581
|
}>>;
|
|
4582
|
+
readonly totalTests: import("effect/Schema").optionalKey<import("effect/Schema").Finite>;
|
|
4553
4583
|
}>;
|
|
4554
4584
|
readonly flaky: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
4555
4585
|
readonly fullName: import("effect/Schema").String;
|
|
@@ -6254,6 +6284,7 @@ export declare const ToolsLayer: import("effect/Layer").Layer<import("effect/ai/
|
|
|
6254
6284
|
}>, import("effect/Schema").Struct<{
|
|
6255
6285
|
readonly kind: import("effect/Schema").Literal<"timeout">;
|
|
6256
6286
|
readonly timeoutSeconds: import("effect/Schema").Number;
|
|
6287
|
+
readonly message: import("effect/Schema").String;
|
|
6257
6288
|
}>, import("effect/Schema").Struct<{
|
|
6258
6289
|
readonly kind: import("effect/Schema").Literal<"error">;
|
|
6259
6290
|
readonly message: import("effect/Schema").String;
|
|
@@ -7120,9 +7151,15 @@ export declare const ToolsLayer: import("effect/Layer").Layer<import("effect/ai/
|
|
|
7120
7151
|
readonly testName: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
7121
7152
|
readonly modulePath: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
7122
7153
|
readonly limit: import("effect/Schema").optionalKey<import("effect/Schema").Int>;
|
|
7154
|
+
readonly maxTests: import("effect/Schema").optionalKey<import("effect/Schema").Int>;
|
|
7155
|
+
readonly worktree: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
7156
|
+
readonly _callerCwd: import("effect/Schema").optionalKey<import("effect/Schema").String>;
|
|
7123
7157
|
}>;
|
|
7124
7158
|
readonly success: import("effect/Schema").Struct<{
|
|
7125
7159
|
readonly project: import("effect/Schema").String;
|
|
7160
|
+
readonly worktree: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
7161
|
+
readonly totalTests: import("effect/Schema").Finite;
|
|
7162
|
+
readonly truncated: import("effect/Schema").Boolean;
|
|
7126
7163
|
readonly hasData: import("effect/Schema").Boolean;
|
|
7127
7164
|
readonly history: import("effect/Schema").Struct<{
|
|
7128
7165
|
readonly project: import("effect/Schema").String;
|
|
@@ -7133,8 +7170,11 @@ export declare const ToolsLayer: import("effect/Layer").Layer<import("effect/ai/
|
|
|
7133
7170
|
readonly runs: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
7134
7171
|
readonly timestamp: import("effect/Schema").String;
|
|
7135
7172
|
readonly state: import("effect/Schema").Literals<readonly ["passed", "failed"]>;
|
|
7173
|
+
readonly branch: import("effect/Schema").optionalKey<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
7174
|
+
readonly worktreeDir: import("effect/Schema").optionalKey<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
7136
7175
|
}>>;
|
|
7137
7176
|
}>>;
|
|
7177
|
+
readonly totalTests: import("effect/Schema").optionalKey<import("effect/Schema").Finite>;
|
|
7138
7178
|
}>;
|
|
7139
7179
|
readonly flaky: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
7140
7180
|
readonly fullName: import("effect/Schema").String;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest-agent/mcp",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Model Context Protocol server for vitest-agent. Exposes 30 tools for agent access to test data, TDD lifecycle, and session management.",
|
|
6
6
|
"keywords": [
|
|
@@ -43,16 +43,16 @@
|
|
|
43
43
|
"vitest-agent-mcp": "bin/vitest-agent-mcp.js"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@effect/platform-node": "4.1.
|
|
46
|
+
"@effect/platform-node": "4.1.7",
|
|
47
47
|
"@effected/commands": "0.22.0",
|
|
48
48
|
"@effected/git": "0.34.0",
|
|
49
49
|
"@effected/glob": "0.23.1",
|
|
50
50
|
"@effected/kit": "0.14.0",
|
|
51
|
-
"@effected/mcp-kit": "0.15.
|
|
52
|
-
"@effected/walker": "0.
|
|
53
|
-
"@vitest-agent/engine": "3.
|
|
54
|
-
"@vitest-agent/sdk": "9.
|
|
55
|
-
"effect": "4.1.
|
|
51
|
+
"@effected/mcp-kit": "0.15.2",
|
|
52
|
+
"@effected/walker": "0.32.0",
|
|
53
|
+
"@vitest-agent/engine": "3.5.0",
|
|
54
|
+
"@vitest-agent/sdk": "9.3.0",
|
|
55
|
+
"effect": "4.1.7"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"vitest": "^5.1.0"
|
package/tools/help.js
CHANGED
|
@@ -73,7 +73,7 @@ const HELP_TEXT = `# vitest-agent MCP Tools
|
|
|
73
73
|
|
|
74
74
|
| Tool | Parameters | Description |
|
|
75
75
|
| ---- | ---------- | ----------- |
|
|
76
|
-
| \`run_tests\` | \`files?\`, \`project?\`, \`tags?\`, \`passWithNoTests?\`, \`timeout?\`, \`projectRoot?\` | Run vitest with optional filters. \`tags\` is a structured \`{ all?, any?, none? }\` filter that intersects with \`project\` and \`files\` via AND. When the resolved filter set matches zero test cases the result discriminator is \`no-match\` (carrying the resolved filter context) rather than \`ok\`. \`passWithNoTests\` is a per-call override of Vitest's project-level \`test.passWithNoTests\` policy. A \`kind: "error"\` result with \`reason: "stale-install"\` means the vitest install was replaced under this long-lived server; restart the MCP server (\`/mcp\`) instead of retrying |
|
|
76
|
+
| \`run_tests\` | \`files?\`, \`project?\`, \`tags?\`, \`lastFailed?\`, \`passWithNoTests?\`, \`timeout?\`, \`projectRoot?\` | Run vitest with optional filters. \`tags\` is a structured \`{ all?, any?, none? }\` filter that intersects with \`project\` and \`files\` via AND. When the resolved filter set matches zero test cases the result discriminator is \`no-match\` (carrying the resolved filter context) rather than \`ok\`. \`passWithNoTests\` is a per-call override of Vitest's project-level \`test.passWithNoTests\` policy. A \`kind: "error"\` result with \`reason: "stale-install"\` means the vitest install was replaced under this long-lived server; restart the MCP server (\`/mcp\`) instead of retrying. \`timeout\` (seconds, default 120) is the run budget: a \`kind: "timeout"\` result means it ran out, so scope the run or raise it for a full suite of a large repo; the tests that finished are saved as an interrupted run. \`projectRoot\`: pass your worktree's absolute path when it differs from the checkout the server started in |
|
|
77
77
|
| \`register_agent\` | \`sessionId\`, \`agentType\`, \`hostKind?\`, \`parentAgentId?\`, \`clientNonce?\`, \`startGitBranch?\`, \`startGitCommitSha?\`, \`startWorktreeDir?\` | Idempotent agent invocation registration |
|
|
78
78
|
|
|
79
79
|
## Diagnostics
|
package/tools/history.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import * as NodeChildProcessSpawner from "@effect/platform-node/NodeChildProcessSpawner";
|
|
2
|
+
import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
|
|
3
|
+
import * as NodePath from "@effect/platform-node/NodePath";
|
|
4
|
+
import { Git } from "@effected/git";
|
|
1
5
|
import { DataReader } from "@vitest-agent/engine";
|
|
2
6
|
import { HistoryRecord, ModuleCacheStat, StrayOutput } from "@vitest-agent/sdk";
|
|
3
|
-
import { Effect, Schema } from "effect";
|
|
7
|
+
import { Effect, Layer, Schema } from "effect";
|
|
4
8
|
import { Tool } from "effect/ai";
|
|
5
9
|
|
|
6
10
|
// src/tools/history.ts
|
|
@@ -78,6 +82,9 @@ const RetriedTestRow = Schema.Struct({
|
|
|
78
82
|
*/
|
|
79
83
|
const TestHistoryResult = Schema.Struct({
|
|
80
84
|
project: Schema.String.annotate({ description: "Workspace project key the history was computed for." }),
|
|
85
|
+
worktree: Schema.NullOr(Schema.String).annotate({ description: "The git worktree root the history was narrowed to (issue #769): runs recorded from that checkout plus older runs that recorded none. `null` means every checkout of the repository, which all share one database." }),
|
|
86
|
+
totalTests: Schema.Finite.annotate({ description: "Tests that matched before the `maxTests` cap. More than `history.tests.length` means the list was truncated." }),
|
|
87
|
+
truncated: Schema.Boolean.annotate({ description: "`true` when `maxTests` dropped tests. Narrow with testName or modulePath, or raise maxTests, to see the rest." }),
|
|
81
88
|
hasData: Schema.Boolean.annotate({ description: "`false` when no history rows exist for the project — agent should suggest running tests first." }),
|
|
82
89
|
history: HistoryRecord.annotate({ description: "Raw per-test history record (stored in `test_runs` joins)." }),
|
|
83
90
|
flaky: Schema.Array(FlakyTestRow).annotate({ description: "Tests with mixed pass/fail outcomes recently." }),
|
|
@@ -91,6 +98,26 @@ const TestHistoryResult = Schema.Struct({
|
|
|
91
98
|
title: "test_history result",
|
|
92
99
|
description: "Per-project flaky/persistent/recovered test classifications computed from `test_runs` history."
|
|
93
100
|
});
|
|
101
|
+
/** The default `maxTests` cap (issue #769: a project-only call returned ~460 KB). */
|
|
102
|
+
const DEFAULT_MAX_TESTS = 50;
|
|
103
|
+
/** The Node platform the caller-worktree lookup runs git on; bound once so it memoizes. */
|
|
104
|
+
const GitPlatform = Git.layer.pipe(Layer.provide(NodeChildProcessSpawner.layer), Layer.provide(Layer.mergeAll(NodeFileSystem.layer, NodePath.layer)));
|
|
105
|
+
/**
|
|
106
|
+
* The worktree root to narrow to: an explicit `worktree` wins ("all" means
|
|
107
|
+
* none), else the git root of the hook-injected caller directory. Any git
|
|
108
|
+
* failure (not a repository, no git) reads every checkout rather than
|
|
109
|
+
* guessing. `Git.repoRoot` answers the physical path, as the reporter's
|
|
110
|
+
* `RunContextLive` records it.
|
|
111
|
+
*/
|
|
112
|
+
const resolveWorktree = (input) => {
|
|
113
|
+
if (input.worktree === "all") return Effect.succeed(null);
|
|
114
|
+
const explicit = input.worktree;
|
|
115
|
+
const start = explicit ?? input._callerCwd;
|
|
116
|
+
if (start === void 0) return Effect.succeed(null);
|
|
117
|
+
return Effect.gen(function* () {
|
|
118
|
+
return yield* (yield* Git).repoRoot(start);
|
|
119
|
+
}).pipe(Effect.provide(GitPlatform), Effect.orElseSucceed(() => explicit ?? null));
|
|
120
|
+
};
|
|
94
121
|
/**
|
|
95
122
|
* The `test_history` tool's parameters.
|
|
96
123
|
*
|
|
@@ -100,7 +127,10 @@ const TestHistoryInput = Schema.Struct({
|
|
|
100
127
|
project: Schema.String.annotate({ description: "Project name (required)" }),
|
|
101
128
|
testName: Schema.optionalKey(Schema.String).annotate({ description: "Exact full_name match — narrows to a single test's history." }),
|
|
102
129
|
modulePath: Schema.optionalKey(Schema.String).annotate({ description: "Exact module_path match — narrows to tests in one file." }),
|
|
103
|
-
limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0)).annotate({ description: "Max runs kept per test, most-recent-first. Must be a positive integer. Default 20." }))
|
|
130
|
+
limit: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0)).annotate({ description: "Max runs kept per test, most-recent-first. Must be a positive integer. Default 20; at most 10 are stored per test." })),
|
|
131
|
+
maxTests: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0)).annotate({ description: `Max tests returned (default ${DEFAULT_MAX_TESTS}). Tests with a recent failure come first; \`truncated\` says whether any were dropped.` })),
|
|
132
|
+
worktree: Schema.optionalKey(Schema.String).annotate({ description: "Which checkout's runs to read. Omit it for the calling worktree (from the hook-injected caller directory; every checkout when that is absent), pass a path inside another checkout (resolved to its worktree root), or \"all\" for every checkout." }),
|
|
133
|
+
_callerCwd: Schema.optionalKey(Schema.String).annotate({ description: "Hook-injected caller working directory; do not pass manually." })
|
|
104
134
|
});
|
|
105
135
|
/**
|
|
106
136
|
* Handler for {@link testHistoryTool}.
|
|
@@ -109,13 +139,16 @@ const TestHistoryInput = Schema.Struct({
|
|
|
109
139
|
*/
|
|
110
140
|
const handleTestHistory = (input) => Effect.gen(function* () {
|
|
111
141
|
const reader = yield* DataReader;
|
|
142
|
+
const worktree = yield* resolveWorktree(input);
|
|
112
143
|
const scopeOptions = {
|
|
113
144
|
...input.testName !== void 0 && { testName: input.testName },
|
|
114
|
-
...input.modulePath !== void 0 && { modulePath: input.modulePath }
|
|
145
|
+
...input.modulePath !== void 0 && { modulePath: input.modulePath },
|
|
146
|
+
...worktree !== null && { worktreeDir: worktree }
|
|
115
147
|
};
|
|
116
148
|
const historyOptions = {
|
|
117
149
|
...scopeOptions,
|
|
118
|
-
...input.limit !== void 0 && { limit: input.limit }
|
|
150
|
+
...input.limit !== void 0 && { limit: input.limit },
|
|
151
|
+
maxTests: input.maxTests ?? DEFAULT_MAX_TESTS
|
|
119
152
|
};
|
|
120
153
|
const [history, flaky, persistent, strayOutput, cacheHistory, retried] = yield* Effect.all([
|
|
121
154
|
reader.getHistory(input.project, historyOptions),
|
|
@@ -137,8 +170,12 @@ const handleTestHistory = (input) => Effect.gen(function* () {
|
|
|
137
170
|
recentRuns: t.runs.slice(0, 10).reverse().map((r) => r.state)
|
|
138
171
|
}));
|
|
139
172
|
const hasData = history.tests.length > 0 || flaky.length > 0 || persistent.length > 0;
|
|
173
|
+
const totalTests = history.totalTests ?? history.tests.length;
|
|
140
174
|
return {
|
|
141
175
|
project: input.project,
|
|
176
|
+
worktree,
|
|
177
|
+
totalTests,
|
|
178
|
+
truncated: totalTests > history.tests.length,
|
|
142
179
|
hasData,
|
|
143
180
|
history,
|
|
144
181
|
flaky,
|
|
@@ -158,7 +195,7 @@ const handleTestHistory = (input) => Effect.gen(function* () {
|
|
|
158
195
|
* @public
|
|
159
196
|
*/
|
|
160
197
|
const testHistoryTool = Tool.make("test_history", {
|
|
161
|
-
description: "Use when failures recur and you need flaky, persistent, and recovered test classifications. Returns a typed JSON object in structuredContent (project, hasData, history, flaky[], persistent[], recovered[], strayOutput: how many of the last 10 runs wrote straight to the terminal, moduleCache: the recent runs' fs module cache stats newest first to compare cold and warm runs, retried[]: tests that ran more than one attempt in the latest run with the state and error ids of each attempt). Optional testName/modulePath narrow to a single test; limit caps runs kept per test (default 20)
|
|
198
|
+
description: "Use when failures recur and you need flaky, persistent, and recovered test classifications. Returns a typed JSON object in structuredContent (project, hasData, history, flaky[], persistent[], recovered[], strayOutput: how many of the last 10 runs wrote straight to the terminal, moduleCache: the recent runs' fs module cache stats newest first to compare cold and warm runs, retried[]: tests that ran more than one attempt in the latest run with the state and error ids of each attempt). Optional testName/modulePath narrow to a single test; limit caps runs kept per test (default 20) ; maxTests caps the number of tests (default 50, failing tests first; truncated says whether any were dropped). History defaults to the calling worktree (every checkout of a repository shares one database); worktree: 'all' reads every checkout, and each run carries the branch and worktree it came from.",
|
|
162
199
|
parameters: TestHistoryInput,
|
|
163
200
|
success: TestHistoryResult,
|
|
164
201
|
dependencies: [DataReader]
|
package/tools/run-tests.js
CHANGED
|
@@ -46,7 +46,8 @@ const RunTestsOk = Schema.Struct({
|
|
|
46
46
|
}).annotate({ identifier: "RunTestsOk" });
|
|
47
47
|
const RunTestsTimeout = Schema.Struct({
|
|
48
48
|
kind: Schema.Literal("timeout"),
|
|
49
|
-
timeoutSeconds: Schema.Number
|
|
49
|
+
timeoutSeconds: Schema.Number,
|
|
50
|
+
message: Schema.String.annotate({ description: "What happened and what to do next (issue #762): the run exceeded `timeout` and was cancelled, the tests that finished were saved as an `interrupted` run the query tools can read, and the next call should scope the run or pass a larger `timeout`." })
|
|
50
51
|
}).annotate({ identifier: "RunTestsTimeout" });
|
|
51
52
|
/**
|
|
52
53
|
* The machine-readable reasons a `run_tests` error result may carry. Only
|
|
@@ -450,6 +451,17 @@ const runTestsLane = Effect.runSync(Exclusive.make);
|
|
|
450
451
|
*/
|
|
451
452
|
const LANE_ALLOWANCE_MS = 12e4;
|
|
452
453
|
/**
|
|
454
|
+
* How long a timed-out run may take to wind down after `cancelCurrentRun`
|
|
455
|
+
* (issue #762) before the scope's `close()` tears it down regardless.
|
|
456
|
+
*/
|
|
457
|
+
const CANCEL_GRACE_MS = 3e4;
|
|
458
|
+
/** The `message` of a timeout result: names the knob, so the agent's next call can use it. */
|
|
459
|
+
const timeoutResult = (timeoutSeconds) => ({
|
|
460
|
+
kind: "timeout",
|
|
461
|
+
timeoutSeconds,
|
|
462
|
+
message: `The run exceeded its ${timeoutSeconds} s timeout and was cancelled. Tests that finished were saved as an interrupted run (when the project loads AgentPlugin), so the query tools can read them. Scope the run with files, project or tags, or pass a larger timeout (in seconds, e.g. timeout: 900) for a full suite of a large repo.`
|
|
463
|
+
});
|
|
464
|
+
/**
|
|
453
465
|
* Coerce unknown Vitest unhandled errors into VitestModuleError shape.
|
|
454
466
|
*
|
|
455
467
|
* @internal
|
|
@@ -479,7 +491,7 @@ const RunTestsInput = Schema.Struct({
|
|
|
479
491
|
tags: Schema.optionalKey(TagFilter).annotate({ description: "Structured tag filter; all/any/none AND together with each other and with project/files" }),
|
|
480
492
|
lastFailed: Schema.optionalKey(Schema.Boolean).annotate({ description: "Run only the tests that failed in their last run, using Vitest's `--last-failed` results cache. Counts as a filter: a run that selects nothing (no recorded failures, or `cache: false` in the Vitest config, which always selects nothing) returns the `no-match` result rather than an error, and the coverage-scope note applies." }),
|
|
481
493
|
passWithNoTests: Schema.optionalKey(Schema.Boolean).annotate({ description: "Per-call override of Vitest's native test.passWithNoTests" }),
|
|
482
|
-
timeout: Schema.optionalKey(Schema.Finite).annotate({ description: "
|
|
494
|
+
timeout: Schema.optionalKey(Schema.Finite).annotate({ description: "Run budget in seconds (default: 120). The default suits a scoped run; raise it for an unscoped run of a large suite." }),
|
|
483
495
|
_callerCwd: Schema.optionalKey(Schema.String).annotate({ description: "Hook-injected caller working directory; do not pass manually." }),
|
|
484
496
|
_sessionContext: Schema.optionalKey(Schema.Struct({
|
|
485
497
|
chatId: Schema.String,
|
|
@@ -652,10 +664,10 @@ const runVitest = (args) => Effect.gen(function* () {
|
|
|
652
664
|
outcome: "ok",
|
|
653
665
|
value
|
|
654
666
|
})), Effect.catchTag("TimeoutError", () => Effect.succeed({ outcome: "timeout" })), Effect.catchTag("RunStepFailure", (failure) => hasFilter && isFilesNotFound(failure.cause) ? Effect.succeed({ outcome: "no-match" }) : Effect.fail(failure)));
|
|
655
|
-
if (started.outcome === "timeout")
|
|
656
|
-
|
|
657
|
-
timeoutSeconds
|
|
658
|
-
}
|
|
667
|
+
if (started.outcome === "timeout") {
|
|
668
|
+
yield* Effect.tryPromise(() => vitest.cancelCurrentRun("keyboard-input")).pipe(Effect.timeout(CANCEL_GRACE_MS), Effect.ignore);
|
|
669
|
+
return timeoutResult(timeoutSeconds);
|
|
670
|
+
}
|
|
659
671
|
if (started.outcome === "no-match") return toNoMatch(scope, resolvedRoot);
|
|
660
672
|
const result = started.value;
|
|
661
673
|
const testModules = result.testModules;
|
|
@@ -747,6 +759,7 @@ const runTestsBody = (input, ctx) => Effect.gen(function* () {
|
|
|
747
759
|
reason: "stale-install",
|
|
748
760
|
message: staleMessage
|
|
749
761
|
};
|
|
762
|
+
yield* ProcessScope.env(process.env, { NODE_PATH: void 0 });
|
|
750
763
|
const recovered = input._sessionContext ?? ctx.sessionContext.get();
|
|
751
764
|
if (recovered !== null) yield* ProcessScope.env(process.env, {
|
|
752
765
|
VITEST_AGENT_CHAT_ID: recovered.chatId,
|
|
@@ -798,10 +811,7 @@ const handleRunTests = (input) => Effect.gen(function* () {
|
|
|
798
811
|
onNone: () => NodeFileSystem.layer,
|
|
799
812
|
onSome: (service) => Layer.succeed(FileSystem.FileSystem, service)
|
|
800
813
|
});
|
|
801
|
-
return yield* runTestsLane.run(runTestsBody(input, ctx), { timeout: timeoutSeconds * 1e3 + LANE_ALLOWANCE_MS }).pipe(Effect.catchTag("ExclusiveTimeout", () => Effect.succeed(
|
|
802
|
-
kind: "timeout",
|
|
803
|
-
timeoutSeconds
|
|
804
|
-
})), Effect.provide(platformFs));
|
|
814
|
+
return yield* runTestsLane.run(runTestsBody(input, ctx), { timeout: timeoutSeconds * 1e3 + LANE_ALLOWANCE_MS }).pipe(Effect.catchTag("ExclusiveTimeout", () => Effect.succeed(timeoutResult(timeoutSeconds))), Effect.provide(platformFs));
|
|
805
815
|
});
|
|
806
816
|
/**
|
|
807
817
|
* The Effect-native `run_tests` tool.
|
|
@@ -809,7 +819,7 @@ const handleRunTests = (input) => Effect.gen(function* () {
|
|
|
809
819
|
* @public
|
|
810
820
|
*/
|
|
811
821
|
const runTestsTool = Tool.make("run_tests", {
|
|
812
|
-
description: "Use to run Vitest tests, with optional file, project, and tag filters. structuredContent carries the typed AgentReport plus per-test classifications (discriminate on `kind`: ok, timeout, error, no-match). Unknown parameters are rejected — accepted keys are files, project, tags, lastFailed, passWithNoTests, timeout, projectRoot. Set lastFailed to rerun only the tests that failed in their last run (the Vitest last-failed results cache); a run that selects nothing returns kind no-match. When projectRoot is omitted, the server anchors the Vitest root at the directory of the vitest (or vite) config Vitest would load anyway, walking up from its boot dir and stopping at the git root — so a server booted inside a package subtree still resolves the root config's relative globalSetup/setupFiles correctly. projectRoot overrides that for this call and is used verbatim, but only after validation: it must be an existing directory belonging to the same git repository as ctx.cwd (checked via `git rev-parse --path-format=absolute --git-common-dir`, which needs git 2.31 or newer and is identical across a repo and all its worktrees, including a sibling worktree checked out from the same repo). A path in a different repository, or a non-existent path, is rejected with `{ kind: \"error\" }` naming both paths — never a silent fallback to ctx.cwd. The resolved root actually used is always echoed back on success. When the plugin hook supplies the caller working directory (the hook-injected _callerCwd), a call from a different working tree of the same repository than the resolved root is refused with `{ kind: \"error\" }` naming both trees; pass projectRoot (your own worktree path) to run there. An absent or indeterminate caller directory never refuses. An error result with `reason: \"stale-install\"` means the vitest install was replaced under this long-lived server (the lockfile was regenerated) and the resolved vitest/node entry is gone; restart the MCP server (/mcp in Claude Code) rather than retrying. The legacy format=json arg is dropped — structuredContent supersedes it.",
|
|
822
|
+
description: "Use to run Vitest tests, with optional file, project, and tag filters. structuredContent carries the typed AgentReport plus per-test classifications (discriminate on `kind`: ok, timeout, error, no-match). Unknown parameters are rejected — accepted keys are files, project, tags, lastFailed, passWithNoTests, timeout, projectRoot. Set lastFailed to rerun only the tests that failed in their last run (the Vitest last-failed results cache); a run that selects nothing returns kind no-match. When projectRoot is omitted, the server anchors the Vitest root at the directory of the vitest (or vite) config Vitest would load anyway, walking up from its boot dir and stopping at the git root — so a server booted inside a package subtree still resolves the root config's relative globalSetup/setupFiles correctly. projectRoot overrides that for this call and is used verbatim, but only after validation: it must be an existing directory belonging to the same git repository as ctx.cwd (checked via `git rev-parse --path-format=absolute --git-common-dir`, which needs git 2.31 or newer and is identical across a repo and all its worktrees, including a sibling worktree checked out from the same repo). A path in a different repository, or a non-existent path, is rejected with `{ kind: \"error\" }` naming both paths — never a silent fallback to ctx.cwd. The resolved root actually used is always echoed back on success. When the plugin hook supplies the caller working directory (the hook-injected _callerCwd), a call from a different working tree of the same repository than the resolved root is refused with `{ kind: \"error\" }` naming both trees; pass projectRoot (your own worktree path) to run there. An absent or indeterminate caller directory never refuses. An error result with `reason: \"stale-install\"` means the vitest install was replaced under this long-lived server (the lockfile was regenerated) and the resolved vitest/node entry is gone; restart the MCP server (/mcp in Claude Code) rather than retrying. A timeout result means the budget ran out: scope the run or pass a larger timeout (seconds, default 120); tests that finished are saved as an interrupted run. The NODE_PATH of the server process (set by the package-manager shim that launched it) is removed for the run, so tests resolve modules from the project rather than from the launching install. The legacy format=json arg is dropped — structuredContent supersedes it.",
|
|
813
823
|
parameters: RunTestsInput,
|
|
814
824
|
success: RunTestsResult,
|
|
815
825
|
dependencies: [
|
package/tsdoc-metadata.json
CHANGED