╭ changed ───────╮ │src/test/net.zig│ ╰────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭──────────────────────────────────────╮ │2 const builtin = @import("builtin");│ │3 const hx = @import("haxy"); │ │4 const xit = hx.xit; │ │5 +const evt = hx.event; │ │6 const rp = xit.repo; │ │7 const rf = xit.ref; │ │8 const work = xit.workdir; │ ╰──────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────╮ │24 test "push small" { │ │25 const io = std.testing.io; │ │26 const allocator = std.testing.allocator; │ │26 - try testPush(.xit, .{ .wire = .http }, io, allocator); │ │27 if (.windows != builtin.os.tag) { │ │28 try testPush(.xit, .{ .wire = .ssh }, io, allocator);│ │29 } │ ╰─────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────╮ │32 test "push creates missing repo under serve" { │ │33 const io = std.testing.io; │ │34 const allocator = std.testing.allocator; │ │35 - try testPushCreatesMissingRepo(.xit, .{ .wire = .http }, io, allocator); │ │35 if (.windows != builtin.os.tag) { │ │36 try testPushCreatesMissingRepo(.xit, .{ .wire = .ssh }, io, allocator);│ │37 } │ ╰───────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────╮ │67 test "push large subprocess" { │ │68 const io = std.testing.io; │ │69 const allocator = std.testing.allocator; │ │71 - try testPushLarge(.git, .{ .wire = .http }, true, io, allocator); │ │70 if (.windows != builtin.os.tag) { │ │71 try testPushLarge(.git, .{ .wire = .ssh }, true, io, allocator);│ │72 } │ ╰────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────╮ │ 94 try priv_key_file.setPermissions(io, @enumFromInt(0o600)); │ │ 95 } │ │ 96 } │ │ 97 + │ │ 98 + // seed the admin event store so the server can resolve <owner>/<repo> paths│ │ 99 + // and authenticate pushes from the dev key above │ │100 + try setupAdmin(io, allocator, temp_dir_name); │ │101 │ │102 const cwd_path = try std.process.currentPathAlloc(io, allocator); │ │103 defer allocator.free(cwd_path); │ ╰─────────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │108 const ssh_listen_arg = std.fmt.comptimePrint("127.0.0.1:{}", .{ssh_port}); │ │109 │ │110 const process = try std.process.spawn(io, .{ │ │109 - .argv = &.{ haxy_path, "serve", "--http-listen", http_listen_arg, "--ssh-listen", ssh_listen_arg, "--data-dir", temp_dir_name, "--test" },│ │111 + .argv = &.{ haxy_path, "serve", "--http-listen", http_listen_arg, "--ssh-listen", ssh_listen_arg, "--data-dir", temp_dir_name }, │ │112 .stdin = .ignore, │ │113 .stdout = .ignore, │ │114 .stderr = .ignore, │ ╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │150 var server_process = try runServer(io, allocator, temp_dir_name); │ │151 defer _ = server_process.kill(io); │ │152 │ │151 - const cwd_path = try std.process.currentPathAlloc(io, allocator); │ │152 - defer allocator.free(cwd_path); │ │153 - │ │154 - const server_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "repos", "server" }); │ │153 + // register the repo under admin and locate its on-disk directory │ │154 + const server_path = (try repoOnDiskPath(io, allocator, temp_dir_name, "testrepo", true)).?; │ │155 defer allocator.free(server_path); │ │156 │ │157 var server_repo = try rp.Repo(.xit, .{ .is_test = true }).init(io, allocator, .{ .path = server_path });│ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────╮ │177 // add a tag │ │178 _ = try server_repo.addTag(io, allocator, .{ .name = "1.0.0", .message = "hi" }); │ │179 │ │180 + const cwd_path = try std.process.currentPathAlloc(io, allocator); │ │181 + defer allocator.free(cwd_path); │ │182 + │ │183 const client_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "client" });│ │184 defer allocator.free(client_path); │ │185 │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │188 │ │189 // add remote │ │190 { │ │188 - if (.windows == builtin.os.tag) { │ │189 - std.mem.replaceScalar(u8, server_path, '\\', '/'); │ │190 - } │ │191 - const separator = if (server_path[0] == '/') "" else "/"; │ │192 - │ │193 - const remote_url = switch (transport_def) { │ │194 - //.file => try std.fmt.allocPrint(allocator, "file://{s}{s}", .{ separator, server_path }), │ │195 - .file => try std.fmt.allocPrint(allocator, "../server", .{}), // relative file paths work too │ │196 - .wire => |wire_kind| switch (wire_kind) { │ │197 - .http => try std.fmt.allocPrint(allocator, "http://localhost:{}/server", .{http_port}), │ │198 - .raw => try std.fmt.allocPrint(allocator, "git://localhost:{}/server", .{http_port}), │ │199 - .ssh => try std.fmt.allocPrint(allocator, "ssh://localhost:{}{s}{s}", .{ ssh_port, separator, server_path }),│ │200 - }, │ │201 - }; │ │191 + const remote_url = try remoteUrl(transport_def, allocator, "testrepo"); │ │192 defer allocator.free(remote_url); │ │193 │ │194 try client_repo.addRemote(io, allocator, .{ .name = "origin", .value = remote_url }); │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │208 .file => false, │ │209 .wire => |wire_kind| .ssh == wire_kind, │ │210 }; │ │221 - // haxy generates a fresh host key on every run, so don't try to record │ │222 - // it. accept the unknown host and skip writing to known_hosts. the key │ │223 - // identity flag picks the ed25519 key created in runServer. │ │224 - const ssh_cmd_maybe: ?[]const u8 = if (is_ssh) blk: { │ │225 - const priv_key_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "key" }); │ │226 - defer allocator.free(priv_key_path); │ │227 - │ │228 - break :blk try std.fmt.allocPrint(allocator, "ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -o IdentityFile=\"{s}\"", .{priv_key_path});│ │229 - } else null; │ │211 + const ssh_cmd_maybe = try sshCommand(is_ssh, allocator, cwd_path, temp_dir_name); │ │212 defer if (ssh_cmd_maybe) |ssh_cmd| allocator.free(ssh_cmd); │ │213 │ │214 try client_repo.fetch( │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────╮ │next →│ ╰──────╯