Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions tests/Feature/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,48 @@
fclose($stdin);
fclose($stdout);
});

it('usingListModels returns the client instance', function () {
$client = new Client;

expect($client->usingListModels(fn () => []))->toBe($client);
});

it('usingListModels with null clears the handler', function () {
$client = new Client;
$client->usingListModels(fn () => []);
$client->usingListModels(null);

expect($client->usingListModels(null))->toBe($client);
});

it('listModels calls custom handler set via usingListModels', function () {
$client = new Client;
$client->usingListModels(fn () => [
[
'id' => 'my-model',
'name' => 'My Model',
'capabilities' => [
'supports' => ['vision' => false],
'limits' => ['max_context_window_tokens' => 8192],
],
],
]);

$models = $client->listModels();

expect($models)->toHaveCount(1)
->and($models[0])->toBeInstanceOf(\Revolution\Copilot\Types\ModelInfo::class)
->and($models[0]->id)->toBe('my-model')
->and($models[0]->name)->toBe('My Model');
});

it('listModels returns empty array when custom handler returns empty', function () {
$client = new Client;
$client->usingListModels(fn () => []);

$models = $client->listModels();

expect($models)->toBe([]);
});
});
35 changes: 32 additions & 3 deletions tests/Unit/Types/ResumeSessionConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
'disabledSkills' => ['skill1'],
'infiniteSessions' => new InfiniteSessionConfig(enabled: true, backgroundCompactionThreshold: 0.80, bufferExhaustionThreshold: 0.95),
'disableResume' => true,
'agent' => 'reviewer',
]);

expect($config->tools)->toBe([['name' => 'test_tool']])
Expand All @@ -54,7 +55,8 @@
->and($config->mcpServers)->toBe(['server1' => ['command' => 'npx']])
->and($config->customAgents)->toBe([['name' => 'agent1']])
->and($config->skillDirectories)->toBe(['/path/to/skills'])
->and($config->disabledSkills)->toBe(['skill1']);
->and($config->disabledSkills)->toBe(['skill1'])
->and($config->agent)->toBe('reviewer');
});

it('can be created from array with minimal fields', function () {
Expand All @@ -71,7 +73,8 @@
->and($config->mcpServers)->toBeNull()
->and($config->customAgents)->toBeNull()
->and($config->skillDirectories)->toBeNull()
->and($config->disabledSkills)->toBeNull();
->and($config->disabledSkills)->toBeNull()
->and($config->agent)->toBeNull();
});

it('preserves ProviderConfig instance when passed directly', function () {
Expand Down Expand Up @@ -118,6 +121,7 @@
disabledSkills: ['skill1'],
infiniteSessions: new InfiniteSessionConfig(enabled: true, backgroundCompactionThreshold: 0.80, bufferExhaustionThreshold: 0.95),
disableResume: false,
agent: 'reviewer',
);

$array = $config->toArray();
Expand All @@ -134,7 +138,8 @@
->and($array['mcpServers'])->toBe(['server1' => ['command' => 'test']])
->and($array['customAgents'])->toBe([['name' => 'agent1']])
->and($array['skillDirectories'])->toBe(['/skills'])
->and($array['disabledSkills'])->toBe(['skill1']);
->and($array['disabledSkills'])->toBe(['skill1'])
->and($array['agent'])->toBe('reviewer');
});

it('filters null values in toArray', function () {
Expand Down Expand Up @@ -211,4 +216,28 @@

expect($config->reasoningEffort)->toBe(ReasoningEffort::MEDIUM);
});

it('accepts agent parameter', function () {
$config = new ResumeSessionConfig(agent: 'reviewer');

expect($config->agent)->toBe('reviewer');
});

it('includes agent in toArray', function () {
$config = new ResumeSessionConfig(agent: 'code-review');

expect($config->toArray()['agent'])->toBe('code-review');
});

it('can be created from array with agent', function () {
$config = ResumeSessionConfig::fromArray(['agent' => 'my-agent']);

expect($config->agent)->toBe('my-agent');
});

it('excludes agent from toArray when null', function () {
$config = new ResumeSessionConfig;

expect($config->toArray())->not->toHaveKey('agent');
});
});
35 changes: 32 additions & 3 deletions tests/Unit/Types/SessionConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
'skillDirectories' => ['/path/to/skills'],
'disabledSkills' => ['skill1'],
'infiniteSessions' => ['enabled' => true, 'backgroundCompactionThreshold' => 0.80],
'agent' => 'reviewer',
]);

expect($config->sessionId)->toBe('test-session-id')
Expand All @@ -58,7 +59,8 @@
->and($config->disabledSkills)->toBe(['skill1'])
->and($config->infiniteSessions)->toBeInstanceOf(InfiniteSessionConfig::class)
->and($config->infiniteSessions->enabled)->toBeTrue()
->and($config->infiniteSessions->backgroundCompactionThreshold)->toBe(0.80);
->and($config->infiniteSessions->backgroundCompactionThreshold)->toBe(0.80)
->and($config->agent)->toBe('reviewer');
});

it('can be created from array with minimal fields', function () {
Expand All @@ -82,7 +84,8 @@
->and($config->customAgents)->toBeNull()
->and($config->skillDirectories)->toBeNull()
->and($config->disabledSkills)->toBeNull()
->and($config->infiniteSessions)->toBeNull();
->and($config->infiniteSessions)->toBeNull()
->and($config->agent)->toBeNull();
});

it('preserves SystemMessageConfig instance when passed directly', function () {
Expand Down Expand Up @@ -128,6 +131,7 @@
skillDirectories: ['/skills'],
disabledSkills: ['skill1'],
infiniteSessions: new InfiniteSessionConfig(enabled: false),
agent: 'reviewer',
);

$array = $config->toArray();
Expand All @@ -150,7 +154,8 @@
->and($array['customAgents'])->toBe([['name' => 'agent1']])
->and($array['skillDirectories'])->toBe(['/skills'])
->and($array['disabledSkills'])->toBe(['skill1'])
->and($array['infiniteSessions'])->toBe(['enabled' => false]);
->and($array['infiniteSessions'])->toBe(['enabled' => false])
->and($array['agent'])->toBe('reviewer');
});

it('filters null values in toArray', function () {
Expand Down Expand Up @@ -258,4 +263,28 @@

expect($config->reasoningEffort)->toBe(ReasoningEffort::MEDIUM);
});

it('accepts agent parameter', function () {
$config = new SessionConfig(agent: 'reviewer');

expect($config->agent)->toBe('reviewer');
});

it('includes agent in toArray', function () {
$config = new SessionConfig(agent: 'code-review');

expect($config->toArray()['agent'])->toBe('code-review');
});

it('can be created from array with agent', function () {
$config = SessionConfig::fromArray(['agent' => 'my-agent']);

expect($config->agent)->toBe('my-agent');
});

it('excludes agent from toArray when null', function () {
$config = new SessionConfig;

expect($config->toArray())->not->toHaveKey('agent');
});
});