#!/usr/bin/env node
/**
* File Operations Tests
* Verifies CRUD operations, search, and advanced file handling
*/
const fs = require('fs');
const path = require('path');
console.log('š File Operations Verification\n');
let passed = 0;
let failed = 0;
function test(name, condition) {
if (condition) {
console.log(`ā
${name}`);
passed++;
} else {
console.log(`ā ${name}`);
failed++;
}
}
function checkFile(filePath, content) {
try {
const fullPath = path.join(__dirname, '..', filePath);
if (!fs.existsSync(fullPath)) return false;
const fileContent = fs.readFileSync(fullPath, 'utf-8');
if (Array.isArray(content)) {
return content.every(c => fileContent.includes(c));
}
return content ? fileContent.includes(content) : true;
} catch (e) {
return false;
}
}
// Basic CRUD Operations
console.log('š Basic File CRUD Operations');
test('File listing (gas_ls)', checkFile('src/tools/filesystem.ts', 'gas_ls'));
test('File reading (gas_cat)', checkFile('src/tools/filesystem.ts', 'gas_cat'));
test('File writing (gas_write)', checkFile('src/tools/filesystem.ts', 'gas_write'));
test('File deletion (gas_rm)', checkFile('src/tools/filesystem.ts', 'gas_rm'));
test('File copying (gas_cp)', checkFile('src/tools/filesystem.ts', 'gas_cp'));
test('File moving (gas_mv)', checkFile('src/tools/filesystem.ts', 'gas_mv'));
console.log('\nš Search and Discovery');
test('File finding (gas_find)', checkFile('src/tools/find.ts', 'gas_find'));
test('Content searching (gas_grep)', checkFile('src/tools/grep.ts', 'gas_grep'));
test('Pattern matching support', checkFile('src/tools/find.ts', ['wildcard', 'regex']));
test('Advanced search filters', checkFile('src/tools/grep.ts', ['caseSensitive', 'wholeWord']));
console.log('\nš File Transformations');
test('CommonJS integration', checkFile('src/tools/filesystem.ts', 'CommonJS'));
test('File type detection', checkFile('src/utils/virtualFileTranslation.ts', ['SERVER_JS', 'HTML', 'JSON']));
test('Virtual file translation', checkFile('src/utils/virtualFileTranslation.ts', '.git'));
test('Binary file handling', checkFile('src/utils/virtualFileTranslation.ts', 'base64'));
console.log('\nš Path and Metadata Handling');
test('Path parsing utility', checkFile('src/utils/pathParser.ts'));
test('Script ID validation', checkFile('src/utils/validation.ts', 'scriptId'));
test('File extension handling', checkFile('src/utils/pathParser.ts', 'extension'));
test('Virtual path support', checkFile('src/utils/pathParser.ts', 'virtual'));
console.log('\nā” Advanced Features');
test('Concurrent file operations', checkFile('src/tools/filesystem.ts', ['Promise.all', 'batch']));
test('File position management', checkFile('src/tools/filesystem.ts', 'position'));
test('Local caching support', checkFile('src/tools/filesystem.ts', ['local', 'cache']));
test('Remote-first workflow', checkFile('src/tools/filesystem.ts', 'remote'));
console.log('\nš”ļø Safety and Error Handling');
test('File operation validation', checkFile('src/tools/filesystem.ts', ['validate', 'schema']));
test('Path traversal prevention', checkFile('src/utils/pathParser.ts', ['sanitize', 'normalize']));
test('Error recovery mechanisms', checkFile('src/tools/filesystem.ts', ['try', 'catch', 'retry']));
test('Quota management', checkFile('src/tools/filesystem.ts', ['quota', 'limit']));
console.log('\nš Integration Features');
test('Git integration ready', checkFile('src/tools/filesystem.ts', ['.git', 'sync']));
test('Project context awareness', checkFile('src/tools/filesystem.ts', 'project'));
test('Multi-format support', checkFile('src/tools/filesystem.ts', ['HTML', 'JSON', 'SERVER_JS']));
console.log('\nš Results:');
console.log(`ā
Passed: ${passed}`);
console.log(`ā Failed: ${failed}`);
if (failed === 0) {
console.log('\nš File operations system fully verified!');
console.log('\nš Capabilities confirmed:');
console.log(' ⢠Complete CRUD operations (create, read, update, delete)');
console.log(' ⢠Advanced search and discovery (find, grep, patterns)');
console.log(' ⢠File transformations (CommonJS, virtual files)');
console.log(' ⢠Safety features (validation, error handling)');
console.log(' ⢠Integration ready (git, projects, multi-format)');
console.log(' ⢠Performance optimized (caching, concurrent ops)');
} else {
console.log('\nā ļø File operations system needs attention');
}