Skip to content

refactor: extract useCleanupTestDir to eliminate repeated test boilerplate#3481

Merged
lpcox merged 3 commits into
mainfrom
copilot/fix-duplicate-code-setup
May 21, 2026
Merged

refactor: extract useCleanupTestDir to eliminate repeated test boilerplate#3481
lpcox merged 3 commits into
mainfrom
copilot/fix-duplicate-code-setup

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 20, 2026

Each of the 6 describe blocks in container-cleanup-branches.test.ts duplicated ~10 lines of identical let testDir / beforeEach / afterEach setup — ~60 lines of boilerplate with no meaningful variation except which mock was reset.

Changes

  • New helper useCleanupTestDir in src/test-helpers/docker-test-fixtures.test-utils.ts: manages awf-* temp dir lifecycle (beforeEach create, afterEach remove) with an optional resetMocks callback (defaults to jest.clearAllMocks())
  • Refactored all 6 describe blocks in src/container-cleanup-branches.test.ts to use the helper; removed the local makeTmpDir function

Each block now reads:

describe('cleanup - cli-proxy logs', () => {
  const { getDir } = useCleanupTestDir(() => {
    jest.clearAllMocks();
    mockExecaSync.mockReturnValue(undefined);
  });
  // tests use getDir() instead of testDir
});

The helper follows the same pattern as the existing useTempWorkDir in the same file.

Remove ~60 lines of repeated beforeEach/afterEach boilerplate from
container-cleanup-branches.test.ts by introducing useCleanupTestDir
in docker-test-fixtures.test-utils.ts.
Copilot AI changed the title [WIP] Refactor duplicate beforeEach/afterEach in test setup refactor: extract useCleanupTestDir to eliminate repeated test boilerplate May 20, 2026
Copilot finished work on behalf of lpcox May 20, 2026 23:19
Copilot AI requested a review from lpcox May 20, 2026 23:19
@lpcox lpcox marked this pull request as ready for review May 20, 2026 23:55
Copilot AI review requested due to automatic review settings May 20, 2026 23:55
@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 95.73% 95.79% 📈 +0.06%
Statements 95.56% 95.62% 📈 +0.06%
Functions 96.86% 96.67% 📉 -0.19%
Branches 89.30% 89.31% 📈 +0.01%
📁 Per-file Coverage Changes (2 files)
File Lines (Before → After) Statements (Before → After)
src/test-helpers/docker-test-fixtures.test-utils.ts 100.0% → 94.7% (-5.27%) 100.0% → 95.0% (-5.00%)
src/config-writer.ts 83.0% → 85.6% (+2.54%) 83.0% → 85.6% (+2.54%)

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

Copy link
Copy Markdown
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 refactors test setup in container-cleanup-branches.test.ts by extracting repeated temp-dir lifecycle boilerplate into a shared Jest helper (useCleanupTestDir) in the existing docker test fixtures utilities module.

Changes:

  • Added useCleanupTestDir(resetMocks?) helper to create/remove an awf-* temp dir per test with an optional mock-reset callback.
  • Refactored all describe blocks in container-cleanup-branches.test.ts to use useCleanupTestDir() and getDir() instead of local testDir setup/teardown.
Show a summary per file
File Description
src/test-helpers/docker-test-fixtures.test-utils.ts Adds useCleanupTestDir helper to standardize temp dir lifecycle for cleanup-focused unit tests.
src/container-cleanup-branches.test.ts Replaces repeated per-describe temp dir setup/teardown with the new helper and updates call sites to use getDir().

Copilot's findings

Tip

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

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

Comment on lines +57 to +61
afterEach(() => {
if (fs.existsSync(testDir)) {
fs.rmSync(testDir, { recursive: true, force: true });
}
});
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented May 21, 2026

@copilot address review feedback

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 21, 2026

@copilot address review feedback

Addressed in commit b248ab1.

Updated useCleanupTestDir so afterEach only removes the directory when testDir is set, avoiding existsSync(undefined) if temp dir creation fails. Also made getDir() throw a clear error if accessed before initialization.

Copilot finished work on behalf of lpcox May 21, 2026 00:26
@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 95.73% 95.79% 📈 +0.06%
Statements 95.56% 95.62% 📈 +0.06%
Functions 96.86% 96.70% 📉 -0.16%
Branches 89.30% 89.24% 📉 -0.06%
📁 Per-file Coverage Changes (3 files)
File Lines (Before → After) Statements (Before → After)
src/test-helpers/docker-test-fixtures.test-utils.ts 100.0% → 90.9% (-9.10%) 100.0% → 90.9% (-9.10%)
src/config-writer.ts 83.0% → 85.6% (+2.54%) 83.0% → 85.6% (+2.54%)
src/commands/validate-options.ts 87.3% → 100.0% (+12.70%) 86.4% → 100.0% (+13.62%)
✨ New Files (4 files)
  • src/commands/validators/agent-options.ts: 93.0% lines
  • src/commands/validators/config-assembly.ts: 83.0% lines
  • src/commands/validators/log-and-limits.ts: 95.2% lines
  • src/commands/validators/network-options.ts: 81.3% lines

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

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test Results

✅ GitHub API: 2 PR entries confirmed in recent-prs.json
✅ Playwright: GitHub homepage loaded, title contains "GitHub"
✅ File verify: smoke-test-claude-26197938438.txt exists

Result: PASS

💥 [THE END] — Illustrated by Smoke Claude

@github-actions
Copy link
Copy Markdown
Contributor

🔥 Smoke Test: Copilot BYOK (Offline) Mode

Test Result
GitHub MCP connectivity ✅ PR listed successfully
GitHub.com HTTP ⚠️ Pre-step template vars unresolved
File write/read ⚠️ Pre-step template vars unresolved
BYOK inference (api-proxy → api.githubcopilot.com) ✅ Responding now

Running in BYOK offline mode (COPILOT_OFFLINE=true) via api-proxy → api.githubcopilot.com.

Author: @Copilot | Assignees: @lpcox, @Copilot

Overall: PARTIAL PASS (core BYOK path ✅; pre-step data not injected into prompt)

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions
Copy link
Copy Markdown
Contributor

🔬 Smoke Test Results

Test Status
GitHub MCP connectivity
GitHub.com HTTP connectivity ⚠️ (template vars not expanded)
File write/read ⚠️ (template vars not expanded)

PR: "refactor: extract useCleanupTestDir to eliminate repeated test boilerplate"
Author: @Copilot | Assignees: @lpcox, @Copilot

Overall: PARTIAL — MCP ✅, pre-step outputs were not interpolated so HTTP/file tests could not be verified.

📰 BREAKING: Report filed by Smoke Copilot

@github-actions
Copy link
Copy Markdown
Contributor

Gemini Smoke Test: GitHub MCP: FAIL, Connectivity: FAIL, File Writing: PASS, Bash Tool: PASS. Overall: 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

Smoke Test Summary

Merged PRs: ✅ fix: flatten OTEL cache attribute names for Sentry compatibility; fix: align OTEL attributes with gen_ai semconv spec
Safe Inputs GH CLI: ❌ safeinputs-gh unavailable
Playwright: ✅ GitHub title verified | Tavily: ❌ search tool unavailable
File + bash: ✅ smoke-test-codex-26197938490.txt verified | Discussion: ✅ #3491 commented
Build AWF: ✅ npm ci && npm run build
Overall status: FAIL

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

Chroot Smoke Test Results

Runtime Host Version Chroot Version Match?
Python Python 3.12.13 Python 3.12.3
Node.js v24.15.0 v20.20.2
Go go1.22.12 go1.22.12

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

Tested by Smoke Chroot

@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 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 issue #3481 · ● 4.2M ·

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test Results

Check Result
Redis PING ❌ Timeout — no response
PostgreSQL pg_isready ❌ No response
PostgreSQL SELECT 1 ❌ Failed

Overall: FAILhost.docker.internal is unreachable from this runner environment. Service containers may not be running or the hostname is not resolvable.

🔌 Service connectivity validated by Smoke Services

@lpcox lpcox merged commit ae64aa6 into main May 21, 2026
65 of 68 checks passed
@lpcox lpcox deleted the copilot/fix-duplicate-code-setup branch May 21, 2026 00:42
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] Repeated beforeEach/afterEach testDir setup block across 6 describe groups in container-cleanup-branches.test.ts

3 participants