-
Notifications
You must be signed in to change notification settings - Fork 276
Expand file tree
/
Copy pathupdate-homebrew-formula.test.ts
More file actions
92 lines (84 loc) · 3.03 KB
/
Copy pathupdate-homebrew-formula.test.ts
File metadata and controls
92 lines (84 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { describe, expect, test } from "bun:test";
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
const ASSETS = [
"hunkdiff-darwin-arm64.tar.gz",
"hunkdiff-darwin-x64.tar.gz",
"hunkdiff-linux-arm64.tar.gz",
"hunkdiff-linux-x64.tar.gz",
] as const;
/** Create minimal release asset placeholders for formula checksum generation. */
function createTestAssets(assetRoot: string) {
for (const asset of ASSETS) {
writeFileSync(path.join(assetRoot, asset), `contents for ${asset}`);
}
}
describe("update-homebrew-formula", () => {
test("rejects unsafe repository slugs before writing Ruby formula URLs", () => {
const root = mkdtempSync(path.join(tmpdir(), "hunk-homebrew-formula-"));
const assetRoot = path.join(root, "assets");
const outputRoot = path.join(root, "tap");
try {
mkdirSync(assetRoot, { recursive: true });
createTestAssets(assetRoot);
const proc = Bun.spawnSync(
[
"bun",
"run",
path.resolve(import.meta.dir, "update-homebrew-formula.ts"),
"--tag",
"v1.2.3",
"--asset-root",
assetRoot,
"--output-root",
outputRoot,
"--repo",
'modem-dev/hunk"; system("echo owned") #',
],
{ stdout: "pipe", stderr: "pipe" },
);
expect(proc.exitCode).not.toBe(0);
expect(proc.stderr.toString()).toContain("Invalid GitHub repository slug");
} finally {
rmSync(root, { recursive: true, force: true });
}
});
test("writes a formula that installs the binary through the Homebrew update-notice wrapper", () => {
const root = mkdtempSync(path.join(tmpdir(), "hunk-homebrew-formula-"));
const assetRoot = path.join(root, "assets");
const outputRoot = path.join(root, "tap");
try {
mkdirSync(assetRoot, { recursive: true });
createTestAssets(assetRoot);
const proc = Bun.spawnSync(
[
"bun",
"run",
path.resolve(import.meta.dir, "update-homebrew-formula.ts"),
"--tag",
"v1.2.3",
"--asset-root",
assetRoot,
"--output-root",
outputRoot,
],
{ stdout: "pipe", stderr: "pipe" },
);
expect(proc.exitCode).toBe(0);
const formula = readFileSync(path.join(outputRoot, "Formula", "hunk.rb"), "utf8");
expect(formula).toContain('version "1.2.3"');
expect(formula).toContain("hunkdiff-darwin-arm64.tar.gz");
expect(formula).toContain("hunkdiff-linux-x64.tar.gz");
expect(formula).toContain('chmod 0755, "hunk"');
expect(formula).toContain('libexec.install "hunk"');
expect(formula).toContain('libexec.install "kitty"');
expect(formula).toContain('libexec.install "skills"');
expect(formula).toContain(
'(bin/"hunk").write_env_script libexec/"hunk", HUNK_INSTALL_SOURCE: "homebrew"',
);
} finally {
rmSync(root, { recursive: true, force: true });
}
});
});