@2501-ai/cli
Version:
[](https://www.npmjs.com/package/@2501-ai/cli) [](https://www.2501.ai/research/full-humaneval-benchmark) [![Lic
150 lines (149 loc) • 7.69 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const files_1 = require("../files");
const ignore_1 = require("../ignore");
const constants_1 = require("../../constants");
describe('getDirectoryFiles', () => {
let ignoreManagerInstance;
const mockBasePath = path_1.default.join(__dirname, 'mocks/workspace');
beforeEach(() => {
ignoreManagerInstance = new ignore_1.IgnoreManager();
jest
.spyOn(ignore_1.IgnoreManager, 'getInstance')
.mockImplementation(() => ignoreManagerInstance);
});
it('should return the correct file hashes for mock dir', () => {
const result = (0, files_1.getDirectoryFiles)({
directoryPath: mockBasePath,
maxDepth: constants_1.DEFAULT_MAX_DEPTH,
maxDirSize: constants_1.DEFAULT_MAX_DIR_SIZE,
currentPath: '',
currentDepth: 0,
currentTotalSize: 0,
ignoreManager: ignoreManagerInstance,
});
expect(result.totalSize).toEqual(2919);
expect(result.fileHashes.size).toEqual(4);
expect(result.fileHashes.has('example/.gitignore')).toStrictEqual(true);
expect(result.fileHashes.has('example/index.html')).toStrictEqual(true);
expect(result.fileHashes.has('example/other/.gitignore')).toStrictEqual(true);
expect(result.fileHashes.has('example/other/myfile.csv')).toStrictEqual(true);
expect(result.fileHashes.has('example/other/.env')).toStrictEqual(false);
expect(result.fileHashes.has('example/data')).toStrictEqual(false);
expect(result.fileHashes.has('example/data/data.txt')).toStrictEqual(false);
});
it('should return the correct file hashes for mock dir and depth 1', () => {
const result = (0, files_1.getDirectoryFiles)({
directoryPath: mockBasePath,
maxDepth: 1,
maxDirSize: constants_1.DEFAULT_MAX_DIR_SIZE,
currentPath: '',
currentDepth: 0,
currentTotalSize: 0,
ignoreManager: ignoreManagerInstance,
});
expect(result.totalSize).toEqual(2914);
expect(result.fileHashes.size).toEqual(2);
expect(result.fileHashes.has('example/.gitignore')).toStrictEqual(true);
expect(result.fileHashes.has('example/index.html')).toStrictEqual(true);
expect(result.fileHashes.has('example/other/.gitignore')).toStrictEqual(false);
expect(result.fileHashes.has('example/other/myfile.csv')).toStrictEqual(false);
expect(result.fileHashes.has('example/other/.env')).toStrictEqual(false);
expect(result.fileHashes.has('example/data')).toStrictEqual(false);
expect(result.fileHashes.has('example/data/data.txt')).toStrictEqual(false);
});
it('should return the correct file hashes for mock dir/other', () => {
const result = (0, files_1.getDirectoryFiles)({
directoryPath: mockBasePath,
maxDepth: constants_1.DEFAULT_MAX_DEPTH,
maxDirSize: constants_1.DEFAULT_MAX_DIR_SIZE,
currentPath: 'example/other',
currentDepth: 0,
currentTotalSize: 0,
ignoreManager: ignoreManagerInstance,
});
expect(result.totalSize).toEqual(5);
expect(result.fileHashes.size).toEqual(2);
expect(result.fileHashes.has('example/.gitignore')).toStrictEqual(false);
expect(result.fileHashes.has('example/index.html')).toStrictEqual(false);
expect(result.fileHashes.has('example/other/.gitignore')).toStrictEqual(true);
expect(result.fileHashes.has('example/other/myfile.csv')).toStrictEqual(true);
expect(result.fileHashes.has('example/other/.env')).toStrictEqual(false);
expect(result.fileHashes.has('example/data')).toStrictEqual(false);
expect(result.fileHashes.has('example/data/data.txt')).toStrictEqual(false);
});
});
describe('getDirectoryFiles from subfolder', () => {
let ignoreManagerInstance;
const mockBasePath = path_1.default.join(__dirname, 'mocks/workspace/example');
beforeEach(() => {
ignoreManagerInstance = new ignore_1.IgnoreManager();
jest
.spyOn(ignore_1.IgnoreManager, 'getInstance')
.mockImplementation(() => ignoreManagerInstance);
});
it('should return the correct file hashes for mock dir', () => {
const result = (0, files_1.getDirectoryFiles)({
directoryPath: mockBasePath,
maxDepth: constants_1.DEFAULT_MAX_DEPTH,
maxDirSize: constants_1.DEFAULT_MAX_DIR_SIZE,
currentPath: '',
currentDepth: 0,
currentTotalSize: 0,
ignoreManager: ignoreManagerInstance,
});
expect(result.totalSize).toEqual(2919);
expect(result.fileHashes.size).toEqual(4);
expect(result.fileHashes.has('.gitignore')).toStrictEqual(true);
expect(result.fileHashes.has('index.html')).toStrictEqual(true);
expect(result.fileHashes.has('other/.gitignore')).toStrictEqual(true);
expect(result.fileHashes.has('other/myfile.csv')).toStrictEqual(true);
expect(result.fileHashes.has('other/.env')).toStrictEqual(false);
expect(result.fileHashes.has('data')).toStrictEqual(false);
expect(result.fileHashes.has('data/data.txt')).toStrictEqual(false);
});
it('should return the correct file hashes for mock dir and depth 1', () => {
const result = (0, files_1.getDirectoryFiles)({
directoryPath: mockBasePath,
maxDepth: 1,
maxDirSize: constants_1.DEFAULT_MAX_DIR_SIZE,
currentPath: '',
currentDepth: 0,
currentTotalSize: 0,
ignoreManager: ignoreManagerInstance,
});
expect(result.totalSize).toEqual(2919);
expect(result.fileHashes.size).toEqual(4);
expect(result.fileHashes.has('.gitignore')).toStrictEqual(true);
expect(result.fileHashes.has('index.html')).toStrictEqual(true);
expect(result.fileHashes.has('other/.gitignore')).toStrictEqual(true);
expect(result.fileHashes.has('other/myfile.csv')).toStrictEqual(true);
expect(result.fileHashes.has('other/.env')).toStrictEqual(false);
expect(result.fileHashes.has('data')).toStrictEqual(false);
expect(result.fileHashes.has('data/data.txt')).toStrictEqual(false);
});
it('should return the correct file hashes for mock dir/other', () => {
const result = (0, files_1.getDirectoryFiles)({
directoryPath: mockBasePath,
maxDepth: constants_1.DEFAULT_MAX_DEPTH,
maxDirSize: constants_1.DEFAULT_MAX_DIR_SIZE,
currentPath: 'other',
currentDepth: 0,
currentTotalSize: 0,
ignoreManager: ignoreManagerInstance,
});
expect(result.totalSize).toEqual(5);
expect(result.fileHashes.size).toEqual(2);
expect(result.fileHashes.has('.gitignore')).toStrictEqual(false);
expect(result.fileHashes.has('index.html')).toStrictEqual(false);
expect(result.fileHashes.has('other/.gitignore')).toStrictEqual(true);
expect(result.fileHashes.has('other/myfile.csv')).toStrictEqual(true);
expect(result.fileHashes.has('other/.env')).toStrictEqual(false);
expect(result.fileHashes.has('data')).toStrictEqual(false);
expect(result.fileHashes.has('data/data.txt')).toStrictEqual(false);
});
});