Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
feat(install): add release-pinned installer scripts (#189)
Kartikca1c83d295cc
diff --git a/.github/workflows/installer-tests.yml b/.github/workflows/installer-tests.ymlnew file mode 100644index 000000000..b2d9e4704--- /dev/null+++ b/.github/workflows/installer-tests.yml@@ -0,0 +1,27 @@+name: Installer tests++on:+ pull_request:+ paths:+ - "scripts/install-windows*"+ - ".github/workflows/installer-tests.yml"+ workflow_dispatch:++permissions:+ contents: read++concurrency:+ group: installer-tests-${{ github.event.pull_request.number || github.ref }}+ cancel-in-progress: true++jobs:+ windows:+ name: Windows installer behavior+ runs-on: windows-latest+ timeout-minutes: 10+ steps:+ - name: Checkout+ uses: actions/checkout@v6+ - name: Verify installer and Restricted-policy bootstrap+ shell: powershell+ run: powershell.exe -NoProfile -ExecutionPolicy Bypass -File scripts/install-windows.behavior.test.ps1diff --git a/docs/internals/ci.md b/docs/internals/ci.mdindex 8dcc8e7dc..28f29bcfe 100644--- a/docs/internals/ci.md+++ b/docs/internals/ci.md@@ -24,6 +24,11 @@ updates the pull request body after Tegami updates its branch, then dispatches CThis explicit dispatch is required because pushes made with the GitHub Actions token do not startanother pull-request workflow.+[`.github/workflows/installer-tests.yml`](../../.github/workflows/installer-tests.yml) runs focused+Windows PowerShell 5.1 tests when the Windows installer changes. It checks checksum rejection,+per-invocation temporary files, failure cleanup, and the bootstrap under Restricted execution policy.+Downloads and installer launches use fixtures; this job does not install Akeru Bot.+[`.github/workflows/release-smoke.yml`](../../.github/workflows/release-smoke.yml) is a manual,non-publishing artifact smoke workflow. It uses a 4-vCPU Tenki runner for Linux and GitHub-hostedApple Silicon macOS and Windows runners. It builds a Developer ID signed macOS arm64 app.diff --git a/scripts/install-linux.sh b/scripts/install-linux.shnew file mode 100755index 000000000..05152e16e--- /dev/null+++ b/scripts/install-linux.sh@@ -0,0 +1,88 @@+#!/usr/bin/env bash+#+# One-line Linux installer for Akeru Bot (x86_64).+#+# t=$(curl -fsSL https://api.github.com/repos/opencoredev/akeru-bot/releases/latest | sed -n 's/.*"tag_name":[[:space:]]*"\(v[0-9][^"]*\)".*/\1/p' | head -1); if [ -z "$t" ]; then echo "Could not resolve the latest Akeru Bot release." >&2; (exit 1); else f=$(mktemp /tmp/akeru-install.XXXXXX) && curl -fsSL -o "$f" "https://raw.githubusercontent.com/opencoredev/akeru-bot/$t/scripts/install-linux.sh" && bash "$f" --tag "$t"; rc=$?; rm -f "${f:-/tmp/akeru-install-none}"; (exit $rc); fi+# bash install-linux.sh --tag v1.2.3+#+# Downloads the GitHub AppImage for the latest stable tag (or --tag), checks+# SHA256SUMS, then installs atomically to ~/.local/bin.++set -euo pipefail++tag=""+while [ "$#" -gt 0 ]; do+ case "$1" in+ --tag)+ if [ "$#" -lt 2 ]; then+ echo "install-linux.sh: --tag requires a value (vX.Y.Z)" >&2+ exit 1+ fi+ tag="$2"+ shift 2+ ;;+ --tag=*)+ tag="${1#--tag=}"+ shift+ ;;+ -h|--help)+ echo "usage: install-linux.sh [--tag vX.Y.Z]"+ echo "installs Akeru-Bot-<version>-x64.AppImage to ~/.local/bin/akeru-bot"+ exit 0+ ;;+ *)+ echo "install-linux.sh: unknown argument: $1" >&2+ echo "usage: install-linux.sh [--tag vX.Y.Z]" >&2+ exit 1+ ;;+ esac+done++[ "$(uname -s)" = Linux ]+case "$(uname -m)" in+ x86_64|amd64) ;;+ *)+ echo "install-linux.sh: unsupported architecture: $(uname -m) (need x86_64 or amd64)" >&2+ exit 1+ ;;+esac++tmp="$(mktemp -d)"+trap 'rm -rf "$tmp"' EXIT++if [ -z "$tag" ]; then+ tag="$(curl -fsSL https://api.github.com/repos/opencoredev/akeru-bot/releases/latest | sed -n 's/.*"tag_name":[[:space:]]*"\(v[0-9][^"]*\)".*/\1/p' | head -1)"+fi+[[ "$tag" =~ ^v[0-9]+[.][0-9]+[.][0-9]+$ ]]++version="${tag#v}"+echo "Installing Akeru Bot $tag for Linux (x86_64)..."++appimage="Akeru-Bot-${version}-x64.AppImage"+base="https://github.com/opencoredev/akeru-bot/releases/download/${tag}"+curl -fsSL -o "$tmp/SHA256SUMS" "$base/SHA256SUMS"+curl -fL -o "$tmp/$appimage" "$base/$appimage"++echo "Verifying checksum..."+line="$(grep -E "^[a-fA-F0-9]{64}[[:space:]]+\*?${appimage}\$" "$tmp/SHA256SUMS")" || exit 1+( cd "$tmp" && printf "%s\n" "$line" | sha256sum -c - )++echo "Installing..."+dest="$HOME/.local/bin/akeru-bot"+mkdir -p "$HOME/.local/bin"+if [ -e "$dest" ] && [ ! -f "$dest" ]; then+ echo "install-linux.sh: refusing to overwrite non-regular file: $dest" >&2+ exit 1+fi+staged="$dest.new.$$"+trap 'rm -rf "$tmp"; rm -f "$staged"' EXIT+if ! cp -p "$tmp/$appimage" "$staged"; then+ rm -f "$staged"+ exit 1+fi+if ! chmod +x "$staged"; then+ rm -f "$staged"+ exit 1+fi+mv -f "$staged" "$dest"+echo "Installed Akeru Bot $tag."diff --git a/scripts/install-linux.test.ts b/scripts/install-linux.test.tsnew file mode 100644index 000000000..b99ef00b3--- /dev/null+++ b/scripts/install-linux.test.ts@@ -0,0 +1,247 @@+// @effect-diagnostics nodeBuiltinImport:off - Tests pin installer shell text and exercise its arg parsing.+import * as NodeAssert from "node:assert/strict";+import * as NodeChildProcess from "node:child_process";+import * as NodeCrypto from "node:crypto";+import * as NodeOS from "node:os";+import * as NodeFS from "node:fs";+import * as NodePath from "node:path";+import * as Context from "effect/Context";+import { HostProcessArchitecture, HostProcessPlatform } from "@t3tools/shared/hostProcess";+import { describe, it } from "vite-plus/test";++const scriptPath = NodePath.resolve(import.meta.dirname, "./install-linux.sh");+const script = NodeFS.readFileSync(scriptPath, "utf8");++function tryBash(args: string[]): { status: number; stdout: string; stderr: string } | null {+ try {+ const stdout = NodeChildProcess.execFileSync("bash", [scriptPath, ...args], {+ encoding: "utf8",+ stdio: ["ignore", "pipe", "pipe"],+ });+ return { status: 0, stdout, stderr: "" };+ } catch (error) {+ const failure = error as {+ status?: number;+ stdout?: unknown;+ stderr?: unknown;+ code?: string;+ };+ if (failure.code === "ENOENT") return null;+ return {+ status: failure.status ?? 1,+ stdout: String(failure.stdout ?? ""),+ stderr: String(failure.stderr ?? ""),+ };+ }+}++describe.runIf(+ Context.get(Context.empty(), HostProcessPlatform) === "linux" &&+ Context.get(Context.empty(), HostProcessArchitecture) === "x64",+)("install-linux.sh installation", () => {+ for (const scenario of [+ "fresh",+ "replacement",+ "checksum",+ "missing-entry",+ "download",+ "directory",+ ]) {+ it(`handles ${scenario} without leaving staging files`, () => {+ const root = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "akeru-install-test-"));+ try {+ const bin = NodePath.join(root, "bin");+ const home = NodePath.join(root, "home");+ const temp = NodePath.join(root, "tmp");+ const destination = NodePath.join(home, ".local/bin/akeru-bot");+ for (const directory of [bin, temp, NodePath.dirname(destination)]) {+ NodeFS.mkdirSync(directory, { recursive: true });+ }+ const payload = "fixture AppImage bytes\n";+ const asset = "Akeru-Bot-1.2.3-x64.AppImage";+ const digest = NodeCrypto.createHash("sha256").update(payload).digest("hex");+ NodeFS.writeFileSync(NodePath.join(root, "payload"), payload);+ NodeFS.writeFileSync(+ NodePath.join(root, "checksums"),+ `${scenario === "checksum" ? "0".repeat(64) : digest} ${scenario === "missing-entry" ? "other.AppImage" : asset}\n`,+ );+ NodeFS.writeFileSync(+ NodePath.join(bin, "curl"),+ `#!/usr/bin/env bash+set -euo pipefail+out=""+url=""+while [ "$#" -gt 0 ]; do+ case "$1" in+ -o) out="$2"; shift 2 ;;+ -*) shift ;;+ *) url="$1"; shift ;;+ esac+done+case "$url" in+ https://github.com/opencoredev/akeru-bot/releases/download/v1.2.3/SHA256SUMS) cp "$FIXTURE_ROOT/checksums" "$out" ;;+ https://github.com/opencoredev/akeru-bot/releases/download/v1.2.3/Akeru-Bot-1.2.3-x64.AppImage)+ [ "$FIXTURE_SCENARIO" != download ] || exit 22+ cp "$FIXTURE_ROOT/payload" "$out" ;;+ *) exit 99 ;;+esac+`,+ { mode: 0o755 },+ );+ if (scenario === "directory") {+ NodeFS.mkdirSync(destination);+ } else if (scenario !== "fresh") {+ NodeFS.writeFileSync(destination, "previous installation");+ }+ const result = NodeChildProcess.spawnSync("bash", [scriptPath, "--tag", "v1.2.3"], {+ encoding: "utf8",+ env: {+ ...process.env,+ HOME: home,+ TMPDIR: temp,+ PATH: `${bin}${NodePath.delimiter}${process.env.PATH}`,+ FIXTURE_ROOT: root,+ FIXTURE_SCENARIO: scenario,+ },+ });+ NodeAssert.ifError(result.error);+ if (scenario === "fresh" || scenario === "replacement") {+ NodeAssert.equal(result.status, 0, result.stderr);+ NodeAssert.equal(NodeFS.readFileSync(destination, "utf8"), payload);+ NodeAssert.ok(NodeFS.statSync(destination).mode & 0o111);+ NodeAssert.match(result.stdout, /Installed Akeru Bot v1.2.3\./);+ } else {+ NodeAssert.notEqual(result.status, 0);+ NodeAssert.doesNotMatch(result.stdout, /Installed Akeru Bot/);+ if (scenario === "directory") {+ NodeAssert.ok(NodeFS.statSync(destination).isDirectory());+ } else {+ NodeAssert.equal(NodeFS.readFileSync(destination, "utf8"), "previous installation");+ }+ }+ NodeAssert.deepEqual(NodeFS.readdirSync(NodePath.dirname(destination)), ["akeru-bot"]);+ NodeAssert.deepEqual(NodeFS.readdirSync(temp), []);+ } finally {+ NodeFS.rmSync(root, { recursive: true, force: true });+ }+ });+ }+});++describe("install-linux.sh", () => {+ it("starts in strict bash mode", () => {+ NodeAssert.ok(script.startsWith("#!/usr/bin/env bash\n"));+ NodeAssert.match(script, /^set -euo pipefail$/m);+ NodeAssert.doesNotMatch(script, /^set -x$/m);+ });++ it("gates on Linux x86_64", () => {+ NodeAssert.match(script, /^\[ "\$\(uname -s\)" = Linux \]$/m);+ NodeAssert.match(script, /^\s*x86_64\|amd64\) ;;$/m);+ });++ it("uses a temp dir cleaned by an EXIT trap", () => {+ NodeAssert.match(script, /^tmp="\$\(mktemp -d\)"$/m);+ NodeAssert.match(script, /^trap 'rm -rf "\$tmp"' EXIT$/m);+ });++ it("supports a --tag override and defaults to the latest stable release", () => {+ NodeAssert.match(script, /--tag\)/);+ NodeAssert.match(script, /--tag=\*\)/);+ NodeAssert.match(+ script,+ /curl -fsSL https:\/\/api\.github\.com\/repos\/opencoredev\/akeru-bot\/releases\/latest/,+ );+ NodeAssert.match(script, /if \[ -z "\$tag" \]; then/);+ });++ it("parses --tag, --tag=, --help, and rejects unknown args", () => {+ const help = tryBash(["--help"]);+ if (help === null) return;+ NodeAssert.equal(help.status, 0);+ NodeAssert.match(help.stdout, /usage: install-linux\.sh \[--tag vX\.Y\.Z\]/);+ NodeAssert.match(help.stdout, /Akeru-Bot-.*-x64\.AppImage/);++ const unknown = tryBash(["--bogus"]);+ NodeAssert.notEqual(unknown, null);+ NodeAssert.equal(unknown?.status, 1);+ NodeAssert.match(unknown?.stderr ?? "", /unknown argument/);++ const missing = tryBash(["--tag"]);+ NodeAssert.notEqual(missing, null);+ NodeAssert.equal(missing?.status, 1);+ NodeAssert.match(missing?.stderr ?? "", /--tag requires a value/);+ });++ it("accepts only strict vX.Y.Z tags", () => {+ NodeAssert.match(script, /\[\[ "\$tag" =~ \^v\[0-9\]\+\[\.\]\[0-9\]\+\[\.\]\[0-9\]\+\$ \]\]/);+ });++ it("downloads the same-tag AppImage and SHA256SUMS", () => {+ NodeAssert.match(script, /appimage="Akeru-Bot-\$\{version\}-x64\.AppImage"/);+ NodeAssert.match(+ script,+ /base="https:\/\/github\.com\/opencoredev\/akeru-bot\/releases\/download\/\$\{tag\}"/,+ );+ NodeAssert.match(script, /curl -fsSL -o "\$tmp\/SHA256SUMS" "\$base\/SHA256SUMS"/);+ NodeAssert.match(script, /curl -fL -o "\$tmp\/\$appimage" "\$base\/\$appimage"/);+ NodeAssert.doesNotMatch(script, /\/releases\/latest\/download/);+ });++ it("verifies the exact checksum line before installing", () => {+ NodeAssert.match(+ script,+ /line="\$\(grep -E "\^\[a-fA-F0-9\]\{64\}\[\[:space:\]\]\+\\\*\?\$\{appimage\}\\\$" "\$tmp\/SHA256SUMS"\)" \|\| exit 1/,+ );+ NodeAssert.match(script, /sha256sum -c -/);+ NodeAssert.doesNotMatch(script, /shasum/);+ });++ it("installs atomically to ~/.local/bin with a per-run staging path", () => {+ NodeAssert.match(script, /dest="\$HOME\/\.local\/bin\/akeru-bot"/);+ NodeAssert.match(script, /mkdir -p "\$HOME\/\.local\/bin"/);+ NodeAssert.match(script, /if \[ -e "\$dest" \] && \[ ! -f "\$dest" \]; then/);+ NodeAssert.match(script, /refusing to overwrite non-regular file/);+ NodeAssert.match(script, /staged="\$dest\.new\.\$\$"/);+ NodeAssert.match(script, /trap 'rm -rf "\$tmp"; rm -f "\$staged"' EXIT/);+ NodeAssert.match(script, /cp -p "\$tmp\/\$appimage" "\$staged"/);+ NodeAssert.match(script, /chmod \+x "\$staged"/);+ NodeAssert.match(script, /mv -f "\$staged" "\$dest"/);+ NodeAssert.doesNotMatch(script, /cp -p "\$tmp\/\$appimage" "\$dest"/);+ NodeAssert.doesNotMatch(script, /staged="\$dest\.new"/);+ NodeAssert.doesNotMatch(script, /\.backup/);+ });++ it("prints the exact success sentence last", () => {+ NodeAssert.match(script, /^echo "Installed Akeru Bot \$tag\."$/m);+ const lines = script.split("\n");+ const installed = lines.filter((line) => line === 'echo "Installed Akeru Bot $tag."');+ NodeAssert.equal(installed.length, 1);+ NodeAssert.ok(script.trimEnd().endsWith('echo "Installed Akeru Bot $tag."'));+ });++ it("documents a private-temp-file one-liner that preserves failures", () => {+ NodeAssert.match(script, /if \[ -z "\$t" \]; then/);+ NodeAssert.match(+ script,+ /raw\.githubusercontent\.com\/opencoredev\/akeru-bot\/\$t\/scripts\/install-linux\.sh/,+ );+ NodeAssert.match(script, /--tag "\$t"/);+ NodeAssert.match(script, /f=\$\(mktemp \/tmp\/akeru-install\.XXXXXX\)/);+ NodeAssert.match(script, /Could not resolve the latest Akeru Bot release/);+ NodeAssert.match(script, /rc=\$\?; rm -f "\$\{f:-\/tmp\/akeru-install-none\}"; \(exit \$rc\)/);+ NodeAssert.doesNotMatch(script, /curl -fsSL -o \/tmp\/akeru-install-linux\.sh/);+ NodeAssert.doesNotMatch(script, /\|\s*(bash|sh)([\s;]|$)/);+ });++ it("keeps output to milestone lines only", () => {+ const echoes = script.split("\n").filter((line) => /^\s*echo /.test(line));+ NodeAssert.ok(echoes.length > 0 && echoes.length <= 12);+ for (const line of echoes) {+ NodeAssert.match(+ line,+ /usage:|unknown argument|--tag requires a value|unsupported architecture|refusing to overwrite|Installing|Verifying checksum|Installed Akeru Bot|installs Akeru-Bot-/,+ );+ }+ });+});diff --git a/scripts/install-macos.sh b/scripts/install-macos.shnew file mode 100755index 000000000..fe9dbe6d5--- /dev/null+++ b/scripts/install-macos.sh@@ -0,0 +1,87 @@+#!/usr/bin/env bash+#+# One-line macOS installer for Akeru Bot (Apple Silicon).+#+# t=$(curl -fsSL https://api.github.com/repos/opencoredev/akeru-bot/releases/latest | sed -n 's/.*"tag_name":[[:space:]]*"\(v[0-9][^"]*\)".*/\1/p' | head -1); if [ -z "$t" ]; then echo "Could not resolve the latest Akeru Bot release." >&2; (exit 1); else f=$(mktemp /tmp/akeru-install.XXXXXX) && curl -fsSL -o "$f" "https://raw.githubusercontent.com/opencoredev/akeru-bot/$t/scripts/install-macos.sh" && bash "$f" --tag "$t"; rc=$?; rm -f "${f:-/tmp/akeru-install-none}"; (exit $rc); fi+# bash install-macos.sh --tag v1.2.3+#+# Downloads the GitHub DMG for the latest stable tag (or --tag), checks+# SHA256SUMS, then installs atomically with backup + rollback.++set -euo pipefail++tag=""+while [ "$#" -gt 0 ]; do+ case "$1" in+ --tag)+ if [ "$#" -lt 2 ]; then+ echo "install-macos.sh: --tag requires a value (vX.Y.Z)" >&2+ exit 1+ fi+ tag="$2"+ shift 2+ ;;+ --tag=*)+ tag="${1#--tag=}"+ shift+ ;;+ -h|--help)+ echo "usage: install-macos.sh [--tag vX.Y.Z]"+ exit 0+ ;;+ *)+ echo "install-macos.sh: unknown argument: $1" >&2+ echo "usage: install-macos.sh [--tag vX.Y.Z]" >&2+ exit 1+ ;;+ esac+done++[ "$(uname -s)" = Darwin ]+[ "$(uname -m)" = arm64 ]++tmp="$(mktemp -d)"+mnt="$tmp/mnt"+trap 'hdiutil detach "$mnt" >/dev/null 2>&1 || true; rm -rf "$tmp"' EXIT+mkdir -p "$mnt"++if [ -z "$tag" ]; then+ tag="$(curl -fsSL https://api.github.com/repos/opencoredev/akeru-bot/releases/latest | sed -n 's/.*"tag_name":[[:space:]]*"\(v[0-9][^"]*\)".*/\1/p' | head -1)"+fi+[[ "$tag" =~ ^v[0-9]+[.][0-9]+[.][0-9]+$ ]]++version="${tag#v}"+echo "Installing Akeru Bot $tag for macOS (arm64)..."++dmg="Akeru-Bot-${version}-arm64.dmg"+base="https://github.com/opencoredev/akeru-bot/releases/download/${tag}"+curl -fsSL -o "$tmp/SHA256SUMS" "$base/SHA256SUMS"+curl -fL -o "$tmp/$dmg" "$base/$dmg"++echo "Verifying checksum..."+line="$(grep -E "^[a-fA-F0-9]{64}[[:space:]]+\*?${dmg}\$" "$tmp/SHA256SUMS")" || exit 1+( cd "$tmp" && printf "%s\n" "$line" | shasum -a 256 -c - )++echo "Installing..."+hdiutil attach "$tmp/$dmg" -nobrowse -readonly -mountpoint "$mnt"+app="/Applications/Akeru Bot (Alpha).app"+source_app="$mnt/Akeru Bot (Alpha).app"+prepared_app="$tmp/Akeru Bot (Alpha).app"+ditto "$source_app" "$prepared_app"+identifier="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "$prepared_app/Contents/Info.plist")"+[ "$identifier" = dev.leodoes.akeru ]+install_id="$(uuidgen)"+new_app="/Applications/.Akeru Bot (Alpha).app.installing.$install_id"+old_app="/Applications/.Akeru Bot (Alpha).app.backup.$install_id"+osascript - "$prepared_app" "$new_app" "$old_app" "$app" <<'APPLESCRIPT'+on run argv+ set preparedApp to quoted form of item 1 of argv+ set newApp to quoted form of item 2 of argv+ set oldApp to quoted form of item 3 of argv+ set installedApp to quoted form of item 4 of argv+ do shell script "rm -rf " & newApp & " " & oldApp & " && test ! -e " & newApp & " && test ! -e " & oldApp & " && { ditto " & preparedApp & " " & newApp & " || { rm -rf " & newApp & "; exit 1; }; } && { test ! -e " & installedApp & " || mv " & installedApp & " " & oldApp & "; } && { mv " & newApp & " " & installedApp & " || { test ! -e " & oldApp & " || mv " & oldApp & " " & installedApp & " || { rm -rf " & newApp & "; echo Previous application remains at " & oldApp & " >&2; exit 1; }; rm -rf " & newApp & "; exit 1; }; } && rm -rf " & oldApp with administrator privileges+end run+APPLESCRIPT+xattr -d com.apple.quarantine "$app" 2>/dev/null || true+open "$app"+echo "Installed Akeru Bot $tag."diff --git a/scripts/install-macos.test.ts b/scripts/install-macos.test.tsnew file mode 100644index 000000000..a8ff9eef0--- /dev/null+++ b/scripts/install-macos.test.ts@@ -0,0 +1,150 @@+// @effect-diagnostics nodeBuiltinImport:off - Tests pin installer shell text and exercise its arg parsing.+import * as NodeAssert from "node:assert/strict";+import * as NodeChildProcess from "node:child_process";+import * as NodeFS from "node:fs";+import * as NodePath from "node:path";+import { describe, it } from "vite-plus/test";++const scriptPath = NodePath.resolve(import.meta.dirname, "./install-macos.sh");+const script = NodeFS.readFileSync(scriptPath, "utf8");++function tryBash(args: string[]): { status: number; stdout: string; stderr: string } | null {+ try {+ const stdout = NodeChildProcess.execFileSync("bash", [scriptPath, ...args], {+ encoding: "utf8",+ stdio: ["ignore", "pipe", "pipe"],+ });+ return { status: 0, stdout, stderr: "" };+ } catch (error) {+ const failure = error as {+ status?: number;+ stdout?: unknown;+ stderr?: unknown;+ code?: string;+ };+ if (failure.code === "ENOENT") return null;+ return {+ status: failure.status ?? 1,+ stdout: String(failure.stdout ?? ""),+ stderr: String(failure.stderr ?? ""),+ };+ }+}++describe("install-macos.sh", () => {+ it("starts in strict bash mode", () => {+ NodeAssert.ok(script.startsWith("#!/usr/bin/env bash\n"));+ NodeAssert.match(script, /^set -euo pipefail$/m);+ NodeAssert.doesNotMatch(script, /^set -x$/m);+ });++ it("gates on macOS Apple Silicon", () => {+ NodeAssert.match(script, /^\[ "\$\(uname -s\)" = Darwin \]$/m);+ NodeAssert.match(script, /^\[ "\$\(uname -m\)" = arm64 \]$/m);+ });++ it("uses a temp dir cleaned by an EXIT trap", () => {+ NodeAssert.match(script, /^tmp="\$\(mktemp -d\)"$/m);+ NodeAssert.match(+ script,+ /^trap 'hdiutil detach "\$mnt" >\/dev\/null 2>&1 \|\| true; rm -rf "\$tmp"' EXIT$/m,+ );+ });++ it("supports a --tag override and defaults to the latest stable release", () => {+ NodeAssert.match(script, /--tag\)/);+ NodeAssert.match(script, /--tag=\*\)/);+ NodeAssert.match(+ script,+ /curl -fsSL https:\/\/api\.github\.com\/repos\/opencoredev\/akeru-bot\/releases\/latest/,+ );+ NodeAssert.match(script, /if \[ -z "\$tag" \]; then/);+ });++ it("parses --tag, --tag=, --help, and rejects unknown args", () => {+ const help = tryBash(["--help"]);+ if (help === null) return;+ NodeAssert.equal(help.status, 0);+ NodeAssert.match(help.stdout, /usage: install-macos\.sh \[--tag vX\.Y\.Z\]/);++ const unknown = tryBash(["--bogus"]);+ NodeAssert.notEqual(unknown, null);+ NodeAssert.equal(unknown?.status, 1);+ NodeAssert.match(unknown?.stderr ?? "", /unknown argument/);+ });++ it("accepts only strict vX.Y.Z tags", () => {+ NodeAssert.match(script, /\[\[ "\$tag" =~ \^v\[0-9\]\+\[\.\]\[0-9\]\+\[\.\]\[0-9\]\+\$ \]\]/);+ });++ it("downloads the same-tag DMG and SHA256SUMS", () => {+ NodeAssert.match(script, /dmg="Akeru-Bot-\$\{version\}-arm64\.dmg"/);+ NodeAssert.match(+ script,+ /base="https:\/\/github\.com\/opencoredev\/akeru-bot\/releases\/download\/\$\{tag\}"/,+ );+ NodeAssert.match(script, /curl -fsSL -o "\$tmp\/SHA256SUMS" "\$base\/SHA256SUMS"/);+ NodeAssert.match(script, /curl -fL -o "\$tmp\/\$dmg" "\$base\/\$dmg"/);+ NodeAssert.doesNotMatch(script, /\/releases\/latest\/download/);+ });++ it("verifies the exact checksum line before mounting", () => {+ NodeAssert.match(+ script,+ /line="\$\(grep -E "\^\[a-fA-F0-9\]\{64\}\[\[:space:\]\]\+\\\*\?\$\{dmg\}\\\$" "\$tmp\/SHA256SUMS"\)" \|\| exit 1/,+ );+ NodeAssert.match(script, /printf "%s\\n" "\$line" \| shasum -a 256 -c -/);+ NodeAssert.match(+ script,+ /hdiutil attach "\$tmp\/\$dmg" -nobrowse -readonly -mountpoint "\$mnt"/,+ );+ });++ it("asserts the bundle identifier before installing", () => {+ NodeAssert.match(script, /Print :CFBundleIdentifier/);+ NodeAssert.match(script, /^\[ "\$identifier" = dev\.leodoes\.akeru \]$/m);+ });++ it("installs atomically with backup and rollback", () => {+ NodeAssert.match(+ script,+ /^osascript - "\$prepared_app" "\$new_app" "\$old_app" "\$app" <<'APPLESCRIPT'$/m,+ );+ NodeAssert.match(+ script,+ /new_app="\/Applications\/\.Akeru Bot \(Alpha\)\.app\.installing\.\$install_id"/,+ );+ NodeAssert.match(+ script,+ /old_app="\/Applications\/\.Akeru Bot \(Alpha\)\.app\.backup\.\$install_id"/,+ );+ NodeAssert.match(script, /mv " & installedApp & " " & oldApp/);+ NodeAssert.match(script, /mv " & newApp & " " & installedApp/);+ NodeAssert.match(script, /mv " & oldApp & " " & installedApp/);+ NodeAssert.match(script, /echo Previous application remains at " & oldApp & " >&2/);+ NodeAssert.match(script, /with administrator privileges/);+ NodeAssert.doesNotMatch(script, /backup\.\$\$/);+ });++ it("clears quarantine on the installed app only and never disables Gatekeeper", () => {+ NodeAssert.match(script, /^xattr -d com\.apple\.quarantine "\$app" 2>\/dev\/null \|\| true$/m);+ NodeAssert.doesNotMatch(script.toLowerCase(), /spctl/);+ NodeAssert.doesNotMatch(script.toLowerCase(), /disable/);+ });++ it("opens the app at the end", () => {+ NodeAssert.match(script, /^open "\$app"$/m);+ NodeAssert.ok(script.lastIndexOf('open "$app"') > script.lastIndexOf("APPLESCRIPT"));+ });++ it("keeps output to milestone lines only", () => {+ const echoes = script.split("\n").filter((line) => /^\s*echo /.test(line));+ NodeAssert.ok(echoes.length > 0 && echoes.length <= 8);+ for (const line of echoes) {+ NodeAssert.match(+ line,+ /usage:|unknown argument|--tag requires a value|Installing|Verifying checksum|Installed Akeru Bot/,+ );+ }+ });+});diff --git a/scripts/install-windows.behavior.test.ps1 b/scripts/install-windows.behavior.test.ps1new file mode 100644index 000000000..e77969270--- /dev/null+++ b/scripts/install-windows.behavior.test.ps1@@ -0,0 +1,230 @@+# Run with Windows PowerShell 5.1; no network, installer process, or Pester is needed.+$ErrorActionPreference = 'Stop'+Set-StrictMode -Version Latest++$installerScript = Join-Path $PSScriptRoot 'install-windows.ps1'+$header = Get-Content -LiteralPath $installerScript | Where-Object { $_ -like '# $t = *' }+if (@($header).Count -ne 1) { throw 'Expected one bootstrap command in the installer header.' }+$bootstrap = $header.Substring(4)+$scratch = Join-Path ([IO.Path]::GetTempPath()) "akeru-windows-tests-$([Guid]::NewGuid())"+$originalTemp = $env:TEMP+$originalArchitecture = $env:PROCESSOR_ARCHITECTURE+$null = New-Item -ItemType Directory -Path $scratch+$testState = @{+ downloadDirectories = @()+ requests = @()+ installerFile = ''+ scenario = ''+ unblocked = $false+ started = $false+ lockedFile = $null+}++function Assert-True {+ param([bool]$Condition, [string]$Message)+ if (-not $Condition) { throw $Message }+}++function Assert-Empty {+ param([string]$Path)+ Assert-True (@(Get-ChildItem -LiteralPath $Path -Force).Count -eq 0) "Temporary files remain in $Path"+}++# These mocks are visible only to installer invocations in this test process.+function Invoke-RestMethod {+ throw 'Unexpected release lookup: tests supply an explicit tag.'+}++function Invoke-WebRequest {+ param([string]$Uri, [string]$OutFile, [switch]$UseBasicParsing)+ Assert-True $UseBasicParsing 'Downloads must avoid Internet Explorer parsing.'+ $directory = Split-Path -Parent $OutFile+ Assert-True ((Split-Path -Parent $directory) -eq $env:TEMP) 'Download escaped the private TEMP directory.'+ Assert-True (Test-Path -LiteralPath $directory -PathType Container) 'Download directory does not exist.'+ $testState.requests += $Uri+ if ($Uri -eq 'https://github.com/opencoredev/akeru-bot/releases/download/v1.2.3/Akeru-Bot-1.2.3-x64.exe') {+ $testState.downloadDirectories += $directory+ $testState.installerFile = $OutFile+ [IO.File]::WriteAllText($OutFile, 'Harmless installer fixture, never executed.')+ if ($testState.scenario -eq 'exe-download') { throw 'fixture exe download failed' }+ return+ }+ Assert-True ($Uri -eq 'https://github.com/opencoredev/akeru-bot/releases/download/v1.2.3/SHA256SUMS') "Unexpected URL: $Uri"+ Assert-True ($directory -eq (Split-Path -Parent $testState.installerFile)) 'Downloads used different directories.'+ $hash = (Get-FileHash -LiteralPath $testState.installerFile -Algorithm SHA256).Hash.ToLowerInvariant()+ $entry = "$hash *Akeru-Bot-1.2.3-x64.exe"+ switch ($testState.scenario) {+ 'mismatch' { $entry = "$('0' * 64) Akeru-Bot-1.2.3-x64.exe" }+ 'missing' { $entry = "$hash another.exe" }+ 'duplicate' { $entry = "$entry`r`n$entry" }+ }+ [IO.File]::WriteAllText($OutFile, "$entry`r`n")+ if ($testState.scenario -eq 'checksum-download') { throw 'fixture checksum download failed' }+}++function Unblock-File {+ param([string]$Path)+ Assert-True ($Path -eq $testState.installerFile) 'Unblocked the wrong file.'+ Assert-True (Test-Path -LiteralPath $Path -PathType Leaf) 'Installer disappeared before unblock.'+ $testState.unblocked = $true+ if ($testState.scenario -eq 'unblock') { throw 'fixture unblock failed' }+}++function Start-Process {+ param([string]$FilePath, [switch]$Wait, [switch]$PassThru)+ Assert-True ($FilePath -eq $testState.installerFile) 'Started the wrong file.'+ Assert-True ($Wait -and $PassThru -and $testState.unblocked) 'Installer must be unblocked and run with -Wait -PassThru.'+ $testState.started = $true+ if ($testState.scenario -eq 'launch') { throw 'fixture launch failed' }+ if ($testState.scenario -like 'cleanup-*') {+ $testState.lockedFile = [IO.File]::Open($FilePath, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::None)+ }+ $code = 0+ if ($testState.scenario -in @('exit', 'cleanup-exit')) { $code = 37 }+ [pscustomobject]@{ ExitCode = $code }+}++function Test-Payload {+ param([string]$Scenario, [string]$ExpectedError = '', [bool]$Unblocked = $false, [bool]$Started = $false)+ $testState.scenario = $Scenario+ $testState.requests = @()+ $testState.installerFile = ''+ $testState.unblocked = $false+ $testState.started = $false+ $failure = $null+ $output = @()+ try { $output = @(& $installerScript -Tag v1.2.3) } catch { $failure = $_ }+ if ($Scenario -like 'cleanup-*') {+ Assert-True (Test-Path -LiteralPath $testState.installerFile) 'Fixture did not keep the installer locked during cleanup.'+ $testState.lockedFile.Dispose()+ $testState.lockedFile = $null+ Remove-Item -LiteralPath (Split-Path -Parent $testState.installerFile) -Recurse -Force+ }+ if ($ExpectedError) {+ Assert-True ($null -ne $failure) "$Scenario unexpectedly succeeded."+ Assert-True ($failure.Exception.Message.Contains($ExpectedError)) "$Scenario failed for the wrong reason: $failure"+ } else {+ Assert-True ($null -eq $failure) "$Scenario failed: $failure"+ Assert-True ($output -contains 'Installed Akeru Bot v1.2.3.') 'Success message missing.'+ }+ $requestCount = 2+ if ($Scenario -eq 'exe-download') { $requestCount = 1 }+ Assert-True ($testState.requests.Count -eq $requestCount) "$Scenario made unexpected downloads."+ Assert-True ($testState.unblocked -eq $Unblocked) "$Scenario had unexpected unblock behavior."+ Assert-True ($testState.started -eq $Started) "$Scenario had unexpected launch behavior."+ Assert-Empty $env:TEMP+ Write-Output "PASS payload: $Scenario"+}++function Test-Bootstrap {+ param([string]$Scenario, [int]$FixtureExit = 0)+ $caseDirectory = Join-Path $scratch "bootstrap-$Scenario"+ $tempDirectory = Join-Path $caseDirectory 'temp'+ $null = New-Item -ItemType Directory -Path $tempDirectory -Force+ $fixture = @'+param([string]$Tag)+$ErrorActionPreference = 'Stop'+if ((Get-ExecutionPolicy -Scope Process) -ne 'Bypass') { throw 'Fixture did not run under Bypass.' }+if ($Tag -ne 'v1.2.3') { throw 'Bootstrap did not forward the release tag.' }+[IO.File]::WriteAllText((Join-Path (Split-Path -Parent $env:TEMP) 'executed'), $PSCommandPath)+exit __EXIT__+'@+ $fixture = $fixture.Replace('__EXIT__', [string]$FixtureExit)+ $child = @'+$ErrorActionPreference = 'Stop'+$env:TEMP = [Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('__TEMP__'))+$caseDirectory = Split-Path -Parent $env:TEMP+try {+ if ((Get-ExecutionPolicy -Scope Process) -ne 'Restricted') { throw 'Bootstrap parent must be Restricted.' }+ function Invoke-RestMethod {+ [CmdletBinding()]+ param([Parameter(Position = 0)][string]$Uri)+ if ($Uri -ne 'https://api.github.com/repos/opencoredev/akeru-bot/releases/latest') { throw 'Unexpected release URL.' }+ [pscustomobject]@{ tag_name = 'v1.2.3' }+ }+ function Invoke-WebRequest {+ [CmdletBinding()]+ param([Parameter(Position = 0)][string]$Uri, [string]$OutFile, [switch]$UseBasicParsing)+ if (-not $UseBasicParsing) { throw 'Bootstrap must avoid Internet Explorer parsing.' }+ if ($Uri -ne 'https://raw.githubusercontent.com/opencoredev/akeru-bot/v1.2.3/scripts/install-windows.ps1') { throw 'Unexpected script URL.' }+ if ((Split-Path -Parent $OutFile) -ne $env:TEMP) { throw 'Bootstrap escaped private TEMP.' }+ [IO.File]::WriteAllText((Join-Path $caseDirectory 'download-path'), $OutFile)+ $fixture = [Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('__FIXTURE__'))+ [IO.File]::WriteAllText($OutFile, $fixture)+ if ('__SCENARIO__' -eq 'download-failure') { throw 'fixture script download failed' }+ }+ $bootstrap = [Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('__BOOTSTRAP__'))+ & ([scriptblock]::Create($bootstrap))+ exit 0+} catch {+ [IO.File]::WriteAllText((Join-Path $caseDirectory 'failure'), $_.Exception.Message)+ exit 1+}+'@+ $child = $child.Replace('__TEMP__', [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($tempDirectory)))+ $child = $child.Replace('__FIXTURE__', [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($fixture)))+ $child = $child.Replace('__BOOTSTRAP__', [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($bootstrap)))+ $child = $child.Replace('__SCENARIO__', $Scenario)+ $encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($child))+ # Inline commands can run under Restricted; a downloaded script still needs the child Bypass.+ $command = "& ([scriptblock]::Create([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String('$encoded'))))"+ & "$PSHOME\powershell.exe" -NoProfile -ExecutionPolicy Restricted -Command $command+ $exitCode = $LASTEXITCODE+ $failurePath = Join-Path $caseDirectory 'failure'+ $failure = ''+ if (Test-Path -LiteralPath $failurePath) { $failure = [IO.File]::ReadAllText($failurePath) }+ if ($Scenario -eq 'download-failure') {+ Assert-True ($exitCode -ne 0 -and $failure.Contains('fixture script download failed')) "Download failure was not propagated: $failure"+ } elseif ($FixtureExit -ne 0) {+ Assert-True ($exitCode -ne 0 -and $failure.Contains("installer failed with exit code $FixtureExit")) "Child failure was not propagated: $failure"+ } else {+ Assert-True ($exitCode -eq 0 -and -not $failure) "Bootstrap failed: $failure"+ }+ $downloadPath = [IO.File]::ReadAllText((Join-Path $caseDirectory 'download-path'))+ Assert-True ((Split-Path -Leaf $downloadPath) -match '^akeru-install-[0-9a-f-]{36}\.ps1$') 'Bootstrap did not use a GUID filename.'+ $executedPath = Join-Path $caseDirectory 'executed'+ if ($Scenario -eq 'download-failure') {+ Assert-True (-not (Test-Path -LiteralPath $executedPath)) 'Executed a failed script download.'+ } else {+ Assert-True ([IO.File]::ReadAllText($executedPath) -eq $downloadPath) 'The downloaded fixture did not execute.'+ }+ Assert-Empty $tempDirectory+ Write-Host "PASS bootstrap: $Scenario"+ return (Split-Path -Leaf $downloadPath)+}++try {+ $env:TEMP = Join-Path $scratch 'payload'+ $null = New-Item -ItemType Directory -Path $env:TEMP+ $env:PROCESSOR_ARCHITECTURE = 'AMD64'+ Test-Payload 'success' '' $true $true+ Test-Payload 'success-again' '' $true $true+ Test-Payload 'exe-download' 'fixture exe download failed'+ Test-Payload 'checksum-download' 'fixture checksum download failed'+ Test-Payload 'mismatch' 'checksum mismatch'+ Test-Payload 'missing' 'must contain exactly one entry'+ Test-Payload 'duplicate' 'must contain exactly one entry'+ Test-Payload 'unblock' 'fixture unblock failed' $true+ Test-Payload 'launch' 'fixture launch failed' $true $true+ Test-Payload 'exit' 'installer exited with code 37' $true $true+ Test-Payload 'cleanup-success' '' $true $true+ Test-Payload 'cleanup-exit' 'installer exited with code 37' $true $true+ Assert-True ($testState.downloadDirectories.Count -eq 12) 'Missing payload runs.'+ Assert-True (@($testState.downloadDirectories | Select-Object -Unique).Count -eq 12) 'Payload runs reused a temporary directory.'+ foreach ($directory in $testState.downloadDirectories) {+ Assert-True ((Split-Path -Leaf $directory) -match '^akeru-install-[0-9a-f-]{36}$') 'Payload did not use a GUID directory.'+ }+ $bootstrapPaths = @(+ Test-Bootstrap 'success'+ Test-Bootstrap 'success-again'+ Test-Bootstrap 'nonzero' 37+ Test-Bootstrap 'download-failure'+ )+ Assert-True ($bootstrapPaths.Count -eq 4 -and @($bootstrapPaths | Select-Object -Unique).Count -eq 4) 'Bootstrap runs reused a temporary filename.'+ Write-Output 'PASS all Windows installer behavioral tests'+} finally {+ if ($null -ne $testState.lockedFile) { $testState.lockedFile.Dispose() }+ $env:TEMP = $originalTemp+ $env:PROCESSOR_ARCHITECTURE = $originalArchitecture+ Remove-Item -LiteralPath $scratch -Recurse -Force+}diff --git a/scripts/install-windows.ps1 b/scripts/install-windows.ps1new file mode 100644index 000000000..04774ea05--- /dev/null+++ b/scripts/install-windows.ps1@@ -0,0 +1,70 @@+# One-line Windows installer for Akeru Bot (x64).+#+# $t = (Invoke-RestMethod https://api.github.com/repos/opencoredev/akeru-bot/releases/latest -ErrorAction Stop).tag_name; if ($t -match '^v\d+\.\d+\.\d+$') { $f = Join-Path $env:TEMP $("akeru-install-$([Guid]::NewGuid()).ps1"); try { Invoke-WebRequest "https://raw.githubusercontent.com/opencoredev/akeru-bot/$t/scripts/install-windows.ps1" -OutFile $f -UseBasicParsing -ErrorAction Stop; & powershell.exe -NoProfile -ExecutionPolicy Bypass -File $f -Tag $t; if ($LASTEXITCODE -ne 0) { throw "Akeru Bot installer failed with exit code $LASTEXITCODE." } } finally { Remove-Item -LiteralPath $f -Force -ErrorAction SilentlyContinue } } else { throw "Could not resolve the latest Akeru Bot release." }+# powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\install-windows.ps1 -Tag v1.2.3+#+# Downloads the GitHub exe for the latest stable tag (or -Tag), checks+# SHA256SUMS, unblocks the file, then runs the self-installer.+param(+ [string]$Tag = '',+ [switch]$Help+)++$ErrorActionPreference = 'Stop'++if ($Help) {+ Write-Output 'usage: install-windows.ps1 [-Tag vX.Y.Z]'+ exit 0+}++if ($env:PROCESSOR_ARCHITECTURE -ne 'AMD64') {+ throw "install-windows.ps1: Windows x64 (AMD64) only; detected '$($env:PROCESSOR_ARCHITECTURE)'. ARM64 and x86 are not supported."+}++[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12++if (-not $Tag) {+ $Tag = (Invoke-RestMethod -Uri 'https://api.github.com/repos/opencoredev/akeru-bot/releases/latest').tag_name+}+if (-not $Tag) {+ throw 'install-windows.ps1: could not resolve a release tag.'+}+if ($Tag -notmatch '^v\d+\.\d+\.\d+$') {+ throw "install-windows.ps1: invalid tag '$Tag'. Expected vX.Y.Z."+}++$version = $Tag.Substring(1)+Write-Output "Installing Akeru Bot $Tag for Windows (x64)..."++$asset = "Akeru-Bot-$version-x64.exe"+$base = "https://github.com/opencoredev/akeru-bot/releases/download/$Tag"+$tempDirectory = Join-Path $env:TEMP "akeru-install-$([Guid]::NewGuid())"+$null = New-Item -ItemType Directory -Path $tempDirectory+try {+ $installerPath = Join-Path $tempDirectory $asset+ $checksumPath = Join-Path $tempDirectory 'SHA256SUMS'+ Invoke-WebRequest -Uri "$base/$asset" -OutFile $installerPath -UseBasicParsing+ Invoke-WebRequest -Uri "$base/SHA256SUMS" -OutFile $checksumPath -UseBasicParsing++ Write-Output 'Verifying checksum...'+ $entries = @(Select-String -Path $checksumPath -Pattern ('^[a-fA-F0-9]{64}\s+\*?' + [regex]::Escape($asset) + '$'))+ if ($entries.Count -ne 1) {+ throw "install-windows.ps1: SHA256SUMS must contain exactly one entry for '$asset'."+ }+ $expected = ($entries[0].Line -split '\s+')[0]+ $actual = (Get-FileHash -Path $installerPath -Algorithm SHA256).Hash+ if ($actual -ne $expected) {+ throw "install-windows.ps1: checksum mismatch for '$asset'."+ }++ Unblock-File -Path $installerPath++ Write-Output 'Installing...'+ $proc = Start-Process -FilePath $installerPath -Wait -PassThru+ if ($proc.ExitCode -ne 0) {+ throw "install-windows.ps1: installer exited with code $($proc.ExitCode)."+ }+ Write-Output "Installed Akeru Bot $Tag."+} finally {+ Remove-Item -LiteralPath $tempDirectory -Recurse -Force -ErrorAction SilentlyContinue+}diff --git a/scripts/install-windows.test.ts b/scripts/install-windows.test.tsnew file mode 100644index 000000000..d459e1e64--- /dev/null+++ b/scripts/install-windows.test.ts@@ -0,0 +1,126 @@+// @effect-diagnostics nodeBuiltinImport:off - Tests pin installer script text; behavior runs separately on Windows.+import * as NodeAssert from "node:assert/strict";+import * as NodeFS from "node:fs";+import * as NodePath from "node:path";+import { describe, it } from "vite-plus/test";++const scriptPath = NodePath.resolve(import.meta.dirname, "./install-windows.ps1");+const script = NodeFS.readFileSync(scriptPath, "utf8");++describe("install-windows.ps1", () => {+ it("stops on every failed check", () => {+ NodeAssert.match(script, /^\$ErrorActionPreference = 'Stop'$/m);+ });++ it("gates on Windows x64 and refuses ARM64 and x86", () => {+ NodeAssert.match(script, /\$env:PROCESSOR_ARCHITECTURE/);+ NodeAssert.match(script, /\$env:PROCESSOR_ARCHITECTURE -ne 'AMD64'/);+ NodeAssert.match(script, /ARM64/);+ NodeAssert.match(script, /x86/);+ });++ it("requires TLS 1.2", () => {+ NodeAssert.match(script, /\[Net\.ServicePointManager\]::SecurityProtocol/);+ NodeAssert.match(script, /Tls12/);+ });++ it("supports a -Tag override and defaults to the latest stable release", () => {+ NodeAssert.match(script, /\$Tag/);+ NodeAssert.match(script, /Invoke-RestMethod/);+ NodeAssert.match(+ script,+ /https:\/\/api\.github\.com\/repos\/opencoredev\/akeru-bot\/releases\/latest/,+ );+ NodeAssert.match(script, /if \(-not \$Tag\)/);+ });++ it("accepts only strict vX.Y.Z tags", () => {+ NodeAssert.match(script, /\^v\\d\+\\.\\d\+\\.\\d\+\$/);+ });++ it("downloads the same-tag exe and SHA256SUMS to TEMP", () => {+ NodeAssert.match(script, /Akeru-Bot-\$version-x64\.exe/);+ NodeAssert.match(+ script,+ /\$base = "https:\/\/github\.com\/opencoredev\/akeru-bot\/releases\/download\/\$Tag"/,+ );+ NodeAssert.match(script, /Join-Path \$env:TEMP/);+ NodeAssert.match(script, /Invoke-WebRequest -Uri "\$base\/\$asset" -OutFile \$installerPath/);+ NodeAssert.match(script, /Invoke-WebRequest -Uri "\$base\/SHA256SUMS" -OutFile \$checksumPath/);+ NodeAssert.doesNotMatch(script, /\/releases\/latest\/download/);+ });++ it("verifies the exact checksum line with Get-FileHash before unblocking", () => {+ NodeAssert.match(script, /Select-String -Path \$checksumPath/);+ NodeAssert.match(script, /\[regex\]::Escape\(\$asset\)/);+ NodeAssert.match(script, /if \(\$entries\.Count -ne 1\)/);+ NodeAssert.match(script, /Get-FileHash -Path \$installerPath -Algorithm SHA256/);+ const hashIndex = script.indexOf("Get-FileHash");+ NodeAssert.ok(hashIndex > -1);+ NodeAssert.ok(script.indexOf("Unblock-File") > hashIndex);+ });++ it("unblocks the installer, checks its exit code, and runs it without silent flags", () => {+ NodeAssert.match(script, /^\s+Unblock-File -Path \$installerPath$/m);+ NodeAssert.match(script, /\$proc = Start-Process -FilePath \$installerPath -Wait -PassThru/);+ NodeAssert.match(script, /if \(\$proc\.ExitCode -ne 0\)/);+ NodeAssert.match(script, /installer exited with code/);+ NodeAssert.ok(script.indexOf("Start-Process") > script.indexOf("Unblock-File"));+ NodeAssert.doesNotMatch(script, /\/verysilent/i);+ NodeAssert.doesNotMatch(script, /\/silent/i);+ NodeAssert.doesNotMatch(script, /\/quiet/i);+ NodeAssert.doesNotMatch(script, / --silent/i);+ NodeAssert.doesNotMatch(script, / --quiet/i);+ });++ it("isolates payload downloads and removes them in finally", () => {+ NodeAssert.match(+ script,+ /\$tempDirectory = Join-Path \$env:TEMP "akeru-install-\$\(\[Guid\]::NewGuid\(\)\)"/,+ );+ NodeAssert.match(script, /New-Item -ItemType Directory -Path \$tempDirectory\r?\ntry \{/);+ NodeAssert.match(script, /\$installerPath = Join-Path \$tempDirectory \$asset/);+ NodeAssert.match(script, /\$checksumPath = Join-Path \$tempDirectory 'SHA256SUMS'/);+ NodeAssert.match(+ script,+ /\} finally \{\r?\n\s+Remove-Item -LiteralPath \$tempDirectory -Recurse -Force -ErrorAction SilentlyContinue\r?\n\}/,+ );+ });++ it("bootstraps in a Bypass child and always removes the downloaded script", () => {+ const bootstrap = script.split(/\r?\n/).find((line) => line.startsWith("# $t = "));+ NodeAssert.ok(bootstrap);+ NodeAssert.match(bootstrap, /akeru-install-\$\(\[Guid\]::NewGuid\(\)\)\.ps1/);+ NodeAssert.match(bootstrap, /Invoke-RestMethod .* -ErrorAction Stop/);+ NodeAssert.match(+ bootstrap,+ /try \{ Invoke-WebRequest .* -OutFile \$f -UseBasicParsing -ErrorAction Stop;/,+ );+ NodeAssert.match(+ bootstrap,+ /& powershell\.exe -NoProfile -ExecutionPolicy Bypass -File \$f -Tag \$t;/,+ );+ NodeAssert.match(bootstrap, /if \(\$LASTEXITCODE -ne 0\) \{ throw /);+ NodeAssert.match(+ bootstrap,+ /finally \{ Remove-Item -LiteralPath \$f -Force -ErrorAction SilentlyContinue \}/,+ );+ NodeAssert.doesNotMatch(bootstrap, /& \$f/);+ });++ it("never changes system-wide security settings", () => {+ NodeAssert.doesNotMatch(script, /Disable-/);+ NodeAssert.doesNotMatch(script, /Set-ExecutionPolicy/);+ NodeAssert.doesNotMatch(script, /SmartScreen/i);+ });++ it("supports -Help", () => {+ NodeAssert.match(script, /\[switch\]\$Help/);+ NodeAssert.match(script, /if \(\$Help\)/);+ NodeAssert.match(script, /usage: install-windows\.ps1 \[-Tag vX\.Y\.Z\]/);+ });++ it("prints the exact success sentence", () => {+ NodeAssert.match(script, /Write-Output "Installed Akeru Bot \$Tag\."/);+ });+});