From 485def8582a414f7ca9a400f2dbe00f495d14952 Mon Sep 17 00:00:00 2001 From: Affaan Mustafa Date: Fri, 13 Feb 2026 07:04:55 -0800 Subject: [PATCH] test: add 3 tests for evaluate-session regex, empty rules/skills dirs (Round 65) - evaluate-session.js: verify regex whitespace tolerance around colon matches "type" : "user" (with spaces), not just compact JSON - validate-rules.js: empty directory with no .md files yields Validated 0 - validate-skills.js: directory with only files, no subdirectories yields Validated 0 Total: 800 tests, all passing --- tests/ci/validators.test.js | 29 ++++++++++++++++++++++++++++ tests/hooks/evaluate-session.test.js | 27 ++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/tests/ci/validators.test.js b/tests/ci/validators.test.js index d0c69c4f..679fdd5c 100644 --- a/tests/ci/validators.test.js +++ b/tests/ci/validators.test.js @@ -1866,6 +1866,35 @@ function runTests() { cleanupTestDir(testDir); })) passed++; else failed++; + // ── Round 65: empty directories for rules and skills ── + console.log('\nRound 65: validate-rules.js (empty directory — no .md files):'); + + if (test('passes on rules directory with no .md files (Validated 0)', () => { + const testDir = createTestDir(); + // Only non-.md files — readdirSync filter yields empty array + fs.writeFileSync(path.join(testDir, 'notes.txt'), 'not a rule'); + fs.writeFileSync(path.join(testDir, 'config.json'), '{}'); + + const result = runValidatorWithDir('validate-rules', 'RULES_DIR', testDir); + assert.strictEqual(result.code, 0, 'Should pass on empty rules directory'); + assert.ok(result.stdout.includes('Validated 0'), 'Should report 0 validated rule files'); + cleanupTestDir(testDir); + })) passed++; else failed++; + + console.log('\nRound 65: validate-skills.js (empty directory — no subdirectories):'); + + if (test('passes on skills directory with only files, no subdirectories (Validated 0)', () => { + const testDir = createTestDir(); + // Only files, no subdirectories — isDirectory filter yields empty array + fs.writeFileSync(path.join(testDir, 'README.md'), '# Skills'); + fs.writeFileSync(path.join(testDir, '.gitkeep'), ''); + + const result = runValidatorWithDir('validate-skills', 'SKILLS_DIR', testDir); + assert.strictEqual(result.code, 0, 'Should pass on skills directory with no subdirectories'); + assert.ok(result.stdout.includes('Validated 0'), 'Should report 0 validated skill directories'); + cleanupTestDir(testDir); + })) passed++; else failed++; + // Summary console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`); process.exit(failed > 0 ? 1 : 0); diff --git a/tests/hooks/evaluate-session.test.js b/tests/hooks/evaluate-session.test.js index f5c7ddc6..bf01b9fd 100644 --- a/tests/hooks/evaluate-session.test.js +++ b/tests/hooks/evaluate-session.test.js @@ -284,6 +284,33 @@ function runTests() { cleanupTestDir(testDir); })) passed++; else failed++; + // ── Round 65: regex whitespace tolerance in countInFile ── + console.log('\nRound 65: regex whitespace tolerance around colon:'); + + if (test('counts user messages when JSON has spaces around colon ("type" : "user")', () => { + const testDir = createTestDir(); + const filePath = path.join(testDir, 'spaced.jsonl'); + // Manually write JSON with spaces around the colon — NOT JSON.stringify + // The regex /"type"\s*:\s*"user"/g should match these + const lines = []; + for (let i = 0; i < 12; i++) { + lines.push(`{"type" : "user", "content": "msg ${i}"}`); + lines.push(`{"type" : "assistant", "content": "resp ${i}"}`); + } + fs.writeFileSync(filePath, lines.join('\n') + '\n'); + + const result = runEvaluate({ transcript_path: filePath }); + assert.strictEqual(result.code, 0); + // 12 user messages >= 10 threshold → should evaluate (not "too short") + assert.ok(!result.stderr.includes('too short'), + 'Should NOT say too short for 12 spaced-colon user messages'); + assert.ok( + result.stderr.includes('12 messages') || result.stderr.includes('evaluate'), + `Should evaluate session with spaced-colon JSON. Got stderr: ${result.stderr}` + ); + cleanupTestDir(testDir); + })) passed++; else failed++; + // Summary console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`); process.exit(failed > 0 ? 1 : 0);