fix(extract): regenerate stale Yaegi symbol tables; fix wfextract directive
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).
This commit is contained in:
1 parent
cbc8aac724
commit
3d37a437ff
9 files changed
+499
-62
No files matched your search
+186
@@ -0,0 +1,186 @@
|
||||
// Code generated by 'yaegi extract github.com/samcharles93/archie-core/internal/domain/workflow'. DO NOT EDIT.
|
||||
|
||||
package wfextract
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Symbols["github.com/samcharles93/archie-core/internal/domain/workflow/workflow"] = map[string]reflect.Value{
|
||||
// function, constant and variable definitions
|
||||
"Bootstrap": reflect.ValueOf(workflow.Bootstrap),
|
||||
"Definitions": reflect.ValueOf(workflow.Definitions),
|
||||
"DefinitionsWithOrigins": reflect.ValueOf(workflow.DefinitionsWithOrigins),
|
||||
"Feasibility": reflect.ValueOf(workflow.Feasibility),
|
||||
"GateFromRepo": reflect.ValueOf(workflow.GateFromRepo),
|
||||
"Implement": reflect.ValueOf(workflow.Implement),
|
||||
"LoadKindWorkflowsYAML": reflect.ValueOf(workflow.LoadKindWorkflowsYAML),
|
||||
"LoadLabelWorkflowsYAML": reflect.ValueOf(workflow.LoadLabelWorkflowsYAML),
|
||||
"LoadPlaybookDirs": reflect.ValueOf(workflow.LoadPlaybookDirs),
|
||||
"MergeKindWorkflows": reflect.ValueOf(workflow.MergeKindWorkflows),
|
||||
"MergeLabelWorkflows": reflect.ValueOf(workflow.MergeLabelWorkflows),
|
||||
"NewCompletedReviewReport": reflect.ValueOf(workflow.NewCompletedReviewReport),
|
||||
"NewNotRunReviewReport": reflect.ValueOf(workflow.NewNotRunReviewReport),
|
||||
"NewSkippedReviewReport": reflect.ValueOf(workflow.NewSkippedReviewReport),
|
||||
"OpenPR": reflect.ValueOf(workflow.OpenPR),
|
||||
"ReviewBlocking": reflect.ValueOf(workflow.ReviewBlocking),
|
||||
"ReviewCategoryDeadCode": reflect.ValueOf(workflow.ReviewCategoryDeadCode),
|
||||
"ReviewCategoryGoroutineLeak": reflect.ValueOf(workflow.ReviewCategoryGoroutineLeak),
|
||||
"ReviewCategoryHardcodedValue": reflect.ValueOf(workflow.ReviewCategoryHardcodedValue),
|
||||
"ReviewCategoryInterfaceSatisfaction": reflect.ValueOf(workflow.ReviewCategoryInterfaceSatisfaction),
|
||||
"ReviewCategoryNilRisk": reflect.ValueOf(workflow.ReviewCategoryNilRisk),
|
||||
"ReviewCategoryOther": reflect.ValueOf(workflow.ReviewCategoryOther),
|
||||
"ReviewCategoryRace": reflect.ValueOf(workflow.ReviewCategoryRace),
|
||||
"ReviewCategoryUncheckedError": reflect.ValueOf(workflow.ReviewCategoryUncheckedError),
|
||||
"ReviewDispositionFixed": reflect.ValueOf(workflow.ReviewDispositionFixed),
|
||||
"ReviewDispositionNoChangeNeeded": reflect.ValueOf(workflow.ReviewDispositionNoChangeNeeded),
|
||||
"ReviewDispositionSkipped": reflect.ValueOf(workflow.ReviewDispositionSkipped),
|
||||
"ReviewLevelError": reflect.ValueOf(workflow.ReviewLevelError),
|
||||
"ReviewLevelWarn": reflect.ValueOf(workflow.ReviewLevelWarn),
|
||||
"ReviewStatusCompleted": reflect.ValueOf(workflow.ReviewStatusCompleted),
|
||||
"ReviewStatusNotRun": reflect.ValueOf(workflow.ReviewStatusNotRun),
|
||||
"ReviewStatusSkipped": reflect.ValueOf(workflow.ReviewStatusSkipped),
|
||||
"ReviewVerdictConfirmed": reflect.ValueOf(workflow.ReviewVerdictConfirmed),
|
||||
"ReviewVerdictPlausible": reflect.ValueOf(workflow.ReviewVerdictPlausible),
|
||||
"Route": reflect.ValueOf(workflow.Route),
|
||||
"Run": reflect.ValueOf(workflow.Run),
|
||||
"SetKindWorkflows": reflect.ValueOf(workflow.SetKindWorkflows),
|
||||
"SetLabelWorkflows": reflect.ValueOf(workflow.SetLabelWorkflows),
|
||||
"StageBaselineGate": reflect.ValueOf(workflow.StageBaselineGate),
|
||||
"StageCommit": reflect.ValueOf(workflow.StageCommit),
|
||||
"StageCommitPush": reflect.ValueOf(workflow.StageCommitPush),
|
||||
"StageDiffCap": reflect.ValueOf(workflow.StageDiffCap),
|
||||
"StageOpenPR": reflect.ValueOf(workflow.StageOpenPR),
|
||||
"StagePrepareWorktree": reflect.ValueOf(workflow.StagePrepareWorktree),
|
||||
"StageRepoStages": reflect.ValueOf(workflow.StageRepoStages),
|
||||
"StageReview": reflect.ValueOf(workflow.StageReview),
|
||||
"StageYaegiGate": reflect.ValueOf(workflow.StageYaegiGate),
|
||||
"TDD": reflect.ValueOf(workflow.TDD),
|
||||
"Triage": reflect.ValueOf(workflow.Triage),
|
||||
|
||||
// type definitions
|
||||
"AgentStage": reflect.ValueOf((*workflow.AgentStage)(nil)),
|
||||
"Definition": reflect.ValueOf((*workflow.Definition)(nil)),
|
||||
"Forger": reflect.ValueOf((*workflow.Forger)(nil)),
|
||||
"KindWorkflows": reflect.ValueOf((*workflow.KindWorkflows)(nil)),
|
||||
"LabelWorkflows": reflect.ValueOf((*workflow.LabelWorkflows)(nil)),
|
||||
"Outcome": reflect.ValueOf((*workflow.Outcome)(nil)),
|
||||
"Registry": reflect.ValueOf((*workflow.Registry)(nil)),
|
||||
"ReviewCategory": reflect.ValueOf((*workflow.ReviewCategory)(nil)),
|
||||
"ReviewDisposition": reflect.ValueOf((*workflow.ReviewDisposition)(nil)),
|
||||
"ReviewFinding": reflect.ValueOf((*workflow.ReviewFinding)(nil)),
|
||||
"ReviewLevel": reflect.ValueOf((*workflow.ReviewLevel)(nil)),
|
||||
"ReviewReport": reflect.ValueOf((*workflow.ReviewReport)(nil)),
|
||||
"ReviewRequest": reflect.ValueOf((*workflow.ReviewRequest)(nil)),
|
||||
"ReviewStatus": reflect.ValueOf((*workflow.ReviewStatus)(nil)),
|
||||
"ReviewVerdict": reflect.ValueOf((*workflow.ReviewVerdict)(nil)),
|
||||
"Reviewer": reflect.ValueOf((*workflow.Reviewer)(nil)),
|
||||
"Stage": reflect.ValueOf((*workflow.Stage)(nil)),
|
||||
"TaskContext": reflect.ValueOf((*workflow.TaskContext)(nil)),
|
||||
"Trees": reflect.ValueOf((*workflow.Trees)(nil)),
|
||||
"Workflow": reflect.ValueOf((*workflow.Workflow)(nil)),
|
||||
|
||||
// interface wrapper definitions
|
||||
"_Forger": reflect.ValueOf((*_github_com_samcharles93_archie_core_internal_domain_workflow_Forger)(nil)),
|
||||
"_Reviewer": reflect.ValueOf((*_github_com_samcharles93_archie_core_internal_domain_workflow_Reviewer)(nil)),
|
||||
"_Trees": reflect.ValueOf((*_github_com_samcharles93_archie_core_internal_domain_workflow_Trees)(nil)),
|
||||
}
|
||||
}
|
||||
|
||||
// _github_com_samcharles93_archie_core_internal_domain_workflow_Forger is an interface wrapper for Forger type
|
||||
type _github_com_samcharles93_archie_core_internal_domain_workflow_Forger struct {
|
||||
IValue interface{}
|
||||
WCloseIssue func(ctx context.Context, owner string, repo string, number int, comment string) error
|
||||
WCreatePR func(ctx context.Context, owner string, repo string, title string, head string, base string, body string) (int, error)
|
||||
WLinkBranch func(ctx context.Context, owner string, repo string, issueNumber int, branch string) error
|
||||
}
|
||||
|
||||
func (W _github_com_samcharles93_archie_core_internal_domain_workflow_Forger) CloseIssue(ctx context.Context, owner string, repo string, number int, comment string) error {
|
||||
if W.WCloseIssue == nil {
|
||||
return nil
|
||||
}
|
||||
return W.WCloseIssue(ctx, owner, repo, number, comment)
|
||||
}
|
||||
func (W _github_com_samcharles93_archie_core_internal_domain_workflow_Forger) CreatePR(ctx context.Context, owner string, repo string, title string, head string, base string, body string) (int, error) {
|
||||
if W.WCreatePR == nil {
|
||||
return 0, nil
|
||||
}
|
||||
return W.WCreatePR(ctx, owner, repo, title, head, base, body)
|
||||
}
|
||||
func (W _github_com_samcharles93_archie_core_internal_domain_workflow_Forger) LinkBranch(ctx context.Context, owner string, repo string, issueNumber int, branch string) error {
|
||||
if W.WLinkBranch == nil {
|
||||
return nil
|
||||
}
|
||||
return W.WLinkBranch(ctx, owner, repo, issueNumber, branch)
|
||||
}
|
||||
|
||||
// _github_com_samcharles93_archie_core_internal_domain_workflow_Reviewer is an interface wrapper for Reviewer type
|
||||
type _github_com_samcharles93_archie_core_internal_domain_workflow_Reviewer struct {
|
||||
IValue interface{}
|
||||
WReview func(ctx context.Context, req workflow.ReviewRequest) workflow.ReviewReport
|
||||
}
|
||||
|
||||
func (W _github_com_samcharles93_archie_core_internal_domain_workflow_Reviewer) Review(ctx context.Context, req workflow.ReviewRequest) workflow.ReviewReport {
|
||||
if W.WReview == nil {
|
||||
return workflow.ReviewReport{}
|
||||
}
|
||||
return W.WReview(ctx, req)
|
||||
}
|
||||
|
||||
// _github_com_samcharles93_archie_core_internal_domain_workflow_Trees is an interface wrapper for Trees type
|
||||
type _github_com_samcharles93_archie_core_internal_domain_workflow_Trees struct {
|
||||
IValue interface{}
|
||||
WChangedFiles func(ctx context.Context, dir string, base string) ([]string, error)
|
||||
WChangedLines func(ctx context.Context, dir string, base string) (int, error)
|
||||
WCommitAll func(ctx context.Context, dir string, message string) (bool, error)
|
||||
WDiff func(ctx context.Context, dir string, base string) (string, error)
|
||||
WPrepare func(ctx context.Context, owner string, repo string, base string, issue int, title string, body string, labels string) (dir string, branch string, err error)
|
||||
WPush func(ctx context.Context, dir string, branch string) error
|
||||
WSnapshot func(ctx context.Context, dir string, destDir string) error
|
||||
}
|
||||
|
||||
func (W _github_com_samcharles93_archie_core_internal_domain_workflow_Trees) ChangedFiles(ctx context.Context, dir string, base string) ([]string, error) {
|
||||
if W.WChangedFiles == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return W.WChangedFiles(ctx, dir, base)
|
||||
}
|
||||
func (W _github_com_samcharles93_archie_core_internal_domain_workflow_Trees) ChangedLines(ctx context.Context, dir string, base string) (int, error) {
|
||||
if W.WChangedLines == nil {
|
||||
return 0, nil
|
||||
}
|
||||
return W.WChangedLines(ctx, dir, base)
|
||||
}
|
||||
func (W _github_com_samcharles93_archie_core_internal_domain_workflow_Trees) CommitAll(ctx context.Context, dir string, message string) (bool, error) {
|
||||
if W.WCommitAll == nil {
|
||||
return false, nil
|
||||
}
|
||||
return W.WCommitAll(ctx, dir, message)
|
||||
}
|
||||
func (W _github_com_samcharles93_archie_core_internal_domain_workflow_Trees) Diff(ctx context.Context, dir string, base string) (string, error) {
|
||||
if W.WDiff == nil {
|
||||
return "", nil
|
||||
}
|
||||
return W.WDiff(ctx, dir, base)
|
||||
}
|
||||
func (W _github_com_samcharles93_archie_core_internal_domain_workflow_Trees) Prepare(ctx context.Context, owner string, repo string, base string, issue int, title string, body string, labels string) (dir string, branch string, err error) {
|
||||
if W.WPrepare == nil {
|
||||
return "", "", nil
|
||||
}
|
||||
return W.WPrepare(ctx, owner, repo, base, issue, title, body, labels)
|
||||
}
|
||||
func (W _github_com_samcharles93_archie_core_internal_domain_workflow_Trees) Push(ctx context.Context, dir string, branch string) error {
|
||||
if W.WPush == nil {
|
||||
return nil
|
||||
}
|
||||
return W.WPush(ctx, dir, branch)
|
||||
}
|
||||
func (W _github_com_samcharles93_archie_core_internal_domain_workflow_Trees) Snapshot(ctx context.Context, dir string, destDir string) error {
|
||||
if W.WSnapshot == nil {
|
||||
return nil
|
||||
}
|
||||
return W.WSnapshot(ctx, dir, destDir)
|
||||
}
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
// Code generated by 'yaegi extract github.com/samcharles93/archie-core/internal/workflow'. DO NOT EDIT.
|
||||
|
||||
package wfextract
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Symbols["github.com/samcharles93/archie-core/internal/domain/workflow/workflow"] = map[string]reflect.Value{
|
||||
// function, constant and variable definitions
|
||||
"Bootstrap": reflect.ValueOf(workflow.Bootstrap),
|
||||
"Feasibility": reflect.ValueOf(workflow.Feasibility),
|
||||
"GateFromRepo": reflect.ValueOf(workflow.GateFromRepo),
|
||||
"Implement": reflect.ValueOf(workflow.Implement),
|
||||
"OpenPR": reflect.ValueOf(workflow.OpenPR),
|
||||
"Route": reflect.ValueOf(workflow.Route),
|
||||
"Run": reflect.ValueOf(workflow.Run),
|
||||
"StageBaselineGate": reflect.ValueOf(workflow.StageBaselineGate),
|
||||
"StageCommit": reflect.ValueOf(workflow.StageCommit),
|
||||
"StageCommitPush": reflect.ValueOf(workflow.StageCommitPush),
|
||||
"StageDiffCap": reflect.ValueOf(workflow.StageDiffCap),
|
||||
"StageOpenPR": reflect.ValueOf(workflow.StageOpenPR),
|
||||
"StagePrepareWorktree": reflect.ValueOf(workflow.StagePrepareWorktree),
|
||||
"StageRepoStages": reflect.ValueOf(workflow.StageRepoStages),
|
||||
"StageYaegiGate": reflect.ValueOf(workflow.StageYaegiGate),
|
||||
"TDD": reflect.ValueOf(workflow.TDD),
|
||||
|
||||
// type definitions
|
||||
"AgentStage": reflect.ValueOf((*workflow.AgentStage)(nil)),
|
||||
"Outcome": reflect.ValueOf((*workflow.Outcome)(nil)),
|
||||
"Registry": reflect.ValueOf((*workflow.Registry)(nil)),
|
||||
"Stage": reflect.ValueOf((*workflow.Stage)(nil)),
|
||||
"TaskContext": reflect.ValueOf((*workflow.TaskContext)(nil)),
|
||||
"Workflow": reflect.ValueOf((*workflow.Workflow)(nil)),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,16 @@
|
||||
// Package wfextract holds the Yaegi symbol table for internal/workflow,
|
||||
// generated by `go generate`. Kept separate from internal/workflow itself
|
||||
// so the generated file can import it without a self-import cycle.
|
||||
// Package wfextract holds the Yaegi symbol table for internal/domain/workflow,
|
||||
// generated by `go generate`. Kept separate from internal/domain/workflow
|
||||
// itself so the generated file can import it without a self-import cycle.
|
||||
//
|
||||
// IMPORTANT: Running `go generate` overwrites the generated file with
|
||||
// Yaegi's default wrapper which does NOT include nil-guards on function
|
||||
// fields. The `TestWrapperNilGuardsPreserved` test catches this if
|
||||
// regeneration strips the guards. Re-apply nil-guards manually after
|
||||
// regeneration until Yaegi supports generating them natively.
|
||||
package wfextract
|
||||
|
||||
import "reflect"
|
||||
|
||||
//go:generate go run github.com/traefik/yaegi/cmd/yaegi extract -name wfextract github.com/samcharles93/archie-core/internal/workflow
|
||||
//go:generate go run github.com/traefik/yaegi/cmd/yaegi extract -name wfextract github.com/samcharles93/archie-core/internal/domain/workflow
|
||||
|
||||
var Symbols = map[string]map[string]reflect.Value{}
|
||||
@@ -3,9 +3,8 @@
|
||||
package gateextract
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/gate"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
+64
-9
@@ -3,29 +3,85 @@
|
||||
package pluginextract
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"context"
|
||||
"github.com/samcharles93/archie-core/internal/plugin"
|
||||
"go/constant"
|
||||
"go/token"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func init() {
|
||||
Symbols["github.com/samcharles93/archie-core/internal/plugin/plugin"] = map[string]reflect.Value{
|
||||
// function, constant and variable definitions
|
||||
"LoadDir": reflect.ValueOf(plugin.LoadDir),
|
||||
"AdaptLegacy": reflect.ValueOf(plugin.AdaptLegacy),
|
||||
"HealthDegraded": reflect.ValueOf(plugin.HealthDegraded),
|
||||
"HealthHealthy": reflect.ValueOf(plugin.HealthHealthy),
|
||||
"HealthUnhealthy": reflect.ValueOf(plugin.HealthUnhealthy),
|
||||
"HealthUnknown": reflect.ValueOf(plugin.HealthUnknown),
|
||||
"HostAPIVersion": reflect.ValueOf(constant.MakeFromLiteral("\"1.0.0\"", token.STRING, 0)),
|
||||
"LoadDir": reflect.ValueOf(plugin.LoadDir),
|
||||
"NewHost": reflect.ValueOf(plugin.NewHost),
|
||||
"StateFailed": reflect.ValueOf(plugin.StateFailed),
|
||||
"StateRegistered": reflect.ValueOf(plugin.StateRegistered),
|
||||
"StateRunning": reflect.ValueOf(plugin.StateRunning),
|
||||
"StateStarting": reflect.ValueOf(plugin.StateStarting),
|
||||
"StateStopped": reflect.ValueOf(plugin.StateStopped),
|
||||
"StateStopping": reflect.ValueOf(plugin.StateStopping),
|
||||
|
||||
// type definitions
|
||||
"Plugin": reflect.ValueOf((*plugin.Plugin)(nil)),
|
||||
"Registry": reflect.ValueOf((*plugin.Registry)(nil)),
|
||||
"CapabilityKind": reflect.ValueOf((*plugin.CapabilityKind)(nil)),
|
||||
"Health": reflect.ValueOf((*plugin.Health)(nil)),
|
||||
"HealthStatus": reflect.ValueOf((*plugin.HealthStatus)(nil)),
|
||||
"Host": reflect.ValueOf((*plugin.Host)(nil)),
|
||||
"LifecycleState": reflect.ValueOf((*plugin.LifecycleState)(nil)),
|
||||
"Manifest": reflect.ValueOf((*plugin.Manifest)(nil)),
|
||||
"Module": reflect.ValueOf((*plugin.Module)(nil)),
|
||||
"ModuleStatus": reflect.ValueOf((*plugin.ModuleStatus)(nil)),
|
||||
"Permission": reflect.ValueOf((*plugin.Permission)(nil)),
|
||||
"Plugin": reflect.ValueOf((*plugin.Plugin)(nil)),
|
||||
"Registry": reflect.ValueOf((*plugin.Registry)(nil)),
|
||||
|
||||
// interface wrapper definitions
|
||||
"_Module": reflect.ValueOf((*_github_com_samcharles93_archie_core_internal_plugin_Module)(nil)),
|
||||
"_Plugin": reflect.ValueOf((*_github_com_samcharles93_archie_core_internal_plugin_Plugin)(nil)),
|
||||
}
|
||||
}
|
||||
|
||||
// _github_com_samcharles93_archie_core_internal_plugin_Module is an interface wrapper for Module type
|
||||
type _github_com_samcharles93_archie_core_internal_plugin_Module struct {
|
||||
IValue interface{}
|
||||
WHealth func(a0 context.Context) plugin.Health
|
||||
WManifest func() plugin.Manifest
|
||||
WStart func(a0 context.Context) error
|
||||
WStop func(a0 context.Context) error
|
||||
}
|
||||
|
||||
func (W _github_com_samcharles93_archie_core_internal_plugin_Module) Health(a0 context.Context) plugin.Health {
|
||||
if W.WHealth == nil {
|
||||
return plugin.Health{}
|
||||
}
|
||||
return W.WHealth(a0)
|
||||
}
|
||||
func (W _github_com_samcharles93_archie_core_internal_plugin_Module) Manifest() plugin.Manifest {
|
||||
if W.WManifest == nil {
|
||||
return plugin.Manifest{}
|
||||
}
|
||||
return W.WManifest()
|
||||
}
|
||||
func (W _github_com_samcharles93_archie_core_internal_plugin_Module) Start(a0 context.Context) error {
|
||||
if W.WStart == nil {
|
||||
return nil
|
||||
}
|
||||
return W.WStart(a0)
|
||||
}
|
||||
func (W _github_com_samcharles93_archie_core_internal_plugin_Module) Stop(a0 context.Context) error {
|
||||
if W.WStop == nil {
|
||||
return nil
|
||||
}
|
||||
return W.WStop(a0)
|
||||
}
|
||||
|
||||
// _github_com_samcharles93_archie_core_internal_plugin_Plugin is an interface wrapper for Plugin type
|
||||
// generated by 'yaegi extract'. IValue is required by Yaegi's interface bridging --
|
||||
// it holds the underlying concrete value for the interpreter's type system even
|
||||
// though Name()/Version() delegate to the function fields. Do not remove.
|
||||
type _github_com_samcharles93_archie_core_internal_plugin_Plugin struct {
|
||||
IValue interface{}
|
||||
WName func() string
|
||||
@@ -38,7 +94,6 @@ func (W _github_com_samcharles93_archie_core_internal_plugin_Plugin) Name() stri
|
||||
}
|
||||
return W.WName()
|
||||
}
|
||||
|
||||
func (W _github_com_samcharles93_archie_core_internal_plugin_Plugin) Version() string {
|
||||
if W.WVersion == nil {
|
||||
return ""
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
package pluginextract
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/traefik/yaegi/interp"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/plugin"
|
||||
"github.com/samcharles93/archie-core/internal/yaegiutil"
|
||||
)
|
||||
|
||||
// TestPreviouslyMissingSymbolsReachableFromInterpretedCode is the regression
|
||||
// test for the stale symbol-table drift (e7bo): the committed generated file
|
||||
// predated internal/plugin/host.go (f73b2d1) and was never regenerated, so
|
||||
// the Host/Module/Manifest/Permission/Health/CapabilityKind/LifecycleState/
|
||||
// ModuleStatus types and the NewHost/AdaptLegacy/HostAPIVersion identifiers
|
||||
// that plugin.go's LoadDir exposes to interpreted daemon plugins were absent
|
||||
// from the table. A daemon plugin written against the capability-host API
|
||||
// could not resolve them, silently.
|
||||
//
|
||||
// This test interprets a plugin that references the previously-missing
|
||||
// symbols, resolves it, and calls it -- proving the symbols are wired.
|
||||
func TestPreviouslyMissingSymbolsReachableFromInterpretedCode(t *testing.T) {
|
||||
src := `package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/plugin"
|
||||
)
|
||||
|
||||
// BuildHost exercises NewHost and HostAPIVersion -- the module-capability
|
||||
// registration surface that was missing from the symbol table.
|
||||
func BuildHost(m plugin.Module) (string, error) {
|
||||
h := plugin.NewHost()
|
||||
if h == nil {
|
||||
return "", fmt.Errorf("NewHost returned nil")
|
||||
}
|
||||
if plugin.HostAPIVersion == "" {
|
||||
return "", fmt.Errorf("HostAPIVersion empty")
|
||||
}
|
||||
if err := h.Register(m); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := h.Start(context.Background()); err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer h.Stop(context.Background())
|
||||
return plugin.HostAPIVersion, nil
|
||||
}
|
||||
`
|
||||
|
||||
i, err := yaegiutil.New(interp.Options{}, Symbols)
|
||||
if err != nil {
|
||||
t.Fatalf("New: %v", err)
|
||||
}
|
||||
buildHost, err := yaegiutil.Resolve[func(plugin.Module) (string, error)](i, src, "main.BuildHost")
|
||||
if err != nil {
|
||||
t.Fatalf("Resolve BuildHost: %v", err)
|
||||
}
|
||||
|
||||
// Call through with a Go-side module implementing the contract. This
|
||||
// proves the interpreted host API works across the boundary end to end.
|
||||
mod := testModule{}
|
||||
version, err := buildHost(mod)
|
||||
if err != nil {
|
||||
t.Fatalf("BuildHost: %v", err)
|
||||
}
|
||||
if version != plugin.HostAPIVersion {
|
||||
t.Errorf("BuildHost version = %q, want %q", version, plugin.HostAPIVersion)
|
||||
}
|
||||
}
|
||||
|
||||
// testModule implements plugin.Module for the Go-side call.
|
||||
type testModule struct{}
|
||||
|
||||
func (testModule) Manifest() plugin.Manifest {
|
||||
return plugin.Manifest{
|
||||
ID: "test",
|
||||
Name: "test",
|
||||
Version: "1.0.0",
|
||||
APIVersion: plugin.HostAPIVersion,
|
||||
Capabilities: []plugin.CapabilityKind{"test.capability"},
|
||||
}
|
||||
}
|
||||
|
||||
func (testModule) Start(context.Context) error { return nil }
|
||||
func (testModule) Health(context.Context) plugin.Health {
|
||||
return plugin.Health{Status: plugin.HealthHealthy}
|
||||
}
|
||||
func (testModule) Stop(context.Context) error { return nil }
|
||||
|
||||
// TestWrapperNilGuardsPreserved follows the established pattern: yaegi's
|
||||
// fresh wrapper generation omits nil-guards on interface-wrappers, 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 mod _github_com_samcharles93_archie_core_internal_plugin_Module
|
||||
if err := mod.Start(context.Background()); err != nil {
|
||||
t.Errorf("Start on nil WStart = %v, want nil", err)
|
||||
}
|
||||
if got := mod.Manifest(); got.ID != "" || got.Name != "" || got.APIVersion != "" {
|
||||
t.Errorf("Manifest on nil WManifest = %#v, want empty", got)
|
||||
}
|
||||
if got := mod.Health(context.Background()); got.Status != "" || got.Message != "" {
|
||||
t.Errorf("Health on nil WHealth = %#v, want empty", got)
|
||||
}
|
||||
if err := mod.Stop(context.Background()); err != nil {
|
||||
t.Errorf("Stop on nil WStop = %v, want nil", err)
|
||||
}
|
||||
|
||||
var legacy _github_com_samcharles93_archie_core_internal_plugin_Plugin
|
||||
if got := legacy.Name(); got != "" {
|
||||
t.Errorf("Name on nil WName = %q, want empty", got)
|
||||
}
|
||||
if got := legacy.Version(); got != "" {
|
||||
t.Errorf("Version on nil WVersion = %q, want empty", got)
|
||||
}
|
||||
}
|
||||
|
||||
var _ plugin.Module = testModule{}
|
||||
+2
-8
@@ -3,9 +3,8 @@
|
||||
package secretextract
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/secret"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -25,11 +24,8 @@ func init() {
|
||||
}
|
||||
|
||||
// _github_com_samcharles93_archie_core_internal_secret_Engine is an interface wrapper for Engine type
|
||||
// generated by 'yaegi extract'. IValue is required by Yaegi's interface bridging --
|
||||
// it holds the underlying concrete value for the interpreter's type system even
|
||||
// though Name()/Resolve()/Version() delegate to the function fields. Do not remove.
|
||||
type _github_com_samcharles93_archie_core_internal_secret_Engine struct {
|
||||
IValue any
|
||||
IValue interface{}
|
||||
WName func() string
|
||||
WResolve func(key string) (string, error)
|
||||
WVersion func() string
|
||||
@@ -41,14 +37,12 @@ func (W _github_com_samcharles93_archie_core_internal_secret_Engine) Name() stri
|
||||
}
|
||||
return W.WName()
|
||||
}
|
||||
|
||||
func (W _github_com_samcharles93_archie_core_internal_secret_Engine) Resolve(key string) (string, error) {
|
||||
if W.WResolve == nil {
|
||||
return "", nil
|
||||
}
|
||||
return W.WResolve(key)
|
||||
}
|
||||
|
||||
func (W _github_com_samcharles93_archie_core_internal_secret_Engine) Version() string {
|
||||
if W.WVersion == nil {
|
||||
return ""
|
||||
|
||||
Reference in new issue
Block a user