Skip to content

Commit bc40f81

Browse files
committed
🤖 fix: stabilize telemetry+systemMessage tests for CI
- Force NODE_ENV='test' in telemetry client tests so initTelemetry short-circuits - Pin MUX_ROOT to temp .mux in systemMessage tests to avoid host config bleed _Generated with _
1 parent 2fee2ce commit bc40f81

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/common/telemetry/client.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import { initTelemetry, trackEvent, isTelemetryInitialized } from "./client";
1212

1313
describe("Telemetry", () => {
1414
describe("in test environment", () => {
15+
beforeAll(() => {
16+
process.env.NODE_ENV = "test";
17+
});
18+
1519
it("should not initialize PostHog", () => {
1620
initTelemetry();
1721
expect(isTelemetryInitialized()).toBe(false);

src/node/services/systemMessage.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ describe("buildSystemMessage", () => {
1414
let globalDir: string;
1515
let mockHomedir: Mock<typeof os.homedir>;
1616
let runtime: LocalRuntime;
17+
let originalMuxRoot: string | undefined;
1718

1819
beforeEach(async () => {
20+
// Snapshot any existing MUX_ROOT so we can restore it after the test.
21+
originalMuxRoot = process.env.MUX_ROOT;
22+
1923
// Create temp directory for test
2024
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "systemMessage-test-"));
2125
projectDir = path.join(tempDir, "project");
@@ -29,13 +33,24 @@ describe("buildSystemMessage", () => {
2933
mockHomedir = spyOn(os, "homedir");
3034
mockHomedir.mockReturnValue(tempDir);
3135

36+
// Force mux home to our test .mux directory regardless of host MUX_ROOT.
37+
process.env.MUX_ROOT = globalDir;
38+
3239
// Create a local runtime for tests
3340
runtime = new LocalRuntime(tempDir);
3441
});
3542

3643
afterEach(async () => {
3744
// Clean up temp directory
3845
await fs.rm(tempDir, { recursive: true, force: true });
46+
47+
// Restore environment override
48+
if (originalMuxRoot === undefined) {
49+
delete process.env.MUX_ROOT;
50+
} else {
51+
process.env.MUX_ROOT = originalMuxRoot;
52+
}
53+
3954
// Restore the original homedir
4055
mockHomedir?.mockRestore();
4156
});

0 commit comments

Comments
 (0)