Add v1 smoke fixture target
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
const std = @import("std");
|
||||
|
||||
const lsp = @import("lsp.zig");
|
||||
const profile = @import("profile.zig");
|
||||
const repo = @import("repo.zig");
|
||||
const session_mod = @import("session.zig");
|
||||
const socket = @import("socket.zig");
|
||||
const syntax = @import("syntax.zig");
|
||||
const tui = @import("tui.zig");
|
||||
|
||||
const allocator = std.testing.allocator;
|
||||
|
||||
test "regular: v1 smoke opens edits saves and reports local socket context" {
|
||||
var client = try tui.Client.init(allocator, .{ .width = 44, .height = 10 });
|
||||
defer client.deinit();
|
||||
|
||||
try client.handleTraceLine("open pub fn main() void {}");
|
||||
try client.handleTraceLine("right");
|
||||
try client.handleTraceLine("insert // mobile fix");
|
||||
try client.handleTraceLine("save");
|
||||
try std.testing.expect(std.mem.indexOf(u8, try client.saved(), "// mobile fix") != null);
|
||||
|
||||
const frame = try client.render(allocator);
|
||||
defer allocator.free(frame);
|
||||
try std.testing.expect(std.mem.indexOf(u8, frame, "saved") != null);
|
||||
|
||||
var session = session_mod.Session.init(allocator);
|
||||
defer session.deinit();
|
||||
try session.openFixture("pub const answer = 42;\n");
|
||||
try session.openListPanel("files", &.{ "src/main.zig", "src/lib.zig" });
|
||||
|
||||
const path = "/tmp/mim-v1-smoke.sock";
|
||||
var server = try socket.Server.listen(allocator, path, &session);
|
||||
defer server.deinit();
|
||||
|
||||
const thread = try std.Thread.spawn(.{}, socket.Server.acceptOnce, .{&server});
|
||||
const response = try socket.request(allocator, path, "context iphone_fix inspect");
|
||||
defer allocator.free(response);
|
||||
thread.join();
|
||||
|
||||
try std.testing.expect(std.mem.indexOf(u8, response, "context:v1\n") != null);
|
||||
try std.testing.expect(std.mem.indexOf(u8, response, "active_panel=files") != null);
|
||||
try std.testing.expect(std.mem.indexOf(u8, response, "task=iphone_fix") != null);
|
||||
}
|
||||
|
||||
test "regular: v1 smoke covers repo panels, syntax, and LSP fixture rows" {
|
||||
var client = try tui.Client.init(allocator, .{ .width = 52, .height = 12 });
|
||||
defer client.deinit();
|
||||
|
||||
try client.handleTraceLine("repo_gitignore zig-out/");
|
||||
try client.handleTraceLine("repo_file src/main.zig=pub fn main() void { add(1, 2); }");
|
||||
try client.handleTraceLine("repo_file zig-out/log.txt=ignored build output");
|
||||
try client.handleTraceLine("file_picker");
|
||||
{
|
||||
const frame = try client.render(allocator);
|
||||
defer allocator.free(frame);
|
||||
try std.testing.expect(std.mem.indexOf(u8, frame, "src/main.zig") != null);
|
||||
try std.testing.expect(std.mem.indexOf(u8, frame, "zig-out/log.txt") == null);
|
||||
}
|
||||
|
||||
try client.handleTraceLine("search_text add");
|
||||
{
|
||||
const frame = try client.render(allocator);
|
||||
defer allocator.free(frame);
|
||||
try std.testing.expect(std.mem.indexOf(u8, frame, "src/main.zig:1:") != null);
|
||||
}
|
||||
|
||||
const syntax_rows = try syntax.rowsAlloc(allocator, "zig", "pub const answer = 42; // ok\n");
|
||||
defer freeRows(syntax_rows);
|
||||
try std.testing.expect(syntax_rows.len >= 2);
|
||||
try std.testing.expect(std.mem.indexOf(u8, syntax_rows[0], "syntax:zig:keyword") != null);
|
||||
|
||||
const hover_rows = try lsp.hoverRowsAlloc(allocator,
|
||||
\\{"jsonrpc":"2.0","id":8,"result":{"contents":{"kind":"markdown","value":"pub fn add(lhs: i32, rhs: i32) i32"}}}
|
||||
, 28);
|
||||
defer freeRows(hover_rows);
|
||||
try std.testing.expect(hover_rows.len >= 2);
|
||||
try std.testing.expect(std.mem.indexOf(u8, hover_rows[0], "lsp:hover") != null);
|
||||
|
||||
const param = try lsp.parameterMoveRowsAlloc(allocator, "add(1, 2)", 4, .next);
|
||||
defer freeRows(param.rows);
|
||||
try std.testing.expect(param.cursor > 4);
|
||||
try std.testing.expect(std.mem.indexOf(u8, param.rows[0], "lsp:param:active_2") != null);
|
||||
}
|
||||
|
||||
test "adversarial: v1 smoke catches realistic profile and boundary failures" {
|
||||
try std.testing.expectError(error.NonLocalPath, socket.validateLocalSocketPath("relative.sock"));
|
||||
try std.testing.expectError(error.NonLocalPath, socket.validateLocalSocketPath("/home/user/mim.sock"));
|
||||
|
||||
var index = repo.Index.init(allocator);
|
||||
defer index.deinit();
|
||||
try index.addIgnorePattern("secret/");
|
||||
try index.addFile("src/main.zig", "pub fn main() void {}\n");
|
||||
try index.addFile("secret/token.txt", "do-not-show\n");
|
||||
|
||||
const rows = try index.pickerItemsAlloc(allocator, false);
|
||||
defer allocator.free(rows);
|
||||
try std.testing.expectEqual(@as(usize, 1), rows.len);
|
||||
try std.testing.expectEqualStrings("src/main.zig", rows[0]);
|
||||
|
||||
try std.testing.expectError(lsp.Error.InvalidNavigationRow, lsp.navigationLocationFromRow("not a navigation row"));
|
||||
|
||||
const status = try profile.statusAlloc(allocator);
|
||||
defer allocator.free(status);
|
||||
try std.testing.expect(std.mem.indexOf(u8, status, "profile:v1") != null);
|
||||
try std.testing.expect(std.mem.indexOf(u8, status, "remote_transport=not_built") != null);
|
||||
try std.testing.expect(std.mem.indexOf(u8, status, "plugin_host=not_built") != null);
|
||||
}
|
||||
|
||||
fn freeRows(rows: [][]const u8) void {
|
||||
for (rows) |row| allocator.free(row);
|
||||
allocator.free(rows);
|
||||
}
|
||||
Reference in New Issue
Block a user