@vitest-agent/engine 3.3.0 → 3.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 CHANGED
@@ -12,7 +12,7 @@
12
12
  */
13
13
  import { Context, Effect, FileSystem, Layer, LogLevel, Option, Path, Schema } from "effect";
14
14
  import { ConfigCodecError, ConfigFileShape, ConfigReadError } from "@effected/config-file";
15
- import { Agent, AgentNotFoundError, AgentReport, ArtifactKind, ArtifactKind as ArtifactKind$1, ArtifactSuite, ArtifactSuite as ArtifactSuite$1, BehaviorDetail, BehaviorNotFoundError, BehaviorRow, BehaviorStatus, CacheManifest, CitedArtifact, CoverageBaselines, CoverageReport, DataStoreError, DetailLevel, DiscoveryError, Environment, Executor, FileCoverageReport, GoalDetail, GoalNotFoundError, GoalRow, GoalStatus, HistoryRecord, IdempotencyHit, IllegalStatusTransitionError, Phase, ProjectIdentityError, ProjectIdentityNotResolvableError, ProjectIdentitySourceError, RegistrationConflictError, ResolvedThresholds, RunRetentionPolicy, StrayOutput, TddTaskAlreadyEndedError, TddTaskNotFoundError, TestClassification, TestRun, TrendEntry, TrendRecord, TurnPayload, VitestAgentConfig } from "@vitest-agent/sdk";
15
+ import { Agent, AgentNotFoundError, AgentReport, ArtifactKind, ArtifactKind as ArtifactKind$1, ArtifactSuite, ArtifactSuite as ArtifactSuite$1, BehaviorDetail, BehaviorNotFoundError, BehaviorRow, BehaviorStatus, CacheManifest, CitedArtifact, CoverageBaselines, CoverageReport, DataStoreError, DetailLevel, DiscoveryError, Environment, Executor, FileCoverageReport, GoalDetail, GoalNotFoundError, GoalRow, GoalStatus, HistoryRecord, IdempotencyHit, IllegalStatusTransitionError, ModuleCacheStat, Phase, ProjectIdentityError, ProjectIdentityNotResolvableError, ProjectIdentitySourceError, RegistrationConflictError, ResolvedThresholds, RunRetentionPolicy, StrayOutput, TddTaskAlreadyEndedError, TddTaskNotFoundError, TestClassification, TestRun, TraceStep, TrendEntry, TrendRecord, TurnPayload, VitestAgentConfig } from "@vitest-agent/sdk";
16
16
  import { SqlClient } from "effect/sql/SqlClient";
17
17
  import { CiName, RuntimeEnv } from "@effected/env";
18
18
  import { WorkspaceDiscovery, WorkspaceDiscoveryFailure, WorkspaceRootNotFoundError } from "@effected/workspaces";
@@ -167,6 +167,13 @@ export interface TestRunInput {
167
167
  * recorded nothing, which the row stores as NULL in every `stray_*` column.
168
168
  */
169
169
  readonly strayOutput?: StrayOutput | null;
170
+ /**
171
+ * How well Vitest's fs module cache served this project's run (issue 741).
172
+ * Per project, so each project row of one invocation carries its own value.
173
+ * Omitted or `null` when the run produced no timing data, which the row
174
+ * stores as NULL in every `module_cache_*` column.
175
+ */
176
+ readonly moduleCache?: ModuleCacheStat | null;
170
177
  }
171
178
  /** @public */
172
179
  export interface ModuleInput {
@@ -212,6 +219,20 @@ export interface TestCaseInput {
212
219
  */
213
220
  readonly createdTurnId?: number;
214
221
  }
222
+ /**
223
+ * One retry / repeat attempt of a test case (Vitest 5.1
224
+ * `TestCase.attempts()`), persisted in `test_attempts`.
225
+ * @public
226
+ */
227
+ export interface TestAttemptInput {
228
+ /** Zero-based retry index within the repeat. */
229
+ readonly retryIndex: number;
230
+ /** Zero-based repeat index. */
231
+ readonly repeatIndex: number;
232
+ readonly state: "passed" | "failed" | "skipped";
233
+ readonly duration?: number;
234
+ readonly startTime?: number;
235
+ }
215
236
  /** @public */
216
237
  export interface StackFrameInput {
217
238
  readonly ordinal: number;
@@ -225,6 +246,8 @@ export interface StackFrameInput {
225
246
  /** @public */
226
247
  export interface TestErrorInput {
227
248
  readonly testCaseId?: number;
249
+ /** `test_attempts.id` of the attempt that raised this error, when known. */
250
+ readonly attemptId?: number;
228
251
  readonly testSuiteId?: number;
229
252
  readonly moduleId?: number;
230
253
  readonly scope: "test" | "suite" | "module" | "unhandled";
@@ -517,6 +540,18 @@ declare const DataStore_base: Context.ServiceClass<DataStore, "vitest-agent/Data
517
540
  readonly writeModules: (runId: number, modules: ReadonlyArray<ModuleInput>) => Effect.Effect<ReadonlyArray<number>, DataStoreError>;
518
541
  readonly writeSuites: (moduleId: number, suites: ReadonlyArray<SuiteInput>) => Effect.Effect<ReadonlyArray<number>, DataStoreError>;
519
542
  readonly writeTestCases: (moduleId: number, tests: ReadonlyArray<TestCaseInput>) => Effect.Effect<ReadonlyArray<number>, DataStoreError>;
543
+ /**
544
+ * Persist one row per retry / repeat attempt of a test case; returns
545
+ * the new `test_attempts.id` values in input order so errors can link
546
+ * to their attempt through `TestErrorInput.attemptId`.
547
+ */
548
+ readonly writeTestAttempts: (testCaseId: number, attempts: ReadonlyArray<TestAttemptInput>) => Effect.Effect<ReadonlyArray<number>, DataStoreError>;
549
+ /**
550
+ * Persist the Vitest 5.1 trace-timeline steps of a test case's failed
551
+ * attempt (`test_trace_steps`), in input order. `attemptId` links the
552
+ * steps to their `test_attempts` row when one is known.
553
+ */
554
+ readonly writeTraceSteps: (testCaseId: number, attemptId: number | null, steps: ReadonlyArray<TraceStep>) => Effect.Effect<void, DataStoreError>;
520
555
  readonly writeErrors: (runId: number, errors: ReadonlyArray<TestErrorInput>) => Effect.Effect<void, DataStoreError>;
521
556
  /**
522
557
  * Persist `context.annotate` notes and their attachment descriptors.
@@ -657,6 +692,36 @@ export interface ProjectRunSummary {
657
692
  readonly skipped: number;
658
693
  /** The latest run's stray output (issue 578); `null` when it recorded none. */
659
694
  readonly strayOutput: StrayOutput | null;
695
+ /** The latest run's module cache stat (issue 741); `null` when it recorded none. */
696
+ readonly moduleCache: ModuleCacheStat | null;
697
+ }
698
+ /**
699
+ * Options for `DataReader.getModuleCacheHistory`.
700
+ * @public
701
+ */
702
+ export interface ModuleCacheHistoryOptions {
703
+ /** Only runs of this project; every project otherwise. */
704
+ readonly project?: string;
705
+ /** How many of the most recent runs that recorded a stat to return. Default 10. */
706
+ readonly limit?: number;
707
+ }
708
+ /**
709
+ * One run's module cache stat (issue 741).
710
+ * @public
711
+ */
712
+ export interface ModuleCacheHistoryRun {
713
+ readonly project: string;
714
+ readonly timestamp: string;
715
+ readonly moduleCache: ModuleCacheStat;
716
+ }
717
+ /**
718
+ * The module cache stats of recent runs, newest first, so a cold run (large
719
+ * transform time, many modules written) reads against a warm one (small
720
+ * transform time, none written). Runs that recorded no stat are skipped.
721
+ * @public
722
+ */
723
+ export interface ModuleCacheHistory {
724
+ readonly runs: ReadonlyArray<ModuleCacheHistoryRun>;
660
725
  }
661
726
  /**
662
727
  * Options for `DataReader.getStrayOutputHistory`.
@@ -721,6 +786,41 @@ export interface TestError {
721
786
  readonly scope: "test" | "suite" | "module" | "unhandled";
722
787
  readonly testFullName: string | null;
723
788
  readonly moduleFile: string | null;
789
+ /**
790
+ * The retry / repeat attempt that raised this error (zero-based indexes),
791
+ * or `null` when the error is not tied to an attempt: suite, module and
792
+ * unhandled errors, and errors persisted before attempts were recorded.
793
+ */
794
+ readonly attempt: {
795
+ readonly retryIndex: number;
796
+ readonly repeatIndex: number;
797
+ } | null;
798
+ /** Trace-timeline steps recorded for the test's failed attempt; empty when none. */
799
+ readonly traceSteps: ReadonlyArray<TraceStep>;
800
+ }
801
+ /** One persisted retry / repeat attempt of a test (`test_attempts`). @public */
802
+ export interface TestAttemptRow {
803
+ readonly id: number;
804
+ readonly retryIndex: number;
805
+ readonly repeatIndex: number;
806
+ readonly state: "passed" | "failed" | "skipped";
807
+ readonly duration: number | null;
808
+ readonly startTime: number | null;
809
+ /** `test_errors.id` values raised by this attempt; cite one in a hypothesis. */
810
+ readonly errorIds: ReadonlyArray<number>;
811
+ }
812
+ /** A test that ran more than one attempt (retry or repeat) in a run. @public */
813
+ export interface RetriedTest {
814
+ readonly fullName: string;
815
+ readonly modulePath: string;
816
+ readonly attempts: ReadonlyArray<TestAttemptRow>;
817
+ }
818
+ /** @public */
819
+ export interface RetriedTestQueryOptions {
820
+ /** Exact `full_name` match. */
821
+ readonly testName?: string;
822
+ /** Exact module path match. */
823
+ readonly modulePath?: string;
724
824
  }
725
825
  /** @public */
726
826
  export interface NoteRow {
@@ -1039,6 +1139,8 @@ export interface TestArtifactRow {
1039
1139
  declare const DataReader_base: Context.ServiceClass<DataReader, "vitest-agent/DataReader", {
1040
1140
  readonly getLatestRun: (project: string) => Effect.Effect<Option.Option<AgentReport>, DataStoreError>;
1041
1141
  readonly getRunsByProject: () => Effect.Effect<ReadonlyArray<ProjectRunSummary>, DataStoreError>;
1142
+ /** Recent runs' module cache stats, newest first; see {@link ModuleCacheHistory}. */
1143
+ readonly getModuleCacheHistory: (options?: ModuleCacheHistoryOptions) => Effect.Effect<ModuleCacheHistory, DataStoreError>;
1042
1144
  /** How often the most recent runs wrote stray output; see {@link StrayOutputHistory}. */
1043
1145
  readonly getStrayOutputHistory: (options?: StrayOutputHistoryOptions) => Effect.Effect<StrayOutputHistory, DataStoreError>;
1044
1146
  readonly getHistory: (project: string, options?: HistoryQueryOptions) => Effect.Effect<HistoryRecord, DataStoreError>;
@@ -1050,6 +1152,12 @@ declare const DataReader_base: Context.ServiceClass<DataReader, "vitest-agent/Da
1050
1152
  readonly getCoverage: (project: string) => Effect.Effect<Option.Option<CoverageReport>, DataStoreError>;
1051
1153
  readonly getTestsForFile: (filePath: string) => Effect.Effect<ReadonlyArray<string>, DataStoreError>;
1052
1154
  readonly getErrors: (project: string, errorName?: string) => Effect.Effect<ReadonlyArray<TestError>, DataStoreError>;
1155
+ /**
1156
+ * Tests that ran more than one attempt (a retry or a repeat) in the
1157
+ * project's latest run, with every attempt in order. Tests that ran
1158
+ * once are omitted.
1159
+ */
1160
+ readonly getRetriedTests: (project: string, options?: RetriedTestQueryOptions) => Effect.Effect<ReadonlyArray<RetriedTest>, DataStoreError>;
1053
1161
  /** Annotations recorded for a test in the project's latest run. */
1054
1162
  readonly getAnnotationsForTest: (project: string, fullName: string, options?: TestArtifactQueryOptions) => Effect.Effect<ReadonlyArray<TestAnnotationRow>, DataStoreError>;
1055
1163
  /** Artifacts recorded for a test in the project's latest run. */
@@ -1835,6 +1943,9 @@ export declare const PROJECT_MIGRATIONS: {
1835
1943
  readonly "0003_run_retention": import("effect/Effect").Effect<void, import("effect/sql/SqlError").SqlError, import("effect/sql/SqlClient").SqlClient>;
1836
1944
  readonly "0004_stray_output": import("effect/Effect").Effect<void, import("effect/sql/SqlError").SqlError, import("effect/sql/SqlClient").SqlClient>;
1837
1945
  readonly "0005_scrub_ci_env_vars": import("effect/Effect").Effect<void, import("effect/sql/SqlError").SqlError, import("effect/sql/SqlClient").SqlClient>;
1946
+ readonly "0006_test_attempts": import("effect/Effect").Effect<void, import("effect/sql/SqlError").SqlError, import("effect/sql/SqlClient").SqlClient>;
1947
+ readonly "0007_trace_steps": import("effect/Effect").Effect<void, import("effect/sql/SqlError").SqlError, import("effect/sql/SqlClient").SqlClient>;
1948
+ readonly "0008_module_cache": import("effect/Effect").Effect<void, import("effect/sql/SqlError").SqlError, import("effect/sql/SqlClient").SqlClient>;
1838
1949
  };
1839
1950
  /**
1840
1951
  * Migration for the global discovery registry SQLite at
@@ -20,6 +20,19 @@ const strayOutputFromRow = (row) => row.stray_total === null ? null : {
20
20
  bytes: row.stray_bytes ?? 0,
21
21
  samples: Option.getOrElse(decodeStraySamples(row.stray_samples ?? "[]"), () => [])
22
22
  };
23
+ /**
24
+ * The run's module cache stat from its `test_runs` row, or `null` when the row
25
+ * recorded none (every column NULL: no timing data, or a row older than
26
+ * migration 0008). Pure; the inverse is `DataStoreLive`'s `moduleCacheColumns`.
27
+ * The share is derived, not stored.
28
+ */
29
+ const moduleCacheFromRow = (row) => row.module_cache_enabled === null || row.module_cache_transform_ms === null || row.module_cache_tracked_ms === null ? null : {
30
+ enabled: row.module_cache_enabled === 1,
31
+ transformMs: row.module_cache_transform_ms,
32
+ trackedMs: row.module_cache_tracked_ms,
33
+ share: row.module_cache_tracked_ms > 0 ? row.module_cache_transform_ms / row.module_cache_tracked_ms : 0,
34
+ ...row.module_cache_modules_written !== null && { modulesWritten: row.module_cache_modules_written }
35
+ };
23
36
  /** @public */
24
37
  const DataReaderLive = Layer.effect(DataReader, Effect.gen(function* () {
25
38
  const sql = yield* SqlClient;
@@ -47,7 +60,7 @@ const DataReaderLive = Layer.effect(DataReader, Effect.gen(function* () {
47
60
  });
48
61
  const getLatestRun = (project) => Effect.gen(function* () {
49
62
  yield* Effect.logDebug("getLatestRun").pipe(Effect.annotateLogs({ project }));
50
- const runs = yield* sql`SELECT id, timestamp, reason, duration, total, passed, failed, skipped, project, stray_total, stray_stdout, stray_stderr, stray_bytes, stray_samples
63
+ const runs = yield* sql`SELECT id, timestamp, reason, duration, total, passed, failed, skipped, project, stray_total, stray_stdout, stray_stderr, stray_bytes, stray_samples, module_cache_enabled, module_cache_transform_ms, module_cache_tracked_ms, module_cache_modules_written
51
64
  FROM test_runs
52
65
  WHERE project = ${project}
53
66
  ORDER BY timestamp DESC LIMIT 1`;
@@ -118,6 +131,7 @@ const DataReaderLive = Layer.effect(DataReader, Effect.gen(function* () {
118
131
  const failedFiles = failedModules.map((m) => m.file_path);
119
132
  const projectName = run.project;
120
133
  const strayOutput = strayOutputFromRow(run);
134
+ const moduleCache = moduleCacheFromRow(run);
121
135
  const coverageRunId = yield* resolveCoverageRunId(run.id);
122
136
  const fileCovRows = yield* sql`SELECT f.path AS file_path, fc.statements, fc.branches, fc.functions, fc.lines,
123
137
  fc.uncovered_lines, fc.tier
@@ -196,7 +210,8 @@ const DataReaderLive = Layer.effect(DataReader, Effect.gen(function* () {
196
210
  })),
197
211
  failedFiles,
198
212
  ...coverage ? { coverage } : {},
199
- ...strayOutput !== null ? { strayOutput } : {}
213
+ ...strayOutput !== null ? { strayOutput } : {},
214
+ ...moduleCache !== null ? { moduleCache } : {}
200
215
  };
201
216
  return Option.some(report);
202
217
  }).pipe(Effect.annotateLogs("service", "DataReader"), Effect.mapError((e) => new DataStoreError({
@@ -218,7 +233,11 @@ const DataReaderLive = Layer.effect(DataReader, Effect.gen(function* () {
218
233
  t1.stray_stdout,
219
234
  t1.stray_stderr,
220
235
  t1.stray_bytes,
221
- t1.stray_samples
236
+ t1.stray_samples,
237
+ t1.module_cache_enabled,
238
+ t1.module_cache_transform_ms,
239
+ t1.module_cache_tracked_ms,
240
+ t1.module_cache_modules_written
222
241
  FROM test_runs t1
223
242
  INNER JOIN (
224
243
  SELECT project, MAX(timestamp) as max_ts
@@ -233,8 +252,39 @@ const DataReaderLive = Layer.effect(DataReader, Effect.gen(function* () {
233
252
  passed: r.passed,
234
253
  failed: r.failed,
235
254
  skipped: r.skipped,
236
- strayOutput: strayOutputFromRow(r)
255
+ strayOutput: strayOutputFromRow(r),
256
+ moduleCache: moduleCacheFromRow(r)
257
+ }));
258
+ }).pipe(Effect.annotateLogs("service", "DataReader"), Effect.mapError((e) => new DataStoreError({
259
+ operation: "read",
260
+ table: "test_runs",
261
+ reason: extractSqlReason(e)
262
+ })));
263
+ const getModuleCacheHistory = (options = {}) => Effect.gen(function* () {
264
+ const limit = options.limit ?? 10;
265
+ yield* Effect.logDebug("getModuleCacheHistory").pipe(Effect.annotateLogs({
266
+ project: options.project ?? "*",
267
+ limit
237
268
  }));
269
+ return { runs: (yield* sql`SELECT
270
+ project,
271
+ timestamp,
272
+ module_cache_enabled,
273
+ module_cache_transform_ms,
274
+ module_cache_tracked_ms,
275
+ module_cache_modules_written
276
+ FROM test_runs
277
+ WHERE module_cache_enabled IS NOT NULL
278
+ ${options.project !== void 0 ? sql`AND project = ${options.project}` : sql``}
279
+ ORDER BY timestamp DESC, id DESC
280
+ LIMIT ${limit}`).flatMap((row) => {
281
+ const moduleCache = moduleCacheFromRow(row);
282
+ return moduleCache === null ? [] : [{
283
+ project: row.project,
284
+ timestamp: row.timestamp,
285
+ moduleCache
286
+ }];
287
+ }) };
238
288
  }).pipe(Effect.annotateLogs("service", "DataReader"), Effect.mapError((e) => new DataStoreError({
239
289
  operation: "read",
240
290
  table: "test_runs",
@@ -643,25 +693,54 @@ const DataReaderLive = Layer.effect(DataReader, Effect.gen(function* () {
643
693
  ORDER BY timestamp DESC LIMIT 1`;
644
694
  if (runs.length === 0) return [];
645
695
  const runId = runs[0].id;
646
- return (yield* errorName ? sql`SELECT te.id, sf.id AS top_stack_frame_id,
696
+ const rows = yield* errorName ? sql`SELECT te.id, te.test_case_id, sf.id AS top_stack_frame_id,
647
697
  te.name, te.message, te.diff, te.actual, te.expected, te.stack, te.scope,
648
698
  tc.full_name as test_full_name,
649
- f.path as module_file
699
+ f.path as module_file,
700
+ ta.retry_index, ta.repeat_index
650
701
  FROM test_errors te
702
+ LEFT JOIN test_attempts ta ON ta.id = te.attempt_id
651
703
  LEFT JOIN test_cases tc ON tc.id = te.test_case_id
652
704
  LEFT JOIN test_modules tm ON tm.id = COALESCE(te.module_id, tc.module_id)
653
705
  LEFT JOIN files f ON f.id = tm.file_id
654
706
  LEFT JOIN stack_frames sf ON sf.error_id = te.id AND sf.ordinal = 0
655
- WHERE te.run_id = ${runId} AND te.name = ${errorName}` : sql`SELECT te.id, sf.id AS top_stack_frame_id,
707
+ WHERE te.run_id = ${runId} AND te.name = ${errorName}` : sql`SELECT te.id, te.test_case_id, sf.id AS top_stack_frame_id,
656
708
  te.name, te.message, te.diff, te.actual, te.expected, te.stack, te.scope,
657
709
  tc.full_name as test_full_name,
658
- f.path as module_file
710
+ f.path as module_file,
711
+ ta.retry_index, ta.repeat_index
659
712
  FROM test_errors te
713
+ LEFT JOIN test_attempts ta ON ta.id = te.attempt_id
660
714
  LEFT JOIN test_cases tc ON tc.id = te.test_case_id
661
715
  LEFT JOIN test_modules tm ON tm.id = COALESCE(te.module_id, tc.module_id)
662
716
  LEFT JOIN files f ON f.id = tm.file_id
663
717
  LEFT JOIN stack_frames sf ON sf.error_id = te.id AND sf.ordinal = 0
664
- WHERE te.run_id = ${runId}`).map((r) => ({
718
+ WHERE te.run_id = ${runId}`;
719
+ const caseIds = [...new Set(rows.flatMap((r) => r.test_case_id === null ? [] : [r.test_case_id]))];
720
+ const stepsByCase = /* @__PURE__ */ new Map();
721
+ if (caseIds.length > 0) {
722
+ const stepRows = yield* sql`SELECT test_case_id, name, status, start_time, duration, depth, locator,
723
+ location_file, location_line, location_column
724
+ FROM test_trace_steps WHERE test_case_id IN ${sql.in(caseIds)} ORDER BY test_case_id, ordinal, id`;
725
+ for (const s of stepRows) {
726
+ const list = stepsByCase.get(s.test_case_id) ?? [];
727
+ stepsByCase.set(s.test_case_id, list);
728
+ list.push({
729
+ name: s.name,
730
+ ...s.status === "pass" || s.status === "fail" ? { status: s.status } : {},
731
+ startTime: s.start_time,
732
+ ...s.duration !== null && { duration: s.duration },
733
+ depth: s.depth,
734
+ ...s.locator !== null && { locator: s.locator },
735
+ ...s.location_file !== null && s.location_line !== null && s.location_column !== null && { location: {
736
+ file: s.location_file,
737
+ line: s.location_line,
738
+ column: s.location_column
739
+ } }
740
+ });
741
+ }
742
+ }
743
+ return rows.map((r) => ({
665
744
  id: r.id,
666
745
  topStackFrameId: r.top_stack_frame_id,
667
746
  name: r.name,
@@ -672,7 +751,12 @@ const DataReaderLive = Layer.effect(DataReader, Effect.gen(function* () {
672
751
  stack: r.stack,
673
752
  scope: r.scope,
674
753
  testFullName: r.test_full_name,
675
- moduleFile: r.module_file
754
+ moduleFile: r.module_file,
755
+ attempt: r.retry_index !== null && r.repeat_index !== null ? {
756
+ retryIndex: r.retry_index,
757
+ repeatIndex: r.repeat_index
758
+ } : null,
759
+ traceSteps: r.test_case_id === null ? [] : stepsByCase.get(r.test_case_id) ?? []
676
760
  }));
677
761
  }).pipe(Effect.annotateLogs("service", "DataReader"), Effect.mapError((e) => new DataStoreError({
678
762
  operation: "read",
@@ -706,6 +790,61 @@ const DataReaderLive = Layer.effect(DataReader, Effect.gen(function* () {
706
790
  }
707
791
  return grouped;
708
792
  });
793
+ const getRetriedTests = (project, options) => Effect.gen(function* () {
794
+ yield* Effect.logDebug("getRetriedTests").pipe(Effect.annotateLogs({
795
+ project,
796
+ ...options
797
+ }));
798
+ const runId = yield* latestRunId(project);
799
+ if (runId === null) return [];
800
+ const testName = options?.testName ?? null;
801
+ const modulePath = options?.modulePath ?? null;
802
+ const rows = yield* sql`SELECT ta.id, ta.test_case_id, tc.full_name, tm.relative_module_id AS module_path,
803
+ ta.retry_index, ta.repeat_index, ta.state, ta.duration, ta.start_time
804
+ FROM test_attempts ta
805
+ JOIN test_cases tc ON tc.id = ta.test_case_id
806
+ JOIN test_modules tm ON tm.id = tc.module_id
807
+ WHERE tm.run_id = ${runId}
808
+ AND (${testName} IS NULL OR tc.full_name = ${testName})
809
+ AND (${modulePath} IS NULL OR tm.relative_module_id = ${modulePath})
810
+ AND (SELECT COUNT(*) FROM test_attempts x WHERE x.test_case_id = ta.test_case_id) > 1
811
+ ORDER BY ta.test_case_id, ta.repeat_index, ta.retry_index, ta.id`;
812
+ if (rows.length === 0) return [];
813
+ const errorRows = yield* sql`
814
+ SELECT id, attempt_id FROM test_errors WHERE attempt_id IN ${sql.in(rows.map((r) => r.id))} ORDER BY id`;
815
+ const errorsByAttempt = /* @__PURE__ */ new Map();
816
+ for (const e of errorRows) {
817
+ const list = errorsByAttempt.get(e.attempt_id);
818
+ if (list) list.push(e.id);
819
+ else errorsByAttempt.set(e.attempt_id, [e.id]);
820
+ }
821
+ const byCase = /* @__PURE__ */ new Map();
822
+ for (const r of rows) {
823
+ let entry = byCase.get(r.test_case_id);
824
+ if (entry === void 0) {
825
+ entry = {
826
+ fullName: r.full_name,
827
+ modulePath: r.module_path,
828
+ attempts: []
829
+ };
830
+ byCase.set(r.test_case_id, entry);
831
+ }
832
+ entry.attempts.push({
833
+ id: r.id,
834
+ retryIndex: r.retry_index,
835
+ repeatIndex: r.repeat_index,
836
+ state: r.state,
837
+ duration: r.duration,
838
+ startTime: r.start_time,
839
+ errorIds: errorsByAttempt.get(r.id) ?? []
840
+ });
841
+ }
842
+ return Array.from(byCase.values());
843
+ }).pipe(Effect.annotateLogs("service", "DataReader"), Effect.mapError((e) => new DataStoreError({
844
+ operation: "read",
845
+ table: "test_attempts",
846
+ reason: extractSqlReason(e)
847
+ })));
709
848
  const getAnnotationsForTest = (project, fullName, options) => Effect.gen(function* () {
710
849
  yield* Effect.logDebug("getAnnotationsForTest").pipe(Effect.annotateLogs({
711
850
  project,
@@ -1932,6 +2071,7 @@ const DataReaderLive = Layer.effect(DataReader, Effect.gen(function* () {
1932
2071
  getLatestRun,
1933
2072
  getRunsByProject,
1934
2073
  getStrayOutputHistory,
2074
+ getModuleCacheHistory,
1935
2075
  getHistory,
1936
2076
  getBaselines,
1937
2077
  getTrends,
@@ -1941,6 +2081,7 @@ const DataReaderLive = Layer.effect(DataReader, Effect.gen(function* () {
1941
2081
  getCoverage,
1942
2082
  getTestsForFile,
1943
2083
  getErrors,
2084
+ getRetriedTests,
1944
2085
  getAnnotationsForTest,
1945
2086
  getArtifactsForTest,
1946
2087
  getNotes,
@@ -25,6 +25,23 @@ const strayOutputColumns = (stray) => stray == null ? {
25
25
  bytes: stray.bytes,
26
26
  samples: JSON.stringify(stray.samples)
27
27
  };
28
+ /**
29
+ * The four `test_runs.module_cache_*` column values for a project run's
30
+ * module cache stat: all NULL when the run recorded none; the written count
31
+ * is NULL on its own when it is unknown (pure; the inverse lives in
32
+ * `DataReaderLive`).
33
+ */
34
+ const moduleCacheColumns = (stat) => stat == null ? {
35
+ enabled: null,
36
+ transformMs: null,
37
+ trackedMs: null,
38
+ modulesWritten: null
39
+ } : {
40
+ enabled: stat.enabled ? 1 : 0,
41
+ transformMs: stat.transformMs,
42
+ trackedMs: stat.trackedMs,
43
+ modulesWritten: stat.modulesWritten ?? null
44
+ };
28
45
  const isLegalLifecycleTransition = (from, to) => {
29
46
  if (from === to) return true;
30
47
  if (from === "done" || from === "abandoned") return false;
@@ -92,7 +109,8 @@ const DataStoreLive = Layer.effect(DataStore, Effect.gen(function* () {
92
109
  const gitDirtyInt = input.gitDirty === void 0 || input.gitDirty === null ? null : input.gitDirty ? 1 : 0;
93
110
  const hostMetadataJson = input.hostMetadata == null ? null : JSON.stringify(input.hostMetadata);
94
111
  const stray = strayOutputColumns(input.strayOutput);
95
- yield* sql`INSERT INTO test_runs (invocation_id, project, settings_hash, timestamp, commit_sha, branch, reason, duration, total, passed, failed, skipped, scoped, snapshot_added, snapshot_matched, snapshot_unmatched, snapshot_updated, snapshot_unchecked, snapshot_total, snapshot_failure, snapshot_did_update, snapshot_files_added, snapshot_files_removed, snapshot_files_unmatched, snapshot_files_updated, actor_type, agent_id, conversation_id, git_branch, git_commit_sha, git_dirty, git_upstream, git_worktree_dir, host_source, host_value, host_metadata, stray_total, stray_stdout, stray_stderr, stray_bytes, stray_samples) VALUES (${input.invocationId}, ${input.project}, ${input.settingsHash}, ${input.timestamp}, ${input.commitSha ?? null}, ${input.branch ?? null}, ${input.reason}, ${input.duration}, ${input.total}, ${input.passed}, ${input.failed}, ${input.skipped}, ${input.scoped ? 1 : 0}, ${input.snapshotAdded ?? 0}, ${input.snapshotMatched ?? 0}, ${input.snapshotUnmatched ?? 0}, ${input.snapshotUpdated ?? 0}, ${input.snapshotUnchecked ?? 0}, ${input.snapshotTotal ?? 0}, ${boolToInt(input.snapshotFailure) ?? 0}, ${boolToInt(input.snapshotDidUpdate) ?? 0}, ${input.snapshotFilesAdded ?? 0}, ${input.snapshotFilesRemoved ?? 0}, ${input.snapshotFilesUnmatched ?? 0}, ${input.snapshotFilesUpdated ?? 0}, ${actorType}, ${agentId}, ${conversationId}, ${input.gitBranch ?? null}, ${input.gitCommitSha ?? null}, ${gitDirtyInt}, ${input.gitUpstream ?? null}, ${input.gitWorktreeDir ?? null}, ${input.hostSource ?? null}, ${input.hostValue ?? null}, ${hostMetadataJson}, ${stray.total}, ${stray.stdout}, ${stray.stderr}, ${stray.bytes}, ${stray.samples})`;
112
+ const cache = moduleCacheColumns(input.moduleCache);
113
+ yield* sql`INSERT INTO test_runs (invocation_id, project, settings_hash, timestamp, commit_sha, branch, reason, duration, total, passed, failed, skipped, scoped, snapshot_added, snapshot_matched, snapshot_unmatched, snapshot_updated, snapshot_unchecked, snapshot_total, snapshot_failure, snapshot_did_update, snapshot_files_added, snapshot_files_removed, snapshot_files_unmatched, snapshot_files_updated, actor_type, agent_id, conversation_id, git_branch, git_commit_sha, git_dirty, git_upstream, git_worktree_dir, host_source, host_value, host_metadata, stray_total, stray_stdout, stray_stderr, stray_bytes, stray_samples, module_cache_enabled, module_cache_transform_ms, module_cache_tracked_ms, module_cache_modules_written) VALUES (${input.invocationId}, ${input.project}, ${input.settingsHash}, ${input.timestamp}, ${input.commitSha ?? null}, ${input.branch ?? null}, ${input.reason}, ${input.duration}, ${input.total}, ${input.passed}, ${input.failed}, ${input.skipped}, ${input.scoped ? 1 : 0}, ${input.snapshotAdded ?? 0}, ${input.snapshotMatched ?? 0}, ${input.snapshotUnmatched ?? 0}, ${input.snapshotUpdated ?? 0}, ${input.snapshotUnchecked ?? 0}, ${input.snapshotTotal ?? 0}, ${boolToInt(input.snapshotFailure) ?? 0}, ${boolToInt(input.snapshotDidUpdate) ?? 0}, ${input.snapshotFilesAdded ?? 0}, ${input.snapshotFilesRemoved ?? 0}, ${input.snapshotFilesUnmatched ?? 0}, ${input.snapshotFilesUpdated ?? 0}, ${actorType}, ${agentId}, ${conversationId}, ${input.gitBranch ?? null}, ${input.gitCommitSha ?? null}, ${gitDirtyInt}, ${input.gitUpstream ?? null}, ${input.gitWorktreeDir ?? null}, ${input.hostSource ?? null}, ${input.hostValue ?? null}, ${hostMetadataJson}, ${stray.total}, ${stray.stdout}, ${stray.stderr}, ${stray.bytes}, ${stray.samples}, ${cache.enabled}, ${cache.transformMs}, ${cache.trackedMs}, ${cache.modulesWritten})`;
96
114
  return (yield* sql`SELECT last_insert_rowid() as id`)[0].id;
97
115
  }).pipe(Effect.annotateLogs("service", "DataStore"), Effect.mapError((e) => new DataStoreError({
98
116
  operation: "write",
@@ -160,6 +178,38 @@ const DataStoreLive = Layer.effect(DataStore, Effect.gen(function* () {
160
178
  table: "test_cases",
161
179
  reason: extractSqlReason(e)
162
180
  })));
181
+ const writeTestAttempts = (testCaseId, attempts) => Effect.gen(function* () {
182
+ yield* Effect.logDebug("writeTestAttempts").pipe(Effect.annotateLogs({
183
+ testCaseId,
184
+ count: attempts.length
185
+ }));
186
+ const ids = [];
187
+ for (const attempt of attempts) {
188
+ yield* sql`INSERT INTO test_attempts (test_case_id, retry_index, repeat_index, state, duration, start_time) VALUES (${testCaseId}, ${attempt.retryIndex}, ${attempt.repeatIndex}, ${attempt.state}, ${attempt.duration ?? null}, ${attempt.startTime ?? null})`;
189
+ const rows = yield* sql`SELECT last_insert_rowid() as id`;
190
+ ids.push(rows[0].id);
191
+ }
192
+ return ids;
193
+ }).pipe(Effect.annotateLogs("service", "DataStore"), Effect.mapError((e) => new DataStoreError({
194
+ operation: "write",
195
+ table: "test_attempts",
196
+ reason: extractSqlReason(e)
197
+ })));
198
+ const writeTraceSteps = (testCaseId, attemptId, steps) => Effect.gen(function* () {
199
+ yield* Effect.logDebug("writeTraceSteps").pipe(Effect.annotateLogs({
200
+ testCaseId,
201
+ count: steps.length
202
+ }));
203
+ for (let ordinal = 0; ordinal < steps.length; ordinal++) {
204
+ const step = steps[ordinal];
205
+ if (step === void 0) continue;
206
+ yield* sql`INSERT INTO test_trace_steps (test_case_id, attempt_id, ordinal, name, status, start_time, duration, depth, locator, location_file, location_line, location_column) VALUES (${testCaseId}, ${attemptId}, ${ordinal}, ${step.name}, ${step.status ?? null}, ${step.startTime}, ${step.duration ?? null}, ${step.depth}, ${step.locator ?? null}, ${step.location?.file ?? null}, ${step.location?.line ?? null}, ${step.location?.column ?? null})`;
207
+ }
208
+ }).pipe(Effect.annotateLogs("service", "DataStore"), Effect.mapError((e) => new DataStoreError({
209
+ operation: "write",
210
+ table: "test_trace_steps",
211
+ reason: extractSqlReason(e)
212
+ })));
163
213
  const writeErrors = (runId, errors) => Effect.gen(function* () {
164
214
  yield* Effect.logDebug("writeErrors").pipe(Effect.annotateLogs({
165
215
  runId,
@@ -167,7 +217,7 @@ const DataStoreLive = Layer.effect(DataStore, Effect.gen(function* () {
167
217
  }));
168
218
  for (const err of errors) {
169
219
  const message = coerceErrorText(err.message) ?? "<missing message>";
170
- yield* sql`INSERT INTO test_errors (run_id, test_case_id, test_suite_id, module_id, scope, name, message, diff, actual, expected, stack, cause_error_id, signature_hash, ordinal) VALUES (${runId}, ${err.testCaseId ?? null}, ${err.testSuiteId ?? null}, ${err.moduleId ?? null}, ${err.scope}, ${coerceErrorText(err.name) ?? null}, ${message}, ${coerceErrorText(err.diff) ?? null}, ${coerceErrorText(err.actual) ?? null}, ${coerceErrorText(err.expected) ?? null}, ${coerceErrorText(err.stack) ?? null}, ${err.causeErrorId ?? null}, ${err.signatureHash ?? null}, ${err.ordinal ?? 0})`;
220
+ yield* sql`INSERT INTO test_errors (run_id, test_case_id, attempt_id, test_suite_id, module_id, scope, name, message, diff, actual, expected, stack, cause_error_id, signature_hash, ordinal) VALUES (${runId}, ${err.testCaseId ?? null}, ${err.attemptId ?? null}, ${err.testSuiteId ?? null}, ${err.moduleId ?? null}, ${err.scope}, ${coerceErrorText(err.name) ?? null}, ${message}, ${coerceErrorText(err.diff) ?? null}, ${coerceErrorText(err.actual) ?? null}, ${coerceErrorText(err.expected) ?? null}, ${coerceErrorText(err.stack) ?? null}, ${err.causeErrorId ?? null}, ${err.signatureHash ?? null}, ${err.ordinal ?? 0})`;
171
221
  const stackText = coerceErrorText(err.stack);
172
222
  if (err.frames && err.frames.length > 0) {
173
223
  const errorId = (yield* sql`SELECT last_insert_rowid() as id`)[0].id;
@@ -1345,6 +1395,8 @@ const DataStoreLive = Layer.effect(DataStore, Effect.gen(function* () {
1345
1395
  writeModules,
1346
1396
  writeSuites,
1347
1397
  writeTestCases,
1398
+ writeTestAttempts,
1399
+ writeTraceSteps,
1348
1400
  writeErrors,
1349
1401
  writeAnnotations,
1350
1402
  writeArtifacts,
@@ -1,8 +1,24 @@
1
+ import { describeModuleCache } from "@vitest-agent/sdk";
1
2
  import { Effect, Option } from "effect";
2
3
  import { DataReader } from "../services/DataReader.js";
3
4
 
4
5
  // src/lib/format-triage.ts
5
6
  const STRAY_OUTPUT_WINDOW = 10;
7
+ /** Runs read across all projects for the module cache lines; each project shows its two newest. */
8
+ const MODULE_CACHE_WINDOW = 50;
9
+ /**
10
+ * A project's "module cache" line of the Recent Test Runs section (issue
11
+ * 741): its newest recorded stat and, when there is one, the run before it,
12
+ * so a cold run reads against a warm one. `runs` is newest first. `undefined`
13
+ * when the project recorded no stat. Pure, so the wording is testable without
14
+ * a database.
15
+ * @public
16
+ */
17
+ const formatModuleCacheTriageLine = (runs) => {
18
+ const [latest, previous] = runs;
19
+ if (latest === void 0) return void 0;
20
+ return ` - Module cache: ${describeModuleCache(latest.moduleCache)}${previous === void 0 ? "" : ` (previous run: ${describeModuleCache(previous.moduleCache)})`}`;
21
+ };
6
22
  const describeStrayOutput = (stray) => {
7
23
  const lines = `${stray.total} line${stray.total === 1 ? "" : "s"}`;
8
24
  const sample = stray.samples[0];
@@ -37,6 +53,7 @@ const formatTriageEffect = (options = {}) => Effect.gen(function* () {
37
53
  runsWithStrayOutput: 0,
38
54
  latest: null
39
55
  })));
56
+ const moduleCacheHistory = yield* reader.getModuleCacheHistory({ limit: MODULE_CACHE_WINDOW }).pipe(Effect.orElseSucceed(() => ({ runs: [] })));
40
57
  const fallbackMetrics = {
41
58
  phaseEvidenceIntegrity: {
42
59
  total: 0,
@@ -79,6 +96,8 @@ const formatTriageEffect = (options = {}) => Effect.gen(function* () {
79
96
  const status = p.lastResult ?? "unknown";
80
97
  const counts = `${p.passed} passed, ${p.failed} failed`;
81
98
  lines.push(`- **${p.project}** — ${status} (${counts})`);
99
+ const cacheLine = formatModuleCacheTriageLine(moduleCacheHistory.runs.filter((r) => r.project === p.project));
100
+ if (cacheLine !== void 0) lines.push(cacheLine);
82
101
  }
83
102
  const strayLine = formatStrayOutputLine(strayHistory);
84
103
  if (strayLine !== void 0) lines.push(strayLine);
@@ -122,4 +141,4 @@ const formatTriageEffect = (options = {}) => Effect.gen(function* () {
122
141
  return out;
123
142
  });
124
143
 
125
- export { formatStrayOutputLine, formatTriageEffect };
144
+ export { formatModuleCacheTriageLine, formatStrayOutputLine, formatTriageEffect };
@@ -0,0 +1,24 @@
1
+ import { Effect } from "effect";
2
+ import { SqlClient } from "effect/sql/SqlClient";
3
+
4
+ // src/migrations/0006_test_attempts.ts
5
+ /** @internal */
6
+ const migration = Effect.gen(function* () {
7
+ const sql = yield* SqlClient;
8
+ yield* sql`
9
+ CREATE TABLE test_attempts (
10
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
11
+ test_case_id INTEGER NOT NULL REFERENCES test_cases(id) ON DELETE CASCADE,
12
+ retry_index INTEGER NOT NULL,
13
+ repeat_index INTEGER NOT NULL,
14
+ state TEXT NOT NULL CHECK (state IN ('passed', 'failed', 'skipped')),
15
+ duration REAL,
16
+ start_time REAL
17
+ )
18
+ `;
19
+ yield* sql`CREATE INDEX idx_test_attempts_case ON test_attempts(test_case_id)`;
20
+ yield* sql`ALTER TABLE test_errors ADD COLUMN attempt_id INTEGER REFERENCES test_attempts(id) ON DELETE CASCADE`;
21
+ yield* sql`CREATE INDEX idx_test_errors_attempt ON test_errors(attempt_id)`;
22
+ });
23
+
24
+ export { migration as default };
@@ -0,0 +1,29 @@
1
+ import { Effect } from "effect";
2
+ import { SqlClient } from "effect/sql/SqlClient";
3
+
4
+ // src/migrations/0007_trace_steps.ts
5
+ /** @internal */
6
+ const migration = Effect.gen(function* () {
7
+ const sql = yield* SqlClient;
8
+ yield* sql`
9
+ CREATE TABLE test_trace_steps (
10
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
11
+ test_case_id INTEGER NOT NULL REFERENCES test_cases(id) ON DELETE CASCADE,
12
+ attempt_id INTEGER REFERENCES test_attempts(id) ON DELETE CASCADE,
13
+ ordinal INTEGER NOT NULL,
14
+ name TEXT NOT NULL,
15
+ status TEXT CHECK (status IS NULL OR status IN ('pass', 'fail')),
16
+ start_time REAL NOT NULL,
17
+ duration REAL,
18
+ depth INTEGER NOT NULL DEFAULT 0,
19
+ locator TEXT,
20
+ location_file TEXT,
21
+ location_line INTEGER,
22
+ location_column INTEGER
23
+ )
24
+ `;
25
+ yield* sql`CREATE INDEX idx_test_trace_steps_case ON test_trace_steps(test_case_id, ordinal)`;
26
+ yield* sql`CREATE INDEX idx_test_trace_steps_attempt ON test_trace_steps(attempt_id)`;
27
+ });
28
+
29
+ export { migration as default };
@@ -0,0 +1,14 @@
1
+ import { Effect } from "effect";
2
+ import { SqlClient } from "effect/sql/SqlClient";
3
+
4
+ // src/migrations/0008_module_cache.ts
5
+ /** @internal */
6
+ const migration = Effect.gen(function* () {
7
+ const sql = yield* SqlClient;
8
+ yield* sql`ALTER TABLE test_runs ADD COLUMN module_cache_enabled INTEGER`;
9
+ yield* sql`ALTER TABLE test_runs ADD COLUMN module_cache_transform_ms REAL`;
10
+ yield* sql`ALTER TABLE test_runs ADD COLUMN module_cache_tracked_ms REAL`;
11
+ yield* sql`ALTER TABLE test_runs ADD COLUMN module_cache_modules_written INTEGER`;
12
+ });
13
+
14
+ export { migration as default };
@@ -3,6 +3,9 @@ import migration$1 from "./0002_test_artifacts.js";
3
3
  import migration$2 from "./0003_run_retention.js";
4
4
  import migration$3 from "./0004_stray_output.js";
5
5
  import migration$4 from "./0005_scrub_ci_env_vars.js";
6
+ import migration$5 from "./0006_test_attempts.js";
7
+ import migration$6 from "./0007_trace_steps.js";
8
+ import migration$7 from "./0008_module_cache.js";
6
9
 
7
10
  // src/migrations/index.ts
8
11
  /**
@@ -27,7 +30,10 @@ const PROJECT_MIGRATIONS = {
27
30
  "0002_test_artifacts": migration$1,
28
31
  "0003_run_retention": migration$2,
29
32
  "0004_stray_output": migration$3,
30
- "0005_scrub_ci_env_vars": migration$4
33
+ "0005_scrub_ci_env_vars": migration$4,
34
+ "0006_test_attempts": migration$5,
35
+ "0007_trace_steps": migration$6,
36
+ "0008_module_cache": migration$7
31
37
  };
32
38
 
33
39
  export { PROJECT_MIGRATIONS };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitest-agent/engine",
3
- "version": "3.3.0",
3
+ "version": "3.4.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": [
@@ -46,7 +46,7 @@
46
46
  "@effected/cli-kit": "0.30.1",
47
47
  "@effected/config-file": "0.29.0",
48
48
  "@effected/env": "0.12.0",
49
- "@effected/git": "0.33.0",
49
+ "@effected/git": "0.34.0",
50
50
  "@effected/glob": "0.23.0",
51
51
  "@effected/jsonc": "0.25.0",
52
52
  "@effected/kit": "0.14.0",
@@ -55,10 +55,10 @@
55
55
  "@effected/store": "0.25.0",
56
56
  "@effected/toml": "0.20.0",
57
57
  "@effected/walker": "0.30.0",
58
- "@effected/workspaces": "0.48.2",
58
+ "@effected/workspaces": "0.49.1",
59
59
  "@effected/xdg": "0.22.0",
60
60
  "@effected/yaml": "0.30.0",
61
- "@vitest-agent/sdk": "9.1.0",
61
+ "@vitest-agent/sdk": "9.2.0",
62
62
  "effect": "4.1.5"
63
63
  },
64
64
  "engines": {
package/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Agent, Agent as Agent$1, AgentId, AgentNotFoundError, AgentNotFoundError as AgentNotFoundError$1, AgentReport, AgentReport as AgentReport$1, ArtifactKind, ArtifactKind as ArtifactKind$1, ArtifactKind as ArtifactKind$2, ArtifactSuite, ArtifactSuite as ArtifactSuite$1, ArtifactSuite as ArtifactSuite$2, BehaviorDetail, BehaviorDetail as BehaviorDetail$1, BehaviorNotFoundError, BehaviorNotFoundError as BehaviorNotFoundError$1, BehaviorRow, BehaviorRow as BehaviorRow$1, BehaviorStatus, BehaviorStatus as BehaviorStatus$1, CacheManifest, CacheManifest as CacheManifest$1, ChatId, CitedArtifact, CitedArtifact as CitedArtifact$1, CoverageBaselines, CoverageBaselines as CoverageBaselines$1, CoverageReport, CoverageReport as CoverageReport$1, DataStoreError, DataStoreError as DataStoreError$1, FileCoverageReport, FileCoverageReport as FileCoverageReport$1, GoalDetail, GoalDetail as GoalDetail$1, GoalNotFoundError, GoalNotFoundError as GoalNotFoundError$1, GoalRow, GoalRow as GoalRow$1, GoalStatus, GoalStatus as GoalStatus$1, HistoryRecord, HistoryRecord as HistoryRecord$1, IdempotencyHit, IdempotencyHit as IdempotencyHit$1, IllegalStatusTransitionEntity, IllegalStatusTransitionError, IllegalStatusTransitionError as IllegalStatusTransitionError$1, Phase, Phase as Phase$1, RegistrationConflictError, RegistrationConflictError as RegistrationConflictError$1, ResolvedThresholds, ResolvedThresholds as ResolvedThresholds$1, RunRetentionPolicy, RunRetentionPolicy as RunRetentionPolicy$1, StrayOutput, TddTaskAlreadyEndedError, TddTaskAlreadyEndedError as TddTaskAlreadyEndedError$1, TddTaskEndOutcome, TddTaskNotFoundError, TddTaskNotFoundError as TddTaskNotFoundError$1, TrendEntry, TrendEntry as TrendEntry$1, TrendRecord, TrendRecord as TrendRecord$1 } from "@vitest-agent/sdk";
1
+ import { Agent, Agent as Agent$1, AgentId, AgentNotFoundError, AgentNotFoundError as AgentNotFoundError$1, AgentReport, AgentReport as AgentReport$1, ArtifactKind, ArtifactKind as ArtifactKind$1, ArtifactKind as ArtifactKind$2, ArtifactSuite, ArtifactSuite as ArtifactSuite$1, ArtifactSuite as ArtifactSuite$2, BehaviorDetail, BehaviorDetail as BehaviorDetail$1, BehaviorNotFoundError, BehaviorNotFoundError as BehaviorNotFoundError$1, BehaviorRow, BehaviorRow as BehaviorRow$1, BehaviorStatus, BehaviorStatus as BehaviorStatus$1, CacheManifest, CacheManifest as CacheManifest$1, ChatId, CitedArtifact, CitedArtifact as CitedArtifact$1, CoverageBaselines, CoverageBaselines as CoverageBaselines$1, CoverageReport, CoverageReport as CoverageReport$1, DataStoreError, DataStoreError as DataStoreError$1, FileCoverageReport, FileCoverageReport as FileCoverageReport$1, GoalDetail, GoalDetail as GoalDetail$1, GoalNotFoundError, GoalNotFoundError as GoalNotFoundError$1, GoalRow, GoalRow as GoalRow$1, GoalStatus, GoalStatus as GoalStatus$1, HistoryRecord, HistoryRecord as HistoryRecord$1, IdempotencyHit, IdempotencyHit as IdempotencyHit$1, IllegalStatusTransitionEntity, IllegalStatusTransitionError, IllegalStatusTransitionError as IllegalStatusTransitionError$1, ModuleCacheStat, Phase, Phase as Phase$1, RegistrationConflictError, RegistrationConflictError as RegistrationConflictError$1, ResolvedThresholds, ResolvedThresholds as ResolvedThresholds$1, RunRetentionPolicy, RunRetentionPolicy as RunRetentionPolicy$1, StrayOutput, TddTaskAlreadyEndedError, TddTaskAlreadyEndedError as TddTaskAlreadyEndedError$1, TddTaskEndOutcome, TddTaskNotFoundError, TddTaskNotFoundError as TddTaskNotFoundError$1, TraceStep, TrendEntry, TrendEntry as TrendEntry$1, TrendRecord, TrendRecord as TrendRecord$1 } from "@vitest-agent/sdk";
2
2
  import { Context, Effect, Layer, Option, Schema } from "effect";
3
3
  import { StoreError, StoreMigrationError } from "@effected/store";
4
4
  import { SqlError } from "effect/sql/SqlError";
@@ -103,6 +103,13 @@ interface TestRunInput {
103
103
  * recorded nothing, which the row stores as NULL in every `stray_*` column.
104
104
  */
105
105
  readonly strayOutput?: StrayOutput | null;
106
+ /**
107
+ * How well Vitest's fs module cache served this project's run (issue 741).
108
+ * Per project, so each project row of one invocation carries its own value.
109
+ * Omitted or `null` when the run produced no timing data, which the row
110
+ * stores as NULL in every `module_cache_*` column.
111
+ */
112
+ readonly moduleCache?: ModuleCacheStat | null;
106
113
  }
107
114
  /** @public */
108
115
  interface ModuleInput {
@@ -148,6 +155,20 @@ interface TestCaseInput {
148
155
  */
149
156
  readonly createdTurnId?: number;
150
157
  }
158
+ /**
159
+ * One retry / repeat attempt of a test case (Vitest 5.1
160
+ * `TestCase.attempts()`), persisted in `test_attempts`.
161
+ * @public
162
+ */
163
+ interface TestAttemptInput {
164
+ /** Zero-based retry index within the repeat. */
165
+ readonly retryIndex: number;
166
+ /** Zero-based repeat index. */
167
+ readonly repeatIndex: number;
168
+ readonly state: "passed" | "failed" | "skipped";
169
+ readonly duration?: number;
170
+ readonly startTime?: number;
171
+ }
151
172
  /** @public */
152
173
  interface StackFrameInput {
153
174
  readonly ordinal: number;
@@ -161,6 +182,8 @@ interface StackFrameInput {
161
182
  /** @public */
162
183
  interface TestErrorInput {
163
184
  readonly testCaseId?: number;
185
+ /** `test_attempts.id` of the attempt that raised this error, when known. */
186
+ readonly attemptId?: number;
164
187
  readonly testSuiteId?: number;
165
188
  readonly moduleId?: number;
166
189
  readonly scope: "test" | "suite" | "module" | "unhandled";
@@ -446,6 +469,18 @@ declare const DataStore_base: Context.ServiceClass<DataStore, "vitest-agent/Data
446
469
  readonly writeModules: (runId: number, modules: ReadonlyArray<ModuleInput>) => Effect.Effect<ReadonlyArray<number>, DataStoreError$1>;
447
470
  readonly writeSuites: (moduleId: number, suites: ReadonlyArray<SuiteInput>) => Effect.Effect<ReadonlyArray<number>, DataStoreError$1>;
448
471
  readonly writeTestCases: (moduleId: number, tests: ReadonlyArray<TestCaseInput>) => Effect.Effect<ReadonlyArray<number>, DataStoreError$1>;
472
+ /**
473
+ * Persist one row per retry / repeat attempt of a test case; returns
474
+ * the new `test_attempts.id` values in input order so errors can link
475
+ * to their attempt through `TestErrorInput.attemptId`.
476
+ */
477
+ readonly writeTestAttempts: (testCaseId: number, attempts: ReadonlyArray<TestAttemptInput>) => Effect.Effect<ReadonlyArray<number>, DataStoreError$1>;
478
+ /**
479
+ * Persist the Vitest 5.1 trace-timeline steps of a test case's failed
480
+ * attempt (`test_trace_steps`), in input order. `attemptId` links the
481
+ * steps to their `test_attempts` row when one is known.
482
+ */
483
+ readonly writeTraceSteps: (testCaseId: number, attemptId: number | null, steps: ReadonlyArray<TraceStep>) => Effect.Effect<void, DataStoreError$1>;
449
484
  readonly writeErrors: (runId: number, errors: ReadonlyArray<TestErrorInput>) => Effect.Effect<void, DataStoreError$1>;
450
485
  /**
451
486
  * Persist `context.annotate` notes and their attachment descriptors.
@@ -586,6 +621,36 @@ interface ProjectRunSummary {
586
621
  readonly skipped: number;
587
622
  /** The latest run's stray output (issue 578); `null` when it recorded none. */
588
623
  readonly strayOutput: StrayOutput | null;
624
+ /** The latest run's module cache stat (issue 741); `null` when it recorded none. */
625
+ readonly moduleCache: ModuleCacheStat | null;
626
+ }
627
+ /**
628
+ * Options for `DataReader.getModuleCacheHistory`.
629
+ * @public
630
+ */
631
+ interface ModuleCacheHistoryOptions {
632
+ /** Only runs of this project; every project otherwise. */
633
+ readonly project?: string;
634
+ /** How many of the most recent runs that recorded a stat to return. Default 10. */
635
+ readonly limit?: number;
636
+ }
637
+ /**
638
+ * One run's module cache stat (issue 741).
639
+ * @public
640
+ */
641
+ interface ModuleCacheHistoryRun {
642
+ readonly project: string;
643
+ readonly timestamp: string;
644
+ readonly moduleCache: ModuleCacheStat;
645
+ }
646
+ /**
647
+ * The module cache stats of recent runs, newest first, so a cold run (large
648
+ * transform time, many modules written) reads against a warm one (small
649
+ * transform time, none written). Runs that recorded no stat are skipped.
650
+ * @public
651
+ */
652
+ interface ModuleCacheHistory {
653
+ readonly runs: ReadonlyArray<ModuleCacheHistoryRun>;
589
654
  }
590
655
  /**
591
656
  * Options for `DataReader.getStrayOutputHistory`.
@@ -650,6 +715,41 @@ interface TestError {
650
715
  readonly scope: "test" | "suite" | "module" | "unhandled";
651
716
  readonly testFullName: string | null;
652
717
  readonly moduleFile: string | null;
718
+ /**
719
+ * The retry / repeat attempt that raised this error (zero-based indexes),
720
+ * or `null` when the error is not tied to an attempt: suite, module and
721
+ * unhandled errors, and errors persisted before attempts were recorded.
722
+ */
723
+ readonly attempt: {
724
+ readonly retryIndex: number;
725
+ readonly repeatIndex: number;
726
+ } | null;
727
+ /** Trace-timeline steps recorded for the test's failed attempt; empty when none. */
728
+ readonly traceSteps: ReadonlyArray<TraceStep>;
729
+ }
730
+ /** One persisted retry / repeat attempt of a test (`test_attempts`). @public */
731
+ interface TestAttemptRow {
732
+ readonly id: number;
733
+ readonly retryIndex: number;
734
+ readonly repeatIndex: number;
735
+ readonly state: "passed" | "failed" | "skipped";
736
+ readonly duration: number | null;
737
+ readonly startTime: number | null;
738
+ /** `test_errors.id` values raised by this attempt; cite one in a hypothesis. */
739
+ readonly errorIds: ReadonlyArray<number>;
740
+ }
741
+ /** A test that ran more than one attempt (retry or repeat) in a run. @public */
742
+ interface RetriedTest {
743
+ readonly fullName: string;
744
+ readonly modulePath: string;
745
+ readonly attempts: ReadonlyArray<TestAttemptRow>;
746
+ }
747
+ /** @public */
748
+ interface RetriedTestQueryOptions {
749
+ /** Exact `full_name` match. */
750
+ readonly testName?: string;
751
+ /** Exact module path match. */
752
+ readonly modulePath?: string;
653
753
  }
654
754
  /** @public */
655
755
  interface NoteRow {
@@ -968,6 +1068,8 @@ interface TestArtifactRow {
968
1068
  declare const DataReader_base: Context.ServiceClass<DataReader, "vitest-agent/DataReader", {
969
1069
  readonly getLatestRun: (project: string) => Effect.Effect<Option.Option<AgentReport$1>, DataStoreError$1>;
970
1070
  readonly getRunsByProject: () => Effect.Effect<ReadonlyArray<ProjectRunSummary>, DataStoreError$1>;
1071
+ /** Recent runs' module cache stats, newest first; see {@link ModuleCacheHistory}. */
1072
+ readonly getModuleCacheHistory: (options?: ModuleCacheHistoryOptions) => Effect.Effect<ModuleCacheHistory, DataStoreError$1>;
971
1073
  /** How often the most recent runs wrote stray output; see {@link StrayOutputHistory}. */
972
1074
  readonly getStrayOutputHistory: (options?: StrayOutputHistoryOptions) => Effect.Effect<StrayOutputHistory, DataStoreError$1>;
973
1075
  readonly getHistory: (project: string, options?: HistoryQueryOptions) => Effect.Effect<HistoryRecord$1, DataStoreError$1>;
@@ -979,6 +1081,12 @@ declare const DataReader_base: Context.ServiceClass<DataReader, "vitest-agent/Da
979
1081
  readonly getCoverage: (project: string) => Effect.Effect<Option.Option<CoverageReport$1>, DataStoreError$1>;
980
1082
  readonly getTestsForFile: (filePath: string) => Effect.Effect<ReadonlyArray<string>, DataStoreError$1>;
981
1083
  readonly getErrors: (project: string, errorName?: string) => Effect.Effect<ReadonlyArray<TestError>, DataStoreError$1>;
1084
+ /**
1085
+ * Tests that ran more than one attempt (a retry or a repeat) in the
1086
+ * project's latest run, with every attempt in order. Tests that ran
1087
+ * once are omitted.
1088
+ */
1089
+ readonly getRetriedTests: (project: string, options?: RetriedTestQueryOptions) => Effect.Effect<ReadonlyArray<RetriedTest>, DataStoreError$1>;
982
1090
  /** Annotations recorded for a test in the project's latest run. */
983
1091
  readonly getAnnotationsForTest: (project: string, fullName: string, options?: TestArtifactQueryOptions) => Effect.Effect<ReadonlyArray<TestAnnotationRow>, DataStoreError$1>;
984
1092
  /** Artifacts recorded for a test in the project's latest run. */
@@ -1162,6 +1270,9 @@ export declare const PROJECT_MIGRATIONS: {
1162
1270
  readonly "0003_run_retention": import("effect/Effect").Effect<void, import("effect/sql/SqlError").SqlError, import("effect/sql/SqlClient").SqlClient>;
1163
1271
  readonly "0004_stray_output": import("effect/Effect").Effect<void, import("effect/sql/SqlError").SqlError, import("effect/sql/SqlClient").SqlClient>;
1164
1272
  readonly "0005_scrub_ci_env_vars": import("effect/Effect").Effect<void, import("effect/sql/SqlError").SqlError, import("effect/sql/SqlClient").SqlClient>;
1273
+ readonly "0006_test_attempts": import("effect/Effect").Effect<void, import("effect/sql/SqlError").SqlError, import("effect/sql/SqlClient").SqlClient>;
1274
+ readonly "0007_trace_steps": import("effect/Effect").Effect<void, import("effect/sql/SqlError").SqlError, import("effect/sql/SqlClient").SqlClient>;
1275
+ readonly "0008_module_cache": import("effect/Effect").Effect<void, import("effect/sql/SqlError").SqlError, import("effect/sql/SqlClient").SqlClient>;
1165
1276
  };
1166
1277
  /** @public */
1167
1278
  export declare function makeTestLayer(filename: string): Layer.Layer<DataReader | DataStore | import("effect/sql/SqlClient").SqlClient | import("@effect/sql-sqlite-node/SqliteClient").SqliteClient | import("@effect/platform-node/NodeServices").NodeServices, PlatformLiveError, never>;
@@ -1177,5 +1288,5 @@ export declare function withFailures(filename: string): Layer.Layer<DataReader |
1177
1288
  export declare function flaky(filename: string): Layer.Layer<DataReader | DataStore | import("effect/sql/SqlClient").SqlClient | import("@effect/sql-sqlite-node/SqliteClient").SqliteClient | import("@effect/platform-node/NodeServices").NodeServices, import("@vitest-agent/sdk").DataStoreError | PlatformLiveError, never>;
1178
1289
  /** @public */
1179
1290
  export declare function withTddTask(filename: string): Layer.Layer<DataReader | DataStore | import("effect/sql/SqlClient").SqlClient | import("@effect/sql-sqlite-node/SqliteClient").SqliteClient | import("@effect/platform-node/NodeServices").NodeServices, import("@vitest-agent/sdk").BehaviorNotFoundError | import("@vitest-agent/sdk").DataStoreError | import("@vitest-agent/sdk").GoalNotFoundError | import("@vitest-agent/sdk").IllegalStatusTransitionError | import("@vitest-agent/sdk").TddTaskAlreadyEndedError | import("@vitest-agent/sdk").TddTaskNotFoundError | PlatformLiveError, never>;
1180
- export { type AcceptanceMetrics, Agent, AgentId, AgentNotFoundError, AgentReport, type ArtifactKind, type ArtifactSuite, type AssociateRunSessionInput, BehaviorDetail, BehaviorNotFoundError, BehaviorRow, BehaviorStatus, CacheManifest, type ChangeKind, ChatId, type CitedArtifact, type CitedArtifactRow, type ClassificationQueryOptions, type CommitChangesEntry, CoverageBaselines, CoverageReport, type CreateBehaviorInput, type CreateGoalInput, type CurrentTddPhase, DataStoreError, type EndTddTaskInput, type FailureSignatureDetail, type FailureSignatureWriteInput, type FileCoverageInput, FileCoverageReport, type FlakyTest, GoalDetail, GoalNotFoundError, GoalRow, GoalStatus, type HistoryQueryOptions, HistoryRecord, type HypothesisDetail, type HypothesisInput, IdempotencyHit, type IdempotentResponseInput, type IllegalStatusTransitionEntity, IllegalStatusTransitionError, type ModuleInput, type ModuleListEntry, type NoteInput, type NoteRow, type PersistedAttachment, type PersistentFailure, type Phase, type PlatformLiveError, type ProjectRunSummary, type PruneRunsResult, type RegisterAgentInput, RegistrationConflictError, type ResolvedThresholds, type RunChangedFile, type RunInvocationMethod, RunRetentionPolicy, type SessionDetail, type SessionInput, type SettingsInput, type SettingsListEntry, type SettingsRow, type StackFrameInput, type StrayOutputHistory, type StrayOutputHistoryOptions, type SuiteInput, type SuiteListEntry, type TagInventoryRow, type TddArtifactDetail, type TddArtifactRow, type TddPhaseDetail, TddTaskAlreadyEndedError, type TddTaskDetail, type TddTaskEndOutcome, type TddTaskInput, TddTaskNotFoundError, type TddTaskSummary, type TestAnnotationInput, type TestAnnotationRow, type TestArtifactInput, type TestArtifactQueryOptions, type TestArtifactRow, type TestAttachmentInput, type TestCaseInput, type TestError, type TestErrorInput, type TestListEntry, type TestLookupOptions, type TestRunInput, TrendEntry, TrendRecord, type TurnInput, type TurnSearchOptions, type TurnSummary, type UpdateBehaviorInput, type UpdateGoalInput, type ValidateHypothesisInput, type WriteCommitInput, type WriteRunChangedFilesInput, type WriteTddArtifactInput, type WriteTddPhaseInput, type WriteTddPhaseOutput };
1291
+ export { type AcceptanceMetrics, Agent, AgentId, AgentNotFoundError, AgentReport, type ArtifactKind, type ArtifactSuite, type AssociateRunSessionInput, BehaviorDetail, BehaviorNotFoundError, BehaviorRow, BehaviorStatus, CacheManifest, type ChangeKind, ChatId, type CitedArtifact, type CitedArtifactRow, type ClassificationQueryOptions, type CommitChangesEntry, CoverageBaselines, CoverageReport, type CreateBehaviorInput, type CreateGoalInput, type CurrentTddPhase, DataStoreError, type EndTddTaskInput, type FailureSignatureDetail, type FailureSignatureWriteInput, type FileCoverageInput, FileCoverageReport, type FlakyTest, GoalDetail, GoalNotFoundError, GoalRow, GoalStatus, type HistoryQueryOptions, HistoryRecord, type HypothesisDetail, type HypothesisInput, IdempotencyHit, type IdempotentResponseInput, type IllegalStatusTransitionEntity, IllegalStatusTransitionError, type ModuleCacheHistory, type ModuleCacheHistoryOptions, type ModuleCacheHistoryRun, type ModuleInput, type ModuleListEntry, type NoteInput, type NoteRow, type PersistedAttachment, type PersistentFailure, type Phase, type PlatformLiveError, type ProjectRunSummary, type PruneRunsResult, type RegisterAgentInput, RegistrationConflictError, type ResolvedThresholds, type RetriedTest, type RetriedTestQueryOptions, type RunChangedFile, type RunInvocationMethod, RunRetentionPolicy, type SessionDetail, type SessionInput, type SettingsInput, type SettingsListEntry, type SettingsRow, type StackFrameInput, type StrayOutputHistory, type StrayOutputHistoryOptions, type SuiteInput, type SuiteListEntry, type TagInventoryRow, type TddArtifactDetail, type TddArtifactRow, type TddPhaseDetail, TddTaskAlreadyEndedError, type TddTaskDetail, type TddTaskEndOutcome, type TddTaskInput, TddTaskNotFoundError, type TddTaskSummary, type TestAnnotationInput, type TestAnnotationRow, type TestArtifactInput, type TestArtifactQueryOptions, type TestArtifactRow, type TestAttachmentInput, type TestAttemptInput, type TestAttemptRow, type TestCaseInput, type TestError, type TestErrorInput, type TestListEntry, type TestLookupOptions, type TestRunInput, TrendEntry, TrendRecord, type TurnInput, type TurnSearchOptions, type TurnSummary, type UpdateBehaviorInput, type UpdateGoalInput, type ValidateHypothesisInput, type WriteCommitInput, type WriteRunChangedFilesInput, type WriteTddArtifactInput, type WriteTddPhaseInput, type WriteTddPhaseOutput };
1181
1292
  //# sourceMappingURL=testing.d.ts.map
package/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
2
  /** Build-time injected package version (see architecture.md D36). @public */
3
- const CURRENT_ENGINE_VERSION = "3.3.0";
3
+ const CURRENT_ENGINE_VERSION = "3.4.0";
4
4
 
5
5
  export { CURRENT_ENGINE_VERSION };