51 lines
2.4 KiB
TypeScript
51 lines
2.4 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { Host } from "@opencode/plugin/host";
|
|
import { build } from "../scripts/build.js";
|
|
import { install } from "../scripts/install.js";
|
|
|
|
test("packed package has independent native plugins and quota-only TUI discovery", async () => {
|
|
const directory = await mkdtemp(join(tmpdir(), "plugin-package-"));
|
|
try {
|
|
await build();
|
|
const archive = join(directory, "stanp-opencode.tgz");
|
|
const pack = Bun.spawn([process.execPath, "pm", "pack", "--filename", archive], {
|
|
stdout: "pipe",
|
|
stderr: "pipe",
|
|
});
|
|
const output = new Response(pack.stderr).text();
|
|
expect(await pack.exited, await output).toBe(0);
|
|
const unpack = Bun.spawn(["tar", "-xzf", archive, "-C", directory], {
|
|
stdout: "ignore",
|
|
stderr: "pipe",
|
|
});
|
|
expect(await unpack.exited).toBe(0);
|
|
const source = join(directory, "package");
|
|
const manifest = await Bun.file(join(source, "package.json")).json();
|
|
expect(manifest.exports["."]).toBeUndefined();
|
|
expect(await Bun.file(join(source, "index.js")).exists()).toBe(false);
|
|
expect(await Bun.file(join(source, "dist", "index.js")).exists()).toBe(false);
|
|
for (const name of ["agents", "multi-work", "quota", "optchat"]) {
|
|
const entrypoint = join(source, manifest.exports[`./${name}`].import);
|
|
const { default: plugin } = await import(entrypoint);
|
|
expect(plugin.id).toBe(`stanp-opencode.${name}`);
|
|
}
|
|
const config = join(directory, "config");
|
|
await mkdir(config);
|
|
await install(source, config, "agents,multi-work,quota,optchat");
|
|
for (const name of ["agents", "multi-work", "quota", "optchat"]) {
|
|
const entries = Host.resolve({
|
|
directory: join(config, "plugins", "stanp-opencode", name),
|
|
});
|
|
expect(entries.server).toBeDefined();
|
|
expect(entries.tui !== undefined).toBe(name === "quota");
|
|
}
|
|
const { QuotaRpc } = await import(join(source, manifest.exports["./quota-rpc"].import));
|
|
expect(QuotaRpc.id).toBe("stanp-opencode.quota");
|
|
} finally {
|
|
await rm(directory, { recursive: true, force: true });
|
|
}
|
|
}, 30_000);
|