-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest-basic.ts
More file actions
145 lines (120 loc) Β· 4.22 KB
/
test-basic.ts
File metadata and controls
145 lines (120 loc) Β· 4.22 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env bun
/**
* Basic functionality test - verifies the app works without hanging
*/
import { spawn } from "bun";
async function runTest(name: string, command: string[]): Promise<boolean> {
console.log(`π§ͺ Testing: ${name}`);
try {
const proc = spawn({
cmd: command,
stdout: "pipe",
stderr: "pipe",
env: {
...process.env,
NODE_ENV: "test"
}
});
// Set timeout
const timeoutId = setTimeout(() => {
proc.kill();
}, 5000);
const stdout = await new Response(proc.stdout).text();
const stderr = await new Response(proc.stderr).text();
const exitCode = await proc.exited;
clearTimeout(timeoutId);
if (exitCode === 0) {
console.log(` β
${name} - PASSED`);
return true;
} else {
console.log(` β ${name} - FAILED (exit code: ${exitCode})`);
if (stderr) console.log(` Error: ${stderr.slice(0, 100)}...`);
return false;
}
} catch (error) {
console.log(` β ${name} - ERROR: ${error}`);
return false;
}
}
async function testRateLimiting(): Promise<boolean> {
console.log(`π§ͺ Testing: Rate Limiting Modules`);
try {
// Test rate limiting imports
const { RATE_LIMIT_PROFILES } = await import("./src/rateLimit/config.js");
const { RateLimitManager } = await import("./src/rateLimit/manager.js");
const { TweetEstimator } = await import("./src/rateLimit/estimator.js");
// Test basic functionality
const manager = new RateLimitManager();
const status = manager.getStatus();
const estimate = TweetEstimator.estimateCollectionTime(100, RATE_LIMIT_PROFILES.conservative!);
if (status.profile && estimate.estimatedMinutes > 0) {
console.log(` β
Rate Limiting Modules - PASSED`);
return true;
} else {
console.log(` β Rate Limiting Modules - FAILED (invalid data)`);
return false;
}
} catch (error) {
console.log(` β Rate Limiting Modules - ERROR: ${error}`);
return false;
}
}
async function testDatabase(): Promise<boolean> {
console.log(`π§ͺ Testing: Database Modules`);
try {
// Test database imports
const schema = await import("./src/database/schema.js");
const queries = await import("./src/database/queries.js");
if (schema.users && schema.tweets && queries.userQueries && queries.tweetQueries) {
console.log(` β
Database Modules - PASSED`);
return true;
} else {
console.log(` β Database Modules - FAILED (missing exports)`);
return false;
}
} catch (error) {
console.log(` β Database Modules - ERROR: ${error}`);
return false;
}
}
async function main() {
console.log("π XGPT CLI Basic Test Suite");
console.log("=" .repeat(40));
console.log();
const tests = [
// CLI tests
{ name: "CLI Help", command: ["bun", "run", "src/cli.ts", "--help"] },
{ name: "CLI Version", command: ["bun", "run", "src/cli.ts", "--version"] },
{ name: "Database Stats", command: ["bun", "run", "src/cli.ts", "db", "--stats"] },
{ name: "Scrape Help", command: ["bun", "run", "src/cli.ts", "scrape", "--help"] },
{ name: "Build", command: ["bun", "build", "src/cli.ts", "--outdir", "./dist", "--target", "bun"] }
];
let passed = 0;
let total = tests.length + 2; // +2 for module tests
// Run CLI tests
for (const test of tests) {
const success = await runTest(test.name, test.command);
if (success) passed++;
}
// Run module tests
if (await testRateLimiting()) passed++;
if (await testDatabase()) passed++;
console.log();
console.log("π RESULTS");
console.log("-" .repeat(20));
console.log(`Passed: ${passed}/${total}`);
console.log(`Success Rate: ${Math.round((passed / total) * 100)}%`);
console.log();
if (passed === total) {
console.log("π ALL TESTS PASSED!");
console.log(" The XGPT CLI basic functionality is working!");
} else if (passed >= total * 0.8) {
console.log("β
MOST TESTS PASSED!");
console.log(" The XGPT CLI core functionality is working.");
} else {
console.log("β TESTS FAILED!");
console.log(" Critical issues found in basic functionality.");
}
process.exit(passed === total ? 0 : 1);
}
main().catch(console.error);