fix: prevent premature config load for unconfigured projects in monorepo sub-directories#34129
Open
mschile wants to merge 5 commits into
Open
fix: prevent premature config load for unconfigured projects in monorepo sub-directories#34129mschile wants to merge 5 commits into
mschile wants to merge 5 commits into
Conversation
When opening an unconfigured project straight into component testing (cypress open --component) from a monorepo sub-directory, framework detection was skipped and the user was asked to pick a framework even though one was installed. The relevant-runs poller calls projectId() as soon as git commit shas are found. In a sub-directory with no local .git, those shas come from the parent repo, so the poller fires during startup and forces getProjectId() -> getConfig() to load a non-existent cypress.config.js. That throws CONFIG_FILE_REQUIRE_ERROR, leaves the lifecycle in an error state, and makes waitForInitializeSuccess() resolve false -- so initializeProjectSetup() (and its CT framework auto-detection) is skipped. git init in the sub-directory was a known workaround because an empty repo has no shas, so the poller returns early. getProjectId() now returns null when the project has no config file, matching the existing readyToInitialize gate, instead of forcing a load. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
--component in monorepo sub-directoriesCursor Bugbot risk assessment is no longer Low Risk. Auto-approval dismissed; manual review required.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…othendieck-eb2357 # Conflicts: # cli/CHANGELOG.md
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
--componentused to open) #27410Additional details
When an unconfigured project (no
cypress.config.*) is opened directly into a testing type from a monorepo sub-directory, startup breaks in two ways that share a single root cause:cypress open --component(CT setup detection may fail if launchpad skipped (--componentused to open) #27410): framework detection is skipped and the user is asked to pick a framework even though one is installed.cypress open --e2e(open with --e2e in unconfigured monorepo hangs #29544): the launchpad hangs forever on "Initializing config…".Going through the launchpad manually (
cypress open→ select a testing type) works in both cases, andgit initin the sub-directory was a known workaround for both.Root cause: The relevant-runs poller calls
projectId()as soon as git commit shas are found. In a sub-directory with no local.git, those shas come from the parent repo, so the poller fires during startup and forcesgetProjectId()→getConfig()to load a non-existentcypress.config.js. That throwsCONFIG_FILE_REQUIRE_ERROR, leaves the lifecycle in an error state, and makeswaitForInitializeSuccess()resolvefalse— soinitializeProjectSetup()is skipped. For--componentthat skips CT framework auto-detection; for--e2ethat skips the config scaffold (scaffoldTestingType/scaffoldE2E), so the config file is never created and the launchpad retries the failing config load indefinitely.git initworked around it because an empty repo has no shas, so the poller returns early.Fix:
getProjectId()now returnsnullwhen the project has no valid config file instead of forcing a config load. An unconfigured project has noprojectId, and this matches the existingreadyToInitializegate that already restricts config loading tometaState.hasValidConfigFile.getConfig()is intentionally left unchanged — it's a shared accessor whose other callers rely on it loading the full config; the invariant being expressed ("unconfigured → no projectId") belongs at thegetProjectIdlayer.Steps to test
Component (#27410):
npx cypress open --component(do notgit initin the sub-directory).E2E (#29544):
npx cypress open --e2e(do notgit initin the sub-directory).cypress.config.jsand reaches the browser-selection screen instead of hanging on "Initializing config…".Verified manually against both repros on the built dev binary. For
--component, the server-sidewizard.frameworkwasnull("Pick a framework") before the fix and resolves React.js + Vite after. For--e2e, before the fix the config IPC repeatedly threwCONFIG_FILE_REQUIRE_ERRORfor the missingcypress.config.jsand no file was scaffolded; after the fix the project scaffolds and proceeds. Confirmedgit initin the sub-directory also works (the original workaround), and that the configured-project path is unchanged.How has the user experience changed?
In a monorepo sub-directory with an unconfigured project:
cypress open --componentnow auto-detects the installed framework/bundler instead of showing "Pick a framework".cypress open --e2enow scaffolds the config and continues to browser selection instead of hanging on "Initializing config…".Before
--component:Front-end framework: Pick a framework--e2e: hangs indefinitely on "Initializing config…"After
--component:Front-end framework: React.js (detected)/Bundler: Vite (detected)--e2e: config is scaffolded and the browser-selection screen is shownPR Tasks
cypress-documentation?type definitions?Note
Low Risk
Small, targeted guard in project lifecycle startup with unit tests; behavior for projects with a valid config is unchanged.
Overview
Fixes monorepo sub-directory opens where an unconfigured project (no
cypress.config.*) skipped setup:--componentmissed framework auto-detection and--e2ecould hang on "Initializing config…".ProjectLifecycleManager.getProjectId()now returnsnullwhenmetaState.hasValidConfigFileis false instead of callinggetConfig(). That stops startup paths (e.g. Cloud relevant-runs polling after parent-repo git SHAs) from forcing a load of a missing config, which previously put the lifecycle in an error state and blockedinitializeProjectSetup(). Configured projects still load config and returnprojectIdas before.Unit tests cover both branches; 15.17.1 changelog documents the fix (#27410, #29544).
Reviewed by Cursor Bugbot for commit bb1a112. Bugbot is set up for automated code reviews on this repo. Configure here.