The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
test: cover countInFile/grepFile string patterns and validate-commands warnings suffix
Affaan Mustafa9dccdb9068dd
diff --git a/tests/ci/validators.test.js b/tests/ci/validators.test.jsindex 94937c05c..ffc033a6c 100644--- a/tests/ci/validators.test.js+++ b/tests/ci/validators.test.js@@ -2031,6 +2031,28 @@ function runTests() {cleanupTestDir(testDir);})) passed++; else failed++;+ // ── Round 79: validate-commands.js warnings count suffix in output ──+ console.log('\nRound 79: validate-commands.js (warnings count in output):');++ if (test('output includes (N warnings) suffix when skill references produce warnings', () => {+ const testDir = createTestDir();+ const agentsDir = createTestDir();+ const skillsDir = createTestDir();+ // Create a command that references 2 non-existent skill directories+ // Each triggers a WARN (not error) — warnCount should be 2+ fs.writeFileSync(path.join(testDir, 'cmd-warn.md'),+ '# Command\nSee skills/fake-skill-a/ and skills/fake-skill-b/ for details.');++ const result = runValidatorWithDirs('validate-commands', {+ COMMANDS_DIR: testDir, AGENTS_DIR: agentsDir, SKILLS_DIR: skillsDir+ });+ assert.strictEqual(result.code, 0, 'Skill warnings should not cause error exit');+ // The validate-commands output appends "(N warnings)" when warnCount > 0+ assert.ok(result.stdout.includes('(2 warnings)'),+ `Output should include "(2 warnings)" suffix, got: ${result.stdout}`);+ cleanupTestDir(testDir); cleanupTestDir(agentsDir); cleanupTestDir(skillsDir);+ })) passed++; else failed++;+// Summaryconsole.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.jsindex 698ab7e5f..45ac1e24d 100644--- a/tests/lib/utils.test.js+++ b/tests/lib/utils.test.js@@ -1096,6 +1096,41 @@ function runTests() {}})) passed++; else failed++;+ // ── Round 79: countInFile with valid string pattern ──+ console.log('\nRound 79: countInFile (valid string pattern):');++ if (test('countInFile counts occurrences using a plain string pattern', () => {+ const testFile = path.join(utils.getTempDir(), `utils-test-count-str-${Date.now()}.txt`);+ try {+ utils.writeFile(testFile, 'apple banana apple cherry apple');+ // Pass a plain string (not RegExp) — exercises typeof pattern === 'string'+ // branch at utils.js:441-442 which creates new RegExp(pattern, 'g')+ const count = utils.countInFile(testFile, 'apple');+ assert.strictEqual(count, 3, 'String pattern should count all occurrences');+ } finally {+ fs.unlinkSync(testFile);+ }+ })) passed++; else failed++;++ // ── Round 79: grepFile with valid string pattern ──+ console.log('\nRound 79: grepFile (valid string pattern):');++ if (test('grepFile finds matching lines using a plain string pattern', () => {+ const testFile = path.join(utils.getTempDir(), `utils-test-grep-str-${Date.now()}.txt`);+ try {+ utils.writeFile(testFile, 'line1 alpha\nline2 beta\nline3 alpha\nline4 gamma');+ // Pass a plain string (not RegExp) — exercises the else branch+ // at utils.js:468-469 which creates new RegExp(pattern)+ const matches = utils.grepFile(testFile, 'alpha');+ assert.strictEqual(matches.length, 2, 'String pattern should find 2 matching lines');+ assert.strictEqual(matches[0].lineNumber, 1, 'First match at line 1');+ assert.strictEqual(matches[1].lineNumber, 3, 'Second match at line 3');+ assert.ok(matches[0].content.includes('alpha'), 'Content should include pattern');+ } finally {+ fs.unlinkSync(testFile);+ }+ })) passed++; else failed++;+// Summaryconsole.log('\n=== Test Results ===');console.log(`Passed: ${passed}`);