|
| 1 | +/** |
| 2 | + * Homebrew formula generation tests. |
| 3 | + * |
| 4 | + * Validates that the brew formula template in publish.ts generates |
| 5 | + * correct Ruby syntax, URLs, version fields, and platform coverage. |
| 6 | + */ |
| 7 | +import { describe, test, expect } from "bun:test" |
| 8 | +import fs from "fs" |
| 9 | +import path from "path" |
| 10 | + |
| 11 | +const PUBLISH_SCRIPT = fs.readFileSync( |
| 12 | + path.resolve(import.meta.dir, "../../script/publish.ts"), |
| 13 | + "utf-8", |
| 14 | +) |
| 15 | + |
| 16 | +/** |
| 17 | + * Generate a brew formula using the same template logic as publish.ts, |
| 18 | + * but with test values substituted. |
| 19 | + */ |
| 20 | +function generateBrewFormula(opts: { |
| 21 | + version: string |
| 22 | + macX64Sha: string |
| 23 | + macArm64Sha: string |
| 24 | + x64Sha: string |
| 25 | + arm64Sha: string |
| 26 | +}): string { |
| 27 | + return [ |
| 28 | + "# typed: false", |
| 29 | + "# frozen_string_literal: true", |
| 30 | + "", |
| 31 | + "class AltimateCode < Formula", |
| 32 | + ` desc "The AI coding agent built for the terminal."`, |
| 33 | + ` homepage "https://github.com/AltimateAI/altimate-code"`, |
| 34 | + ` version "${opts.version.split("-")[0]}"`, |
| 35 | + "", |
| 36 | + ` depends_on "ripgrep"`, |
| 37 | + "", |
| 38 | + " on_macos do", |
| 39 | + " if Hardware::CPU.intel?", |
| 40 | + ` url "https://github.com/AltimateAI/altimate-code/releases/download/v${opts.version}/altimate-code-darwin-x64.zip"`, |
| 41 | + ` sha256 "${opts.macX64Sha}"`, |
| 42 | + "", |
| 43 | + " def install", |
| 44 | + ' bin.install "altimate"', |
| 45 | + ' bin.install_symlink "altimate" => "altimate-code"', |
| 46 | + " end", |
| 47 | + " end", |
| 48 | + " if Hardware::CPU.arm?", |
| 49 | + ` url "https://github.com/AltimateAI/altimate-code/releases/download/v${opts.version}/altimate-code-darwin-arm64.zip"`, |
| 50 | + ` sha256 "${opts.macArm64Sha}"`, |
| 51 | + "", |
| 52 | + " def install", |
| 53 | + ' bin.install "altimate"', |
| 54 | + ' bin.install_symlink "altimate" => "altimate-code"', |
| 55 | + " end", |
| 56 | + " end", |
| 57 | + " end", |
| 58 | + "", |
| 59 | + " on_linux do", |
| 60 | + " if Hardware::CPU.intel? and Hardware::CPU.is_64_bit?", |
| 61 | + ` url "https://github.com/AltimateAI/altimate-code/releases/download/v${opts.version}/altimate-code-linux-x64.tar.gz"`, |
| 62 | + ` sha256 "${opts.x64Sha}"`, |
| 63 | + " def install", |
| 64 | + ' bin.install "altimate"', |
| 65 | + ' bin.install_symlink "altimate" => "altimate-code"', |
| 66 | + " end", |
| 67 | + " end", |
| 68 | + " if Hardware::CPU.arm? and Hardware::CPU.is_64_bit?", |
| 69 | + ` url "https://github.com/AltimateAI/altimate-code/releases/download/v${opts.version}/altimate-code-linux-arm64.tar.gz"`, |
| 70 | + ` sha256 "${opts.arm64Sha}"`, |
| 71 | + " def install", |
| 72 | + ' bin.install "altimate"', |
| 73 | + ' bin.install_symlink "altimate" => "altimate-code"', |
| 74 | + " end", |
| 75 | + " end", |
| 76 | + " end", |
| 77 | + "end", |
| 78 | + "", |
| 79 | + "", |
| 80 | + ].join("\n") |
| 81 | +} |
| 82 | + |
| 83 | +describe("brew formula template", () => { |
| 84 | + const formula = generateBrewFormula({ |
| 85 | + version: "0.4.9", |
| 86 | + macX64Sha: "abc123", |
| 87 | + macArm64Sha: "def456", |
| 88 | + x64Sha: "ghi789", |
| 89 | + arm64Sha: "jkl012", |
| 90 | + }) |
| 91 | + |
| 92 | + test("version field is clean semver without v prefix", () => { |
| 93 | + expect(formula).toContain('version "0.4.9"') |
| 94 | + expect(formula).not.toContain('version "v0.4.9"') |
| 95 | + }) |
| 96 | + |
| 97 | + test("URLs have exactly one v prefix", () => { |
| 98 | + const urls = formula.match(/url "([^"]+)"/g) || [] |
| 99 | + expect(urls.length).toBe(4) |
| 100 | + for (const url of urls) { |
| 101 | + expect(url).toContain("/download/v0.4.9/") |
| 102 | + expect(url).not.toContain("/download/vv0.4.9/") |
| 103 | + } |
| 104 | + }) |
| 105 | + |
| 106 | + test("all 4 platform variants are present", () => { |
| 107 | + expect(formula).toContain("altimate-code-darwin-x64.zip") |
| 108 | + expect(formula).toContain("altimate-code-darwin-arm64.zip") |
| 109 | + expect(formula).toContain("altimate-code-linux-x64.tar.gz") |
| 110 | + expect(formula).toContain("altimate-code-linux-arm64.tar.gz") |
| 111 | + }) |
| 112 | + |
| 113 | + test("macOS uses .zip format", () => { |
| 114 | + const macUrls = formula.match(/darwin-[^"]+/g) || [] |
| 115 | + for (const url of macUrls) { |
| 116 | + expect(url).toMatch(/\.zip$/) |
| 117 | + } |
| 118 | + }) |
| 119 | + |
| 120 | + test("Linux uses .tar.gz format", () => { |
| 121 | + const linuxUrls = formula.match(/linux-[^"]+/g) || [] |
| 122 | + for (const url of linuxUrls) { |
| 123 | + expect(url).toMatch(/\.tar\.gz$/) |
| 124 | + } |
| 125 | + }) |
| 126 | + |
| 127 | + test("SHA256 hashes are present for all platforms", () => { |
| 128 | + const shas = formula.match(/sha256 "[^"]+"/g) || [] |
| 129 | + expect(shas.length).toBe(4) |
| 130 | + }) |
| 131 | + |
| 132 | + test("depends on ripgrep", () => { |
| 133 | + expect(formula).toContain('depends_on "ripgrep"') |
| 134 | + }) |
| 135 | + |
| 136 | + test("installs altimate binary and creates altimate-code symlink", () => { |
| 137 | + const installLines = formula.match(/bin\.install "altimate"/g) || [] |
| 138 | + expect(installLines.length).toBe(4) // once per platform variant |
| 139 | + |
| 140 | + const symlinkLines = formula.match(/bin\.install_symlink "altimate" => "altimate-code"/g) || [] |
| 141 | + expect(symlinkLines.length).toBe(4) |
| 142 | + }) |
| 143 | + |
| 144 | + test("class name is AltimateCode", () => { |
| 145 | + expect(formula).toContain("class AltimateCode < Formula") |
| 146 | + }) |
| 147 | + |
| 148 | + test("has correct homepage", () => { |
| 149 | + expect(formula).toContain('homepage "https://github.com/AltimateAI/altimate-code"') |
| 150 | + }) |
| 151 | +}) |
| 152 | + |
| 153 | +describe("brew formula with pre-release version", () => { |
| 154 | + const formula = generateBrewFormula({ |
| 155 | + version: "1.0.0-beta.1", |
| 156 | + macX64Sha: "aaa", |
| 157 | + macArm64Sha: "bbb", |
| 158 | + x64Sha: "ccc", |
| 159 | + arm64Sha: "ddd", |
| 160 | + }) |
| 161 | + |
| 162 | + test("version field strips pre-release suffix", () => { |
| 163 | + expect(formula).toContain('version "1.0.0"') |
| 164 | + expect(formula).not.toContain('version "1.0.0-beta.1"') |
| 165 | + }) |
| 166 | + |
| 167 | + test("URLs include full pre-release version", () => { |
| 168 | + expect(formula).toContain("/download/v1.0.0-beta.1/") |
| 169 | + }) |
| 170 | +}) |
| 171 | + |
| 172 | +describe("publish.ts brew formula template matches test template", () => { |
| 173 | + test("publish.ts generates formula with same structure", () => { |
| 174 | + // Verify the template in publish.ts uses the same patterns we test |
| 175 | + expect(PUBLISH_SCRIPT).toContain("class AltimateCode < Formula") |
| 176 | + expect(PUBLISH_SCRIPT).toContain('depends_on "ripgrep"') |
| 177 | + expect(PUBLISH_SCRIPT).toContain('bin.install "altimate"') |
| 178 | + expect(PUBLISH_SCRIPT).toContain('bin.install_symlink "altimate" => "altimate-code"') |
| 179 | + expect(PUBLISH_SCRIPT).toContain("on_macos do") |
| 180 | + expect(PUBLISH_SCRIPT).toContain("on_linux do") |
| 181 | + expect(PUBLISH_SCRIPT).toContain("Hardware::CPU.intel?") |
| 182 | + expect(PUBLISH_SCRIPT).toContain("Hardware::CPU.arm?") |
| 183 | + }) |
| 184 | + |
| 185 | + test("publish.ts uses Script.version in URL construction", () => { |
| 186 | + // URLs must use v${Script.version} — not vv or raw tag |
| 187 | + expect(PUBLISH_SCRIPT).toContain("v${Script.version}/altimate-code-darwin-x64.zip") |
| 188 | + expect(PUBLISH_SCRIPT).toContain("v${Script.version}/altimate-code-darwin-arm64.zip") |
| 189 | + expect(PUBLISH_SCRIPT).toContain("v${Script.version}/altimate-code-linux-x64.tar.gz") |
| 190 | + expect(PUBLISH_SCRIPT).toContain("v${Script.version}/altimate-code-linux-arm64.tar.gz") |
| 191 | + }) |
| 192 | +}) |
0 commit comments