CodeVetter · Repo Unpack · Behavior traces
cypress-io/cypress
Three concrete flows were followed across their relevant files: test-run startup/results, interception registration through response completion, and interactive-session persistence through CLI attachment. The traces below retain important branches such as dev verification bypass, recording delegation, static-response termination, and browser-readiness filtering. A supplementary startup trace explains how the interactive window becomes available.
- Run entry: bin/cypress.ts → CLI.init() → run command action → runModule.start() → processRunOptions() → spawnStart(); non-dev execution awaits binary verify.start(), while dev execution bypasses it.
- Run initialization: cypress.start() parses argv and selects run for runProject → startInMode() → runElectron() → modes factory → setCtx(makeDataContext()) and initializeMode() → modes/run.run() awaits loading and calls ready().
- Run completion: ready() discovers browsers and opens the project, validates recording parameters, and handles empty specs; runAllSpecs() calls runSpecs(), which invokes before:run → iterateThroughSpecs/runEachSpec → runSpec() → after:run → writeOutput(). Recording delegates through createRunAndRecordSpecs; POSIX mode collapses failure counts except reserved code 112.
- Intercept registration: addCommand() installs intercept → getMatcherOptions() → validateRouteMatcherOptions() → addRoute() → emitNetEvent('route:added') via Cypress.backend('net', ...) → onNetStubbingEvent() → onRouteAdded().
- Intercept request: SetMatchingRoutes() applies dev-server/preflight conditions and core.matchRoutes() → InterceptRequest() → core.handleRequest() → handleInterceptRequest() creates and registers InterceptedRequest → ensureBody() → addDefaultSubscriptions() → before:request handlers → merge changes → end() if responseSent, otherwise continueRequest().
- Intercept response: handleInterceptResponse() bypasses unmatched requests, obtains a plain-text/binary body, invokes before:response → response:callback → response subscriptions, merges response/header changes, and continues with getBodyStream(); response finish emits after:response and removes the request from server state.
- Session lifecycle: ProjectBase registers an open-mode session → addSession() creates UUID identity → persist() serializes writes and renames a temporary JSON file → CLI readLiveSessions() validates records/reaps dead PIDs → verifySessionRecord() checks the session echo and CDP /json/version → resolveSession() filters ready supported sessions → CDP attachment probes page targets for the tap binding.
- Interactive startup: modes factory starts initializeMode() → interactive.run() concurrently awaits app.whenReady() and makeGraphQLServer() → ready() loads saved state and opens the desktop window → optional 'Cypress is ready' sentinel lets detached CLI spawning destroy streams, unref the child, and resolve.