Skip to content

feat(orchestrator): add external agent container to test topology#20

Open
erenaslandev wants to merge 1 commit into
mainfrom
DT-803
Open

feat(orchestrator): add external agent container to test topology#20
erenaslandev wants to merge 1 commit into
mainfrom
DT-803

Conversation

@erenaslandev

@erenaslandev erenaslandev commented Jun 18, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

Release Notes

  • New Features

    • Test cases now support configuring optional external agent containers
    • Customize agent container image, environment variables, and commands
    • Control whether agent containers mount shared data volumes
    • Reserved "agent" service name to prevent naming conflicts with endpoints
  • Tests

    • Added tests validating agent container rendering and configuration
    • Added tests ensuring endpoint names cannot use the reserved agent service name

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Adds an optional agent: block to test case YAML configuration. A new AgentConfig struct and TestCase.Agent field define the container's image, env, command, and shared-data mount flag. writeCompose conditionally renders a bench-agent service in Docker Compose output, and the reserved name "agent" is blocked from endpoint use.

Changes

Agent Container Support

Layer / File(s) Summary
AgentConfig schema, UsesAgent helper, and reserved-name validation
internal/config/case.go
TestCase gains an Agent *AgentConfig field. New AgentConfig struct defines image, env, command, and mounts_shared_data. UsesAgent() helper returns whether an agent is configured. Validate() adds "agent" to the reserved service-name set.
Compose template and writeCompose agent rendering
internal/orchestrator/docker.go
Compose YAML template adds a conditional bench-agent service depending on subject startup, with optional shared-data:/data mount, root user switch, and injected command/env. composeVars struct gains five agent fields. writeCompose populates them via UsesAgent(), escaping $ characters for Compose interpolation safety.
Compose render and validation tests
internal/orchestrator/compose_render_test.go
TestComposeRendersAgent verifies the agent service appears with correct image/env/command/depends_on when configured, and is absent when not. TestValidateRejectsAgentNameAsEndpoint confirms validation rejects an endpoint named "agent".

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • VirtualMetric/PipeBench#5: Also modifies TestCase endpoint-name validation in internal/config/case.go to prevent reserved/generated service-name collisions, the same mechanism this PR extends to reserve "agent".

Poem

🐇 A hop, a skip, a YAML parse,
A new agent jumps into the sparse—
bench-agent waits for subject's health,
Then mounts its /data shelf.
No endpoint dares steal "agent"'s name,
The rabbit validates, all the same! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding support for an external agent container to the test topology orchestration system.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch DT-803

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/config/case.go (1)

542-644: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add validation for Agent.Image when Agent is configured.

When Agent is set but Agent.Image is empty, validation passes but compose rendering will fail at runtime with an unclear error. Following the pattern used for Endpoint validation (lines 593-594), the Agent should validate that Image is required.

🛡️ Proposed fix to add Agent validation

Add this validation block after the endpoint validation (after line 609):

 		epNames[e.Name] = struct{}{}
 	}
+	// Agent: require image when agent block is present.
+	if tc.Agent != nil && tc.Agent.Image == "" {
+		return fmt.Errorf("case %q: agent missing required `image`", tc.Name)
+	}
 	// Kafka types require the broker block + a generator producing in kafka mode.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/config/case.go` around lines 542 - 644, The Validate method on
TestCase does not validate that Agent.Image is required when Agent is
configured, which causes compose rendering to fail at runtime with unclear
errors. Add a validation check after the endpoint validation block that follows
the same pattern used for endpoint validation: check if tc.Agent is not nil and
if so, verify that tc.Agent.Image is not empty, returning a descriptive error
message if validation fails.
🧹 Nitpick comments (1)
internal/orchestrator/compose_render_test.go (1)

738-810: ⚡ Quick win

Consider adding test coverage for MountsSharedData and "$" escaping.

The test verifies core agent rendering but has two coverage gaps:

  1. MountsSharedData: Line 784's comment acknowledges MountsSharedData is untested. When true, it should render the shared-data:/data volume mount and user: "0:0".

  2. "$" escaping: The feature escapes $ to $$ in command/env (lines 1932-1938 in docker.go) to prevent Docker Compose interpolation, but this behavior isn't verified.

📋 Suggested test additions

Add assertions after line 782 to test MountsSharedData:

// Test with MountsSharedData enabled
tcWithMount := &config.TestCase{
	Name:     "agent-with-mount",
	Type:     "correctness",
	Duration: "60s",
	Receiver: config.ReceiverConfig{Mode: "tcp", Listen: ":9001"},
	Agent: &config.AgentConfig{
		Image:            "vmetric/director-enterprise:2.0.0",
		MountsSharedData: true,
	},
}
// ... writeCompose and assertions ...
mustContain(t, out, "shared-data:/data")
mustContain(t, out, "user: \"0:0\"")

Add a test for "$" escaping:

// Test command with $ characters (should be escaped to $$)
tcWithDollar := &config.TestCase{
	Name:     "agent-dollar-escape",
	Type:     "correctness",
	Duration: "60s",
	Receiver: config.ReceiverConfig{Mode: "tcp", Listen: ":9001"},
	Agent: &config.AgentConfig{
		Image:   "test:1.0",
		Command: []string{"sh", "-c", "echo $VAR $(date)"},
		Env:     map[string]string{"KEY": "$VALUE"},
	},
}
// ... writeCompose and assertions ...
mustContain(t, out, "$$VAR")
mustContain(t, out, "$$(date)")
mustContain(t, out, "$$VALUE")
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/orchestrator/compose_render_test.go` around lines 738 - 810, The
TestComposeRendersAgent test lacks coverage for two features: the
MountsSharedData configuration and the "$" escaping behavior in commands/env.
Add two new test cases within this test function to cover these gaps. First,
create a test case where Agent.MountsSharedData is set to true and verify the
output contains "shared-data:/data" and "user: \"0:0\"" using writeCompose and
mustContain assertions similar to existing checks. Second, create another test
case with an Agent.Command containing dollar sign characters like "echo $VAR
$(date)" and verify the composed output escapes them to "$$VAR" and "$$(date)",
ensuring the "$" escaping behavior mentioned in docker.go is properly tested.
Place these additional test cases after the initial agent rendering checks and
before the "no-agent" test case.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@internal/config/case.go`:
- Around line 542-644: The Validate method on TestCase does not validate that
Agent.Image is required when Agent is configured, which causes compose rendering
to fail at runtime with unclear errors. Add a validation check after the
endpoint validation block that follows the same pattern used for endpoint
validation: check if tc.Agent is not nil and if so, verify that tc.Agent.Image
is not empty, returning a descriptive error message if validation fails.

---

Nitpick comments:
In `@internal/orchestrator/compose_render_test.go`:
- Around line 738-810: The TestComposeRendersAgent test lacks coverage for two
features: the MountsSharedData configuration and the "$" escaping behavior in
commands/env. Add two new test cases within this test function to cover these
gaps. First, create a test case where Agent.MountsSharedData is set to true and
verify the output contains "shared-data:/data" and "user: \"0:0\"" using
writeCompose and mustContain assertions similar to existing checks. Second,
create another test case with an Agent.Command containing dollar sign characters
like "echo $VAR $(date)" and verify the composed output escapes them to "$$VAR"
and "$$(date)", ensuring the "$" escaping behavior mentioned in docker.go is
properly tested. Place these additional test cases after the initial agent
rendering checks and before the "no-agent" test case.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f13208d8-9150-4553-b975-3ee9d8ad9390

📥 Commits

Reviewing files that changed from the base of the PR and between d0d0c90 and 59fc38f.

📒 Files selected for processing (3)
  • internal/config/case.go
  • internal/orchestrator/compose_render_test.go
  • internal/orchestrator/docker.go

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant