Skip to content

Commit aaae417

Browse files
prekshivyasclaude
andauthored
fix(test): prevent flaky tarball test race condition (#1982)
## Summary The `createTarball` success test writes `output.tar.gz` into the same temp directory being archived. `tar` sees the file appear while reading the directory and exits with code 1 ("file changed as we read it"), causing intermittent CI failures on any PR that rebases onto main. Fix: write output to a separate temp directory. ## Test plan - [x] 10/10 debug tests pass - [x] Race condition eliminated — output dir is separate from source dir Signed-off-by: Prekshi Vyas <prekshiv@nvidia.com> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Improved test isolation by writing generated test artifacts to a separate temporary output directory instead of the archived source directory. * Enhanced cleanup to remove the separate output directory (recursive) after each test, ensuring no leftover artifacts remain. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Prekshi Vyas <prekshiv@nvidia.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f7a3c33 commit aaae417

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/lib/debug.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@ describe("redact", () => {
5656

5757
describe("createTarball", () => {
5858
let tempDir: string;
59+
let outputDir: string;
5960

6061
beforeEach(() => {
6162
process.exitCode = undefined;
6263
});
6364

6465
afterEach(() => {
6566
if (tempDir) rmSync(tempDir, { recursive: true, force: true });
67+
if (outputDir) rmSync(outputDir, { recursive: true, force: true });
6668
process.exitCode = undefined;
6769
});
6870

@@ -77,7 +79,10 @@ describe("createTarball", () => {
7779
it("creates tarball successfully and returns true for valid output path", () => {
7880
tempDir = mkdtempSync(join(tmpdir(), "debug-test-"));
7981
writeFileSync(join(tempDir, "dummy.txt"), "test data");
80-
const output = join(tempDir, "output.tar.gz");
82+
// Write output to a SEPARATE directory — writing into the source dir
83+
// causes tar to see the file changing as it reads, returning exit 1.
84+
outputDir = mkdtempSync(join(tmpdir(), "debug-test-out-"));
85+
const output = join(outputDir, "output.tar.gz");
8186
const ok = createTarball(tempDir, output);
8287
expect(ok).toBe(true);
8388
expect(process.exitCode).toBeUndefined();

0 commit comments

Comments
 (0)