Files
seal-use/scripts/dev-override.test.ts
gitea a189f49223 Group core utility modules into util, skill, and update
Move duration, redact, runtime, secure-file, and semver under core/util; embedded-skill and skill-version under core/skill; update-cache under core/update. Move the dev-override test next to the script it covers, and update the embedded-skill generator output path and regenerated manifest. No behavior change.
2026-11-19 16:31:50 +08:00

44 lines
2.0 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import { chmodSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { resolveTargetBinaryPath } from "./dev-override.js";
describe("development CLI install target", () => {
test("npm-linked source is never selected as the binary replacement target", () => {
const dir = mkdtempSync(join(tmpdir(), "seal-dev-target-test-"));
const originalPath = process.env.PATH;
try {
const command = join(dir, "seal-use");
const source = join(dir, "cli.ts");
writeFileSync(source, "#!/usr/bin/env bun\nconsole.log('source fixture')\n");
chmodSync(source, 0o755);
symlinkSync(source, command);
process.env.PATH = `${dir}${process.platform === "win32" ? ";" : ":"}${originalPath ?? ""}`;
expect(resolveTargetBinaryPath()).toBe(command);
expect(readFileSync(source, "utf8")).toContain("source fixture");
} finally {
if (originalPath === undefined) delete process.env.PATH; else process.env.PATH = originalPath;
rmSync(dir, { recursive: true, force: true });
}
});
test("native command symlinks continue to replace the installed target", () => {
const dir = mkdtempSync(join(tmpdir(), "seal-dev-target-test-"));
const originalPath = process.env.PATH;
try {
const command = join(dir, "seal-use");
mkdirSync(join(dir, "formula"));
const target = join(dir, "formula", "seal-use");
writeFileSync(target, "native binary fixture");
chmodSync(target, 0o755);
symlinkSync(target, command);
process.env.PATH = `${dir}${process.platform === "win32" ? ";" : ":"}${originalPath ?? ""}`;
expect(resolveTargetBinaryPath()).toBe(realpathSync(target));
} finally {
if (originalPath === undefined) delete process.env.PATH; else process.env.PATH = originalPath;
rmSync(dir, { recursive: true, force: true });
}
});
});