refactor: split src/host-env.ts into focused modules#3259
Conversation
src/host-env.ts into focused modules
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
This PR refactors src/host-env.ts by splitting it into focused modules to reduce coupling and make the UID/GID handling easier to audit, while keeping src/host-env.ts as a backwards-compatible facade.
Changes:
- Introduces new focused modules:
src/constants.ts,src/docker-host.ts,src/host-identity.ts, andsrc/github-env.ts. - Converts
src/host-env.tsinto a facade that re-exports the new modules while retaining a few host-env-specific utilities/types. - Updates multiple production callers to import from the focused modules instead of
host-env.
Show a summary per file
| File | Description |
|---|---|
| src/services/squid-service.ts | Imports squid constants from ../constants while keeping SslConfig from host-env. |
| src/services/doh-proxy-service.ts | Switches container-name import to ../constants. |
| src/services/cli-proxy-service.ts | Switches container-name import to ../constants; keeps parseDifcProxyHost from host-env. |
| src/services/api-proxy-service.ts | Switches constants import to ../constants and moves readEnvFile import to ../github-env. |
| src/services/agent-service.ts | Moves host UID/GID helpers + ACT preset image import to ../host-identity; constants to ../constants. |
| src/services/agent-environment.ts | Splits imports across ../constants, ../host-identity, and ../github-env for clarity. |
| src/host-identity.ts | New module containing UID/GID/home-dir logic and related constants. |
| src/github-env.ts | New module for GitHub Actions env/path recovery and env-file parsing. |
| src/docker-host.ts | New module for Docker host override + local docker env selection. |
| src/constants.ts | New module containing container name constants, SQUID_PORT, and env-size thresholds. |
| src/host-env.ts | Becomes a facade re-exporting focused modules, while retaining SslConfig, stripScheme, parseDifcProxyHost, and subnet overlap helpers. |
| src/container-lifecycle.ts | Imports container constants from ./constants and docker env helper from ./docker-host. |
| src/container-cleanup.ts | Imports container constants from ./constants and docker env helper from ./docker-host. |
| src/config-writer.ts | Switches to SQUID_PORT from ./constants and host identity helpers from ./host-identity. |
| src/compose-generator.ts | Switches getRealUserHome import to ./host-identity (keeps SslConfig from host-env). |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 15/15 changed files
- Comments generated: 1
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@copilot merge main |
Done — merged |
Smoke Test Results❌ GitHub API: gh CLI not authenticated in sandboxed environment Overall: FAIL (2/3 tests passed)
|
Smoke Test: Copilot BYOK (Offline) Mode — Run #25969530767
Running in BYOK offline mode ( Overall: PARTIAL (2/4 fully verified; 1 env issue, 1 infra limitation)
|
🔬 Smoke Test Results
Overall: PASS (MCP 401 is a sandbox credential limitation, not a functional failure) Author:
|
|
Smoke test: FAIL Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "registry.npmjs.org"See Network Configuration for more information.
|
|
Smoke test failed Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "localhost"See Network Configuration for more information.
|
Chroot Smoke Test Results
Result: ❌ Not all tests passed — Python and Node.js versions differ between host and chroot.
|
Smoke Test Results — Services Connectivity
Overall: FAIL —
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS
|
src/host-env.tshad grown to 514 lines mixing 8 unrelated concerns, making the security-critical UID/GID path hard to audit in isolation and forcing every importer to take a dependency on everything.New modules
src/constants.tsSQUID_PORT, env-size thresholdssrc/docker-host.tssetAwfDockerHost,getLocalDockerEnvsrc/host-identity.tsvalidateIdNotInSystemRange,getSafeHostUid,getSafeHostGid,getRealUserHome,ACT_PRESET_BASE_IMAGE,MIN_REGULAR_UIDsrc/github-env.tsreadGitHubPathEntries,readGitHubEnvEntries,parseGitHubEnvFile,mergeGitHubPathEntries,readEnvFile,TOOLCHAIN_ENV_VARS,extractGhHostFromServerUrlsrc/host-env.ts(facade, ~125 lines)Retains
subnetsOverlap/testHelpers,SslConfig,stripScheme, andparseDifcProxyHostdirectly. Re-exports everything from the four new modules for backward compatibility — existing tests importing from./host-envcontinue to work unchanged.Caller updates
All 12 production callers updated to import from the focused module that owns what they need: