Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions test/clone.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { cloneRepos, destinationFault, findGit, listRepos, planClone, type Desti
import type { RepoEntry } from "../src/core/repos.js";
import type { RunRequest } from "../src/core/proc.js";
import { tmpDir } from "./helpers/forge.js";
import { removeWithRetry } from "./helpers/fs.js";

// Spec 37 §5.1 *Destination*, §5.2 and §10 — C5 in each of its forms, the listing's states, planClone's refusals
// (C3–C5, R1–R3), findGit, and cloneRepos with a recording runner. No test runs git: the runner is injected.
Expand All @@ -17,7 +18,7 @@ afterEach(async () => {
});
async function scratch(prefix = "craftar-clone-"): Promise<string> {
const dir = await fs.realpath(await tmpDir(prefix));
cleanups.push(() => fs.rm(dir, { recursive: true, force: true }));
cleanups.push(() => removeWithRetry(dir));
return dir;
}
const entry = (name: string, extra: Partial<RepoEntry> = {}): RepoEntry => ({ name, url: `https://git.example.com/acme/${name}.git`, path: name, ref: null, ...extra });
Expand Down Expand Up @@ -238,7 +239,7 @@ describe("findGit — onPath, nothing else", () => {
// spelling exists on win32 too — a temp dir may sit on another drive, where path.relative gives an absolute path.
const dir = path.join(process.cwd(), "node_modules", ".cache", `craftar-findgit-${process.pid}-${Date.now()}`);
await fs.mkdir(dir, { recursive: true });
cleanups.push(() => fs.rm(dir, { recursive: true, force: true }));
cleanups.push(() => removeWithRetry(dir));
await fs.copyFile(process.execPath, path.join(dir, "git" + EXE));
await fs.chmod(path.join(dir, "git" + EXE), 0o755);
const rel = path.relative(process.cwd(), dir);
Expand Down
3 changes: 2 additions & 1 deletion test/helpers/fake-git.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { promises as fs } from "node:fs";
import path from "node:path";
import { tmpDir } from "./forge.js";
import { removeWithRetry } from "./fs.js";

// Spec 37 §10: no test runs a real `git clone` and none reaches the network. The CLI's clone step is exercised with
// a fake git: a copy of node named `git` (`git.exe` on win32) alone on an absolute PATH entry — the trick
Expand Down Expand Up @@ -54,7 +55,7 @@ export async function fakeGit(): Promise<FakeGit> {
log,
// NODE_OPTIONS reads `\` inside double quotes as an escape: on win32 the hook's path is given with `/`, which node accepts.
env: (extra = {}) => ({ PATH: dir, Path: dir, NODE_OPTIONS: `--require "${hook.replace(/\\/g, "/")}"`, CRAFTAR_TEST_CLONE_LOG: log, ...extra }),
cleanup: () => fs.rm(dir, { recursive: true, force: true }),
cleanup: () => removeWithRetry(dir),
};
}

Expand Down
Loading