Skip to content

fix(plugin): validator accepts only what the step executors run (#1130, #1055) - #1221

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/plugin-validator-agree
Oct 20, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/plugin-validator-agree

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1130
Fixes #1055

#1130: what each case became

Case Decision Why
push in local.deprovision reject RunDeprovision refuses it at teardown, and nothing follows a teardown step to receive the value.
local.reconcile already works, kept The issue's claim that nothing runs it is stale. spawn start calls reconcileAllLocalPlugins (cmd/state.go:410), which replays rec.Reconcile, the copy saved in the local plugin record, through RunDeprovision (cmd/plugin.go). A grep for Local.Reconcile misses it. Because it runs through RunDeprovision, it now gets the same run-only schema, so push there is rejected too. spore-sync uses it.
capture: on a remote step reject spored streams remote stdout to its log and never parses it. Implementing capture would mean recording outputs into spored state and threading them into later steps, which is not small.
background: / as_user: on a local step reject Local steps run as the controller user, in the foreground.
capture: in local.deprovision/reconcile (found while doing this) reject It was parsed (so non-JSON stdout failed the step) and then discarded. runCapture is split into runLocal + captureOutputs, and RunDeprovision calls only runLocal.

The validator now has one schema per section, giving each step type and the yaml fields that type takes (pkg/plugin/validate.go). Any other type, or any other set field, is an error that names the field and lists what the type takes. It replaces the old type sets and the special-case sha256 only on fetch check. Empty maps count as unset, because re-marshalling a Step writes capture: {}.

spawn plugin install now runs spec.Validate before any local step. spored already validated on receipt (pushapi.go), so a spec it would refuse used to leave a local footprint first.

Stale comments fixed: spec.go sha256 ("the registry's publish-time CI requires it": nothing in spore-plugins does), as_user ("ignored for local steps": now rejected), and template.go shellEscapeContext/RenderShellStep ("instance values … left unescaped": they are quoted too).

Gates (each watched failing against a compiling revert)

TestValidatorAcceptsExactlyWhatTheExecutorsRun (pkg/plugin/step_schema_gate_test.go):

  • Sections are discovered by reflection: every []Step field of PluginSpec. Each one must map to the function that runs it, and a new section with no mapping fails.
  • go list -export and go/types load pkg/plugin and pkg/pluginruntime. From each executor entry point the gate follows calls into those packages, skipping renderers (functions returning a Step). It collects Step field selections by type, not by name, and attributes them per step type, using the cases of a switch on Step.Type or an if step.Type != "x" { return } guard.
  • It then asserts behaviourally through Validate. Every type the executor runs is accepted, and every other type is rejected. On an accepted type, every field it reads is accepted, and every other field is rejected by name.
  • It fails if discovery finds no dispatch, or no field read for a type.

The discovered sets match the table: provision run {run, env, capture}, push {key, value}; deprovision run {run, env}; remote run {run, env, background, as_user}, fetch {url, dest, sha256}, extract {src, dest}.

Reverts it caught:

  • R1: validator accepts remote capture
  • R2: push in teardown
  • R3: local background/as_user
  • R4: RunDeprovision calls runCapture again. This one is an executor change: the gate then demands that the validator accept capture.
  • R5: _ = step.Capture added to the remote runCommand

Known blind spot: an executor that silently skips a type (if step.Type == "push" { continue }) is not seen as dispatch, so the gate stays green.

TestCheckSporeOSAgreesWithPlatformConditions (#1055) asserts, for each spelling, refused ⇔ an os: windows platform condition passes, refused ⇒ os: linux fails, and Linux ⇒ neither. It fails against a compiling hand-rolled normaliser ("\tWINDOWS\n"). The pre-change EqualFold(TrimSpace) agreed with NormalizeOS, so this is a drift gate, not a bug repro.

TestRunPluginInstall_InvalidSpecRunsNoLocalStep fails with the new Validate call disabled: the local step runs and the install proceeds to ssh.

Registry check

Every plugins/*/plugin.yaml in spore-host/spore-plugins (12) passes spawn plugin validate --strict with this build. Positive control: docker passes. Negative control: docker with capture: added to a remote run step fails and names the field.

Checks

make check passes through step 6. Step 7, check-build-tags, fails identically on unmodified main in a /private/tmp worktree. semgrep is clean. No help text changed.

@scttfrdmn scttfrdmn added this to the v0.137.0 milestone Oct 20, 2026
@codecov

codecov Bot commented Oct 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.37931% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/plugin/local_executor.go 54.54% 4 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

#1055)

Each step section now accepts only the step types its executor runs and,
per type, only the Step fields the executor reads; a gate derives both from
the executors' source. CheckSporeOS uses NormalizeOS, gated to agree with
platform conditions. spawn plugin install validates before any local step.
@scttfrdmn
scttfrdmn force-pushed the fix/plugin-validator-agree branch from 7456b33 to 59b7881 Compare October 20, 2026 06:35
@scttfrdmn
scttfrdmn merged commit 72571d0 into main Oct 20, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/plugin-validator-agree branch October 20, 2026 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant