# Possible to determine action context from ProgramRunner.canRun()?

**URL:** <https://platform.jetbrains.com/t/possible-to-determine-action-context-from-programrunner-canrun/4916>\
**Category:** IntelliJ Platform\
**Created:** [August 21, 2026, 6:22pm UTC](https://platform.jetbrains.com/t/possible-to-determine-action-context-from-programrunner-canrun/4916 "2026-08-21T18:22:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![illuminatedcloud](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/illuminatedcloud/32/55_2.png) [@illuminatedcloud](https://platform.jetbrains.com/u/illuminatedcloud)\
**Post date:** [August 21, 2026, 6:22pm UTC](https://platform.jetbrains.com/t/possible-to-determine-action-context-from-programrunner-canrun/4916/1 "2026-08-21T18:22:08Z")

</div>

In my plugin, there are two unit test execution engines, one that executes locally and one that executes via API on a server. My plugin includes distinct `Executor`s for these execution engines and the respective actions that each supports (run, run w/coverage, debug, watch, and profile):

 ![image](https://us1.discourse-cdn.com/flex001/uploads/jetbrains_platform/original/2X/5/517d77ac811e7f2da1c78bab91db46ca4c3ad388.png)

That all works wonderfully, so no issues there. The problem is that once you’ve executed tests, the context menu actions for entries in the test results tool window don’t seem to have context for which specific executor was used to run those tests. The coarse-grained rerun failed tests action is fine because it was created with the original executor, but if you right-click on a test class or method, implementations of `ProgramRunner.canRun()` are called to filter the available executors, and that’s only passed each executor ID in turn alongside the `RunProfile` which is (or should be) execution-agnostic. Ideally the context menu would only include the executors for the specific unit test execution engine that yielded those test results. Hopefully that makes sense…

If I had access to the full `AnActionEvent` that was originally passed to `ExecutorAction.update()` which is itself what calls `ProgramRunner.canRun()`, I could filter by that event’s `DataContext` which includes enough information for reliable filtering, but that’s unavailable to implementations of `canRun()`, at least directly.

Is there any other way to get this type of action invocation context from an implementation of `ProgramRunner.canRun()`? Is it available as a thread local or other type of indirect context?

---

<div class="post-metadata">

**Author:** ![patrick.scheibe](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/patrick.scheibe/32/2594_2.png) [@patrick.scheibe](https://platform.jetbrains.com/u/patrick.scheibe)\
**Post date:** [August 25, 2026, 10:51pm UTC](https://platform.jetbrains.com/t/possible-to-determine-action-context-from-programrunner-canrun/4916/2 "2026-08-25T22:51:57Z")

</div>

Hey Scott,

I looked into it until someone from the Platform team comes up with an authoritative answer. Full disclosure: I was looking for evidence in the Platform code on how this could be solved. I didn’t test it, the answer is purely based on how it’s used in the Platform code, and, yes, I used an LLM to dig through the sources.

You have multiple executors for two test engines, and when the user right-clicks a test node in the test results tree, the popup is populated through the normal **Run Context** flow. That eventually filters executors via `ProgramRunner.canRun(executorId, profile)`, but `canRun()` only gets `executorId` + `RunProfile`, not the original `AnActionEvent`/`DataContext`. So both engine-specific executors can appear unless the `RunProfile` itself carries enough information.

There is no public API to get the invoking `DataContext`/action context, and I did not find a public thread-local/indirect context intended for that directly from `ProgramRunner.canRun()`. But there seems to be a public API way to solve the overall problem.

Use the configuration-context layer, not `ProgramRunner.canRun()`, to recover the original test run context and produce an engine-specific rerun configuration (or mark the produced `RunProfile` with the originating engine). Then `canRun()` can remain a pure check on `executorId + profile`.

`ConfigurationContext` already preserves the original run configuration / execution environment for exactly this kind of case:

- `ConfigurationContext` constructor first looks for `RunConfiguration.DATA_KEY`
- if absent, it looks for `ExecutionDataKeys.EXECUTION_ENVIRONMENT`
- it exposes `getOriginalConfiguration(...)`

And its javadoc explicitly says this is for cases like:

> “some test framework runtime configuration that had been launched and that had brought a result test tree on which a right-click action was performed.”

So the supported solution is:

1. In your `RunConfigurationProducer` / context-based rerun production code, inspect:
  - `context.getOriginalConfiguration(...)`
  - optionally `context.getDataContext().getData(ExecutionDataKeys.EXECUTION_ENVIRONMENT)`

2. Determine whether the original run came from local vs server engine.
3. Create/configure the rerun `RunConfiguration` accordingly.
4. Let `ProgramRunner.canRun()` filter based on data now stored in the `RunProfile`.

# Evidence

- [`platform/execution/src/com/intellij/execution/runners/ProgramRunner.java`](https://github.com/JetBrains/intellij-community/blob/master/platform/execution/src/com/intellij/execution/runners/ProgramRunner.java)
  - `getRunner()` calls `it.canRun(executorId, settings)` only.

- [`platform/lang-api/src/com/intellij/execution/actions/ConfigurationContext.java`](https://github.com/JetBrains/intellij-community/blob/master/platform/lang-api/src/com/intellij/execution/actions/ConfigurationContext.java)
  - lines 118–127: pulls `RunConfiguration.DATA_KEY` or `ExecutionDataKeys.EXECUTION_ENVIRONMENT`
  - lines 387–398: `getOriginalConfiguration(...)` with javadoc describing right-click on a test result tree

- [`platform/testRunner/src/com/intellij/execution/testframework/TestTreeView.java`](https://github.com/JetBrains/intellij-community/blob/master/platform/testRunner/src/com/intellij/execution/testframework/TestTreeView.java)
  - the test tree popup is `TestTreePopupMenu`
  - it publishes `RunConfiguration.DATA_KEY`, `AbstractTestProxy.DATA_KEY`, etc. into the popup context

- [`platform/testRunner/resources/intellij.platform.testRunner.xml`](https://github.com/JetBrains/intellij-community/blob/master/platform/testRunner/resources/intellij.platform.testRunner.xml)
  - `TestTreePopupMenu` includes `RunContextGroup`

- [`plugins/junit/src/com/intellij/execution/junit/UniqueIdConfigurationProducer.java`](https://github.com/JetBrains/intellij-community/blob/master/plugins/junit/src/com/intellij/execution/junit/UniqueIdConfigurationProducer.java)
  - reads `RunConfiguration.DATA_KEY` from the context for test-tree-based rerun behavior

- [`platform/lang-api/src/com/intellij/execution/actions/RunConfigurationProducer.java`](https://github.com/JetBrains/intellij-community/blob/master/platform/lang-api/src/com/intellij/execution/actions/RunConfigurationProducer.java)
  - `cloneTemplateConfigurationStatic(...)` uses `context.getOriginalConfiguration(...)` to clone from the originating configuration

---

<div class="post-metadata">

**Author:** ![illuminatedcloud](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/illuminatedcloud/32/55_2.png) [@illuminatedcloud](https://platform.jetbrains.com/u/illuminatedcloud)\
**Post date:** [August 26, 2026, 3:16am UTC](https://platform.jetbrains.com/t/possible-to-determine-action-context-from-programrunner-canrun/4916/3 "2026-08-26T03:16:36Z")

</div>

Hi, @patrick.scheibe. Thanks for the suggestion.

That’s actually pretty much exactly what I did actually! There are some minor differences, but overall the approach of using `ExecutionDataKeys.EXECUTION_ENVIRONMENT` and checking `PlatformCoreDataKeys.CONTEXT_COMPONENT` as being a `TestTreeView` all holds. I specifically do it from `RunConfigurationProducer.isConfigurationFromContext()` when everything else matches, and in addition to returning `true`, I set a “contextual executor” for the run configuration that’s then used for filtering in `canRun()`. Works like a charm!

Apologies for not following up here, and again, I really appreciate the time you spent coming up with a really useful recommendation.
