/** * Tests the rollout command builder without touching a remote host. * The guard is a shell command, so these checks pin the safety-critical text. */ import { expect, test } from "bun:test"; import { buildRolloutCommand } from "./rollout"; /** Builds the smallest complete rollout input for command rendering tests. */ function rolloutInput(allowEmptyRepositories: boolean) { return { allowEmptyRepositories, composeEnvFilePath: "compose.env", composeFilePath: "compose.yaml", dockerhubPullTokenFilePath: "dockerhub.pull.token", dockerhubUsername: "kaychaks", knotEnvFilePath: "knot.env", }; } test("rollout guard refuses an unexpected empty repository directory", () => { const command = buildRolloutCommand(rolloutInput(false)); expect(command).toContain("allow_empty_repositories=0"); expect(command).toContain("repository_count=$(find /opt/knot/repositories"); expect(command).toContain( "Refusing rollout: /opt/knot/repositories is empty while /opt/knot/server/knotserver.db exists.", ); expect(command).toContain("KNOT_ROLLOUT_ALLOW_EMPTY_REPOSITORIES=1"); }); test("rollout guard renders the explicit empty-repository override", () => { const command = buildRolloutCommand(rolloutInput(true)); expect(command).toContain("allow_empty_repositories=1"); });