@vitest-agent/engine 3.4.3 → 3.5.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 +18 -1
- package/layers/DataReaderLive.js +59 -26
- package/lib/format-triage.js +1 -1
- package/package.json +2 -2
- package/testing.d.ts +18 -1
- package/version.js +1 -1
package/index.d.ts
CHANGED
|
@@ -821,6 +821,11 @@ export interface RetriedTestQueryOptions {
|
|
|
821
821
|
readonly testName?: string;
|
|
822
822
|
/** Exact module path match. */
|
|
823
823
|
readonly modulePath?: string;
|
|
824
|
+
/**
|
|
825
|
+
* Read the latest run recorded from this git worktree root (or one that recorded none) instead of the
|
|
826
|
+
* project's latest run from any checkout.
|
|
827
|
+
*/
|
|
828
|
+
readonly worktreeDir?: string;
|
|
824
829
|
}
|
|
825
830
|
/** @public */
|
|
826
831
|
export interface NoteRow {
|
|
@@ -914,8 +919,18 @@ export interface HistoryQueryOptions {
|
|
|
914
919
|
readonly testName?: string;
|
|
915
920
|
/** Exact `module_path` match — narrows to tests in one file. */
|
|
916
921
|
readonly modulePath?: string;
|
|
917
|
-
/** Max runs kept per (module_path, full_name) pair, most-recent-first. Default 20. */
|
|
922
|
+
/** Max runs kept per (module_path, full_name) pair, most-recent-first. Default 20 (the writer keeps 10). */
|
|
918
923
|
readonly limit?: number;
|
|
924
|
+
/**
|
|
925
|
+
* Keep only runs recorded from this git worktree root (`test_runs.git_worktree_dir`),
|
|
926
|
+
* plus runs that recorded none (older rows). Unset reads every checkout.
|
|
927
|
+
*/
|
|
928
|
+
readonly worktreeDir?: string;
|
|
929
|
+
/**
|
|
930
|
+
* Max tests returned. Tests with a failure in the window come first, then by module path and name.
|
|
931
|
+
* Unset returns every test; `HistoryRecord.totalTests` carries the uncapped count either way.
|
|
932
|
+
*/
|
|
933
|
+
readonly maxTests?: number;
|
|
919
934
|
}
|
|
920
935
|
/**
|
|
921
936
|
* Narrowing options shared by the classification reads
|
|
@@ -932,6 +947,8 @@ export interface ClassificationQueryOptions {
|
|
|
932
947
|
readonly testName?: string;
|
|
933
948
|
/** Exact `module_path` match — narrows to tests in one file. */
|
|
934
949
|
readonly modulePath?: string;
|
|
950
|
+
/** Same worktree filter as {@link HistoryQueryOptions.worktreeDir}. */
|
|
951
|
+
readonly worktreeDir?: string;
|
|
935
952
|
}
|
|
936
953
|
/**
|
|
937
954
|
* Narrowing options for `DataReader.getTestByFullName`. A
|
package/layers/DataReaderLive.js
CHANGED
|
@@ -327,37 +327,59 @@ const DataReaderLive = Layer.effect(DataReader, Effect.gen(function* () {
|
|
|
327
327
|
const testName = options?.testName ?? null;
|
|
328
328
|
const modulePath = options?.modulePath ?? null;
|
|
329
329
|
const limit = options?.limit ?? 20;
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
WHERE project = ${project}
|
|
338
|
-
AND (${testName} IS NULL OR full_name = ${testName})
|
|
339
|
-
AND (${modulePath} IS NULL OR module_path = ${modulePath})
|
|
330
|
+
const worktreeDir = options?.worktreeDir ?? null;
|
|
331
|
+
const maxTests = options?.maxTests ?? null;
|
|
332
|
+
const rows = yield* sql`WITH scoped AS (
|
|
333
|
+
SELECT th.module_path, th.full_name, th.timestamp, th.state,
|
|
334
|
+
COALESCE(r.git_branch, r.branch) AS branch, r.git_worktree_dir AS worktree_dir
|
|
335
|
+
FROM test_history th
|
|
336
|
+
JOIN test_runs r ON r.id = th.run_id
|
|
337
|
+
WHERE th.project = ${project}
|
|
338
|
+
AND (${testName} IS NULL OR th.full_name = ${testName})
|
|
339
|
+
AND (${modulePath} IS NULL OR th.module_path = ${modulePath})
|
|
340
|
+
AND (${worktreeDir} IS NULL OR r.git_worktree_dir IS NULL OR r.git_worktree_dir = ${worktreeDir})
|
|
341
|
+
),
|
|
342
|
+
ranked AS (
|
|
343
|
+
SELECT *, ROW_NUMBER() OVER (
|
|
344
|
+
PARTITION BY module_path, full_name
|
|
345
|
+
ORDER BY timestamp DESC
|
|
346
|
+
) AS rn
|
|
347
|
+
FROM scoped
|
|
348
|
+
),
|
|
349
|
+
windowed AS (SELECT * FROM ranked WHERE rn <= ${limit}),
|
|
350
|
+
tests AS (
|
|
351
|
+
SELECT module_path, full_name, MAX(CASE WHEN state = 'failed' THEN 1 ELSE 0 END) AS has_fail
|
|
352
|
+
FROM windowed
|
|
353
|
+
WHERE state IN ('passed', 'failed')
|
|
354
|
+
GROUP BY module_path, full_name
|
|
355
|
+
),
|
|
356
|
+
ordered AS (
|
|
357
|
+
SELECT module_path, full_name,
|
|
358
|
+
ROW_NUMBER() OVER (ORDER BY has_fail DESC, module_path, full_name) AS test_rank,
|
|
359
|
+
COUNT(*) OVER () AS total_tests
|
|
360
|
+
FROM tests
|
|
340
361
|
)
|
|
341
|
-
SELECT module_path, full_name, timestamp, state
|
|
342
|
-
FROM
|
|
343
|
-
|
|
344
|
-
|
|
362
|
+
SELECT w.module_path, w.full_name, w.timestamp, w.state, w.branch, w.worktree_dir, o.total_tests
|
|
363
|
+
FROM windowed w
|
|
364
|
+
JOIN ordered o ON o.module_path = w.module_path AND o.full_name = w.full_name
|
|
365
|
+
WHERE (${maxTests} IS NULL OR o.test_rank <= ${maxTests})
|
|
366
|
+
ORDER BY w.module_path, w.full_name, w.timestamp DESC`;
|
|
345
367
|
const testsMap = /* @__PURE__ */ new Map();
|
|
346
368
|
for (const row of rows) {
|
|
347
369
|
if (row.state !== "passed" && row.state !== "failed") continue;
|
|
370
|
+
const run = {
|
|
371
|
+
timestamp: row.timestamp,
|
|
372
|
+
state: row.state,
|
|
373
|
+
branch: row.branch,
|
|
374
|
+
worktreeDir: row.worktree_dir
|
|
375
|
+
};
|
|
348
376
|
const key = historyKey(row.module_path, row.full_name);
|
|
349
377
|
const existing = testsMap.get(key);
|
|
350
|
-
if (existing) existing.runs.push(
|
|
351
|
-
timestamp: row.timestamp,
|
|
352
|
-
state: row.state
|
|
353
|
-
});
|
|
378
|
+
if (existing) existing.runs.push(run);
|
|
354
379
|
else testsMap.set(key, {
|
|
355
380
|
modulePath: row.module_path,
|
|
356
381
|
fullName: row.full_name,
|
|
357
|
-
runs: [
|
|
358
|
-
timestamp: row.timestamp,
|
|
359
|
-
state: row.state
|
|
360
|
-
}]
|
|
382
|
+
runs: [run]
|
|
361
383
|
});
|
|
362
384
|
}
|
|
363
385
|
const tests = Array.from(testsMap.values()).map(({ modulePath, fullName, runs }) => ({
|
|
@@ -372,7 +394,8 @@ const DataReaderLive = Layer.effect(DataReader, Effect.gen(function* () {
|
|
|
372
394
|
if (ts > latest) return ts;
|
|
373
395
|
return latest;
|
|
374
396
|
}, "") || DateTime.formatIso(yield* DateTime.now),
|
|
375
|
-
tests
|
|
397
|
+
tests,
|
|
398
|
+
totalTests: rows[0]?.total_tests ?? 0
|
|
376
399
|
};
|
|
377
400
|
}).pipe(Effect.annotateLogs("service", "DataReader"), Effect.mapError((e) => new DataStoreError({
|
|
378
401
|
operation: "read",
|
|
@@ -471,6 +494,7 @@ const DataReaderLive = Layer.effect(DataReader, Effect.gen(function* () {
|
|
|
471
494
|
}));
|
|
472
495
|
const testName = options?.testName ?? null;
|
|
473
496
|
const modulePath = options?.modulePath ?? null;
|
|
497
|
+
const worktreeDir = options?.worktreeDir ?? null;
|
|
474
498
|
return (yield* sql`SELECT
|
|
475
499
|
th1.full_name,
|
|
476
500
|
th1.module_path,
|
|
@@ -487,6 +511,9 @@ const DataReaderLive = Layer.effect(DataReader, Effect.gen(function* () {
|
|
|
487
511
|
WHERE th1.project = ${project}
|
|
488
512
|
AND (${testName} IS NULL OR th1.full_name = ${testName})
|
|
489
513
|
AND (${modulePath} IS NULL OR th1.module_path = ${modulePath})
|
|
514
|
+
AND (${worktreeDir} IS NULL OR th1.run_id IN (
|
|
515
|
+
SELECT id FROM test_runs WHERE git_worktree_dir IS NULL OR git_worktree_dir = ${worktreeDir}
|
|
516
|
+
))
|
|
490
517
|
GROUP BY th1.full_name, th1.module_path, th1.project
|
|
491
518
|
-- Flaky means oscillation, not a clean recovery. A test with both
|
|
492
519
|
-- passes and fails is only flaky when at least one failure occurs at
|
|
@@ -518,6 +545,7 @@ const DataReaderLive = Layer.effect(DataReader, Effect.gen(function* () {
|
|
|
518
545
|
}));
|
|
519
546
|
const testName = options?.testName ?? null;
|
|
520
547
|
const modulePath = options?.modulePath ?? null;
|
|
548
|
+
const worktreeDir = options?.worktreeDir ?? null;
|
|
521
549
|
return (yield* sql`WITH ranked AS (
|
|
522
550
|
SELECT full_name, module_path, project, state, timestamp, error_message,
|
|
523
551
|
ROW_NUMBER() OVER (
|
|
@@ -528,6 +556,9 @@ const DataReaderLive = Layer.effect(DataReader, Effect.gen(function* () {
|
|
|
528
556
|
WHERE project = ${project}
|
|
529
557
|
AND (${testName} IS NULL OR full_name = ${testName})
|
|
530
558
|
AND (${modulePath} IS NULL OR module_path = ${modulePath})
|
|
559
|
+
AND (${worktreeDir} IS NULL OR run_id IN (
|
|
560
|
+
SELECT id FROM test_runs WHERE git_worktree_dir IS NULL OR git_worktree_dir = ${worktreeDir}
|
|
561
|
+
))
|
|
531
562
|
),
|
|
532
563
|
streak AS (
|
|
533
564
|
SELECT full_name, module_path, project, state, timestamp, error_message, rn,
|
|
@@ -763,8 +794,10 @@ const DataReaderLive = Layer.effect(DataReader, Effect.gen(function* () {
|
|
|
763
794
|
table: "test_errors",
|
|
764
795
|
reason: extractSqlReason(e)
|
|
765
796
|
})));
|
|
766
|
-
const latestRunId = (project) => Effect.gen(function* () {
|
|
767
|
-
const runs = yield* sql`SELECT id FROM test_runs WHERE project = ${project}
|
|
797
|
+
const latestRunId = (project, worktreeDir = null) => Effect.gen(function* () {
|
|
798
|
+
const runs = yield* sql`SELECT id FROM test_runs WHERE project = ${project}
|
|
799
|
+
AND (${worktreeDir} IS NULL OR git_worktree_dir IS NULL OR git_worktree_dir = ${worktreeDir})
|
|
800
|
+
ORDER BY timestamp DESC LIMIT 1`;
|
|
768
801
|
return runs.length === 0 ? null : runs[0].id;
|
|
769
802
|
});
|
|
770
803
|
/**
|
|
@@ -795,7 +828,7 @@ const DataReaderLive = Layer.effect(DataReader, Effect.gen(function* () {
|
|
|
795
828
|
project,
|
|
796
829
|
...options
|
|
797
830
|
}));
|
|
798
|
-
const runId = yield* latestRunId(project);
|
|
831
|
+
const runId = yield* latestRunId(project, options?.worktreeDir ?? null);
|
|
799
832
|
if (runId === null) return [];
|
|
800
833
|
const testName = options?.testName ?? null;
|
|
801
834
|
const modulePath = options?.modulePath ?? null;
|
package/lib/format-triage.js
CHANGED
|
@@ -85,7 +85,7 @@ const formatTriageEffect = (options = {}) => Effect.gen(function* () {
|
|
|
85
85
|
lines.push("");
|
|
86
86
|
lines.push("- `run_tests` — run Vitest programmatically; returns AgentReport + classifications");
|
|
87
87
|
lines.push("- `test_errors` — failure detail (after a failing run)");
|
|
88
|
-
lines.push("- `test_history` —
|
|
88
|
+
lines.push("- `test_history` — one test's run series (pass `testName` or `modulePath`; after recurring failures)");
|
|
89
89
|
lines.push("- `file_coverage` — per-file coverage gaps (after coverage drops)");
|
|
90
90
|
lines.push("- `triage_brief` — orient on the current test landscape");
|
|
91
91
|
lines.push("");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest-agent/engine",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Shared services, layers, SQLite data layer, migrations and platform resolution for the vitest-agent CLI and MCP server.",
|
|
6
6
|
"keywords": [
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"@effected/workspaces": "0.49.3",
|
|
59
59
|
"@effected/xdg": "0.24.0",
|
|
60
60
|
"@effected/yaml": "0.31.0",
|
|
61
|
-
"@vitest-agent/sdk": "9.
|
|
61
|
+
"@vitest-agent/sdk": "9.3.0",
|
|
62
62
|
"effect": "4.1.7"
|
|
63
63
|
},
|
|
64
64
|
"engines": {
|
package/testing.d.ts
CHANGED
|
@@ -750,6 +750,11 @@ interface RetriedTestQueryOptions {
|
|
|
750
750
|
readonly testName?: string;
|
|
751
751
|
/** Exact module path match. */
|
|
752
752
|
readonly modulePath?: string;
|
|
753
|
+
/**
|
|
754
|
+
* Read the latest run recorded from this git worktree root (or one that recorded none) instead of the
|
|
755
|
+
* project's latest run from any checkout.
|
|
756
|
+
*/
|
|
757
|
+
readonly worktreeDir?: string;
|
|
753
758
|
}
|
|
754
759
|
/** @public */
|
|
755
760
|
interface NoteRow {
|
|
@@ -843,8 +848,18 @@ interface HistoryQueryOptions {
|
|
|
843
848
|
readonly testName?: string;
|
|
844
849
|
/** Exact `module_path` match — narrows to tests in one file. */
|
|
845
850
|
readonly modulePath?: string;
|
|
846
|
-
/** Max runs kept per (module_path, full_name) pair, most-recent-first. Default 20. */
|
|
851
|
+
/** Max runs kept per (module_path, full_name) pair, most-recent-first. Default 20 (the writer keeps 10). */
|
|
847
852
|
readonly limit?: number;
|
|
853
|
+
/**
|
|
854
|
+
* Keep only runs recorded from this git worktree root (`test_runs.git_worktree_dir`),
|
|
855
|
+
* plus runs that recorded none (older rows). Unset reads every checkout.
|
|
856
|
+
*/
|
|
857
|
+
readonly worktreeDir?: string;
|
|
858
|
+
/**
|
|
859
|
+
* Max tests returned. Tests with a failure in the window come first, then by module path and name.
|
|
860
|
+
* Unset returns every test; `HistoryRecord.totalTests` carries the uncapped count either way.
|
|
861
|
+
*/
|
|
862
|
+
readonly maxTests?: number;
|
|
848
863
|
}
|
|
849
864
|
/**
|
|
850
865
|
* Narrowing options shared by the classification reads
|
|
@@ -861,6 +876,8 @@ interface ClassificationQueryOptions {
|
|
|
861
876
|
readonly testName?: string;
|
|
862
877
|
/** Exact `module_path` match — narrows to tests in one file. */
|
|
863
878
|
readonly modulePath?: string;
|
|
879
|
+
/** Same worktree filter as {@link HistoryQueryOptions.worktreeDir}. */
|
|
880
|
+
readonly worktreeDir?: string;
|
|
864
881
|
}
|
|
865
882
|
/**
|
|
866
883
|
* Narrowing options for `DataReader.getTestByFullName`. A
|
package/version.js
CHANGED