Skip to content

armgit / ECC

Public Imported from GitHub
0

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

test: add Round 117 edge-case tests for grepFile CRLF, getSessionSize boundaries, and parseSessionFilename case

Affaan Mustafa06af1acb8daa
diff --git a/tests/lib/session-manager.test.js b/tests/lib/session-manager.test.js
index a65302572..63a556a9d 100644
--- a/tests/lib/session-manager.test.js
+++ b/tests/lib/session-manager.test.js
@@ -2111,6 +2111,81 @@ file.ts
'Should find at least 1 completed item in CRLF-only content');
})) passed++; else failed++;
+ // ── Round 117: getSessionSize boundary values — B/KB/MB formatting thresholds ──
+ console.log('\nRound 117: getSessionSize (B/KB/MB formatting at exact boundary thresholds):');
+ if (test('getSessionSize formats correctly at B→KB boundary (1023→"1023 B", 1024→"1.0 KB") and KB→MB', () => {
+ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'r117-size-boundary-'));
+ try {
+ // Zero-byte file
+ const zeroFile = path.join(tmpDir, '2026-01-01-session.tmp');
+ fs.writeFileSync(zeroFile, '');
+ assert.strictEqual(sessionManager.getSessionSize(zeroFile), '0 B',
+ 'Empty file should be "0 B"');
+
+ // 1 byte file
+ const oneByteFile = path.join(tmpDir, '2026-01-02-session.tmp');
+ fs.writeFileSync(oneByteFile, 'x');
+ assert.strictEqual(sessionManager.getSessionSize(oneByteFile), '1 B',
+ 'Single byte file should be "1 B"');
+
+ // 1023 bytes — last value in B range (size < 1024)
+ const file1023 = path.join(tmpDir, '2026-01-03-session.tmp');
+ fs.writeFileSync(file1023, 'x'.repeat(1023));
+ assert.strictEqual(sessionManager.getSessionSize(file1023), '1023 B',
+ '1023 bytes is still in B range (< 1024)');
+
+ // 1024 bytes — first value in KB range (size >= 1024, < 1024*1024)
+ const file1024 = path.join(tmpDir, '2026-01-04-session.tmp');
+ fs.writeFileSync(file1024, 'x'.repeat(1024));
+ assert.strictEqual(sessionManager.getSessionSize(file1024), '1.0 KB',
+ '1024 bytes = exactly 1.0 KB');
+
+ // 1025 bytes — KB with decimal
+ const file1025 = path.join(tmpDir, '2026-01-05-session.tmp');
+ fs.writeFileSync(file1025, 'x'.repeat(1025));
+ assert.strictEqual(sessionManager.getSessionSize(file1025), '1.0 KB',
+ '1025 bytes rounds to 1.0 KB (1025/1024 = 1.000...)');
+
+ // Non-existent file returns '0 B'
+ assert.strictEqual(sessionManager.getSessionSize('/nonexistent/file.tmp'), '0 B',
+ 'Non-existent file should return "0 B"');
+ } finally {
+ fs.rmSync(tmpDir, { recursive: true, force: true });
+ }
+ })) passed++; else failed++;
+
+ // ── Round 117: parseSessionFilename with uppercase short ID — regex rejects [A-Z] ──
+ console.log('\nRound 117: parseSessionFilename (uppercase short ID — regex [a-z0-9] rejects uppercase):');
+ if (test('parseSessionFilename rejects uppercase short IDs because regex uses [a-z0-9] not [a-zA-Z0-9]', () => {
+ // The regex: /^(\d{4}-\d{2}-\d{2})(?:-([a-z0-9]{8,}))?-session\.tmp$/
+ // Note: [a-z0-9] — lowercase only
+
+ // All uppercase — rejected
+ const upper = sessionManager.parseSessionFilename('2026-01-15-ABCDEFGH-session.tmp');
+ assert.strictEqual(upper, null,
+ 'All-uppercase ID should be rejected (regex uses [a-z0-9])');
+
+ // Mixed case — rejected
+ const mixed = sessionManager.parseSessionFilename('2026-01-15-AbCdEfGh-session.tmp');
+ assert.strictEqual(mixed, null,
+ 'Mixed-case ID should be rejected (uppercase chars not in [a-z0-9])');
+
+ // All lowercase — accepted
+ const lower = sessionManager.parseSessionFilename('2026-01-15-abcdefgh-session.tmp');
+ assert.notStrictEqual(lower, null, 'All-lowercase ID should be accepted');
+ assert.strictEqual(lower.shortId, 'abcdefgh');
+
+ // Uppercase hex-like (common in UUIDs) — rejected
+ const hexUpper = sessionManager.parseSessionFilename('2026-01-15-A1B2C3D4-session.tmp');
+ assert.strictEqual(hexUpper, null,
+ 'Uppercase hex ID should be rejected');
+
+ // Lowercase hex — accepted
+ const hexLower = sessionManager.parseSessionFilename('2026-01-15-a1b2c3d4-session.tmp');
+ assert.notStrictEqual(hexLower, null, 'Lowercase hex ID should be accepted');
+ assert.strictEqual(hexLower.shortId, 'a1b2c3d4');
+ })) passed++; else failed++;
+
// Summary
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
process.exit(failed > 0 ? 1 : 0);
diff --git a/tests/lib/utils.test.js b/tests/lib/utils.test.js
index cd03462f4..d5fc69e8a 100644
--- a/tests/lib/utils.test.js
+++ b/tests/lib/utils.test.js
@@ -1833,6 +1833,42 @@ function runTests() {
}
})) passed++; else failed++;
+ // ── Round 117: grepFile with CRLF content — split('\n') leaves \r, anchored patterns fail ──
+ console.log('\nRound 117: grepFile (CRLF content — trailing \\r breaks anchored regex patterns):');
+ if (test('grepFile with CRLF content: unanchored patterns work but anchored $ fails due to trailing \\r', () => {
+ const tmpDir = fs.mkdtempSync(path.join(utils.getTempDir(), 'r117-grep-crlf-'));
+ const testFile = path.join(tmpDir, 'test.txt');
+ try {
+ // Write CRLF content
+ fs.writeFileSync(testFile, 'hello\r\nworld\r\nfoo bar\r\n');
+
+ // Unanchored pattern works — 'hello' matches in 'hello\r'
+ const unanchored = utils.grepFile(testFile, 'hello');
+ assert.strictEqual(unanchored.length, 1, 'Unanchored pattern should find 1 match');
+ assert.strictEqual(unanchored[0].lineNumber, 1, 'Should be on line 1');
+ assert.ok(unanchored[0].content.endsWith('\r'),
+ 'Line content should have trailing \\r from split("\\n") on CRLF');
+
+ // Anchored pattern /^hello$/ does NOT match 'hello\r' because $ is before \r
+ const anchored = utils.grepFile(testFile, /^hello$/);
+ assert.strictEqual(anchored.length, 0,
+ 'Anchored /^hello$/ should NOT match "hello\\r" — $ fails before \\r');
+
+ // But /^hello\r?$/ or /^hello/ work
+ const withOptCr = utils.grepFile(testFile, /^hello\r?$/);
+ assert.strictEqual(withOptCr.length, 1,
+ '/^hello\\r?$/ matches "hello\\r" because \\r? consumes the trailing CR');
+
+ // Contrast: LF-only content works with anchored patterns
+ fs.writeFileSync(testFile, 'hello\nworld\nfoo bar\n');
+ const lfAnchored = utils.grepFile(testFile, /^hello$/);
+ assert.strictEqual(lfAnchored.length, 1,
+ 'LF-only content: anchored /^hello$/ matches normally');
+ } finally {
+ fs.rmSync(tmpDir, { recursive: true, force: true });
+ }
+ })) passed++; else failed++;
+
// ── Round 116: replaceInFile with null/undefined replacement — JS coerces to string ──
console.log('\nRound 116: replaceInFile (null/undefined replacement — JS coerces to string "null"/"undefined"):');
if (test('replaceInFile with null replacement coerces to string "null" via String.replace ToString', () => {