MCPcopy Create free account
hub / github.com/Facets-cloud/flow / stubBGCommand

Function stubBGCommand

internal/app/background_test.go:103–128  ·  view source on GitHub ↗

stubBGCommand swaps claude.BGCommandRunner with a recorder that dispatches on args: `agents` returns *agentsJSON (mutable so a test can change registry state mid-run), `--resume` returns resumeBanner, the rest are spawns (returning spawnBanner). Both banners default to bgBanner; tests set resumeBann

(t *testing.T, agentsJSON *string)

Source from the content-addressed store, hash-verified

101// bgBanner; tests set resumeBanner to simulate the new id --bg mints on
102// resume.
103func stubBGCommand(t *testing.T, agentsJSON *string) *bgCalls {
104 t.Helper()
105 c := &bgCalls{spawnBanner: bgBanner, resumeBanner: bgBanner}
106 old := claude.BGCommandRunner
107 claude.BGCommandRunner = func(workDir string, args []string) ([]byte, error) {
108 if len(args) >= 1 && args[0] == "agents" {
109 c.agents++
110 return []byte(*agentsJSON), nil
111 }
112 for _, a := range args {
113 if a == "--resume" {
114 c.resume++
115 c.lastResume = args
116 if c.onResume != nil {
117 c.onResume()
118 }
119 return []byte(c.resumeBanner), nil
120 }
121 }
122 c.spawn++
123 c.lastSpawn = args
124 return []byte(c.spawnBanner), nil
125 }
126 t.Cleanup(func() { claude.BGCommandRunner = old })
127 return c
128}
129
130// TestCmdDoBackgroundFreshSpawn: $FLOW_TERM=bg flow do <task> spawns a bg
131// agent, captures the REAL full session id (not a pre-allocated phantom),

Calls

no outgoing calls

Tested by

no test coverage detected