Add initial project files and configurations for clawd_code
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import "package:test/test.dart";
|
||||
import "package:clawd_code/src/tools/bash_tool.dart";
|
||||
|
||||
|
||||
void main() {
|
||||
late BashTool tool;
|
||||
|
||||
setUp(() {
|
||||
tool = BashTool();
|
||||
});
|
||||
|
||||
group("BashTool", () {
|
||||
test("runs a simple echo command", () async {
|
||||
final result = await tool.execute({"command": "echo hello"});
|
||||
expect(result.trim(), equals("hello"));
|
||||
});
|
||||
|
||||
test("captures multi-line output", () async {
|
||||
final result = await tool.execute({"command": "printf 'line1\nline2\n'"});
|
||||
expect(result, contains("line1"));
|
||||
expect(result, contains("line2"));
|
||||
});
|
||||
|
||||
test("includes exit code on failure", () async {
|
||||
final result = await tool.execute({"command": "exit 1"});
|
||||
expect(result, contains("Exit code: 1"));
|
||||
});
|
||||
|
||||
test("throws on empty command", () async {
|
||||
expect(
|
||||
() => tool.execute({"command": " "}),
|
||||
throwsA(isA<ArgumentError>()),
|
||||
);
|
||||
});
|
||||
|
||||
test("captures stderr output", () async {
|
||||
final result = await tool.execute({"command": "echo errormsg >&2"});
|
||||
expect(result, contains("errormsg"));
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import "dart:io";
|
||||
import "package:test/test.dart";
|
||||
import "package:clawd_code/src/tools/file_read_tool.dart";
|
||||
|
||||
|
||||
void main() {
|
||||
late FileReadTool tool;
|
||||
late Directory tempDir;
|
||||
|
||||
setUp(() async {
|
||||
tool = FileReadTool();
|
||||
tempDir = await Directory.systemTemp.createTemp("file_read_test_");
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
await tempDir.delete(recursive: true);
|
||||
});
|
||||
|
||||
group("FileReadTool", () {
|
||||
test("reads a known file with line numbers", () async {
|
||||
final f = File("${tempDir.path}/sample.txt");
|
||||
await f.writeAsString("hello\nworld\n");
|
||||
|
||||
final result = await tool.execute({"file_path": f.path});
|
||||
expect(result, contains("hello"));
|
||||
expect(result, contains("world"));
|
||||
// line numbers present
|
||||
expect(result, contains("1"));
|
||||
});
|
||||
|
||||
test("returns error for missing file", () async {
|
||||
final result = await tool.execute({"file_path": "/does/not/exist.txt"});
|
||||
expect(result.toLowerCase(), contains("error"));
|
||||
});
|
||||
|
||||
test("respects offset and limit", () async {
|
||||
final f = File("${tempDir.path}/multiline.txt");
|
||||
await f.writeAsString("line1\nline2\nline3\nline4\nline5\n");
|
||||
|
||||
final result = await tool.execute({
|
||||
"file_path": f.path,
|
||||
"offset": 1,
|
||||
"limit": 2,
|
||||
});
|
||||
|
||||
expect(result, contains("line2"));
|
||||
expect(result, contains("line3"));
|
||||
expect(result, isNot(contains("line1")));
|
||||
expect(result, isNot(contains("line4")));
|
||||
});
|
||||
|
||||
test("empty file returns empty marker", () async {
|
||||
final f = File("${tempDir.path}/empty.txt");
|
||||
await f.writeAsString("");
|
||||
|
||||
final result = await tool.execute({"file_path": f.path});
|
||||
expect(result, contains("1\t"));
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user