Skip to content

Add convenience builders for agents + some tests - #672

Merged
jrvb-rl merged 3 commits into
mainfrom
jrvb-agent-builders
Dec 8, 2025
Merged

Add convenience builders for agents + some tests#672
jrvb-rl merged 3 commits into
mainfrom
jrvb-agent-builders

Conversation

@jrvb-rl

@jrvb-rl jrvb-rl commented Dec 5, 2025

Copy link
Copy Markdown
Contributor

CodeAnt-AI Description

Create agents from NPM, Pip, Git, or storage objects

What Changed

  • Added four new AgentOps helper methods to create agents directly from NPM packages, Pip packages, Git repositories, or storage objects; each method builds the expected source payload and calls the existing create flow.
  • Each builder accepts the source identifier (package_name, repository, or object_id) plus optional version/registry and agent_setup, and includes those fields in the created agent's source when provided.
  • Added unit tests that verify each builder calls the agent creation API with the correct source structure and optional fields.

Impact

✅ Shorter agent registration from NPM/Pip/Git/storage
✅ Fewer payload construction errors when creating agents
✅ Faster developer iteration thanks to unit tests for builders

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

@codeant-ai

codeant-ai Bot commented Dec 5, 2025

Copy link
Copy Markdown
Contributor

CodeAnt AI is reviewing your PR.


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@jrvb-rl
jrvb-rl requested a review from dines-rl December 5, 2025 23:10
@codeant-ai codeant-ai Bot added the size:L This PR changes 100-499 lines, ignoring generated files label Dec 5, 2025
@jrvb-rl

jrvb-rl commented Dec 5, 2025

Copy link
Copy Markdown
Contributor Author

One change we probably need - I wasn't sure where the best place was for these tests, so the new 'sdk' directory is just a placeholder. LMK if there is a better spot?

@codeant-ai

codeant-ai Bot commented Dec 5, 2025

Copy link
Copy Markdown
Contributor

Nitpicks 🔍

🔒 No security issues identified
⚡ Recommended areas for review

  • Type safety
    Several helper functions construct configuration objects using any (e.g. npmConfig, pipConfig, gitConfig, objectConfig). This loses compile-time guarantees and can allow invalid shapes to be sent to the API. Replace any with concrete types from the API types or with Record<string, unknown> and assert/cast to the expected union variant where needed.

  • API shape assumptions
    Helpers assume the server expects source: { type: 'npm'|'pip'|'git'|'object', npm|pip|git|object: {...} }. Confirm these property names and nested keys match generated API types; otherwise the constructed payload may be rejected. Validate keys and naming against the autogenerated Runloop API types.

  • Mocking correctness
    The test mocks the Agent module and then calls new Agent(...) inside mockResolvedValue. Since the class is auto-mocked by jest.mock(...), constructing a new instance of the mocked class may not behave like a real Agent instance and can lead to brittle tests or confusing runtime behavior. Prefer returning a plain mock object or a proper jest-mocked instance to ensure deterministic behavior.

let mockAgentData: AgentView;

beforeEach(() => {
// Create mock client

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.

Suggestion: Tests reuse module-level mocks across examples; not clearing mock state between runs can lead to flaky tests (leftover call counts or mock implementations). Call jest.clearAllMocks() at the start of beforeEach to reset mock call history and implementations. [possible bug]

Severity Level: Critical 🚨

Suggested change
// Create mock client
jest.clearAllMocks();
Why it matters? ⭐

Good catch. While mockClient's member mocks are recreated in beforeEach, the module-level mock (Agent.create) retains call history across tests unless cleared. Adding jest.clearAllMocks() at the top of beforeEach prevents stale call counts or previous mock implementations from leaking between tests and makes assertions like toHaveBeenCalledWith deterministic. This is a small, safe improvement to test hygiene.

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/sdk/agent-ops.test.ts
**Line:** 14:14
**Comment:**
	*Possible Bug: Tests reuse module-level mocks across examples; not clearing mock state between runs can lead to flaky tests (leftover call counts or mock implementations). Call `jest.clearAllMocks()` at the start of `beforeEach` to reset mock call history and implementations.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.

Comment thread tests/sdk/agent-ops.test.ts Outdated
};

// Mock Agent.create to return a mock Agent instance
(Agent.create as jest.Mock).mockResolvedValue(new Agent(mockClient, 'agent-123'));

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.

Suggestion: Mocking Agent.create by resolving to new Agent(...) can fail when the Agent export is mocked by Jest (the mocked constructor may not behave like the real class or may not be a constructor), and casting to jest.Mock is brittle. Create an explicit lightweight mock instance (plain object typed as Agent) and use jest.spyOn(Agent, 'create') to stub the static method; this avoids calling the mocked constructor and ensures the stub is a proper mock function. [possible bug]

Severity Level: Critical 🚨

Suggested change
(Agent.create as jest.Mock).mockResolvedValue(new Agent(mockClient, 'agent-123'));
const mockAgentInstance = { id: 'agent-123', getInfo: jest.fn() } as unknown as Agent;
jest.spyOn(Agent as any, 'create').mockResolvedValue(mockAgentInstance);
Why it matters? ⭐

The suggestion is valid. The test file calls jest.mock('../../src/sdk/agent') at module scope, so Agent is a mocked export; calling new Agent(...) will invoke the mocked constructor which may not behave like the real class and can lead to brittle tests or surprises. Returning a plain, explicitly-shaped object and spying on Agent.create avoids invoking the mocked constructor and makes the test intent clearer and more robust. This change fixes a real fragility in the test setup rather than being purely cosmetic.

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** tests/sdk/agent-ops.test.ts
**Line:** 40:40
**Comment:**
	*Possible Bug: Mocking `Agent.create` by resolving to `new Agent(...)` can fail when the `Agent` export is mocked by Jest (the mocked constructor may not behave like the real class or may not be a constructor), and casting to `jest.Mock` is brittle. Create an explicit lightweight mock instance (plain object typed as `Agent`) and use `jest.spyOn(Agent, 'create')` to stub the static method; this avoids calling the mocked constructor and ensures the stub is a proper mock function.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.

@codeant-ai

codeant-ai Bot commented Dec 5, 2025

Copy link
Copy Markdown
Contributor

CodeAnt AI finished reviewing your PR.

Comment thread src/sdk.ts
*
* @param {object} params - Parameters for creating the agent.
* @param {string} params.package_name - NPM package name.
* @param {string} [params.npm_version] - NPM version constraint.

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.

examples would be good here

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.

for all of these

Comment thread src/sdk.ts
* Create an agent from a storage object.
*
* @param {object} params - Parameters for creating the agent.
* @param {string} params.object_id - Storage object ID.

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.

string | storage object would be good here

Comment thread src/sdk.ts
*
* @param {object} params - Parameters for creating the agent.
* @param {string} params.package_name - Pip package name.
* @param {string} [params.pip_version] - Pip version constraint.

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.

these examples also with the examples so people can see what would go here

@codeant-ai

codeant-ai Bot commented Dec 8, 2025

Copy link
Copy Markdown
Contributor

CodeAnt AI is running Incremental review


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@github-actions

github-actions Bot commented Dec 8, 2025

Copy link
Copy Markdown

⚠️ Object Smoke Tests & Coverage Report

Test Results

✅ All smoke tests passed

Coverage Results

Metric Coverage Required Status
Functions 99.22% 100%
Lines 87.11% - ℹ️
Branches 47.66% - ℹ️
Statements 85.12% - ℹ️

Coverage Requirement: 100% function coverage (all public methods must be called in smoke tests)

⚠️ Some object methods are not covered in smoke tests. Please add tests that call all public methods.

View detailed coverage report

Coverage reports are available in the workflow artifacts. Lines/branches/statements coverage is tracked but not required to be 100%.

📋 View workflow run

@jrvb-rl
jrvb-rl merged commit 042865b into main Dec 8, 2025
9 checks passed
@jrvb-rl
jrvb-rl deleted the jrvb-agent-builders branch December 8, 2025 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants