Skip to content

Conversation

@grittyfrog
Copy link
Contributor

plugin-self-test.webm

(apologies for the terrible framerate)

The goal of this change is to let plugins register their own self-tests.

We do this through the ISelfTestRegistry interface. For a plugin it would look like this:

[PluginService]
public ISelfTestRegistry SelfTestRegistry

// Somewhere that gets called by your plugin
SelfTestRegistry.RegisterTestSteps([
  new MySelfTestStep(),
  new MyOtherSelfTestStep()
])

Where MySelfTest and MyOtherSelfTest are instances of the existing ISelfTestStep interface.

The biggest changes are to SelfTestWindow and the introduction of SelfTestWithResults. I wanted to make sure test state wasn't lost when changing the dropdown state and I was finding it a bit annoying to work with the Dictionary now that we can't just rely on the index of the item.

To fix this I moved all the "test run" state into SelfTestWithResults, most of the changes to SelfTestWindow are derived from that, other then the addition of the combo box.

The documentation for this service is a bit sparse, but I wanted to put it up for review first before I invest a bunch of time making nice documentation.

I'm keen to hear if we think this is useful or if any changes are needed.

@grittyfrog grittyfrog requested a review from a team as a code owner October 12, 2025 10:30
Copy link
Member

@goaaats goaaats left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a new warning in the window class, looks good though otherwise.
Echoing Hasel's concern from Discord, what happens when a plugin unloads while its tests are selected? Ideally you wouldn't copy the tests into the window class, you are not allowed to keep references to objects that belong to the plugin around, but I'll leave it up to you :)

@grittyfrog
Copy link
Contributor Author

I'll address the feedback tomorrow, thanks for taking a look! 🙂

@grittyfrog grittyfrog force-pushed the push-plttolzpzvkr branch 2 times, most recently from 17cba95 to d366f4e Compare October 13, 2025 07:47
@grittyfrog
Copy link
Contributor Author

grittyfrog commented Oct 13, 2025

Updated the PR in response to all the feedback:

  • When a plugin is unloaded the SelfTestWithResults class now disposes of the ISelfTestStep reference, this should prevent any errant plugin derived class references from sticking around
  • When a plugin is unloaded the self test group is now marked as "Unloaded" in the window. We show an icon and unload all the tests, but it remains selected and available in the dropdown
  • When a plugin is reloaded the self-tests will automatically repopulate
  • Added docstrings to everything and an example to ISelfTestRegistry (since stylecop complained)

There was also a ton of stylecop errors in the previous PR which I have fixed. Please let me know if there's any other issues with this change 🙂

The goal of this change is to let plugins register their own self-tests. 

We do this through the `ISelfTestRegistry` interface. For a plugin it
would look like this:

```csharp
[PluginService]
public ISelfTestRegistry SelfTestRegistry

// Somewhere that gets called by your plugin
SelfTestRegistry.RegisterTestSteps([
  new MySelfTestStep(),
  new MyOtherSelfTestStep()
])
```

Where `MySelfTest` and `MyOtherSelfTest` are instances of
the existing `ISelfTestStep` interface.

The biggest changes are to `SelfTestWindow` and the introduction of
`SelfTestWithResults`. I wanted to make sure test state wasn't lost when
changing the dropdown state and I was finding it a bit annoying to work
with the Dictionary now that we can't just rely on the index of the
item.

To fix this I moved all the "test run" state into `SelfTestWithResults`,
most of the changes to `SelfTestWindow` are derived from that, other
then the addition of the combo box.

The documentation for this service is a bit sparse, but I wanted to put
it up for review first before I invest a bunch of time making nice
documentation. 

I'm keen to hear if we think this is useful or if any changes are
needed.
@goaaats
Copy link
Member

goaaats commented Nov 4, 2025

Thanks, looks great!

@goaaats goaaats merged commit fc480d8 into goatcorp:master Nov 4, 2025
3 checks passed
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.

2 participants