Skip to content

feat: automatically update hosts file when domain resolution fails#2808

Open
sjinks wants to merge 1 commit intotrunkfrom
z-225776
Open

feat: automatically update hosts file when domain resolution fails#2808
sjinks wants to merge 1 commit intotrunkfrom
z-225776

Conversation

@sjinks
Copy link
Copy Markdown
Member

@sjinks sjinks commented May 1, 2026

Description

We will try to automatically update the /etc/hosts file when domain resolution fails.

This feature is not enabled by default and is guarded by a command-line option (TBD).

Currently, it is not available on Windows (console handles don't cross the UAC boundary; Node's spawn will also fail due to the requireAdministrator manifest. These issues are solvable, but I will address them later).

The idea is to collect the list of the failed domains and add them to the system's hosts file using an external binary with elevated privileges.

hosts-updater.mp4

Changelog Description

Added

  • TBD

Pull request checklist

New release checklist

Steps to Test

echo '127.0.0.2 vip-local.vipdev.lndo.site' | sudo tess -a /etc/hosts
vip dev-env create < /dev/null
vip dev-env start -a

@sjinks sjinks self-assigned this May 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 1, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@sjinks sjinks force-pushed the z-225776 branch 5 times, most recently from 6c7c9cd to 021d0a3 Compare May 4, 2026 09:39
@sjinks sjinks marked this pull request as ready for review May 4, 2026 09:48
Copilot AI review requested due to automatic review settings May 4, 2026 09:48
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 adds an optional dev-env startup flow that tries to repair local DNS resolution problems by downloading a helper binary and using it to update the system hosts file when Lando URLs do not resolve to loopback. It extends the dev-environment startup path and introduces a new helper module to install and invoke the external updater.

Changes:

  • Added a new hosts-updater helper that resolves release URLs, downloads/checksums the updater binary, picks an install directory, and spawns the updater process.
  • Wired optional domain autofix behavior into landoStart/landoRebuild and the core start flow.
  • Added a new non-Windows CLI flag, --autofix-domain-resolution, to enable the feature.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 6 comments.

File Description
src/lib/dev-environment/hosts-updater.ts New helper module for downloading, installing, validating, and executing the hosts updater binary.
src/lib/dev-environment/dev-environment-lando.ts Hooks autofix logic into Lando start/rebuild and domain-resolution checks.
src/lib/dev-environment/dev-environment-core.ts Threads the new autofix option through the environment start orchestration.
src/bin/vip-dev-env-start.js Exposes the new CLI flag and passes it into the start flow.

Comment thread src/lib/dev-environment/hosts-updater.ts
Comment thread src/lib/dev-environment/hosts-updater.ts Outdated
Comment thread src/lib/dev-environment/hosts-updater.ts Outdated
Comment thread src/lib/dev-environment/hosts-updater.ts Outdated
Comment thread src/lib/dev-environment/hosts-updater.ts
Comment thread src/lib/dev-environment/hosts-updater.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

Copilot reviewed 4 out of 5 changed files in this pull request and generated 5 comments.

Comment thread src/lib/dev-environment/hosts-updater.ts
Comment thread src/lib/dev-environment/hosts-updater.ts Outdated
Comment thread src/lib/dev-environment/dev-environment-lando.ts Outdated
Comment thread src/lib/dev-environment/dev-environment-lando.ts
Comment thread src/lib/dev-environment/hosts-updater.ts Outdated
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

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

Comment thread src/lib/dev-environment/hosts-updater.ts Outdated
Comment thread src/lib/dev-environment/dev-environment-lando.ts
Comment thread src/lib/dev-environment/dev-environment-lando.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

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

Comment on lines +826 to +842
try {
await access( binary, constants.X_OK );
} catch {
try {
binary = await installBinary( 'latest', dir, AUTOFIX_DOWNLOAD_TIMEOUT_MS );
} catch ( err: unknown ) {
return new Error(
'Failed to install hosts updater binary, cannot autofix domain resolution issues.',
{ cause: ensureError( err ) }
);
}
}

const fixableDomains = domains.filter( domain => ! domain.includes( '*' ) );
if ( fixableDomains.length ) {
try {
await updateDomains( binary, fixableDomains );
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's acceptable for now. Anyway, we cannot write the file to a location that isn't writable by the user.

Comment on lines +823 to +836
const filename = getExeName();
let binary: string = path.join( dir, filename );

try {
await access( binary, constants.X_OK );
} catch {
try {
binary = await installBinary( 'latest', dir, AUTOFIX_DOWNLOAD_TIMEOUT_MS );
} catch ( err: unknown ) {
return new Error(
'Failed to install hosts updater binary, cannot autofix domain resolution issues.',
{ cause: ensureError( err ) }
);
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine for now.

Comment thread src/lib/dev-environment/dev-environment-lando.ts
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 4, 2026

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 4, 2026

@sjinks sjinks deployed to npm-publish May 5, 2026 08:41 — with GitHub Actions Active
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.

2 participants