Skip to content

test: add logger/aggregator tests for blocked domain detection#1262

Merged
Mossaka merged 1 commit intomainfrom
test/100-logger-tests
Mar 12, 2026
Merged

test: add logger/aggregator tests for blocked domain detection#1262
Mossaka merged 1 commit intomainfrom
test/100-logger-tests

Conversation

@Mossaka
Copy link
Collaborator

@Mossaka Mossaka commented Mar 12, 2026

Summary

  • Adds comprehensive tests ensuring blocked domains are properly detected by log parsers and aggregated correctly
  • Covers denied HTTP/HTTPS requests, various Squid decision codes (TCP_HIT, TCP_REFRESH_MODIFIED, NONE_NONE), blocked domain extraction, and mixed allowed/denied per-domain aggregation
  • Adds end-to-end tests flowing real log lines through parser → aggregator to verify blocked domain detection
  • Improves log-streamer test coverage with PID enrichment path tests

Fixes #100

Test plan

  • All 896 existing tests pass
  • 15 new tests added across log-parser, log-aggregator, and log-streamer
  • Build succeeds
  • Lint passes (no new errors)

🤖 Generated with Claude Code

Add comprehensive tests ensuring blocked domains are properly detected
by the log parsers and aggregated correctly:

- Parser: denied HTTP requests, TCP_HIT/TCP_REFRESH decision codes,
  blocked domain extraction, allowed vs denied same-domain distinction
- Aggregator: multiple blocked domains, mixed allowed/denied per domain,
  end-to-end blocked domain detection from real log lines (HTTPS + HTTP)
- Streamer: PID enrichment path (withPid=true), PID lookup failure,
  PID tracking unavailability warning

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 12, 2026 18:43
@github-actions
Copy link
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 82.56% 83.02% 📈 +0.46%
Statements 82.57% 83.02% 📈 +0.45%
Functions 83.01% 83.49% 📈 +0.48%
Branches 75.12% 75.96% 📈 +0.84%
📁 Per-file Coverage Changes (2 files)
File Lines (Before → After) Statements (Before → After)
src/docker-manager.ts 84.1% → 84.6% (+0.54%) 83.4% → 83.9% (+0.52%)
src/logs/log-streamer.ts 77.6% → 86.8% (+9.21%) 77.9% → 87.0% (+9.09%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands the log-related unit test suite to cover additional “blocked/denied” Squid access log scenarios and to validate PID/process enrichment behavior when streaming logs.

Changes:

  • Added log-parser test cases for denied HTTP/HTTPS lines and additional decision codes (e.g., TCP_DENIED, TCP_HIT, NONE_NONE).
  • Added log-aggregator tests to ensure denied/blocked domains are counted and grouped correctly, including end-to-end loadAndAggregate coverage using realistic log lines.
  • Added log-streamer tests (with module mocks) for withPid enrichment and for the “PID tracking not available” warning path.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/logs/log-streamer.test.ts Adds PID enrichment tests and mocks for pid-tracker to validate withPid behavior.
src/logs/log-parser.test.ts Adds parsing coverage for denied GET/CONNECT lines and additional Squid decision variants.
src/logs/log-aggregator.test.ts Adds aggregation and loadAndAggregate tests focusing on blocked/denied domain statistics.
Comments suppressed due to low confidence (1)

src/logs/log-streamer.test.ts:345

  • inode is modeled as a string in the PID tracking types (PidTrackResult.inode?: string), but this test uses a numeric inode (56789). Using the correct type here will keep the test aligned with runtime expectations and avoid accidental widening of JSON output shape.
      (trackPidForPortSync as jest.Mock).mockReturnValue({
        pid: 1234,
        cmdline: 'curl https://api.github.com',
        comm: 'curl',
        inode: 56789,
      });

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

jest.mock('execa');
jest.mock('fs');
jest.mock('../pid-tracker', () => ({
trackPidForPortSync: jest.fn().mockReturnValue({ pid: -1, cmdline: '', comm: '', inode: 0 }),
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mock trackPidForPortSync return value uses inode: 0 (number), but the real PidTrackResult.inode type is an optional string. Using the wrong type in the module mock can mask type/serialization issues in PID enrichment; return a string inode (e.g. '0'/'56789') or undefined to match production behavior.

This issue also appears on line 340 of the same file.

Suggested change
trackPidForPortSync: jest.fn().mockReturnValue({ pid: -1, cmdline: '', comm: '', inode: 0 }),
trackPidForPortSync: jest.fn().mockReturnValue({ pid: -1, cmdline: '', comm: '', inode: '0' }),

Copilot uses AI. Check for mistakes.
Comment on lines +347 to +353
await streamLogs({
follow: false,
source,
formatter,
parse: true,
withPid: true,
});
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These withPid tests exercise PID enrichment while follow: false on a preserved file source. In the CLI, --with-pid is explicitly disabled unless -f/--follow is set (and the option docs say "real-time only"), so this test is asserting behavior that is effectively unreachable and contradicts the intended contract. Consider switching the test to follow: true (tailing) or otherwise aligning it with the documented/CLI behavior.

Copilot uses AI. Check for mistakes.
Comment on lines +100 to +109
it('should mark TCP_HIT as allowed (cached response)', () => {
const line =
'1761074374.646 172.30.0.20:39748 example.com:80 93.184.216.34:80 1.1 GET 200 TCP_HIT:HIER_NONE http://example.com/ "-"';
const result = parseLogLine(line);

expect(result).not.toBeNull();
// TCP_HIT is neither TCP_TUNNEL nor TCP_MISS, so isAllowed should be false
// This documents current behavior: only TCP_TUNNEL and TCP_MISS are considered allowed
expect(result!.isAllowed).toBe(false);
});
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test name contradicts the asserted behavior: it says "should mark TCP_HIT as allowed" but the test (correctly, per current isAllowed logic) expects isAllowed to be false. Please rename the test to reflect the actual expectation so failures are easier to interpret.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Contributor

🤖 Smoke test results for @Mossaka

✅ GitHub MCP — Last 2 merged PRs: #1261 "ci: skip CI when only release.yml changes", #1260 "fix: make release workflow compatible with branch protection"
✅ Playwright — github.com title contains "GitHub"
✅ File write — /tmp/gh-aw/agent/smoke-test-copilot-23018270821.txt created
✅ Bash — file content verified via cat

Overall: PASS

📰 BREAKING: Report filed by Smoke Copilot for issue #1262

@github-actions
Copy link
Contributor

Smoke test results (run 23018270850)

✅ GitHub MCP: #1230 docs: document flag validation constraints, #1223 docs: sync version references and add missing CLI flags
✅ Playwright: github.com title verified
✅ File write: /tmp/gh-aw/agent/smoke-test-claude-23018270850.txt created
✅ Bash verify: file contents confirmed

Overall: PASS

💥 [THE END] — Illustrated by Smoke Claude for issue #1262

@github-actions
Copy link
Contributor

Chroot Version Comparison Results

Runtime Host Version Chroot Version Match?
Python Python 3.12.12 Python 3.12.3
Node.js v24.14.0 v20.20.0
Go go1.22.12 go1.22.12

Result: ❌ Not all versions matched — Python and Node.js versions differ between host and chroot environments.

Tested by Smoke Chroot for issue #1262

@github-actions
Copy link
Contributor

PRs: chore(deps): aggregated dependency updates; docs: document flag validation constraints
GitHub MCP (last 2 merged PRs) ✅
Safeinputs GH PR list ✅
Playwright title contains GitHub ✅
Tavily search ❌
File write + cat ✅
Discussion comment ✅
Build npm ci && npm run build
Overall: FAIL

🔮 The oracle has spoken through Smoke Codex for issue #1262

@github-actions
Copy link
Contributor

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia 1/1 passed ✅ PASS
Bun hono 1/1 passed ✅ PASS
C++ fmt N/A ✅ PASS
C++ json N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world N/A ✅ PASS
.NET json-parse N/A ✅ PASS
Go color passed ✅ PASS
Go env passed ✅ PASS
Go uuid passed ✅ PASS
Java gson 1/1 passed ✅ PASS
Java caffeine 1/1 passed ✅ PASS
Node.js clsx passed ✅ PASS
Node.js execa passed ✅ PASS
Node.js p-limit passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

Note: Java Maven tests required using the Squid proxy IP (172.30.0.10:3128) directly instead of the squid-proxy hostname, as the hostname from pre-configured ~/.m2/settings.xml failed to resolve outside of Docker networking context.

Generated by Build Test Suite for issue #1262 ·

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logger tests

2 participants