mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-14 18:18:21 +00:00
style: format source and test files
This commit is contained in:
1 parent
f451f4e421
commit
539afea737
34 files changed
+486
-295
No files matched your search
@@ -1,89 +1,91 @@
|
||||
import { expect, test, describe, beforeEach, afterEach } from "bun:test";
|
||||
import * as path from "path";
|
||||
import * as os from "os";
|
||||
import { expandPath } from "../../../src/utils/helpers";
|
||||
import { expect, test, describe, beforeEach, afterEach } from 'bun:test';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import { expandPath } from '../../../src/utils/helpers';
|
||||
|
||||
describe("expandPath", () => {
|
||||
describe('expandPath', () => {
|
||||
const originalEnv = { ...process.env };
|
||||
const HOME = os.homedir();
|
||||
|
||||
beforeEach(() => {
|
||||
process.env.TEST_HOME = "/custom/home";
|
||||
process.env.TEST_VAR = "foo";
|
||||
process.env.TEST_HOME = '/custom/home';
|
||||
process.env.TEST_VAR = 'foo';
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
process.env = { ...originalEnv };
|
||||
});
|
||||
|
||||
test("1. Tilde expansion: ~/path -> /home/user/path", () => {
|
||||
expect(expandPath("~/test/file.txt")).toBe(path.join(HOME, "test/file.txt"));
|
||||
test('1. Tilde expansion: ~/path -> /home/user/path', () => {
|
||||
expect(expandPath('~/test/file.txt')).toBe(path.join(HOME, 'test/file.txt'));
|
||||
});
|
||||
|
||||
test("2. Windows tilde with backslash: ~\\path", () => {
|
||||
test('2. Windows tilde with backslash: ~\\path', () => {
|
||||
// expandPath handles both ~/ and ~\ regardless of platform
|
||||
expect(expandPath("~\\test\\file.txt")).toBe(path.join(HOME, "test/file.txt"));
|
||||
expect(expandPath('~\\test\\file.txt')).toBe(path.join(HOME, 'test/file.txt'));
|
||||
});
|
||||
|
||||
test("3. Environment variable expansion: ${VAR}/path", () => {
|
||||
expect(expandPath("${TEST_HOME}/file.txt")).toBe(path.normalize("/custom/home/file.txt"));
|
||||
test('3. Environment variable expansion: ${VAR}/path', () => {
|
||||
expect(expandPath('${TEST_HOME}/file.txt')).toBe(path.normalize('/custom/home/file.txt'));
|
||||
});
|
||||
|
||||
test("4. Dollar sign env vars: $VAR/path", () => {
|
||||
expect(expandPath("$TEST_HOME/file.txt")).toBe(path.normalize("/custom/home/file.txt"));
|
||||
test('4. Dollar sign env vars: $VAR/path', () => {
|
||||
expect(expandPath('$TEST_HOME/file.txt')).toBe(path.normalize('/custom/home/file.txt'));
|
||||
});
|
||||
|
||||
test("5. Windows %VAR% expansion: %VAR%\\path (simulated)", () => {
|
||||
test('5. Windows %VAR% expansion: %VAR%\\path (simulated)', () => {
|
||||
// We can't easily mock process.platform if it's not win32,
|
||||
// but the function check process.platform === 'win32'
|
||||
if (process.platform === 'win32') {
|
||||
expect(expandPath("%TEST_HOME%\\file.txt")).toBe(path.normalize("/custom/home/file.txt"));
|
||||
expect(expandPath('%TEST_HOME%\\file.txt')).toBe(path.normalize('/custom/home/file.txt'));
|
||||
} else {
|
||||
// Should remain unchanged on non-windows (but separators normalized)
|
||||
expect(expandPath("%TEST_HOME%\\file.txt")).toBe(path.normalize("%TEST_HOME%/file.txt"));
|
||||
expect(expandPath('%TEST_HOME%\\file.txt')).toBe(path.normalize('%TEST_HOME%/file.txt'));
|
||||
}
|
||||
});
|
||||
|
||||
test("6. Mixed path separators normalization", () => {
|
||||
const result = expandPath("path/to\\some/file");
|
||||
expect(result).toBe(path.normalize("path/to/some/file"));
|
||||
test('6. Mixed path separators normalization', () => {
|
||||
const result = expandPath('path/to\\some/file');
|
||||
expect(result).toBe(path.normalize('path/to/some/file'));
|
||||
});
|
||||
|
||||
test("7. Nested env vars: ${HOME}/${VAR}/path", () => {
|
||||
expect(expandPath("${TEST_HOME}/${TEST_VAR}/file.txt")).toBe(path.normalize("/custom/home/foo/file.txt"));
|
||||
test('7. Nested env vars: ${HOME}/${VAR}/path', () => {
|
||||
expect(expandPath('${TEST_HOME}/${TEST_VAR}/file.txt')).toBe(
|
||||
path.normalize('/custom/home/foo/file.txt')
|
||||
);
|
||||
});
|
||||
|
||||
test("8. Empty/null path handling", () => {
|
||||
expect(expandPath("")).toBe(".");
|
||||
test('8. Empty/null path handling', () => {
|
||||
expect(expandPath('')).toBe('.');
|
||||
});
|
||||
|
||||
test("9. Already absolute paths stay unchanged", () => {
|
||||
const absPath = "/absolute/path";
|
||||
test('9. Already absolute paths stay unchanged', () => {
|
||||
const absPath = '/absolute/path';
|
||||
expect(expandPath(absPath)).toBe(path.normalize(absPath));
|
||||
});
|
||||
|
||||
test("10. Undefined env vars -> empty string", () => {
|
||||
expect(expandPath("${UNDEFINED_VAR}/file.txt")).toBe(path.normalize("/file.txt"));
|
||||
expect(expandPath("$UNDEFINED_VAR/file.txt")).toBe(path.normalize("/file.txt"));
|
||||
test('10. Undefined env vars -> empty string', () => {
|
||||
expect(expandPath('${UNDEFINED_VAR}/file.txt')).toBe(path.normalize('/file.txt'));
|
||||
expect(expandPath('$UNDEFINED_VAR/file.txt')).toBe(path.normalize('/file.txt'));
|
||||
});
|
||||
|
||||
test("11. Windows drive letters stay intact", () => {
|
||||
test('11. Windows drive letters stay intact', () => {
|
||||
// Windows drive letter paths should be preserved
|
||||
const result = expandPath("C:\\Users\\test\\file.txt");
|
||||
expect(result).toContain("Users");
|
||||
expect(result).toContain("test");
|
||||
const result = expandPath('C:\\Users\\test\\file.txt');
|
||||
expect(result).toContain('Users');
|
||||
expect(result).toContain('test');
|
||||
});
|
||||
|
||||
test("12. Windows UNC paths handled", () => {
|
||||
test('12. Windows UNC paths handled', () => {
|
||||
// UNC paths start with \\
|
||||
const uncPath = "\\\\server\\share\\folder";
|
||||
const uncPath = '\\\\server\\share\\folder';
|
||||
const result = expandPath(uncPath);
|
||||
// Should normalize but preserve the structure
|
||||
expect(result).toContain("server");
|
||||
expect(result).toContain("share");
|
||||
expect(result).toContain('server');
|
||||
expect(result).toContain('share');
|
||||
});
|
||||
|
||||
test("13. Null-like input throws TypeError", () => {
|
||||
test('13. Null-like input throws TypeError', () => {
|
||||
// Function requires string input - documents current behavior
|
||||
// @ts-ignore - testing runtime edge case
|
||||
expect(() => expandPath(undefined as unknown as string)).toThrow(TypeError);
|
||||
@@ -91,14 +93,14 @@ describe("expandPath", () => {
|
||||
expect(() => expandPath(null as unknown as string)).toThrow(TypeError);
|
||||
});
|
||||
|
||||
test("14. Path with spaces preserved", () => {
|
||||
const pathWithSpaces = "~/My Documents/file.txt";
|
||||
test('14. Path with spaces preserved', () => {
|
||||
const pathWithSpaces = '~/My Documents/file.txt';
|
||||
const result = expandPath(pathWithSpaces);
|
||||
expect(result).toContain("My Documents");
|
||||
expect(result).toContain('My Documents');
|
||||
});
|
||||
|
||||
test("15. Multiple consecutive slashes normalized", () => {
|
||||
const result = expandPath("path//to///file.txt");
|
||||
expect(result).toBe(path.normalize("path/to/file.txt"));
|
||||
test('15. Multiple consecutive slashes normalized', () => {
|
||||
const result = expandPath('path//to///file.txt');
|
||||
expect(result).toBe(path.normalize('path/to/file.txt'));
|
||||
});
|
||||
});
|
||||
@@ -97,7 +97,9 @@ describe('signal-forwarder', () => {
|
||||
const child = createMockChildProcess();
|
||||
const before = getSignalListenerCounts();
|
||||
const onError = jest.fn(async () => {});
|
||||
const err = Object.assign(new Error('spawn failed'), { code: 'ENOENT' }) as NodeJS.ErrnoException;
|
||||
const err = Object.assign(new Error('spawn failed'), {
|
||||
code: 'ENOENT',
|
||||
}) as NodeJS.ErrnoException;
|
||||
|
||||
wireChildProcessSignals(child, onError);
|
||||
child.emit('error', err);
|
||||
@@ -113,7 +115,9 @@ describe('signal-forwarder', () => {
|
||||
const child = createMockChildProcess();
|
||||
const onError = jest.fn(async () => {});
|
||||
const onExit = jest.fn();
|
||||
const err = Object.assign(new Error('spawn failed'), { code: 'ENOENT' }) as NodeJS.ErrnoException;
|
||||
const err = Object.assign(new Error('spawn failed'), {
|
||||
code: 'ENOENT',
|
||||
}) as NodeJS.ErrnoException;
|
||||
|
||||
wireChildProcessSignals(child, onError, onExit);
|
||||
child.emit('error', err);
|
||||
@@ -134,7 +138,9 @@ describe('signal-forwarder', () => {
|
||||
.mockImplementation((() => undefined as never) as typeof process.exit);
|
||||
|
||||
try {
|
||||
const err = Object.assign(new Error('spawn failed'), { code: 'ENOENT' }) as NodeJS.ErrnoException;
|
||||
const err = Object.assign(new Error('spawn failed'), {
|
||||
code: 'ENOENT',
|
||||
}) as NodeJS.ErrnoException;
|
||||
wireChildProcessSignals(child, onError);
|
||||
child.emit('error', err);
|
||||
await Promise.resolve();
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { expect, test, describe } from 'bun:test';
|
||||
import { isCcsWebSearchHook, deduplicateCcsHooks } from '../../../../src/utils/websearch/hook-utils';
|
||||
import {
|
||||
isCcsWebSearchHook,
|
||||
deduplicateCcsHooks,
|
||||
} from '../../../../src/utils/websearch/hook-utils';
|
||||
|
||||
describe('isCcsWebSearchHook', () => {
|
||||
test('Returns true for CCS hook with forward slashes (Unix path)', () => {
|
||||
|
||||
Reference in new issue
Block a user