Skip to content

Commit 419be44

Browse files
committed
test(worktree): fix concurrent test worktree conflict and biome lint warnings
1 parent 0ee3054 commit 419be44

6 files changed

Lines changed: 46 additions & 17 deletions

File tree

cli/commands/install/cross-platform.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe("applyWin32LongPathPrefix — Task 23 (T2.12) — cross-platform invari
9696
value: "win32",
9797
configurable: true,
9898
});
99-
const path = "C:\\" + "a".repeat(260 - 3); // total 260
99+
const path = `C:\\${"a".repeat(260 - 3)}`; // total 260
100100
expect(applyWin32LongPathPrefix(path)).toBe(path);
101101
});
102102

@@ -105,7 +105,7 @@ describe("applyWin32LongPathPrefix — Task 23 (T2.12) — cross-platform invari
105105
value: "win32",
106106
configurable: true,
107107
});
108-
const path = "C:\\" + "a".repeat(261 - 3); // total 261
108+
const path = `C:\\${"a".repeat(261 - 3)}`; // total 261
109109
const out = applyWin32LongPathPrefix(path);
110110
expect(out.startsWith("\\\\?\\")).toBe(true);
111111
expect(out.endsWith(path)).toBe(true);
@@ -116,7 +116,7 @@ describe("applyWin32LongPathPrefix — Task 23 (T2.12) — cross-platform invari
116116
value: "win32",
117117
configurable: true,
118118
});
119-
const prefixed = "\\\\?\\C:\\" + "a".repeat(300);
119+
const prefixed = `\\\\?\\C:\\${"a".repeat(300)}`;
120120
expect(applyWin32LongPathPrefix(prefixed)).toBe(prefixed);
121121
});
122122

@@ -125,7 +125,7 @@ describe("applyWin32LongPathPrefix — Task 23 (T2.12) — cross-platform invari
125125
value: "darwin",
126126
configurable: true,
127127
});
128-
const path = "/tmp/" + "a".repeat(300);
128+
const path = `/tmp/${"a".repeat(300)}`;
129129
expect(applyWin32LongPathPrefix(path)).toBe(path);
130130
});
131131

@@ -134,7 +134,7 @@ describe("applyWin32LongPathPrefix — Task 23 (T2.12) — cross-platform invari
134134
value: "linux",
135135
configurable: true,
136136
});
137-
const path = "/home/" + "a".repeat(300);
137+
const path = `/home/${"a".repeat(300)}`;
138138
expect(applyWin32LongPathPrefix(path)).toBe(path);
139139
});
140140
});

cli/commands/install/install-global.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,10 @@ describe("install --global: _install.json schema and meta", () => {
293293
).mock.calls.filter((call: unknown[]) => call[0] === configPath);
294294

295295
// At least one write to oma-config.yaml should have occurred
296-
expect(writes.length).toBeGreaterThan(0);
297-
const lastWrite = writes[writes.length - 1]!;
296+
const lastWrite = writes[writes.length - 1];
297+
if (!lastWrite) {
298+
throw new Error("Expected at least one write");
299+
}
298300
const writtenContent = String(lastWrite[1]);
299301
expect(writtenContent).toContain("custom_user_field: my_value");
300302
});

cli/commands/update/update-global.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ describe("update --global: _install.json lifecycle", () => {
280280
fs.mkdirSync(path.join(repoDir, ".agents", "skills"), { recursive: true });
281281
fs.writeFileSync(
282282
path.join(repoDir, ".agents", "skills", "_version.json"),
283-
JSON.stringify({ version: "8.1.0" }) + "\n",
283+
`${JSON.stringify({ version: "8.1.0" })}\n`,
284284
);
285285
tarballState.downloadAndExtract.mockResolvedValue({
286286
dir: repoDir,

cli/io/worktree.test.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import { afterEach, beforeEach, describe, expect, it } from "vitest";
1414
import { createWorktree, formatWorktreeSummary } from "./worktree.js";
1515

1616
let repoDir: string;
17+
let sessionsToCleanup: string[] = [];
1718

1819
beforeEach(() => {
20+
sessionsToCleanup = [];
1921
repoDir = mkdtempSync(path.join(tmpdir(), "oma-worktree-test-"));
2022
execSync("git init -b main", { cwd: repoDir, stdio: "pipe" });
2123
execSync('git config user.email "test@example.com"', {
@@ -52,16 +54,32 @@ afterEach(() => {
5254
} catch {
5355
// ignore — repo may already be torn down
5456
}
57+
58+
// Clean up any worktree directories from tmp
59+
for (const sess of sessionsToCleanup) {
60+
try {
61+
const wtRoot = path.join(tmpdir(), "oma-worktrees", sess);
62+
if (existsSync(wtRoot)) {
63+
rmSync(wtRoot, { recursive: true, force: true });
64+
}
65+
} catch {
66+
// ignore
67+
}
68+
}
69+
5570
if (existsSync(repoDir)) {
5671
rmSync(repoDir, { recursive: true, force: true });
5772
}
5873
});
5974

6075
describe("createWorktree", () => {
6176
it("creates a worktree + branch from the current HEAD", () => {
62-
const handle = createWorktree("sess-001", "oma-backend", repoDir);
77+
const sessId = `sess-001-${Math.random().toString(36).slice(2)}`;
78+
sessionsToCleanup.push(sessId);
79+
80+
const handle = createWorktree(sessId, "oma-backend", repoDir);
6381
expect(existsSync(handle.path)).toBe(true);
64-
expect(handle.branch).toBe("oma/sess-001/oma-backend");
82+
expect(handle.branch).toBe(`oma/${sessId}/oma-backend`);
6583
expect(handle.base).toBe("main");
6684

6785
// The branch should be checked out at the new path
@@ -73,8 +91,12 @@ describe("createWorktree", () => {
7391
});
7492

7593
it("sanitizes unsafe characters in sessionId / agentId for the branch", () => {
76-
const handle = createWorktree("sess with space", "agent$weird", repoDir);
77-
expect(handle.branch).toMatch(/^oma\/sess-with-space\/agent-weird$/);
94+
const sessId = `sess with space-${Math.random().toString(36).slice(2)}`;
95+
sessionsToCleanup.push(sessId);
96+
97+
const handle = createWorktree(sessId, "agent$weird", repoDir);
98+
const safeSess = sessId.replace(/[^A-Za-z0-9._-]/g, "-").slice(0, 64);
99+
expect(handle.branch).toBe(`oma/${safeSess}/agent-weird`);
78100
});
79101

80102
it("throws when source is not a git repo", () => {
@@ -86,8 +108,11 @@ describe("createWorktree", () => {
86108
});
87109

88110
it("throws when the target worktree path already exists", () => {
89-
createWorktree("dup-session", "agent", repoDir);
90-
expect(() => createWorktree("dup-session", "agent", repoDir)).toThrow(
111+
const sessId = `dup-session-${Math.random().toString(36).slice(2)}`;
112+
sessionsToCleanup.push(sessId);
113+
114+
createWorktree(sessId, "agent", repoDir);
115+
expect(() => createWorktree(sessId, "agent", repoDir)).toThrow(
91116
/Worktree path already exists/,
92117
);
93118
});

cli/platform/hooks-composer.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ describe("hook self-dedup preamble (EC-6 / T2.1)", () => {
1515
expect(withoutShebang.startsWith(HOOK_DEDUP_PREAMBLE)).toBe(true);
1616
});
1717

18+
// biome-ignore lint/suspicious/noTemplateCurlyInString: Bash variables
1819
it("dedup preamble references /tmp/oma-hook-${UID}-${OMA_SESSION_ID:-default}.lock", () => {
1920
expect(HOOK_DEDUP_PREAMBLE).toContain(
21+
// biome-ignore lint/suspicious/noTemplateCurlyInString: Bash variables
2022
'"/tmp/oma-hook-${UID:-${EUID:-0}}-${OMA_SESSION_ID:-default}.lock"',
2123
);
2224
});

cli/utils/i18n.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ describe("t()", () => {
5151
it("returns ko text when LANG=ko_KR.UTF-8", () => {
5252
process.env.LANG = "ko_KR.UTF-8";
5353
const result = t("install.sudoRefused");
54-
expect(result).toBe(MESSAGES["install.sudoRefused"]!.ko);
54+
expect(result).toBe(MESSAGES["install.sudoRefused"]?.ko);
5555
});
5656

5757
it("returns en text when LANG=en_US.UTF-8", () => {
5858
process.env.LANG = "en_US.UTF-8";
5959
const result = t("install.sudoRefused");
60-
expect(result).toBe(MESSAGES["install.sudoRefused"]!.en);
60+
expect(result).toBe(MESSAGES["install.sudoRefused"]?.en);
6161
});
6262

6363
it("interpolates {pid} correctly", () => {
@@ -77,6 +77,6 @@ describe("t()", () => {
7777
it("returns message without interpolation when no vars passed", () => {
7878
process.env.LANG = "en_US.UTF-8";
7979
const result = t("install.sudoRefused");
80-
expect(result).toBe(MESSAGES["install.sudoRefused"]!.en);
80+
expect(result).toBe(MESSAGES["install.sudoRefused"]?.en);
8181
});
8282
});

0 commit comments

Comments
 (0)