Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
fix(ci): make daemon packaging tests portable (#465)
Genera6d401783499
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex e68226718..45fbaa326 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -106,6 +106,9 @@ jobs:steps:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7- uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6+ - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2+ with:+ bun-version: 1.3.11- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7with:node-version: 22@@ -129,6 +132,9 @@ jobs:steps:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7- uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6+ - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2+ with:+ bun-version: 1.3.11- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7with:node-version: 22@@ -227,6 +233,9 @@ jobs:steps:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7- uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6+ - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2+ with:+ bun-version: 1.3.11- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7with:node-version: 22diff --git a/scripts/ci/workflow-contract.test.ts b/scripts/ci/workflow-contract.test.tsindex 7152cd9ed..8ded7ef89 100644--- a/scripts/ci/workflow-contract.test.ts+++ b/scripts/ci/workflow-contract.test.ts@@ -3,10 +3,21 @@ import { resolve } from "node:path"import { describe, expect, it } from "vitest"const workflowRoot = resolve(import.meta.dirname, "../../.github/workflows")-const workflow = readFileSync(resolve(workflowRoot, "e2e-ui.yml"), "utf8")-const ciWorkflow = readFileSync(resolve(workflowRoot, "ci.yml"), "utf8")+function normalizeWorkflow(text: string): string {+ return text.replace(/\r\n/g, "\n")+}++const workflow = normalizeWorkflow(readFileSync(resolve(workflowRoot, "e2e-ui.yml"), "utf8"))+const ciWorkflow = normalizeWorkflow(readFileSync(resolve(workflowRoot, "ci.yml"), "utf8"))const publishWorkflows = ["publish-app.yml", "publish-cli.yml", "publish-daemon.yml"]- .map((name) => readFileSync(resolve(workflowRoot, name), "utf8"))+ .map((name) => normalizeWorkflow(readFileSync(resolve(workflowRoot, name), "utf8")))++function ciJob(name: string): string {+ const start = ciWorkflow.indexOf(`\n ${name}:\n`)+ if (start < 0) throw new Error(`missing CI job: ${name}`)+ const next = ciWorkflow.slice(start + 1).search(/\n [a-z][a-z0-9-]*:\n/)+ return next < 0 ? ciWorkflow.slice(start) : ciWorkflow.slice(start, start + 1 + next)+}describe("E2E UI workflow", () => {it("runs before merge without running on main pushes", () => {@@ -25,9 +36,17 @@ describe("E2E UI workflow", () => {})describe("Bun workflow setup", () => {- it("installs Bun only in the CI build job and pins every retained setup", () => {- expect(ciWorkflow.match(/oven-sh\/setup-bun/g)).toHaveLength(1)- expect(ciWorkflow).toContain("bun-version: 1.3.11")+ it("normalizes Windows checkout line endings before locating jobs", () => {+ expect(normalizeWorkflow("jobs:\r\n test-linux:\r\n")).toBe("jobs:\n test-linux:\n")+ })++ it("installs pinned Bun in every CI job that builds a daemon package fixture", () => {+ const bunJobs = ["test-linux", "test-windows", "build", "coverage"]+ expect(ciWorkflow.match(/oven-sh\/setup-bun/g)).toHaveLength(bunJobs.length)+ for (const job of bunJobs) {+ expect(ciJob(job)).toContain("oven-sh/setup-bun")+ expect(ciJob(job)).toContain("bun-version: 1.3.11")+ }for (const publishWorkflow of publishWorkflows) {expect(publishWorkflow).toContain("oven-sh/setup-bun")expect(publishWorkflow).toContain("bun-version: 1.3.11")diff --git a/src/daemon/src/cli/daemonSelfUpdate.real.test.ts b/src/daemon/src/cli/daemonSelfUpdate.real.test.tsindex 958b8b829..5442b8c6a 100644--- a/src/daemon/src/cli/daemonSelfUpdate.real.test.ts+++ b/src/daemon/src/cli/daemonSelfUpdate.real.test.ts@@ -6,6 +6,7 @@ import * as os from "node:os";import * as path from "node:path";import { fileURLToPath } from "node:url";import { WebSocket, WebSocketServer } from "ws";+import { commandShimShell, execPackageManagerSync } from "../test-package-manager.js";const packageRoot = fileURLToPath(new URL("../..", import.meta.url));const machineId = "cm_self_update_real_123456";@@ -48,7 +49,11 @@ function packFixture(version: string): string {"--ignore-scripts","--pack-destination",fixtureRoot,- ], { cwd: dir, encoding: "utf8" })) as Array<{ filename: string }>;+ ], {+ cwd: dir,+ encoding: "utf8",+ shell: commandShimShell(),+ })) as Array<{ filename: string }>;return path.join(fixtureRoot, packed[0]!.filename);}@@ -61,6 +66,7 @@ function runNpmPackage(execFile("npm", ["exec", "--yes", `--package=${tgz}`, "--", "alook-daemon", ...args], {env: { ...process.env, ...env },maxBuffer: 10 * 1024 * 1024,+ shell: commandShimShell(),}, (error, stdout, stderr) => {if (error && typeof (error as NodeJS.ErrnoException & { code?: unknown }).code !== "number") {reject(error);@@ -223,7 +229,7 @@ async function waitForUpdateSettled(baseDir: string, timeoutMs = 45_000): Promis}beforeAll(() => {- execFileSync("pnpm", ["run", "build"], { cwd: packageRoot, stdio: "pipe" });+ execPackageManagerSync(["run", "build"], { cwd: packageRoot, stdio: "pipe" });oldTgz = packFixture("9.9.0");newTgz = packFixture("9.9.1");}, 120_000);diff --git a/src/daemon/src/test-package-manager.test.ts b/src/daemon/src/test-package-manager.test.tsnew file mode 100644index 000000000..b6fd9ed4a--- /dev/null+++ b/src/daemon/src/test-package-manager.test.ts@@ -0,0 +1,61 @@+import { describe, expect, it } from "vitest";+import { commandShimShell, resolvePackageManagerCommand } from "./test-package-manager.js";++describe("resolvePackageManagerCommand", () => {+ it("runs a JavaScript lifecycle entrypoint through Node", () => {+ expect(resolvePackageManagerCommand(+ ["run", "build"],+ { npm_execpath: "C:\\tools\\pnpm.cjs" },+ "C:\\tools\\node.exe",+ "win32",+ )).toEqual({+ file: "C:\\tools\\node.exe",+ args: ["C:\\tools\\pnpm.cjs", "run", "build"],+ });+ });++ it("uses the Windows command shell for a pnpm cmd shim", () => {+ expect(resolvePackageManagerCommand(+ ["pack"],+ { npm_execpath: "C:\\tools\\pnpm.cmd" },+ "C:\\tools\\node.exe",+ "win32",+ )).toEqual({+ file: "C:\\tools\\pnpm.cmd",+ args: ["pack"],+ shell: true,+ });+ });++ it("runs a native lifecycle executable directly", () => {+ expect(resolvePackageManagerCommand(+ ["pack"],+ { npm_execpath: "/tools/pnpm" },+ "/tools/node",+ "linux",+ )).toEqual({+ file: "/tools/pnpm",+ args: ["pack"],+ });+ });++ it("uses a shell-backed PATH fallback on Windows", () => {+ expect(resolvePackageManagerCommand(["pack"], {}, "C:\\tools\\node.exe", "win32")).toEqual({+ file: "pnpm",+ args: ["pack"],+ shell: true,+ });+ });++ it("uses a direct PATH fallback on POSIX", () => {+ expect(resolvePackageManagerCommand(["pack"], {}, "/tools/node", "linux")).toEqual({+ file: "pnpm",+ args: ["pack"],+ });+ });++ it("shell-enables command shims only on Windows", () => {+ expect(commandShimShell("win32")).toBe(true);+ expect(commandShimShell("linux")).toBeUndefined();+ });+});diff --git a/src/daemon/src/test-package-manager.ts b/src/daemon/src/test-package-manager.tsnew file mode 100644index 000000000..2f107976b--- /dev/null+++ b/src/daemon/src/test-package-manager.ts@@ -0,0 +1,47 @@+import { execFileSync, type ExecFileSyncOptions } from "node:child_process";+import { extname } from "node:path";++export interface PackageManagerCommand {+ file: string;+ args: string[];+ shell?: true;+}++export function commandShimShell(platform = process.platform): true | undefined {+ return platform === "win32" ? true : undefined;+}++export function resolvePackageManagerCommand(+ args: string[],+ env: NodeJS.ProcessEnv = process.env,+ nodeExecutable = process.execPath,+ platform = process.platform,+): PackageManagerCommand {+ const npmExecPath = env.npm_execpath;+ if (!npmExecPath) {+ const shell = commandShimShell(platform);+ return shell+ ? { file: "pnpm", args, shell }+ : { file: "pnpm", args };+ }++ const extension = extname(npmExecPath).toLowerCase();+ if ([".js", ".cjs", ".mjs"].includes(extension)) {+ return { file: nodeExecutable, args: [npmExecPath, ...args] };+ }+ if (platform === "win32" && [".bat", ".cmd"].includes(extension)) {+ return { file: npmExecPath, args, shell: commandShimShell(platform) };+ }+ return { file: npmExecPath, args };+}++export function execPackageManagerSync(+ args: string[],+ options: ExecFileSyncOptions,+): Buffer | string {+ const command = resolvePackageManagerCommand(args);+ return execFileSync(command.file, command.args, {+ ...options,+ shell: command.shell,+ });+}diff --git a/src/daemon/src/version.packed.test.ts b/src/daemon/src/version.packed.test.tsindex 986489969..2038afd4e 100644--- a/src/daemon/src/version.packed.test.ts+++ b/src/daemon/src/version.packed.test.ts@@ -6,6 +6,7 @@ import { join } from "node:path";import { promisify } from "node:util";import { fileURLToPath } from "node:url";import { afterEach, describe, expect, it } from "vitest";+import { execPackageManagerSync } from "./test-package-manager.js";const execFileAsync = promisify(execFile);const packageRoot = fileURLToPath(new URL("../", import.meta.url));@@ -24,12 +25,8 @@ describe("packed daemon version", () => {it("reports the root package version from the real dist/cli bin", { timeout: 120_000 }, async () => {const root = mkdtempSync(join(tmpdir(), "alook-daemon-version-pack-"));tempRoots.push(root);- const npmExecPath = process.env.npm_execpath;- if (!npmExecPath) throw new Error("npm_execpath is required to build the packed daemon fixture");-- await execFileAsync(- process.execPath,- [npmExecPath, "pack", "--pack-destination", root],+ execPackageManagerSync(+ ["pack", "--pack-destination", root],{ cwd: packageRoot, maxBuffer: 10 * 1024 * 1024 },);const tarball = readdirSync(root).find((name) => name.endsWith(".tgz"));