Skip to content

fix(pluginkit): use accurate step names - #298

Merged
eddie-knight merged 4 commits into
privateerproj:mainfrom
eddie-knight:feat/wire-step-names
Sep 8, 2026
Merged

eddie-knight merged 4 commits into
privateerproj:mainfrom
eddie-knight:feat/wire-step-names

Conversation

@eddie-knight

@eddie-knight eddie-knight commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Adopt the fix from gemaraproj/go-gemara#129 to allow step names to be populated in output logs in a way that they can also be ingested and verified by other go-gemara users (i.e. grc.store)

Consumer-visible

The go-gemara bump (v0.9.2 → v0.10.0) also rewrites the SARIF converter, which --output sarif inherits:

  • Results now carry a kind reflecting the Gemara status (fail, review, open, pass); level is set only for fail (error). Previously NeedsReview and Unknown were level: warning and Passed was level: note.
  • Each result gains partialFingerprints (keyed on requirement id) and properties["gemara/result"].

Anything filtering SARIF on level: warning will stop seeing NeedsReview results and should filter on kind instead. The SARIF test now pins kind/level per status.

adaptTypedSteps wraps every typed step in one closure, so gemara's
AssessmentStep.String resolved each to the adapter's symbol and every
step in a published log read as pluginkit.adaptTypedSteps[...].func1.
The captured name only reached the benchmark report.

Wrap the adapter in gemara.NamedStep so String, and therefore the
json/yaml/gemara/sarif outputs, report the plugin function instead.

Blocked on a go-gemara release carrying NamedStep (gemaraproj/go-gemara#129);
builds under go.work against that branch, fails against the pinned v0.9.2.

Signed-off-by: Eddie Knight <knight@linux.com>
Pre-emptive pin for the go-gemara release that carries gemaraproj/go-gemara#129.
go.sum gains its entry via go mod tidy once the tag exists; until then the
branch builds only under go.work with a local go-gemara checkout.

Signed-off-by: Eddie Knight <knight@linux.com>
@eddie-knight
eddie-knight requested a review from a team September 7, 2026 18:52
@eddie-knight
eddie-knight marked this pull request as draft September 7, 2026 18:52
@github-actions github-actions Bot added the fix label Sep 7, 2026
Signed-off-by: Eddie Knight <knight@linux.com>
@eddie-knight
eddie-knight marked this pull request as ready for review September 8, 2026 14:48
@eddie-knight eddie-knight changed the title fix(pluginkit): wire step names fix(pluginkit): use accurate step names Sep 8, 2026

@julianvance242 julianvance242 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 Multi-model review: haiku, sonnet, and opus each reviewed a local worktree at 862e3e7 independently; every claim below was re-verified against source, and the proposed deletion was applied and run (go vet, go test, go test -race ./pluginkit green).

One question. The description says the names are to be "ingested and verified by other go-gemara users (i.e. grc.store)". Nothing in the PR shows what grc.store does with a step name — is there a hub-side consumer or issue to link?

Security / efficiency / brevity

  • Security: no new exposure. The name is a compile-time symbol from the plugin's own binary, JSON-escaped on output. Typed steps' package paths now reach published logs, which untyped steps already did. The one security-adjacent item is the SARIF change (inline major on go.mod).
  • Efficiency: run time is fine (one closure per step, one type assertion per call). The code is not minimal: the parallel names map and everything it feeds now duplicate step.String() (inline major on typed_steps.go); fn := step is dead under go 1.26 (inline nit).
  • Brevity, not anchorable because the lines are context: typed_steps.go:65 still says the name "survives into the benchmark report" (now every output); evaluation_orchestrator.go:129 reads "captures each step's name before it is captured". Both fixed in the patch below.

Blocking: the two inline majors. Minor inline: no test proves the name survives into a serialized log; the patch adds one that fails when NamedStep is stripped.

Patch: delete the names plumbing (-59), fix the stale docs, add the wire test. Applies on 862e3e7.
diff --git a/pluginkit/evaluation_orchestrator.go b/pluginkit/evaluation_orchestrator.go
index afdf4c1..a858233 100644
--- a/pluginkit/evaluation_orchestrator.go
+++ b/pluginkit/evaluation_orchestrator.go
@@ -126,15 +126,8 @@ func (v *EvaluationOrchestrator) addPossibleControls(catalog *gemara.ControlCata
 // Steps registered this way are named by symbol lookup at report time, which
 // only resolves while the step is a plain function value. Plugins that adapt
 // their steps through a closure should register via AddEvaluationSuiteTyped so
-// the SDK captures each step's name before it is captured.
+// the SDK resolves each step's name before wrapping it.
 func (v *EvaluationOrchestrator) AddEvaluationSuite(catalogId string, loader DataLoader, steps map[string][]gemara.AssessmentStep) error {
-	return v.addEvaluationSuiteNamed(catalogId, loader, steps, nil)
-}
-
-// addEvaluationSuiteNamed is AddEvaluationSuite with optional step names,
-// supplied by the typed registration helpers. names is keyed by requirement id
-// and positionally parallel to steps; a nil map falls back to symbol lookup.
-func (v *EvaluationOrchestrator) addEvaluationSuiteNamed(catalogId string, loader DataLoader, steps map[string][]gemara.AssessmentStep, names map[string][]string) error {
 	if catalogId == "" {
 		return BAD_CATALOG(v.PluginName, "suite catalog id cannot be empty", "aos10")
 	}
@@ -145,7 +138,7 @@ func (v *EvaluationOrchestrator) addEvaluationSuiteNamed(catalogId string, loade
 		if catalog.Metadata.Id == "" {
 			return BAD_CATALOG(v.PluginName, "no id found in catalog metadata", "aos30")
 		}
-		v.addEvaluationSuite(catalog, loader, steps, names)
+		v.addEvaluationSuite(catalog, loader, steps)
 		return nil
 	}
 	return BAD_CATALOG(v.PluginName, fmt.Sprintf("no reference catalog found with id '%s'", catalogId), "aos40")
@@ -167,7 +160,7 @@ func (v *EvaluationOrchestrator) AddEvaluationSuiteForAllCatalogs(loader DataLoa
 	return nil
 }
 
-func (v *EvaluationOrchestrator) addEvaluationSuite(catalog *gemara.ControlCatalog, loader DataLoader, steps map[string][]gemara.AssessmentStep, names map[string][]string) {
+func (v *EvaluationOrchestrator) addEvaluationSuite(catalog *gemara.ControlCatalog, loader DataLoader, steps map[string][]gemara.AssessmentStep) {
 	for _, existing := range v.possibleSuites {
 		if existing.CatalogId == catalog.Metadata.Id {
 			return
@@ -190,7 +183,6 @@ func (v *EvaluationOrchestrator) addEvaluationSuite(catalog *gemara.ControlCatal
 		CatalogId: catalog.Metadata.Id,
 		catalog:   suiteCatalog,
 		steps:     steps,
-		stepNames: names,
 		config:    v.config,
 	}
 
diff --git a/pluginkit/evaluation_suite.go b/pluginkit/evaluation_suite.go
index c35b814..b509e09 100644
--- a/pluginkit/evaluation_suite.go
+++ b/pluginkit/evaluation_suite.go
@@ -33,7 +33,6 @@ type EvaluationSuite struct {
 	changeManager *ChangeManager                     // changes is a list of changes made during the evaluation
 	catalog       *gemara.ControlCatalog             // The Catalog this evaluation suite references
 	steps         map[string][]gemara.AssessmentStep // steps is a map of control IDs to their assessment steps
-	stepNames     map[string][]string                // step names captured at registration, parallel to steps; nil falls back to symbol lookup
 
 	evalSuccesses int // successes is the number of successful evaluations
 	evalFailures  int // failures is the number of failed evaluations
@@ -160,18 +159,6 @@ func (e *EvaluationSuite) restoreSteps() {
 	}
 }
 
-// stepName returns the name captured at registration for the step at index i of
-// requirementId, falling back to symbol lookup when the plugin registered
-// untyped steps. Symbol lookup is only meaningful when the registered value is
-// the plugin's own function; a plugin-side adapter closure resolves to the
-// adapter, identically for every step it wraps.
-func (e *EvaluationSuite) stepName(requirementId string, i int, step gemara.AssessmentStep) string {
-	if names, ok := e.stepNames[requirementId]; ok && i < len(names) && names[i] != "" {
-		return names[i]
-	}
-	return step.String()
-}
-
 // timedSteps wraps each executed step in a closure that records its duration, name, and result.
 func (e *EvaluationSuite) timedSteps(controlId, requirementId string, steps []gemara.AssessmentStep) []gemara.AssessmentStep {
 	if len(steps) == 0 {
@@ -179,7 +166,7 @@ func (e *EvaluationSuite) timedSteps(controlId, requirementId string, steps []ge
 	}
 	timed := make([]gemara.AssessmentStep, len(steps))
 	for i, step := range steps {
-		name := e.stepName(requirementId, i, step)
+		name := step.String()
 		timed[i] = func(payload interface{}) (gemara.Result, string, gemara.ConfidenceLevel) {
 			start := time.Now()
 			result, message, confidence := step(payload)
diff --git a/pluginkit/typed_steps.go b/pluginkit/typed_steps.go
index 1a77458..3d5436f 100644
--- a/pluginkit/typed_steps.go
+++ b/pluginkit/typed_steps.go
@@ -31,38 +31,31 @@ func FuncName(fn any) string {
 }
 
 // adaptTypedSteps converts payload-typed steps into gemara.AssessmentStep,
-// resolving each step's name before the closure captures it. It returns the
-// adapted steps and a parallel map of names keyed by requirement id.
+// resolving each step's name before the closure captures it.
 func adaptTypedSteps[S ~func(T) (gemara.Result, string, gemara.ConfidenceLevel), T any](
 	steps map[string][]S,
-) (map[string][]gemara.AssessmentStep, map[string][]string) {
+) map[string][]gemara.AssessmentStep {
 	adapted := make(map[string][]gemara.AssessmentStep, len(steps))
-	names := make(map[string][]string, len(steps))
 	for id, list := range steps {
 		for _, step := range list {
-			fn := step // capture per iteration, not the loop variable
-			name := FuncName(fn)
-			names[id] = append(names[id], name)
-			// NamedStep keeps the real name on the wire: without it every adapted
-			// step serializes as this closure's symbol.
-			adapted[id] = append(adapted[id], gemara.NamedStep(name, func(payload any) (gemara.Result, string, gemara.ConfidenceLevel) {
+			adapted[id] = append(adapted[id], gemara.NamedStep(FuncName(step), func(payload any) (gemara.Result, string, gemara.ConfidenceLevel) {
 				typed, ok := payload.(T)
 				if !ok {
 					var zero T
 					return gemara.Unknown, fmt.Sprintf("expected %T, got %T", zero, payload), 0
 				}
-				return fn(typed)
+				return step(typed)
 			}))
 		}
 	}
-	return adapted, names
+	return adapted
 }
 
 // AddEvaluationSuiteTyped registers an evaluation suite whose steps take a
 // concrete payload type T rather than an untyped any. The SDK performs the
 // payload type assertion once, so plugins need neither a per-step payload guard
 // nor their own adapter — and because the adaptation happens here, each step's
-// real function name survives into the benchmark report.
+// real function name survives into the written results.
 //
 // It is a package-level function rather than a method because Go does not allow
 // type parameters on methods.
@@ -72,8 +65,7 @@ func adaptTypedSteps[S ~func(T) (gemara.Result, string, gemara.ConfidenceLevel),
 func AddEvaluationSuiteTyped[S ~func(T) (gemara.Result, string, gemara.ConfidenceLevel), T any](
 	v *EvaluationOrchestrator, catalogId string, loader DataLoader, steps map[string][]S,
 ) error {
-	adapted, names := adaptTypedSteps[S, T](steps)
-	return v.addEvaluationSuiteNamed(catalogId, loader, adapted, names)
+	return v.AddEvaluationSuite(catalogId, loader, adaptTypedSteps[S, T](steps))
 }
 
 // AddEvaluationSuiteTypedForAllCatalogs is AddEvaluationSuiteTyped applied to
@@ -85,9 +77,9 @@ func AddEvaluationSuiteTypedForAllCatalogs[S ~func(T) (gemara.Result, string, ge
 	if len(v.referenceCatalogs) == 0 {
 		return BAD_CATALOG(v.PluginName, "no reference catalogs loaded", "aac10")
 	}
-	adapted, names := adaptTypedSteps[S, T](steps)
+	adapted := adaptTypedSteps[S, T](steps)
 	for catalogId := range v.referenceCatalogs {
-		if err := v.addEvaluationSuiteNamed(catalogId, loader, adapted, names); err != nil {
+		if err := v.AddEvaluationSuite(catalogId, loader, adapted); err != nil {
 			return err
 		}
 	}
diff --git a/pluginkit/typed_steps_test.go b/pluginkit/typed_steps_test.go
index 399a489..51a7cf9 100644
--- a/pluginkit/typed_steps_test.go
+++ b/pluginkit/typed_steps_test.go
@@ -68,24 +68,18 @@ func TestAdaptTypedSteps_CapturesRealNames(t *testing.T) {
 		"CCC.Core.C01.TR01": {typedStep_BranchProtection, typedStep_SigningEnabled},
 	}
 
-	adapted, names := adaptTypedSteps[pluginTypedStep, testPayload](steps)
+	adapted := adaptTypedSteps[pluginTypedStep, testPayload](steps)
 
-	got := names["CCC.Core.C01.TR01"]
+	got := adapted["CCC.Core.C01.TR01"]
 	if len(got) != 2 {
-		t.Fatalf("expected 2 captured names, got %d", len(got))
+		t.Fatalf("expected 2 adapted steps, got %d", len(got))
 	}
-	if !strings.HasSuffix(got[0], "typedStep_BranchProtection") {
-		t.Errorf("expected first name to be the real function, got %q", got[0])
+	// String is what every marshaler writes, so this is the wire name
+	if !strings.HasSuffix(got[0].String(), "typedStep_BranchProtection") {
+		t.Errorf("expected first name to be the real function, got %q", got[0].String())
 	}
-	if !strings.HasSuffix(got[1], "typedStep_SigningEnabled") {
-		t.Errorf("expected second name to be the real function, got %q", got[1])
-	}
-
-	// the adapted steps carry those names themselves, so they reach the wire
-	for i, step := range adapted["CCC.Core.C01.TR01"] {
-		if step.String() != got[i] {
-			t.Errorf("adapted step %d serializes as %q, want %q", i, step.String(), got[i])
-		}
+	if !strings.HasSuffix(got[1].String(), "typedStep_SigningEnabled") {
+		t.Errorf("expected second name to be the real function, got %q", got[1].String())
 	}
 
 	// the adapted step still runs, with the payload asserted for the caller
@@ -99,7 +93,7 @@ func TestAdaptTypedSteps_PayloadMismatch(t *testing.T) {
 	steps := map[string][]pluginTypedStep{
 		"CCC.Core.C01.TR01": {typedStep_BranchProtection},
 	}
-	adapted, _ := adaptTypedSteps[pluginTypedStep, testPayload](steps)
+	adapted := adaptTypedSteps[pluginTypedStep, testPayload](steps)
 
 	result, message, _ := adapted["CCC.Core.C01.TR01"][0]("not-a-payload")
 	if result != gemara.Unknown {
@@ -124,11 +118,10 @@ func TestBenchmark_TypedSteps_ReportsRealNames(t *testing.T) {
 	typed := map[string][]pluginTypedStep{
 		"CCC.Core.C01.TR01": {typedStep_BranchProtection, typedStep_SigningEnabled},
 	}
-	adapted, names := adaptTypedSteps[pluginTypedStep, testPayload](typed)
+	adapted := adaptTypedSteps[pluginTypedStep, testPayload](typed)
 
 	orchestrator := benchmarkOrchestrator(cfg, adapted)
 	orchestrator.loader = func(*config.Config) (any, error) { return testPayload{Repo: "x"}, nil }
-	orchestrator.possibleSuites[0].stepNames = names
 
 	if err := orchestrator.Mobilize(); err != nil {
 		t.Fatalf("Mobilize failed: %v", err)
@@ -158,3 +151,28 @@ func TestBenchmark_TypedSteps_ReportsRealNames(t *testing.T) {
 		}
 	}
 }
+
+// TestMobilize_TypedSteps_NamesReachTheWire asserts the plugin's function name
+// is what the evaluation log serializes, not the adapter's symbol.
+func TestMobilize_TypedSteps_NamesReachTheWire(t *testing.T) {
+	cfg := setBasicConfig()
+	cfg.Policy.ControlCatalogs = []string{"CCC.ObjStor"}
+	cfg.Write = false
+
+	adapted := adaptTypedSteps[pluginTypedStep, testPayload](map[string][]pluginTypedStep{
+		"CCC.Core.C01.TR01": {typedStep_BranchProtection},
+	})
+	orchestrator := benchmarkOrchestrator(cfg, adapted)
+	orchestrator.loader = func(*config.Config) (any, error) { return testPayload{Repo: "x"}, nil }
+	if err := orchestrator.Mobilize(); err != nil {
+		t.Fatalf("Mobilize failed: %v", err)
+	}
+
+	wire, err := json.Marshal(orchestrator.Evaluation_Suites[0].EvaluationLog)
+	if err != nil {
+		t.Fatal(err)
+	}
+	if !strings.Contains(string(wire), "typedStep_BranchProtection") || strings.Contains(string(wire), "adaptTypedSteps") {
+		t.Errorf("serialized log does not carry the plugin's step name: %s", wire)
+	}
+}

Checked and not problems (recorded so they don't get re-raised)

  • Untyped AddEvaluationSuite path unchanged; existing plugins see no behavior change.
  • Benchmark wrapper never reaches the wire: restoreSteps reassigns e.steps before serialization.
  • NamedStep pointer identity holds across generic instantiations (//go:noinline in go-gemara).
  • go.sum churn matches go-gemara v0.10.0's own go.mod diff exactly.
  • Refuted from one reviewer: "NamedStep is inlinable" (it is //go:noinline) and "stepNames is a cache that avoids symbol lookup" (String() on a NamedStep is a probe call; deletion passes the suite).

Comment thread go.mod Resolved
Comment thread pluginkit/typed_steps.go Resolved
Comment thread pluginkit/typed_steps_test.go Resolved
Comment thread pluginkit/typed_steps.go Resolved
…s it

With go-gemara v0.10.0, an adapted step's String() already returns the
plugin's own function name, so the parallel names map, the
addEvaluationSuiteNamed forwarder, the stepNames field, and stepName()
all computed what step.String() returns. Delete them; typed registration
now goes through AddEvaluationSuite like everything else.

Tests: add TestMobilize_TypedSteps_NamesReachTheWire, which marshals the
evaluation log and fails when the NamedStep wrapper is stripped; pin the
SARIF kind/level per result status, since the go-gemara bump changed the
converter (NeedsReview: level warning -> kind review; Passed: level note
-> kind pass) and the existing test only checked the driver.

Signed-off-by: Eddie Knight <knight@linux.com>
@eddie-knight

Copy link
Copy Markdown
Contributor Author

Re the grc.store question: the consumer is described in gemaraproj/go-gemara#129. grc.store started decoding Privateer plugin output through go-gemara before accepting it, and rejected every log because AssessmentStep had no unmarshaler. That PR made logs with step names decode and added NamedStep; this PR is the SDK side, so the names the hub decodes are the plugin functions rather than the adapter symbol.

@julianvance242 julianvance242 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 Non-binding approval. Head 0177689 verified locally: go vet ./... and go test -race -count=1 ./... pass; the four threads from the earlier multi-model review are addressed (SARIF kind/level pinned, step-name map deleted, TestMobilize_TypedSteps_NamesReachTheWire fails when the NamedStep wrapper is stripped). Consumer-visible SARIF change is documented in the description.

@eddie-knight
eddie-knight merged commit 3445984 into privateerproj:main Sep 8, 2026
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants