feat(FN-2101): merge fusion/fn-2101

This commit is contained in:
Fusion
2026-04-18 22:07:28 -07:00
committed by gsxdsm
parent 4e3e2ca7fe
commit e1171ba24c
4 changed files with 33 additions and 5 deletions

View File

@@ -39,6 +39,7 @@
"check-disk-space": "^3.4.0",
"cron-parser": "^5.5.0",
"extract-zip": "^2.0.1",
"tar": "^7.5.13",
"yaml": "^2.8.3"
}
}

View File

@@ -367,6 +367,23 @@ name: Archive CEO
expect(pkg.agents[0]?.name).toBe("Archive CEO");
});
it("throws AgentCompaniesParseError for a corrupt .tar.gz file", async () => {
const root = createTempDir();
const archivePath = join(root, "corrupt.tgz");
writeTextFile(archivePath, "not a real gzip archive");
await expect(parseCompanyArchive(archivePath)).rejects.toBeInstanceOf(AgentCompaniesParseError);
await expect(parseCompanyArchive(archivePath)).rejects.toThrow(
"Failed to parse Agent Companies archive",
);
});
it("throws AgentCompaniesParseError for a non-existent .tar.gz file", async () => {
const archivePath = join(createTempDir(), "missing.tgz");
await expect(parseCompanyArchive(archivePath)).rejects.toBeInstanceOf(AgentCompaniesParseError);
});
const zipIt = hasCommand("zip") ? it : it.skip;
zipIt("parses a .zip archive", async () => {
const root = createTempDir();

View File

@@ -4,8 +4,8 @@
* @module agent-companies-parser
*/
import { execSync } from "node:child_process";
import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync } from "node:fs";
import { createRequire } from "node:module";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
@@ -24,6 +24,16 @@ import type {
} from "./agent-companies-types.js";
import type { AgentCapability, AgentCreateInput } from "./types.js";
type TarExtractOptions = {
file: string;
cwd: string;
};
const require = createRequire(import.meta.url);
const { x: tarExtract } = require("tar") as {
x: (options: TarExtractOptions) => Promise<void>;
};
export class AgentCompaniesParseError extends Error {
constructor(message: string) {
super(message);
@@ -486,10 +496,7 @@ export async function parseCompanyArchive(archivePath: string): Promise<AgentCom
try {
if (resolvedArchivePath.endsWith(".tar.gz") || resolvedArchivePath.endsWith(".tgz")) {
execSync(
`tar xzf ${JSON.stringify(resolvedArchivePath)} -C ${JSON.stringify(tempDir)}`,
{ stdio: "pipe" },
);
await tarExtract({ file: resolvedArchivePath, cwd: tempDir });
} else if (resolvedArchivePath.endsWith(".zip")) {
await extractZip(resolvedArchivePath, { dir: tempDir });
} else {