diff --git a/.windsurf/workflows/review.md b/.windsurf/workflows/review.md new file mode 100644 index 0000000..6595c4a --- /dev/null +++ b/.windsurf/workflows/review.md @@ -0,0 +1,22 @@ +--- +auto_execution_mode: 0 +description: Review code changes for bugs, security issues, and improvements +--- +You are a senior software engineer performing a thorough code review to identify potential bugs. + +Your task is to find all potential bugs and code improvements in the code changes. Focus on: +1. Logic errors and incorrect behavior +2. Edge cases that aren't handled +3. Null/undefined reference issues +4. Race conditions or concurrency issues +5. Security vulnerabilities +6. Improper resource management or resource leaks +7. API contract violations +8. Incorrect caching behavior, including cache staleness issues, cache key-related bugs, incorrect cache invalidation, and ineffective caching +9. Violations of existing code patterns or conventions + +Make sure to: +1. If exploring the codebase, call multiple tools in parallel for increased efficiency. Do not spend too much time exploring. +2. If you find any pre-existing bugs in the code, you should also report those since it's important for us to maintain general code quality for the user. +3. Do NOT report issues that are speculative or low-confidence. All your conclusions should be based on a complete understanding of the codebase. +4. Remember that if you were given a specific git commit, it may not be checked out and local code states may be different. \ No newline at end of file diff --git a/cli/tests/logs_debug_test.zig b/cli/tests/logs_debug_test.zig new file mode 100644 index 0000000..79b5f9e --- /dev/null +++ b/cli/tests/logs_debug_test.zig @@ -0,0 +1,124 @@ +const std = @import("std"); +const testing = std.testing; +const src = @import("src"); + +// Test that logs command module can be imported and has expected structure +test "logs command module structure" { + // Verify the logs module is exported from commands + _ = src.commands.logs; + + // Test basic string operations used in logs command + const test_target = "abc123"; + try testing.expect(test_target.len > 0); + try testing.expect(std.ascii.isAlphanumeric(test_target[0])); +} + +// Test that debug command module can be imported and has expected structure +test "debug command module structure" { + // Verify the debug module is exported from commands + _ = src.commands.debug; + + // Test basic string operations used in debug command + const test_target = "task-123"; + try testing.expect(test_target.len > 0); + try testing.expect(std.mem.indexOf(u8, test_target, "-") != null); +} + +// Test logs command argument parsing patterns +test "logs command argument parsing" { + const test_cases = [_]struct { + args: []const []const u8, + expect_target: []const u8, + expect_follow: bool, + expect_tail: ?usize, + }{ + .{ .args = &[_][]const u8{"abc123"}, .expect_target = "abc123", .expect_follow = false, .expect_tail = null }, + .{ .args = &[_][]const u8{ "abc123", "-f" }, .expect_target = "abc123", .expect_follow = true, .expect_tail = null }, + .{ .args = &[_][]const u8{ "abc123", "--follow" }, .expect_target = "abc123", .expect_follow = true, .expect_tail = null }, + .{ .args = &[_][]const u8{ "abc123", "-n", "100" }, .expect_target = "abc123", .expect_follow = false, .expect_tail = 100 }, + .{ .args = &[_][]const u8{ "abc123", "--tail", "50" }, .expect_target = "abc123", .expect_follow = false, .expect_tail = 50 }, + }; + + for (test_cases) |case| { + // Verify target is first argument + try testing.expect(std.mem.eql(u8, case.args[0], case.expect_target)); + + // Check for follow flag + var has_follow = false; + for (case.args) |arg| { + if (std.mem.eql(u8, arg, "-f") or std.mem.eql(u8, arg, "--follow")) { + has_follow = true; + break; + } + } + try testing.expect(has_follow == case.expect_follow); + } +} + +// Test debug command argument parsing patterns +test "debug command argument parsing" { + const test_cases = [_]struct { + args: []const []const u8, + expect_target: []const u8, + expect_interactive: bool, + expect_gdb: bool, + }{ + .{ .args = &[_][]const u8{"abc123"}, .expect_target = "abc123", .expect_interactive = false, .expect_gdb = false }, + .{ .args = &[_][]const u8{ "abc123", "-i" }, .expect_target = "abc123", .expect_interactive = true, .expect_gdb = false }, + .{ .args = &[_][]const u8{ "abc123", "--interactive" }, .expect_target = "abc123", .expect_interactive = true, .expect_gdb = false }, + .{ .args = &[_][]const u8{ "abc123", "--gdb" }, .expect_target = "abc123", .expect_interactive = false, .expect_gdb = true }, + .{ .args = &[_][]const u8{ "abc123", "--pdb" }, .expect_target = "abc123", .expect_interactive = false, .expect_gdb = false }, + }; + + for (test_cases) |case| { + // Verify target is first argument + try testing.expect(std.mem.eql(u8, case.args[0], case.expect_target)); + + // Check for interactive flag + var has_interactive = false; + for (case.args) |arg| { + if (std.mem.eql(u8, arg, "-i") or std.mem.eql(u8, arg, "--interactive")) { + has_interactive = true; + break; + } + } + try testing.expect(has_interactive == case.expect_interactive); + + // Check for gdb flag + var has_gdb = false; + for (case.args) |arg| { + if (std.mem.eql(u8, arg, "--gdb")) { + has_gdb = true; + break; + } + } + try testing.expect(has_gdb == case.expect_gdb); + } +} + +// Test target ID validation patterns (common to both logs and debug) +test "target ID validation for logs and debug" { + const valid_targets = [_][]const u8{ + "abc123", + "task-123", + "run-abc-456", + "abc123def4567890", // long hex-like + }; + + for (valid_targets) |target| { + // All valid targets should be non-empty + try testing.expect(target.len > 0); + + // Should not contain spaces + try testing.expect(std.mem.indexOf(u8, target, " ") == null); + } +} + +// Test that commands.zig properly exports logs and debug modules +test "commands module exports" { + // Verify logs module is exported + _ = src.commands.logs; + + // Verify debug module is exported + _ = src.commands.debug; +} diff --git a/cli/tests/main_test.zig b/cli/tests/main_test.zig index e17756a..7d54fce 100644 --- a/cli/tests/main_test.zig +++ b/cli/tests/main_test.zig @@ -16,7 +16,7 @@ test "CLI basic functionality" { test "CLI command validation" { // Test command validation logic - const commands = [_][]const u8{ "init", "sync", "queue", "q", "status", "monitor", "cancel", "prune", "watch", "validate" }; + const commands = [_][]const u8{ "init", "sync", "queue", "q", "status", "monitor", "cancel", "prune", "watch", "validate", "logs", "debug" }; for (commands) |cmd| { try testing.expect(cmd.len > 0);