|
1 | 1 | // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
2 | 2 | // SPDX-License-Identifier: Apache-2.0 |
3 | 3 |
|
4 | | -import { existsSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; |
| 4 | +import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs"; |
5 | 5 | import { tmpdir } from "node:os"; |
6 | 6 | import { join } from "node:path"; |
7 | 7 | import { afterEach, beforeEach, describe, expect, it } from "vitest"; |
@@ -82,20 +82,27 @@ describe("createTarball", () => { |
82 | 82 | expect(process.exitCode).toBe(1); |
83 | 83 | }); |
84 | 84 |
|
85 | | - it("removes any partial tarball when tar fails", () => { |
| 85 | + it("leaves pre-existing user output untouched and removes the temp sibling when tar fails", () => { |
86 | 86 | tempDir = mkdtempSync(join(tmpdir(), "debug-test-")); |
87 | 87 | writeFileSync(join(tempDir, "payload.txt"), "test data"); |
88 | 88 | outputDir = mkdtempSync(join(tmpdir(), "debug-test-out-")); |
89 | 89 | const output = join(outputDir, "partial.tar.gz"); |
90 | | - // Pre-create a stub file so createTarball can prove it removed a partial. |
91 | | - writeFileSync(output, "stub partial tarball"); |
| 90 | + // Pre-existing user file must NOT be clobbered when tar fails. |
| 91 | + const previous = "pre-existing user content"; |
| 92 | + writeFileSync(output, previous); |
92 | 93 | // Removing the source dir forces tar to fail without racing in-progress |
93 | 94 | // collection. |
94 | 95 | rmSync(tempDir, { recursive: true, force: true }); |
95 | 96 | const ok = createTarball(tempDir, output); |
96 | 97 | expect(ok).toBe(false); |
97 | 98 | expect(process.exitCode).toBe(1); |
98 | | - expect(existsSync(output)).toBe(false); |
| 99 | + expect(existsSync(output)).toBe(true); |
| 100 | + expect(readFileSync(output, "utf-8")).toBe(previous); |
| 101 | + // No .partial sibling should remain after cleanup. |
| 102 | + const partials = readdirSync(outputDir).filter( |
| 103 | + (name) => name.endsWith(".partial") || name.includes(".partial."), |
| 104 | + ); |
| 105 | + expect(partials).toEqual([]); |
99 | 106 | }); |
100 | 107 |
|
101 | 108 | it("creates tarball successfully and returns true for valid output path", () => { |
|
0 commit comments