The events table had no attempt column, so two attempts of the same task were indistinguishable: a retried task's stage events interleaved into one timeline and nothing could say which run produced a given result. - events gains an `attempt` column through the existing presence-gated migrateTasks loop rather than a version bump, so user_version stays 3 and an existing archie.db is migrated in place. A legacy-database test builds the pre-change schema and proves both that existing rows survive unattributed (attempt = 0) and that a new value round-trips. - Event.attempt = 11 and ReadTaskLogRequest.stage = 9 are field additions to existing messages: no new RPC, no new table, and no change to any canonical error message that crosses the state-store wire. - Every task event the workflow engine emits now carries the attempt. Producers that have no attempt yet (task_queued, binding_dispatch_failure) stay unattributed rather than guessing one. - Changed files are captured as a durable changes_captured event at commit and push time, reusing the existing three-dot diff primitive: paths from FilePatches(), counts from Stats(), base_sha recorded as the merge base actually diffed rather than the base tip, a 200-file cap with totals kept complete. Consumption goes through an unexported optional interface so workflow.Trees -- the yaegi capability surface for interpreted stage plugins -- is not widened. A capture is also taken once the pull request exists, so the capture can link it. - The per-attempt configuration is captured as a durable config_captured event carrying the non-secret config.TaskConfig, instead of a new table plus two new state-store RPCs: events are already this system's per-attempt provenance stream, so a table would have given one feature two provenance mechanisms. Redaction is proven against canary secrets. Measured payload: 539 bytes typical, 2333 bytes at 20 models. - Captures carry a schema marker and are refused unless their key set matches the declared payload shape, so drift surfaces as "recorded but could not be read" rather than as a capture of zeroes. - Three read endpoints serve the attempt rail, the changed-file captures and a raw debug view, mapping to UI-owned response types rather than dumping store types. - The task-log read gains a stage filter, bound to the stage logger for that stage's own lines; agent and tool output records no stage. A task-scoped grant may already insert events on its own task, so this provenance is exactly as trustworthy as the rest of that task's event stream. That limit is documented rather than papered over.
179 lines
6.8 KiB
Go
179 lines
6.8 KiB
Go
package wfextract
|
|
|
|
import (
|
|
"context"
|
|
"reflect"
|
|
"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)
|
|
}
|
|
}
|
|
|
|
// TestChangeCaptureIsNotCallableFromInterpretedCode is the acceptance test for
|
|
// "the sandbox surface did not widen", in the same shape as the reachability
|
|
// test above and with the opposite assertion.
|
|
//
|
|
// An attempt's changed files are captured through an UNEXPORTED optional
|
|
// interface asserted on TaskContext.Trees, precisely so that the capability is
|
|
// not part of workflow.Trees: Trees is projected into this symbol table, so a
|
|
// method added to it would become callable by every repository-authored
|
|
// .archie/stages/*.go file. Both halves are asserted here -- the interface's
|
|
// method set, and the interpreted call that must not resolve -- because the
|
|
// second alone would be weaker: it would still pass if the symbol table lost
|
|
// Trees altogether.
|
|
func TestChangeCaptureIsNotCallableFromInterpretedCode(t *testing.T) {
|
|
trees := reflect.TypeFor[workflow.Trees]()
|
|
if _, ok := trees.MethodByName("ChangedFileStats"); ok {
|
|
t.Fatalf("workflow.Trees gained ChangedFileStats; interpreted stage code can now read a diffstat the engine only meant to capture")
|
|
}
|
|
|
|
// The control first: an interpreted call to a method Trees really has must
|
|
// resolve, so the refusal below is the missing method and not a broken
|
|
// harness.
|
|
const control = `package main
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
|
)
|
|
|
|
func UseTrees(t workflow.Trees) {
|
|
_, _ = t.Diff(context.Background(), "", "")
|
|
}
|
|
`
|
|
const probe = `package main
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
|
)
|
|
|
|
// CaptureDiffstat is an interpreted stage trying to reach the engine's
|
|
// change capture through the surface TaskContext hands it.
|
|
func CaptureDiffstat(t workflow.Trees) {
|
|
stats, err := t.ChangedFileStats(context.Background(), "", "")
|
|
_, _ = stats.HeadSHA, err
|
|
}
|
|
`
|
|
|
|
i, err := yaegiutil.New(interp.Options{}, Symbols)
|
|
if err != nil {
|
|
t.Fatalf("New: %v", err)
|
|
}
|
|
if _, err := yaegiutil.Resolve[func(workflow.Trees)](i, control, "main.UseTrees"); err != nil {
|
|
t.Fatalf("the control call Trees.Diff did not resolve (%v); this test cannot tell a missing capability from a broken symbol table", err)
|
|
}
|
|
|
|
j, err := yaegiutil.New(interp.Options{}, Symbols)
|
|
if err != nil {
|
|
t.Fatalf("New: %v", err)
|
|
}
|
|
if _, err := yaegiutil.Resolve[func(workflow.Trees)](j, probe, "main.CaptureDiffstat"); err == nil {
|
|
t.Error("interpreted stage code resolved Trees.ChangedFileStats; the capture capability leaked into the projected surface")
|
|
}
|
|
}
|