package release import ( "crypto/sha256" "encoding/hex" "os" "os/exec" "path/filepath" "strings" "testing" ) const ( finishVersion = "abc1234" keptID = "KEPTINSTANCE00000000000000" ) // finishRig is production as the 2026-11-19 cutover left it: steps 1 to 5 // recorded, the instance serving finishVersion on the kept database, the // old runner stopped with its old origin and files. scripts/cutover-finish-thin.sh // runs against stub carlos, systemctl, journalctl and curl on a temporary // HOME; carlos db (the replica) fails if anything calls it. type finishRig struct { t *testing.T root, home, runner string repo, log string serviceEnv, unit string } func newFinishRig(t *testing.T) *finishRig { t.Helper() root := t.TempDir() r := &finishRig{t: t, root: root, home: filepath.Join(root, "home"), log: filepath.Join(root, "calls.log"), repo: filepath.Join(root, "repo")} r.runner = filepath.Join(r.home, ".local/share/equipo-runner") for _, name := range []string{"cutover-finish-thin.sh", "cutover-thin.sh", "upgrade-thin.sh", "runner-config.py"} { src, err := os.ReadFile("../../scripts/" + name) r.must(err) r.write(filepath.Join(r.repo, "scripts", name), string(src), 0700) } release := filepath.Join(r.repo, "releases", "equipo-runner-linux-amd64-"+finishVersion) runner := "#!/bin/sh\n" + rendererStub(r.log) + "if [ \"$1\" = verify-installed ]; then echo \"equipo-runner verify-installed $EQUIPO_TOOL_PROXY_PATH\" >> " + r.log + "; exit; fi\necho \"equipo-runner $1 $EQUIPO_INSTANCE_ID $EQUIPO_ORIGIN\" >> " + r.log + "\n[ -e " + filepath.Join(root, "enrolfail") + " ] && exit 1\n# The running runner holds the state lock enrol needs.\n[ -e " + filepath.Join(root, "active") + " ] && { echo state locked >&2; exit 1; }\necho new > \"$EQUIPO_RUNNER_STATE_DIR/credentials.json\"\n" + linkedScanner + linkedRenderer r.write(filepath.Join(release, "equipo-runner"), runner, 0700) r.write(filepath.Join(release, RendererArchive), string(rendererArchiveBytes), 0600) r.write(filepath.Join(release, "equipo-tool-proxy"), "proxy", 0700) r.write(filepath.Join(release, "gitleaks"), scannerBytes, 0700) sum := func(s string) string { h := sha256.Sum256([]byte(s)); return hex.EncodeToString(h[:]) } r.write(filepath.Join(r.repo, "releases", "staged", finishVersion+".json"), `{"staging": "PASS", "sha256": {"runner": "`+sum(runner)+`", "tool_proxy": "`+sum("proxy")+`", "gitleaks": "`+sum(scannerBytes)+`"}}`, 0600) r.serviceEnv = "EQUIPO_ORIGIN=\"https://equipo.bds.oncarlos.com\"\nEQUIPO_INSTANCE_ID=\"" + keptID + "\"\nEQUIPO_TOOL_PROXY_PATH=\"/old/equipo-tool-proxy\"\nEQUIPO_RUNNER_STATE_DIR=\"" + filepath.Join(r.runner, "state") + "\"\n" r.unit = "[Service]\nEnvironmentFile=" + filepath.Join(r.runner, "service.env") + "\nExecStart=/old/equipo-runner run\nRestart=on-failure\nRestartSec=5\n" r.write(filepath.Join(r.runner, "service.env"), r.serviceEnv, 0600) r.write(filepath.Join(r.runner, "equipo-runner.service"), r.unit, 0600) r.write(filepath.Join(r.runner, "state", "credentials.json"), "old", 0600) backups := filepath.Join(r.home, ".local/share/equipo-cutover") r.write(filepath.Join(backups, "cutover.state"), "version="+finishVersion+"\nstamp=20261119T140850Z\nprev_version=prev999\nprev_always_on=1\nprev_database=-unset-\nprev_origin=https://equipo.bds.oncarlos.com\nold_instance_id="+keptID+"\ndone_preflight=1\ndone_export=1\ndone_config=1\ndone_deploy=1\n", 0600) r.write(filepath.Join(backups, "prior", "service.env"), r.serviceEnv, 0600) r.write(filepath.Join(backups, "prior", "equipo-runner.service"), r.unit, 0600) r.write(filepath.Join(root, "served"), finishVersion+"\n", 0600) r.setInstall("https://equipo.oficina.works", finishVersion, keptID) r.must(os.MkdirAll(filepath.Join(root, "proc", "4242"), 0700)) r.must(os.Symlink(filepath.Join(r.runner, "releases", finishVersion, "equipo-runner"), filepath.Join(root, "proc", "4242", "exe"))) bin := filepath.Join(root, "bin") log := "echo \"$(basename $0) $*\" >> " + r.log + "\n" r.write(filepath.Join(bin, "curl"), "#!/bin/sh\n"+log+`case "$*" in */install.sh) cat `+filepath.Join(root, "install.sh")+` ;; *) cat `+filepath.Join(root, "served")+` ;; esac `, 0700) unitStubs(r.write, root, filepath.Join(r.runner, "equipo-runner.service"), r.log) // mv and install fail once when asked to (root/failmv, root/failinstallstate): // a step interrupted half way. r.write(filepath.Join(bin, "mv"), "#!/bin/sh\nif [ -e "+filepath.Join(root, "failmv")+" ]; then rm "+filepath.Join(root, "failmv")+"; exit 1; fi\nexec /usr/bin/mv \"$@\"\n", 0700) r.write(filepath.Join(bin, "install"), "#!/bin/sh\ncase \"$*\" in *equipo-runner/state) if [ -e "+filepath.Join(root, "failinstallstate")+" ]; then rm "+filepath.Join(root, "failinstallstate")+"; exit 1; fi ;; esac\nexec /usr/bin/install \"$@\"\n", 0700) r.write(filepath.Join(bin, "carlos"), "#!/bin/sh\n"+log+`case "$1 $2" in "env list") printf 'using console\nKEY VALUE\nEQUIPO_DATABASE equipo-v1.db\nEQUIPO_ORIGIN https://equipo.oficina.works\n' ;; db*) echo "the copy failed its integrity check" >&2; exit 1 ;; esac `, 0700) return r } // setInstall is what the instance's /install.sh says. func (r *finishRig) setInstall(origin, version, instance string) { r.write(filepath.Join(r.root, "install.sh"), "#!/bin/sh\nset -eu\ncurl --fail '"+origin+"/releases/"+version+"/install-v1.sh' | sh -s -- '"+origin+"' '"+version+"' '"+instance+"'\n", 0600) } func (r *finishRig) must(err error) { r.t.Helper() if err != nil { r.t.Fatal(err) } } func (r *finishRig) write(path, body string, mode os.FileMode) { r.t.Helper() r.must(os.MkdirAll(filepath.Dir(path), 0700)) r.must(os.WriteFile(path, []byte(body), mode)) } func (r *finishRig) read(path string) string { raw, _ := os.ReadFile(path) return string(raw) } func (r *finishRig) run(script string, args ...string) (string, error) { cmd := exec.Command("bash", append([]string{filepath.Join(r.repo, "scripts", script)}, args...)...) cmd.Env = []string{"HOME=" + r.home, "PATH=" + filepath.Join(r.root, "bin") + ":/usr/bin:/bin", "CUTOVER_YES=1", "CUTOVER_TRIES=3", "CUTOVER_WAIT=0", "CUTOVER_PROC=" + filepath.Join(r.root, "proc"), "LANG=C.UTF-8"} out, err := cmd.CombinedOutput() return string(out), err } func (r *finishRig) state() string { return r.read(filepath.Join(r.home, ".local/share/equipo-cutover/cutover.state")) } // The plan changes nothing, never reads the replica, and lists the steps. func TestCutoverFinishPlanChangesNothing(t *testing.T) { r := newFinishRig(t) state := r.state() out, err := r.run("cutover-finish-thin.sh") if err != nil { t.Fatalf("plan: %v\n%s", err, out) } inOrder(t, out, "instance "+keptID, "== 6 identity", "sh -s -- 'https://equipo.oficina.works' '"+finishVersion+"' '"+keptID+"'", "== 7 config", "env unset --app equipo --account oficina --console https://console.carloku.com EQUIPO_DATABASE", "== 8 install", "runner-config.py render", "EQUIPO_INSTANCE_ID="+keptID, "EQUIPO_ORIGIN=https://equipo.oficina.works", "state.pre-thin-20261119T140850Z", "== 9 enrol", "runner-config.py check", "verify-installed", "enrol", "== 10 start", "systemctl --user start", "== 11 verify", "_SYSTEMD_INVOCATION_ID=", "msg=welcome", "Plan only.") if strings.Contains(out, "would refuse") || strings.Contains(out, "carlos db") { t.Fatalf("plan refuses or reads the replica:\n%s", out) } if r.read(r.log) != "" || r.state() != state || r.read(filepath.Join(r.runner, "service.env")) != r.serviceEnv { t.Fatalf("the plan changed something:\n%s", r.read(r.log)) } } // The finish moves the runner to the public origin with the kept instance // id, enrols it, verifies through the instance alone, and records the // steps so the upgrade accepts the cutover as finished. func TestCutoverFinishOnTheKeptDatabase(t *testing.T) { r := newFinishRig(t) out, err := r.run("cutover-finish-thin.sh", "--execute") if err != nil { t.Fatalf("finish: %v\n%s", err, out) } calls := r.read(r.log) inOrder(t, calls, "install.sh", "env unset --app equipo --account oficina --console https://console.carloku.com EQUIPO_DATABASE", "install.sh", "daemon-reload", "equipo-runner verify-installed "+filepath.Join(r.runner, "releases", finishVersion, "equipo-tool-proxy"), "equipo-runner enrol "+keptID+" https://equipo.oficina.works", "systemctl --user start", "install.sh", "journalctl --user -b _SYSTEMD_INVOCATION_ID=0123456789abcdef0123456789abcdef _PID=4242") for _, never := range []string{"carlos db", "promote", "deploy", "env set"} { if strings.Contains(calls, never) { t.Fatalf("finish ran %q:\n%s", never, calls) } } env := r.read(filepath.Join(r.runner, "service.env")) if !strings.Contains(env, "EQUIPO_ORIGIN=\"https://equipo.oficina.works\"") || !strings.Contains(env, "EQUIPO_INSTANCE_ID=\""+keptID+"\"") { t.Fatalf("runner config not moved:\n%s", env) } if r.read(filepath.Join(r.runner, "state.pre-thin-20261119T140850Z", "credentials.json")) != "old" { t.Fatal("old runner state not kept aside") } st := r.state() for _, want := range []string{"kept_database=1", "new_instance_id=" + keptID, "done_identity=1", "done_unset=1", "done_runner=1", "done_enrol=1", "done_verify=1"} { if !strings.Contains(st, want) { t.Fatalf("cutover.state lacks %q:\n%s", want, st) } } if out, err = r.run("upgrade-thin.sh", "bbb2222"); err != nil || strings.Contains(out, "would refuse") { t.Fatalf("upgrade does not accept the finished cutover: %v\n%s", err, out) } if out, err = r.run("cutover-finish-thin.sh", "--execute"); err == nil || !strings.Contains(out, "complete") { t.Fatalf("second finish allowed: %v\n%s", err, out) } } // Anything that does not show the kept database, or a cutover not at its // deploy, stops the finish before it changes anything. func TestCutoverFinishRefusesBeforeChangingAnything(t *testing.T) { for name, set := range map[string]func(r *finishRig){ "another instance id": func(r *finishRig) { r.setInstall("https://equipo.oficina.works", finishVersion, "FRESHINSTANCE0000000000000") }, "the old origin": func(r *finishRig) { r.setInstall("https://equipo.bds.oncarlos.com", finishVersion, keptID) }, "another version": func(r *finishRig) { r.write(filepath.Join(r.root, "served"), "ccc3333\n", 0600) }, "other runner bytes": func(r *finishRig) { r.write(filepath.Join(r.repo, "releases", "equipo-runner-linux-amd64-"+finishVersion, "equipo-runner"), "#!/bin/sh\n", 0700) }, "unstaged scanner": func(r *finishRig) { r.write(filepath.Join(r.repo, "releases", "staged", finishVersion+".json"), strings.Replace(r.read(filepath.Join(r.repo, "releases", "staged", finishVersion+".json")), `"gitleaks": "`, `"gitleaks": "0`, 1), 0600) }, "unstaged version": func(r *finishRig) { r.write(filepath.Join(r.repo, "releases", "staged", finishVersion+".json"), `{"staging": "FAIL"}`, 0600) }, "no deploy": func(r *finishRig) { r.write(filepath.Join(r.home, ".local/share/equipo-cutover/cutover.state"), strings.Replace(r.state(), "done_deploy=1\n", "", 1), 0600) }, } { t.Run(name, func(t *testing.T) { r := newFinishRig(t) r.t = t set(r) state := r.state() out, err := r.run("cutover-finish-thin.sh", "--execute") if err == nil || !strings.Contains(out, "refused") { t.Fatalf("not refused: %v\n%s", err, out) } for _, change := range []string{"env unset", "systemctl", "enrol"} { if strings.Contains(r.read(r.log), change) { t.Fatalf("changed something (%s) before refusing:\n%s", change, r.read(r.log)) } } if r.state() != state || r.read(filepath.Join(r.runner, "service.env")) != r.serviceEnv || r.read(filepath.Join(r.runner, "state", "credentials.json")) != "old" { t.Fatal("state or runner changed before refusing") } }) } } // Verify needs the staged bytes running and the instance's welcome to that // process in its log; once both hold, the same run resumes and finishes. func TestCutoverFinishVerifiesThroughTheInstance(t *testing.T) { r := newFinishRig(t) r.write(filepath.Join(r.root, "journal"), "msg=\"runner stream\" err=unauthorized\n", 0600) if out, err := r.run("cutover-finish-thin.sh", "--execute"); err == nil || !strings.Contains(out, "not connected") { t.Fatalf("verified without a welcome: %v\n%s", err, out) } r.write(filepath.Join(r.root, "journal"), "msg=welcome generation=2\n", 0600) exe := filepath.Join(r.root, "proc", "4242", "exe") r.must(os.Remove(exe)) r.must(os.Symlink("/bin/sh", exe)) if out, err := r.run("cutover-finish-thin.sh", "--execute"); err == nil || !strings.Contains(out, "not the staged") { t.Fatalf("accepted another running binary: %v\n%s", err, out) } if strings.Contains(r.state(), "done_verify=1") { t.Fatal("verify recorded after a failed check") } r.must(os.Remove(exe)) r.must(os.Symlink(filepath.Join(r.runner, "releases", finishVersion, "equipo-runner"), exe)) if out, err := r.run("cutover-finish-thin.sh", "--execute"); err != nil || strings.Count(r.read(r.log), "equipo-runner enrol") != 1 { t.Fatalf("did not resume past finished steps: %v\n%s\n%s", err, out, r.read(r.log)) } } // Rollback puts the runner back as the cutover left it, stopped, offers // no earlier version, and the upgrade and the cutover's own rollback then // refuse. func TestCutoverFinishRollbackOffersNoEarlierVersion(t *testing.T) { r := newFinishRig(t) if out, err := r.run("cutover-finish-thin.sh", "--execute"); err != nil { t.Fatalf("finish: %v\n%s", err, out) } before := r.read(r.log) out, err := r.run("cutover-finish-thin.sh", "rollback", "--execute") if err != nil { t.Fatalf("rollback: %v\n%s", err, out) } if r.read(filepath.Join(r.runner, "service.env")) != r.serviceEnv || r.read(filepath.Join(r.runner, "equipo-runner.service")) != r.unit || r.read(filepath.Join(r.runner, "state", "credentials.json")) != "old" { t.Fatal("runner not put back exactly") } calls := strings.TrimPrefix(r.read(r.log), before) for _, never := range []string{"promote", "deploy", "env set", "systemctl --user start"} { if strings.Contains(calls, never) { t.Fatalf("rollback ran %q:\n%s", never, calls) } } if !strings.Contains(out, "prev999 is not offered") || !strings.Contains(out, "cannot read the migrated schema") { t.Fatalf("rollback does not say why the earlier version is not offered:\n%s", out) } if out, err = r.run("upgrade-thin.sh", "bbb2222"); err != nil || !strings.Contains(out, "would refuse: the cutover has not finished") { t.Fatalf("upgrade accepts a rolled-back finish: %v\n%s", err, out) } if out, err = r.run("cutover-thin.sh", "rollback", "--execute"); err == nil || !strings.Contains(out, "prev999 cannot read it") { t.Fatalf("the cutover's rollback offers prev999: %v\n%s", err, out) } if out, err = r.run("cutover-finish-thin.sh", "rollback", "--execute"); err == nil { t.Fatalf("second rollback allowed: %s", out) } if out, err = r.run("cutover-finish-thin.sh", "--execute"); err != nil { t.Fatalf("finish again after rollback: %v\n%s", err, out) } } // finished asserts the finish ended with the runner moved, the old state // kept aside, and the original runner files recorded. func (r *finishRig) finished(out string, err error) { r.t.Helper() if err != nil { r.t.Fatalf("finish: %v\n%s", err, out) } if !strings.Contains(r.read(filepath.Join(r.runner, "service.env")), "EQUIPO_ORIGIN=\"https://equipo.oficina.works\"") || r.read(filepath.Join(r.runner, "state.pre-thin-20261119T140850Z", "credentials.json")) != "old" || r.read(filepath.Join(r.runner, "state", "credentials.json")) != "new\n" || !strings.Contains(r.state(), "done_verify=1") { r.t.Fatalf("not finished:\n%s\n%s", out, r.state()) } snap := filepath.Join(r.home, ".local/share/equipo-cutover/finish-20261119T140850Z") if r.read(filepath.Join(snap, "service.env")) != r.serviceEnv || r.read(filepath.Join(snap, "equipo-runner.service")) != r.unit { r.t.Fatal("the recorded runner files are not the originals") } } // Step 8 interrupted anywhere resumes: after the files are written but // before the state moves, after the move but before the new state exists, // after the new state exists, and after a move nobody recorded. func TestCutoverFinishRunnerStepResumes(t *testing.T) { for _, flag := range []string{"failmv", "failinstallstate", "failreload"} { t.Run(flag, func(t *testing.T) { r := newFinishRig(t) r.t = t r.write(filepath.Join(r.root, flag), "", 0600) if out, err := r.run("cutover-finish-thin.sh", "--execute"); err == nil || strings.Contains(r.state(), "done_runner=1") { t.Fatalf("step 8 did not stop: %v\n%s", err, out) } r.finished(r.run("cutover-finish-thin.sh", "--execute")) }) } t.Run("unrecorded move", func(t *testing.T) { r := newFinishRig(t) r.t = t r.must(os.Rename(filepath.Join(r.runner, "state"), filepath.Join(r.runner, "state.pre-thin-20261119T140850Z"))) r.finished(r.run("cutover-finish-thin.sh", "--execute")) }) t.Run("both states and no record", func(t *testing.T) { r := newFinishRig(t) r.t = t r.write(filepath.Join(r.runner, "state.pre-thin-20261119T140850Z", "credentials.json"), "older", 0600) out, err := r.run("cutover-finish-thin.sh", "--execute") if err == nil || !strings.Contains(out, "no move is recorded") || r.read(filepath.Join(r.runner, "state", "credentials.json")) != "old" { t.Fatalf("went on with two runner states: %v\n%s", err, out) } }) } // A record that cannot be written stops the run at once. func TestCutoverFinishStopsWhenItCannotRecord(t *testing.T) { r := newFinishRig(t) r.must(os.Chmod(filepath.Join(r.home, ".local/share/equipo-cutover/cutover.state"), 0400)) out, err := r.run("cutover-finish-thin.sh", "--execute") if err == nil || !strings.Contains(out, "could not record") || strings.Contains(r.read(r.log), "env unset") { t.Fatalf("went on without its record: %v\n%s", err, out) } } // The runner's files must hold each expected entry exactly once; the // written and the loaded configuration are checked again before enrolment. func TestCutoverFinishChecksTheRunnerConfig(t *testing.T) { for name, set := range map[string]func(r *finishRig){ "origin twice": func(r *finishRig) { r.serviceEnv += "EQUIPO_ORIGIN=\"https://elsewhere.example.com\"\n" r.write(filepath.Join(r.runner, "service.env"), r.serviceEnv, 0600) }, "no instance id": func(r *finishRig) { r.serviceEnv = strings.Replace(r.serviceEnv, "EQUIPO_INSTANCE_ID=\""+keptID+"\"\n", "", 1) r.write(filepath.Join(r.runner, "service.env"), r.serviceEnv, 0600) }, "no RestartSec": func(r *finishRig) { r.unit = strings.Replace(r.unit, "RestartSec=5\n", "", 1) r.write(filepath.Join(r.runner, "equipo-runner.service"), r.unit, 0600) }, } { t.Run(name, func(t *testing.T) { r := newFinishRig(t) r.t = t set(r) out, err := r.run("cutover-finish-thin.sh", "--execute") if err == nil || !strings.Contains(out, "not one") || strings.Contains(r.read(r.log), "equipo-runner enrol") || r.read(filepath.Join(r.runner, "state", "credentials.json")) != "old" { t.Fatalf("went on with an unexpected runner config: %v\n%s", err, out) } }) } t.Run("changed before enrol", func(t *testing.T) { r := newFinishRig(t) r.t = t r.write(filepath.Join(r.root, "enrolfail"), "", 0600) if out, err := r.run("cutover-finish-thin.sh", "--execute"); err == nil || !strings.Contains(r.state(), "done_runner=1") { t.Fatalf("enrol failure not reached: %v\n%s", err, out) } r.must(os.Remove(filepath.Join(r.root, "enrolfail"))) env := filepath.Join(r.runner, "service.env") r.write(env, strings.Replace(r.read(env), "https://equipo.oficina.works", "https://equipo.bds.oncarlos.com", 1), 0600) before := strings.Count(r.read(r.log), "equipo-runner enrol") out, err := r.run("cutover-finish-thin.sh", "--execute") if err == nil || !strings.Contains(out, "does not hold EQUIPO_ORIGIN") || strings.Count(r.read(r.log), "equipo-runner enrol") != before { t.Fatalf("enrolled with a changed config: %v\n%s", err, out) } }) t.Run("another unit loaded", func(t *testing.T) { r := newFinishRig(t) r.t = t r.write(filepath.Join(r.root, "loaded"), "{ path=/old/equipo-runner ; argv[]=/old/equipo-runner run }\n", 0600) out, err := r.run("cutover-finish-thin.sh", "--execute") if err == nil || !strings.Contains(out, "the loaded equipo-runner.service does not start") || strings.Contains(r.read(r.log), "equipo-runner enrol") { t.Fatalf("enrolled with another unit loaded: %v\n%s", err, out) } }) t.Run("unsafe value", func(t *testing.T) { cmd := exec.Command("python3", "../../scripts/runner-config.py", "check", t.TempDir(), "--exec", "/x/equipo-runner", "EQUIPO_ORIGIN=https://a|b") if out, err := cmd.CombinedOutput(); err == nil || !strings.Contains(string(out), "unexpected characters") { t.Fatalf("accepted a value with a replacement character: %v %s", err, out) } }) } // Verified means connected now, in this invocation. func TestCutoverFinishVerifiesTheCurrentConnection(t *testing.T) { for name, set := range map[string]func(r *finishRig){ "dropped since": func(r *finishRig) { r.write(filepath.Join(r.root, "journal"), "msg=welcome generation=1\nmsg=\"runner stream ended\" retry_in=1s\n", 0600) }, "another invocation each time": func(r *finishRig) { r.write(filepath.Join(r.root, "flap"), "", 0600) }, } { t.Run(name, func(t *testing.T) { r := newFinishRig(t) r.t = t set(r) out, err := r.run("cutover-finish-thin.sh", "--execute") if err == nil || !strings.Contains(out, "not connected") || strings.Contains(r.state(), "done_verify=1") { t.Fatalf("verified without a current connection: %v\n%s", err, out) } }) } } // A rollback that leaves the runner running is not recorded. func TestCutoverFinishRollbackChecksTheRunnerStopped(t *testing.T) { r := newFinishRig(t) if out, err := r.run("cutover-finish-thin.sh", "--execute"); err != nil { t.Fatalf("finish: %v\n%s", err, out) } r.write(filepath.Join(r.root, "stuck"), "", 0600) if out, err := r.run("cutover-finish-thin.sh", "rollback", "--execute"); err == nil || !strings.Contains(out, "still running") || strings.Contains(r.state(), "kept_database=0") { t.Fatalf("rollback recorded with the runner running: %v\n%s", err, out) } } // A run cut off right after the unit starts resumes forward: enrolment is // already recorded, so enrol (which the running runner's state lock would // refuse) does not run again, and the unit is not started twice. func TestCutoverFinishResumesAfterTheStart(t *testing.T) { r := newFinishRig(t) r.write(filepath.Join(r.root, "killafterstart"), "", 0600) if out, err := r.run("cutover-finish-thin.sh", "--execute"); err == nil { t.Fatalf("the run was not interrupted:\n%s", out) } if !strings.Contains(r.state(), "done_enrol=1") || strings.Contains(r.state(), "done_start=1") { t.Fatalf("enrol not recorded before the start:\n%s", r.state()) } r.finished(r.run("cutover-finish-thin.sh", "--execute")) if n := strings.Count(r.read(r.log), "equipo-runner enrol"); n != 1 { t.Fatalf("enrol ran %d times", n) } }