[Test Coverage] test: improve pid-tracker branch coverage for edge cases#1334
[Test Coverage] test: improve pid-tracker branch coverage for edge cases#1334github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (2 files)
Coverage comparison generated by |
There was a problem hiding this comment.
Pull request overview
This pull request strengthens the unit-test suite for pid-tracker by adding coverage for additional edge cases encountered when parsing /proc/net/tcp and reading process metadata from a mocked /proc filesystem.
Changes:
- Add
parseNetTcptests to ensure empty lines and malformed rows are skipped safely. - Add
getProcessInfotests for scenarios wherecmdlineorcommfiles are missing. - Add
findProcessByInodetests for missing/procdirectories and missingcmdline/commfiles on otherwise matching processes.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Smoke test results for run 23208183337: ✅ GitHub MCP — PR #1332: "fix: fix awf-runner timeout detection and no-docker test timeouts" | PR #1331: "fix: route GHEC Copilot proxy to copilot-api subdomain" Overall: PASS —
|
Smoke Test Results
Overall: PASS
|
|
🔮 The ancient spirits stir; the smoke sigils are read.
Warning
|
🏗️ Build Test Suite Results
Overall: 0/8 ecosystems passed — ❌ FAIL Error DetailsAll repository clones failed with: The
|
Chroot Version Comparison Results
Result:
|
Summary
Adds 7 new unit tests to
src/pid-tracker.test.tsto cover previously uncovered branches in thepid-tracker.tsmodule.Coverage Improvement
Before:
After:
Overall project branch coverage: 78.43% → 78.85% (+0.42%)
Security-Critical Paths Now Covered
The
pid-tracker.tsmodule is used to track which process is making outbound network connections by scanning the/procfilesystem. Reliable edge-case handling is important for accurate audit logs in the firewall.New Tests
parseNetTcp- skip empty lines in the middle of TCP table content (defensive against malformed/proc/net/tcpentries)parseNetTcp- skip lines with fewer than 10 fields (defensive against truncated kernel output)getProcessInfo- returns'unknown'for cmdline when the cmdline file is missing (process race condition)getProcessInfo- returns'unknown'for comm when the comm file is missing (process race condition)findProcessByInode- returnsnullwhen the proc directory doesn't exist (defensive, catch block)findProcessByInode- returns'unknown'cmdline when process owns socket but has no cmdline filefindProcessByInode- returns'unknown'comm when process owns socket but has no comm fileRemaining Uncovered Lines
Lines 354 and 420 (outer catch blocks in
trackPidForPortandtrackPidForPortSync) are defensive code that's only reachable via unexpected runtime errors. These would require mocking pure functions to trigger and are deferred.