Skip to content

refactor(tests): extract useAgentVolumesTestConfig to eliminate duplicated setup boilerplate#4263

Merged
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-usetempworkdir
Jun 3, 2026
Merged

refactor(tests): extract useAgentVolumesTestConfig to eliminate duplicated setup boilerplate#4263
lpcox merged 3 commits into
mainfrom
copilot/duplicate-code-usetempworkdir

Conversation

Copilot AI commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

The let mockConfig: WrapperConfig + useTempWorkDir(baseConfig, …) block was copy-pasted verbatim across all four agent-volumes-*.test.ts files (~18 lines × 4 = 72 duplicated lines), meaning any change to useTempWorkDir's API or baseConfig shape required edits in four places.

Changes

  • service-test-setup.test-utils.ts — adds useAgentVolumesTestConfig(), which encapsulates the let mockConfig binding and useTempWorkDir(baseConfig, …) call, returning a getConfig accessor:

    export function useAgentVolumesTestConfig(): { getConfig: () => WrapperConfig } {
      let mockConfig: WrapperConfig;
      useTempWorkDir(baseConfig, (c) => { mockConfig = c; }, () => mockConfig);
      return { getConfig: () => mockConfig };
    }
  • agent-volumes-{logs,security,workspace,mounts}.test.ts — replace the duplicated block with a single call at module scope:

    const { getConfig } = useAgentVolumesTestConfig();
    
    describe('agent service', () => {
      it('…', () => {
        const result = generateDockerCompose(getConfig(), mockNetworkConfig);
        // …
      });
    });

    Files that only used WrapperConfig for the let mockConfig declaration also drop that import.

Adds `useAgentVolumesTestConfig()` to `service-test-setup.test-utils.ts`
and updates all four `agent-volumes-*.test.ts` files to use it, removing
the ~18 duplicated lines of useTempWorkDir boilerplate from each file.

Closes #3320
Copilot AI changed the title [WIP] Refactor duplicated useTempWorkDir setup in agent-volumes tests refactor(tests): extract useAgentVolumesTestConfig to eliminate duplicated setup boilerplate Jun 3, 2026
Copilot finished work on behalf of lpcox June 3, 2026 14:11
Copilot AI requested a review from lpcox June 3, 2026 14:11
@lpcox lpcox marked this pull request as ready for review June 3, 2026 14:48
Copilot AI review requested due to automatic review settings June 3, 2026 14:48
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 96.42% 96.51% 📈 +0.09%
Statements 96.28% 96.37% 📈 +0.09%
Functions 98.12% 98.13% ➡️ +0.01%
Branches 90.36% 90.41% 📈 +0.05%
📁 Per-file Coverage Changes (3 files)
File Lines (Before → After) Statements (Before → After)
src/services/service-test-setup.test-utils.ts 100.0% → 90.9% (-9.10%) 100.0% → 93.3% (-6.67%)
src/config-writer.ts 89.3% → 90.9% (+1.65%) 89.3% → 90.9% (+1.65%)
src/host-iptables-rules.ts 97.6% → 100.0% (+2.37%) 97.7% → 100.0% (+2.33%)

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

@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.

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 agent-volumes-*.test.ts service unit tests to reduce duplicated test setup by extracting the repeated mockConfig + useTempWorkDir(baseConfig, ...) boilerplate into a shared helper in service-test-setup.test-utils.ts.

Changes:

  • Added useAgentVolumesTestConfig() helper to encapsulate temp workDir lifecycle wiring and expose a getConfig() accessor.
  • Updated agent-volumes-{logs,security,workspace,mounts}.test.ts to use useAgentVolumesTestConfig() instead of per-file let mockConfig + useTempWorkDir(...) blocks.
  • Simplified imports in updated tests by dropping no-longer-needed setup imports/types.
Show a summary per file
File Description
src/services/service-test-setup.test-utils.ts Introduces useAgentVolumesTestConfig() to centralize repeated agent-volumes test setup.
src/services/agent-volumes-workspace.test.ts Replaces local temp-dir setup with shared getConfig() accessor.
src/services/agent-volumes-security.test.ts Replaces local temp-dir setup with shared getConfig() accessor.
src/services/agent-volumes-mounts.test.ts Replaces local temp-dir setup with shared getConfig() accessor (formatting issues introduced in a couple blocks).
src/services/agent-volumes-logs.test.ts Replaces local temp-dir setup with shared getConfig() accessor.

Copilot's findings

Tip

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

  • Files reviewed: 5/5 changed files
  • Comments generated: 3

Comment on lines +35 to +45
export function useAgentVolumesTestConfig(): { getConfig: () => WrapperConfig } {
let mockConfig: WrapperConfig;
useTempWorkDir(
baseConfig,
(c) => {
mockConfig = c;
},
() => mockConfig,
);
return { getConfig: () => mockConfig };
}
Comment on lines +44 to +45
it('should mount required volumes in agent container (default behavior)', () => {
const result = generateDockerCompose(getConfig(), mockNetworkConfig);
Comment on lines 59 to 63
it('should use custom volume mounts when specified', () => {
const configWithMounts = {
...mockConfig,
...getConfig(),
volumeMounts: ['/workspace:/workspace:ro', '/data:/data:rw']
};
@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

lpcox commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

@copilot address review feedback

Copilot AI commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

@copilot address review feedback

Addressed in ebe6a02.

Copilot finished work on behalf of lpcox June 3, 2026 16:02
Comment thread src/services/agent-volumes-mounts.test.ts Dismissed
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Smoke Test: Claude Engine

Result: PASS

💥 [THE END] — Illustrated by Smoke Claude

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

🔥 Smoke Test: Copilot BYOK (Offline) Mode

Test Result
GitHub MCP (list PRs) ✅ Got PR #4265 "Remove test-only parseAgentTimeout export..."
GitHub.com connectivity ⚠️ Template vars not expanded (${{ steps.smoke-data.outputs.SMOKE_HTTP_CODE }})
File write/read ⚠️ Template vars not expanded — cannot verify
BYOK inference (this response) ✅ Running in BYOK offline mode (COPILOT_OFFLINE=true) via api-proxy → api.githubcopilot.com

Overall: PARTIAL — BYOK inference and MCP tools work. Pre-step template variables were not substituted in the prompt.

PR author: @Copilot | Assignees: @lpcox, @Copilot

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Remove test-only parseAgentTimeout export from option parser API ✅
Remove test-only export from signal handler dependencies ✅
GitHub homepage ✅
File write/read ✅
Discussion query/comment ✅
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

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

🧪 Smoke Test Results — PASS

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

PR: "refactor(tests): extract useAgentVolumesTestConfig to eliminate duplicated setup boilerplate"
Author: @Copilot | Assignees: @lpcox, @Copilot

🟢 Overall: PASS

📰 BREAKING: Report filed by Smoke Copilot

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Gemini Engine Smoke Test Results

  • GitHub MCP Testing: ❌ (mcpscripts command not found)
  • GitHub.com Connectivity: ❌ (Status 000, SSL error)
  • 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

github-actions Bot commented Jun 3, 2026

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.

Tested by Smoke Chroot

@github-actions

github-actions Bot commented Jun 3, 2026

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 passed ✅ PASS
Node.js execa passed ✅ PASS
Node.js p-limit passed ✅ PASS
Rust fd 0/0 passed ✅ PASS
Rust zoxide 0/0 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

Generated by Build Test Suite for issue #4263 · sonnet46 881.4K ·

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Smoke Test: GitHub Actions Services Connectivity

Check Result
Redis PING ❌ Timeout/no response
PostgreSQL pg_isready ❌ No response on port 5432
PostgreSQL SELECT 1 ❌ Timeout/no response

Overall: FAILhost.docker.internal is not reachable from this environment. Services are inaccessible.

🔌 Service connectivity validated by Smoke Services

@lpcox lpcox merged commit 4a0baee into main Jun 3, 2026
61 of 64 checks passed
@lpcox lpcox deleted the copilot/duplicate-code-usetempworkdir branch June 3, 2026 16:41
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] useTempWorkDir setup block duplicated across four agent-volumes test files

4 participants