-
Notifications
You must be signed in to change notification settings - Fork 0
fix(app): tell the user localhost means the container, not their machine (#1346) #1347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e3e6c2a
fix(app): tell the user localhost means the container, not their machine
alfredorubin96 d617837
fix(cli): make host access an opt-in --expose-host flag, and say whos…
alfredorubin96 47c25ce
fix(cli): reject --expose-host without --full, and assert the mapping…
alfredorubin96 d6f874b
test: stop the compose check depending on a gitignored generated file
alfredorubin96 e1be17c
test: compare the extra_hosts MAPPING, not compose's spelling of it
alfredorubin96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { describe, it, expect, vi, beforeEach } from "vitest"; | ||
|
|
||
| const mockExistsSync = vi.fn(); | ||
| vi.mock("node:fs", () => ({ existsSync: (p: string) => mockExistsSync(p) })); | ||
|
|
||
| import { isContainerised, _resetContainerisedCache } from "../is-containerised"; | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| _resetContainerisedCache(); | ||
| }); | ||
|
|
||
| describe("isContainerised (#1346)", () => { | ||
| it("reports true when /.dockerenv exists", () => { | ||
| mockExistsSync.mockReturnValue(true); | ||
| expect(isContainerised()).toBe(true); | ||
| expect(mockExistsSync).toHaveBeenCalledWith("/.dockerenv"); | ||
| }); | ||
|
|
||
| it("reports false on a host install", () => { | ||
| // The case that keeps the hint honest: a local-mode user pointing at | ||
| // localhost is correct, and must not be told to use a Docker hostname. | ||
| mockExistsSync.mockReturnValue(false); | ||
| expect(isContainerised()).toBe(false); | ||
| }); | ||
|
|
||
| it("checks the filesystem only once", () => { | ||
| // Called from an error path; the answer cannot change while the process | ||
| // runs, so a stat per failed connection test would be pure waste. | ||
| mockExistsSync.mockReturnValue(true); | ||
| isContainerised(); | ||
| isContainerised(); | ||
| isContainerised(); | ||
| expect(mockExistsSync).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it("caches false as firmly as true", () => { | ||
| // `cached ??= …` treats a cached false as unset if written naively. | ||
| mockExistsSync.mockReturnValue(false); | ||
| expect(isContainerised()).toBe(false); | ||
| expect(isContainerised()).toBe(false); | ||
| expect(mockExistsSync).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { existsSync } from "node:fs"; | ||
|
|
||
| /** | ||
| * Is this process running inside a container? | ||
| * | ||
| * Used to tell two identical-looking failures apart: a connection to | ||
| * `localhost` that fails from the host is a real network problem, while the | ||
| * same failure from inside a container usually means `localhost` resolved to | ||
| * the container rather than the user's machine (#1346). | ||
| * | ||
| * `/.dockerenv` is written by the Docker runtime and is the cheap, stable | ||
| * signal. Evaluated once — the answer cannot change while the process runs, | ||
| * and this is called from an error path. | ||
| */ | ||
| let cached: boolean | undefined; | ||
|
|
||
| export function isContainerised(): boolean { | ||
| cached ??= existsSync("/.dockerenv"); | ||
| return cached; | ||
| } | ||
|
|
||
| /** @internal — test-only, since the answer is cached for the process lifetime. */ | ||
| export function _resetContainerisedCache(): void { | ||
| cached = undefined; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Co-locate these tests with their sources.
cli/src/__tests__/commands/start.test.ts#L277-L284: move tocli/src/commands/__tests__/start.test.ts.cli/src/__tests__/lib/docker.test.ts#L99-L134: move tocli/src/lib/__tests__/docker.test.ts.As per coding guidelines, tests live in an
__tests__/directory next to the file under test, within the same package.📍 Affects 2 files
cli/src/__tests__/commands/start.test.ts#L277-L284(this comment)cli/src/__tests__/lib/docker.test.ts#L99-L134🤖 Prompt for AI Agents
Source: Coding guidelines