@@ -14,6 +14,7 @@ import (
1414 mf "github.com/coder/agentapi/lib/msgfmt"
1515 "github.com/coder/agentapi/lib/termexec"
1616 "github.com/coder/agentapi/x/acpio"
17+ "github.com/coder/quartz"
1718)
1819
1920type SetupProcessConfig struct {
@@ -64,6 +65,7 @@ func SetupProcess(ctx context.Context, config SetupProcessConfig) (*termexec.Pro
6465type SetupACPConfig struct {
6566 Program string
6667 ProgramArgs []string
68+ Clock quartz.Clock
6769}
6870
6971// SetupACPResult contains the result of setting up an ACP process.
@@ -76,6 +78,10 @@ type SetupACPResult struct {
7678func SetupACP (ctx context.Context , config SetupACPConfig ) (* SetupACPResult , error ) {
7779 logger := logctx .From (ctx )
7880
81+ if config .Clock == nil {
82+ config .Clock = quartz .NewReal ()
83+ }
84+
7985 args := config .ProgramArgs
8086 logger .Info (fmt .Sprintf ("Running (ACP): %s %s" , config .Program , strings .Join (args , " " )))
8187
@@ -111,7 +117,7 @@ func SetupACP(ctx context.Context, config SetupACPConfig) (*SetupACPResult, erro
111117 _ = stdin .Close ()
112118 _ = stdout .Close ()
113119 // Force kill after timeout
114- time .AfterFunc (5 * time .Second , func () {
120+ config . Clock .AfterFunc (5 * time .Second , func () {
115121 _ = cmd .Process .Kill ()
116122 })
117123 case <- done :
0 commit comments