Skip to content

[Control Plane] Add tests for nodes_rest.go lifecycle — lease/ack/claim/shutdown #395

@santoshkumarradha

Description

@santoshkumarradha

Test coverage: handlers/nodes_rest.go — lease, ack, claim, shutdown

Scope

New test files (one per handler, following existing nodes_rest_test.go naming):

  • nodes_rest_status_test.goNodeStatusLeaseHandler
  • nodes_rest_actions_test.goNodeActionAckHandler + ClaimActionsHandler
  • nodes_rest_shutdown_test.goNodeShutdownHandler

Test cases

Lease:

Case Setup Assertion
default TTL when configured TTL ≤ 0 handler with zero TTL response lease_seconds == 300
versioned lookup path used when payload includes version body with version=v2 storage stub GetAgentVersion called (not GetAgent)
pending-approval agent only renews heartbeat stored lifecycle pending_approval, payload phase ready heartbeat touched, no status-manager update, 200
invalid health score rejected health_score=-1 or 101 400
unsupported phase rejected phase=booting 400 with phase error
happy path updates status and heartbeat healthy agent, phase=ready, health_score=99 status manager normalized active/ready, heartbeat updated, lease fields returned

Action ack + claim:

  • ack normalizes execution status before logging (completed / CANCELLED aliases)
  • ack returns 404 for unknown node
  • ack default TTL used when zero
  • claim defaults max_items to 1 when body has 0
  • claim defaults next_poll_after to 5 when wait_seconds ≤ 0
  • claim renews heartbeat for known node

Shutdown:

  • versioned lookup uses GetAgentVersion
  • unknown node returns 404
  • malformed optional JSON does not fail the request
  • success path updates heartbeat and forgets presence
  • success path pushes offline status update with reason=agent shutdown
  • response is 202 with lease_seconds=0

Fixture / mock boundary

httptest plus a package-local stub storage extending the existing reasonerTestStorage pattern, plus a fake status/presence manager. No gomock needed.

Acceptance criteria

  • All three test files added
  • go test ./control-plane/internal/handlers/... -run NodesRest passes

Size: L · Difficulty: intermediate · Language: Go


Part of epic #387parent tracker.


How to work on this

Setup

git clone https://github.com/Agent-Field/agentfield.git
cd agentfield
make install        # installs Go, Python (via uv), and Node deps
make build          # optional — builds the control plane binary

Run the baseline test suite

Before you change anything, run the tests for the language this issue targets so you know what "green" looks like:

  • Go control plane: cd control-plane && go test ./... -count=1
  • Go SDK: cd sdk/go && go test ./... -count=1
  • Python SDK: cd sdk/python && uv run pytest -q
  • TypeScript SDK: cd sdk/typescript && bun test

Package coverage baseline (so you can show improvement in the PR):

  • go test -cover ./control-plane/internal/...
  • uv run pytest --cov=agentfield sdk/python/tests
  • bun test --coverage (TypeScript)

Using Claude Code or another AI coding agent

This repo has a CLAUDE.md at the root that Claude Code and compatible agents will read automatically. A working flow:

  1. cd into the repo and run claude (or open in your IDE's agent).
  2. Paste this issue URL and say: "Please implement this issue, following every acceptance-criteria checkbox. Do not change source files — only add tests under the target path in the issue. When you're done, run the test suite command from the issue and paste the result."
  3. Let the agent read existing tests in the same package as a model for style / fixtures — we point to them in the issue.
  4. Run make lint before opening the PR.

See the AI-Assisted Contributions guide for testing requirements. Tag your PR with ai-assisted if you used an AI agent.

Claiming this issue

Comment I'd like to work on this and a maintainer will assign it to you. If you're new to open source, issues labelled good first issue or first-timers-only are hand-picked for a smooth first PR — we'll guide you if you get stuck.

Opening the PR

  • Branch name: tests/<short-description> or refactor/<short-description>
  • Link this issue in the PR description with Closes #<number>
  • Paste the before/after test output or coverage delta in the PR body
  • Keep the diff to the scope in this issue — no drive-by cleanups

Help & questions

  • Comment on this issue — we monitor all assigned issues.
  • Join the community Discord: run /gsd-join-discord or check the README for the invite.
  • For repo-wide questions, open a discussion with the help tag.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-friendlyWell-documented task suitable for AI-assisted developmentarea:control-planeControl plane server functionalityhelp wantedExtra attention is neededtest-coveragePart of the drive to 95%+ test coveragetestsUnit test improvements and coverage

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions