-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-codex-export-v2.js
More file actions
131 lines (110 loc) Β· 4.57 KB
/
test-codex-export-v2.js
File metadata and controls
131 lines (110 loc) Β· 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env node
// Improved test for codexRepository function export with better mocking
// Import ts-node to handle TypeScript files
require('ts-node').register({ transpileOnly: true });
console.log('π§ͺ TESTING FUNCTION EXPORT (IMPROVED VERSION)');
console.log('Attempting to import codexRepository function from src/lib/codex.ts...');
// Set up mocks BEFORE importing the module
const child_process = require('child_process');
const fs = require('fs');
const path = require('path');
const os = require('os');
// Save original functions
const originalExecSync = child_process.execSync;
const originalMkdtempSync = fs.mkdtempSync;
const originalWriteFileSync = fs.writeFileSync;
const originalUnlinkSync = fs.unlinkSync;
const originalExistsSync = fs.existsSync;
// Mock execSync to prevent any actual commands from running
child_process.execSync = function(command, options) {
console.log(`[MOCK] execSync: ${command.substring(0, 50)}${command.length > 50 ? '...' : ''}`);
return 'mocked output';
};
// Mock fs.mkdtempSync to return a predictable path
fs.mkdtempSync = function(prefix) {
console.log(`[MOCK] mkdtempSync: ${prefix}`);
return '/mock/temp/dir';
};
// Mock fs.writeFileSync to prevent actual file creation
fs.writeFileSync = function(filePath, content, options) {
console.log(`[MOCK] writeFileSync: ${filePath}`);
return;
};
// Mock fs.unlinkSync to prevent actual file deletion
fs.unlinkSync = function(filePath) {
console.log(`[MOCK] unlinkSync: ${filePath}`);
return;
};
// Mock fs.existsSync to always return true
fs.existsSync = function(path) {
console.log(`[MOCK] existsSync: ${path}`);
return true;
};
try {
// Now import the module with all mocks in place
const codexModule = require('./src/lib/codex');
// Check if codexRepository is exported
if (typeof codexModule.codexRepository !== 'function') {
console.error('β codexRepository is not exported as a function!');
console.error(`Type of codexModule.codexRepository: ${typeof codexModule.codexRepository}`);
console.log('Available exports:');
console.log(Object.keys(codexModule));
process.exit(1);
}
// Check function signature
const functionStr = codexModule.codexRepository.toString();
console.log('\nπ Function signature:');
const signature = functionStr.split('{')[0].trim();
console.log(signature);
// Check basic signature requirements
const hasCorrectParams = signature.includes('prompt') &&
signature.includes('repoUrl') &&
signature.includes('branchName') &&
signature.includes('installationId');
if (hasCorrectParams) {
console.log('β
Function has the expected parameters');
} else {
console.warn('β οΈ Function parameters might not match expectations');
console.log('Expected: prompt, repoUrl, branchName, installationId (optional)');
}
// Check if function is async/returns Promise
const isAsync = signature.includes('async') || /Promise\s*</.test(functionStr);
if (isAsync) {
console.log('β
Function is async or returns a Promise');
} else {
console.warn('β οΈ Function may not be async/return a Promise as expected');
}
// Test calling the function with minimal parameters
console.log('\nπ CALLING FUNCTION WITH TEST PARAMETERS:');
try {
const promise = codexModule.codexRepository(
'Test prompt',
'https://github.com/example/repo.git',
'test-branch'
);
if (promise instanceof Promise) {
console.log('β
Function returned a Promise object');
} else {
console.warn(`β οΈ Function returned ${typeof promise}, not a Promise`);
}
// Just let the promise run without awaiting it
// Our mocks will prevent any real operations
console.log('Function call initiated successfully');
} catch (error) {
console.error('β Error calling function:', error.message);
}
console.log('\nπ SUMMARY:');
console.log('β
The codexRepository function is properly exported');
console.log('β
The function can be imported correctly');
console.log('β
Function calls can be initiated with the expected parameters');
console.log('NOTE: Full execution was prevented by mocks to avoid external calls');
} catch (error) {
console.error('β Error during test:', error);
} finally {
// Restore all original functions to prevent side effects
child_process.execSync = originalExecSync;
fs.mkdtempSync = originalMkdtempSync;
fs.writeFileSync = originalWriteFileSync;
fs.unlinkSync = originalUnlinkSync;
fs.existsSync = originalExistsSync;
}