From 5f79c39687c535f370dfa894b0bc714dce285df8 Mon Sep 17 00:00:00 2001 From: Nguyen Thanh Dat Date: Tue, 25 Aug 2026 18:34:12 +0700 Subject: [PATCH] test(locale-agents): derive the file lists instead of accumulating them Review feedback on #2879, citing rules/common/coding-style.md ("Immutability (CRITICAL): ALWAYS create new objects, NEVER mutate existing ones"). Build one list of locale entries, then derive the matched and orphaned sets from it with filter/map, and build the canonical Map the same way. Behaviour is unchanged and both mutations still fail: reintroducing the drift in one locale file gives `Passed: 4, Failed: 3`, an orphan gives `Passed: 6, Failed: 1`, both exit 1. --- tests/ci/locale-agent-frontmatter.test.js | 31 +++++++++++++---------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/tests/ci/locale-agent-frontmatter.test.js b/tests/ci/locale-agent-frontmatter.test.js index 26dc92228..454e1e002 100644 --- a/tests/ci/locale-agent-frontmatter.test.js +++ b/tests/ci/locale-agent-frontmatter.test.js @@ -76,23 +76,26 @@ function runTest(name, fn) { function main() { console.log('\n=== Testing locale agent frontmatter against canonical ===\n'); - const canonical = new Map(); - for (const file of fs.readdirSync(AGENTS_DIR).filter(f => f.endsWith('.md'))) { - const fields = frontmatter(path.join(AGENTS_DIR, file)); - if (fields) canonical.set(file, fields); - } + const canonical = new Map( + fs + .readdirSync(AGENTS_DIR) + .filter(file => file.endsWith('.md')) + .map(file => [file, frontmatter(path.join(AGENTS_DIR, file))]) + .filter(([, fields]) => fields !== null) + ); const rel = filePath => path.relative(REPO_ROOT, filePath).split(path.sep).join('/'); - const localeFiles = []; - const orphans = []; - for (const dir of localeAgentDirs()) { - for (const file of fs.readdirSync(dir).filter(f => f.endsWith('.md'))) { - const filePath = path.join(dir, file); - if (canonical.has(file)) localeFiles.push({ file, filePath }); - else orphans.push(rel(filePath)); - } - } + const localeEntries = localeAgentDirs().flatMap(dir => + fs + .readdirSync(dir) + .filter(file => file.endsWith('.md')) + .map(file => ({ file, filePath: path.join(dir, file) })) + ); + const localeFiles = localeEntries.filter(({ file }) => canonical.has(file)); + const orphans = localeEntries + .filter(({ file }) => !canonical.has(file)) + .map(({ filePath }) => rel(filePath)); const tests = [ ['there are locale agent docs to check', () => {