Skip to content

Tear down CLI-owned e2e agent when its suite ends#1204

Merged
jhivandb merged 1 commit into
wso2:mainfrom
jhivandb:cli-e2e-shared-agent-teardown
Jun 29, 2026
Merged

Tear down CLI-owned e2e agent when its suite ends#1204
jhivandb merged 1 commit into
wso2:mainfrom
jhivandb:cli-e2e-shared-agent-teardown

Conversation

@jhivandb

@jhivandb jhivandb commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Purpose

The amctl CLI platform-agent e2e suite provisions a dedicated agent (e2e-cli-it-helpdesk) in its own project (e2e-cli-shared) once on parallel process 1. Until now nothing ever deleted it: it was intentionally excluded from the stale-resource sweep (which only reaps e2e-test-*), so the agent and project leaked indefinitely. This wires up an always-on teardown so the CLI suite cleans up the resources it fully owns when it ends.

For:

Goals

  • Always delete the CLI-owned agent + project when the CLI platform-agent suite finishes.
  • Add a durable backstop for runs that die before teardown (hard kill / panic).

Approach

  • Add amctl.WithSharedTeardown(func()) to the CLI harness — the symmetric counterpart to WithSharedSetup. It runs exactly once on parallel process 1 inside the harness's existing single SynchronizedAfterSuite, after every process has finished, before the built binary is dropped.
  • Add testsetup.CleanupCLILifecycleAgent(...), a best-effort teardown that deletes the agent (existing DeleteAgentBestEffort) then its project (deleteProjectBestEffort, with 409-retry for the async agent cascade). It deletes by the well-known constant names rather than the provisioned handle, so cleanup still runs even if provisioning only partially succeeded. Failures are logged, never fatal.
  • Wire the teardown into the CLI platform-agent suite registration.
  • Broaden the stale sweep (CleanupStaleE2EResources) to also reap e2e-cli-* projects older than the 1h cutoff — the backstop for SynchronizedAfterSuite being skipped (e.g. kill -9). Introduces E2ECLIProjectPrefix and derives E2ECLIProjectName from it.

Why it's safe to always delete: e2e-cli-it-helpdesk / e2e-cli-shared are owned solely by this CLI suite. The HTTP observability suites read a different shared agent (e2e-it-helpdesk in e2e-test-shared); a grep confirms nothing else references the CLI-owned names.

Coverage by exit type:

  • Normal pass/fail → SynchronizedAfterSuite deletes it.
  • Single Ctrl-C → Ginkgo runs AfterSuite gracefully.
  • kill -9 / second Ctrl-C / panic → next run's stale sweep reaps it.

The CLI agent now rebuilds on every run; in the ephemeral CI environment the build happens regardless, so there is no added cost.

User stories

N/A — test-infrastructure change, no user-facing behavior.

Release note

N/A — internal e2e test harness only.

Documentation

N/A — no user-facing docs affected (updated in-code doc comments only).

Training

N/A

Certification

N/A

Marketing

N/A

Automation tests

  • Unit: N/A — this is e2e test-harness lifecycle code; not unit-testable in isolation.
  • Integration: This change is e2e harness wiring. Validated locally with go build ./..., go vet, and gofmt over the e2e module (all clean). The teardown path exercises only when the CLI platform-agent suite runs against a live environment.

Security checks

  • Did you add any new external dependencies? No.
  • Did you implement any cryptographic functions / handle secrets? No.
  • Did you introduce any new APIs or change authentication/authorization? No.

Samples

N/A

Related PRs

N/A

Migrations

N/A — no DB migrations.

Test environment

Standard e2e environment (ephemeral). No special setup.

Learning

N/A

Summary by CodeRabbit

  • Bug Fixes
    • Improved end-to-end cleanup so leftover CLI-related resources are removed more reliably after test runs.
    • Added a safer teardown path for shared test environments to reduce stale resources and conflicts.
    • Expanded automatic cleanup to catch additional leftover CLI projects from interrupted runs.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Shared teardown support was added to the amctl e2e suite, and the CLI agent platform suite now uses it to remove the CLI lifecycle agent and project. Stale cleanup also now matches e2e-cli-* projects.

Changes

CLI e2e shared teardown and cleanup

Layer / File(s) Summary
Suite teardown hook
test/e2e/framework/amctl/suite.go
The amctl suite stores an optional process-1 teardown callback and invokes it during synchronized after-suite cleanup.
CLI cleanup helper
test/e2e/framework/shared_agent.go, test/e2e/testsetup/setup_shared_agents.go
The CLI project prefix and lifecycle cleanup helper are updated to delete the agent and project with retry handling for project deletion.
Suite wiring and stale cleanup
test/e2e/tests/cli/agentplatform/suite_test.go, test/e2e/testsetup/cleanup.go
The CLI agent platform suite registers the shared teardown helper, and stale cleanup now includes CLI projects in the eligible prefix check.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • wso2/agent-manager#1146: Extends the same CLI e2e suite harness and lifecycle-agent cleanup flow with related amctl suite behavior.
  • wso2/agent-manager#1191: Adds the complementary shared setup path for the same CLI lifecycle agent and project resources used here.

Suggested reviewers

  • hanzjk

Poem

A rabbit hops by, tail all bright,
tidying CLI burrows at night.
Shared teardown runs, clean and neat,
and stale little projects retreat. 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: cleaning up the CLI-owned e2e agent when the suite ends.
Description check ✅ Passed The description follows the template closely and covers the main sections, with only minor gaps in the explicit security-check yes/no formatting.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@jhivandb jhivandb force-pushed the cli-e2e-shared-agent-teardown branch from a9fe1c5 to 94a96a2 Compare June 26, 2026 10:17

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (1)
test/e2e/testsetup/setup_shared_agents.go (1)

213-240: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consolidate duplicated project-deletion retry logic.

deleteProjectBestEffort reimplements the same 5-attempt / 409-retry / 204|404-success loop that already exists inline in CleanupStaleE2EResources (test/e2e/testsetup/cleanup.go lines 84-107). Having two copies risks them drifting (e.g. attempt count or backoff). Consider having the stale-sweep call this helper.

🤖 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 `@test/e2e/testsetup/setup_shared_agents.go` around lines 213 - 240,
`deleteProjectBestEffort` duplicates the same project-delete retry flow already
used by `CleanupStaleE2EResources`; consolidate the logic so there is one source
of truth. Update the stale-sweep path to call `deleteProjectBestEffort` for
project cleanup, and keep the 5-attempt / 409-retry / 204|404-success behavior
in that helper so it can be reused consistently.
🤖 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.

Nitpick comments:
In `@test/e2e/testsetup/setup_shared_agents.go`:
- Around line 213-240: `deleteProjectBestEffort` duplicates the same
project-delete retry flow already used by `CleanupStaleE2EResources`;
consolidate the logic so there is one source of truth. Update the stale-sweep
path to call `deleteProjectBestEffort` for project cleanup, and keep the
5-attempt / 409-retry / 204|404-success behavior in that helper so it can be
reused consistently.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 06614805-69a8-4dbb-bc1f-e1162d84ddcd

📥 Commits

Reviewing files that changed from the base of the PR and between c27d1b0 and 94a96a2.

📒 Files selected for processing (5)
  • test/e2e/framework/amctl/suite.go
  • test/e2e/framework/shared_agent.go
  • test/e2e/tests/cli/agentplatform/suite_test.go
  • test/e2e/testsetup/cleanup.go
  • test/e2e/testsetup/setup_shared_agents.go

@jhivandb jhivandb merged commit 1dfb99d into wso2:main Jun 29, 2026
2 checks passed
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.

2 participants