Skip to content

Commit 64968e5

Browse files
test(cli): make code-pack + setup-scip tests host-agnostic (#154)
## Summary Two `@opencodehub/cli` tests baked in host-environment assumptions and failed on macOS (they pass on Linux CI, so they were latent). Surfaced while validating an unrelated dep bump on a Mac. **Test-only — no production code changes.** ## The two fixes **1. `code-pack` — "resolves a relative repo path against process.cwd()"** The test asserted `opts.repoPath === resolve(cwd)` where `cwd` came from `mkdtemp(tmpdir(), ...)`. On macOS `tmpdir()` returns `/tmp/...`, but `/tmp` is a symlink to `/private/tmp`, so after `process.chdir(cwd)` the production code resolves against `process.cwd()` → `/private/tmp/...`. The assertion compared `/private/tmp/...` (actual) vs `/tmp/...` (expected) and failed. → Read `process.cwd()` back after `chdir` and assert against that — exactly what the production code sees. **2. `setup-scip` — "installs a single tool via injected fetch + allowPlaceholder"** The test hard-coded a `{ os: "linux", arch: "x64" }` platform pin (comment even said "the test runs on AL2023 which is already linux-x64"). On darwin/arm64 the downloader's `detectPlatform()` found no matching platform entry, installed 0 tools, and `result.installed.length` was `0 !== 1`. → Build the pin from `detectPlatform()` so it matches whatever host runs the test — linux-x64 in CI, darwin-arm64 on a dev Mac. ## Why now Both failures reproduce on a clean `main` checkout in a macOS sandbox (verified against the clean `origin/main` worktree). They're invisible in CI (Linux, no `/tmp` symlink, host is linux-x64), so they only bite local Mac development. This removes the host assumption. ## Verification - `pnpm --filter @opencodehub/cli test` — **256/256 pass** (was 254 pass / 2 fail) - Full pre-push gate (`pnpm -r test` recursive + typecheck + verdict) — green - Banned-strings patterns checked manually against the diff (clean); local hook can't run (needs bash 4+, macOS ships 3.2) ## Test plan - [x] Both tests pass on macOS arm64 - [x] Logic preserves the linux-x64 path (CI host) via `detectPlatform()` - [x] No production code touched
1 parent 7d0c41b commit 64968e5

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

packages/cli/src/commands/code-pack.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,19 @@ test("runCodePack engine='pack' resolves a relative repo path against process.cw
138138
const original = process.cwd();
139139
try {
140140
process.chdir(cwd);
141+
// After chdir, read the cwd back: on macOS `tmpdir()` yields `/tmp/...`
142+
// but `/tmp` is a symlink to `/private/tmp`, so `process.cwd()` (and the
143+
// production code that resolves against it) returns the realpath form.
144+
// Assert against that, not the raw mkdtemp string, or the comparison is
145+
// a symlink artifact rather than a real check.
146+
const resolvedCwd = process.cwd();
141147
const fakeGenerate = (async (
142148
opts: { repoPath: string; outDir: string; budgetTokens: number; tokenizerId: string },
143149
_internal: unknown,
144150
) => {
145151
// The point of this test is to assert the resolved repo path equals
146152
// the absolute form of the cwd, NOT a relative `./` form.
147-
assert.equal(opts.repoPath, resolve(cwd));
153+
assert.equal(opts.repoPath, resolvedCwd);
148154
await mkdir(opts.outDir, { recursive: true });
149155
await writeFile(join(opts.outDir, "manifest.json"), "{}");
150156
return makeFakeManifest({ packHash: "1234" });
@@ -157,7 +163,7 @@ test("runCodePack engine='pack' resolves a relative repo path against process.cw
157163
});
158164

159165
assert.equal(result.engine, "pack");
160-
assert.equal(result.outDir, resolve(cwd, ".codehub", "packs", "1234"));
166+
assert.equal(result.outDir, resolve(resolvedCwd, ".codehub", "packs", "1234"));
161167
} finally {
162168
process.chdir(original);
163169
await rm(cwd, { recursive: true, force: true });

packages/cli/src/commands/setup.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { test } from "node:test";
88
import { fileURLToPath } from "node:url";
99
import * as TOML from "@iarna/toml";
1010
import type { EditorId } from "../editors/types.js";
11-
import type { FetchFn as ScipFetchFn } from "../scip-downloader.js";
11+
import { detectPlatform, type FetchFn as ScipFetchFn } from "../scip-downloader.js";
1212
import {
1313
type FsApi,
1414
parseScipFlag,
@@ -439,14 +439,19 @@ test("runSetupScip installs a single tool via injected fetch + allowPlaceholder"
439439
type Pin = (typeof pinsModule.SCIP_PINS)["clang"];
440440
const mutable = pinsModule.SCIP_PINS as unknown as { clang: Pin };
441441
const original: Pin = mutable.clang;
442+
// Pin the platform entry to the ACTUAL host (detectPlatform reads
443+
// process.platform/arch) so the downloader finds a match wherever the
444+
// test runs — linux-x64 in CI, darwin-arm64 on a dev Mac. Hard-coding
445+
// linux-x64 made this test silently install nothing (0 tools) on macOS.
446+
const host = detectPlatform();
442447
mutable.clang = {
443448
tool: original.tool,
444449
version: original.version,
445450
installerKind: original.installerKind,
446451
binName: original.binName,
447452
placeholder: false,
448453
platforms: [
449-
{ os: "linux", arch: "x64", url: "https://example.test/clang", sha256: expected },
454+
{ os: host.os, arch: host.arch, url: "https://example.test/clang", sha256: expected },
450455
],
451456
};
452457
try {
@@ -462,8 +467,6 @@ test("runSetupScip installs a single tool via injected fetch + allowPlaceholder"
462467
});
463468
};
464469
const logs: string[] = [];
465-
// Force linux-x64 platform selection via the downloader internals — the
466-
// test runs on AL2023 which is already linux-x64, so this is a no-op.
467470
const result = await runSetupScip({
468471
tool: "clang",
469472
destDir: dir,

0 commit comments

Comments
 (0)