a2854ba768
Migrate 203 test files (356 call sites) from fs.rm/fs.rmSync to
removeWithRetries/removeSyncWithRetries to reduce EBUSY test failures
on Windows. removeWithRetries is now exported from @oh-my-pi/pi-utils.
The migration uses a regex-based approach that:
- Replaces fs.rm(path, { recursive, force }) → removeWithRetries(path)
- Replaces fs.rmSync(path, { recursive, force }) → removeSyncWithRetries(path)
- Replaces fs.rm(path) → removeWithRetries(path) (no options)
- Skips fs.rm/fs.rmSync inside template literals (bun --eval scripts)
- Adds imports to existing @oh-my-pi/pi-utils import or creates new one
- Removes unused fs imports where fs.rm was the only fs usage (4 files)
80 lines
3.1 KiB
TypeScript
80 lines
3.1 KiB
TypeScript
/**
|
|
* Regression guard for issue #2190 / PR #2193 review.
|
|
*
|
|
* The CLI loads extensions early to parse custom flags, then hands the result
|
|
* back through `preloadedExtensions` so its OWN session can reuse the loaded
|
|
* instances without redoing the FS scan. `createAgentSession()` augments the
|
|
* result with inline extensions (autoresearch + custom-tools wrapper), so it
|
|
* MUST clone the caller's `extensions` array before mutating it — otherwise
|
|
* the caller's array accumulates session-local wrappers it never authored.
|
|
*
|
|
* Subagent forwarding is a separate path (`preloadedExtensionPaths`) which
|
|
* reloads extensions per session so each session's `ExtensionAPI` is its own.
|
|
*/
|
|
import { afterAll, beforeAll, describe, expect, it } from "bun:test";
|
|
import * as fs from "node:fs";
|
|
import * as os from "node:os";
|
|
import * as path from "node:path";
|
|
import { ModelRegistry } from "@oh-my-pi/pi-coding-agent/config/model-registry";
|
|
import { Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
|
|
import type { LoadExtensionsResult } from "@oh-my-pi/pi-coding-agent/extensibility/extensions/types";
|
|
import { createAgentSession } from "@oh-my-pi/pi-coding-agent/sdk";
|
|
import { AuthStorage } from "@oh-my-pi/pi-coding-agent/session/auth-storage";
|
|
import { SessionManager } from "@oh-my-pi/pi-coding-agent/session/session-manager";
|
|
import { removeSyncWithRetries } from "@oh-my-pi/pi-utils";
|
|
|
|
describe("createAgentSession preloadedExtensions isolation (issue #2190)", () => {
|
|
let sharedDir: string;
|
|
let authStorage: AuthStorage;
|
|
let modelRegistry: ModelRegistry;
|
|
|
|
beforeAll(async () => {
|
|
sharedDir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-preloaded-ext-"));
|
|
authStorage = await AuthStorage.create(path.join(sharedDir, "auth.db"));
|
|
modelRegistry = new ModelRegistry(authStorage, path.join(sharedDir, "models.yml"));
|
|
});
|
|
|
|
afterAll(() => {
|
|
authStorage.close();
|
|
removeSyncWithRetries(sharedDir);
|
|
});
|
|
|
|
it("does not mutate the caller's extensions array when preloadedExtensions is provided", async () => {
|
|
const preloaded: LoadExtensionsResult = {
|
|
extensions: [],
|
|
errors: [],
|
|
runtime: {
|
|
flagValues: new Map(),
|
|
pendingProviderRegistrations: [],
|
|
// Cast: only the fields we touch matter; the SDK happily accepts a
|
|
// minimal runtime when no extension hooks fire.
|
|
} as unknown as LoadExtensionsResult["runtime"],
|
|
};
|
|
const beforeLength = preloaded.extensions.length;
|
|
const beforeArrayRef = preloaded.extensions;
|
|
|
|
await createAgentSession({
|
|
cwd: sharedDir,
|
|
agentDir: sharedDir,
|
|
sessionManager: SessionManager.inMemory(),
|
|
modelRegistry,
|
|
settings: Settings.isolated(),
|
|
preloadedExtensions: preloaded,
|
|
// Disable everything that would touch the network / FS scans.
|
|
enableLsp: false,
|
|
enableMCP: false,
|
|
skipPythonPreflight: true,
|
|
skills: [],
|
|
rules: [],
|
|
preloadedCustomToolPaths: [],
|
|
contextFiles: [],
|
|
promptTemplates: [],
|
|
});
|
|
|
|
// The session's own `extensionsResult` carries inline wrappers, but the
|
|
// caller's array (and its identity) must be untouched.
|
|
expect(preloaded.extensions).toBe(beforeArrayRef);
|
|
expect(preloaded.extensions.length).toBe(beforeLength);
|
|
});
|
|
});
|