Skip to content

refactor(test): extract runAuditFilter helper to deduplicate audit filter tests - #5461

Merged
lpcox merged 3 commits into
mainfrom
copilot/audit-command-filtering-duplication
Jun 24, 2026
Merged

refactor(test): extract runAuditFilter helper to deduplicate audit filter tests#5461
lpcox merged 3 commits into
mainfrom
copilot/audit-command-filtering-duplication

Conversation

Copilot AI commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Four audit filter tests repeated identical setup/invoke/parse boilerplate, differing only in the filter option and assertion. Extracts a runAuditFilter helper that owns the common flow, letting each test express only what's unique.

Changes

  • src/commands/logs-audit.test.ts — adds runAuditFilter(options: Omit<AuditCommandOptions, 'format'>): Promise<any[]> inside the filtering describe block; refactors the four filter tests to use it
// Before — repeated in each of the four tests:
setupMocksWithMultipleEntries();
const options: AuditCommandOptions = { format: 'json', rule: 'deny-default' };
await auditCommand(options);
const output = mockConsoleLog.mock.calls[0][0] as string;
const parsed = JSON.parse(output);
expect(parsed).toHaveLength(1);
expect(parsed[0].domain).toBe('evil.com');

// After — helper owns the boilerplate:
async function runAuditFilter(options: Omit<AuditCommandOptions, 'format'>): Promise<any[]> {
  setupMocksWithMultipleEntries();
  await auditCommand({ format: 'json', ...options });
  const output = mockConsoleLog.mock.calls[0][0] as string;
  return JSON.parse(output);
}

it('should filter by rule ID', async () => {
  const parsed = await runAuditFilter({ rule: 'deny-default' });
  expect(parsed).toHaveLength(1);
  expect(parsed[0].domain).toBe('evil.com');
});

Copilot AI changed the title [WIP] Refactor duplicate code in audit command filtering tests refactor(test): extract runAuditFilter helper to deduplicate audit filter tests Jun 23, 2026
Copilot AI requested a review from lpcox June 23, 2026 23:11
Copilot finished work on behalf of lpcox June 23, 2026 23:11
@lpcox
lpcox marked this pull request as ready for review June 23, 2026 23:44
Copilot AI review requested due to automatic review settings June 23, 2026 23:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 refactors the logs-audit command unit tests to reduce duplicated setup/invoke/parse boilerplate in the “filtering” test cases by introducing a shared helper.

Changes:

  • Add a runAuditFilter(...) helper within the filtering describe block to encapsulate common test flow.
  • Refactor four filtering tests (rule/domain/decision allowed/decision denied) to use the helper.
Show a summary per file
File Description
src/commands/logs-audit.test.ts Extracts a helper to deduplicate repeated audit filtering test boilerplate and updates the relevant tests to use it.

Copilot's findings

Tip

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

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment thread src/commands/logs-audit.test.ts Outdated
}

it('should filter by rule ID', async () => {
async function runAuditFilter(options: Omit<AuditCommandOptions, 'format'>): Promise<any[]> {
@lpcox

lpcox commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

@copilot address review feedback

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

✅ Copilot review passed with no inline comments.

@copilot Add the ready-for-aw label to this PR to trigger agentic CI smoke tests.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 98.06% 98.10% 📈 +0.04%
Statements 98.00% 98.03% 📈 +0.03%
Functions 99.52% 99.52% ➡️ +0.00%
Branches 93.75% 93.78% 📈 +0.03%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/workdir-setup.ts 92.7% → 94.5% (+1.82%) 92.7% → 94.5% (+1.82%)

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

Copilot AI commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

@copilot address review feedback

Done in 66f48b2. Added a local AuditJsonEntry type that mirrors the shape produced by formatAuditJson(), changed runAuditFilter to return Promise<AuditJsonEntry[]>, and removed the (e: any) annotations in the .every() callbacks since the type is now inferred.

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Security Guard has started processing this pull request

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Build Test Suite completed successfully!

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Chroot tests passed! Smoke Chroot - All security and functionality tests succeeded.

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK AOAI (Entra) completed. Copilot AOAI BYOK (Entra) mode operational. 🔓

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Smoke Gemini completed. All facets verified. 💎

Smoke test in progress

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

🔑 Smoke Copilot PAT PAT auth validated. All systems operational. ✅

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

📡 Smoke OTel Tracing completed. All tracing scenarios validated. ✅

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

🔌 Smoke Services — All services reachable! ✅

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK AOAI (api-key) completed. Copilot AOAI BYOK (api-key) mode operational. 🔓

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Contribution Check completed successfully!

Contribution guidelines review complete for PR #5461: no significant guideline issues found. The change is a test-only refactor, remains in the existing test file location, uses TypeScript types, does not add new functionality requiring new tests or docs, and has a clear PR description.

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Smoke Claude passed

@github-actions

github-actions Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓

@github-actions

Copy link
Copy Markdown
Contributor

🔬 Smoke Test Results — PASS

Test Result
GitHub MCP connectivity
GitHub.com HTTP ✅ 200
File write/read

PR: refactor(test): extract runAuditFilter helper to deduplicate audit filter tests
Author: @Copilot | Assignees: @lpcox @Copilot

Overall: ✅ PASS

📰 BREAKING: Report filed by Smoke Copilot

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot PAT Auth — FAIL

Test Result
GitHub MCP
HTTP (github.com) ❌ pre-step data missing
File write/read ❌ pre-step data missing

Overall: FAIL — template variables (${{ steps.smoke-data.outputs.* }}) were not substituted; pre-computed step outputs unavailable.

PR: "refactor(test): extract runAuditFilter helper to deduplicate audit filter tests" | Author: @Copilot | Assignees: @lpcox @Copilot
Auth mode: PAT (COPILOT_GITHUB_TOKEN)

🔑 PAT report filed by Smoke Copilot PAT

@github-actions github-actions Bot mentioned this pull request Jun 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Claude Engine Validation

  • API status: ✅ PASS
  • GH check: ✅ PASS
  • File status: ✅ PASS

Overall result: PASS

Generated by Smoke Claude for issue #5461 · 61.1 AIC · ⊞ 3.1K ·

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Direct Mode) — PASS

  • MCP connectivity: ✅ (gh-aw-firewall PRs listed)
  • GitHub.com connectivity: ✅
  • File write/read: ✅ (/tmp/gh-aw/agent/smoke-test-copilot-byok.txt)
  • BYOK inference path: ✅ (api-proxy → api.githubcopilot.com)

Running in direct BYOK mode (COPILOT_PROVIDER_API_KEY) via api-proxy sidecar.

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions

Copy link
Copy Markdown
Contributor
  • Add Self-Hosted Runner Doctor workflow for ARC/DinD and enterprise AWF triage
  • Refactor api-proxy credential isolation into per-provider env builders
    Checks: GitHub title ✅ | file write ✅ | discussion ✅ | build ✅
    Overall: PASS

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • registry.npmjs.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "registry.npmjs.org"

See Network Configuration for more information.

🔮 The oracle has spoken through Smoke Codex

@github-actions

Copy link
Copy Markdown
Contributor

🔭 Smoke Test: API Proxy OpenTelemetry Tracing

Scenario Result Notes
1. Module Loading otel.js loads cleanly; exports: startRequestSpan, setTokenAttributes, setBudgetAttributes, endSpan, endSpanError, shutdown, isEnabled
2. Test Suite 59/59 tests pass across otel.test.js + otel-fanout.test.js
3. Env Var Forwarding api-proxy-env-config.ts forwards GH_AW_OTLP_ENDPOINTS, OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_HEADERS, GITHUB_AW_OTEL_TRACE_ID, GITHUB_AW_OTEL_PARENT_SPAN_ID, OTEL_SERVICE_NAME
4. Token Tracker Integration onUsage callback present in token-tracker-http.js (lines 283, 324, 374)
5. OTEL Diagnostics Graceful degradation confirmed — no OTLP endpoint configured, falls back to FileSpanExporter/var/log/api-proxy/otel.jsonl

All scenarios pass. ✅

📡 OTel tracing validated by Smoke OTel Tracing

@github-actions

Copy link
Copy Markdown
Contributor

@Copilot @lpcox Smoke Test Results:

  • GitHub MCP connectivity: ✅
  • GitHub.com connectivity: ✅
  • File I/O test: ✅
  • BYOK inference test: ✅

Running in direct BYOK mode (COPILOT_PROVIDER_API_KEY + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw)

Overall: PASS

🔑 BYOK (AOAI api-key) report filed by Smoke Copilot BYOK AOAI (api-key)

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results

Check Result
Redis PING ❌ timeout
PostgreSQL pg_isready ❌ no response
PostgreSQL SELECT 1 ❌ timeout

Overall: FAILhost.docker.internal (172.17.0.1) is unreachable on ports 6379 and 5432. Service containers may not be running or network access is blocked.

🔌 Service connectivity validated by Smoke Services

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

Chroot Version Comparison Results

Runtime Host Version Chroot Version Match?
Python Python 3.12.13 Python 3.12.3 ❌ No
Node.js v24.16.0 v22.22.3 ❌ No
Go go1.22.12 go1.22.12 ✅ Yes

Overall: ❌ Not all tests passed — Python and Node.js versions differ between host and chroot environments.

Tested by Smoke Chroot

@github-actions

Copy link
Copy Markdown
Contributor

@lpcox @Copilot

  • GitHub MCP Testing: ✅
  • GitHub.com Connectivity: ✅
  • File Write/Read Test: ✅
  • BYOK Inference Test: ✅

Running in direct BYOK mode (AWF_AUTH_TYPE=github-oidc + AWF_AUTH_AZURE_* + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw) authenticated via Microsoft Entra

Overall: PASS

🪪 BYOK (AOAI Entra) report filed by Smoke Copilot BYOK AOAI (Entra)

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results (Gemini)

Overall status: PASS

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • localhost

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "localhost"

See Network Configuration for more information.

💎 Faceted by Smoke Gemini

@github-actions

Copy link
Copy Markdown
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 All passed ✅ PASS
Node.js execa All passed ✅ PASS
Node.js p-limit All passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

Generated by Build Test Suite for issue #5461 · 52.5 AIC · ⊞ 7.7K ·

@lpcox
lpcox merged commit 39abc55 into main Jun 24, 2026
90 of 92 checks passed
@lpcox
lpcox deleted the copilot/audit-command-filtering-duplication branch June 24, 2026 00:20
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.

3 participants