Two pre-existing issues discovered while scoping the Module-position slice
(archie-core-e7bo), unrelated to the playbook engine work:
1. wfextract's //go:generate directive still targeted
internal/workflow, a path gone since the domain migration -- the
committed generated file was hand-patched for imports only, never
regenerated. 'go generate ./...' failed repo-wide, silently.
2. Regeneration surfaced real drift on three surfaces:
- wfextract: the committed table predated the migration and was
missing everything added since -- routing YAML loaders (t2db.9/.10/
.11), the review types, and the Forger/Reviewer/Trees interfaces
that TaskContext exposes to every interpreted stage plugin. A stage
plugin referencing tc.Trees or the review types could not resolve
them.
- pluginextract: internal/plugin/host.go (f73b2d1) added the
Host/Module/Manifest/Permission/Health/CapabilityKind/LifecycleState
/ModuleStatus types and NewHost/AdaptLegacy/HostAPIVersion, none of
which were ever extracted. A daemon plugin written against the
capability-host API (bootstrap.go:707 LoadDir) silently had no way
to reference them.
- secretextract: symbol exports were current; only the hand-applied
nil-guards and comments differ from raw generator output.
Fix: update the wfextract directive to internal/domain/workflow and
regenerate all four extract surfaces via 'go generate ./...'. Re-apply
the documented hand-written nil-guards on interface wrappers (Yaegi
wrappers omit them natively), restating the IMPORTANT note in wfextract's
package doc (it now has interface wrappers for the first time). Delete
the stale hand-patched wfextract generated file in favour of the
correctly-named regeneration.
Regression coverage (the previously-missing types are now reachable from
interpreted code, proven by tests that fail against the old tables):
- wfextract/reachability_test.go: interprets a stage plugin referencing
Trees/Reviewer/LoadPlaybookDirs and calls it; plus a Go-side nil-guard
test on the three wrappers.
- pluginextract/reachability_test.go: interprets a daemon plugin building
a Host from a Go-side Module and calls it end to end; plus nil-guard
tests on the _Module/_Plugin wrappers.
- secretextract keeps its existing wrapper nil-guard tests.
Verified red-then-green: after a fresh 'go generate ./...' wipes the
guards, the guard tests fail with nil-pointer panics; after re-applying,
they pass. task check clean (113/113 UI, exit 0).
112 lines
4.4 KiB
Go
112 lines
4.4 KiB
Go
package wfextract
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/traefik/yaegi/interp"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
|
"github.com/samcharles93/archie-core/internal/yaegiutil"
|
|
)
|
|
|
|
// TestPreviouslyMissingSymbolsReachableFromInterpretedCode is the regression
|
|
// test for the stale-symbol-table drift (e7bo): the committed generated file
|
|
// predated the domain migration and was hand-patched for imports only, never
|
|
// regenerated -- so symbols added after the migration (the routing YAML
|
|
// loaders t2db.9/.10/.11, the review types, and the Forger/Reviewer/Trees
|
|
// interfaces that TaskContext exposes to every interpreted stage plugin)
|
|
// were missing from the table. A stage plugin referencing tc.Trees or the
|
|
// review types could not resolve them, silently.
|
|
//
|
|
// This test interprets a plugin that references the previously-missing
|
|
// symbols. It fails if the symbols or wrappers are dropped from the table.
|
|
func TestPreviouslyMissingSymbolsReachableFromInterpretedCode(t *testing.T) {
|
|
src := `package main
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
|
)
|
|
|
|
// Trees is the branch/prepare/diff surface TaskContext.Trees exposes.
|
|
func UseTrees(t workflow.Trees) (string, int, error) {
|
|
dir, _, err := t.Prepare(context.Background(), "o", "r", "main", 1, "t", "", "")
|
|
if err != nil {
|
|
return "", 0, err
|
|
}
|
|
diff, err := t.Diff(context.Background(), dir, "main")
|
|
lines, err := t.ChangedLines(context.Background(), dir, "main")
|
|
return diff, lines, err
|
|
}
|
|
|
|
// Reviewer is the adversarial-review surface TaskContext.Reviewer exposes.
|
|
func UseReviewer(r workflow.Reviewer) workflow.ReviewReport {
|
|
return r.Review(context.Background(), workflow.ReviewRequest{})
|
|
}
|
|
|
|
// Routing loaders are the t2db.9/.10/.11 API stage plugins may call.
|
|
func UseRouting() error {
|
|
_, _, err := workflow.LoadPlaybookDirs([]string{"/nonexistent"})
|
|
return err
|
|
}
|
|
`
|
|
|
|
i, err := yaegiutil.New(interp.Options{}, Symbols)
|
|
if err != nil {
|
|
t.Fatalf("New: %v", err)
|
|
}
|
|
|
|
// Resolve and call the routing loader through interpreted code -- the
|
|
// strongest proof the previously-missing symbol is reachable.
|
|
useRouting, err := yaegiutil.Resolve[func() error](i, src, "main.UseRouting")
|
|
if err != nil {
|
|
t.Fatalf("Resolve UseRouting: %v", err)
|
|
}
|
|
err = useRouting()
|
|
if err == nil {
|
|
// LoadPlaybookDirs("/nonexistent") errors only if the dir list is
|
|
// valid and the files are missing -- but an empty / nonexistent
|
|
// directory is a no-op (matching t2db.11's empty-means-defaults).
|
|
// Either way, the call itself resolving and executing proves the
|
|
// symbol is wired.
|
|
t.Logf("UseRouting returned nil error (nonexistent dir is a no-op)")
|
|
}
|
|
}
|
|
|
|
// TestWrapperNilGuardsPreserved is the Go-side nil-guard regression test,
|
|
// following the established pattern in secretextract/wrapper_test.go and
|
|
// pluginextract's TestGeneratedWrapperHasNilGuards: yaegi's fresh wrapper
|
|
// generation omits nil-guards, so they are re-applied by hand after every
|
|
// regeneration. A zero-value wrapper (all function fields nil) must not
|
|
// panic.
|
|
func TestWrapperNilGuardsPreserved(t *testing.T) {
|
|
var forger _github_com_samcharles93_archie_core_internal_domain_workflow_Forger
|
|
if err := forger.CloseIssue(context.Background(), "", "", 0, ""); err != nil {
|
|
t.Errorf("CloseIssue on nil WCloseIssue = %v, want nil", err)
|
|
}
|
|
if _, err := forger.CreatePR(context.Background(), "", "", "", "", "", ""); err != nil {
|
|
t.Errorf("CreatePR on nil WCreatePR = %v, want nil", err)
|
|
}
|
|
if err := forger.LinkBranch(context.Background(), "", "", 0, ""); err != nil {
|
|
t.Errorf("LinkBranch on nil WLinkBranch = %v, want nil", err)
|
|
}
|
|
|
|
var reviewer _github_com_samcharles93_archie_core_internal_domain_workflow_Reviewer
|
|
if got := reviewer.Review(context.Background(), workflow.ReviewRequest{}); len(got.Findings) != 0 || got.Status != "" || got.Summary != "" {
|
|
t.Errorf("Review on nil WReview = %#v, want empty report", got)
|
|
}
|
|
|
|
var trees _github_com_samcharles93_archie_core_internal_domain_workflow_Trees
|
|
if _, _, err := trees.Prepare(context.Background(), "", "", "", 0, "", "", ""); err != nil {
|
|
t.Errorf("Prepare on nil WPrepare = %v, want nil", err)
|
|
}
|
|
if _, err := trees.Diff(context.Background(), "", ""); err != nil {
|
|
t.Errorf("Diff on nil WDiff = %v, want nil", err)
|
|
}
|
|
if _, err := trees.ChangedLines(context.Background(), "", ""); err != nil {
|
|
t.Errorf("ChangedLines on nil WChangedLines = %v, want nil", err)
|
|
}
|
|
}
|