Add visible v1 diagnostics guardrails
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
const std = @import("std");
|
||||
|
||||
const diagnostics = @import("diagnostics.zig");
|
||||
const job = @import("job.zig");
|
||||
const lsp = @import("lsp.zig");
|
||||
const profile = @import("profile.zig");
|
||||
const repo = @import("repo.zig");
|
||||
@@ -107,6 +109,81 @@ test "adversarial: v1 smoke catches realistic profile and boundary failures" {
|
||||
try std.testing.expect(std.mem.indexOf(u8, status, "plugin_host=not_built") != null);
|
||||
}
|
||||
|
||||
test "regular: v1 smoke exposes bounded search, job, LSP, and save diagnostics" {
|
||||
var client = try tui.Client.init(allocator, .{ .width = 72, .height = 12 });
|
||||
defer client.deinit();
|
||||
|
||||
try client.handleTraceLine("open ready");
|
||||
var line_buf: [64]u8 = undefined;
|
||||
var i: usize = 0;
|
||||
while (i < diagnostics.max_search_rows + 3) : (i += 1) {
|
||||
const line = try std.fmt.bufPrint(&line_buf, "repo_file src/file{d}.zig=needle_{d}", .{ i, i });
|
||||
try client.handleTraceLine(line);
|
||||
}
|
||||
try client.handleTraceLine("search_text needle");
|
||||
{
|
||||
const frame = try client.render(allocator);
|
||||
defer allocator.free(frame);
|
||||
try std.testing.expect(std.mem.indexOf(u8, frame, "diagnostic:search_truncated") != null);
|
||||
}
|
||||
|
||||
const job_rows = try job.runRowsAlloc(allocator, std.Io.failing, ".", &.{"definitely-missing-mim-command"});
|
||||
defer freeRows(job_rows);
|
||||
try std.testing.expect(rowsContain(job_rows, "diagnostic:job_limits"));
|
||||
try std.testing.expect(rowsContain(job_rows, "job:status:spawn_error"));
|
||||
|
||||
const lsp_rows = try lsp.runDocumentSyncRowsAlloc(allocator, std.Io.failing, ".", &.{"definitely-missing-lsp"}, .{
|
||||
.uri = "file:///repo/src/main.zig",
|
||||
.language_id = "zig",
|
||||
.text = "pub fn main() void {}",
|
||||
});
|
||||
defer freeRows(lsp_rows);
|
||||
try std.testing.expect(rowsContain(lsp_rows, "diagnostic:lsp_limits"));
|
||||
try std.testing.expect(rowsContain(lsp_rows, "lsp:status:spawn_error"));
|
||||
}
|
||||
|
||||
test "adversarial: v1 smoke surfaces large or unsupported file and save failures" {
|
||||
var client = try tui.Client.init(allocator, .{ .width = 72, .height = 6 });
|
||||
defer client.deinit();
|
||||
|
||||
try std.testing.expectError(repo.Error.InvalidPath, client.handleTraceLine("repo_file ../secret=hidden"));
|
||||
{
|
||||
const frame = try client.render(allocator);
|
||||
defer allocator.free(frame);
|
||||
try std.testing.expect(std.mem.indexOf(u8, frame, "diagnostic:unsupported_file") != null);
|
||||
}
|
||||
|
||||
const large_bytes = try allocator.alloc(u8, diagnostics.max_file_bytes + 1);
|
||||
defer allocator.free(large_bytes);
|
||||
@memset(large_bytes, 'x');
|
||||
const large_command = try std.fmt.allocPrint(allocator, "repo_file src/large.txt={s}", .{large_bytes});
|
||||
defer allocator.free(large_command);
|
||||
try std.testing.expectError(tui.Error.ProtocolRejected, client.handleTraceLine(large_command));
|
||||
{
|
||||
const frame = try client.render(allocator);
|
||||
defer allocator.free(frame);
|
||||
try std.testing.expect(std.mem.indexOf(u8, frame, "diagnostic:file_too_large") != null);
|
||||
}
|
||||
|
||||
try client.handleTraceLine("open ok");
|
||||
const insert_command = try std.fmt.allocPrint(allocator, "insert {s}", .{large_bytes});
|
||||
defer allocator.free(insert_command);
|
||||
try client.handleTraceLine(insert_command);
|
||||
try std.testing.expectError(tui.Error.ProtocolRejected, client.handleTraceLine("save"));
|
||||
{
|
||||
const frame = try client.render(allocator);
|
||||
defer allocator.free(frame);
|
||||
try std.testing.expect(std.mem.indexOf(u8, frame, "diagnostic:save_failed:file_too_large") != null);
|
||||
}
|
||||
}
|
||||
|
||||
fn rowsContain(rows: []const []const u8, needle: []const u8) bool {
|
||||
for (rows) |row| {
|
||||
if (std.mem.indexOf(u8, row, needle) != null) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
fn freeRows(rows: [][]const u8) void {
|
||||
for (rows) |row| allocator.free(row);
|
||||
allocator.free(rows);
|
||||
|
||||
Reference in New Issue
Block a user