Skip to content

refactor: extract shared config-writer test harness to eliminate duplicate setup#5702

Merged
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-writeconfigs-setup
Jun 30, 2026
Merged

refactor: extract shared config-writer test harness to eliminate duplicate setup#5702
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-writeconfigs-setup

Conversation

Copilot AI commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

config-writer.test.ts and config-writer-branches.test.ts duplicated ~53 lines of identical Jest mock setup, a buildWriteConfig factory, and temp-dir lifecycle boilerplate verbatim.

New: src/test-helpers/config-writer-test-harness.test-utils.ts

Centralises everything that was repeated:

  • Mock factoriessslBumpMockFactory, domainMatchersMockFactory, squidConfigMockFactory, composeGeneratorMockFactory — consumed via require() inside each file's jest.mock() declarations (which must stay per-file due to Jest hoisting)
  • buildWriteConfig(tempDir, overrides?) — minimal valid WrapperConfig factory
  • setupConfigWriterTempDir(prefix?) — creates temp dir, clears mocks, stubs chownSync and getRealUserHome; returns the path
  • cleanupConfigWriterTempDir(tempDir) — removes temp dir and -chroot-home sibling

Updated test files

The seven jest.mock() blocks collapse from ~31 lines to 7 one-liners each:

jest.mock('./ssl-bump', () =>
  require('./test-helpers/config-writer-test-harness.test-utils').sslBumpMockFactory()
);

beforeEach/afterEach bodies and the local buildWriteConfig declaration are replaced with imports from the harness. All existing call sites updated to the new buildWriteConfig(tempDir, overrides) signature.

Copilot AI changed the title [WIP] Refactor duplicated test setup in writeConfigs suite refactor: extract shared config-writer test harness to eliminate duplicate setup Jun 30, 2026
Copilot finished work on behalf of lpcox June 30, 2026 01:04
Copilot AI requested a review from lpcox June 30, 2026 01:04
@lpcox lpcox marked this pull request as ready for review June 30, 2026 01:46
Copilot AI review requested due to automatic review settings June 30, 2026 01:46

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 config-writer unit test suites by extracting duplicated Jest mock setup, temp-dir lifecycle handling, and minimal WrapperConfig construction into a shared test harness under src/test-helpers/, reducing repetition while preserving Jest’s per-file jest.mock() hoisting requirements.

Changes:

  • Added config-writer-test-harness.test-utils.ts to centralize mock factories, a buildWriteConfig(tempDir, overrides) factory, and temp directory setup/cleanup helpers.
  • Updated config-writer.test.ts and config-writer-branches.test.ts to use the shared harness and collapse repeated jest.mock() blocks into one-liners.
Show a summary per file
File Description
src/test-helpers/config-writer-test-harness.test-utils.ts New shared harness providing mock factories and temp-dir/config factories for config-writer tests.
src/config-writer.test.ts Replaces duplicated mocks and per-test setup/teardown with harness helpers; updates buildWriteConfig call sites.
src/config-writer-branches.test.ts Same refactor as above for branch-focused tests; updates buildWriteConfig call sites.

Review details

Tip

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

  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Low

@github-actions

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

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Contribution Check completed successfully!

Contribution check complete: PR #5702 follows the applicable CONTRIBUTING.md guidance. It is a test-only refactor with a clear description, appropriate test-helper placement under src/test-helpers, and no documentation or new-functionality tests required.

@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Build Test Suite completed successfully!

@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟

@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Security Guard has started processing this pull request

@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓

@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Smoke Claude passed

@github-actions

github-actions Bot commented Jun 30, 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 30, 2026

Copy link
Copy Markdown
Contributor

Smoke Gemini completed. All facets verified. 💎

@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

🔌 Smoke Services — All services reachable! ✅

@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

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

Renamed the second '## Build-tools sysroot image' heading to
'## Sysroot staging lifecycle' to resolve MD024/no-duplicate-heading.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Coverage Regression Detected

This PR decreases test coverage. Please add tests to maintain coverage levels.

Overall Coverage

Metric Base PR Delta
Lines 98.39% 98.43% 📈 +0.04%
Statements 98.31% 98.36% 📈 +0.05%
Functions 99.54% 99.55% ➡️ +0.01%
Branches 94.44% 94.41% 📉 -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%)
✨ New Files (1 files)
  • src/test-helpers/config-writer-test-harness.test-utils.ts: 100.0% lines

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

@github-actions

Copy link
Copy Markdown
Contributor

Documentation Preview

Documentation build failed for this PR. View logs.

Built from commit cdf1871

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Coverage Regression Detected

This PR decreases test coverage. Please add tests to maintain coverage levels.

Overall Coverage

Metric Base PR Delta
Lines 98.39% 98.43% 📈 +0.04%
Statements 98.31% 98.36% 📈 +0.05%
Functions 99.54% 99.55% ➡️ +0.01%
Branches 94.44% 94.41% 📉 -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%)
✨ New Files (1 files)
  • src/test-helpers/config-writer-test-harness.test-utils.ts: 100.0% lines

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

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Claude Engine Validation

Check Status
API ✅ PASS
GH ✅ PASS
File ✅ PASS

Overall result: PASS

Generated by Smoke Claude for #5702 · 52.2 AIC · ⊞ 3.3K ·

@github-actions

Copy link
Copy Markdown
Contributor

🔬 Smoke Test: Copilot PAT Auth — PR #5702

Test Result
GitHub MCP connectivity ✅ PR data fetched successfully
GitHub.com HTTP ✅ 200 OK
File write/read ⚠️ Pre-step outputs not resolved (template substitution issue)

Overall: ⚠️ PARTIAL — 2/3 tests verified; file test skipped due to unresolved ${{ steps.smoke-data.outputs.* }} variables.

Auth mode: PAT (COPILOT_GITHUB_TOKEN) | @lpcox @Copilot

🔑 PAT report filed by Smoke Copilot PAT

@github-actions

Copy link
Copy Markdown
Contributor

Smoke test summary

  • ✅ Add ARC-DinD runner topology with sysroot-stage build-tools image
  • ✅ build(docker): add build-tools sysroot image and runner.topology config for arc-dind
  • ✅ GitHub title check
  • ✅ Smoke file verification
  • ✅ Discussion comment posted
  • ✅ npm ci && npm run build
    Overall status: 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

@lpcox @Copilot

PR titles:

  • refactor: extract shared config-writer test harness to eliminate duplicate setup
  • fix: correctly recover runner tool on PATH (after sudo w/ secure_path). remove incorrect reading from GITHUB_PATH

✅ MCP testing, GitHub.com, File I/O, BYOK inference
Running direct BYOK mode (AWF_AUTH_TYPE=github-oidc + AWF_AUTH_AZURE_* + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw)
PASS

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

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Direct) Mode

✅ GitHub MCP connectivity
✅ GitHub.com connectivity (HTTP 200)
✅ File write/read capability
✅ BYOK inference path (api-proxy → api.githubcopilot.com)

Status: PASS
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

@Copilot @lpcox

  • refactor: extract shared config-writer test harness to eliminate duplicate setup: ✅
  • fix: correctly recover runner tool on PATH (after sudo w/ secure_path): ✅
  • GitHub.com connectivity: ✅
  • File I/O: ✅
  • BYOK inference: ✅

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

PR: refactor: extract shared config-writer test harness to eliminate duplicate setup
Author: @Copilot | Assignees: @lpcox @Copilot

Test Result
GitHub MCP connectivity
GitHub.com HTTP ✅ 200
File write/read ⚠️ (pre-step data unavailable)

Overall: PASS

📰 BREAKING: Report filed by Smoke Copilot

@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.17.0 v22.23.0 ❌ 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

📡 OTel Tracing Smoke Test Results

Scenario Status Detail
1. Module Loading otel.js loaded; isEnabled: true; exports: startRequestSpan, setTokenAttributes, setBudgetAttributes, endSpan, endSpanError, shutdown, isEnabled
2. Test Suite 59/59 tests passed (2 suites: otel.test.js, otel-fanout.test.js)
3. Env Var Forwarding ⚠️ OTEL_EXPORTER_OTLP_ENDPOINT/GITHUB_AW_OTEL_TRACE_ID not yet in api-proxy-service.ts — expected during development
4. Token Tracker Integration token-tracker-http.js has onUsage callback (OTEL hook point confirmed)
5. OTEL Diagnostics ⚠️ No span file at runtime — expected (env var forwarding not yet wired)

All scenarios pass or are expected-pending during development. ✅

📡 OTel tracing validated by Smoke OTel Tracing

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results

  • GitHub MCP Testing: ❌ (Unable to list merged PRs)
  • GitHub.com Connectivity: ❌ (Status 000)
  • File Writing Testing: ✅
  • Bash Tool Testing: ✅

Overall status: FAIL

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 ✅ (cmake + make) N/A ✅ PASS
C++ json ✅ (cmake + make) N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world ✅ (restore + build + run) N/A ✅ PASS
.NET json-parse ✅ (restore + build + run) N/A ✅ PASS
Go color 1/1 passed ✅ PASS
Go env 1/1 passed ✅ PASS
Go uuid 1/1 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 #5702 · 57.3 AIC · ⊞ 7.8K ·

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Services Connectivity — ❌ FAIL

  • ❌ Redis (host.docker.internal:6379): TCP timeout (connection refused/unreachable)
  • ❌ PostgreSQL pg_isready (host.docker.internal:5432): TCP timeout
  • ❌ PostgreSQL SELECT 1: TCP timeout

host.docker.internal resolves to 172.17.0.1 but both ports are unreachable. Service containers may not be running or are not bound to the expected ports.

🔌 Service connectivity validated by Smoke Services

@lpcox lpcox merged commit 6756880 into main Jun 30, 2026
24 of 25 checks passed
@lpcox lpcox deleted the copilot/duplicate-code-writeconfigs-setup branch June 30, 2026 02:03
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.

[Duplicate Code] writeConfigs test setup duplicated across config-writer suites

3 participants