Skip to content

Commit 003762a

Browse files
authored
test: fix env-dependent and parallel-process test failures (#39467)
Two orthogonal local test failures, unrelated to product behavior: 1. /tmp/gh-aw transport-file race. create_pull_request.test.cjs and push_to_pull_request_branch.test.cjs (and generate_git_bundle.test.cjs) share the process-global /tmp/gh-aw directory. Each test's beforeEach globbed and deleted every aw-*.patch/aw-*.bundle file in that directory, so when vitest ran the files in parallel processes they deleted each other's in-flight transport files mid-test. Track only the paths each test file creates and delete just those. 2. handle_noop_message.test.cjs depended on an ambient RUNNER_TEMP. getPromptPath() throws unless GH_AW_PROMPTS_DIR or RUNNER_TEMP is set; RUNNER_TEMP is present on CI but not in local dev, so 16 tests threw before reaching their assertions. Set GH_AW_PROMPTS_DIR explicitly in beforeEach (fs.readFileSync is already mocked, so the path is irrelevant).
1 parent 355cb87 commit 003762a

3 files changed

Lines changed: 42 additions & 18 deletions

File tree

actions/setup/js/create_pull_request.test.cjs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,31 @@ const { getBundlePathForBranch, getBundlePathForBranchInRepo } = require("./gene
1414
// The privileged handler derives patch/bundle paths from `branch` (and `repo`)
1515
// via resolveTransportPaths, so tests must write transport files at the
1616
// canonical derived location and let the handler discover them.
17+
//
18+
// `/tmp/gh-aw` is a process-global path shared by every test file. Vitest runs
19+
// test files in parallel processes, so a cleanup that globbed the whole
20+
// directory would delete another file's in-flight transport files mid-test.
21+
// Track only the paths this file created and delete just those.
22+
const createdTransportPaths = new Set();
1723
function canonicalPatchPath(branch, repo) {
1824
fs.mkdirSync("/tmp/gh-aw", { recursive: true });
19-
return repo ? getPatchPathForBranchInRepo(branch, repo) : getPatchPathForBranch(branch);
25+
const p = repo ? getPatchPathForBranchInRepo(branch, repo) : getPatchPathForBranch(branch);
26+
createdTransportPaths.add(p);
27+
return p;
2028
}
2129
function canonicalBundlePath(branch, repo) {
2230
fs.mkdirSync("/tmp/gh-aw", { recursive: true });
23-
return repo ? getBundlePathForBranchInRepo(branch, repo) : getBundlePathForBranch(branch);
31+
const p = repo ? getBundlePathForBranchInRepo(branch, repo) : getBundlePathForBranch(branch);
32+
createdTransportPaths.add(p);
33+
return p;
2434
}
2535
function cleanupCanonicalTransports() {
26-
try {
27-
for (const f of fs.readdirSync("/tmp/gh-aw")) {
28-
if (/^aw-.*\.(patch|bundle)$/.test(f)) {
29-
fs.rmSync(`/tmp/gh-aw/${f}`, { force: true });
30-
}
31-
}
32-
} catch {}
36+
for (const p of createdTransportPaths) {
37+
try {
38+
fs.rmSync(p, { force: true });
39+
} catch {}
40+
}
41+
createdTransportPaths.clear();
3342
}
3443

3544
beforeEach(() => {

actions/setup/js/handle_noop_message.test.cjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ describe("handle_noop_message", () => {
2020
// Create temp directory for test files
2121
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "handle-noop-test-"));
2222

23+
// getPromptPath() throws unless GH_AW_PROMPTS_DIR or RUNNER_TEMP is set.
24+
// On CI RUNNER_TEMP is ambient, but it is not set in local dev, so set the
25+
// prompts dir explicitly to make the suite environment-independent. The
26+
// actual path is irrelevant because fs.readFileSync is mocked below.
27+
process.env.GH_AW_PROMPTS_DIR = tempDir;
28+
2329
// Mock fs.readFileSync to return template content
2430
originalReadFileSync = fs.readFileSync;
2531
fs.readFileSync = vi.fn((filePath, encoding) => {

actions/setup/js/push_to_pull_request_branch.test.cjs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,31 @@ const { getBundlePathForBranch, getBundlePathForBranchInRepo } = require("./gene
99
// The privileged handler derives patch/bundle paths from `branch` (and `repo`)
1010
// via resolveTransportPaths, so tests must write transport files at the
1111
// canonical derived location and let the handler discover them.
12+
//
13+
// `/tmp/gh-aw` is a process-global path shared by every test file. Vitest runs
14+
// test files in parallel processes, so a cleanup that globbed the whole
15+
// directory would delete another file's in-flight transport files mid-test.
16+
// Track only the paths this file created and delete just those.
17+
const createdTransportPaths = new Set();
1218
function canonicalPatchPath(branch, repo) {
1319
fs.mkdirSync("/tmp/gh-aw", { recursive: true });
14-
return repo ? getPatchPathForBranchInRepo(branch, repo) : getPatchPathForBranch(branch);
20+
const p = repo ? getPatchPathForBranchInRepo(branch, repo) : getPatchPathForBranch(branch);
21+
createdTransportPaths.add(p);
22+
return p;
1523
}
1624
function canonicalBundlePath(branch, repo) {
1725
fs.mkdirSync("/tmp/gh-aw", { recursive: true });
18-
return repo ? getBundlePathForBranchInRepo(branch, repo) : getBundlePathForBranch(branch);
26+
const p = repo ? getBundlePathForBranchInRepo(branch, repo) : getBundlePathForBranch(branch);
27+
createdTransportPaths.add(p);
28+
return p;
1929
}
2030
function cleanupCanonicalTransports() {
21-
try {
22-
for (const f of fs.readdirSync("/tmp/gh-aw")) {
23-
if (/^aw-.*\.(patch|bundle)$/.test(f)) {
24-
fs.rmSync(`/tmp/gh-aw/${f}`, { force: true });
25-
}
26-
}
27-
} catch {}
31+
for (const p of createdTransportPaths) {
32+
try {
33+
fs.rmSync(p, { force: true });
34+
} catch {}
35+
}
36+
createdTransportPaths.clear();
2837
}
2938

3039
beforeEach(() => {

0 commit comments

Comments
 (0)