80 lines
3.2 KiB
JavaScript
80 lines
3.2 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { dirname, join } from "node:path";
|
|
import test from "node:test";
|
|
import { installCodingAgentConsumer, packReleasePackages, smokeTestCodingAgentConsumer } from "./coding-agent-consumer.mjs";
|
|
|
|
const codingAgentName = "@earendil-works/pi-coding-agent";
|
|
|
|
function createFixture(t, { importMissing = false } = {}) {
|
|
const root = mkdtempSync(join(tmpdir(), "pi-consumer-test-"));
|
|
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
const packages = [codingAgentName, "@earendil-works/chord"].map((name) => ({
|
|
name,
|
|
directory: join(root, "packages", name.split("/")[1]),
|
|
}));
|
|
for (const pkg of packages) {
|
|
const isAgent = pkg.name === codingAgentName;
|
|
const manifest = {
|
|
name: pkg.name,
|
|
version: "1.0.0",
|
|
type: "module",
|
|
exports: isAgent ? { ".": "./dist/index.js" } : "./dist/index.js",
|
|
...(isAgent
|
|
? {
|
|
bin: { pi: "dist/bundle/cli.js" },
|
|
dependencies: { "@earendil-works/chord": "1.0.0" },
|
|
}
|
|
: {}),
|
|
};
|
|
const files = {
|
|
"package.json": JSON.stringify(manifest),
|
|
"dist/index.js": isAgent
|
|
? `
|
|
${importMissing ? 'import "@earendil-works/pi-missing";' : ""}
|
|
import { marker } from "@earendil-works/chord";
|
|
if (marker !== "local tarball") throw new Error("Wrong Chord artifact");
|
|
export function createAgentSession() {}
|
|
export class SessionManager { static inMemory() {} }
|
|
export class ModelRuntime { static create() {} }
|
|
`
|
|
: 'export const marker = "local tarball";',
|
|
...(isAgent
|
|
? {
|
|
"dist/cli.js": 'console.log("1.0.0");',
|
|
"dist/bundle/cli.js": 'console.log("1.0.0");',
|
|
}
|
|
: {}),
|
|
};
|
|
for (const [path, content] of Object.entries(files)) {
|
|
mkdirSync(dirname(join(pkg.directory, path)), { recursive: true });
|
|
writeFileSync(join(pkg.directory, path), content);
|
|
}
|
|
}
|
|
const tarballs = packReleasePackages(packages, join(root, "tarballs"));
|
|
const directory = join(root, "consumer");
|
|
installCodingAgentConsumer(directory, tarballs);
|
|
return directory;
|
|
}
|
|
|
|
// #9132: installing every tarball directly hid undeclared runtime imports.
|
|
test("installs only coding-agent directly and uses overrides only for declared runtime dependencies", (t) => {
|
|
const directory = createFixture(t);
|
|
const manifest = JSON.parse(readFileSync(join(directory, "package.json"), "utf8"));
|
|
assert.deepEqual(Object.keys(manifest.dependencies), [codingAgentName]);
|
|
assert.ok(manifest.overrides["@earendil-works/chord"]);
|
|
assert.equal(existsSync(join(directory, "node_modules", "@earendil-works/chord")), true);
|
|
smokeTestCodingAgentConsumer(directory);
|
|
|
|
const developmentOnly = join(directory, "node_modules", codingAgentName, "dist/cli/experimental");
|
|
mkdirSync(developmentOnly, { recursive: true });
|
|
assert.throws(() => smokeTestCodingAgentConsumer(directory), /contains development-only code/);
|
|
});
|
|
|
|
// #9132: smoke-test the public SDK, not just a bundled CLI that hides missing imports.
|
|
test("fails when the SDK imports an undeclared package despite a working CLI", (t) => {
|
|
const directory = createFixture(t, { importMissing: true });
|
|
assert.throws(() => smokeTestCodingAgentConsumer(directory), /Cannot find package '@earendil-works\/pi-missing'/);
|
|
});
|