MCPcopy Index your code
hub / github.com/coder/agentapi / setup

Function setup

e2e/echo_test.go:329–432  ·  view source on GitHub ↗
(ctx context.Context, t testing.TB, p *params, waitForStable bool)

Source from the content-addressed store, hash-verified

327}
328
329func setup(ctx context.Context, t testing.TB, p *params, waitForStable bool) ([]ScriptEntry, *agentapisdk.Client, func()) {
330 t.Helper()
331
332 if p == nil {
333 p = &params{}
334 }
335 if p.cmdFn == nil {
336 if p.stateFile != "" {
337 p.cmdFn = stateCmdFn(p.stateFile, p.initialPrompt)
338 } else {
339 p.cmdFn = defaultCmdFn
340 }
341 }
342
343 scriptFilePath := p.scriptFilePath
344 if scriptFilePath == "" {
345 scriptFilePath = filepath.Join("testdata", filepath.Base(t.Name())+".json")
346 }
347 data, err := os.ReadFile(scriptFilePath)
348 require.NoError(t, err, "Failed to read test script file: %s", scriptFilePath)
349
350 var script []ScriptEntry
351 err = json.Unmarshal(data, &script)
352 require.NoError(t, err, "Failed to unmarshal script from %s", scriptFilePath)
353
354 binaryPath := os.Getenv("AGENTAPI_BINARY_PATH")
355 if binaryPath == "" {
356 cwd, err := os.Getwd()
357 require.NoError(t, err, "Failed to get current working directory")
358 binaryPath = filepath.Join(cwd, "..", "out", "agentapi")
359 t.Logf("Building binary at %s", binaryPath)
360 buildCmd := exec.CommandContext(ctx, "go", "build", "-o", binaryPath, ".")
361 buildCmd.Dir = filepath.Join(cwd, "..")
362 t.Logf("run: %s", buildCmd.String())
363 require.NoError(t, buildCmd.Run(), "Failed to build binary")
364 }
365
366 serverPort, err := getFreePort()
367 require.NoError(t, err, "Failed to get free port for server")
368
369 cwd, err := os.Getwd()
370 require.NoError(t, err, "Failed to get current working directory")
371
372 bin, args := p.cmdFn(ctx, t, serverPort, binaryPath, cwd, scriptFilePath)
373 t.Logf("Running command: %s %s", bin, strings.Join(args, " "))
374 cmd := exec.CommandContext(ctx, bin, args...)
375
376 // Capture output for debugging
377 stdout, err := cmd.StdoutPipe()
378 require.NoError(t, err, "Failed to create stdout pipe")
379
380 stderr, err := cmd.StderrPipe()
381 require.NoError(t, err, "Failed to create stderr pipe")
382
383 // Start process
384 err = cmd.Start()
385 require.NoError(t, err, "Failed to start agentapi server")
386

Callers 1

TestE2EFunction · 0.85

Calls 10

stateCmdFnFunction · 0.85
getFreePortFunction · 0.85
logOutputFunction · 0.85
waitForServerFunction · 0.85
waitAgentAPIStableFunction · 0.85
AddMethod · 0.80
SignalMethod · 0.80
WaitMethod · 0.80
StringMethod · 0.65
StartMethod · 0.65

Tested by

no test coverage detected