Skip to content

Add a cmake refresh task and mark Test Explorer results outdated after refresh/build (#5007) - #5025

Open
Hannia Valera (hanniavalera) wants to merge 5 commits into
mainfrom
dev/hanniavalera/issue-5007
Open

Add a cmake refresh task and mark Test Explorer results outdated after refresh/build (#5007)#5025
Hannia Valera (hanniavalera) wants to merge 5 commits into
mainfrom
dev/hanniavalera/issue-5007

Conversation

@hanniavalera

@hanniavalera Hannia Valera (hanniavalera) commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Addresses #5007.

Comprehensive fix for #5007 ("refresh the test view from a task"), based on maintainer dogfooding of the original refresh-task change.

1. refresh command for the cmake task type

Adds a refresh command to the cmake task type that runs the same path as CMake: Refresh Tests (build the default target, then re-read the CTest information and refresh the Test Explorer). It can be chained after a build via dependsOn, and is invokable from automation that drives builds through tasks.

2. Mark previously-run test results as outdated (the real dogfooding bug)

Refreshing the tests re-populated the Test Explorer's items but never retired the prior TestRun results, so stale pass/fail icons kept looking current after a refresh or rebuild (the code even had a // TODO: There's no way to mark tests as outdated now.). VS Code's TestController.invalidateTestResults() is the supported way to mark results outdated (they render muted/de-emphasized, signalling "re-run me" — not literally "yellow", and not cleared).

This PR adds a project-root-scoped CTestDriver.markTestResultsOutdated(sourceDir) (never invalidates other projects sharing the singleton controller) and calls it:

  • after CMake: Refresh Tests and the refresh task (CMakeProject.refreshTests()),
  • after a successful Build, Build All, or Clean Rebuild (command or the type: cmake build task), since rebuilt binaries make prior results stale — this directly cures the "test view not visible during the build" scenario in [Feature] Ability to refresh Build Analyzer from a task #5007 without needing a second task.

Fail-safe design

Build-path invalidation is opt-in (markOutdated defaults false on CMakeProject.build()), so internal builds that run during an active test run — preTest, per-test target builds, coverage pre/post builds, API/programmatic builds — never retire an in-flight run's own results. The direct type: cmake build task uses an isInternalBuild flag so builds that CMake Tools launches internally via cmake.buildTask are excluded too; only genuine user-invoked builds/tasks invalidate. Clean (single or all) does not invalidate.

Validation

  • tsc, webpack, yarn lint: clean.
  • yarn backendTests: 369 passing. yarn unitTests: 330 passing.
  • Behavior verified for presets and kits modes; the Test Explorer path is gated by cmake.ctest.testExplorerIntegrationEnabled and test mode as before.

Manual verification checklist (Test Explorer state isn't assertable via the public API)

  • Run a passing/failing test, then CMake: Refresh Tests → prior results become muted ("outdated"), not cleared, not yellow.
  • Run a type: cmake build task with the Testing view closed → open it: tests are rediscovered and prior results are outdated.
  • Two-root workspace: refreshing/building root A leaves root B's results untouched.
  • With cmake.buildTask set, run tests with coverage → the just-finished run stays current (internal pre/post builds don't retire it).

Deliberately out of scope (possible follow-up): marking results outdated on every configure.

Builds and other automation driven through VS Code tasks (for example a build launched from another extension, where the CMake test view is not visible during the build) had no way to refresh the CMake test information afterwards: the 'CMake: Refresh Tests' command does it, but VS Code tasks cannot invoke arbitrary commands, and there was no equivalent 'cmake' task command.

Add a 'refresh' command to the 'cmake' task type that runs the same project.refreshTests() path as the 'CMake: Refresh Tests' command (build the default target, then re-read the CTest information and refresh the Test Explorer). It can be chained after a build task via dependsOn. Updates the task command enum in package.json, docs/tasks.md, and the changelog.
…ds (#5007)

After 'CMake: Refresh Tests', the refresh task, and a successful build/build-all/clean-rebuild (command or 'type: cmake' build task), previously-run tests are now marked outdated (muted) in the Test Explorer instead of misleadingly appearing current, since rebuilt binaries make earlier results stale.

Adds CTestDriver.markTestResultsOutdated(sourceDir), scoped to the project's root TestItem so other projects sharing the singleton controller are untouched. Invalidation is opt-in (default false) so internal builds during an active test run (preTest, per-test/coverage builds, API builds) never retire an in-flight run's results.
1) Internal cmake.buildTask executions (launched by CMakeDriver.build() for preTest/coverage builds during a test run) no longer refresh/invalidate the Test Explorer: CustomBuildTaskTerminal gains an isInternalBuild flag set only at the internal resolveInternalTask construction site, and Hook C is gated on !isInternalBuild. Prevents retiring an in-flight (coverage) run's own results.

2) Clean All now opts out of marking results outdated (buildAll gains a markOutdated param, default true; cleanAll passes false), matching single-project clean.

3) refreshTestsAfterExternalBuild marks results outdated in a finally so a throwing discovery still retires stale results.
resolveInternalTask is only called from CMakeDriver.build() for internal cmake.buildTask executions, but its else branch returned an execution-bearing task unchanged. findBuildTask's ambiguous/no-match fallback returns a provideTask-built task whose terminal defaults to isInternalBuild=false, so an internal build (e.g. a coverage pre/post build during an active test run) could trip Hook C and retire the in-flight run's results. Drop the if (!execution) guard so every returned task uses an internal terminal (isInternalBuild=true) and a real exitCodePromise; user-facing provideTask/resolveTask remain isInternalBuild=false.
A type: cmake, command: build task now refreshes the test information and marks prior results outdated on completion, so chaining a refresh task after it is redundant. Document that the refresh task is for builds that do not go through a cmake task (external/shell builds, or builds driven by another extension).
@hanniavalera Hannia Valera (hanniavalera) changed the title Add a refresh command to the cmake task type (#5007) Add a cmake refresh task and mark Test Explorer results outdated after refresh/build (#5007) Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant