Files
PerishFire 0688faaec3 reland(sidecar): converge product clients on package boundary (#7636)
* reland(sidecar): converge product clients after weekly release

Restore the sidecar convergence from #7244 after the release-scheduling revert in #7634. This tree matches the previously reviewed and cross-platform QA-accepted implementation at d83d4e032f.

* fix(sidecar): clarify identity and cache witnesses

Generated-By: looper 0.11.2 (runner=fixer, agent=codex)

* fix(packaged): probe cross-source desktop owners

Generated-By: looper 0.11.2 (runner=fixer, agent=codex)

* fix(sidecar): preserve cross-source launch ownership

Generated-By: looper 0.11.2 (runner=fixer, agent=codex)

* test(pack): assert cross-source Windows launch ownership

Generated-By: looper 0.11.2 (runner=fixer, agent=codex)

* fix(sidecar): align HyperFrames with client boundary

Generated-By: looper 0.11.2 (runner=fixer, agent=codex)

* fix(e2e): keep HyperFrames fixture in helper lane

Generated-By: looper 0.11.2 (runner=fixer, agent=codex)

* docs(sidecar): restore review and handoff contracts

Generated-By: looper 0.11.2 (runner=fixer, agent=codex)

* fix(sidecar): restore cache and daemon boundaries

Generated-By: looper 0.11.2 (runner=fixer, agent=codex)

* fix(pack): restore sourcemaps and Linux smoke discovery

Generated-By: looper 0.11.2 (runner=fixer, agent=codex)

* fix(sidecar): make payload handoff generation-atomic

* fix(sidecar): preserve packaged action and mode parity

Generated-By: looper 0.11.2 (runner=fixer, agent=codex)

* test(pack): align Linux cleanup resource count

Generated-By: looper 0.11.2 (runner=fixer, agent=codex)

* fix(packaged): preserve headless sidecar mode

* test: normalize source line endings

* fix(daemon): launch Codex cmd shims on Windows

---------

Co-authored-by: Looper <looper@noreply.github.com>
2026-09-01 13:22:04 +00:00

165 lines
5.3 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import {
acquirePackagedHeadlessStartup,
parsePackagedHeadlessRequest,
resolvePackagedMcpBootstrapLaunch,
runPackagedMcpActionAgainstExistingDaemon,
} from "../src/headless-runtime.js";
import { APP_KEYS, SIDECAR_SOURCES } from "@open-design/sidecar-proto";
describe("parsePackagedHeadlessRequest", () => {
it("accepts a headless Codex MCP install request", () => {
expect(parsePackagedHeadlessRequest([
"--headless",
"--mcp-install",
"codex",
])).toEqual({
headless: true,
mcpInstallAgent: "codex",
});
});
it("rejects unsupported MCP install targets", () => {
expect(() => parsePackagedHeadlessRequest([
"--headless",
"--mcp-install",
"claude",
])).toThrow(/only supports codex/i);
});
});
describe("resolvePackagedMcpBootstrapLaunch", () => {
it("uses macOS open against the stable signed app bundle", () => {
expect(resolvePackagedMcpBootstrapLaunch({
currentExecutablePath:
"/private/payload/Open Design.app/Contents/MacOS/Open Design",
installedLaunchPath: "/Applications/Open Design.app",
platform: "darwin",
})).toEqual({
command: "/usr/bin/open",
args: [
"-g",
"-j",
"/Applications/Open Design.app",
"--args",
"--headless",
],
});
});
it("invokes a non-macOS installed launcher directly", () => {
expect(resolvePackagedMcpBootstrapLaunch({
currentExecutablePath: "/tmp/payload/open-design",
installedLaunchPath: "/opt/open-design/open-design",
platform: "linux",
})).toEqual({
command: "/opt/open-design/open-design",
args: ["--headless"],
});
});
});
describe("runPackagedMcpActionAgainstExistingDaemon", () => {
const launchStamp = {
app: APP_KEYS.DESKTOP,
channel: "beta",
mode: "headless",
namespace: "release-beta",
source: "packaged",
} as const;
it("installs through a healthy existing headless daemon without bootstrapping", async () => {
const installMcp = vi.fn(async () => undefined);
const getStatus = vi.fn(async () => ({
state: "running",
url: "http://127.0.0.1:7457",
}));
await expect(runPackagedMcpActionAgainstExistingDaemon(
{ headless: true, mcpInstallAgent: "codex" },
launchStamp,
{ getStatus: getStatus as never, installMcp },
)).resolves.toBe(true);
expect(getStatus).toHaveBeenCalledWith(
{ ...launchStamp, app: APP_KEYS.DAEMON },
{ timeoutMs: 350 },
);
expect(installMcp).toHaveBeenCalledWith("http://127.0.0.1:7457");
});
it("leaves bootstrap to the caller when no healthy daemon exists", async () => {
const installMcp = vi.fn(async () => undefined);
await expect(runPackagedMcpActionAgainstExistingDaemon(
{ headless: true, mcpInstallAgent: "codex" },
launchStamp,
{
getStatus: vi.fn(async () => ({ state: "stopped", url: "http://127.0.0.1:7457" })) as never,
installMcp,
},
)).resolves.toBe(false);
expect(installMcp).not.toHaveBeenCalled();
});
it("finds a packaged-source daemon for a tools-pack request", async () => {
const installMcp = vi.fn(async () => undefined);
const getStatus = vi.fn(async (candidate: { source: string }) => candidate.source === SIDECAR_SOURCES.PACKAGED
? { state: "running", url: "http://127.0.0.1:7457" }
: Promise.reject(new Error("missing endpoint")));
await expect(runPackagedMcpActionAgainstExistingDaemon(
{ headless: true, mcpInstallAgent: "codex" },
{ ...launchStamp, source: SIDECAR_SOURCES.TOOLS_PACK },
{ getStatus: getStatus as never, installMcp },
)).resolves.toBe(true);
expect(getStatus.mock.calls.map(([candidate]) => candidate.source)).toEqual([
SIDECAR_SOURCES.TOOLS_PACK,
SIDECAR_SOURCES.PACKAGED,
]);
expect(installMcp).toHaveBeenCalledWith("http://127.0.0.1:7457");
});
});
describe("acquirePackagedHeadlessStartup", () => {
function createDependencies(failAt: "mcp" | "none") {
const closed: string[] = [];
return {
closed,
dependencies: {
confirmRuntime: vi.fn(async () => undefined),
installMcp: vi.fn(async () => {
if (failAt === "mcp") throw new Error("MCP install failed");
}),
startSidecars: vi.fn(async () => ({
close: async () => {
closed.push("sidecars");
},
currentWebUrl: () => "http://127.0.0.1:7456",
daemon: {
desktopAuthGateActive: false,
state: "running" as const,
url: "http://127.0.0.1:7457",
},
web: { state: "running" as const, url: "http://127.0.0.1:7456" },
})),
},
};
}
it("closes sidecars when MCP installation fails", async () => {
const { closed, dependencies } = createDependencies("mcp");
await expect(acquirePackagedHeadlessStartup(dependencies)).rejects.toThrow(
"MCP install failed",
);
expect(closed).toEqual(["sidecars"]);
});
it("returns a shutdown handle that closes sidecars", async () => {
const { closed, dependencies } = createDependencies("none");
const handle = await acquirePackagedHeadlessStartup(dependencies);
await handle.shutdown();
expect(closed).toEqual(["sidecars"]);
});
});