mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-06 01:03:32 +08:00
test: add 3 tests for stdin 1MB overflow and analyzePhase async method (round 87)
- post-edit-format.js: verify MAX_STDIN truncation at 1MB limit - post-edit-typecheck.js: verify MAX_STDIN truncation at 1MB limit - skill-create-output.js: test analyzePhase() returns Promise and writes output
This commit is contained in:
@@ -3446,6 +3446,41 @@ Some random content without the expected ### Context to Load section
|
|||||||
}
|
}
|
||||||
})) passed++; else failed++;
|
})) passed++; else failed++;
|
||||||
|
|
||||||
|
// ── Round 87: post-edit-format.js and post-edit-typecheck.js stdin overflow (1MB) ──
|
||||||
|
console.log('\nRound 87: post-edit-format.js (stdin exceeding 1MB — truncation):');
|
||||||
|
|
||||||
|
if (await asyncTest('truncates stdin at 1MB limit and still passes through data (post-edit-format)', async () => {
|
||||||
|
// Send 1.2MB of data — exceeds the 1MB MAX_STDIN limit (lines 14-22)
|
||||||
|
const payload = 'x'.repeat(1024 * 1024 + 200000);
|
||||||
|
const result = await runScript(path.join(scriptsDir, 'post-edit-format.js'), payload);
|
||||||
|
|
||||||
|
assert.strictEqual(result.code, 0, 'Should exit 0 even with oversized stdin');
|
||||||
|
// Output should be truncated — significantly less than input
|
||||||
|
assert.ok(result.stdout.length < payload.length,
|
||||||
|
`stdout (${result.stdout.length}) should be shorter than input (${payload.length})`);
|
||||||
|
// Output should be approximately 1MB (last accepted chunk may push slightly over)
|
||||||
|
assert.ok(result.stdout.length <= 1024 * 1024 + 65536,
|
||||||
|
`stdout (${result.stdout.length}) should be near 1MB, not unbounded`);
|
||||||
|
assert.ok(result.stdout.length > 0, 'Should still pass through truncated data');
|
||||||
|
})) passed++; else failed++;
|
||||||
|
|
||||||
|
console.log('\nRound 87: post-edit-typecheck.js (stdin exceeding 1MB — truncation):');
|
||||||
|
|
||||||
|
if (await asyncTest('truncates stdin at 1MB limit and still passes through data (post-edit-typecheck)', async () => {
|
||||||
|
// Send 1.2MB of data — exceeds the 1MB MAX_STDIN limit (lines 16-24)
|
||||||
|
const payload = 'x'.repeat(1024 * 1024 + 200000);
|
||||||
|
const result = await runScript(path.join(scriptsDir, 'post-edit-typecheck.js'), payload);
|
||||||
|
|
||||||
|
assert.strictEqual(result.code, 0, 'Should exit 0 even with oversized stdin');
|
||||||
|
// Output should be truncated — significantly less than input
|
||||||
|
assert.ok(result.stdout.length < payload.length,
|
||||||
|
`stdout (${result.stdout.length}) should be shorter than input (${payload.length})`);
|
||||||
|
// Output should be approximately 1MB (last accepted chunk may push slightly over)
|
||||||
|
assert.ok(result.stdout.length <= 1024 * 1024 + 65536,
|
||||||
|
`stdout (${result.stdout.length}) should be near 1MB, not unbounded`);
|
||||||
|
assert.ok(result.stdout.length > 0, 'Should still pass through truncated data');
|
||||||
|
})) passed++; else failed++;
|
||||||
|
|
||||||
// Summary
|
// Summary
|
||||||
console.log('\n=== Test Results ===');
|
console.log('\n=== Test Results ===');
|
||||||
console.log(`Passed: ${passed}`);
|
console.log(`Passed: ${passed}`);
|
||||||
|
|||||||
@@ -497,6 +497,34 @@ function runTests() {
|
|||||||
'Should NOT show 80% — confidence=0 is explicitly provided, not missing');
|
'Should NOT show 80% — confidence=0 is explicitly provided, not missing');
|
||||||
})) passed++; else failed++;
|
})) passed++; else failed++;
|
||||||
|
|
||||||
|
// ── Round 87: analyzePhase() async method (untested) ──
|
||||||
|
console.log('\nRound 87: analyzePhase() async method:');
|
||||||
|
|
||||||
|
if (test('analyzePhase completes without error and writes to stdout', () => {
|
||||||
|
const output = new SkillCreateOutput('test-repo');
|
||||||
|
// analyzePhase is async and calls animateProgress which uses sleep() and
|
||||||
|
// process.stdout.write/clearLine/cursorTo. In non-TTY environments clearLine
|
||||||
|
// and cursorTo are undefined, but the code uses optional chaining (?.) to
|
||||||
|
// handle this safely. We verify it resolves without throwing.
|
||||||
|
// Capture stdout.write to verify output was produced.
|
||||||
|
const writes = [];
|
||||||
|
const origWrite = process.stdout.write;
|
||||||
|
process.stdout.write = function(str) { writes.push(String(str)); return true; };
|
||||||
|
try {
|
||||||
|
// Call synchronously by accessing the returned promise — we just need to
|
||||||
|
// verify it doesn't throw during setup. The sleeps total 1.9s so we
|
||||||
|
// verify the promise is a thenable (async function returns Promise).
|
||||||
|
const promise = output.analyzePhase({ commits: 42 });
|
||||||
|
assert.ok(promise && typeof promise.then === 'function',
|
||||||
|
'analyzePhase should return a Promise');
|
||||||
|
} finally {
|
||||||
|
process.stdout.write = origWrite;
|
||||||
|
}
|
||||||
|
// Verify that process.stdout.write was called (the header line is written synchronously)
|
||||||
|
assert.ok(writes.length > 0, 'Should have written output via process.stdout.write');
|
||||||
|
assert.ok(writes.some(w => w.includes('Analyzing')), 'Should include "Analyzing" label');
|
||||||
|
})) passed++; else failed++;
|
||||||
|
|
||||||
// Summary
|
// Summary
|
||||||
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
|
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
|
||||||
process.exit(failed > 0 ? 1 : 0);
|
process.exit(failed > 0 ? 1 : 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user