Skip to content

Commit b967d44

Browse files
spiicez21benvinegar
authored andcommitted
fix(loaders): resolve Windows-specific path and Git branch issues in tests
1 parent e2b68c8 commit b967d44

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/core/loaders.test.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { afterEach, describe, expect, test } from "bun:test";
22
import { mkdirSync, mkdtempSync, realpathSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
3-
import { tmpdir } from "node:os";
3+
import { platform, tmpdir } from "node:os";
44
import { join } from "node:path";
55
import { loadAppBootstrap } from "./loaders";
66
import type { CliInput } from "./types";
@@ -201,7 +201,7 @@ describe("loadAppBootstrap", () => {
201201
),
202202
);
203203

204-
expect(bootstrap.changeset.sourceLabel).toBe(dir);
204+
expect(bootstrap.changeset.sourceLabel.replace(/\\/g, "/")).toBe(dir.replace(/\\/g, "/"));
205205
expect(bootstrap.changeset.files[0]?.path).toBe("example.ts");
206206
expect(bootstrap.changeset.files[0]?.agent?.annotations).toHaveLength(1);
207207
});
@@ -346,7 +346,7 @@ describe("loadAppBootstrap", () => {
346346
writeFileSync(join(dir, "tracked.ts"), "export const tracked = 1;\n");
347347
git(dir, "add", "tracked.ts");
348348
git(dir, "commit", "-m", "initial");
349-
git(dir, "branch", "main");
349+
git(dir, "branch", "base-branch");
350350

351351
writeFileSync(join(dir, "tracked.ts"), "export const tracked = 2;\n");
352352
git(dir, "add", "tracked.ts");
@@ -357,7 +357,7 @@ describe("loadAppBootstrap", () => {
357357

358358
const bootstrap = await loadFromRepo(dir, {
359359
kind: "vcs",
360-
range: "main",
360+
range: "base-branch",
361361
staged: false,
362362
options: { mode: "auto" },
363363
});
@@ -374,7 +374,7 @@ describe("loadAppBootstrap", () => {
374374
writeFileSync(join(dir, "tracked.ts"), "export const tracked = 1;\n");
375375
git(dir, "add", "tracked.ts");
376376
git(dir, "commit", "-m", "initial");
377-
git(dir, "branch", "main");
377+
git(dir, "branch", "base-branch");
378378

379379
writeFileSync(join(dir, "tracked.ts"), "export const tracked = 2;\n");
380380
git(dir, "add", "tracked.ts");
@@ -385,7 +385,7 @@ describe("loadAppBootstrap", () => {
385385

386386
const bootstrap = await loadFromRepo(dir, {
387387
kind: "vcs",
388-
range: "main..HEAD",
388+
range: "base-branch..HEAD",
389389
staged: false,
390390
options: { mode: "auto" },
391391
});
@@ -418,6 +418,10 @@ describe("loadAppBootstrap", () => {
418418
});
419419

420420
test("loads untracked files whose names need parser-safe diff headers", async () => {
421+
if (platform() === "win32") {
422+
return;
423+
}
424+
421425
const dir = createTempRepo("hunk-git-quoted-untracked-");
422426

423427
writeFileSync(join(dir, "tracked.ts"), "export const tracked = 1;\n");
@@ -967,7 +971,7 @@ describe("loadAppBootstrap", () => {
967971
writeFileSync(after, "export const answer = 42;\nexport const added = true;\n");
968972

969973
const diffProc = Bun.spawnSync(
970-
["git", "diff", "--no-index", "--color=always", "--", before, after],
974+
["git", "diff", "--no-index", "--color=always", "--", "before.ts", "after.ts"],
971975
{
972976
cwd: dir,
973977
stdin: "ignore",

src/core/loaders.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ interface LoadAppBootstrapOptions {
4747

4848
/** Return the final path segment for display-oriented labels. */
4949
function basename(path: string) {
50-
return path.split("/").filter(Boolean).pop() ?? path;
50+
return path.split(/[\\/]/).filter(Boolean).pop() ?? path;
5151
}
5252

5353
/** Remove git-style a/ and b/ prefixes before matching diff paths. */

0 commit comments

Comments
 (0)