Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pluginkit/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Releases of this module are tagged `pluginkit/vX.Y.Z`. Releases up to
- `Schema.FormFields` describes each field for a settings form as a `FormField`, in manifest order, and a secret only as set or not set.
- A duration `Value` keeps the text it was read from in `Text`, so `2h` stays `2h`.
- `ScreenGate` is an optional interface whose `ShowsScreens` tells an application whether a plugin's admin menu entries and screens show for the caller in the context.
- `plugintest.LifecycleFindings` checks the promises of the plugin contract from a plugin's own tests, each check on a new plugin within a time limit the application passes, and answers one `Finding` per broken promise with its rule, problem and fix.
- `wire.CheckID` checks one manifest's id against the reserved ids and the generated wiring, as `Load` does.
- The module needs Go 1.27.4.

## 0.12.0 - 2026-11-07
Expand Down
6 changes: 3 additions & 3 deletions pluginkit/boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Boot struct {
// NewBoot reads every record of store once.
func NewBoot(ctx context.Context, store PluginStore) (*Boot, error) {
var records map[string]PluginRecord
err := guarded(ctx, "read the plugin records", func(ctx context.Context) error {
err := runWithRecover(ctx, "read the plugin records", func(ctx context.Context) error {
var readErr error
records, readErr = store.Records(ctx)
return readErr
Expand Down Expand Up @@ -79,14 +79,14 @@ func (b *Boot) admit(ctx context.Context, id string) (bool, error) {

// Pause pauses the plugin the failure names, recording its step and its reason apart.
func (b *Boot) Pause(ctx context.Context, failure Failure) error {
return guarded(ctx, "pause "+failure.ID, func(ctx context.Context) error {
return runWithRecover(ctx, "pause "+failure.ID, func(ctx context.Context) error {
return b.store.Pause(ctx, failure.ID, failure.Step, failure.Reason)
})
}

// activate marks the plugin id active and clears its step and its error.
func (b *Boot) activate(ctx context.Context, id string) error {
return guarded(ctx, "activate "+id, func(ctx context.Context) error { return b.store.Activate(ctx, id) })
return runWithRecover(ctx, "activate "+id, func(ctx context.Context) error { return b.store.Activate(ctx, id) })
}

// Started pauses each plugin that failed to migrate or start, and activates each paused plugin that started.
Expand Down
4 changes: 4 additions & 0 deletions pluginkit/features/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ func TestSettingsChanges(t *testing.T) {
func TestScreenGate(t *testing.T) {
runFeature(t, "screen-gate.feature", initializeScreenGate(t))
}

func TestPluginChecks(t *testing.T) {
runFeature(t, "plugin-checks.feature", initializePluginChecks())
}
125 changes: 125 additions & 0 deletions pluginkit/features/plugin-checks.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
Feature: Checking the promises a plugin makes to its host from its own tests
A downstream application lends plugin authors a check they run from a
plugin's own tests, with a time limit the application sets. The check
holds a plugin to the promises of the plugin contract: Register answers
a plugin with its manifest's id within the time limit, Routes and
PublicPaths answer before Start runs, Stop works on a plugin that never
started, Start runs again after Stop, and Stop runs again after Stop.
Each check registers a new plugin from new dependencies, so one broken
promise does not hide another, and a call that never returns is cut at
the time limit. A Start or a Stop that fails before a second Stop is
named under start-stop-again, and a finding two checks give alike is
named once. Each finding names its rule, the problem and the fix. An
application can also check one manifest's id against the ids it
reserves and the names the generated wiring uses.

Scenario: A plugin that keeps every promise gives no finding
Given the plugin "events" keeps every promise
When the application checks the lifecycle of "events" with a time limit of 200ms
Then the check gives no finding

Scenario: A plugin with no routes and no public paths gives no finding
Given the plugin "events" has no routes and no public paths
When the application checks the lifecycle of "events" with a time limit of 200ms
Then the check gives no finding

Scenario Outline: A plugin whose Register breaks a promise gives that finding alone
Given the plugin "events" <fault>
When the application checks the lifecycle of "events" with a time limit of 200ms
Then the check gives one finding, under the rule "<rule>"
And its problem reads: <problem>
And its fix reads: <fix>

Examples:
| fault | rule | problem | fix |
| answers the error "no database" from Register | register | Register answered the error: no database | Return the plugin from Register with no error, and leave work that can fail to Start. |
| panics with "boom" in Register | register | Register panicked: boom | Return the plugin from Register with no error, and leave work that can fail to Start. |
| answers no plugin from Register | register | Register answered no plugin | Return the plugin Register builds. |
| calls itself "news" | register | Register answered a plugin that calls itself "news", not "events" | Make ID return "events", the id in plugin.json. |
| takes 1s in Register | register-time | Register did not return within 200ms | Keep Register to building the plugin, and open connections or read data in Start. |

Scenario Outline: A plugin that breaks a promise after Register is named under its rule
Given the plugin "events" <fault>
When the application checks the lifecycle of "events" with a time limit of 200ms
Then the check gives one finding, under the rule "<rule>"
And its problem reads: <problem>
And its fix reads: <fix>

Examples:
| fault | rule | problem | fix |
| answers no handler from Routes | routes-before-start | Routes before Start answered no handler | Build the handler and the paths in Register, so Routes and PublicPaths answer whether or not Start ran. |
| panics with "boom" in Routes | routes-before-start | Routes before Start panicked: boom | Build the handler and the paths in Register, so Routes and PublicPaths answer whether or not Start ran. |
| never returns from Routes | routes-before-start | Routes before Start did not return within 200ms | Build the handler and the paths in Register, so Routes and PublicPaths answer whether or not Start ran. |
| panics with "boom" in PublicPaths | routes-before-start | PublicPaths before Start panicked: boom | Build the handler and the paths in Register, so Routes and PublicPaths answer whether or not Start ran. |
| answers the error "nothing to close" from Stop before any Start | stop-without-start | Stop before any Start answered the error: nothing to close | Let Stop release only what Start opened, and return nil when Start never ran. |
| panics with "boom" in Stop before any Start | stop-without-start | Stop before any Start panicked: boom | Let Stop release only what Start opened, and return nil when Start never ran. |
| never returns from Stop before any Start | stop-without-start | Stop before any Start did not return within 200ms | Let Stop release only what Start opened, and return nil when Start never ran. |
| answers the error "no route table" from the first Start | start-stop-again | the first Start answered the error: no route table | Let Start open again what Stop released, and let each call return by the time its context ends. |
| never returns from the first Start | start-stop-again | the first Start did not return within 200ms | Let Start open again what Stop released, and let each call return by the time its context ends. |
| answers the error "already closed" from the Stop after the first Start | start-stop-again | the first Stop answered the error: already closed | Let Start open again what Stop released, and let each call return by the time its context ends. |
| answers the error "already started" from the second Start | start-stop-again | the second Start answered the error: already started | Let Start open again what Stop released, and let each call return by the time its context ends. |
| panics with "boom" in the second Start | start-stop-again | the second Start panicked: boom | Let Start open again what Stop released, and let each call return by the time its context ends. |
| panics with "boom" in the Stop after the second Start | start-stop-again | the second Stop panicked: boom | Let Start open again what Stop released, and let each call return by the time its context ends. |
| answers the error "already closed" from the second Stop after the first Start | stop-twice | the second of two Stops answered the error: already closed | Let a second Stop find nothing left to release and return nil. |
| panics with "boom" in the second Stop after the first Start | stop-twice | the second of two Stops panicked: boom | Let a second Stop find nothing left to release and return nil. |
| never returns from the second Stop after the first Start | stop-twice | the second of two Stops did not return within 200ms | Let a second Stop find nothing left to release and return nil. |

Scenario: Each check registers a new plugin, so one broken promise does not hide another
Given the plugin "events" answers no handler from Routes
And the plugin "events" answers the error "nothing to close" from Stop before any Start
And the plugin "events" answers the error "already started" from the second Start
And the plugin "events" answers the error "already closed" from the second Stop after the first Start
When the application checks the lifecycle of "events" with a time limit of 200ms
Then the check gives these findings, in this order:
| rule | problem |
| routes-before-start | Routes before Start answered no handler |
| stop-without-start | Stop before any Start answered the error: nothing to close |
| start-stop-again | the second Start answered the error: already started |
| stop-twice | the second of two Stops answered the error: already closed |
And every Register of "events" received dependencies built for it alone

Scenario: A Start that fails only on the plugin of a later check is still named
Given the plugin "events" keeps its port after Stop
When the application checks the lifecycle of "events" with a time limit of 200ms
Then the check gives these findings, in this order:
| rule | problem |
| start-stop-again | the second Start answered the error: port in use |
| start-stop-again | the first Start answered the error: port in use |

Scenario: A call that never returns is cut at the time limit and the later checks still run
Given the plugin "events" never returns from Routes
And the plugin "events" answers the error "already started" from the second Start
When the application checks the lifecycle of "events" with a time limit of 200ms
Then the check gives these findings, in this order:
| rule | problem |
| routes-before-start | Routes before Start did not return within 200ms |
| start-stop-again | the second Start answered the error: already started |

Scenario: A Routes that never returns does not hold up the check of PublicPaths
Given the plugin "events" guards Routes and PublicPaths with one lock
And the plugin "events" never returns from Routes
When the application checks the lifecycle of "events" with a time limit of 200ms
Then the check gives these findings, in this order:
| rule | problem |
| routes-before-start | Routes before Start did not return within 200ms |

Scenario: Start and Stop each get a context that ends at the time limit
Given the plugin "events" keeps every promise
When the application checks the lifecycle of "events" with a time limit of 200ms
Then every Start and Stop of "events" got a context that ends within 200ms of the call

Scenario Outline: One manifest's id is checked against the reserved ids and the generated wiring
Given a manifest with the id "<id>" and <parts>
And the application reserves the ids "core" and "admin"
When the application checks the manifest's id
Then the id check <result>

Examples:
| id | parts | result |
| events | a backend | passes |
| core | a backend | rejects it with: id "core" is reserved |
| admin | only a frontend | rejects it with: id "admin" is reserved |
| fmt | a backend | rejects it with: id "fmt" collides with the generated Go wiring |
| import | a backend | rejects it with: id "import" collides with the generated Go wiring |
| fmt | only a frontend | passes |
| import | only a frontend | rejects it with: id "import" collides with the generated TypeScript wiring |
Loading