refactor(test): dedupe agent harnesses and routing fixtures

This commit is contained in:
Peter Steinberger
2026-02-18 04:48:40 +00:00
parent 8a9fddedc9
commit 31f83c86b2
12 changed files with 440 additions and 755 deletions

View File

@@ -86,6 +86,27 @@ async function createVoiceCallArchive(params: {
return { pkgDir, archivePath };
}
async function setupVoiceCallArchiveInstall(params: { outName: string; version: string }) {
const stateDir = makeTempDir();
const workDir = makeTempDir();
const { archivePath } = await createVoiceCallArchive({
workDir,
outName: params.outName,
version: params.version,
});
return {
stateDir,
archivePath,
extensionsDir: path.join(stateDir, "extensions"),
};
}
function expectPluginFiles(result: { targetDir: string }, stateDir: string, pluginId: string) {
expect(result.targetDir).toBe(path.join(stateDir, "extensions", pluginId));
expect(fs.existsSync(path.join(result.targetDir, "package.json"))).toBe(true);
expect(fs.existsSync(path.join(result.targetDir, "dist", "index.js"))).toBe(true);
}
function setupPluginInstallDirs() {
const tmpDir = makeTempDir();
const pluginDir = path.join(tmpDir, "plugin-src");
@@ -164,15 +185,11 @@ beforeEach(() => {
describe("installPluginFromArchive", () => {
it("installs into ~/.openclaw/extensions and uses unscoped id", async () => {
const stateDir = makeTempDir();
const workDir = makeTempDir();
const { archivePath } = await createVoiceCallArchive({
workDir,
const { stateDir, archivePath, extensionsDir } = await setupVoiceCallArchiveInstall({
outName: "plugin.tgz",
version: "0.0.1",
});
const extensionsDir = path.join(stateDir, "extensions");
const { installPluginFromArchive } = await import("./install.js");
const result = await installPluginFromArchive({
archivePath,
@@ -183,21 +200,15 @@ describe("installPluginFromArchive", () => {
return;
}
expect(result.pluginId).toBe("voice-call");
expect(result.targetDir).toBe(path.join(stateDir, "extensions", "voice-call"));
expect(fs.existsSync(path.join(result.targetDir, "package.json"))).toBe(true);
expect(fs.existsSync(path.join(result.targetDir, "dist", "index.js"))).toBe(true);
expectPluginFiles(result, stateDir, "voice-call");
});
it("rejects installing when plugin already exists", async () => {
const stateDir = makeTempDir();
const workDir = makeTempDir();
const { archivePath } = await createVoiceCallArchive({
workDir,
const { archivePath, extensionsDir } = await setupVoiceCallArchiveInstall({
outName: "plugin.tgz",
version: "0.0.1",
});
const extensionsDir = path.join(stateDir, "extensions");
const { installPluginFromArchive } = await import("./install.js");
const first = await installPluginFromArchive({
archivePath,
@@ -246,9 +257,7 @@ describe("installPluginFromArchive", () => {
return;
}
expect(result.pluginId).toBe("zipper");
expect(result.targetDir).toBe(path.join(stateDir, "extensions", "zipper"));
expect(fs.existsSync(path.join(result.targetDir, "package.json"))).toBe(true);
expect(fs.existsSync(path.join(result.targetDir, "dist", "index.js"))).toBe(true);
expectPluginFiles(result, stateDir, "zipper");
});
it("allows updates when mode is update", async () => {