Files
AgentCompany/tests/unit/ipc-core-admin-handlers.test.ts
T
ZacharyZhang-NY c71d033b0c refactor: prune dead IPC surface and orphaned modules
Drop code that nothing consumed. Verified by full renderer+shared grep:
every removed channel had zero callers via window.agentCompany.* and
zero references from desktop-api types. No backend internal use either —
the database/API-server layers keep their methods, only the IPC exposure
goes.

Removed IPC handlers (26 total):

  Thread CRUD surface (12) — writes happen inside the backend
    createThread, listThreads, addThreadEvent,
    setThreadWaitState, resolveThreadWaitState,
    addParticipant, removeParticipant, listParticipants,
    subscribeThread, unsubscribeThread,
    listSubscriptions, listSubscribedThreads
    (kept reads: getThread, listThreadEvents, listThreadWaitStates)

  Half-implemented features (13)
    saveSecret, listComments, getAgentMetrics, getApiPort,
    listWakeupRequests, listAgentMessages, autoAssignTask,
    listRunEvents, recoveryDismiss,
    getHeartbeatPolicy, setHeartbeatPolicy,
    getRuntimeState, setRuntimeState

  Whole vertical slice: openConnectorAuthTerminal
    IPC handler + channel + preload + DesktopApi type +
    connector-auth-service function + useConnectorCallbacks
    handleLoginConnector + OnboardingContext.onLoginConnector +
    OnboardingWizard wiring. Pi-mono has no CLI auth flow;
    the no-op that "returned false for legacy UI compatibility"
    had no legacy UI left.

Orphaned modules (zero importers in repo):
  src/main/runtime-env.ts
  src/main/database-stale-recovery.ts

Dead schema files (only referenced by their own barrel re-export):
  schemas-participants, schemas-subscriptions, schemas-heartbeat,
  schemas-run-events, schemas-runtime-state, schemas-wakeup

Renderer leftovers:
  .activity-row-enter CSS + its two unreferenced keyframes
  5 orphan i18n keys (app.console, app.refresh, app.expand,
  activity.timeline, auto.trigger) left over from earlier feature
  deletions

Also update two unit tests that mocked openConnectorAuthTerminal in
the RegisterCoreHandlersDependencies pick.
2026-04-17 22:38:10 -04:00

82 lines
2.7 KiB
TypeScript

import { mkdtemp, rm } from "node:fs/promises";
import { join } from "node:path";
import { tmpdir } from "node:os";
import { afterEach, describe, expect, it, vi } from "vitest";
import type { IpcMainInvokeEvent } from "electron";
import type { DesktopResult } from "@shared/contracts";
import { IPC_CHANNELS } from "@shared/contracts";
import { AppDatabase } from "../../src/main/database";
import { registerCoreAdminHandlers } from "../../src/main/ipc-core-admin-handlers";
type IpcHandler = (
event: IpcMainInvokeEvent,
...args: unknown[]
) => Promise<DesktopResult<unknown>> | DesktopResult<unknown>;
const tempDirs: string[] = [];
async function createTempDir(prefix: string) {
const dir = await mkdtemp(join(tmpdir(), prefix));
tempDirs.push(dir);
return dir;
}
afterEach(async () => {
await Promise.all(tempDirs.splice(0).map((dir) => rm(dir, { recursive: true, force: true })));
});
describe("ipc-core-admin-handlers connector saves", () => {
it("accepts a valid pi-ai model for a pi-mono connector", async () => {
const profileDir = await createTempDir("agentcompany-admin-handler-");
const db = new AppDatabase(profileDir);
db.init();
const { getModels } = await import("@mariozechner/pi-ai");
const anthropicModel = getModels("anthropic" as never)[0]?.id;
if (!anthropicModel) {
throw new Error("pi-ai anthropic provider must expose at least one model.");
}
const handlers = new Map<string, IpcHandler>();
registerCoreAdminHandlers({
registerHandle: (channel, handler) => {
handlers.set(channel, handler);
},
db,
ensureCompanyExists: () => null,
publishDomainChanged: vi.fn(),
handleApprovalResolved: vi.fn(),
checkConnector: vi.fn(),
openGenericTerminal: vi.fn(),
});
const saveConnector = handlers.get(IPC_CHANNELS.saveConnector);
if (!saveConnector) {
throw new Error("saveConnector handler was not registered.");
}
// Pi-mono connectors default to an empty command; the schema requires a
// non-empty one, so seed it before hitting the IPC handler.
db.saveConnector({
id: "anthropic",
command: "pi-mono",
model: null,
envBindingText: "",
notes: "",
});
const result = await saveConnector(null as unknown as IpcMainInvokeEvent, {
id: "anthropic",
command: "pi-mono",
model: anthropicModel,
envBindingText: "ANTHROPIC_BASE_URL=https://example.com/anthropic",
notes: "Pi-mono connector",
}) as { ok: boolean; error?: { code: string; message: string } };
expect(result.ok).toBe(true);
expect(db.getConnector("anthropic").model).toBe(anthropicModel);
db.close();
});
});