create-freeholder 0.2.0-beta.4 → 0.2.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/template/.changeset/native-linux-install.md +6 -0
- package/dist/template/.changeset/public-beta-5.md +4 -0
- package/dist/template/.github/ISSUE_TEMPLATE/bug_report.yml +1 -1
- package/dist/template/.github/workflows/release-tarballs.yml +117 -0
- package/dist/template/AGENTS.md +15 -2
- package/dist/template/Dockerfile +3 -0
- package/dist/template/MASTER.md +34 -4
- package/dist/template/README.md +1 -1
- package/dist/template/deploy/README.md +26 -9
- package/dist/template/deploy/docker-selfhost/.env.example +11 -1
- package/dist/template/deploy/docker-selfhost/README.md +78 -50
- package/dist/template/deploy/docker-selfhost/infra/backup.sh +81 -0
- package/dist/template/deploy/docker-selfhost/infra/compose.https.yml +37 -1
- package/dist/template/deploy/docker-selfhost/infra/compose.yml +37 -1
- package/dist/template/deploy/docker-selfhost/migrate.md +8 -5
- package/dist/template/deploy/docker-selfhost/recipe.yaml +9 -10
- package/dist/template/deploy/docker-selfhost/selfhost.sh +206 -0
- package/dist/template/deploy/docker-selfhost/verify.md +11 -4
- package/dist/template/deploy/f-criteria-matrix.md +15 -0
- package/dist/template/deploy/linux/.env.example +28 -0
- package/dist/template/deploy/linux/README.md +181 -0
- package/dist/template/deploy/linux/freeholder +655 -0
- package/dist/template/deploy/linux/install.sh +173 -0
- package/dist/template/deploy/linux/migrate.md +17 -0
- package/dist/template/deploy/linux/recipe.yaml +50 -0
- package/dist/template/deploy/linux/share/Caddyfile.template +19 -0
- package/dist/template/deploy/linux/share/systemd/freeholder-backup.service +13 -0
- package/dist/template/deploy/linux/share/systemd/freeholder-backup.timer +12 -0
- package/dist/template/deploy/linux/share/systemd/freeholder.service +41 -0
- package/dist/template/deploy/linux/verify.md +22 -0
- package/dist/template/gitignore.template +1 -0
- package/dist/template/package.json +3 -2
- package/dist/template/packages/cli/package.json +1 -1
- package/dist/template/packages/create-freeholder/package.json +1 -1
- package/dist/template/packages/freeholder-app/package.json +1 -1
- package/dist/template/packages/mobile-app/package.json +1 -1
- package/dist/template/packages/plugin-kit/package.json +1 -1
- package/dist/template/packages/sdk/package.json +1 -1
- package/dist/template/packages/sdk/src/version.ts +1 -1
- package/dist/template/packages/templates/package.json +1 -1
- package/dist/template/scripts/build-release.d.mts +4 -0
- package/dist/template/scripts/build-release.mjs +171 -0
- package/dist/template/scripts/launch-prepare.mjs +6 -3
- package/dist/template/scripts/recipe-matrix.sh +22 -7
- package/dist/template/security/adversarial-audit-2026-10-08.md +1 -1
- package/dist/template/src/adapters/storage/local-mode.ts +54 -0
- package/dist/template/src/adapters/storage/local.ts +53 -26
- package/dist/template/src/core/doctor/index.ts +19 -10
- package/dist/template/src/core/env.ts +6 -1
- package/dist/template/src/core/update/preflight.ts +3 -2
- package/dist/template/src/core/update/release-declaration.json +1 -1
- package/dist/template/src/core/update/service.ts +7 -17
- package/dist/template/tests/core/agent-launch.test.ts +7 -2
- package/dist/template/tests/core/client-readiness-security.test.ts +3 -1
- package/dist/template/tests/core/deploy-recipe.test.ts +54 -4
- package/dist/template/tests/core/linux-install.test.ts +169 -0
- package/dist/template/tests/core/local-storage-mode.test.ts +29 -0
- package/dist/template/tests/core/storage.test.ts +38 -2
- package/dist/template-manifest.json +168 -63
- package/package.json +1 -1
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// Copyright (C) 2026 Tony Aly
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// C3.44: the no-Docker Linux install. These files are shell and systemd, not
|
|
4
|
+
// imported by anything, so the properties an owner relies on are pinned here.
|
|
5
|
+
// The installer itself runs end to end in .github/workflows/release-tarballs.yml.
|
|
6
|
+
import { execFileSync } from "node:child_process";
|
|
7
|
+
import { readFileSync } from "node:fs";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { describe, expect, it } from "vitest";
|
|
10
|
+
import { parse } from "yaml";
|
|
11
|
+
import { releaseArch, releaseName } from "../../scripts/build-release.mjs";
|
|
12
|
+
|
|
13
|
+
const LINUX = join("deploy", "linux");
|
|
14
|
+
const read = (path: string) => readFileSync(path, "utf8");
|
|
15
|
+
const version = (JSON.parse(read("package.json")) as { version: string }).version;
|
|
16
|
+
|
|
17
|
+
describe("the release version is the one every manual install names", () => {
|
|
18
|
+
// Release preparation bumps package.json; this makes it bump the documented
|
|
19
|
+
// install too, so a downloaded install.sh installs its own release and the
|
|
20
|
+
// Docker recipe defaults to it rather than to `edge`.
|
|
21
|
+
it("install.sh, the Compose defaults and the copyable blocks agree with package.json", () => {
|
|
22
|
+
expect(read(join(LINUX, "install.sh"))).toContain(`FREEHOLDER_VERSION_DEFAULT="${version}"`);
|
|
23
|
+
for (const file of ["compose.yml", "compose.https.yml"]) {
|
|
24
|
+
expect(read(join("deploy/docker-selfhost/infra", file))).toContain(`ghcr.io/campdenman/freeholder:${version}}`);
|
|
25
|
+
}
|
|
26
|
+
const download = `https://github.com/CampDenman/freeholder/releases/download/v${version}/install.sh`;
|
|
27
|
+
expect(read("GETTING_STARTED.md")).toContain(download);
|
|
28
|
+
expect(read(join(LINUX, "README.md"))).toContain(download);
|
|
29
|
+
expect(read("deploy/docker-selfhost/README.md")).toContain(`--branch v${version} `);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe("install.sh", () => {
|
|
34
|
+
const script = read(join(LINUX, "install.sh"));
|
|
35
|
+
|
|
36
|
+
it("is POSIX sh that dash parses, and stops at the first error", () => {
|
|
37
|
+
expect(script.startsWith("#!/bin/sh\n")).toBe(true);
|
|
38
|
+
expect(script).toMatch(/^set -eu$/m);
|
|
39
|
+
execFileSync("sh", ["-n", join(LINUX, "install.sh")]);
|
|
40
|
+
execFileSync("sh", ["-n", join(LINUX, "freeholder")]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("verifies the tarball's SHA-256 before unpacking anything", () => {
|
|
44
|
+
const verify = script.indexOf('[ "$expected" = "$actual" ]');
|
|
45
|
+
expect(verify).toBeGreaterThan(0);
|
|
46
|
+
expect(script.indexOf("tar -xzf")).toBeGreaterThan(verify);
|
|
47
|
+
expect(script).toContain("checksum mismatch");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("installs PostgreSQL 15+ and Caddy from distribution or official repositories only", () => {
|
|
51
|
+
expect(script).toContain("/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh");
|
|
52
|
+
expect(script).toContain("https://dl.cloudsmith.io/public/caddy/stable/gpg.key");
|
|
53
|
+
expect(script).not.toMatch(/curl[^\n]*\|\s*(sh|bash)\b/);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("unpacks into a versioned, root-owned release with a current symlink", () => {
|
|
57
|
+
expect(script).toContain('release="/opt/freeholder/releases/${version}"');
|
|
58
|
+
expect(script).toContain('chown -R root:root "$release.partial"');
|
|
59
|
+
expect(script).toContain("mv -T /opt/freeholder/current.new /opt/freeholder/current");
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe("the freeholder operator command", () => {
|
|
64
|
+
const command = read(join(LINUX, "freeholder"));
|
|
65
|
+
|
|
66
|
+
it("generates secrets with openssl and keeps them private", () => {
|
|
67
|
+
expect(command).toContain("openssl rand -hex 32");
|
|
68
|
+
for (const name of ["BOOTSTRAP_SECRET", "SESSION_SECRET", "CREDENTIAL_KEY", "POSTGRES_PASSWORD"]) {
|
|
69
|
+
expect(command).toContain(`ensure_secret ${name}`);
|
|
70
|
+
}
|
|
71
|
+
expect(command).toContain('chown root:freeholder "$tmp"');
|
|
72
|
+
expect(command).toContain('chmod 640 "$tmp"');
|
|
73
|
+
// The database password goes to psql on stdin, never on a command line.
|
|
74
|
+
expect(command).toMatch(/psql -v ON_ERROR_STOP=1 -qtA postgres\) <<SQL/);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("defaults to local media in the data directory, outside the replaceable release", () => {
|
|
78
|
+
expect(command).toContain("env_set FREEHOLDER_STORAGE local");
|
|
79
|
+
expect(command).toContain('env_set LOCAL_STORAGE_ROOT "$MEDIA"');
|
|
80
|
+
expect(command).toContain("MEDIA=$DATA/media");
|
|
81
|
+
expect(command).toContain("DATA=/var/lib/freeholder");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("backs up a custom-format dump and the media with checksums, and restores into a scratch database", () => {
|
|
85
|
+
expect(command).toContain("pg_dump --format=custom --no-owner --no-privileges freeholder");
|
|
86
|
+
expect(command).toContain("media.tar.gz");
|
|
87
|
+
expect(command).toContain("sha256sum ./* > SHA256SUMS");
|
|
88
|
+
expect(command).toContain("sha256sum --quiet -c SHA256SUMS");
|
|
89
|
+
expect(command).toMatch(/pg_restore [^\n]*-d freeholder_restore/);
|
|
90
|
+
expect(command).not.toMatch(/^\s*[^#\n]*--clean/m);
|
|
91
|
+
// A restore takes a safety backup before it changes anything.
|
|
92
|
+
const restore = command.slice(command.indexOf("cmd_restore() {"));
|
|
93
|
+
expect(restore.indexOf('cmd_backup --reason "before-restore"')).toBeLessThan(restore.indexOf("restore_database"));
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("updates only to a verified release, backs up first, and rolls back the release and database on failure", () => {
|
|
97
|
+
const update = command.slice(command.indexOf("cmd_update() {"), command.indexOf("rollback_to() {"));
|
|
98
|
+
expect(command).toContain('[ -n "$expected" ] && [ "$expected" = "$actual" ]');
|
|
99
|
+
expect(update.indexOf("fetch_release")).toBeLessThan(update.indexOf("cmd_backup"));
|
|
100
|
+
expect(update.indexOf("cmd_backup")).toBeLessThan(update.indexOf("switch_to"));
|
|
101
|
+
expect(update).toContain('rollback_to "$from" "$backup"');
|
|
102
|
+
const rollback = command.slice(command.indexOf("rollback_to() {"));
|
|
103
|
+
expect(rollback).toContain('restore_database "$BACKUPS/$2/database.dump"');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("prints the claim link only to the operator's terminal", () => {
|
|
107
|
+
expect(command).toContain("printf '%s/setup#claim=%s\\n'");
|
|
108
|
+
expect(command).toMatch(/cmd_claim_link\(\) \{\n need_root claim-link/);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("starts on an sslip.io address when DNS is not ready, the same naming as the CLI", () => {
|
|
112
|
+
expect(command).toContain("sslip_host()");
|
|
113
|
+
expect(command).toContain("tr . -");
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe("systemd and Caddy", () => {
|
|
118
|
+
it("runs as the freeholder user with a read-only release and only the data directory writable", () => {
|
|
119
|
+
const unit = read(join(LINUX, "share/systemd/freeholder.service"));
|
|
120
|
+
expect(unit).toMatch(/^User=freeholder$/m);
|
|
121
|
+
expect(unit).toMatch(/^ProtectSystem=strict$/m);
|
|
122
|
+
expect(unit).toMatch(/^ReadWritePaths=\/var\/lib\/freeholder$/m);
|
|
123
|
+
expect(unit).toMatch(/HOSTNAME=127\.0\.0\.1/);
|
|
124
|
+
expect(unit).toMatch(/^ExecStart=\/opt\/freeholder\/current\/runtime\/node\/bin\/node server\.js$/m);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("backs up nightly, catching up after downtime", () => {
|
|
128
|
+
const timer = read(join(LINUX, "share/systemd/freeholder-backup.timer"));
|
|
129
|
+
expect(timer).toMatch(/^OnCalendar=\*-\*-\* 03:15:00$/m);
|
|
130
|
+
expect(timer).toMatch(/^Persistent=true$/m);
|
|
131
|
+
expect(read(join(LINUX, "share/systemd/freeholder-backup.service"))).toContain("freeholder backup --scheduled");
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("the Caddyfile overwrites the trusted client header and refuses the image optimizer", () => {
|
|
135
|
+
const caddy = read(join(LINUX, "share/Caddyfile.template"));
|
|
136
|
+
expect(caddy).toContain("reverse_proxy 127.0.0.1:3000");
|
|
137
|
+
expect(caddy).toMatch(/header_up X-Freeholder-Client-Ip \{client_ip\}/);
|
|
138
|
+
expect(caddy).toMatch(/@nextImage path \/_next\/image \/_next\/image\/\*\n\s*respond @nextImage 404/);
|
|
139
|
+
expect(read(join(LINUX, "freeholder"))).toContain("env_set TRUSTED_CLIENT_IP_HEADER x-freeholder-client-ip");
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe("the recipe", () => {
|
|
144
|
+
it("is a complete recipe whose artifacts exist", () => {
|
|
145
|
+
const recipe = parse(read(join(LINUX, "recipe.yaml"))) as { name: string; artifacts: string[]; operations: Record<string, string> };
|
|
146
|
+
expect(recipe.name).toBe("linux");
|
|
147
|
+
for (const artifact of recipe.artifacts) expect(() => read(artifact)).not.toThrow();
|
|
148
|
+
for (const operation of ["install", "verify", "backup", "restore", "update", "rollback"]) {
|
|
149
|
+
expect(recipe.operations[operation]).toBeTruthy();
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
describe("release tarball naming", () => {
|
|
155
|
+
it("names one tarball per version and architecture", () => {
|
|
156
|
+
expect(releaseName("0.2.0-beta.5", "x64")).toBe("freeholder-0.2.0-beta.5-linux-x64");
|
|
157
|
+
expect(releaseName("1.0.0", "arm64")).toBe("freeholder-1.0.0-linux-arm64");
|
|
158
|
+
expect(() => releaseArch("ia32")).toThrow(/x64 and arm64/);
|
|
159
|
+
expect(() => releaseName("latest", "x64")).toThrow(/release version/);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("is built and installed for both architectures before a release gets it", () => {
|
|
163
|
+
const workflow = read(".github/workflows/release-tarballs.yml");
|
|
164
|
+
expect(workflow).toContain("runner: ubuntu-24.04-arm");
|
|
165
|
+
expect(workflow).toContain("sudo sh dist/release/install.sh --tarball");
|
|
166
|
+
expect(workflow).toContain("sudo freeholder restore latest");
|
|
167
|
+
expect(workflow).toContain("actions/attest-build-provenance@");
|
|
168
|
+
});
|
|
169
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright (C) 2026 Tony Aly
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// C3.44: one rule for when production media may live on local disk.
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
import { describeLocalStorage, localStorageMode } from "@/adapters/storage/local-mode";
|
|
6
|
+
|
|
7
|
+
describe("local storage mode", () => {
|
|
8
|
+
it("is development outside production", () => {
|
|
9
|
+
expect(localStorageMode({ NODE_ENV: "development" })).toBe("development");
|
|
10
|
+
expect(localStorageMode({ NODE_ENV: "test", LOCAL_STORAGE_ROOT: "relative" })).toBe("development");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("accepts only an absolute directory in production, and still honours the legacy override", () => {
|
|
14
|
+
expect(localStorageMode({ NODE_ENV: "production", LOCAL_STORAGE_ROOT: "/var/lib/freeholder/media" })).toBe("persistent");
|
|
15
|
+
expect(localStorageMode({ NODE_ENV: "production", LOCAL_STORAGE_ROOT: ".data/media" })).toBe("refused");
|
|
16
|
+
expect(localStorageMode({ NODE_ENV: "production" })).toBe("refused");
|
|
17
|
+
expect(localStorageMode({ NODE_ENV: "production", FREEHOLDER_UNSAFE_LOCAL_STORAGE: "1" })).toBe("unsafe");
|
|
18
|
+
// The playground's disposable tmpfs: the override wins, so the directory
|
|
19
|
+
// is still created on demand rather than required to exist.
|
|
20
|
+
expect(localStorageMode({ NODE_ENV: "production", FREEHOLDER_UNSAFE_LOCAL_STORAGE: "1", LOCAL_STORAGE_ROOT: "/tmp/media" })).toBe("unsafe");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("tells the owner where the media is and that backups must include it", () => {
|
|
24
|
+
const detail = describeLocalStorage({ NODE_ENV: "production", LOCAL_STORAGE_ROOT: "/var/lib/freeholder/media" });
|
|
25
|
+
expect(detail).toContain("/var/lib/freeholder/media");
|
|
26
|
+
expect(detail).toMatch(/backup/i);
|
|
27
|
+
expect(describeLocalStorage({ NODE_ENV: "production" })).toMatch(/lose/);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -291,7 +291,7 @@ describe("the local adapter refuses production (§18 storage mandate)", () => {
|
|
|
291
291
|
// is the least recoverable thing a business owns, so this fails loudly at
|
|
292
292
|
// boot instead of at restore time.
|
|
293
293
|
withEnv(
|
|
294
|
-
{ NODE_ENV: "production", FREEHOLDER_UNSAFE_LOCAL_STORAGE: undefined },
|
|
294
|
+
{ NODE_ENV: "production", FREEHOLDER_UNSAFE_LOCAL_STORAGE: undefined, LOCAL_STORAGE_ROOT: undefined },
|
|
295
295
|
() => {
|
|
296
296
|
expect(() =>
|
|
297
297
|
createLocalStorage({ root: ".data/media", publicPath: "/media" }),
|
|
@@ -302,13 +302,14 @@ describe("the local adapter refuses production (§18 storage mandate)", () => {
|
|
|
302
302
|
|
|
303
303
|
it("names the way out, so the error is actionable", () => {
|
|
304
304
|
withEnv(
|
|
305
|
-
{ NODE_ENV: "production", FREEHOLDER_UNSAFE_LOCAL_STORAGE: undefined },
|
|
305
|
+
{ NODE_ENV: "production", FREEHOLDER_UNSAFE_LOCAL_STORAGE: undefined, LOCAL_STORAGE_ROOT: undefined },
|
|
306
306
|
() => {
|
|
307
307
|
try {
|
|
308
308
|
createLocalStorage({ root: ".data/media", publicPath: "/media" });
|
|
309
309
|
} catch (error) {
|
|
310
310
|
const message = (error as Error).message;
|
|
311
311
|
expect(message).toContain("freeholder.config.ts");
|
|
312
|
+
expect(message).toContain("LOCAL_STORAGE_ROOT");
|
|
312
313
|
expect(message).toContain("FREEHOLDER_UNSAFE_LOCAL_STORAGE=1");
|
|
313
314
|
}
|
|
314
315
|
},
|
|
@@ -326,6 +327,41 @@ describe("the local adapter refuses production (§18 storage mandate)", () => {
|
|
|
326
327
|
);
|
|
327
328
|
});
|
|
328
329
|
|
|
330
|
+
it("accepts an explicit, existing persistent directory in production (C3.44)", async () => {
|
|
331
|
+
const persistent = await mkdtemp(join(tmpdir(), "freeholder-persistent-"));
|
|
332
|
+
try {
|
|
333
|
+
withEnv(
|
|
334
|
+
{ NODE_ENV: "production", FREEHOLDER_UNSAFE_LOCAL_STORAGE: undefined, LOCAL_STORAGE_ROOT: persistent },
|
|
335
|
+
() => {
|
|
336
|
+
const adapter = createLocalStorage({ root: persistent, publicPath: "/media" });
|
|
337
|
+
// Served only through the app's /media route, which re-checks access.
|
|
338
|
+
expect(adapter.isPublic).toBe(false);
|
|
339
|
+
},
|
|
340
|
+
);
|
|
341
|
+
} finally {
|
|
342
|
+
await rm(persistent, { recursive: true, force: true });
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it("refuses a persistent directory that does not exist, instead of creating it in the container layer", () => {
|
|
347
|
+
const missing = join(tmpdir(), `freeholder-missing-${Date.now()}`);
|
|
348
|
+
withEnv(
|
|
349
|
+
{ NODE_ENV: "production", FREEHOLDER_UNSAFE_LOCAL_STORAGE: undefined, LOCAL_STORAGE_ROOT: missing },
|
|
350
|
+
() => {
|
|
351
|
+
expect(() => createLocalStorage({ root: missing, publicPath: "/media" })).toThrow(/existing directory/);
|
|
352
|
+
},
|
|
353
|
+
);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it("still refuses a relative directory in production", () => {
|
|
357
|
+
withEnv(
|
|
358
|
+
{ NODE_ENV: "production", FREEHOLDER_UNSAFE_LOCAL_STORAGE: undefined, LOCAL_STORAGE_ROOT: ".data/media" },
|
|
359
|
+
() => {
|
|
360
|
+
expect(() => createLocalStorage({ root: ".data/media", publicPath: "/media" })).toThrow(/LOCAL_STORAGE_ROOT/);
|
|
361
|
+
},
|
|
362
|
+
);
|
|
363
|
+
});
|
|
364
|
+
|
|
329
365
|
it("says nothing outside production", () => {
|
|
330
366
|
withEnv({ NODE_ENV: "development" }, () => {
|
|
331
367
|
expect(() =>
|