Skip to content

Commit 8fcafdd

Browse files
committed
test(backup): drop branching from the pre-backup audit hard-link tests
The changed-test conditionals guardrail rejects new `if` statements in test files. Restore environment variables through the same branch-free helper the sibling snapshot tests use. Signed-off-by: Yanyun Liao <yanyunl@nvidia.com>
1 parent 3007d93 commit 8fcafdd

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

test/snapshot-backup-audit-hardlinks.test.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ function writeExecutable(filePath: string, source: string): void {
3131
fs.writeFileSync(filePath, source, { mode: 0o755 });
3232
}
3333

34+
/** Restore an env var without branching, mirroring the sibling snapshot tests. */
35+
function restoreEnv(name: string, value: string | undefined): void {
36+
value === undefined
37+
? Reflect.deleteProperty(process.env, name)
38+
: Reflect.set(process.env, name, value);
39+
}
40+
3441
function writeRegistry(sandboxName: string): void {
3542
fs.mkdirSync(path.join(TMP_HOME, ".nemoclaw"), { recursive: true });
3643
fs.writeFileSync(
@@ -117,19 +124,14 @@ process.exit(0);
117124
process.env.PATH = `${binDir}:${oldPath || ""}`;
118125
return sandboxState.backupSandboxState("alpha");
119126
} finally {
120-
if (oldOpenshell === undefined) {
121-
delete process.env.NEMOCLAW_OPENSHELL_BIN;
122-
} else {
123-
process.env.NEMOCLAW_OPENSHELL_BIN = oldOpenshell;
124-
}
125-
process.env.PATH = oldPath;
127+
restoreEnv("NEMOCLAW_OPENSHELL_BIN", oldOpenshell);
128+
restoreEnv("PATH", oldPath);
126129
fs.rmSync(fixture, { recursive: true, force: true });
127130
}
128131
}
129132

130133
afterAll(() => {
131-
if (ORIGINAL_HOME === undefined) delete process.env.HOME;
132-
else process.env.HOME = ORIGINAL_HOME;
134+
restoreEnv("HOME", ORIGINAL_HOME);
133135
fs.rmSync(TMP_HOME, { recursive: true, force: true });
134136
});
135137

0 commit comments

Comments
 (0)