Skip to content

[BUG] [alpha] Test Coverage Run Tests with Coverage can keep targeting the previous workspace after a same-window project switch #36962

@angelicameri

Description

@angelicameri

Project

ide

Description

In mounted Test Coverage, switching to a different project in the same window does not rebind the testing context to the new workspace.

Visible result:

  1. open project A in the current window,
  2. let testing initialize there,
  3. switch to project B in the same window,
  4. trigger Run Tests with Coverage,
  5. the coverage run can still target project A and its old framework instead of the newly opened workspace.

So the coverage command can run against the wrong project after a same-window workspace switch.

Root Cause

Same-window workspace switches are event-driven and do not remount the app providers:

  • /src/utils/workingSurface.ts:24-28
    • openWorkspaceSurface(...) persists the new project path
    • dispatches workspace:open-folder
    • dispatches folder:did-open
  • /src/context/OptimizedProviders.tsx:212
    • TestingProvider is mounted globally with the app providers

Other contexts explicitly listen for the same-window workspace-open event and update themselves:

  • /src/context/WorkspaceContext.tsx:479-507
    • listens for workspace:open-folder
    • replaces workspace folders in the current window
  • /src/context/SDKContext.tsx:214-220
    • listens for workspace:open-folder
    • updates SDK cwd tracking

But TestingContext does not follow that workspace switch.

It only initializes from the project path once on mount:

  • /src/context/TestingContext.tsx:2021-2040
    • registers testing event listeners
    • loads settings
  • /src/context/TestingContext.tsx:2115-2117
    • reads getProjectPath() once
    • schedules discoverTests(projectPath) once after mount

discoverTests(...) stores the project path in state:

  • /src/context/TestingContext.tsx:453-455
    • setState("projectPath", projectPath)

But later refreshes keep using that stored path:

  • /src/context/TestingContext.tsx:542-545
    • refreshTests() calls discoverTests(state.projectPath)

And the coverage command also uses the stored testing state instead of re-reading the current workspace:

  • /src/context/TestingContext.tsx:1505-1537
    • runWithCoverage() uses state.projectPath
    • and state.framework.framework

There is a second stale-state problem on top of that: framework detection only runs when no framework has already been cached:

  • /src/context/TestingContext.tsx:458-460
    • if (!state.framework) { await detectFramework(projectPath); }

So even if some later path manually calls discoverTests(newProjectPath), the old framework from the previous workspace can still survive.

That leaves the coverage path able to run with:

  • the old project path,
  • the old framework,
  • or both,

after the UI has already switched to a different workspace.

Error Message

Debug Logs

System Information

- Cortex IDE `alpha`
- Platform: any

Screenshots

output.mp4

Steps to Reproduce

  1. Open project A in the current window.
    • Example: a Vitest or Jest workspace.
  2. Let the testing context initialize in that workspace.
  3. Without reloading the app, open project B in the same window using a same-window workspace-open flow.
    • Example: Recent Projects in current window, or another path that dispatches workspace:open-folder.
  4. Run Run Tests with Coverage.
  5. Observe which project/framework the coverage run actually uses.

Expected Behavior

After a same-window project switch, Run Tests with Coverage should target the newly opened workspace.

Testing state should be rebound to the new workspace, including:

  • projectPath
  • detected framework
  • discovered tests
  • coverage state that belongs to the previous workspace

Actual Behavior

TestingContext keeps using stale project/framework state captured from the previous workspace.

As a result, Run Tests with Coverage can continue targeting the old project after the UI has already switched to a different one.

Additional Context

This is not the same as the current live/local Test Coverage issues:

Those issues cover opt-in behavior, overlay command semantics, stylesheet lifecycle, hover math, metric mapping, and stale editor decorations after a failed rerun.

This report is specifically about same-window workspace switching:

  • the workspace changes,
  • TestingContext does not follow the new workspace,
  • and Run Tests with Coverage can still execute against the previous project.

Duplicate Check

Re-checked local (bug-3, bugs-codex) and targeted live repo searches across open and closed issues with:

  • coverage workspace switch old project
  • run with coverage old project after workspace switch
  • testing context workspace switch stale projectPath
  • test coverage stale project switch
  • testing provider workspace switch project path
  • local grep for coverage.*workspace switch, workspace switch.*coverage, old project.*coverage, and stale projectPath.*coverage

Findings:

  • Local: no matching draft found for coverage commands continuing to use stale testing workspace state after a same-window project switch.
  • Live repo: no matching issue found in PlatformNetwork/bounty-challenge for this exact frontend workspace-switch / stale-coverage-target bug at check time (2026-03-24 UTC).
  • Closest live/local items are different:
    • coverage opt-in behavior,
    • overlay command semantics,
    • stylesheet lifecycle,
    • stale decorations after a failed rerun.
  • Why they are different:
    • none of those reports cover TestingContext missing the same-window workspace:open-folder rebinding path and then using stale state.projectPath / state.framework when runWithCoverage() is triggered.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingideIssues related to IDEvalidValid issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions