fetch_ml/cli/tests/logs_debug_test.zig
Jeremie Fraeys fb4c91f4c5
chore: add review workflow and test updates
- Add Windsurf review workflow configuration
- Add logs debug test for CLI
- Update main test file
2026-02-16 20:39:09 -05:00

124 lines
4.7 KiB
Zig

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;
}