@vitest-agent/plugin 3.0.0 → 3.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitest-agent/plugin",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "private": false,
5
5
  "description": "Vitest plugin for the vitest-agent ecosystem: owns persistence, classification, baselines, trends, and dispatches rendering to a configurable reporter.",
6
6
  "keywords": [
@@ -41,11 +41,11 @@
41
41
  "dependencies": {
42
42
  "@effect/platform-node": "4.0.0-rc.112",
43
43
  "@effect/sql-sqlite-node": "4.0.0-rc.112",
44
- "@effected/workspaces": "^0.20.1",
45
- "@vitest-agent/cli": "2.2.16",
46
- "@vitest-agent/mcp": "3.0.0",
47
- "@vitest-agent/reporter": "3.0.0",
48
- "@vitest-agent/sdk": "3.0.0",
44
+ "@effected/workspaces": "^0.20.3",
45
+ "@vitest-agent/cli": "2.2.18",
46
+ "@vitest-agent/mcp": "3.0.2",
47
+ "@vitest-agent/reporter": "3.0.2",
48
+ "@vitest-agent/sdk": "3.1.1",
49
49
  "effect": "4.0.0-rc.112",
50
50
  "magic-string": "^1.2.3"
51
51
  },
package/plugin.js CHANGED
@@ -14,6 +14,7 @@ import { resolveCoverageDirIsolation } from "./utils/resolve-coverage-dir-isolat
14
14
  import { DEFAULT_BUILT_RECENTLY_MS, DEFAULT_LOCK_STALE_MS, DEFAULT_LOCK_WAIT_TIMEOUT_MS, acquireRunScriptLock, markRunScriptDone, parseLockTimingOverride, releaseRunScriptLock } from "./utils/run-script-lock.js";
15
15
  import { stripConsoleReporters } from "./utils/strip-console-reporters.js";
16
16
  import { makeTagCacheKeyGenerator } from "./utils/tag-cache-key.js";
17
+ import { readVitestVersion, vitestPeerVersionMismatchMessage } from "./utils/vitest-peer-version-mismatch-error.js";
17
18
  import { execSync } from "node:child_process";
18
19
  import { mkdtempSync, rmSync } from "node:fs";
19
20
  import { tmpdir } from "node:os";
@@ -125,7 +126,7 @@ const coverageDirDecidedByVitest = /* @__PURE__ */ new WeakSet();
125
126
  *
126
127
  * @public
127
128
  */
128
- const CURRENT_PLUGIN_VERSION = "3.0.0";
129
+ const CURRENT_PLUGIN_VERSION = "3.0.2";
129
130
  const TEST_FILE_DIR_RE = new RegExp(`/(?:${SRC_DIR}|${TEST_DIR})/`);
130
131
  const isTestFile = (id) => isTestFileName(id) && TEST_FILE_DIR_RE.test(id);
131
132
  /**
@@ -196,6 +197,7 @@ function AgentPlugin(options = {}, _layer) {
196
197
  try {
197
198
  const { vitest, project } = ctx;
198
199
  log("configureVitest called | project:", project?.name ?? "(root)");
200
+ if (typeof ctx.defineCacheKeyGenerator !== "function") throw new ConfigurationError(vitestPeerVersionMismatchMessage(readVitestVersion(vitest)));
199
201
  if (discoverStrategyResolved && !cacheKeyGeneratorByVitest.has(vitest)) {
200
202
  cacheKeyGeneratorByVitest.add(vitest);
201
203
  ctx.defineCacheKeyGenerator(makeTagCacheKeyGenerator(classifyForCache));
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.59.0"
8
+ "packageVersion": "7.59.1"
9
9
  }
10
10
  ]
11
11
  }
@@ -1,32 +1,53 @@
1
1
  import { nodeWalkerFs } from "./walker-fs.js";
2
2
  import { findTestFiles } from "./find-test-files.js";
3
3
  import { join } from "node:path";
4
- import { SRC_DIR, TEST_DIR, TEST_FILE_GLOB_SUFFIX } from "@vitest-agent/sdk";
4
+ import { BATS_FILE_GLOB_SUFFIX, SRC_DIR, TEST_DIR, TEST_FILE_GLOB_SUFFIX } from "@vitest-agent/sdk";
5
5
 
6
6
  //#region src/utils/is-test-shaped-package.ts
7
7
  /**
8
- * True when `pkgPath` looks like it was meant to hold tests: a `__test__/`
9
- * directory exists at the package root (regardless of what's inside it), or
10
- * `src/` contains at least one file matching the discoverable test-file
11
- * naming convention (`TEST_FILE_GLOB_SUFFIX`).
8
+ * True when `pkgPath` looks like it was meant to hold tests, yet neither a
9
+ * discoverable Vitest test file nor a Bats test file was found anywhere
10
+ * under it the condition `discoverProjects`'s declined-package warning
11
+ * (issue #229) exists to catch.
12
12
  *
13
- * Reuses `SRC_DIR` / `TEST_DIR` / `TEST_FILE_GLOB_SUFFIX` from
14
- * `@vitest-agent/sdk`'s `utils/test-location.ts` the single source of
15
- * truth for the test-layout rule — and the existing `findTestFiles` walker,
16
- * rather than re-deriving the shape independently.
13
+ * We only want to surface a warning when NO vitest test and NO bats test
14
+ * are found. Concretely, in order:
17
15
  *
18
- * A `__test__/` directory counts on existence alone, not on matching file
19
- * content: the failure mode this predicate exists to catch (issue #229) IS a
20
- * `__test__/` directory whose files don't match the naming convention (wrong
21
- * suffix, wrong extension, typo) `DefaultDiscoverStrategy.buildProject`
22
- * already declined those packages by finding zero matching files, so
23
- * requiring a match here would make the predicate blind to exactly the case
24
- * it needs to catch.
16
+ * 1. A Vitest-convention test file under `src/**` or `__test__/**`
17
+ * (`TEST_FILE_GLOB_SUFFIX`) not test-shaped (false, no warning). The
18
+ * package has real, discoverable tests.
19
+ * 2. A `.bats` file anywhere under the package (`BATS_FILE_GLOB_SUFFIX`,
20
+ * searched recursively a nested `__test__/foo/bar.bats` counts) not
21
+ * test-shaped (false, no warning). Bats tests are run by `bats`, not
22
+ * Vitest (`bats --recursive`, or the `test:bats` package script); a
23
+ * `__test__/` directory holding only `.bats` files (plus fixtures) is a
24
+ * fully supported, intentional layout — see `@effected/claude-code-plugin`'s
25
+ * `plugins/claude-code/__test__/` for the real case this fixes (issue
26
+ * #360-adjacent).
27
+ * 3. Otherwise, a `__test__/` directory existing at all — regardless of what
28
+ * it contains — IS test-shaped (true, warn). This is deliberately
29
+ * existence-only, not content-matching: the failure mode this predicate
30
+ * exists to catch (issue #229) IS a `__test__/` directory whose files
31
+ * match neither convention (wrong suffix, wrong extension, typo, or
32
+ * nothing at all — an empty directory). `DefaultDiscoverStrategy
33
+ * .buildProject` already declined those packages by finding zero
34
+ * matching Vitest files; step 1 above already declined them by finding
35
+ * zero Bats files either; requiring a content match here too would make
36
+ * the predicate blind to exactly the case it needs to catch.
37
+ *
38
+ * Reuses `SRC_DIR` / `TEST_DIR` / `TEST_FILE_GLOB_SUFFIX` /
39
+ * `BATS_FILE_GLOB_SUFFIX` from `@vitest-agent/sdk`'s `utils/test-location.ts`
40
+ * — the single source of truth for the test-layout rule — and the existing
41
+ * `findTestFiles` walker, rather than re-deriving the shape independently.
25
42
  * @internal
26
43
  */
27
44
  async function isTestShapedPackage(pkgPath, fs = nodeWalkerFs) {
28
- if ((await fs.statEntry(join(pkgPath, TEST_DIR)))?.isDirectory === true) return true;
29
- return (await findTestFiles(pkgPath, [`${SRC_DIR}/**/${TEST_FILE_GLOB_SUFFIX}`], fs)).length > 0;
45
+ if ((await findTestFiles(pkgPath, [
46
+ `${SRC_DIR}/**/${TEST_FILE_GLOB_SUFFIX}`,
47
+ `${TEST_DIR}/**/${TEST_FILE_GLOB_SUFFIX}`,
48
+ `**/${BATS_FILE_GLOB_SUFFIX}`
49
+ ], fs)).length > 0) return false;
50
+ return (await fs.statEntry(join(pkgPath, TEST_DIR)))?.isDirectory === true;
30
51
  }
31
52
 
32
53
  //#endregion
@@ -0,0 +1,40 @@
1
+ //#region src/utils/vitest-peer-version-mismatch-error.ts
2
+ /**
3
+ * Builds the message `configureVitest` throws as a {@link ConfigurationError}
4
+ * when the Vitest 5-only `ctx.defineCacheKeyGenerator` field is absent — the
5
+ * reliable signal that the host project's `vitest` peer resolves to a pre-5
6
+ * release (Vitest 4 exposes only the deprecated
7
+ * `experimental_defineCacheKeyGenerator` alias).
8
+ *
9
+ * `@vitest-agent/plugin` 3.x is Vitest-5-only by design: no `experimental_`
10
+ * fallback, no silent degradation. A version mismatch is the user's own
11
+ * environment to fix, which is exactly what `ConfigurationError` means, so
12
+ * this rides that class rather than introducing a parallel one — the catch
13
+ * block in `configureVitest` keeps a single branch.
14
+ *
15
+ * The leading `vitest-agent: ` marker is part of the message because
16
+ * `ConfigurationError` messages are written to stderr verbatim, not prefixed
17
+ * at the write site.
18
+ *
19
+ * @internal
20
+ */
21
+ function vitestPeerVersionMismatchMessage(detectedVersion) {
22
+ return `vitest-agent: @vitest-agent/plugin 3.x requires Vitest >= 5. ${detectedVersion !== void 0 ? `Detected Vitest ${detectedVersion}.` : "The installed Vitest version could not be detected."} Install @vitest-agent/plugin 2.x for Vitest 4.`;
23
+ }
24
+ /**
25
+ * Reads a Vitest version string off the `ctx.vitest` instance handed to
26
+ * `configureVitest`, if present and shaped as expected. Degrades to
27
+ * `undefined` rather than throwing — this runs on the path that is already
28
+ * diagnosing a version mismatch, so it must never itself fail on an
29
+ * unexpected shape.
30
+ *
31
+ * @internal
32
+ */
33
+ function readVitestVersion(vitest) {
34
+ if (vitest === null || typeof vitest !== "object") return void 0;
35
+ const version = vitest.version;
36
+ return typeof version === "string" ? version : void 0;
37
+ }
38
+
39
+ //#endregion
40
+ export { readVitestVersion, vitestPeerVersionMismatchMessage };