repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

test(pi): add mux harness and MiniMax/web tool tests

21571990486593843c898288400c560455fea18b

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (6)

pi/agent/bun.lock

Modified
80 80 "@bugabinga/pi-lib": "workspace:*",
82 82 "devDependencies": {
83 + "@marcfargas/pi-test-harness": ">=0.1.0",
83 84 "@mariozechner/pi-ai": "^0.72.1",
84 85 "@mariozechner/pi-coding-agent": "^0.72.1",
165 166 "dependencies": {
166 167 "@bugabinga/pi-lib": "workspace:*",
169 + "devDependencies": {
170 + "@marcfargas/pi-test-harness": ">=0.1.0",
171 + "@mariozechner/pi-coding-agent": "^0.72.1",
172 + "@mariozechner/pi-tui": "^0.72.1",
173 + "@sinclair/typebox": "latest",
174 + },
169 176 "lib": {
170 177 "name": "@bugabinga/pi-lib",

pi/agent/extensions/mux/__tests__/harness.test.ts

Added
new file mode 100644
1 +import { afterEach, describe, expect, it } from "bun:test";
2 +import path from "node:path";
3 +import { createTestSession, type TestSession } from "@marcfargas/pi-test-harness";
5 +describe("mux extension harness", () => {
6 + let t: TestSession | undefined;
7 + afterEach(() => t?.dispose());
9 + it("loads only mux extension", async () => {
10 + const muxPath = path.resolve(import.meta.dir, "../index.ts");
11 + t = await createTestSession({ extensions: [muxPath] });
13 + const loaded = t.session.extensionRunner.extensions.map((e: { path: string }) => e.path);
14 + expect(loaded).toEqual([muxPath]);
15 + });
17 + it("registers /mux command", async () => {
18 + const muxPath = path.resolve(import.meta.dir, "../index.ts");
19 + t = await createTestSession({ extensions: [muxPath] });
21 + const [extension] = t.session.extensionRunner.extensions;
22 + expect([...extension.commands.keys()]).toContain("mux");
23 + });
24 +});

pi/agent/extensions/mux/package.json

Modified
6 6 "main": "index.ts",
7 7 "scripts": {
8 8 "test": "bun test ./__tests__/*.test.ts",
9 - "test:watch": "bun test ./__tests__/*.test.ts --watch"
9 + "test:watch": "bun test ./__tests__/*.test.ts --watch",
10 + "test:harness": "bun test ./__tests__/harness.test.ts"
11 12 "dependencies": {
12 13 "@bugabinga/pi-lib": "workspace:*"
14 15 "devDependencies": {
16 + "@marcfargas/pi-test-harness": ">=0.1.0",
15 17 "@mariozechner/pi-ai": "^0.72.1",
16 18 "@mariozechner/pi-coding-agent": "^0.72.1"

pi/agent/extensions/web/__tests__/harness.test.ts

Added
new file mode 100644
1 +import { afterEach, describe, expect, it } from "bun:test";
2 +import path from "node:path";
3 +import { createTestSession, type TestSession } from "@marcfargas/pi-test-harness";
5 +describe("web extension harness", () => {
6 + let t: TestSession | undefined;
7 + afterEach(() => t?.dispose());
9 + it("registers web_fetch, web_search, and understand_image tools", async () => {
10 + const webPath = path.resolve(import.meta.dir, "../index.ts");
11 + t = await createTestSession({ extensions: [webPath] });
13 + const [extension] = t.session.extensionRunner.extensions;
14 + expect([...extension.tools.keys()]).toContain("web_fetch");
15 + expect([...extension.tools.keys()]).toContain("web_search");
16 + expect([...extension.tools.keys()]).toContain("understand_image");
17 + });
18 +});

pi/agent/extensions/web/__tests__/minimax.test.ts

Added
new file mode 100644
1 +import { afterEach, describe, expect, it } from "bun:test";
2 +import {
3 + isMinimaxAvailable,
4 + minimaxSearch,
5 + minimaxUnderstandImage,
6 + resolveMinimaxApiKey,
7 + resolveMinimaxBaseUrl,
8 +} from "../minimax.ts";
10 +type FetchCall = { url: string; init: RequestInit; body?: Record<string, unknown> };
12 +function ctx(apiKey = "mm-key", baseUrl = "https://api.minimax.io/anthropic") {
13 + return {
14 + modelRegistry: {
15 + getApiKeyForProvider: async (provider: string) => provider === "minimax" ? apiKey : undefined,
16 + getAll: () => [{ provider: "minimax", baseUrl }],
17 + },
18 + } as any;
21 +function ctxWithoutKey() {
22 + return {
23 + modelRegistry: {
24 + getApiKeyForProvider: async () => undefined,
25 + getAll: () => [],
26 + },
27 + } as any;
30 +function installJsonFetch(calls: FetchCall[], response: unknown, ok = true) {
31 + const prev = globalThis.fetch;
32 + globalThis.fetch = (async (url: string | URL | Request, init?: RequestInit) => {
33 + const body = init?.body ? JSON.parse(String(init.body)) : undefined;
34 + calls.push({ url: String(url), init: init ?? {}, body });
35 + return {
36 + ok,
37 + status: ok ? 200 : 500,
38 + statusText: ok ? "OK" : "ERR",
39 + json: async () => response,
40 + } as Response;
41 + }) as typeof fetch;
42 + return () => { globalThis.fetch = prev; };
45 +describe("minimax client", () => {
46 + let restoreFetch: (() => void) | undefined;
47 + afterEach(() => restoreFetch?.());
49 + it("resolves API key through model registry", async () => {
50 + expect(await resolveMinimaxApiKey(ctx("abc"))).toBe("abc");
51 + expect(await isMinimaxAvailable(ctx("abc"))).toBe(true);
52 + expect(await isMinimaxAvailable(ctxWithoutKey())).toBe(false);
53 + });
55 + it("normalizes anthropic provider base URL to /v1 endpoints", async () => {
56 + const calls: FetchCall[] = [];
57 + restoreFetch = installJsonFetch(calls, {
58 + organic: [],
59 + related_searches: [],
60 + base_resp: { status_code: 0, status_msg: "ok" },
61 + });
63 + await minimaxSearch("pi docs", ctx("key", "https://api.minimax.io/anthropic"));
65 + expect(calls[0]?.url).toBe("https://api.minimax.io/v1/coding_plan/search");
66 + expect(calls[0]?.body).toEqual({ q: "pi docs" });
67 + expect((calls[0]?.init.headers as Record<string, string>).Authorization).toBe("Bearer key");
68 + });
70 + it("returns configured MiniMax model base URL", () => {
71 + expect(resolveMinimaxBaseUrl(ctx("key", "https://example.test/v1"))).toBe("https://example.test/v1");
72 + });
74 + it("understand_image posts data URLs to MiniMax VLM", async () => {
75 + const calls: FetchCall[] = [];
76 + restoreFetch = installJsonFetch(calls, {
77 + content: "a cat",
78 + base_resp: { status_code: 0, status_msg: "ok" },
79 + });
81 + const result = await minimaxUnderstandImage("describe", "data:image/png;base64,abc", ctx("key", "https://api.minimax.io"));
83 + expect(result).toBe("a cat");
84 + expect(calls[0]?.url).toBe("https://api.minimax.io/v1/coding_plan/vlm");
85 + expect(calls[0]?.body).toEqual({ prompt: "describe", image_url: "data:image/png;base64,abc" });
86 + });
87 +});

pi/agent/extensions/web/package.json

Modified
5 5 "name": "@bugabinga/pi-ext-web",
6 6 "version": "0.1.0",
7 7 "private": true,
8 8 "type": "module",
9 9 "main": "index.ts",
10 + "scripts": {
11 + "test": "bun test ./__tests__/*.test.ts",
12 + "test:watch": "bun test ./__tests__/*.test.ts --watch",
13 + "test:harness": "bun test ./__tests__/harness.test.ts"
14 + },
10 15 "dependencies": {
11 16 "@bugabinga/pi-lib": "workspace:*"
17 + },
18 + "devDependencies": {
19 + "@marcfargas/pi-test-harness": ">=0.1.0",
20 + "@mariozechner/pi-coding-agent": "^0.72.1",
21 + "@mariozechner/pi-tui": "^0.72.1",
22 + "@sinclair/typebox": "latest"