Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.
JavaScript agent-orchestrationagentic-workflowai-agentsai-codingclaude-codecode-reviewcodebuddycodexcoding-agentscursordeveloper-toolshuman-on-the-loopllmmcpmulti-agentsdlcself-hostedsopworkflow-automationworkflow-engine
refactor(runner): split collectTaskOutputs into focused helpers (#432)
fx-kurumi3150273efa77
diff --git a/internal/runner/outputs.go b/internal/runner/outputs.goindex 976ec231..93358377 100644--- a/internal/runner/outputs.go+++ b/internal/runner/outputs.go@@ -92,7 +92,18 @@ func collectTaskOutputs(workspace string, inv *domain.RunnerInvocation) *domain.if inv.RecoverOutputs {out.Recovered = recoverOutputFiles(workspace, inv.OutputFiles)}- for _, rel := range inv.OutputFiles {+ out.Files, out.TooLarge = readOutputFiles(workspace, inv.OutputFiles)+ out.Patches = collectPatchInventories(workspace, patchInventoryDirs(inv))+ frontend, evidence := domain.DetectFrontendProject(workspace)+ out.Facts = &domain.RunnerWorkspaceFacts{Frontend: frontend, FrontendEvidence: evidence}+ return out+}++// readOutputFiles reads every safe, regular output file within the upload+// limit. Oversized files are reported by path instead; both results stay nil+// when nothing qualifies.+func readOutputFiles(workspace string, rels []string) (files map[string]string, tooLarge []string) {+ for _, rel := range rels {if !domain.SafeWorkspaceRelPath(rel) {continue}@@ -102,38 +113,51 @@ func collectTaskOutputs(workspace string, inv *domain.RunnerInvocation) *domain.continue}if info.Size() > maxArtifactUploadBytes {- out.TooLarge = append(out.TooLarge, rel)+ tooLarge = append(tooLarge, rel)continue}data, err := os.ReadFile(full)if err != nil {continue}- if out.Files == nil {- out.Files = map[string]string{}+ if files == nil {+ files = map[string]string{}}- out.Files[rel] = string(data)+ files[rel] = string(data)}- dirs := []string{""}- if repositories := invocationRepositoryContexts(inv); len(repositories) > 0 {- dirs = dirs[:0]- for _, repository := range repositories {- dirs = append(dirs, filepath.ToSlash(safeRunnerRepoDir(repository.WorkspaceDir)))- }+ return files, tooLarge+}++// patchInventoryDirs lists the workspace-relative checkout directories whose+// patch inventory is reported: the workspace root without repositories,+// otherwise each repository's checkout directory.+func patchInventoryDirs(inv *domain.RunnerInvocation) []string {+ repositories := invocationRepositoryContexts(inv)+ if len(repositories) == 0 {+ return []string{""}+ }+ dirs := make([]string, 0, len(repositories))+ for _, repository := range repositories {+ dirs = append(dirs, filepath.ToSlash(safeRunnerRepoDir(repository.WorkspaceDir)))}+ return dirs+}++// collectPatchInventories maps each directory with a non-empty patch+// inventory to it; the map stays nil when no directory has changes.+func collectPatchInventories(workspace string, dirs []string) map[string]string {+ var patches map[string]stringfor _, dir := range dirs {patch, err := gitwork.PatchInventory(filepath.Join(workspace, filepath.FromSlash(dir)))if err != nil || len(patch) == 0 {continue}- if out.Patches == nil {- out.Patches = map[string]string{}+ if patches == nil {+ patches = map[string]string{}}- out.Patches[dir] = string(patch)+ patches[dir] = string(patch)}- frontend, evidence := domain.DetectFrontendProject(workspace)- out.Facts = &domain.RunnerWorkspaceFacts{Frontend: frontend, FrontendEvidence: evidence}- return out+ return patches}// recoverOutputFiles moves a missing root-level output into place when thediff --git a/internal/runner/outputs_split_test.go b/internal/runner/outputs_split_test.gonew file mode 100644index 00000000..b17da77f--- /dev/null+++ b/internal/runner/outputs_split_test.go@@ -0,0 +1,90 @@+package runner++import (+ "os"+ "os/exec"+ "path/filepath"+ "reflect"+ "strings"+ "testing"++ "agentflow/internal/domain"+ "agentflow/internal/gitwork"+)++func TestPatchInventoryDirsDefaultsToWorkspaceRoot(t *testing.T) {+ for _, inv := range []*domain.RunnerInvocation{nil, {}} {+ if got := patchInventoryDirs(inv); !reflect.DeepEqual(got, []string{""}) {+ t.Fatalf("dirs = %q", got)+ }+ }+}++func TestPatchInventoryDirsListsRepositoryCheckouts(t *testing.T) {+ single := &domain.RunnerInvocation{Repository: &domain.RunnerRepository{Dir: "app"}}+ if got := patchInventoryDirs(single); !reflect.DeepEqual(got, []string{"app"}) {+ t.Fatalf("single repository dirs = %q", got)+ }+ multi := &domain.RunnerInvocation{Repositories: []domain.RunnerRepository{+ {Dir: "repos/api"}, {Dir: "../escape"}, {Dir: " "},+ }}+ if got := patchInventoryDirs(multi); !reflect.DeepEqual(got, []string{"repos/api", "", ""}) {+ t.Fatalf("multi repository dirs = %q", got)+ }+}++func TestReadOutputFilesKeepsNilWhenNothingQualifies(t *testing.T) {+ files, tooLarge := readOutputFiles(t.TempDir(), []string{"missing.md", "../outside.md"})+ if files != nil || tooLarge != nil {+ t.Fatalf("files = %v, tooLarge = %v", files, tooLarge)+ }+}++func TestCollectPatchInventoriesReportsOnlyChangedCheckouts(t *testing.T) {+ if _, err := exec.LookPath("git"); err != nil {+ t.Skip("git not installed")+ }+ workspace := t.TempDir()+ changed := filepath.Join(workspace, "changed")+ clean := filepath.Join(workspace, "clean")+ for _, dir := range []string{changed, clean} {+ initBaselineRepo(t, dir)+ }+ if err := os.WriteFile(filepath.Join(changed, "new.txt"), []byte("hello\n"), 0o644); err != nil {+ t.Fatal(err)+ }+ if err := os.Mkdir(filepath.Join(workspace, "plain"), 0o755); err != nil {+ t.Fatal(err)+ }+ patches := collectPatchInventories(workspace, []string{"changed", "clean", "plain"})+ if len(patches) != 1 || !strings.Contains(patches["changed"], "new.txt") {+ t.Fatalf("patches = %v", patches)+ }+ if got := collectPatchInventories(workspace, []string{"clean", "plain"}); got != nil {+ t.Fatalf("unchanged patches = %v", got)+ }+}++func initBaselineRepo(t *testing.T, dir string) {+ t.Helper()+ if err := os.MkdirAll(dir, 0o755); err != nil {+ t.Fatal(err)+ }+ if err := os.WriteFile(filepath.Join(dir, "base.txt"), []byte("base\n"), 0o644); err != nil {+ t.Fatal(err)+ }+ for _, args := range [][]string{+ {"init", "-q"},+ {"-c", "user.name=Test", "-c", "[email protected]", "add", "."},+ {"-c", "user.name=Test", "-c", "[email protected]", "commit", "-q", "-m", "base"},+ } {+ cmd := exec.Command("git", args...)+ cmd.Dir = dir+ if out, err := cmd.CombinedOutput(); err != nil {+ t.Fatalf("git %v: %v: %s", args, err, out)+ }+ }+ if err := gitwork.RecordBaseline(dir, ""); err != nil {+ t.Fatal(err)+ }+}