Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

Add explicit verified CLI beta updates

Rach Pradhandd4dde5c3ce1
diff --git a/README.md b/README.md
index f9da7547..b7d1ff62 100644
--- a/README.md
+++ b/README.md
@@ -64,6 +64,13 @@ graff # start an interactive session
graff -p "Explain this project" # ask a single question
```
+To try the newest CLI beta on macOS or Linux, run `graff update --beta --check`
+to see the release, then `graff update --beta` to install it for the next
+launch. The CLI chooses the beta for the newest numeric release branch and
+checks the tarball against that release's `SHA256SUMS`. `graff update` continues
+to use the stable release. Update package-managed installs through their
+package manager.
+
<details>
<summary>Other login options, Windows, and editor integration</summary>
diff --git a/docs/adr/0201-cli-beta-channel-is-explicit.md b/docs/adr/0201-cli-beta-channel-is-explicit.md
new file mode 100644
index 00000000..b3373a85
--- /dev/null
+++ b/docs/adr/0201-cli-beta-channel-is-explicit.md
@@ -0,0 +1,30 @@
+# 0201. CLI beta updates require explicit channel selection
+
+Status: accepted 2026-09-25
+
+## Context
+
+Beta releases are prereleases from numeric `release/v…` branches. GitHub's
+stable `latest` endpoint excludes them, and release listing order does not
+identify the newest branch. The beta CLI archive has no installer.
+
+## Decision
+
+`graff update` stays on the stable channel. `graff update --beta --check`
+reports the newest published beta from the numerically newest release branch;
+`graff update --beta` installs it for the next launch. The branch version may
+have three or four numeric parts. Within that branch, the largest beta run and
+attempt wins. No beta on the newest branch is an error, never a fallback to an
+older branch.
+
+The updater pins that prerelease tag, downloads the platform CLI archive and
+`SHA256SUMS` from it, verifies the archive, and atomically places the binary
+only at a supported user install path. It refuses package-managed and app
+bundle paths. A stable release at the same numeric version is newer than a
+beta. The running process keeps its original binary until the next launch.
+
+## Consequences
+
+Beta discovery reads the branch refs and paginated releases. A missing or malformed feed,
+checksum, or asset fails closed. The stable updater and desktop stable feed
+remain separate from beta updates.
diff --git a/docs/adr/README.md b/docs/adr/README.md
index 5c4a157b..9d6bdf1f 100644
--- a/docs/adr/README.md
+++ b/docs/adr/README.md
@@ -224,6 +224,7 @@ record only when you need the evidence or the edge cases.
| [0198](0198-project-choice-survives-session-isolation.md) | New chats inherit the chosen project while ACP reports each worker checkout; generated worktrees are rooted at the main checkout. |
| [0199](0199-generated-checkouts-belong-to-project-history.md) | Generated worktree activity rolls up to the owning project in automatic suggestions; explicitly saved checkouts stay selectable. |
| [0200](0200-desktop-page-transitions-preserve-tabs.md) | Desktop restart/reload confirms active-turn interruption and restores tab references from saved sessions in their workspaces. |
+| [0201](0201-cli-beta-channel-is-explicit.md) | CLI beta updates require explicit opt-in, select the newest numeric release branch, verify pinned assets, and activate on next launch. |
## When to write one
diff --git a/src/args.zig b/src/args.zig
index 69e61d5f..90c3119c 100644
--- a/src/args.zig
+++ b/src/args.zig
@@ -51,6 +51,7 @@ pub const Flags = struct {
selftest_spinner_flag: bool = false, // --selftest-spinner: headless spinner render for the PTY anti-stealth test
selftest_markdown_flag: bool = false, // --selftest-markdown: render the real streaming markdown fixture in a PTY
update_check: bool = false, // graff update --check
+ update_beta: bool = false, // graff update --beta
model_flag: ?[]const u8 = null,
subagent_provider_flag: ?[]const u8 = null,
subagent_model_flag: ?[]const u8 = null,
@@ -209,6 +210,8 @@ pub fn parse(init: std.process.Init) !Flags {
flags.update_force = true;
} else if (std.mem.eql(u8, arg, "--check")) {
flags.update_check = true;
+ } else if (std.mem.eql(u8, arg, "--beta")) {
+ flags.update_beta = true;
} else if (std.mem.eql(u8, arg, "--resume")) {
const rv = it.next() orelse std.process.fatal("--resume needs a session name — harness --help", .{});
flags.resume_flag = try arena.dupe(u8, rv);
diff --git a/src/beta_feed.zig b/src/beta_feed.zig
new file mode 100644
index 00000000..3092121a
--- /dev/null
+++ b/src/beta_feed.zig
@@ -0,0 +1,125 @@
+//! Resolve the newest published beta for the newest numeric release branch.
+const std = @import("std");
+const Allocator = std.mem.Allocator;
+const Value = std.json.Value;
+
+pub const branches_url = "https://api.github.com/repos/justrach/codegraff/git/matching-refs/heads/release/v";
+pub const releases_url = "https://api.github.com/repos/justrach/codegraff/releases?per_page=100";
+
+pub fn releaseCount(body: []const u8, gpa: Allocator) ?usize {
+ var parsed = std.json.parseFromSlice(Value, gpa, body, .{}) catch return null;
+ defer parsed.deinit();
+ return if (parsed.value == .array) parsed.value.array.items.len else null;
+}
+
+const Version = struct {
+ parts: [4]u32,
+ fn order(a: Version, b: Version) std.math.Order {
+ for (a.parts, b.parts) |x, y| if (x != y) return std.math.order(x, y);
+ return .eq;
+ }
+};
+
+fn version(s: []const u8) ?Version {
+ var parts: [4]u32 = .{ 0, 0, 0, 0 };
+ var it = std.mem.splitScalar(u8, s, '.');
+ var n: usize = 0;
+ while (it.next()) |p| {
+ if (n == 4 or p.len == 0) return null;
+ parts[n] = std.fmt.parseInt(u32, p, 10) catch return null;
+ n += 1;
+ }
+ if (n < 3) return null;
+ return .{ .parts = parts };
+}
+
+pub fn newestBranch(body: []const u8, gpa: Allocator) ?[]u8 {
+ var parsed = std.json.parseFromSlice(Value, gpa, body, .{}) catch return null;
+ defer parsed.deinit();
+ if (parsed.value != .array) return null;
+ var best: ?Version = null;
+ var name: ?[]const u8 = null;
+ for (parsed.value.array.items) |item| {
+ if (item != .object) continue;
+ const ref = item.object.get("ref") orelse continue;
+ if (ref != .string) continue;
+ const prefix = "refs/heads/release/v";
+ if (!std.mem.startsWith(u8, ref.string, prefix)) continue;
+ const suffix = ref.string[prefix.len..];
+ const v = version(suffix) orelse continue;
+ if (best == null or v.order(best.?) == .gt) {
+ best = v;
+ name = suffix;
+ }
+ }
+ return gpa.dupe(u8, name orelse return null) catch null;
+}
+
+fn betaRun(tag: []const u8, branch: []const u8) ?[2]u64 {
+ var prefix_buf: [96]u8 = undefined;
+ const prefix = std.fmt.bufPrint(&prefix_buf, "v{s}-beta.", .{branch}) catch return null;
+ const actual = if (std.mem.startsWith(u8, tag, "v")) tag else tag;
+ const expected = if (std.mem.startsWith(u8, tag, "v")) prefix else prefix[1..];
+ if (!std.mem.startsWith(u8, actual, expected)) return null;
+ var it = std.mem.splitScalar(u8, actual[expected.len..], '.');
+ const run = std.fmt.parseInt(u64, it.next() orelse return null, 10) catch return null;
+ const attempt = std.fmt.parseInt(u64, it.next() orelse return null, 10) catch return null;
+ if (it.next() != null or run == 0 or attempt == 0) return null;
+ return .{ run, attempt };
+}
+
+/// Numeric ordering for two beta tags, including run and attempt. Returns
+/// null for any non-beta version so stable ordering stays separate.
+pub fn compareTags(a_raw: []const u8, b_raw: []const u8) ?std.math.Order {
+ const a = if (std.mem.startsWith(u8, a_raw, "v")) a_raw[1..] else a_raw;
+ const b = if (std.mem.startsWith(u8, b_raw, "v")) b_raw[1..] else b_raw;
+ const a_sep = std.mem.indexOf(u8, a, "-beta.") orelse return null;
+ const b_sep = std.mem.indexOf(u8, b, "-beta.") orelse return null;
+ const av = version(a[0..a_sep]) orelse return null;
+ const bv = version(b[0..b_sep]) orelse return null;
+ const ar = betaRun(a_raw, a[0..a_sep]) orelse return null;
+ const br = betaRun(b_raw, b[0..b_sep]) orelse return null;
+ const base = av.order(bv);
+ if (base != .eq) return base;
+ if (ar[0] != br[0]) return std.math.order(ar[0], br[0]);
+ return std.math.order(ar[1], br[1]);
+}
+
+pub fn newestRelease(body: []const u8, branch: []const u8, gpa: Allocator) ?[]u8 {
+ var parsed = std.json.parseFromSlice(Value, gpa, body, .{}) catch return null;
+ defer parsed.deinit();
+ if (parsed.value != .array) return null;
+ var best: ?[2]u64 = null;
+ var name: ?[]const u8 = null;
+ for (parsed.value.array.items) |item| {
+ if (item != .object) continue;
+ const tag = item.object.get("tag_name") orelse continue;
+ const draft = item.object.get("draft") orelse continue;
+ const pre = item.object.get("prerelease") orelse continue;
+ if (tag != .string or draft != .bool or pre != .bool or draft.bool or !pre.bool) continue;
+ const run = betaRun(tag.string, branch) orelse continue;
+ if (best == null or run[0] > best.?[0] or (run[0] == best.?[0] and run[1] > best.?[1])) {
+ best = run;
+ name = tag.string;
+ }
+ }
+ return gpa.dupe(u8, name orelse return null) catch null;
+}
+
+test "numeric branch and published prerelease selection" {
+ const gpa = std.testing.allocator;
+ const branches =
+ \\[{"ref":"refs/heads/release/v0.0.302.9"},{"ref":"refs/heads/release/v0.0.302.10"},{"ref":"refs/heads/release/v0.0.303-beta"}]
+ ;
+ const branch = newestBranch(branches, gpa).?;
+ defer gpa.free(branch);
+ try std.testing.expectEqualStrings("0.0.302.10", branch);
+ const releases =
+ \\[{"tag_name":"v0.0.302.9-beta.999.1","draft":false,"prerelease":true},{"tag_name":"v0.0.302.10-beta.26.1","draft":false,"prerelease":true},{"tag_name":"v0.0.302.10-beta.26.2","draft":true,"prerelease":true},{"tag_name":"v0.0.302.10-beta.27.1","draft":false,"prerelease":true}]
+ ;
+ const tag = newestRelease(releases, branch, gpa).?;
+ defer gpa.free(tag);
+ try std.testing.expectEqualStrings("v0.0.302.10-beta.27.1", tag);
+ try std.testing.expect(newestRelease(releases, "0.0.303", gpa) == null);
+ try std.testing.expectEqual(std.math.Order.gt, compareTags("0.0.302.10-beta.27.2", "v0.0.302.10-beta.27.1").?);
+}
diff --git a/src/cli.zig b/src/cli.zig
index 9ca35e92..3dc830e0 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -15,6 +15,8 @@ const Allocator = std.mem.Allocator;
const root = @import("main.zig");
const harness_version = root.harness_version;
const version_status = @import("version_status.zig");
+const update_service = @import("update_service.zig");
+const update_target = @import("update_target.zig");
/// Shown under `graff --version` — a terse "what's new" for recent releases.
/// Keep it short and current; bump alongside the version each release.
@@ -77,7 +79,8 @@ pub const usage_text =
\\ `graff remote` anywhere can drive sessions on this machine
\\ graff remote [new|send|tail|…] list and drive the sessions of machines running remote-control
\\ graff acp Agent Client Protocol agent on stdio (Zed and other ACP editors)
- \\ graff update [--force|--check] update graff to the latest GitHub release
+ \\ graff update [--force|--check] update graff to the latest stable release
+ \\ graff update --beta [--check] install the newest beta for the next launch
\\ graff title <prompt> print the AI tab-title for a prompt (test title styles)
\\
\\flags:
@@ -249,3 +252,43 @@ pub fn updateCommand(
try out.writeAll("✓ update installed — restart every running graff session to load the new binary\n");
try out.flush();
}
+
+/// Explicit beta opt-in. Resolve a tag on the newest numeric release branch,
+/// then reuse the in-session updater's pinned checksum and atomic placement.
+pub fn updateBetaCommand(io: Io, gpa: Allocator, arena: Allocator, environ: *const std.process.Environ.Map, check_only: bool) !void {
+ const asset = update_target.assetName() orelse std.process.fatal("beta updates are unavailable on this platform", .{});
+ const exe = std.process.executablePathAlloc(io, gpa) catch std.process.fatal("cannot locate the running graff executable", .{});
+ defer gpa.free(exe);
+ const home = environ.get("HOME") orelse "";
+ var target_buf: [std.fs.max_path_bytes]u8 = undefined;
+ const target = update_target.resolve(exe, home, &target_buf);
+ if (target.kind != .supported) std.process.fatal("beta update: {s}", .{target.detail});
+
+ var http: update_service.HttpFetch = .{ .io = io, .gpa = gpa, .user_agent = "simple-harness/" ++ harness_version };
+ const opts: update_service.Opts = .{
+ .io = io,
+ .gpa = gpa,
+ .running_version = harness_version,
+ .target_path = target.path,
+ .asset_name = asset,
+ .fetch = http.fetch(),
+ .channel = .beta,
+ };
+ var buf: [4096]u8 = undefined;
+ var writer = Io.File.stdout().writer(io, &buf);
+ const out = &writer.interface;
+ const report = if (check_only) update_service.inspect(opts) else update_service.install(opts, .human);
+ switch (report.kind) {
+ .available => try out.print("beta available: {s} (run `graff update --beta`)\n", .{report.latest_tag().?}),
+ .installed => try out.print("installed {s} for the next launch; restart graff to use it\n", .{report.latest_tag().?}),
+ .current, .already_installed => try out.print("beta {s} is already installed\n", .{report.latest_tag().?}),
+ .newer => try out.print("running graff v{s} is newer than beta {s}; keeping it\n", .{ report.running(), report.latest_tag().? }),
+ .offline => std.process.fatal("beta update: could not reach GitHub or download a release asset", .{}),
+ .malformed => std.process.fatal("beta update: no published beta for the newest release branch, or release metadata is invalid", .{}),
+ .verify_failed => std.process.fatal("beta update: SHA256SUMS verification failed", .{}),
+ .permission => std.process.fatal("beta update: cannot write {s}", .{target.path}),
+ else => std.process.fatal("beta update: {s}", .{report.detail}),
+ }
+ try out.flush();
+ _ = arena;
+}
diff --git a/src/main.zig b/src/main.zig
index 01b71ff5..ed0231ea 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -558,6 +558,7 @@ const agentJobsReap = subagent.agentJobsReap; // #276 P0-3: background subagents
const workflow = @import("workflow_test.zig"); // the engine's tests live here (workflow.zig hit the 600-line cap)
const exec = @import("exec.zig");
test { // ── Unit tests (`zig build test`): pull in tests from imported modules (mcp.zig)
+ _ = @import("beta_feed.zig");
_ = .{ @import("jev_tool.zig"), @import("jev_model_scope.zig"), @import("jev_provider_switch_tests.zig"), @import("jev_effort_state.zig") };
_ = .{ @import("mcp_apps.zig"), @import("html_view.zig"), @import("providers_confirmation_tests.zig"), @import("repl_model_confirmation_tests.zig"), @import("repl_model_pick_tests.zig"), @import("engine_sink_citation_tests.zig"), @import("cite_markup_stream_tests.zig"), @import("oneshot_citation_tests.zig"), @import("tui_acp.zig"), @import("acp_permission.zig"), @import("acp_usage.zig") };
_ = .{ @import("mcp_server_tests.zig"), @import("main_test.zig"), @import("artifact_claim_command.zig"), @import("cli_path_hint.zig"), @import("run_budget.zig"), @import("pr_review_input.zig"), @import("pr_claim_review.zig"), @import("tui_paste_transfer.zig") };
diff --git a/src/startup.zig b/src/startup.zig
index 68e362a4..0eb78d68 100644
--- a/src/startup.zig
+++ b/src/startup.zig
@@ -365,7 +365,12 @@ pub fn runSubcommand(io: Io, gpa: Allocator, arena: Allocator, init: std.process
// contradictory combination up front rather than silently ignoring one.
if (flags.update_force and flags.update_check)
std.process.fatal("--force and --check are mutually exclusive — use `graff update` (without --check) to install", .{});
- try cli.updateCommand(io, gpa, arena, init.environ_map, flags.update_force, flags.update_check);
+ if (flags.update_beta) {
+ if (flags.update_force) std.process.fatal("--force is not supported with --beta", .{});
+ try cli.updateBetaCommand(io, gpa, arena, init.environ_map, flags.update_check);
+ } else {
+ try cli.updateCommand(io, gpa, arena, init.environ_map, flags.update_force, flags.update_check);
+ }
return true;
}
diff --git a/src/update_service.zig b/src/update_service.zig
index 1d584bfe..70458476 100644
--- a/src/update_service.zig
+++ b/src/update_service.zig
@@ -15,6 +15,7 @@ const version_status = @import("version_status.zig");
const update_target = @import("update_target.zig");
const archive = @import("update_archive.zig");
const credential_store = @import("credential_store.zig");
+const beta_feed = @import("beta_feed.zig");
pub const FetchError = error{ Offline, Malformed, Permission, OutOfMemory };
@@ -83,6 +84,7 @@ pub const Opts = struct {
target_path: []const u8,
asset_name: []const u8,
fetch: Fetch,
+ channel: enum { stable, beta } = .stable,
cancel: ?*const std.atomic.Value(bool) = null,
};
@@ -125,6 +127,29 @@ fn fetchOwned(opts: Opts, url: []const u8) FetchError![]u8 {
}
fn latestFromFetch(opts: Opts) FetchError![]u8 {
+ if (opts.channel == .beta) {
+ const branches = try fetchOwned(opts, beta_feed.branches_url);
+ defer opts.gpa.free(branches);
+ const branch = beta_feed.newestBranch(branches, opts.gpa) orelse return error.Malformed;
+ defer opts.gpa.free(branch);
+ var best: ?[]u8 = null;
+ errdefer if (best) |b| opts.gpa.free(b);
+ for (1..11) |page| {
+ const url = if (page == 1) beta_feed.releases_url else std.fmt.allocPrint(opts.gpa, "{s}&page={d}", .{ beta_feed.releases_url, page }) catch return error.OutOfMemory;
+ defer if (page != 1) opts.gpa.free(url);
+ const releases = try fetchOwned(opts, url);
+ defer opts.gpa.free(releases);
+ const count = beta_feed.releaseCount(releases, opts.gpa) orelse return error.Malformed;
+ if (beta_feed.newestRelease(releases, branch, opts.gpa)) |candidate| {
+ if (best == null or beta_feed.compareTags(candidate, best.?).? == .gt) {
+ if (best) |b| opts.gpa.free(b);
+ best = candidate;
+ } else opts.gpa.free(candidate);
+ }
+ if (count < 100) return best orelse error.Malformed;
+ }
+ return error.Malformed; // Incomplete feed: never guess at an older beta.
+ }
const body = fetchOwned(opts, version_status.repo_api) catch |err| return err;
defer opts.gpa.free(body);
var tag_buf: [64]u8 = undefined;
@@ -154,9 +179,35 @@ pub fn inspect(opts: Opts) Report {
}, null, installed, "could not reach the release feed");
defer opts.gpa.free(tag);
- const run = version_status.compare(opts.running_version, tag);
+ // The stable comparison parser accepts numeric tags, while beta tags add
+ // two run components. Compare stable versions against the beta's base and
+ // compare beta-to-beta versions with the full tag below.
+ const numeric_tag = if (opts.channel == .beta)
+ tag[0..(std.mem.indexOf(u8, tag, "-beta.") orelse return snapshot(opts, .malformed, tag, installed, "unparseable beta tag"))]
+ else
+ tag;
+ const run = version_status.compare(opts.running_version, numeric_tag);
if (run.failure == .latest_tag) return snapshot(opts, .malformed, tag, installed, "unparseable release tag");
+ if (opts.channel == .beta) {
+ // A stable build at the same base version is newer than its beta.
+ // An identical beta (running or installed) needs no replacement.
+ if (installed) |inst| {
+ if (std.mem.eql(u8, version_status.stripV(std.mem.trim(u8, inst, " \t\r\n")), version_status.stripV(tag)))
+ return snapshot(opts, .already_installed, tag, inst, "the install target is already at this beta");
+ const disk = version_status.compare(std.mem.trim(u8, inst, " \t\r\n"), numeric_tag);
+ const disk_beta = beta_feed.compareTags(std.mem.trim(u8, inst, " \t\r\n"), tag);
+ if (disk.order == .gt or (disk.order == .eq and disk.clean_release) or
+ (disk_beta != null and disk_beta.? == .gt))
+ return snapshot(opts, .newer, tag, inst, "installed version is newer than this beta");
+ }
+ const run_beta = beta_feed.compareTags(opts.running_version, tag);
+ if (run.order == .gt or (run.order == .eq and run.clean_release) or
+ (run_beta != null and run_beta.? == .gt))
+ return snapshot(opts, .newer, tag, installed, "running version is newer than this beta");
+ return snapshot(opts, .available, tag, installed, "");
+ }
+
if (installed) |inst| {
if (version_status.alreadyHasRelease(inst, tag))
return snapshot(opts, .already_installed, tag, inst, "the install target is already at this release");
diff --git a/src/update_target.zig b/src/update_target.zig
index be27a254..4e0a955a 100644
--- a/src/update_target.zig
+++ b/src/update_target.zig
@@ -83,6 +83,7 @@ pub fn classify(path: []const u8, home: []const u8) Kind {
if (contains(path, "/snap/") or contains(path, "/flatpak/") or
contains(path, "/var/lib/flatpak/"))
return .package_managed;
+ if (contains(path, ".app/Contents/")) return .package_managed;
if (contains(path, "/opt/local/")) return .package_managed;
if (std.mem.startsWith(u8, path, "/usr/bin/") or
std.mem.startsWith(u8, path, "/bin/") or
@@ -149,6 +150,7 @@ test "classify: package trees and zig-out never look supported" {
try std.testing.expectEqual(Kind.package_managed, classify("/usr/local/Cellar/graff/0.1/bin/graff", "/Users/me"));
try std.testing.expectEqual(Kind.package_managed, classify("/nix/store/aaa/bin/graff", "/home/me"));
try std.testing.expectEqual(Kind.package_managed, classify("/usr/bin/graff", "/home/me"));
+ try std.testing.expectEqual(Kind.package_managed, classify("/Applications/Codegraff.app/Contents/Resources/graff", "/Users/me"));
try std.testing.expectEqual(Kind.development, classify("/work/codegraff/zig-out/bin/graff", "/home/me"));
try std.testing.expectEqual(Kind.supported, classify("/home/me/bin/graff", "/home/me"));
try std.testing.expectEqual(Kind.supported, classify("/home/me/.local/bin/graff", "/home/me"));
diff --git a/src/update_tests.zig b/src/update_tests.zig
index f0287ffc..54f219cd 100644
--- a/src/update_tests.zig
+++ b/src/update_tests.zig
@@ -23,6 +23,8 @@ const Fixture = struct {
fetches: std.atomic.Value(usize) = .init(0),
cancel_on_tarball: ?*std.atomic.Value(bool) = null,
hold: ?*std.atomic.Value(bool) = null,
+ beta: bool = false,
+ seen_beta_tag: bool = false,
fn get(ctx: ?*anyopaque, gpa: Allocator, url: []const u8) update_service.FetchError![]u8 {
const self: *Fixture = @ptrCast(@alignCast(ctx orelse return error.Offline));
@@ -31,6 +33,12 @@ const Fixture = struct {
while (h.load(.acquire)) std.Thread.yield() catch {};
}
if (self.fail == .offline) return error.Offline;
+ if (self.beta and std.mem.indexOf(u8, url, "/matching-refs/heads/release/v") != null)
+ return gpa.dupe(u8, "[{\"ref\":\"refs/heads/release/v0.0.302.6\"}]") catch return error.OutOfMemory;
+ if (self.beta and std.mem.indexOf(u8, url, "/releases?per_page=100") != null)
+ return gpa.dupe(u8, "[{\"tag_name\":\"v0.0.302.6-beta.26.1\",\"draft\":false,\"prerelease\":true}]") catch return error.OutOfMemory;
+ if (self.beta and std.mem.indexOf(u8, url, "/releases/download/v0.0.302.6-beta.26.1/") != null)
+ self.seen_beta_tag = true;
if (std.mem.indexOf(u8, url, "/releases/latest") != null) {
if (self.fail == .malformed) return gpa.dupe(u8, "{nope") catch return error.OutOfMemory;
return gpa.dupe(u8, latest_json) catch return error.OutOfMemory;
@@ -60,6 +68,58 @@ fn setupArchive(gpa: Allocator) !struct { bytes: []u8, sums: []u8 } {
return .{ .bytes = bytes, .sums = try archive.sumsLine(gpa, asset, bytes) };
}
+test "beta update downloads only pinned verified assets and installs for next launch" {
+ const io = std.testing.io;
+ const gpa = std.testing.allocator;
+ update_service.resetBusyForTest();
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(io, .{ .sub_path = "graff", .data = "OLD" });
+ const target = try fixturePath(&tmp, io, gpa, "graff");
+ defer gpa.free(target);
+ const pack = try setupArchive(gpa);
+ defer gpa.free(pack.bytes);
+ defer gpa.free(pack.sums);
+ var fx: Fixture = .{ .archive = pack.bytes, .sums = pack.sums, .beta = true };
+ var options = opts(io, gpa, target, fx.fetch(), null);
+ options.running_version = "0.0.302.5";
+ options.channel = .beta;
+ const report = update_service.install(options, .human);
+ try std.testing.expectEqual(update_service.Kind.installed, report.kind);
+ try std.testing.expectEqualStrings("v0.0.302.6-beta.26.1", report.latest_tag().?);
+ try std.testing.expect(fx.seen_beta_tag);
+ try std.testing.expect(!fx.seen_latest_download.load(.acquire));
+ const after = try Io.Dir.cwd().readFileAlloc(io, target, gpa, .limited(64));
+ defer gpa.free(after);
+ try std.testing.expectEqualStrings("NEW-GRAFF", after);
+}
+
+test "stable at the beta base is not downgraded, and beta does not block stable" {
+ const gpa = std.testing.allocator;
+ const io = std.testing.io;
+ update_service.resetBusyForTest();
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(io, .{ .sub_path = "graff", .data = "STABLE" });
+ const target = try fixturePath(&tmp, io, gpa, "graff");
+ defer gpa.free(target);
+ const pack = try setupArchive(gpa);
+ defer gpa.free(pack.bytes);
+ defer gpa.free(pack.sums);
+ var fx: Fixture = .{ .archive = pack.bytes, .sums = pack.sums, .beta = true };
+ var options = opts(io, gpa, target, fx.fetch(), null);
+ options.running_version = "0.0.302.6";
+ options.channel = .beta;
+ try std.testing.expectEqual(update_service.Kind.newer, update_service.inspect(options).kind);
+ try std.testing.expect(!@import("version_status.zig").alreadyHasRelease("0.0.302.6-beta.26.1", "v0.0.302.6"));
+ update_service.writeInstalledVersion(io, target, "0.0.302.6-beta.27.1");
+ options.running_version = "0.0.302.5";
+ try std.testing.expectEqual(update_service.Kind.newer, update_service.install(options, .human).kind);
+ const unchanged = try Io.Dir.cwd().readFileAlloc(io, target, gpa, .limited(64));
+ defer gpa.free(unchanged);
+ try std.testing.expectEqualStrings("STABLE", unchanged);
+}
+
fn fixturePath(tmp: *std.testing.TmpDir, io: Io, gpa: Allocator, name: []const u8) ![]u8 {
var buf: [std.fs.max_path_bytes]u8 = undefined;
const n = try tmp.dir.realPath(io, &buf);
diff --git a/src/version_status.zig b/src/version_status.zig
index 10cc8dd2..b8934f73 100644
--- a/src/version_status.zig
+++ b/src/version_status.zig
@@ -126,7 +126,8 @@ pub fn alreadyHasRelease(installed_version: []const u8, latest_tag: []const u8)
const check = compare(installed_version, latest_tag);
return switch (check.state) {
.current, .newer => true,
- .dev => check.order == .gt or check.order == .eq,
+ // A prerelease at the same numeric base is still older than stable.
+ .dev => check.order == .gt,
.older, .unable => false,
};
}