fix: Windows test compatibility — path.resolve in atomicWrite and pathValidation tests
This commit is contained in:
parent
bfb4be1ef8
commit
02bf87b0b0
2 changed files with 10 additions and 5 deletions
|
|
@ -30,7 +30,7 @@ const mockRename = vi.mocked(fs.promises.rename);
|
||||||
const mockCopyFile = vi.mocked(fs.promises.copyFile);
|
const mockCopyFile = vi.mocked(fs.promises.copyFile);
|
||||||
const mockUnlink = vi.mocked(fs.promises.unlink);
|
const mockUnlink = vi.mocked(fs.promises.unlink);
|
||||||
|
|
||||||
const TARGET_PATH = '/Users/test/project/src/index.ts';
|
const TARGET_PATH = path.resolve('/Users/test/project/src/index.ts');
|
||||||
const TARGET_DIR = path.dirname(TARGET_PATH);
|
const TARGET_DIR = path.dirname(TARGET_PATH);
|
||||||
const CONTENT = 'export const hello = "world";';
|
const CONTENT = 'export const hello = "world";';
|
||||||
|
|
||||||
|
|
@ -65,7 +65,8 @@ describe('atomicWriteAsync', () => {
|
||||||
// writeFile should be called with a tmp path in the same directory
|
// writeFile should be called with a tmp path in the same directory
|
||||||
expect(mockWriteFile).toHaveBeenCalledTimes(1);
|
expect(mockWriteFile).toHaveBeenCalledTimes(1);
|
||||||
const tmpPath = getTmpPath();
|
const tmpPath = getTmpPath();
|
||||||
expect(tmpPath).toMatch(new RegExp(`^${TARGET_DIR}/\\.tmp\\.[a-f0-9-]+$`));
|
const escapedDir = TARGET_DIR.replace(/[\\]/g, '\\\\');
|
||||||
|
expect(tmpPath).toMatch(new RegExp(`^${escapedDir}[/\\\\]\\.tmp\\.[a-f0-9-]+$`));
|
||||||
|
|
||||||
// rename from tmp to target
|
// rename from tmp to target
|
||||||
expect(mockRename).toHaveBeenCalledWith(tmpPath, TARGET_PATH);
|
expect(mockRename).toHaveBeenCalledWith(tmpPath, TARGET_PATH);
|
||||||
|
|
|
||||||
|
|
@ -223,14 +223,18 @@ describe('pathValidation', () => {
|
||||||
it('should expand ~ to home directory for paths within ~/.claude', () => {
|
it('should expand ~ to home directory for paths within ~/.claude', () => {
|
||||||
const result = validateFilePath('~/.claude/projects/test.jsonl', null);
|
const result = validateFilePath('~/.claude/projects/test.jsonl', null);
|
||||||
expect(result.valid).toBe(true);
|
expect(result.valid).toBe(true);
|
||||||
expect(result.normalizedPath).toBe(path.join(homeDir, '.claude', 'projects', 'test.jsonl'));
|
expect(result.normalizedPath).toBe(
|
||||||
|
path.resolve(path.join(homeDir, '.claude', 'projects', 'test.jsonl'))
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should expand ~ to home directory for project paths', () => {
|
it('should expand ~ to home directory for project paths', () => {
|
||||||
const projectInHome = path.join(homeDir, 'my-project');
|
const projectInHome = path.join(homeDir, 'my-project');
|
||||||
const result = validateFilePath('~/my-project/src/index.ts', projectInHome);
|
const result = validateFilePath('~/my-project/src/index.ts', projectInHome);
|
||||||
expect(result.valid).toBe(true);
|
expect(result.valid).toBe(true);
|
||||||
expect(result.normalizedPath).toBe(path.join(projectInHome, 'src', 'index.ts'));
|
expect(result.normalizedPath).toBe(
|
||||||
|
path.resolve(path.join(projectInHome, 'src', 'index.ts'))
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reject tilde paths to sensitive files', () => {
|
it('should reject tilde paths to sensitive files', () => {
|
||||||
|
|
@ -250,7 +254,7 @@ describe('pathValidation', () => {
|
||||||
it('should expand tilde in paths', () => {
|
it('should expand tilde in paths', () => {
|
||||||
const result = validateOpenPath('~/.claude', null);
|
const result = validateOpenPath('~/.claude', null);
|
||||||
expect(result.valid).toBe(true);
|
expect(result.valid).toBe(true);
|
||||||
expect(result.normalizedPath).toBe(path.normalize(claudeDir));
|
expect(result.normalizedPath).toBe(path.resolve(claudeDir));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reject sensitive files', () => {
|
it('should reject sensitive files', () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue