Repository navigation
feat(cli): name a caller's owner id on the browsers and warm check it starts #7687
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 all commits
Commits
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 |
|---|---|---|
| @@ -1,19 +1,34 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { HYPERFRAMES_BROWSER_MARKER_ARG, withHyperframesBrowserMarker } from "./browserMarker.js"; | ||
| import { | ||
| HYPERFRAMES_BROWSER_MARKER_ARG, | ||
| withHyperframesBrowserMarker, | ||
| withoutHyperframesOwner, | ||
| } from "./browserMarker.js"; | ||
|
|
||
| describe("withHyperframesBrowserMarker", () => { | ||
| it("appends the marker to a copy of the args", () => { | ||
| const args = ["--no-sandbox"]; | ||
| expect(withHyperframesBrowserMarker(args)).toEqual([ | ||
| expect(withHyperframesBrowserMarker(args, {})).toEqual([ | ||
| "--no-sandbox", | ||
| HYPERFRAMES_BROWSER_MARKER_ARG, | ||
| ]); | ||
| expect(args).toEqual(["--no-sandbox"]); | ||
| }); | ||
|
|
||
| it("adds the marker once when a wrapper marks already-marked args", () => { | ||
| expect(withHyperframesBrowserMarker(withHyperframesBrowserMarker())).toEqual([ | ||
| expect(withHyperframesBrowserMarker(withHyperframesBrowserMarker([], {}), {})).toEqual([ | ||
| HYPERFRAMES_BROWSER_MARKER_ARG, | ||
| ]); | ||
| }); | ||
|
|
||
| // fails without the fix: a caller running several renders at once could not tell whose browser was whose. | ||
| it("names the caller's owner once, and only a plain id", () => { | ||
| const owned = { HYPERFRAMES_OWNER: "run-7" }; | ||
| const args = withHyperframesBrowserMarker(withHyperframesBrowserMarker([], owned), owned); | ||
| expect(args).toEqual([HYPERFRAMES_BROWSER_MARKER_ARG, "--hyperframes-owner=run-7"]); | ||
| expect(withoutHyperframesOwner(args)).toEqual([HYPERFRAMES_BROWSER_MARKER_ARG]); | ||
| expect( | ||
| withHyperframesBrowserMarker([], { HYPERFRAMES_OWNER: "x --remote-debugging-port=9" }), | ||
| ).toEqual([HYPERFRAMES_BROWSER_MARKER_ARG]); | ||
| }); | ||
| }); |
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 |
|---|---|---|
| @@ -1,8 +1,26 @@ | ||
| /** An inert Chrome switch on every browser HyperFrames launches, so orphan cleanup can tell its own from other tools'. */ | ||
| export const HYPERFRAMES_BROWSER_MARKER_ARG = "--hyperframes-owned-browser"; | ||
|
|
||
| export function withHyperframesBrowserMarker(args: readonly string[] = []): string[] { | ||
| return args.includes(HYPERFRAMES_BROWSER_MARKER_ARG) | ||
| /** Set by a caller that runs several renders at once, so each one's browsers and warm checks name it. */ | ||
| export const HYPERFRAMES_OWNER_ENV = "HYPERFRAMES_OWNER"; | ||
| export const HYPERFRAMES_OWNER_ARG = "--hyperframes-owner"; | ||
|
|
||
| export function hyperframesOwnerArgs(source: NodeJS.ProcessEnv = process.env): string[] { | ||
| const owner = source[HYPERFRAMES_OWNER_ENV]; | ||
| return owner && /^[\w.-]{1,64}$/.test(owner) ? [`${HYPERFRAMES_OWNER_ARG}=${owner}`] : []; | ||
| } | ||
|
|
||
| const isOwnerArg = (arg: string) => arg.startsWith(`${HYPERFRAMES_OWNER_ARG}=`); | ||
|
|
||
| export function withHyperframesBrowserMarker( | ||
| args: readonly string[] = [], | ||
| source: NodeJS.ProcessEnv = process.env, | ||
| ): string[] { | ||
| const marked = args.includes(HYPERFRAMES_BROWSER_MARKER_ARG) | ||
| ? [...args] | ||
| : [...args, HYPERFRAMES_BROWSER_MARKER_ARG]; | ||
| return marked.some(isOwnerArg) ? marked : [...marked, ...hyperframesOwnerArgs(source)]; | ||
| } | ||
|
|
||
| export const withoutHyperframesOwner = (args: readonly string[]): string[] => | ||
| args.filter((arg) => !isOwnerArg(arg)); |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.