Skip to content

Commit 445584a

Browse files
gn00295120claude
andcommitted
fix: address Copilot review feedback on mock ordering and type safety
- Use dynamic import in test to guarantee mock bindings are active - Type SAFE_GIT_ENV as NodeJS.ProcessEnv instead of casting Record<string, string> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 65ca145 commit 445584a

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/github/operations/restore-config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const GIT_TIMEOUT_MS = 60_000;
2323

2424
// Environment overrides that prevent git from hanging on credential prompts or
2525
// recursing into submodules. Applied to every git subprocess in this module.
26-
const SAFE_GIT_ENV: Record<string, string> = {
26+
const SAFE_GIT_ENV: NodeJS.ProcessEnv = {
2727
...process.env,
2828
// Prevent git from opening an interactive credential prompt (would block the
2929
// runner forever in a non-interactive CI environment).
@@ -33,7 +33,7 @@ const SAFE_GIT_ENV: Record<string, string> = {
3333
// can cause git to fetch/update submodules, which may hang indefinitely
3434
// if the submodule URLs require authentication not available to the runner.
3535
GIT_SUBMODULE_UPDATE_COMMAND: "true",
36-
} as Record<string, string>;
36+
};
3737

3838
/**
3939
* Restores security-sensitive config paths from the PR base branch.

test/restore-config.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import { describe, it, expect, mock, beforeEach } from "bun:test";
2-
import { execFileSync } from "child_process";
3-
import { rmSync } from "fs";
42

5-
// Mock child_process and fs before importing the module under test
3+
// Create mock functions first, then register them with mock.module
4+
const mockedExecFileSync = mock(() => undefined);
5+
const mockedRmSync = mock(() => undefined);
6+
67
mock.module("child_process", () => ({
7-
execFileSync: mock(() => undefined),
8+
execFileSync: mockedExecFileSync,
89
}));
910

1011
mock.module("fs", () => ({
11-
rmSync: mock(() => undefined),
12+
rmSync: mockedRmSync,
1213
}));
1314

14-
// Import after mocking
15-
import { restoreConfigFromBase } from "../src/github/operations/restore-config";
16-
17-
const mockedExecFileSync = execFileSync as unknown as ReturnType<typeof mock>;
18-
const mockedRmSync = rmSync as unknown as ReturnType<typeof mock>;
15+
// Dynamic import after mocking to guarantee bindings point to mocks
16+
const { restoreConfigFromBase } = await import(
17+
"../src/github/operations/restore-config"
18+
);
1919

2020
describe("restoreConfigFromBase", () => {
2121
beforeEach(() => {

0 commit comments

Comments
 (0)