Skip to content

refactor: decompose 287-line assembleAndValidateConfig into named helpers#4894

Merged
lpcox merged 4 commits into
mainfrom
copilot/refactor-assemble-and-validate-config
Jun 13, 2026
Merged

refactor: decompose 287-line assembleAndValidateConfig into named helpers#4894
lpcox merged 4 commits into
mainfrom
copilot/refactor-assemble-and-validate-config

Conversation

Copilot AI commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

assembleAndValidateConfig mixed three unrelated concerns in a single 287-line function: an env-file parsing utility, config assembly, and seven independent post-assembly validation guards.

Changes

src/parsers/env-parsers.ts

  • Adds readEnvVarFromEnvFiles(envFile, key) as a reusable module-level export, replacing the 29-line nested closure that was previously only accessible inside assembleAndValidateConfig.

src/commands/validators/config-assembly.ts

Seven inline guard blocks extracted into named helpers:

Helper Responsibility
validateInfrastructureOptions --docker-host URI, path prefix & chroot binaries path
applyRateLimitConfig Rate-limit config build + flag/proxy compatibility
validateFeatureFlagCompatibility Token-steering flag + --env-all/--env-file logging
validateHostAccessConfig Host ports, --skip-pull/--build-local, host.docker.internal warn
validateApiProxyOptions API proxy key validation, status logging, target-domain warnings
validateCopilotModelOption Resolves COPILOT_MODEL from all sources and validates identifier

assembleAndValidateConfig is now a ~40-line orchestrator:

export function assembleAndValidateConfig(...): WrapperConfig {
  const config = buildConfig({ ... });
  validateInfrastructureOptions(config);
  applyAgentTimeout(options.agentTimeout as string | undefined, config, logger);
  applyRateLimitConfig(config, options);
  validateFeatureFlagCompatibility(config);
  validateHostAccessConfig(config, networkOptions);
  validateApiProxyOptions(config, networkOptions);
  validateCopilotModelOption(config, agentOptions);
  return config;
}

No behaviour changes; all 39 existing tests pass.

- Extract `readEnvVarFromEnvFiles` to `src/parsers/env-parsers.ts` as a
  reusable exported helper (replaces the 29-line nested closure)
- Extract 5 named post-assembly validation helpers within config-assembly.ts:
  - `validateInfrastructureOptions` – docker host URI, path prefix, chroot binaries path
  - `applyRateLimitConfig` – rate-limit config build + flag validation
  - `validateFeatureFlagCompatibility` – token steering flag + env-all/env-file logs
  - `validateHostAccessConfig` – host service ports, host ports, skip-pull, docker.internal warn
  - `validateApiProxyOptions` – API proxy validation, status logging, target warnings, CLI proxy
  - `validateCopilotModelOption` – COPILOT_MODEL resolution and model-id validation
- `assembleAndValidateConfig` reduces from 287 lines to ~40 lines (orchestrator only)
- All 39 existing tests continue to pass; TypeScript compiles cleanly
Copilot AI changed the title [WIP] Refactor assembleAndValidateConfig function for improved clarity refactor: decompose 287-line assembleAndValidateConfig into named helpers Jun 13, 2026
Copilot AI requested a review from lpcox June 13, 2026 17:23
Copilot finished work on behalf of lpcox June 13, 2026 17:23
@lpcox lpcox marked this pull request as ready for review June 13, 2026 17:25
Copilot AI review requested due to automatic review settings June 13, 2026 17:26
@github-actions

github-actions Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 96.62% 96.66% 📈 +0.04%
Statements 96.49% 96.54% 📈 +0.05%
Functions 98.78% 98.79% 📈 +0.01%
Branches 91.22% 91.25% 📈 +0.03%
📁 Per-file Coverage Changes (3 files)
File Lines (Before → After) Statements (Before → After)
src/commands/validators/config-assembly.ts 98.3% → 98.1% (-0.20%) 97.5% → 98.1% (+0.62%)
src/parsers/env-parsers.ts 100.0% → 100.0% (+0.00%) 100.0% → 96.5% (-3.45%)
src/config-writer.ts 89.9% → 91.1% (+1.19%) 89.9% → 91.1% (+1.19%)

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

Refactors assembleAndValidateConfig by extracting env-file parsing and post-assembly validation logic into named helper functions, aiming to keep config assembly readable while preserving existing behavior.

Changes:

  • Added a reusable readEnvVarFromEnvFiles(envFile, key) export for env-file key lookup.
  • Extracted post-assembly validation/guard blocks into focused helper functions and simplified assembleAndValidateConfig into an orchestrator.
Show a summary per file
File Description
src/parsers/env-parsers.ts Introduces exported env-file variable reader used by config validation.
src/commands/validators/config-assembly.ts Decomposes post-assembly guard logic into helper functions and streamlines assembleAndValidateConfig.

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

Comment thread src/parsers/env-parsers.ts Outdated
Comment thread src/commands/validators/config-assembly.ts
lpcox and others added 2 commits June 13, 2026 10:30
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

Copy link
Copy Markdown
Contributor

🔥 Smoke Test: PAT Auth — PASS

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

Overall: PASS — Auth mode: PAT (COPILOT_GITHUB_TOKEN)

cc @lpcox @Copilot

🔑 PAT report filed by Smoke Copilot PAT

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results: Copilot BYOK (Direct Mode) ✅

Status: PASS

Test Result
MCP Connectivity
GitHub.com (HTTP 200)
File Write/Read
BYOK Inference Path

Mode: Direct BYOK (COPILOT_PROVIDER_API_KEY) → api-proxy sidecar → api.githubcopilot.com

cc @lpcox

🔑 BYOK report filed by Smoke Copilot BYOK

@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: decompose 287-line assembleAndValidateConfig into named helpers
Author: @CopilotAssignees: @lpcox @Copilot

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
Node.js v24.16.0 v22.22.3
Go go1.22.12 go1.22.12

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

Tested by Smoke Chroot

@github-actions

Copy link
Copy Markdown
Contributor

✅ fix(workflow): use gpt-5.4-mini and raise max-ai-credits for copilot-token-usage-analyzer
✅ Honor workflow-level COPILOT_MODEL in Copilot BYOK smoke workflows
✅ GitHub title check, file write, and build
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

@Copilot @lpcox
refactor: decompose 287-line assembleAndValidateConfig into named helpers
MCP connectivity: ✅
GitHub.com connectivity: ✅
File write/read test: ✅
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

@lpcox

  • GitHub MCP connectivity: ✅
  • GitHub.com connectivity: ✅
  • File write/read test: ❌
  • BYOK inference: ✅

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 status: FAIL

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

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: GitHub Actions Services Connectivity

Check Result
Redis PING ❌ timeout (no response on host.docker.internal:6379)
PostgreSQL pg_isready no response on host.docker.internal:5432
PostgreSQL SELECT 1 ❌ timeout (connection failed)

Overall: FAIL — Service containers are not reachable via host.docker.internal from this runner.

🔌 Service connectivity validated by Smoke Services

@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 #4894 ·

@lpcox lpcox merged commit 27e34e5 into main Jun 13, 2026
77 of 80 checks passed
@lpcox lpcox deleted the copilot/refactor-assemble-and-validate-config branch June 13, 2026 20:29
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