fix(ci): isolate vitest home path

This commit is contained in:
777genius 2026-04-25 02:27:40 +03:00
parent 78c49fc631
commit 937b23be4b
2 changed files with 14 additions and 5 deletions

View file

@ -246,13 +246,13 @@ describe('pathDecoder', () => {
describe('getProjectsBasePath', () => {
it('should return projects base path', () => {
expect(getProjectsBasePath()).toBe(path.join('/home/testuser', '.claude', 'projects'));
expect(getProjectsBasePath()).toBe(path.join(defaultHome, '.claude', 'projects'));
});
});
describe('getTodosBasePath', () => {
it('should return todos base path', () => {
expect(getTodosBasePath()).toBe(path.join('/home/testuser', '.claude', 'todos'));
expect(getTodosBasePath()).toBe(path.join(defaultHome, '.claude', 'todos'));
});
});

View file

@ -3,6 +3,10 @@
* Runs before each test file.
*/
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import { afterEach, beforeEach, expect, vi } from 'vitest';
// Mock Sentry Electron SDK — it requires the real `electron` package at import
@ -19,9 +23,14 @@ vi.mock('@sentry/electron/main', () => sentryNoOp);
vi.mock('@sentry/electron/renderer', () => sentryNoOp);
vi.mock('@sentry/react', () => sentryNoOp);
// Mock HOME for tests that need a predictable home path. Use stubEnv so we never
// touch process itself — stubbing process breaks vitest (process.listeners etc).
vi.stubEnv('HOME', '/home/testuser');
// Mock HOME for tests that need a predictable home path. It must be writable:
// some services persist state in best-effort background writes after a test has
// already reset path overrides.
const testHomeDir = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-teams-vitest-home-'));
vi.stubEnv('HOME', testHomeDir);
process.once('exit', () => {
fs.rmSync(testHomeDir, { recursive: true, force: true });
});
let errorSpy: ReturnType<typeof vi.spyOn>;
let warnSpy: ReturnType<typeof vi.spyOn>;