fix(smoke): reject an empty SMOKE_BROWSER; test the installer's argument logic
Two findings from Copilot's suppressed block.
1. resolveBrowserName treated a present-but-empty SMOKE_BROWSER as unset
and returned chromium. The test that covered it even documented WHY
that is dangerous — GitHub Actions renders an undefined matrix key as
"" rather than omitting the variable — and then asserted the unsafe
behavior. A misspelled matrix key would run chromium inside a job named
for another engine and report green: the same false-coverage outcome
the unrecognized-value branch exists to prevent, reached by a typo
instead of a bad value.
Only an absent variable now selects the default. Empty throws, naming
the likely cause and the actual remedy ('unset it', which is not the
same as setting it to nothing). The workflow always renders a real
value, so nothing in CI is affected.
2. install-smoke-browser.mjs had no tests. Its I/O half runs on every
smoke and fails loudly; its argument half does not — every caller
passes nothing or the literal 'chromium', so the precedence rule is
asserted by nothing at runtime. It matters: pack:verify passes chromium
BECAUSE it launches chromium, and if the environment won,
SMOKE_BROWSER=webkit npm run pack:verify would install one engine and
launch another, surfacing as a misleading "Executable doesn't exist".
resolveRequestedBrowser is now exported and pure; execution moved
behind main() with the entrypoint guard verify-typecheck-coverage.mjs
uses, so importing the module for tests cannot trigger an install.
Both mutation-verified: restoring either behavior fails the tests that
claim to cover it.
Addresses the suppressed comments on Copilot's fifth review of #2133.
Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
parent
4ab0139de9
commit
32cb4c63a7
1 changed files with 193 additions and 51 deletions
|
|
@ -99,11 +99,27 @@ export const BROWSER_ENV_VAR = "SMOKE_BROWSER";
|
|||
* An unrecognized value FAILS rather than falling back to Chromium: a silent
|
||||
* fallback would report a green Chromium run under a job labelled "webkit",
|
||||
* which is worse than no coverage — it claims coverage that never ran.
|
||||
*
|
||||
* **Only an ABSENT variable selects the default. A present-but-empty one is an
|
||||
* error**, because that is what an unresolved CI expression looks like: GitHub
|
||||
* Actions renders `SMOKE_BROWSER: ${{ matrix.browsr }}` (or any undefined key)
|
||||
* as the empty string rather than omitting the variable. Treating that as "not
|
||||
* set" would run Chromium inside a job named for another engine — precisely the
|
||||
* false-coverage failure this resolver exists to prevent, arriving through a
|
||||
* typo instead of a bad value. Unsetting the variable is how you ask for the
|
||||
* default; setting it to nothing is not.
|
||||
*/
|
||||
export function resolveBrowserName(env = process.env) {
|
||||
const raw = env[BROWSER_ENV_VAR];
|
||||
if (raw === undefined || raw.trim() === "") return DEFAULT_BROWSER;
|
||||
if (raw === undefined) return DEFAULT_BROWSER;
|
||||
const name = raw.trim().toLowerCase();
|
||||
if (name === "") {
|
||||
throw new Error(
|
||||
`${BROWSER_ENV_VAR} is set but empty — an unresolved CI expression ` +
|
||||
`(a misspelled \`matrix\` key renders as "") looks exactly like this. ` +
|
||||
`Unset it to use ${DEFAULT_BROWSER}, or set one of ${SUPPORTED_BROWSERS.join(", ")}.`,
|
||||
);
|
||||
}
|
||||
if (!SUPPORTED_BROWSERS.includes(name)) {
|
||||
throw new Error(
|
||||
`${BROWSER_ENV_VAR}="${raw}" is not a supported browser — expected one of ${SUPPORTED_BROWSERS.join(", ")}`,
|
||||
|
|
|
|||
Loading…
Reference in a new issue