Acme-Claude-Shell
view release on metacpan or search on metacpan
t/01-tools.t view on Meta::CPAN
#!/usr/bin/env perl
use 5.020;
use strict;
use warnings;
use Test::More;
use File::Temp qw(tempdir tempfile);
use File::Spec;
use Cwd qw(getcwd);
# Test the Tools module functionality
use_ok('Acme::Claude::Shell::Tools', 'shell_tools');
# Create a mock session object for testing
package MockSession;
sub new {
my ($class, %args) = @_;
return bless {
working_dir => $args{working_dir} // '.',
colorful => $args{colorful} // 0,
safe_mode => $args{safe_mode} // 1,
_history => [],
_spinner => undef,
}, $class;
}
sub working_dir { $_[0]->{working_dir} }
sub colorful { $_[0]->{colorful} }
sub safe_mode { $_[0]->{safe_mode} }
sub _history { $_[0]->{_history} }
sub _spinner {
my $self = shift;
if (@_) { $self->{_spinner} = shift }
return $self->{_spinner};
}
sub can {
my ($self, $method) = @_;
return $self->SUPER::can($method) || ($method eq '_spinner' ? 1 : 0);
}
package main;
# Create temp directory for tests
my $tempdir = tempdir(CLEANUP => 1);
# Create some test files
my $test_file = File::Spec->catfile($tempdir, 'test.txt');
open my $fh, '>', $test_file or die "Cannot create test file: $!";
print $fh "Line 1\nLine 2\nLine 3\nLine 4\nLine 5\n";
close $fh;
my $test_file2 = File::Spec->catfile($tempdir, 'test.pm');
open $fh, '>', $test_file2 or die "Cannot create test file: $!";
print $fh "package Test;\nsub foo { 1 }\n1;\n";
close $fh;
# Create subdirectory with files
my $subdir = File::Spec->catdir($tempdir, 'subdir');
mkdir $subdir or die "Cannot create subdir: $!";
my $sub_file = File::Spec->catfile($subdir, 'nested.txt');
open $fh, '>', $sub_file or die "Cannot create nested file: $!";
print $fh "Nested content\n";
close $fh;
# Create mock session
my $session = MockSession->new(
working_dir => $tempdir,
colorful => 0,
safe_mode => 1,
);
# Get tools
my $tools = shell_tools($session);
ok($tools, 'shell_tools returns tools');
is(ref($tools), 'ARRAY', 'shell_tools returns arrayref');
ok(scalar(@$tools) >= 5, 'At least 5 tools defined');
# Check tool names
my %tool_names = map { $_->name => $_ } @$tools;
ok(exists $tool_names{execute_command}, 'execute_command tool exists');
ok(exists $tool_names{read_file}, 'read_file tool exists');
ok(exists $tool_names{list_directory}, 'list_directory tool exists');
ok(exists $tool_names{search_files}, 'search_files tool exists');
ok(exists $tool_names{get_system_info}, 'get_system_info tool exists');
ok(exists $tool_names{get_working_directory}, 'get_working_directory tool exists');
# Test tool has proper structure
for my $tool (@$tools) {
ok($tool->name, "Tool has name: " . $tool->name);
ok($tool->description, "Tool " . $tool->name . " has description");
ok($tool->input_schema, "Tool " . $tool->name . " has input_schema");
}
# Test get_working_directory tool execution
subtest 'get_working_directory tool' => sub {
plan tests => 3;
require IO::Async::Loop;
( run in 0.517 second using v1.01-cache-2.11-cpan-ceb78f64989 )