Skip to content

Tests unit tests for agent sdk lifecycle (pr #174) #425

Open
clintjeff2 wants to merge 2 commits into
Bitcoindefi:mainfrom
clintjeff2:Tests-unit-tests-for-Agent-SDK-lifecycle-(PR-#174)-#176
Open

Tests unit tests for agent sdk lifecycle (pr #174) #425
clintjeff2 wants to merge 2 commits into
Bitcoindefi:mainfrom
clintjeff2:Tests-unit-tests-for-Agent-SDK-lifecycle-(PR-#174)-#176

Conversation

@clintjeff2

Copy link
Copy Markdown
Contributor

Motivation

  • Provide unit coverage for the Agent SDK lifecycle behaviors (start/stop/restart/task execution/heartbeat) that were added without tests.
  • Ensure runtime state transitions match the tested SDK contract so callers and health checks observe consistent statuses.

Description

  • Add new test suite lib/agent-runtime/__tests__/agent.test.ts covering start(), stop(), restart(), executeTask() behavior, heartbeat timing using fake timers, and the /api/agents/[id]/task 404 case.
  • Change Agent.start() to set status to running and Agent.stop() to set status to stopped, and make tasks return the agent to running after completion.
  • Make executeTask() throw when invoked on a stopped (or offline) agent.
  • Expand the AgentStatus union to include running and stopped, and update the valid-status lists in lib/agents/agent-health-store.ts and lib/agent-registry.ts.
  • Update app/api/agents/[id]/task/route.ts to return 404 { ok: false, error: "agent_not_found" } for unknown non-registry agent IDs while preserving runtime creation for generated bot-<n> ids.

Testing

  • Ran the new test file with Vitest: npm test -- lib/agent-runtime/__tests__/agent.test.ts and it passed (7 tests).
  • Ran the new route test together with the agent tests: npm test -- lib/agent-runtime/__tests__/agent.test.ts __tests__/api/agents/task-rate-limit.test.ts and both test files passed (8 tests total).
  • Ran the full test and typecheck flows; the overall test suite and tsc --noEmit surfaced unrelated repo issues (missing optional dev dependencies like lru-cache and @wagmi/connectors) and existing lint failures, which are outside the scope of this change.

Closes #176

@sonarqubecloud

Copy link
Copy Markdown

@clintjeff2

Copy link
Copy Markdown
Contributor Author

@leocagli, review and merge.

@clintjeff2

Copy link
Copy Markdown
Contributor Author

@leocagli, please review and merge.

1 similar comment
@clintjeff2

Copy link
Copy Markdown
Contributor Author

@leocagli, please review and merge.

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.

Tests: unit tests for Agent SDK lifecycle (PR #174)

1 participant