Skip fallback needs complete, empty evidence; capture lists over-budget changes
The server skip fallback for stages with a skipped edge now applies only when every earlier visit recorded a complete file-change capture with no changed files and no image artifact. Any change (no repo-specific UI path or extension list), any partial/unavailable/missing capture, a human decision or a checkpoint-retry prefix runs the model. auto_skip=false opts a stage out. The fallback verdict names the server fallback. Capture compares over-budget text by hash and, in Git, lists paths it could not compare when their git status changes, marked no_patch, so a large workspace no longer records files: [] for a real edit. Run detail gains a warnings list for partial/unavailable captures, also printed by inspect on stderr.
This commit is contained in:
+23
-14
@@ -951,11 +951,14 @@ type runState struct {
|
||||
input stage.Values
|
||||
// changedPaths retains a bounded sample of the run's recorded changed paths
|
||||
// and changedCount the full total, so the skip guard reads only in-memory
|
||||
// evidence. uiSurface is latched once any recorded change touched a UI
|
||||
// surface. Both are folded in by recordChanges (ui_surface.go).
|
||||
changedPaths []string
|
||||
changedCount int
|
||||
uiSurface bool
|
||||
// evidence. uiSurface is latched once any visit captured a rendered (image)
|
||||
// artifact. captureIncomplete counts visits whose file-change capture was
|
||||
// missing, partial or unavailable; any such visit forbids the server skip
|
||||
// fallback. All are folded in by recordChanges (ui_surface.go).
|
||||
changedPaths []string
|
||||
changedCount int
|
||||
uiSurface bool
|
||||
captureIncomplete int
|
||||
// capturedPaths is the full, deduplicated, first-seen-ordered set of the
|
||||
// run's server-captured changed paths, distinct from the bounded
|
||||
// changedPaths sample used only by the skip reason. capturedSeen is the
|
||||
@@ -1020,7 +1023,7 @@ func rebuildRunState(detail *protocol.RunDetail, decided protocol.RunStep) *runS
|
||||
}
|
||||
// Seed the UI-surface accumulator from the persisted evidence so a
|
||||
// resumed run reaches the same skip decision with no extra query.
|
||||
state.recordChanges(step.FileChanges, step.Artifacts)
|
||||
state.recordPersistedStep(step)
|
||||
// Only completed, recorded visits are eligible for a later stage's
|
||||
// review capability. The path is reconstructed by the runner below.
|
||||
if step.Status == "completed" {
|
||||
@@ -1062,7 +1065,7 @@ func rebuildRetryState(detail *protocol.RunDetail, failed protocol.RunStep, hand
|
||||
state.turns = append(state.turns, turn.MemoryEntry{Stage: step.Stage, Visit: state.visits[step.Stage], Output: turnOutput(step.Output), PublicFiles: added})
|
||||
state.lastOutput = turnOutput(step.Output)
|
||||
}
|
||||
state.recordChanges(step.FileChanges, step.Artifacts)
|
||||
state.recordPersistedStep(step)
|
||||
if step.Status == "completed" {
|
||||
state.artifactDirs = append(state.artifactDirs, filepath.Join("", strconv.Itoa(step.Sequence)))
|
||||
}
|
||||
@@ -1073,6 +1076,9 @@ func rebuildRetryState(detail *protocol.RunDetail, failed protocol.RunStep, hand
|
||||
// retry source's immediate steps (which is what made retry-of-retry fail
|
||||
// closed with "memory source ... has not completed").
|
||||
if prefix, ok := handoff["prefix"].(map[string]any); ok {
|
||||
// The checkpoint carries outputs, not file-change captures, so an inherited
|
||||
// prefix is unobserved evidence: the server skip fallback must not apply.
|
||||
state.captureIncomplete++
|
||||
for _, record := range retryPrefixRecords(handoff["prefix_provenance"]) {
|
||||
output, exists := prefix[record.stage].(map[string]any)
|
||||
if !exists {
|
||||
@@ -1591,7 +1597,7 @@ func (r *runner) runLoop(ctx context.Context, id int64, graph protocol.Graph, na
|
||||
}
|
||||
}
|
||||
_, declaresSkip := def.Edges["skipped"]
|
||||
skip := !isHuman && declaresSkip && !state.uiSurface
|
||||
skip := !isHuman && declaresSkip && autoSkipEligible(def.Configs, state)
|
||||
state.nextSequence = sequence + 1
|
||||
state.visits[key]++
|
||||
// Publish the run's server-captured changed paths into the input memory
|
||||
@@ -1683,13 +1689,15 @@ func (r *runner) runLoop(ctx context.Context, id int64, graph protocol.Graph, na
|
||||
r.deliverRunNotificationBatch(time.Now(), 1)
|
||||
return
|
||||
}
|
||||
// A stage that declares a `skipped` route is short-circuited when the run
|
||||
// has recorded no UI surface: the stage would answer exactly that, so skip
|
||||
// the model call and its capture work, record the step as completed and
|
||||
// route along the declared edge. Only a declared route is honoured, and no
|
||||
// other stage or outcome routing changes.
|
||||
// Server skip fallback: a stage that declares a `skipped` route is
|
||||
// short-circuited only when the run's evidence is complete and empty
|
||||
// (autoSkipEligible, ui_surface.go): every visit recorded a complete
|
||||
// capture with no file changes and no rendered artifact. Then skip the
|
||||
// model call and its capture work, record the step as completed with a
|
||||
// verdict that names the server fallback, and route along the declared
|
||||
// edge. Partial, unavailable or missing evidence always runs the model.
|
||||
if skip {
|
||||
reason := skipReasonLine(state)
|
||||
reason := skipReasonLine()
|
||||
step := protocol.RunStep{
|
||||
Sequence: sequence,
|
||||
Stage: key,
|
||||
@@ -1698,6 +1706,7 @@ func (r *runner) runLoop(ctx context.Context, id int64, graph protocol.Graph, na
|
||||
Output: stage.Values{"summary": reason},
|
||||
Target: def.Edges["skipped"],
|
||||
Control: &protocol.ControlEvidence{Visit: state.visits[key], MaxVisits: maxVisits, Memory: reads},
|
||||
Verdict: &protocol.StageVerdict{Reason: reason, ReasonSource: protocol.VerdictReasonFallback},
|
||||
}
|
||||
status, outcome, diagnostic, terminal, finishErr := r.finishStage(id, name, workspace, selected, state, step)
|
||||
if finishErr != nil {
|
||||
|
||||
+154
-72
@@ -2,12 +2,15 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/filediff"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
"git.a-wan.net/alan/pipelines/internal/stage"
|
||||
@@ -30,6 +33,12 @@ func uiReviewerSource(withSkip bool) string {
|
||||
// then returns the persisted detail, the visited keys and the number of verdict
|
||||
// (model) calls the runner made.
|
||||
func runUISkip(t *testing.T, source string, files map[string]string) (*protocol.RunDetail, []string, int) {
|
||||
t.Helper()
|
||||
return runUISkipIn(t, source, files, t.TempDir())
|
||||
}
|
||||
|
||||
// runUISkipIn is runUISkip against a prepared workspace directory.
|
||||
func runUISkipIn(t *testing.T, source string, files map[string]string, dir string) (*protocol.RunDetail, []string, int) {
|
||||
t.Helper()
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
@@ -50,7 +59,6 @@ func runUISkip(t *testing.T, source string, files map[string]string) (*protocol.
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer r.wg.Wait()
|
||||
dir := t.TempDir()
|
||||
var mu sync.Mutex
|
||||
var visited []string
|
||||
verdictCalls := 0
|
||||
@@ -106,37 +114,28 @@ func executed(visited []string, key string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// TestUISkipShortCircuitsWhenNoSurfaceChanged proves a non-UI change skips the
|
||||
// ui_reviewer stage with no model call and routes along its declared skip edge.
|
||||
func TestUISkipShortCircuitsWhenNoSurfaceChanged(t *testing.T) {
|
||||
detail, visited, verdictCalls := runUISkip(t, uiReviewerSource(true), map[string]string{"implement": "internal/server/fake.go"})
|
||||
if executed(visited, "ui_reviewer") {
|
||||
t.Fatalf("ui_reviewer executed a model call; visited=%v", visited)
|
||||
// assertModelRan fails unless ui_reviewer executed its model and routed through
|
||||
// its own outcome rather than the server fallback.
|
||||
func assertModelRan(t *testing.T, detail *protocol.RunDetail, visited []string, verdictCalls int) {
|
||||
t.Helper()
|
||||
if !executed(visited, "ui_reviewer") {
|
||||
t.Fatalf("ui_reviewer was auto-skipped; visited=%v steps=%+v", visited, detail.Steps)
|
||||
}
|
||||
if verdictCalls != 1 {
|
||||
t.Fatalf("verdict (model) calls = %d, want only implement's 1", verdictCalls)
|
||||
if verdictCalls != 2 {
|
||||
t.Fatalf("verdict (model) calls = %d, want 2 for both executed stages", verdictCalls)
|
||||
}
|
||||
if detail.Status != "succeeded" {
|
||||
t.Fatalf("run status = %q, want succeeded: %+v", detail.Status, detail.RunSummary)
|
||||
}
|
||||
if len(detail.Steps) != 2 {
|
||||
t.Fatalf("steps = %d, want 2: %+v", len(detail.Steps), detail.Steps)
|
||||
}
|
||||
step := detail.Steps[1]
|
||||
if step.Stage != "ui_reviewer" || step.Status != "completed" || step.Outcome != "skipped" || step.Target != protocol.SuccessEnd {
|
||||
t.Fatalf("skip step wrong: %+v", step)
|
||||
}
|
||||
if step.FileChanges != nil && len(step.FileChanges.Files) != 0 {
|
||||
t.Fatalf("skip step recorded file changes: %+v", step.FileChanges)
|
||||
}
|
||||
reason, _ := step.Output["summary"].(string)
|
||||
if !strings.Contains(reason, "internal/server/fake.go") {
|
||||
t.Fatalf("skip reason does not name the checked path: %q", reason)
|
||||
step := detail.Steps[len(detail.Steps)-1]
|
||||
if step.Stage != "ui_reviewer" || step.Outcome != "approved" || step.Target != protocol.SuccessEnd {
|
||||
t.Fatalf("executed step did not route through approved: %+v", step)
|
||||
}
|
||||
}
|
||||
|
||||
// TestUISkipZeroChangesStillSkips proves the guard also short-circuits when the
|
||||
// run recorded no file changes at all, with a reason that says so.
|
||||
// TestUISkipZeroChangesStillSkips proves the fallback short-circuits when every
|
||||
// visit recorded a complete capture with no file changes, and that the verdict
|
||||
// says it was a server fallback with no model run.
|
||||
func TestUISkipZeroChangesStillSkips(t *testing.T) {
|
||||
detail, visited, verdictCalls := runUISkip(t, uiReviewerSource(true), nil)
|
||||
if executed(visited, "ui_reviewer") {
|
||||
@@ -148,48 +147,127 @@ func TestUISkipZeroChangesStillSkips(t *testing.T) {
|
||||
if detail.Status != "succeeded" || len(detail.Steps) != 2 {
|
||||
t.Fatalf("run = %q steps=%d, want succeeded/2", detail.Status, len(detail.Steps))
|
||||
}
|
||||
if first := detail.Steps[0].FileChanges; first == nil || first.Status != "complete" {
|
||||
t.Fatalf("implement capture = %+v, want complete", first)
|
||||
}
|
||||
step := detail.Steps[1]
|
||||
if step.Outcome != "skipped" {
|
||||
t.Fatalf("step outcome = %q, want skipped: %+v", step.Outcome, step)
|
||||
if step.Stage != "ui_reviewer" || step.Status != "completed" || step.Outcome != "skipped" || step.Target != protocol.SuccessEnd {
|
||||
t.Fatalf("skip step wrong: %+v", step)
|
||||
}
|
||||
if step.FileChanges != nil {
|
||||
t.Fatalf("skip step recorded a capture: %+v", step.FileChanges)
|
||||
}
|
||||
if step.Verdict == nil || step.Verdict.ReasonSource != protocol.VerdictReasonFallback || !strings.HasPrefix(step.Verdict.Reason, serverSkipReasonPrefix) {
|
||||
t.Fatalf("skip verdict does not name the server fallback: %+v", step.Verdict)
|
||||
}
|
||||
reason, _ := step.Output["summary"].(string)
|
||||
if !strings.Contains(reason, "no recorded file changes") {
|
||||
if !strings.Contains(reason, "recorded no file changes") {
|
||||
t.Fatalf("zero-change reason does not state that: %q", reason)
|
||||
}
|
||||
if len(detail.Warnings) != 0 {
|
||||
t.Fatalf("complete run carries warnings: %v", detail.Warnings)
|
||||
}
|
||||
}
|
||||
|
||||
// TestUISkipRunsStageOnSurfaceChange proves a run that touched a UI surface
|
||||
// still executes the stage and routes through its normal outcome.
|
||||
func TestUISkipRunsStageOnSurfaceChange(t *testing.T) {
|
||||
// TestUISkipRunsModelOnAnyRecordedChange proves no path is classified as "not
|
||||
// UI": a backend file, a Flutter .dart file, a Kotlin file, a Go TUI file and a
|
||||
// web .tsx file all make the stage run its model. The fallback never encodes a
|
||||
// repository layout.
|
||||
func TestUISkipRunsModelOnAnyRecordedChange(t *testing.T) {
|
||||
cases := map[string]string{
|
||||
"android": "android/app/src/main/kotlin/Main.kt",
|
||||
"internal tui": "internal/tui/view.go",
|
||||
"presentation": "web/app.tsx",
|
||||
"go backend": "internal/server/fake.go",
|
||||
"flutter dart": "app/lib/features/home/home_page.dart",
|
||||
"kotlin": "android/app/src/main/kotlin/Main.kt",
|
||||
"go tui": "internal/tui/view.go",
|
||||
"web tsx": "web/app.tsx",
|
||||
"docs": "docs/readme.md",
|
||||
}
|
||||
for name, path := range cases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
detail, visited, verdictCalls := runUISkip(t, uiReviewerSource(true), map[string]string{"implement": path})
|
||||
if !executed(visited, "ui_reviewer") {
|
||||
t.Fatalf("ui_reviewer did not execute on %s; visited=%v", path, visited)
|
||||
}
|
||||
if verdictCalls != 2 {
|
||||
t.Fatalf("verdict (model) calls = %d, want 2 for both executed stages", verdictCalls)
|
||||
}
|
||||
if detail.Status != "succeeded" {
|
||||
t.Fatalf("run status = %q, want succeeded: %+v", detail.Status, detail.RunSummary)
|
||||
}
|
||||
step := detail.Steps[len(detail.Steps)-1]
|
||||
if step.Stage != "ui_reviewer" || step.Outcome != "approved" || step.Target != protocol.SuccessEnd {
|
||||
t.Fatalf("executed step did not route through approved: %+v", step)
|
||||
}
|
||||
assertModelRan(t, detail, visited, verdictCalls)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestUISkipPartialCaptureNeverSkips proves a visit whose capture was partial
|
||||
// (here a protected .env file forces skipped>0) blocks the fallback even when
|
||||
// it recorded no file changes, and that inspect carries a run-level warning.
|
||||
func TestUISkipPartialCaptureNeverSkips(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
if err := os.WriteFile(filepath.Join(dir, ".env"), []byte("A=1\n"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
detail, visited, verdictCalls := runUISkipIn(t, uiReviewerSource(true), nil, dir)
|
||||
if first := detail.Steps[0].FileChanges; first == nil || first.Status != "partial" || len(first.Files) != 0 {
|
||||
t.Fatalf("fixture capture = %+v, want partial with no files", first)
|
||||
}
|
||||
assertModelRan(t, detail, visited, verdictCalls)
|
||||
if len(detail.Warnings) != 1 || !strings.Contains(detail.Warnings[0], "implement #1 (partial)") {
|
||||
t.Fatalf("partial capture warning missing: %v", detail.Warnings)
|
||||
}
|
||||
}
|
||||
|
||||
// TestUISkipOverBudgetGitWorkspaceRunsModel is the run-236 regression: in a Git
|
||||
// workspace whose text exceeds the snapshot budget, a stage edits one .tsx file
|
||||
// sorted after the budget is exhausted. The capture must list that file
|
||||
// (without a patch) and the next stage, which declares `skipped`, must run its
|
||||
// model rather than be auto-routed with "no recorded file changes".
|
||||
func TestUISkipOverBudgetGitWorkspaceRunsModel(t *testing.T) {
|
||||
if _, err := exec.LookPath("git"); err != nil {
|
||||
t.Skip("git unavailable")
|
||||
}
|
||||
restore := filediff.SetSnapshotBudgetForTesting(256)
|
||||
defer restore()
|
||||
dir := t.TempDir()
|
||||
git := func(args ...string) {
|
||||
t.Helper()
|
||||
cmd := exec.Command("git", append([]string{"-C", dir, "-c", "user.email=t@example.invalid", "-c", "user.name=t", "-c", "commit.gpgsign=false"}, args...)...)
|
||||
if data, err := cmd.CombinedOutput(); err != nil {
|
||||
t.Fatalf("%v: %v %s", args, err, data)
|
||||
}
|
||||
}
|
||||
git("init", "-q")
|
||||
target := "web/src/pages/inbox/PortfolioIntelligenceInbox.test.tsx"
|
||||
if err := os.MkdirAll(filepath.Join(dir, filepath.Dir(target)), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for i := 0; i < 40; i++ {
|
||||
if err := os.WriteFile(filepath.Join(dir, fmt.Sprintf("a-%02d.txt", i)), []byte(strings.Repeat("filler line\n", 4)), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, filepath.FromSlash(target)), []byte(strings.Repeat("original test line\n", 8)), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
git("add", ".")
|
||||
git("commit", "-qm", "fixture")
|
||||
detail, visited, verdictCalls := runUISkipIn(t, uiReviewerSource(true), map[string]string{"implement": target}, dir)
|
||||
capture := detail.Steps[0].FileChanges
|
||||
if capture == nil || len(capture.Files) != 1 || capture.Files[0].Path != target || !capture.Files[0].NoPatch {
|
||||
t.Fatalf("over-budget capture did not list the edited file: %+v", capture)
|
||||
}
|
||||
assertModelRan(t, detail, visited, verdictCalls)
|
||||
if len(detail.Warnings) == 0 {
|
||||
t.Fatal("partial capture produced no run-level warning")
|
||||
}
|
||||
}
|
||||
|
||||
// TestUISkipOptOut proves auto_skip=false makes a `skipped` stage run its model
|
||||
// even on complete, empty evidence.
|
||||
func TestUISkipOptOut(t *testing.T) {
|
||||
source := uiReviewerSource(true)
|
||||
at := strings.LastIndex(source, "timeout=1h\n")
|
||||
source = source[:at] + "timeout=1h\nauto_skip=false\n" + source[at+len("timeout=1h\n"):]
|
||||
detail, visited, verdictCalls := runUISkip(t, source, nil)
|
||||
assertModelRan(t, detail, visited, verdictCalls)
|
||||
}
|
||||
|
||||
// TestUISkipNeedsDeclaredEdge proves the guard never invents a skip for a stage
|
||||
// whose definition declares no `skipped` route: it always executes.
|
||||
// whose definition declares no `skipped` route: it always executes, even on
|
||||
// complete, empty evidence.
|
||||
func TestUISkipNeedsDeclaredEdge(t *testing.T) {
|
||||
detail, visited, verdictCalls := runUISkip(t, uiReviewerSource(false), map[string]string{"implement": "internal/server/fake.go"})
|
||||
detail, visited, verdictCalls := runUISkip(t, uiReviewerSource(false), nil)
|
||||
if !executed(visited, "ui_reviewer") {
|
||||
t.Fatalf("ui_reviewer without a skipped edge did not execute; visited=%v", visited)
|
||||
}
|
||||
@@ -205,33 +283,37 @@ func TestUISkipNeedsDeclaredEdge(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUISurfacePathClassification(t *testing.T) {
|
||||
cases := []struct {
|
||||
path string
|
||||
want bool
|
||||
}{
|
||||
{"android/app/src/main/kotlin/Main.kt", true},
|
||||
{"android/README.md", true},
|
||||
{"internal/tui/view.go", true},
|
||||
{"internal/tui", true},
|
||||
{"web/index.html", true},
|
||||
{"web/app.css", true},
|
||||
{"web/app.js", true},
|
||||
{"web/app.ts", true},
|
||||
{"web/app.jsx", true},
|
||||
{"web/app.tsx", true},
|
||||
{"web/Index.HTML", true},
|
||||
{"internal/server/fake.go", false},
|
||||
{"androidx/foo.go", false},
|
||||
{"cmd/pipelines/main.go", false},
|
||||
{"docs/readme.md", false},
|
||||
{"README.md", false},
|
||||
// TestUISkipPersistedEvidence proves the resume/retry seed: a stored server
|
||||
// fallback step neither adds nor breaks evidence, while a stored visit with no
|
||||
// capture (a human decision, a crash, a historical row) or a partial one makes
|
||||
// the evidence incomplete.
|
||||
func TestUISkipPersistedEvidence(t *testing.T) {
|
||||
complete := &protocol.StageFileChanges{Status: "complete", Files: []protocol.FileChange{}}
|
||||
reason := skipReasonLine()
|
||||
serverSkip := protocol.RunStep{Stage: "ui", Outcome: "skipped", Verdict: &protocol.StageVerdict{Reason: reason, ReasonSource: protocol.VerdictReasonFallback}}
|
||||
s := &runState{}
|
||||
s.recordPersistedStep(protocol.RunStep{Stage: "implement", FileChanges: complete})
|
||||
s.recordPersistedStep(serverSkip)
|
||||
if !autoSkipEligible(nil, s) {
|
||||
t.Fatalf("complete evidence plus a server skip is not eligible: %+v", s)
|
||||
}
|
||||
for _, tc := range cases {
|
||||
if got := uiSurfacePath(tc.path); got != tc.want {
|
||||
t.Errorf("uiSurfacePath(%q) = %v, want %v", tc.path, got, tc.want)
|
||||
legacy := serverSkip
|
||||
legacy.Verdict = &protocol.StageVerdict{Reason: "no UI surface changed (no recorded file changes)", ReasonSource: protocol.VerdictReasonFallback}
|
||||
for name, step := range map[string]protocol.RunStep{
|
||||
"no capture": {Stage: "gate", Outcome: "approve"},
|
||||
"partial": {Stage: "implement", FileChanges: &protocol.StageFileChanges{Status: "partial", Files: []protocol.FileChange{}}},
|
||||
"unavailable": {Stage: "implement", FileChanges: &protocol.StageFileChanges{Status: "unavailable"}},
|
||||
"legacy skip row": legacy,
|
||||
} {
|
||||
s := &runState{}
|
||||
s.recordPersistedStep(step)
|
||||
if autoSkipEligible(nil, s) {
|
||||
t.Errorf("%s: incomplete evidence is eligible for the fallback", name)
|
||||
}
|
||||
}
|
||||
if autoSkipEligible(map[string]string{"auto_skip": "false"}, &runState{}) {
|
||||
t.Error("auto_skip=false did not opt out")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUISurfaceArtifactClassification(t *testing.T) {
|
||||
|
||||
@@ -3,36 +3,35 @@ package server
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
// UI-surface classification is the single source of truth for the deterministic
|
||||
// pre-check that lets a stage declaring a `skipped` route short-circuit when the
|
||||
// run changed no rendered surface. The path/extension lists live only here; the
|
||||
// skip guard, its reason and the resumed-run seed all read them.
|
||||
// The server skip fallback lets a stage that declares a `skipped` route
|
||||
// short-circuit, without a model call, only when the run's evidence proves there
|
||||
// is nothing to review: every visit so far recorded a complete file-change
|
||||
// capture, none of them recorded any change, and no visit captured a rendered
|
||||
// (image) artifact. Anything else runs the stage's model, which may still choose
|
||||
// `skipped` itself.
|
||||
//
|
||||
// The rule deliberately classifies no path as "not UI". A path/extension list
|
||||
// encodes one repository's layout (Go TUIs, Flutter .dart, Kotlin, SwiftUI,
|
||||
// templates, strings files and config can all be rendered surface), and absent
|
||||
// or partial evidence must never be read as "no edits". A wrong run costs one
|
||||
// model call; a wrong skip ships an unreviewed UI change.
|
||||
|
||||
// maxRetainedChangedPaths bounds how many recorded changed paths a runState
|
||||
// retains for the skip reason. The full count is kept separately, so the reason
|
||||
// stays informative without unbounded memory.
|
||||
// retains as a sample. The full count is kept separately.
|
||||
const maxRetainedChangedPaths = 32
|
||||
|
||||
// uiSurfaceDirs are the workspace prefixes whose changes are a user-facing
|
||||
// surface. Matching is on a path boundary, so "androidx/" is not "android/".
|
||||
var uiSurfaceDirs = []string{"android", "internal/tui"}
|
||||
// serverSkipReasonPrefix starts every server fallback skip reason, so the
|
||||
// verdict says plainly that no model ran, and so a resumed run recognises its
|
||||
// own earlier fallback steps (which have no capture of their own).
|
||||
const serverSkipReasonPrefix = "Server fallback skip (no model run):"
|
||||
|
||||
// presentationExtensions are the rendered presentation file types a change can
|
||||
// touch without living under a surface directory.
|
||||
var presentationExtensions = map[string]bool{
|
||||
".html": true,
|
||||
".css": true,
|
||||
".js": true,
|
||||
".ts": true,
|
||||
".jsx": true,
|
||||
".tsx": true,
|
||||
}
|
||||
// autoSkipConfig is the stage config that opts a stage out of the fallback.
|
||||
const autoSkipConfig = "auto_skip"
|
||||
|
||||
// renderedArtifactExtensions are the image types a captured artifact may carry
|
||||
// when its content type was not recorded or sniffed as an image.
|
||||
@@ -44,22 +43,6 @@ var renderedArtifactExtensions = map[string]bool{
|
||||
".webp": true,
|
||||
}
|
||||
|
||||
// uiSurfacePath reports whether a run-relative, forward-slash workspace path
|
||||
// changed a user-facing surface: a file under android/ or internal/tui/, or a
|
||||
// file with a presentation extension. It is O(len(path)) with no I/O.
|
||||
func uiSurfacePath(p string) bool {
|
||||
clean := strings.TrimPrefix(path.Clean(filepath.ToSlash(p)), "/")
|
||||
if clean == "" || clean == "." {
|
||||
return false
|
||||
}
|
||||
for _, dir := range uiSurfaceDirs {
|
||||
if clean == dir || strings.HasPrefix(clean, dir+"/") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return presentationExtensions[strings.ToLower(path.Ext(clean))]
|
||||
}
|
||||
|
||||
// uiSurfaceArtifact reports whether a captured artifact is a rendered surface:
|
||||
// an image content type, or an image file extension when no type was recorded.
|
||||
func uiSurfaceArtifact(a protocol.StageArtifact) bool {
|
||||
@@ -69,19 +52,20 @@ func uiSurfaceArtifact(a protocol.StageArtifact) bool {
|
||||
return renderedArtifactExtensions[strings.ToLower(path.Ext(a.Name))]
|
||||
}
|
||||
|
||||
// recordChanges folds one completed step's observed changes into the run's
|
||||
// UI-surface decision. It retains a bounded sample of paths; the count is
|
||||
// unbounded so the reason can state the true total. It is O(changes) with no I/O.
|
||||
// recordChanges folds one executed visit's observed changes into the run's
|
||||
// skip evidence. A nil, partial or unavailable capture marks the run's
|
||||
// evidence incomplete for the rest of the run. It retains a bounded sample of
|
||||
// paths; the count is unbounded. It is O(changes) with no I/O.
|
||||
func (s *runState) recordChanges(changes *protocol.StageFileChanges, artifacts []protocol.StageArtifact) {
|
||||
if changes == nil || changes.Status != "complete" {
|
||||
s.captureIncomplete++
|
||||
}
|
||||
if changes != nil {
|
||||
for _, file := range changes.Files {
|
||||
s.changedCount++
|
||||
if len(s.changedPaths) < maxRetainedChangedPaths {
|
||||
s.changedPaths = append(s.changedPaths, file.Path)
|
||||
}
|
||||
if !s.uiSurface && uiSurfacePath(file.Path) {
|
||||
s.uiSurface = true
|
||||
}
|
||||
// The full captured set is a separate, unbounded dedupe of the actual
|
||||
// evidence, unlike the bounded changedPaths sample above.
|
||||
if file.Path == "" || s.capturedSeen[file.Path] {
|
||||
@@ -101,16 +85,38 @@ func (s *runState) recordChanges(changes *protocol.StageFileChanges, artifacts [
|
||||
}
|
||||
}
|
||||
|
||||
// skipReasonLine states, as one bounded line, why the guard skipped a stage: no
|
||||
// recorded change touched a UI surface. It names the retained checked paths.
|
||||
func skipReasonLine(state *runState) string {
|
||||
if state.changedCount == 0 {
|
||||
return "no UI surface changed (no recorded file changes)"
|
||||
// recordPersistedStep seeds the skip evidence from a stored step when a run is
|
||||
// resumed or retried. A server fallback skip executed nothing and carries no
|
||||
// capture, so it neither adds evidence nor makes it incomplete; every other
|
||||
// stored visit (including a human decision, during which the workspace was not
|
||||
// observed) is folded in like a live visit.
|
||||
func (s *runState) recordPersistedStep(step protocol.RunStep) {
|
||||
if serverSkipStep(step) {
|
||||
return
|
||||
}
|
||||
line := fmt.Sprintf("no UI surface changed in %d recorded file change(s): %s", state.changedCount, strings.Join(state.changedPaths, ", "))
|
||||
if extra := state.changedCount - len(state.changedPaths); extra > 0 {
|
||||
line = fmt.Sprintf("%s (+%d more)", line, extra)
|
||||
s.recordChanges(step.FileChanges, step.Artifacts)
|
||||
}
|
||||
|
||||
// serverSkipStep reports whether a stored step is a server fallback skip.
|
||||
func serverSkipStep(step protocol.RunStep) bool {
|
||||
return step.Outcome == "skipped" && step.FileChanges == nil && step.Verdict != nil &&
|
||||
step.Verdict.ReasonSource == protocol.VerdictReasonFallback &&
|
||||
strings.HasPrefix(step.Verdict.Reason, serverSkipReasonPrefix)
|
||||
}
|
||||
|
||||
// autoSkipEligible reports whether the server may skip a stage declaring a
|
||||
// `skipped` route: the stage has not opted out, every visit so far recorded a
|
||||
// complete capture, no change was recorded and no rendered artifact captured.
|
||||
func autoSkipEligible(configs map[string]string, state *runState) bool {
|
||||
if configs[autoSkipConfig] == "false" {
|
||||
return false
|
||||
}
|
||||
return state.captureIncomplete == 0 && state.changedCount == 0 && !state.uiSurface
|
||||
}
|
||||
|
||||
// skipReasonLine states, as one bounded line, why the server skipped a stage.
|
||||
func skipReasonLine() string {
|
||||
line := fmt.Sprintf("%s every earlier visit's file-change capture was complete and recorded no file changes or screenshots.", serverSkipReasonPrefix)
|
||||
runes := []rune(line)
|
||||
if len(runes) > protocol.VerdictReasonCap {
|
||||
return string(runes[:protocol.VerdictReasonCap])
|
||||
|
||||
Reference in New Issue
Block a user