╭ try.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1 //! start a server with some fake data and then launch 2 //! the TUI. this provides a nice way to test things 3 //! out safely. 4 5 const std = @import("std"); 6 const builtin = @import("builtin"); 7 const hx = @import("haxy"); 8 const srv = hx.serve; 9 const evt = hx.event; 10 const xit = hx.xit; 11 const rp = xit.repo; 12 const ui = hx.ui; 13 14 // cook the terminal before a panic/segfault trace is printed, so the trace 15 // isn't mangled by raw mode and the alternate buffer 16 pub const std_options_debug_io = xit.xitui.terminal.crash_debug_io; 17 18 pub fn main(init: std.process.Init) !void { 19 const allocator = std.heap.smp_allocator; 20 21 var threaded = std.Io.Threaded.init(allocator, .{ 22 .environ = init.minimal.environ, 23 }); 24 defer threaded.deinit(); 25 const io = threaded.io(); 26 27 const temp_dir_name = "temp-try"; 28 29 // create the temp dir 30 const cwd = std.Io.Dir.cwd(); 31 var temp_dir_or_err = cwd.openDir(io, temp_dir_name, .{}); 32 if (temp_dir_or_err) |*temp_dir| { 33 temp_dir.close(io); 34 try cwd.deleteTree(io, temp_dir_name); 35 } else |_| {} 36 var temp_dir = try cwd.createDirPathOpen(io, temp_dir_name, .{}); 37 defer cwd.deleteTree(io, temp_dir_name) catch {}; 38 defer temp_dir.close(io); 39 40 // write the dev SSH private key so pushes can authenticate against the 41 // matching public key seeded on the admin account below 42 { 43 const priv_key_file = try temp_dir.createFile(io, "key", .{}); 44 defer priv_key_file.close(io); 45 try priv_key_file.writeStreamingAll(io, 46 \\-----BEGIN OPENSSH PRIVATE KEY----- 47 \\b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW 48 \\QyNTUxOQAAACCniLPJiaooAWecvOCeAjoJwCSeWxzysvpTNkpYjF22JgAAAJA+7hikPu4Y 49 \\pAAAAAtzc2gtZWQyNTUxOQAAACCniLPJiaooAWecvOCeAjoJwCSeWxzysvpTNkpYjF22Jg 50 \\AAAEDVlopOMnKt/7by/IA8VZvQXUS/O6VLkixOqnnahUdPCKeIs8mJqigBZ5y84J4COgnA 51 \\JJ5bHPKy+lM2SliMXbYmAAAAC3JhZGFyQHJvYXJrAQI= 52 \\-----END OPENSSH PRIVATE KEY----- 53 \\ 54 ); 55 if (.windows != builtin.os.tag) { 56 try priv_key_file.setPermissions(io, @enumFromInt(0o600)); 57 } 58 } 59 60 const cwd_path = try std.process.currentPathAlloc(io, allocator); 61 defer allocator.free(cwd_path); 62 63 const work_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "server", "admin" }); 64 defer allocator.free(work_path); 65 66 const Repo = rp.Repo(.xit, evt.admin_repo_opts); 67 var repo = try Repo.init(io, allocator, .{ .path = work_path }); 68 defer repo.deinit(io, allocator); 69 70 var session_arena = std.heap.ArenaAllocator.init(allocator); 71 defer session_arena.deinit(); 72 73 var session: ui.Session = blk: { 74 var arena = std.heap.ArenaAllocator.init(allocator); 75 defer arena.deinit(); 76 77 // define test events 78 79 var prng = std.Random.DefaultPrng.init(std.testing.random_seed); 80 81 const user_data = [_]struct { 82 name: []const u8, 83 display_name: []const u8, 84 email: []const u8, 85 }{ 86 .{ .name = "admin", .display_name = "Admin", .email = "admin@example.test" }, 87 .{ .name = "alice", .display_name = "Alice Tulley", .email = "alice@example.test" }, 88 .{ .name = "bob", .display_name = "Bob Smith", .email = "bob@example.test" }, 89 .{ .name = "carol", .display_name = "Carol Johnson", .email = "carol@example.test" }, 90 .{ .name = "dave", .display_name = "Dave Wilson", .email = "dave@example.test" }, 91 .{ .name = "eve", .display_name = "Eve Anderson", .email = "eve@example.test" }, 92 .{ .name = "frank", .display_name = "Frank Miller", .email = "frank@example.test" }, 93 .{ .name = "grace", .display_name = "Grace Lee", .email = "grace@example.test" }, 94 .{ .name = "henry", .display_name = "Henry Davis", .email = "henry@example.test" }, 95 .{ .name = "ivy", .display_name = "Ivy Martinez", .email = "ivy@example.test" }, 96 .{ .name = "jack", .display_name = "Jack Thompson", .email = "jack@example.test" }, 97 .{ .name = "kate", .display_name = "Kate Robinson", .email = "kate@example.test" }, 98 .{ .name = "liam", .display_name = "Liam Walker", .email = "liam@example.test" }, 99 .{ .name = "mona", .display_name = "Mona Patel", .email = "mona@example.test" }, 100 .{ .name = "noah", .display_name = "Noah Garcia", .email = "noah@example.test" }, 101 .{ .name = "olivia", .display_name = "Olivia Hernandez", .email = "olivia@example.test" }, 102 .{ .name = "peter", .display_name = "Peter Wright", .email = "peter@example.test" }, 103 .{ .name = "quinn", .display_name = "Quinn Foster", .email = "quinn@example.test" }, 104 .{ .name = "rachel", .display_name = "Rachel Bennett", .email = "rachel@example.test" }, 105 .{ .name = "sam", .display_name = "Sam Brooks", .email = "sam@example.test" }, 106 .{ .name = "tina", .display_name = "Tina Cooper", .email = "tina@example.test" }, 107 }; 108 109 const repo_data = [_]struct { 110 user_index: usize, 111 name: []const u8, 112 description: []const u8, 113 }{ 114 .{ .user_index = 1, .name = "ziglings", .description = "Learn the Zig programming language by fixing tiny broken programs" }, 115 .{ .user_index = 2, .name = "linux", .description = "Linux kernel source tree" }, 116 .{ .user_index = 3, .name = "kubernetes", .description = "Production-grade container orchestration" }, 117 .{ .user_index = 4, .name = "react", .description = "A declarative, efficient, and flexible JavaScript library for building user interfaces" }, 118 .{ .user_index = 5, .name = "typescript", .description = "TypeScript is a superset of JavaScript that compiles to clean JavaScript output" }, 119 .{ .user_index = 6, .name = "rust", .description = "Empowering everyone to build reliable and efficient software" }, 120 .{ .user_index = 7, .name = "go", .description = "The Go programming language" }, 121 .{ .user_index = 8, .name = "nodejs", .description = "Node.js JavaScript runtime" }, 122 .{ .user_index = 9, .name = "cpython", .description = "The Python programming language" }, 123 .{ .user_index = 10, .name = "docker", .description = "Container platform for developing, shipping, and running applications" }, 124 .{ .user_index = 1, .name = "vim", .description = "The ubiquitous text editor" }, 125 .{ .user_index = 2, .name = "neovim", .description = "Hyperextensible Vim-based text editor" }, 126 .{ .user_index = 3, .name = "emacs", .description = "GNU Emacs source code mirror" }, 127 .{ .user_index = 4, .name = "tmux", .description = "Terminal multiplexer" }, 128 .{ .user_index = 5, .name = "zsh", .description = "Mirror of the Z shell source code repository" }, 129 .{ .user_index = 6, .name = "git", .description = "Distributed version control system" }, 130 .{ .user_index = 7, .name = "mercurial", .description = "Source-control management tool" }, 131 .{ .user_index = 8, .name = "tensorflow", .description = "An end-to-end open source machine learning platform" }, 132 .{ .user_index = 9, .name = "pytorch", .description = "Tensors and dynamic neural networks in Python with strong GPU acceleration" }, 133 .{ .user_index = 10, .name = "numpy", .description = "The fundamental package for scientific computing with Python" }, 134 .{ .user_index = 1, .name = "pandas", .description = "Flexible and powerful data analysis and manipulation library for Python" }, 135 .{ .user_index = 2, .name = "scikit-learn", .description = "Machine learning in Python" }, 136 .{ .user_index = 3, .name = "nginx", .description = "High performance HTTP server and reverse proxy" }, 137 .{ .user_index = 4, .name = "redis", .description = "In-memory data structure store, used as a database, cache, and message broker" }, 138 .{ .user_index = 5, .name = "postgres", .description = "The world's most advanced open source relational database" }, 139 .{ .user_index = 6, .name = "sqlite", .description = "Self-contained, serverless, zero-configuration SQL database engine" }, 140 .{ .user_index = 7, .name = "mongodb", .description = "The MongoDB Database" }, 141 .{ .user_index = 8, .name = "elasticsearch", .description = "Free and open, distributed, RESTful search engine" }, 142 .{ .user_index = 9, .name = "kafka", .description = "Distributed event streaming platform" }, 143 .{ .user_index = 10, .name = "terraform", .description = "Infrastructure as code tool" }, 144 .{ .user_index = 11, .name = "svelte", .description = "Cybernetically enhanced web apps" }, 145 .{ .user_index = 12, .name = "vue", .description = "The progressive JavaScript framework" }, 146 .{ .user_index = 13, .name = "flask", .description = "The Python micro framework for building web applications" }, 147 .{ .user_index = 14, .name = "django", .description = "The web framework for perfectionists with deadlines" }, 148 .{ .user_index = 15, .name = "rails", .description = "Ruby on Rails web framework" }, 149 .{ .user_index = 16, .name = "phoenix", .description = "Peace of mind from prototype to production for Elixir web apps" }, 150 .{ .user_index = 17, .name = "laravel", .description = "The PHP framework for web artisans" }, 151 .{ .user_index = 18, .name = "prometheus", .description = "The Prometheus monitoring system and time series database" }, 152 .{ .user_index = 19, .name = "grafana", .description = "The open and composable observability and data visualization platform" }, 153 .{ .user_index = 20, .name = "ansible", .description = "Simple, agentless IT automation" }, 154 }; 155 156 var user_ids: [user_data.len][evt.event_id_size]u8 = undefined; 157 for (&user_ids) |*id| id.* = evt.EventWithId.randomId(prng.random()); 158 159 var repo_event_ids: [repo_data.len][evt.event_id_size]u8 = undefined; 160 for (&repo_event_ids) |*id| id.* = evt.EventWithId.randomId(prng.random()); 161 162 var password_hash_buf: [evt.User.password_hash_max_len]u8 = undefined; 163 const password_hash = try evt.User.hashPassword("password", &password_hash_buf, io); 164 165 // public key matching temp-try/key, given to admin so we can push as admin 166 const admin_ssh_key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKeIs8mJqigBZ5y84J4COgnAJJ5bHPKy+lM2SliMXbYm radar@roark"; 167 168 var events_to_consume: [user_data.len + repo_data.len]evt.EventWithId = undefined; 169 for (user_data, 0..) |u, i| { 170 events_to_consume[i] = .{ 171 .id = std.fmt.bytesToHex(user_ids[i], .lower), 172 // stepped timestamps so the seeded users/repos list in a stable order 173 .timestamp = @intCast(i + 1), 174 .event = .{ 175 .user = .{ 176 .name = u.name, 177 .display_name = u.display_name, 178 .email = u.email, 179 .password_hash = password_hash, 180 .ssh_keys = if (i == 0) admin_ssh_key else "", 181 }, 182 }, 183 }; 184 } 185 for (repo_data, 0..) |r, i| { 186 events_to_consume[user_data.len + i] = .{ 187 .id = std.fmt.bytesToHex(repo_event_ids[i], .lower), 188 .timestamp = @intCast(user_data.len + i + 1), 189 .event = .{ 190 .repo = .{ 191 .user_id = &user_ids[r.user_index], 192 .name = r.name, 193 .description = r.description, 194 }, 195 }, 196 }; 197 } 198 199 // commit the seed events and consume them into the database 200 try evt.commitAndConsume(.xit, evt.admin_repo_opts, io, allocator, &repo, evt.events_ref, &events_to_consume); 201 202 // every repo gets the same generated history, so build it once into a 203 // template repo and copy that to each repo's location below rather than 204 // redoing the expensive commit work for every repo. 205 const template_path = try std.fs.path.join(arena.allocator(), &.{ cwd_path, temp_dir_name, "template" }); 206 { 207 var template_repo = try rp.Repo(.xit, .{}).init(io, allocator, .{ .path = template_path }); 208 defer template_repo.deinit(io, allocator); 209 210 try template_repo.addConfig(io, allocator, .{ .name = "user.name", .value = "haxy" }); 211 try template_repo.addConfig(io, allocator, .{ .name = "user.email", .value = "admin@haxy" }); 212 213 // a README plus a nested doc so the file tree has a directory to 214 // descend into 215 { 216 var repo_dir = try cwd.openDir(io, template_path, .{}); 217 defer repo_dir.close(io); 218 219 const readme = try repo_dir.createFile(io, "README.md", .{}); 220 defer readme.close(io); 221 try readme.writeStreamingAll(io, 222 \\# Sample Repo 223 \\ 224 \\A repository seeded with test data for exercising the UI. 225 \\ 226 \\## Features 227 \\ 228 \\- Fast and lightweight 229 \\- Zero configuration required 230 \\- Works out of the box 231 \\ 232 \\## Installation 233 \\ 234 \\Clone the repository and build it from source: 235 \\ 236 \\```sh 237 \\git clone https://example.test/sample-repo.git 238 \\cd sample-repo 239 \\make install 240 \\``` 241 \\ 242 \\## Usage 243 \\ 244 \\Run the program with the `--help` flag to see all available 245 \\options: 246 \\ 247 \\```sh 248 \\sample-repo --help 249 \\``` 250 \\ 251 \\| Option | Description | 252 \\| ----------- | ------------------------------ | 253 \\| `--verbose` | Print extra diagnostic output | 254 \\| `--quiet` | Suppress all non-error output | 255 \\| `--version` | Print the version and exit | 256 \\ 257 \\## Contributing 258 \\ 259 \\Contributions are welcome! Please open an issue to discuss 260 \\any significant changes before submitting a pull request. 261 \\See the docs under `docs/dev` for more details. 262 \\ 263 \\## License 264 \\ 265 \\Released under the MIT License. See `LICENSE` for the full 266 \\text. 267 \\ 268 ); 269 270 try repo_dir.createDirPath(io, "docs/dev"); 271 const doc = try repo_dir.createFile(io, "docs/dev/contribute.md", .{}); 272 defer doc.close(io); 273 try doc.writeStreamingAll(io, "To contribute, please make a pull request"); 274 } 275 276 try template_repo.add(io, allocator, &.{ "README.md", "docs/dev/contribute.md" }); 277 _ = try template_repo.commit(io, allocator, .{ .message = "let there be light" }); 278 279 // tag every commit in creation order as v1, v2, and so on 280 var tag_num: usize = 1; 281 try addNextTag(&template_repo, io, allocator, &tag_num); 282 283 // a batch of commits so the commits tab has more than one page to 284 // paginate through. each rewrites a few files with scattered line 285 // edits, so every commit is a multi-file diff with several separate 286 // hunks to look at. stepped timestamps vary the date column. 287 const base_ts: u64 = 1_700_000_000; // 2023-11-14 288 const edit_files = [_][]const u8{ "src/alpha.txt", "src/beta.txt", "src/gamma.txt" }; 289 // commit subjects, cycled then padded to a varying length. 290 const subjects = [_][]const u8{ 291 "fix off-by-one in scatter loop", 292 "encode and decode buffers", 293 "tune kernel socket timeouts", 294 "render matrix vector product", 295 "gather falcon and otter stats", 296 "refactor badger walrus module", 297 "drop dead ferret marmot branch", 298 }; 299 var c: usize = 0; 300 while (c < 30) : (c += 1) { 301 { 302 var repo_dir = try cwd.openDir(io, template_path, .{}); 303 defer repo_dir.close(io); 304 try repo_dir.createDirPath(io, "src"); 305 for (edit_files, 0..) |path, fi| { 306 try writeScatterFile(io, allocator, repo_dir, path, fi, c); 307 } 308 } 309 try template_repo.add(io, allocator, &edit_files); 310 // a cycling subject padded to a c-varying length so the commit 311 // list shows messages of different widths, capped at 120. 312 var msg_writer = std.Io.Writer.Allocating.init(allocator); 313 defer msg_writer.deinit(); 314 try msg_writer.writer.print("{s}", .{subjects[c % subjects.len]}); 315 const msg_target = 16 + (c * 41) % 96; 316 var mw = c; 317 while (true) : (mw += 1) { 318 const word = scatter_words[mw % scatter_words.len]; 319 const len = msg_writer.written().len; 320 if (len >= msg_target or len + 1 + word.len > 120) break; 321 try msg_writer.writer.print(" {s}", .{word}); 322 } 323 const message = try arena.allocator().dupe(u8, msg_writer.written()); 324 _ = try template_repo.commit(io, allocator, .{ .message = message, .timestamp = base_ts + c * std.time.s_per_day }); 325 try addNextTag(&template_repo, io, allocator, &tag_num); 326 } 327 328 // two more branches forked off master, each adding a single commit 329 // that makes a scattered edit to one file. tag each new commit too, 330 // and switch back to master after each so the next branch also 331 // forks from master and the template ends up back on master. 332 const branch_data = [_]struct { 333 name: []const u8, 334 file: []const u8, 335 fi: usize, 336 message: []const u8, 337 rev: usize, 338 }{ 339 .{ .name = "extra", .file = "src/alpha.txt", .fi = 0, .message = "scatter alpha on the extra branch", .rev = 30 }, 340 .{ .name = "feature", .file = "src/beta.txt", .fi = 1, .message = "scatter beta on the feature branch", .rev = 31 }, 341 }; 342 for (branch_data) |b| { 343 try template_repo.addBranch(io, .{ .name = b.name }); 344 { 345 var to_branch = try template_repo.switchDir(io, allocator, .{ .target = .{ .ref = .{ .kind = .head, .name = b.name } } }); 346 defer to_branch.deinit(); 347 } 348 349 { 350 var repo_dir = try cwd.openDir(io, template_path, .{}); 351 defer repo_dir.close(io); 352 try writeScatterFile(io, allocator, repo_dir, b.file, b.fi, b.rev); 353 } 354 try template_repo.add(io, allocator, &.{b.file}); 355 _ = try template_repo.commit(io, allocator, .{ .message = b.message, .timestamp = base_ts + b.rev * std.time.s_per_day }); 356 try addNextTag(&template_repo, io, allocator, &tag_num); 357 358 { 359 var to_master = try template_repo.switchDir(io, allocator, .{ .target = .{ .ref = .{ .kind = .head, .name = "master" } } }); 360 defer to_master.deinit(); 361 } 362 } 363 364 // seed issues so every repo's issue tracker has content 365 const issue_data = [_]struct { 366 title: []const u8, 367 description: []const u8, 368 tags: []const u8, 369 status: evt.Issue.Status = .open, 370 }{ 371 .{ 372 .title = "Crash on startup when config file is missing", 373 .description = "Running the program without a config file present dereferences a null pointer and segfaults. Fall back to the built-in defaults and log a warning instead.", 374 .tags = "bug priority-high crash", 375 }, 376 .{ 377 .title = "Support dark mode in the settings panel", 378 .description = "The settings panel is always rendered with the light palette even when the rest of the app is in dark mode. Read the active theme and pick colors accordingly.", 379 .tags = "enhancement ui theme", 380 }, 381 .{ 382 .title = "Memory leak when reconnecting after network failure", 383 .description = "Each reconnect allocates a new connection state without freeing the previous one. After a flaky network session, memory usage grows by several megabytes per hour.", 384 .tags = "bug memory networking", 385 .status = .closed, 386 }, 387 .{ 388 .title = "Document the plugin API", 389 .description = "The plugin interface has no documentation beyond the header comments. Add a guide covering the lifecycle hooks, the event callbacks, and a minimal working plugin.", 390 .tags = "documentation plugins", 391 }, 392 .{ 393 .title = "Slow file indexing on large directories", 394 .description = "Indexing a directory with more than 100k files takes several minutes because every entry is stat'd twice. Cache the first stat result and batch the reads.", 395 .tags = "performance indexing", 396 }, 397 .{ 398 .title = "Add keyboard shortcut for quick search", 399 .description = "Opening the search box currently requires clicking the toolbar icon. Bind a shortcut and show it in the tooltip so keyboard users can search without the mouse.", 400 .tags = "enhancement ux keyboard", 401 }, 402 .{ 403 .title = "Unicode filenames are garbled in the export dialog", 404 .description = "Filenames containing non-ASCII characters display as replacement characters in the export dialog. The dialog decodes the path as Latin-1 instead of UTF-8.", 405 .tags = "bug unicode i18n", 406 }, 407 .{ 408 .title = "Flaky test: integration suite times out on CI", 409 .description = "The integration suite intermittently exceeds the CI time limit because the server fixture waits for a fixed 30 seconds. Poll for readiness instead of sleeping.", 410 .tags = "bug testing ci", 411 }, 412 .{ 413 .title = "Upgrade bundled zlib to the latest release", 414 .description = "The vendored zlib is two major releases behind and misses several upstream fixes. Update the bundled copy and re-run the compression benchmarks.", 415 .tags = "dependencies maintenance", 416 }, 417 .{ 418 .title = "Progress bar overshoots 100% during resumed downloads", 419 .description = "Resuming a partial download counts the already-downloaded bytes twice, so the progress bar reads up to 150%. Subtract the resume offset from the total.", 420 .tags = "bug ui downloads", 421 .status = .closed, 422 }, 423 .{ 424 .title = "Config parser rejects trailing commas", 425 .description = "A trailing comma after the last entry in a config block is reported as a syntax error. Most editors add one automatically, so accept it.", 426 .tags = "bug config parser", 427 }, 428 .{ 429 .title = "Add a --json flag to the status command", 430 .description = "Scripts currently scrape the human-readable status output, which breaks whenever the format changes. Emit a stable machine-readable JSON form behind a flag.", 431 .tags = "enhancement cli", 432 }, 433 .{ 434 .title = "Race condition between autosave and manual save", 435 .description = "Saving manually while an autosave is in flight can interleave the two writes and corrupt the file. Serialize saves through a single queue.", 436 .tags = "bug priority-high data-loss", 437 }, 438 .{ 439 .title = "Reduce binary size of release builds", 440 .description = "The release binary has grown past 40 MB, mostly from debug info and an unused bundled font. Strip symbols and drop the font from the default build.", 441 .tags = "performance build", 442 }, 443 .{ 444 .title = "Tooltips flicker when the cursor moves between adjacent buttons", 445 .description = "Moving the cursor across a toolbar hides and re-shows the tooltip for every button. Keep the tooltip open with a short grace period between neighbors.", 446 .tags = "bug ui polish", 447 }, 448 .{ 449 .title = "Support environment variable expansion in config paths", 450 .description = "Paths in the config file are taken literally, so shared configs can't refer to the home directory portably. Expand environment variables when loading.", 451 .tags = "enhancement config", 452 }, 453 .{ 454 .title = "Log rotation deletes the newest file instead of the oldest", 455 .description = "When the log directory hits its size cap, the rotation logic sorts by name rather than mtime and removes the most recent log. Sort by modification time.", 456 .tags = "bug logging", 457 .status = .closed, 458 }, 459 .{ 460 .title = "Add man pages for all subcommands", 461 .description = "Only the top-level command has a man page. Generate one per subcommand from the existing help text as part of the release build.", 462 .tags = "documentation cli", 463 }, 464 .{ 465 .title = "High CPU usage while idle in the background", 466 .description = "The main loop polls for file changes every 10 ms even when no window is visible. Switch to native file watching and idle at zero CPU.", 467 .tags = "performance priority-high", 468 }, 469 .{ 470 .title = "Paste from clipboard drops the final newline", 471 .description = "Pasting text that ends with a newline silently trims it, which breaks pasted shell snippets. Preserve the clipboard content exactly.", 472 .tags = "bug editor clipboard", 473 }, 474 .{ 475 .title = "Improve error message for expired credentials", 476 .description = "An expired token currently surfaces as a bare 401 with no guidance. Detect the expiry case and tell the user how to re-authenticate.", 477 .tags = "enhancement ux auth", 478 }, 479 .{ 480 .title = "Crash when window is resized during startup animation", 481 .description = "Resizing the window while the splash animation is running dereferences a freed layout node. Cancel the animation before rebuilding the layout.", 482 .tags = "bug crash ui", 483 }, 484 .{ 485 .title = "Add integration tests for the sync engine", 486 .description = "The sync engine only has unit tests with mocked transports. Add end-to-end tests that run two instances against a real local server.", 487 .tags = "testing sync", 488 }, 489 .{ 490 .title = "Timestamps display in UTC instead of local time", 491 .description = "All timestamps in the activity feed render in UTC regardless of the system timezone. Convert to local time and include the offset in tooltips.", 492 .tags = "bug i18n time", 493 }, 494 .{ 495 .title = "Deprecate the legacy plugin format", 496 .description = "Both plugin formats are currently loaded, doubling the maintenance surface. Warn on legacy plugins this release and drop support in the next.", 497 .tags = "maintenance plugins", 498 }, 499 }; 500 501 var issue_events: [issue_data.len]evt.EventWithId = undefined; 502 for (issue_data, 0..) |issue, i| { 503 issue_events[i] = .{ 504 .id = std.fmt.bytesToHex(evt.EventWithId.randomId(prng.random()), .lower), 505 // stepped timestamps so the issues list in a stable order 506 .timestamp = @intCast(i + 1), 507 .event = .{ 508 .issue = .{ 509 .title = issue.title, 510 .description = issue.description, 511 .tags = issue.tags, 512 .status = issue.status, 513 }, 514 }, 515 }; 516 } 517 try evt.commitAndConsume(.xit, .{}, io, allocator, &template_repo, evt.events_ref, &issue_events); 518 } 519 520 // copy the template to each repo's on-disk location, named by its 521 // hex-encoded event id. the template repo is deinitialized above, so its 522 // db file is fully written before we copy it. 523 { 524 var template_dir = try cwd.openDir(io, template_path, .{ .iterate = true }); 525 defer template_dir.close(io); 526 527 for (repo_event_ids) |id_bytes| { 528 const repo_id = std.fmt.bytesToHex(id_bytes, .lower); 529 const repo_path = try std.fs.path.join(arena.allocator(), &.{ cwd_path, temp_dir_name, "server", "repos", &repo_id }); 530 var dest_dir = try cwd.createDirPathOpen(io, repo_path, .{}); 531 defer dest_dir.close(io); 532 try copyDir(io, template_dir, dest_dir); 533 } 534 } 535 536 break :blk try ui.Session.init(&session_arena, &repo, .{}); 537 }; 538 session.is_terminal = true; 539 // try uses the default serve options below, so the footer's url points at 540 // the default web UI port. 541 session.web_port = try (srv.Options{}).wuiPort(); 542 543 // start the server 544 545 var cli = false; 546 547 var arg_it = try init.minimal.args.iterateAllocator(allocator); 548 defer arg_it.deinit(); 549 _ = arg_it.skip(); 550 while (arg_it.next()) |arg| { 551 if (std.mem.eql(u8, "--cli", arg)) { 552 cli = true; 553 } 554 } 555 556 const server_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "server" }); 557 defer allocator.free(server_path); 558 559 // let the native TUI's page builders open the on-disk repos for the file tree 560 session.io = io; 561 session.repos_dir = try std.fs.path.join(session_arena.allocator(), &.{ server_path, "repos" }); 562 563 if (cli) { 564 var stdout_writer = std.Io.File.stdout().writer(io, &.{}); 565 var stderr_writer = std.Io.File.stderr().writer(io, &.{}); 566 const run_opts = hx.main.RunOpts{ .out = &stdout_writer.interface, .err = &stderr_writer.interface }; 567 568 const key_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "key" }); 569 defer allocator.free(key_path); 570 571 const Runnable = struct { 572 io: std.Io, 573 key_path: []const u8, 574 575 pub fn run(self: @This()) !void { 576 std.debug.print( 577 \\ 578 \\connect to the TUI with: 579 \\ ssh -p 8022 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null localhost 580 \\ 581 \\create a git repo and push over SSH: 582 \\ mkdir -p temp-try/client/test 583 \\ cd temp-try/client/test 584 \\ git init 585 \\ echo "hello" > hello.txt 586 \\ git add hello.txt 587 \\ git commit -m "let there be light" 588 \\ GIT_SSH_COMMAND='ssh -p 8022 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -i {s}' git push localhost:admin/test HEAD:master 589 \\ 590 \\to quit, press enter. 591 \\ 592 , .{self.key_path}); 593 // portable stdin read via std.Io — equivalent to the 594 // std.posix.read(STDIN_FILENO, ...) that doesn't compile 595 // on windows. 596 var buf: [1]u8 = undefined; 597 var stdin_reader = std.Io.File.stdin().reader(self.io, &buf); 598 _ = stdin_reader.interface.takeByte() catch {}; 599 } 600 }; 601 602 try srv.run(.xit, .{}, io, allocator, cwd_path, .{ 603 .data_dir = server_path, 604 }, run_opts.err, Runnable{ .io = io, .key_path = key_path }); 605 } else { 606 var null_writer = std.Io.Writer.Discarding.init(&.{}); 607 const run_opts = hx.main.RunOpts{ .out = &null_writer.writer, .err = &null_writer.writer }; 608 609 const Runnable = struct { 610 io: std.Io, 611 allocator: std.mem.Allocator, 612 session: *ui.Session, 613 repo: *Repo, 614 615 pub fn run(self: @This()) !void { 616 // launch the TUI 617 try hx.ui.run(self.io, self.allocator, self.session, self.repo); 618 } 619 }; 620 621 try srv.run(.xit, .{}, io, allocator, cwd_path, .{ 622 .data_dir = server_path, 623 }, run_opts.err, Runnable{ .io = io, .allocator = allocator, .session = &session, .repo = &repo }); 624 } 625 } 626 627 // words cycled through to pad generated lines into prose-like content 628 const scatter_words = [_][]const u8{ 629 "lorem", "ipsum", "dolor", "sit", "amet", "consectetur", 630 "quantum", "vector", "matrix", "buffer", "kernel", "socket", 631 "falcon", "otter", "badger", "walrus", "ferret", "marmot", 632 "scatter", "gather", "encode", "decode", "render", "commit", 633 }; 634 635 // write `path` as 40 lines of mostly-stable filler. revision `c` and file 636 // index `fi` shift which lines change and the words used, so each (c, fi) 637 // yields a distinct multi-hunk diff against the previous revision. untouched 638 // lines stay byte-identical across revisions, so a bump in `c` is a scatter of 639 // small hunks rather than a full rewrite. 640 fn writeScatterFile(io: std.Io, allocator: std.mem.Allocator, repo_dir: std.Io.Dir, path: []const u8, fi: usize, c: usize) !void { 641 const file = try repo_dir.createFile(io, path, .{}); 642 defer file.close(io); 643 var writer = std.Io.Writer.Allocating.init(allocator); 644 defer writer.deinit(); 645 for (0..40) |line| { 646 const start = writer.written().len; 647 if ((line + fi + c) % 8 == 0) { 648 const tag = scatter_words[(line + fi + c * 3) % scatter_words.len]; 649 try writer.writer.print("rev {d} {s}", .{ c, tag }); 650 } 651 const target = 40 + (line * 17 + fi * 23) % 70; 652 var w = line + fi; 653 while (true) : (w += 1) { 654 const word = scatter_words[w % scatter_words.len]; 655 const len = writer.written().len - start; 656 if (len >= target or len + 1 + word.len > 120) break; 657 if (len == 0) 658 try writer.writer.print("{s}", .{word}) 659 else 660 try writer.writer.print(" {s}", .{word}); 661 } 662 try writer.writer.writeByte('\n'); 663 } 664 try file.writeStreamingAll(io, writer.written()); 665 } 666 667 // tag the current HEAD as the next sequential version: v1, v2, and so on 668 fn addNextTag(repo: *rp.Repo(.xit, .{}), io: std.Io, allocator: std.mem.Allocator, n: *usize) !void { 669 var buf: [16]u8 = undefined; 670 const name = try std.fmt.bufPrint(&buf, "v{d}", .{n.*}); 671 _ = try repo.addTag(io, allocator, .{ .name = name }); 672 n.* += 1; 673 } 674 675 // recursively copy the contents of src_dir into dest_dir 676 fn copyDir(io: std.Io, src_dir: std.Io.Dir, dest_dir: std.Io.Dir) !void { 677 var iter = src_dir.iterate(); 678 while (try iter.next(io)) |entry| { 679 switch (entry.kind) { 680 .file => try src_dir.copyFile(entry.name, dest_dir, entry.name, io, .{}), 681 .directory => { 682 try dest_dir.createDirPath(io, entry.name); 683 var dest_entry_dir = try dest_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 684 defer dest_entry_dir.close(io); 685 var src_entry_dir = try src_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 686 defer src_entry_dir.close(io); 687 try copyDir(io, src_entry_dir, dest_entry_dir); 688 }, 689 else => {}, 690 } 691 } 692 } 693