refactor: apply code-review findings to github-native coordination

scripts/github-coordination.js:
- parseArgs: replace 13-entry if/else chain with BOOL_FLAGS/VALUE_FLAGS
  lookup maps; shrinks from 119 to ~45 lines
- Extract dispatchCommand(options, ctx) and formatOutput(payload, options)
  from main(); main() shrinks to ~20 lines

scripts/lib/github-coordination.js:
- Split 1041-line monolith into 6 focused sub-modules under
  scripts/lib/github-coordination/ (policy, parsing, gh-api, state,
  actions, store); index becomes a thin re-export (~55 lines)
- Document ECC_GH_SHIM trust boundary in runGh() (gh-api.js)
- Document applyClaim() read→check→write race condition (actions.js)

tests/lib/github-coordination.test.js:
- Refactor runTests() to data-driven DESCRIPTORS array + runGroup()
  helper; runTests() shrinks to ~10 lines
- Add 5 new edge-case tests: normalizeRepo('') and normalizeRepo('   ')
  throw, desiredLabelsForState for blocked/ready statuses, and
  buildIssueStateFromAction for validate action (15 → 20 tests)

tests/scripts/github-coordination.test.js:
- Replace console.log in test runner with process.stdout.write

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Victor Casado
2026-06-11 14:05:42 -04:00
parent 64470f4307
commit d4486a7a29
10 changed files with 1513 additions and 1429 deletions
+5 -5
View File
@@ -66,11 +66,11 @@ function parseJson(stdout) {
async function test(name, fn) {
try {
await fn();
console.log(` PASS ${name}`);
process.stdout.write(` PASS ${name}\n`);
return true;
} catch (error) {
console.log(` FAIL ${name}`);
console.log(` Error: ${error.message}`);
process.stdout.write(` FAIL ${name}\n`);
process.stdout.write(` Error: ${error.message}\n`);
return false;
}
}
@@ -85,7 +85,7 @@ async function readStore(dbPath) {
}
async function runTests() {
console.log('\n=== Testing github-coordination.js ===\n');
process.stdout.write('\n=== Testing github-coordination.js ===\n\n');
let passed = 0;
let failed = 0;
@@ -228,7 +228,7 @@ async function runTests() {
}
})) passed++; else failed++;
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
process.stdout.write(`\nResults: Passed: ${passed}, Failed: ${failed}\n`);
process.exit(failed > 0 ? 1 : 0);
}