98713e55f5
The committer staged only the implementer's self-declared changed_files, so an incomplete declaration silently left part of the approved change uncommitted. The runner already records the run's real changed paths by comparing the working tree around each step; publish that set to the committer. - runState gains an unbounded, deduplicated, first-seen-ordered captured path accumulator (capturedPaths/capturedSeen), distinct from the bounded changedPaths sample used only by the UI-surface skip reason. - recordChanges folds each captured FileChange path into it in the existing single pass, so no second walk and no new I/O. - publishServerChangedFiles writes the set into the input memory value as input.server_changed_files, called before memoryInput so the binding always resolves (an empty list when nothing was captured) and only stages that select it receive it. rebuildRunState rebuilds it from persisted completed steps, so a resumed run hands the committer the same evidence. - Tests prove the committer receives the captured set distinct from and additive to the implementer's declared changed_files, that an omitted path is still present, and that the field is an empty list when nothing was captured. - control.md and orchestration.md document the reserved field and instruct the committer to select input.server_changed_files alongside the declared changed_files and stage their union. Commands run: go build ./...; go vet ./...; go test -count=1 ./internal/server/... ./internal/stage/...; go test -count=1 ./internal/author/...; go test -count=1 -run TestCommitterReceivesServerCapturedChangedPaths ./internal/server/. All passed. go.mod/go.sum unchanged.
120 lines
4.1 KiB
Go
120 lines
4.1 KiB
Go
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.
|
|
|
|
// 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.
|
|
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"}
|
|
|
|
// 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,
|
|
}
|
|
|
|
// renderedArtifactExtensions are the image types a captured artifact may carry
|
|
// when its content type was not recorded or sniffed as an image.
|
|
var renderedArtifactExtensions = map[string]bool{
|
|
".png": true,
|
|
".jpg": true,
|
|
".jpeg": true,
|
|
".gif": true,
|
|
".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 {
|
|
if strings.HasPrefix(strings.ToLower(a.ContentType), "image/") {
|
|
return true
|
|
}
|
|
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.
|
|
func (s *runState) recordChanges(changes *protocol.StageFileChanges, artifacts []protocol.StageArtifact) {
|
|
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] {
|
|
continue
|
|
}
|
|
if s.capturedSeen == nil {
|
|
s.capturedSeen = map[string]bool{}
|
|
}
|
|
s.capturedSeen[file.Path] = true
|
|
s.capturedPaths = append(s.capturedPaths, file.Path)
|
|
}
|
|
}
|
|
for _, artifact := range artifacts {
|
|
if !s.uiSurface && uiSurfaceArtifact(artifact) {
|
|
s.uiSurface = true
|
|
}
|
|
}
|
|
}
|
|
|
|
// 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)"
|
|
}
|
|
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)
|
|
}
|
|
runes := []rune(line)
|
|
if len(runes) > protocol.VerdictReasonCap {
|
|
return string(runes[:protocol.VerdictReasonCap])
|
|
}
|
|
return line
|
|
}
|