All checks were successful
Why: disinto_init() consumed $1 as repo_url before the argparse loop ran,
so `disinto init --backend=nomad --empty` had --backend=nomad swallowed
into repo_url, backend stayed at its "docker" default, and the --empty
validation then produced the nonsense "--empty is only valid with
--backend=nomad" error — flagged during S0.1 end-to-end verification on
a fresh LXC. nomad backend takes no positional anyway; the LXC already
has the repo cloned by the operator.
Change: only consume $1 as repo_url if it doesn't start with "--", then
defer the "repo URL required" check to after argparse (so the docker
path still errors with a helpful message on a missing positional, not
"Unknown option: --backend=docker").
Verified acceptance criteria:
1. init --backend=nomad --empty → dispatches to nomad
2. init --backend=nomad --empty --dry-run → 9-step plan, exit 0
3. init <repo-url> → docker path unchanged
4. init → "repo URL required"
5. init --backend=docker → "repo URL required"
(not "Unknown option")
6. shellcheck clean
Tests: 4 new regression cases in tests/disinto-init-nomad.bats covering
flag-first nomad invocation (both --flag=value and --flag value forms),
no-args docker default, and --backend=docker missing-positional error
path. Full suite: 10/10 pass.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
145 lines
7.2 KiB
Bash
145 lines
7.2 KiB
Bash
#!/usr/bin/env bats
|
|
# =============================================================================
|
|
# tests/disinto-init-nomad.bats — Regression guard for `disinto init`
|
|
# backend dispatch (S0.5, issue #825).
|
|
#
|
|
# Exercises the three CLI paths the Nomad+Vault migration cares about:
|
|
# 1. --backend=nomad --dry-run → cluster-up step list
|
|
# 2. --backend=nomad --empty --dry-run → same, with "--empty" banner
|
|
# 3. --backend=docker --dry-run → docker path unaffected
|
|
#
|
|
# A throw-away `placeholder/repo` slug satisfies the CLI's positional-arg
|
|
# requirement (the nomad dispatcher never touches it). --dry-run on both
|
|
# backends short-circuits before any network/filesystem mutation, so the
|
|
# suite is hermetic — no Forgejo, no sudo, no real cluster.
|
|
# =============================================================================
|
|
|
|
setup_file() {
|
|
export DISINTO_ROOT
|
|
DISINTO_ROOT="$(cd "$(dirname "$BATS_TEST_FILENAME")/.." && pwd)"
|
|
export DISINTO_BIN="${DISINTO_ROOT}/bin/disinto"
|
|
[ -x "$DISINTO_BIN" ] || {
|
|
echo "disinto binary not executable: $DISINTO_BIN" >&2
|
|
return 1
|
|
}
|
|
}
|
|
|
|
# ── --backend=nomad --dry-run ────────────────────────────────────────────────
|
|
|
|
@test "disinto init --backend=nomad --dry-run exits 0 and prints the step list" {
|
|
run "$DISINTO_BIN" init placeholder/repo --backend=nomad --dry-run
|
|
[ "$status" -eq 0 ]
|
|
|
|
# Dispatcher banner (cluster-up mode, no --empty).
|
|
[[ "$output" == *"nomad backend: default (cluster-up; jobs deferred to Step 1)"* ]]
|
|
|
|
# All nine cluster-up dry-run steps, in order.
|
|
[[ "$output" == *"[dry-run] Step 1/9: install nomad + vault binaries"* ]]
|
|
[[ "$output" == *"[dry-run] Step 2/9: write + enable nomad.service (NOT started)"* ]]
|
|
[[ "$output" == *"[dry-run] Step 3/9: write + enable vault.service + vault.hcl (NOT started)"* ]]
|
|
[[ "$output" == *"[dry-run] Step 4/9: create host-volume dirs under /srv/disinto/"* ]]
|
|
[[ "$output" == *"[dry-run] Step 5/9: install /etc/nomad.d/server.hcl + client.hcl from repo"* ]]
|
|
[[ "$output" == *"[dry-run] Step 6/9: first-run vault init + persist unseal.key + root.token"* ]]
|
|
[[ "$output" == *"[dry-run] Step 7/9: systemctl start vault + poll until unsealed"* ]]
|
|
[[ "$output" == *"[dry-run] Step 8/9: systemctl start nomad + poll until ≥1 node ready"* ]]
|
|
[[ "$output" == *"[dry-run] Step 9/9: write /etc/profile.d/disinto-nomad.sh"* ]]
|
|
|
|
[[ "$output" == *"Dry run complete — no changes made."* ]]
|
|
}
|
|
|
|
# ── --backend=nomad --empty --dry-run ────────────────────────────────────────
|
|
|
|
@test "disinto init --backend=nomad --empty --dry-run prints the --empty banner + step list" {
|
|
run "$DISINTO_BIN" init placeholder/repo --backend=nomad --empty --dry-run
|
|
[ "$status" -eq 0 ]
|
|
|
|
# --empty changes the dispatcher banner but not the step list — Step 1
|
|
# of the migration will branch on $empty to gate job deployment; today
|
|
# both modes invoke the same cluster-up dry-run.
|
|
[[ "$output" == *"nomad backend: --empty (cluster-up only, no jobs)"* ]]
|
|
[[ "$output" == *"[dry-run] Step 1/9: install nomad + vault binaries"* ]]
|
|
[[ "$output" == *"Dry run complete — no changes made."* ]]
|
|
}
|
|
|
|
# ── --backend=docker (regression guard) ──────────────────────────────────────
|
|
|
|
@test "disinto init --backend=docker does NOT dispatch to the nomad path" {
|
|
run "$DISINTO_BIN" init placeholder/repo --backend=docker --dry-run
|
|
[ "$status" -eq 0 ]
|
|
|
|
# Negative assertion: the nomad dispatcher banners must be absent.
|
|
[[ "$output" != *"nomad backend:"* ]]
|
|
[[ "$output" != *"[dry-run] Step 1/9: install nomad + vault binaries"* ]]
|
|
|
|
# Positive assertion: docker-path output still appears — the existing
|
|
# docker dry-run printed "=== disinto init ===" before listing the
|
|
# intended forge/compose actions.
|
|
[[ "$output" == *"=== disinto init ==="* ]]
|
|
[[ "$output" == *"── Dry-run: intended actions ────"* ]]
|
|
}
|
|
|
|
# ── Flag syntax: --flag=value vs --flag value ────────────────────────────────
|
|
|
|
# Both forms must work. The bin/disinto flag loop has separate cases for
|
|
# `--backend value` and `--backend=value`; a regression in either would
|
|
# silently route to the docker default, which is the worst failure mode
|
|
# for a mid-migration dispatcher ("loud-failing stub" lesson from S0.4).
|
|
@test "disinto init --backend nomad (space-separated) dispatches to nomad" {
|
|
run "$DISINTO_BIN" init placeholder/repo --backend nomad --dry-run
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == *"nomad backend: default"* ]]
|
|
[[ "$output" == *"[dry-run] Step 1/9: install nomad + vault binaries"* ]]
|
|
}
|
|
|
|
# ── Flag validation ──────────────────────────────────────────────────────────
|
|
|
|
@test "--backend=bogus is rejected with a clear error" {
|
|
run "$DISINTO_BIN" init placeholder/repo --backend=bogus --dry-run
|
|
[ "$status" -ne 0 ]
|
|
[[ "$output" == *"invalid --backend value"* ]]
|
|
}
|
|
|
|
@test "--empty without --backend=nomad is rejected" {
|
|
run "$DISINTO_BIN" init placeholder/repo --backend=docker --empty --dry-run
|
|
[ "$status" -ne 0 ]
|
|
[[ "$output" == *"--empty is only valid with --backend=nomad"* ]]
|
|
}
|
|
|
|
# ── Positional vs flag-first invocation (#835) ───────────────────────────────
|
|
#
|
|
# Before the #835 fix, disinto_init eagerly consumed $1 as repo_url *before*
|
|
# argparse ran. That swallowed `--backend=nomad` as a repo_url and then
|
|
# complained that `--empty` required a nomad backend — the nonsense error
|
|
# flagged during S0.1 end-to-end verification. The cases below pin the CLI
|
|
# to the post-fix contract: the nomad path accepts flag-first invocation,
|
|
# the docker path still errors helpfully on a missing repo_url.
|
|
|
|
@test "disinto init --backend=nomad --empty --dry-run (no positional) dispatches to nomad" {
|
|
run "$DISINTO_BIN" init --backend=nomad --empty --dry-run
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == *"nomad backend: --empty (cluster-up only, no jobs)"* ]]
|
|
[[ "$output" == *"[dry-run] Step 1/9: install nomad + vault binaries"* ]]
|
|
# The bug symptom must be absent — backend was misdetected as docker
|
|
# when --backend=nomad got swallowed as repo_url.
|
|
[[ "$output" != *"--empty is only valid with --backend=nomad"* ]]
|
|
}
|
|
|
|
@test "disinto init --backend nomad --dry-run (space-separated, no positional) dispatches to nomad" {
|
|
run "$DISINTO_BIN" init --backend nomad --dry-run
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == *"nomad backend: default"* ]]
|
|
[[ "$output" == *"[dry-run] Step 1/9: install nomad + vault binaries"* ]]
|
|
}
|
|
|
|
@test "disinto init (no args) still errors with 'repo URL required'" {
|
|
run "$DISINTO_BIN" init
|
|
[ "$status" -ne 0 ]
|
|
[[ "$output" == *"repo URL required"* ]]
|
|
}
|
|
|
|
@test "disinto init --backend=docker (no positional) errors with 'repo URL required', not 'Unknown option'" {
|
|
run "$DISINTO_BIN" init --backend=docker
|
|
[ "$status" -ne 0 ]
|
|
[[ "$output" == *"repo URL required"* ]]
|
|
[[ "$output" != *"Unknown option"* ]]
|
|
}
|