Skip to content
Merged
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
39 changes: 24 additions & 15 deletions gitnexus/test/unit/ignore-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,21 +561,30 @@ describe('loadIgnoreRules — error handling', () => {
await fs.rm(tmpDir, { recursive: true, force: true });
});

it.skipIf(process.platform === 'win32')('warns on EACCES but does not throw', async () => {
const gitignorePath = path.join(tmpDir, '.gitignore');
await fs.writeFile(gitignorePath, 'data/\n');
await fs.chmod(gitignorePath, 0o000);

const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
const result = await loadIgnoreRules(tmpDir);
// Should still return (null or partial), not throw
expect(result).toBeNull();
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('.gitignore'));

warnSpy.mockRestore();
await fs.chmod(gitignorePath, 0o644);
await fs.unlink(gitignorePath);
});
// Also skip under uid=0: root bypasses POSIX read-permission checks, so
// chmod 000 does NOT trigger EACCES — fs.readFile reads the file anyway
// and loadIgnoreRules returns parsed rules instead of null. This makes
// the test fail in any privileged environment (rootful Docker, CI runners
// configured with root). The non-root branch still exercises the real
// EACCES path; root just can't reproduce the failure mode.
it.skipIf(process.platform === 'win32' || process.getuid?.() === 0)(
'warns on EACCES but does not throw',
async () => {
const gitignorePath = path.join(tmpDir, '.gitignore');
await fs.writeFile(gitignorePath, 'data/\n');
await fs.chmod(gitignorePath, 0o000);

const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
const result = await loadIgnoreRules(tmpDir);
// Should still return (null or partial), not throw
expect(result).toBeNull();
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('.gitignore'));

warnSpy.mockRestore();
await fs.chmod(gitignorePath, 0o644);
await fs.unlink(gitignorePath);
},
);
});

describe('loadIgnoreRules — GITNEXUS_NO_GITIGNORE env var', () => {
Expand Down
Loading