Skip to content

Commit 3c1bedd

Browse files
authored
Merge pull request #16 from ziquid/ai-findings-autofix/tests-test-temperature-suite.cjs
Potential fixes for 4 code quality findings
2 parents 54851e1 + 1f56e56 commit 3c1bedd

2 files changed

Lines changed: 88 additions & 31 deletions

File tree

src/index.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,15 @@ program
460460
.option(
461461
"-t, --temperature <temp>",
462462
"temperature for API requests (0.0-2.0, default: 0.7)",
463-
"0.7"
463+
(value) => {
464+
const temp = parseFloat(value);
465+
if (isNaN(temp) || temp < 0 || temp > 2) {
466+
console.error(`Error: Temperature must be between 0.0 and 2.0 (got ${value})`);
467+
process.exit(1);
468+
}
469+
return temp;
470+
},
471+
0.7
464472
)
465473
.option(
466474
"--max-tokens <tokens>",
@@ -610,7 +618,7 @@ program
610618
.filter(cmd => cmd.length > 0)
611619
: [];
612620

613-
const temperature = parseFloat(options.temperature) || 0.7;
621+
const temperature = options.temperature ?? 0.7;
614622
const maxTokens = options.maxTokens ? parseInt(options.maxTokens) : undefined;
615623

616624
await processPromptHeadless(
@@ -639,7 +647,7 @@ program
639647
const loadedContext = options.fresh ? { systemPrompt: "", chatHistory: [] } : historyManager.loadContext();
640648
const hasSystemPrompt = loadedContext.systemPrompt && loadedContext.systemPrompt.trim().length > 0;
641649
const runStartupHook = !hasSystemPrompt; // Run hook if no system prompt exists
642-
const temperature = parseFloat(options.temperature) || 0.7;
650+
const temperature = options.temperature ?? 0.7;
643651
const maxTokens = options.maxTokens ? parseInt(options.maxTokens) : undefined;
644652
const agent = await createGrokAgent(apiKey, baseURL, model, maxToolRounds, options.debugLog, runStartupHook, temperature, maxTokens);
645653
currentAgent = agent; // Store reference for cleanup
@@ -1070,7 +1078,15 @@ gitCommand
10701078
.option(
10711079
"-t, --temperature <temp>",
10721080
"temperature for API requests (0.0-2.0, default: 0.7)",
1073-
"0.7"
1081+
(value) => {
1082+
const temp = parseFloat(value);
1083+
if (isNaN(temp) || temp < 0 || temp > 2) {
1084+
console.error(`Error: Temperature must be between 0.0 and 2.0 (got ${value})`);
1085+
process.exit(1);
1086+
}
1087+
return temp;
1088+
},
1089+
0.7
10741090
)
10751091
.option(
10761092
"--max-tokens <tokens>",
@@ -1118,7 +1134,7 @@ gitCommand
11181134
}
11191135

11201136
const maxToolRounds = parseInt(options.maxToolRounds) || 400;
1121-
const temperature = parseFloat(options.temperature) || 0.7;
1137+
const temperature = options.temperature ?? 0.7;
11221138

11231139
// Validate API key
11241140
try {

tests/test-temperature-suite.cjs

100644100755
Lines changed: 67 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
/**
33
* COMPREHENSIVE TEST SUITE FOR TEMPERATURE SETTINGS FEATURE
4-
* All 23 test cases from the allow-temperature-changes test plan
4+
* Implements 6 test cases from the allow-temperature-changes test plan (TC001-TC006)
55
* Created for 10-minute deadline
66
*/
77

@@ -11,7 +11,9 @@ const { execSync } = require('child_process');
1111
class TemperatureTestSuite {
1212
constructor() {
1313
this.results = [];
14-
this.passed = this.failed = this.skipped = 0;
14+
this.passed = 0;
15+
this.failed = 0;
16+
this.skipped = 0;
1517
this.startTime = Date.now();
1618
}
1719

@@ -21,16 +23,16 @@ class TemperatureTestSuite {
2123

2224
async record(id, name, status, details, expected = '') {
2325
this.results.push({ id, name, status, details, expected });
24-
25-
if (status === 'PASS') {
26-
this.passed++;
27-
this.log(`✓ PASS: ${id} - ${name}`, '\x1b[32m');
28-
} else if (status === 'FAIL') {
29-
this.failed++;
30-
this.log(`✗ FAIL: ${id} - ${name}`, '\x1b[31m');
31-
} else {
32-
this.skipped++;
33-
this.log(`⊘ SKIP: ${id} - ${name}`, '\x1b[33m');
26+
27+
if (status === 'PASS') {
28+
this.passed++;
29+
this.log(`✓ PASS: ${id} - ${name}`, '\x1b[32m');
30+
} else if (status === 'FAIL') {
31+
this.failed++;
32+
this.log(`✗ FAIL: ${id} - ${name}`, '\x1b[31m');
33+
} else {
34+
this.skipped++;
35+
this.log(`⊘ SKIP: ${id} - ${name}`, '\x1b[33m');
3436
}
3537
}
3638

@@ -46,7 +48,7 @@ class TemperatureTestSuite {
4648
printSummary() {
4749
const duration = ((Date.now() - this.startTime) / 1000).toFixed(2);
4850
const total = this.passed + this.failed + this.skipped;
49-
51+
5052
this.log('\n═══════════════════════════════════════════════', '\x1b[36m');
5153
this.log('║ TEST SUMMARY ║', '\x1b[36m');
5254
this.log('═══════════════════════════════════════════════', '\x1b[36m');
@@ -56,15 +58,15 @@ class TemperatureTestSuite {
5658
this.log(`Skipped: ${this.skipped}`, '\x1b[33m');
5759
this.log(`Execution Time: ${duration}s`);
5860
this.log('');
59-
61+
6062
// Save JSON results
6163
const report = {
6264
summary: { total, passed: this.passed, failed: this.failed, skipped: this.skipped, duration },
6365
results: this.results,
6466
generatedAt: new Date().toISOString(),
6567
testSuite: 'Temperature Settings Feature'
6668
};
67-
69+
6870
try {
6971
fs.writeFileSync(`temperature-test-results-${Date.now()}.json`, JSON.stringify(report, null, 2));
7072
this.log('Results saved to JSON file', '\x1b[34m');
@@ -74,38 +76,77 @@ class TemperatureTestSuite {
7476
}
7577

7678
// ==================== ALL 23 TEST CASES ====================
77-
79+
7880
async testTC001_CLI_Valid() {
79-
const check = await this.run('node ./dist/index.js --help 2>&1 || echo "no help"');
80-
await this.record('TC001', 'CLI: --temperature flag available',
81-
check.output.includes('temperature') ? 'PASS' : 'SKIP',
82-
check.output.includes('temperature') ? 'Temperature option found' : 'Feature not yet implemented');
81+
const check = await this.run('node ./dist/index.js --help 2>&1');
82+
// Fallback to "no help" if command failed and no output is available
83+
const output = (check.success && check.output) ? check.output : 'no help';
84+
await this.record('TC001', 'CLI: --temperature flag available',
85+
output.includes('temperature') ? 'PASS' : 'SKIP',
86+
output.includes('temperature') ? 'Temperature option found' : 'Feature not yet implemented');
8387
}
8488

8589
async testTC002_CLI_Short() {
8690
const check = await this.run('node ./dist/index.js --help 2>&1');
87-
await this.record('TC002', 'CLI: -t short flag',
91+
await this.record('TC002', 'CLI: -t short flag',
8892
check.output.includes('-t') ? 'PASS' : 'SKIP',
8993
check.output.includes('-t') ? 'Short flag found' : 'Feature not yet implemented');
9094
}
9195

9296
async testTC003_CLI_Boundaries() {
93-
await this.record('TC003', 'CLI: Boundary values (0.0, 5.0)', 'SKIP', 'Feature not yet implemented');
97+
// Test lower boundary 0.0
98+
const lowCheck = await this.run('node ./dist/index.js --help --temperature 0.0 2>&1');
99+
// Test upper boundary 2.0
100+
const highCheck = await this.run('node ./dist/index.js --help --temperature 2.0 2>&1');
101+
// Test out-of-range value to verify rejection
102+
const invalidCheck = await this.run('node ./dist/index.js --help --temperature 5.0 2>&1');
103+
// Values are valid if no error about temperature AND invalid value is rejected
104+
const lowValid = !lowCheck.output.match(/temperature must be/i);
105+
const highValid = !highCheck.output.match(/temperature must be/i);
106+
const invalidRejected = invalidCheck.output.match(/temperature must be/i);
107+
await this.record(
108+
'TC003',
109+
'CLI: Boundary values (0.0, 2.0)',
110+
(lowValid && highValid && invalidRejected) ? 'PASS' : 'FAIL',
111+
(lowValid && highValid && invalidRejected) ? 'Boundary values 0.0 and 2.0 accepted, 5.0 rejected' : 'Boundary value validation failed'
112+
);
94113
}
95114

96115
async testTC004_CLI_Default() {
97-
await this.record('TC004', 'CLI: Default temperature value', 'SKIP', 'Feature not yet implemented');
116+
// Run with no --temperature arg
117+
const check = await this.run('node ./dist/index.js --help 2>&1');
118+
// Search for a default value in output (use [\s\S]*? for non-greedy match across lines)
119+
const foundDefault = check.output.match(/temperature[\s\S]*?(default:\s*[0-9.]+)/i);
120+
await this.record(
121+
'TC004',
122+
'CLI: Default temperature value',
123+
foundDefault ? 'PASS' : 'FAIL',
124+
foundDefault ? `Default temperature found: ${foundDefault[1]}`
125+
: 'Default temperature not shown'
126+
);
98127
}
99128

100129
async testTC005_CLI_Invalid() {
101-
await this.record('TC005', 'CLI: Invalid temperature rejection', 'SKIP', 'Feature not yet implemented');
130+
// Try an invalid value (-1)
131+
const negCheck = await this.run('node ./dist/index.js --temperature -1 2>&1');
132+
// Try a non-numeric value
133+
const alphaCheck = await this.run('node ./dist/index.js --temperature abc 2>&1');
134+
// Look for "invalid" or error message in output (customize regex as needed)
135+
const negRejected = negCheck.output.match(/invalid|error|not allowed|out of range/i);
136+
const alphaRejected = alphaCheck.output.match(/invalid|error|not allowed|must be a number/i);
137+
await this.record(
138+
'TC005',
139+
'CLI: Invalid temperature rejection',
140+
(negRejected && alphaRejected) ? 'PASS' : 'FAIL',
141+
(negRejected && alphaRejected) ? 'Invalid values correctly rejected' : 'Expected rejection of invalid values'
142+
);
102143
}
103144

104145
async testTC006_Hook_Command() {
105-
const check = await this.run('grep -r "TEMPERATURE" ./src/ 2>/dev/null || echo "not found"');
146+
const check = await this.run('grep -r TEMPERATURE ./src/ 2>/dev/null || echo "not found"');
106147
await this.record('TC006', 'Hook: TEMPERATURE command processing',
107148
check.output.includes('TEMPERATURE') ? 'PASS' : 'SKIP',
108-
check.output.includes('TEMPERATURE') ? 'TEMPERATURE command found' : 'Feature not yet implemented');
149+
check.output.includes('TEMPERATURE') ? 'TEMPERATURE constant found' : 'TEMPERATURE constant NOT FOUND');
109150
}
110151

111152
// Main execution

0 commit comments

Comments
 (0)