Skip to content

Commit 50be24c

Browse files
committed
fix(plugins): drop unused test reset helper and satisfy oxlint
Remove __resetPluginScanExistenceCacheForTest: the scan cache is push/pop balanced by try/finally in withPluginScanExistenceCache, so the stack never leaks between tests and the helper was dead code. It also tripped oxlint no-underscore-dangle. Refactor the integration test to count existsSync calls via a const-returning helper so there is no useless assignment.
1 parent 338fc0d commit 50be24c

2 files changed

Lines changed: 15 additions & 41 deletions

File tree

‎src/plugins/plugin-scan-existence-cache.test.ts‎

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
import fs from "node:fs";
55
import os from "node:os";
66
import path from "node:path";
7-
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
7+
import { afterEach, describe, expect, it, vi } from "vitest";
88
import { loadBundleManifest, detectBundleManifestFormat } from "./bundle-manifest.js";
99
import {
10-
__resetPluginScanExistenceCacheForTest,
1110
pluginScanExistsSync,
1211
withPluginScanExistenceCache,
1312
} from "./plugin-scan-existence-cache.js";
@@ -21,7 +20,6 @@ function makeTempDir(prefix: string): string {
2120
}
2221

2322
afterEach(() => {
24-
__resetPluginScanExistenceCacheForTest();
2523
for (const dir of tempDirs) {
2624
fs.rmSync(dir, { recursive: true, force: true });
2725
}
@@ -105,10 +103,6 @@ describe("pluginScanExistsSync", () => {
105103
});
106104

107105
describe("bundle manifest scan uses the existence cache", () => {
108-
beforeEach(() => {
109-
__resetPluginScanExistenceCacheForTest();
110-
});
111-
112106
function buildClaudeBundlePlugin(root: string): void {
113107
fs.mkdirSync(path.join(root, ".claude-plugin"), { recursive: true });
114108
fs.writeFileSync(
@@ -129,39 +123,27 @@ describe("bundle manifest scan uses the existence cache", () => {
129123
const root = makeTempDir("claude-bundle-");
130124
buildClaudeBundlePlugin(root);
131125

132-
// Baseline: no scan cache → detect and load re-probe the same marker paths.
133-
let uncachedCalls = 0;
134-
{
126+
// Run a detect + load pair and count fs.existsSync calls under a spy.
127+
const detectAndLoad = (): void => {
128+
const format = detectBundleManifestFormat(root);
129+
if (format) {
130+
loadBundleManifest({ rootDir: root, bundleFormat: format });
131+
}
132+
};
133+
const countExistsSyncCalls = (run: () => void): number => {
135134
const spy = vi.spyOn(fs, "existsSync");
136135
try {
137-
const format = detectBundleManifestFormat(root);
138-
if (format) {
139-
loadBundleManifest({ rootDir: root, bundleFormat: format });
140-
}
141-
uncachedCalls = spy.mock.calls.length;
136+
run();
137+
return spy.mock.calls.length;
142138
} finally {
143139
spy.mockRestore();
144140
}
145-
}
146-
147-
__resetPluginScanExistenceCacheForTest();
141+
};
148142

143+
// Baseline: no scan cache → detect and load re-probe the same marker paths.
144+
const uncachedCalls = countExistsSyncCalls(detectAndLoad);
149145
// Same workload, but the detect + load pair shares one scan cache.
150-
let cachedCalls = 0;
151-
{
152-
const spy = vi.spyOn(fs, "existsSync");
153-
try {
154-
withPluginScanExistenceCache(() => {
155-
const format = detectBundleManifestFormat(root);
156-
if (format) {
157-
loadBundleManifest({ rootDir: root, bundleFormat: format });
158-
}
159-
});
160-
cachedCalls = spy.mock.calls.length;
161-
} finally {
162-
spy.mockRestore();
163-
}
164-
}
146+
const cachedCalls = countExistsSyncCalls(() => withPluginScanExistenceCache(detectAndLoad));
165147

166148
// Both paths must still produce a valid claude bundle manifest.
167149
const manifest = withPluginScanExistenceCache(() => {

‎src/plugins/plugin-scan-existence-cache.ts‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,3 @@ export function pluginScanExistsSync(targetPath: string): boolean {
4949
cache.set(targetPath, result);
5050
return result;
5151
}
52-
53-
/** Test-only: clears any leaked active scan caches. */
54-
export function __resetPluginScanExistenceCacheForTest(): void {
55-
if (process.env.VITEST !== "true" && process.env.NODE_ENV !== "test") {
56-
throw new Error("__resetPluginScanExistenceCacheForTest is only available in tests");
57-
}
58-
scanExistenceCacheStack.length = 0;
59-
}

0 commit comments

Comments
 (0)