Skip to content

feat: extract agent startup into reusable NewAgent for test framework#6956

Open
dejanzele wants to merge 1 commit intomainfrom
feat/runner-programmatic-api
Open

feat: extract agent startup into reusable NewAgent for test framework#6956
dejanzele wants to merge 1 commit intomainfrom
feat/runner-programmatic-api

Conversation

@dejanzele
Copy link
Copy Markdown
Contributor

Pull request description

Extracts runner/service/runnerClient creation from main.go into runner.NewAgent() so the control plane test framework can spin up real agents against a test gRPC server without duplicating startup logic.

Checklist (choose whats happened)

  • breaking change! (describe)
  • tested locally
  • tested on cluster
  • added new dependencies
  • updated the docs
  • added a test

Breaking changes

Changes

Fixes

@dejanzele dejanzele requested a review from a team as a code owner January 12, 2026 17:59
…tests

Signed-off-by: Dejan Zele Pejchev <pejcev.dejan@gmail.com>
@dejanzele dejanzele force-pushed the feat/runner-programmatic-api branch from f184f8e to 03170c5 Compare January 12, 2026 18:05
@olensmar
Copy link
Copy Markdown
Member

olensmar commented Mar 3, 2026

@greptile

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 3, 2026

Greptile Summary

This PR extracts agent startup logic from cmd/api-server/main.go into a reusable runner.NewAgent() factory, enabling the control-plane test framework to spin up real agents against a test gRPC server without code duplication. The refactoring is well-structured and functionally safe for the primary use case (main.go).

Key changes:

  • pkg/runner/start.go (new): Introduces NewAgent(), AgentConfig, AgentCredentials, AgentIdentity, and helper factories
  • pkg/runner/agent.go: Exports NewAgentLoop (was newAgentLoop) for external testability
  • Call sites updated: service.go, agent_conn_test.go updated to use exported name
  • cmd/api-server/main.go: Replaces inlined construction with runner2.NewAgent(AgentConfig{...})

Design note: The AgentCredentials struct used by the test framework path lacks OrgSlug and EnvSlug fields that are present in ProContext and used in execution records. Test agents will record executions with empty slug fields (falling back to IDs).

Confidence Score: 4/5

  • Safe to merge. The primary use case (main.go path) is functionally equivalent to the original code with no new risks. The test framework path works but has missing slug fields in execution records.
  • The refactoring is sound: main.go behavior is unchanged, call sites are properly updated, and the new external API works for its intended purpose. The score is 4/5 rather than 5/5 because the AgentCredentials path used by test frameworks omits OrgSlug and EnvSlug fields that affect execution record metadata, though the system includes fallbacks to use IDs instead. This is a design choice worth documenting but not a blocker.
  • pkg/runner/start.go — Consider whether AgentCredentials should expose slug fields or be clearly documented as intentionally omitting them.

Last reviewed commit: 03170c5

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread pkg/runner/start.go
Comment on lines +59 to +67
// AgentCredentials contains the credentials needed to authenticate with the control plane.
type AgentCredentials struct {
APIKey string
OrgID string
EnvID string
URL string
SkipVerify bool
TLSInsecure bool
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AgentCredentials struct lacks OrgSlug and EnvSlug fields. When buildProContext() constructs a ProContext from AgentCredentials, these fields remain empty strings. However, they are used downstream in execution records — see agent.go lines 355-356:

OrganizationSlug: a.proContext.OrgSlug,
EnvironmentSlug:  a.proContext.GetEnvSlug(environmentId),

When test frameworks use the AgentCredentials path, execution records will have empty slug fields (falling back to IDs via runner.go's fallback logic).

Consider:

  1. Adding OrgSlug and EnvSlug to AgentCredentials so test agents can populate them, or
  2. Documenting explicitly that these fields are intentionally omitted for the test scenario

This affects observability and any slug-based tracking in execution records.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants