Skip to content

refactor: decompose prepareWorkDirectories into two focused sub-functions#5128

Merged
lpcox merged 6 commits into
mainfrom
copilot/refactor-prepare-work-directories
Jun 16, 2026
Merged

refactor: decompose prepareWorkDirectories into two focused sub-functions#5128
lpcox merged 6 commits into
mainfrom
copilot/refactor-prepare-work-directories

Conversation

Copilot AI commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

prepareWorkDirectories in src/workdir-setup.ts handled two unrelated concerns in a single 151-line function, making the security-critical chroot ownership logic hard to audit in isolation.

Changes

  • src/workdir-setup.ts

    • Extracts prepareLogDirectories(logPaths: LogPaths): void — creates all log/state directories (agentLogs, sessionState, squidLogs, apiProxyLogs, cliProxyLogs, MCP logs) with correct ownership
    • Extracts prepareChrootHomeMounts(config: WrapperConfig): void — creates the chroot home placeholder, whitelisted ~/. subdirectories, and runner tool-cache mountpoints with correct UID/GID before Docker bind mounts are established
    • prepareWorkDirectories becomes a backward-compatible two-line facade:
      export function prepareWorkDirectories(config: WrapperConfig, logPaths: LogPaths): void {
        prepareLogDirectories(logPaths);
        prepareChrootHomeMounts(config);
      }
    • Both sub-functions added to workdirSetupTestHelpers for independent unit testing
  • src/workdir-setup.test.ts

    • Adds dedicated describe blocks for prepareLogDirectories and prepareChrootHomeMounts that verify each concern in isolation (e.g. prepareLogDirectories must not touch chroot-home; prepareChrootHomeMounts must not create log directories)

No logic changes — purely structural.

Copilot AI changed the title [WIP] Refactor prepareWorkDirectories into two sub-functions refactor: decompose prepareWorkDirectories into two focused sub-functions Jun 16, 2026
Copilot finished work on behalf of lpcox June 16, 2026 18:52
Copilot AI requested a review from lpcox June 16, 2026 18:52
@lpcox lpcox marked this pull request as ready for review June 16, 2026 19:55
Copilot AI review requested due to automatic review settings June 16, 2026 19:55
@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 97.27% 97.31% 📈 +0.04%
Statements 97.15% 97.19% 📈 +0.04%
Functions 98.81% 98.82% ➡️ +0.01%
Branches 91.95% 91.98% 📈 +0.03%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/workdir-setup.ts 92.6% → 94.5% (+1.95%) 92.6% → 94.5% (+1.95%)

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

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 src/workdir-setup.ts to make the directory-preparation logic easier to audit by splitting the prior multi-concern prepareWorkDirectories implementation into two focused sub-functions (log/state directories vs. chroot-home bind mount preparation), while keeping prepareWorkDirectories as a small compatibility facade.

Changes:

  • Extracts prepareLogDirectories(logPaths) for log/session-state directory creation and ownership/permission setup.
  • Extracts prepareChrootHomeMounts(config) for chroot-home placeholder + whitelisted $HOME subdir + runner tool-cache mountpoint preparation.
  • Adds isolated unit tests for the two extracted sub-functions via workdirSetupTestHelpers.
Show a summary per file
File Description
src/workdir-setup.ts Splits directory setup into prepareLogDirectories and prepareChrootHomeMounts, with prepareWorkDirectories delegating to both.
src/workdir-setup.test.ts Adds dedicated test blocks that exercise the extracted sub-functions independently.

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: 3

Comment thread src/workdir-setup.test.ts Outdated
Comment thread src/workdir-setup.test.ts Outdated
Comment thread src/workdir-setup.test.ts
lpcox and others added 2 commits June 16, 2026 14:05
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Jun 16, 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.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@lpcox

lpcox commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Comment thread src/workdir-setup.test.ts Fixed

Copilot AI commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix thisfailing ci check https://github.com/github/gh-aw-firewall/actions/runs/27648122307/job/81765119494?pr=5128

Fixed in e34704d. The failing ESLint job was caused by a parse error in src/workdir-setup.test.ts (missing closing }); in the prepareChrootHomeMounts sub-function test). I added the missing closure and validated with npm run lint and npm test -- src/workdir-setup.test.ts.

@github-actions

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

Copy link
Copy Markdown
Contributor

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

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

🔌 Smoke Services — All services reachable! ✅

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Contribution Check failed. Please review the logs for details.

@github-actions

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

Copy link
Copy Markdown
Contributor

Smoke Gemini completed. All facets verified. 💎

Verifying safeoutputs

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Smoke Claude failed

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Security Guard has started processing this pull request

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

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

Copy link
Copy Markdown
Contributor

Build Test Suite completed successfully!

@github-actions

github-actions Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

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

🔬 Smoke Test: Copilot PAT Auth — PASS

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

PR: refactor: decompose prepareWorkDirectories into two focused sub-functions
Author: @Copilot | Assignees: @lpcox @Copilot
Auth mode: PAT (COPILOT_GITHUB_TOKEN)

Overall: PASS

🔑 PAT report filed by Smoke Copilot PAT

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Direct) Mode ✅ PASS

  • ✅ MCP GitHub connectivity
  • ✅ github.com connectivity (HTTP 200)
  • ✅ File write/read test
  • ✅ BYOK inference via api-proxy → api.githubcopilot.com

Running in direct BYOK mode with COPILOT_PROVIDER_API_KEY.

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions

Copy link
Copy Markdown
Contributor

🤖 Smoke Test Results

PR: refactor: decompose prepareWorkDirectories into two focused sub-functions
Author: @Copilot | Assignees: @lpcox, @Copilot

Test Result
GitHub MCP connectivity
GitHub.com HTTP connectivity ✅ 200
File write/read ⚠️ pre-step vars not substituted

Overall: PASS (core connectivity tests passed; pre-step outputs were not templated)

📰 BREAKING: Report filed by Smoke Copilot

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: GitHub Actions Services Connectivity

Check Result
Redis PING ❌ (connection timeout)
PostgreSQL pg_isready ❌ (no response)
PostgreSQL SELECT 1 ❌ (skipped — pg unreachable)

Overall: FAILhost.docker.internal services are not reachable from this runner.

🔌 Service connectivity validated by Smoke Services

@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smoke Test: API Proxy OpenTelemetry Tracing

Scenario Result Notes
1. Module Loading otel.js loads; exports startRequestSpan, setTokenAttributes, setBudgetAttributes, endSpan, endSpanError, shutdown, isEnabled
2. Test Suite 39/39 tests pass (otel.test.js)
3. Env Var Forwarding api-proxy-service-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, and OTEL_SERVICE_NAME
4. Token Tracker Integration token-tracker-http.js accepts onUsage callback via opts.onUsage (line 283); invoked with normalized usage at line 324
5. OTEL Diagnostics No OTEL endpoint configured → spans written to /var/log/api-proxy/otel.jsonl via FileSpanExporter (graceful degradation)

All scenarios pass. ✅

📡 OTel tracing validated by Smoke OTel Tracing

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results

  1. GitHub MCP Testing: ✅
  2. GitHub.com Connectivity: ❌ (Status 000/SSL Error)
  3. File Writing Testing: ✅
  4. 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

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 (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 summary for:

  • refactor: decompose prepareWorkDirectories into two focused sub-functions by Copilot

  • fix(ci-gate): tag PR owner with instructions

  • docs: sync schemas and specs with source changes

  • GitHub reads: ❌

  • Playwright title check: ✅

  • File write/cat: ✅

  • Discussion lookup/comment: ✅

  • Build: ✅

Overall: FAIL

🔮 The oracle has spoken through Smoke Codex

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

Generated by Build Test Suite for issue #5128 ·

@lpcox lpcox merged commit 0c76df9 into main Jun 16, 2026
83 of 85 checks passed
@lpcox lpcox deleted the copilot/refactor-prepare-work-directories branch June 16, 2026 22:58
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.

4 participants