Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/docker-manager-cleanup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ import { mockExecaFn, mockExecaSync } from './test-helpers/mock-execa.test-utils
// eslint-disable-next-line @typescript-eslint/no-require-imports
jest.mock('execa', () => require('./test-helpers/mock-execa.test-utils').execaMockFactory());

// Mock host identity functions so chownSync uses the real uid/gid
// (on macOS, gid < 1000 gets clamped to 1000 which causes EPERM)
jest.mock('./host-env', () => {
const actual = jest.requireActual('./host-env');
return {
...actual,
getSafeHostUid: () => String(process.getuid?.() ?? 1000),
getSafeHostGid: () => String(process.getgid?.() ?? 1000),
};
});

describe('docker-manager writeConfigs and cleanup', () => {
describe('writeConfigs', () => {
let testDir: string;
Expand Down
16 changes: 12 additions & 4 deletions src/docker-manager-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,12 @@ describe('docker-manager utilities', () => {
process.env.SUDO_USER = 'root';
process.env.HOME = '/some/other/path';

// Should find root's home directory from /etc/passwd
expect(getRealUserHome()).toBe('/root');
// Read actual root home from /etc/passwd (differs by platform: /root on Linux, /var/root on macOS)
const passwd = fs.readFileSync('/etc/passwd', 'utf-8');
const rootLine = passwd.split('\n').find(line => line.startsWith('root:'));
const expectedRootHome = rootLine ? rootLine.split(':')[5] : '/root';

expect(getRealUserHome()).toBe(expectedRootHome);
});

it('should fall back to HOME when SUDO_USER not found in /etc/passwd', () => {
Expand All @@ -236,9 +240,13 @@ describe('docker-manager utilities', () => {
process.env.SUDO_USER = 'root';
process.env.HOME = '/custom/home';

// Read actual root home from /etc/passwd (differs by platform)
const passwd = fs.readFileSync('/etc/passwd', 'utf-8');
const rootLine = passwd.split('\n').find(line => line.startsWith('root:'));
const expectedRootHome = rootLine ? rootLine.split(':')[5] : '/root';

// With getuid undefined, uid is undefined (falsy), so it attempts passwd lookup
// Should find root's home directory from /etc/passwd
expect(getRealUserHome()).toBe('/root');
expect(getRealUserHome()).toBe(expectedRootHome);
});
});

Expand Down
Loading