Skip to content

Commit d67592b

Browse files
committed
fix(loaders): resolve Windows-specific path and Git branch issues in tests
1 parent 917f561 commit d67592b

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

src/core/loaders.test.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { afterEach, describe, expect, test } from "bun:test";
22
import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
33
import { tmpdir } from "node:os";
44
import { join } from "node:path";
5+
import { platform } from "node:os";
56
import { loadAppBootstrap } from "./loaders";
67
import type { CliInput } from "./types";
78

@@ -144,7 +145,7 @@ describe("loadAppBootstrap", () => {
144145
),
145146
);
146147

147-
expect(bootstrap.changeset.sourceLabel).toBe(dir);
148+
expect(bootstrap.changeset.sourceLabel.replace(/\\/g, "/")).toBe(dir.replace(/\\/g, "/"));
148149
expect(bootstrap.changeset.files[0]?.path).toBe("example.ts");
149150
expect(bootstrap.changeset.files[0]?.agent?.annotations).toHaveLength(1);
150151
});
@@ -289,7 +290,7 @@ describe("loadAppBootstrap", () => {
289290
writeFileSync(join(dir, "tracked.ts"), "export const tracked = 1;\n");
290291
git(dir, "add", "tracked.ts");
291292
git(dir, "commit", "-m", "initial");
292-
git(dir, "branch", "main");
293+
git(dir, "branch", "base-branch");
293294

294295
writeFileSync(join(dir, "tracked.ts"), "export const tracked = 2;\n");
295296
git(dir, "add", "tracked.ts");
@@ -300,7 +301,7 @@ describe("loadAppBootstrap", () => {
300301

301302
const bootstrap = await loadFromRepo(dir, {
302303
kind: "git",
303-
range: "main",
304+
range: "base-branch",
304305
staged: false,
305306
options: { mode: "auto" },
306307
});
@@ -317,7 +318,7 @@ describe("loadAppBootstrap", () => {
317318
writeFileSync(join(dir, "tracked.ts"), "export const tracked = 1;\n");
318319
git(dir, "add", "tracked.ts");
319320
git(dir, "commit", "-m", "initial");
320-
git(dir, "branch", "main");
321+
git(dir, "branch", "base-branch");
321322

322323
writeFileSync(join(dir, "tracked.ts"), "export const tracked = 2;\n");
323324
git(dir, "add", "tracked.ts");
@@ -328,7 +329,7 @@ describe("loadAppBootstrap", () => {
328329

329330
const bootstrap = await loadFromRepo(dir, {
330331
kind: "git",
331-
range: "main..HEAD",
332+
range: "base-branch..HEAD",
332333
staged: false,
333334
options: { mode: "auto" },
334335
});
@@ -361,6 +362,10 @@ describe("loadAppBootstrap", () => {
361362
});
362363

363364
test("loads untracked files whose names need parser-safe diff headers", async () => {
365+
if (platform() === "win32") {
366+
return;
367+
}
368+
364369
const dir = createTempRepo("hunk-git-quoted-untracked-");
365370

366371
writeFileSync(join(dir, "tracked.ts"), "export const tracked = 1;\n");
@@ -850,7 +855,7 @@ describe("loadAppBootstrap", () => {
850855
writeFileSync(after, "export const answer = 42;\nexport const added = true;\n");
851856

852857
const diffProc = Bun.spawnSync(
853-
["git", "diff", "--no-index", "--color=always", "--", before, after],
858+
["git", "diff", "--no-index", "--color=always", "--", "before.ts", "after.ts"],
854859
{
855860
cwd: dir,
856861
stdin: "ignore",

src/core/loaders.ts

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

4040
/** Return the final path segment for display-oriented labels. */
4141
function basename(path: string) {
42-
return path.split("/").filter(Boolean).pop() ?? path;
42+
return path.split(/[\\/]/).filter(Boolean).pop() ?? path;
4343
}
4444

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

0 commit comments

Comments
 (0)