a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
66 lines
2.0 KiB
Go
66 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/zzet/gortex/internal/daemon"
|
|
)
|
|
|
|
// The stop-intent contract is two-sided: `daemon stop` writes a sticky marker
|
|
// and an explicit `daemon start` clears it. If the clear ever regresses, a
|
|
// single `daemon stop` would suppress autostart forever — worse than the
|
|
// original bug — so guard both sides directly.
|
|
|
|
func TestRunDaemonStart_ClearsStopIntent(t *testing.T) {
|
|
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
|
defer restoreSeams()
|
|
|
|
if err := daemon.MarkStopIntent(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// Short-circuit start at the "already running" guard, which sits right
|
|
// after the clear — so no real serve loop is needed.
|
|
isDaemonRunning = func() bool { return true }
|
|
_ = runDaemonStart(&cobra.Command{}, nil)
|
|
|
|
if daemon.StopIntentActive() {
|
|
t.Fatal("an explicit `daemon start` must clear the stop-intent marker")
|
|
}
|
|
}
|
|
|
|
func TestRunDaemonStart_AutostartChildDoesNotClearStopIntent(t *testing.T) {
|
|
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
|
t.Setenv("GORTEX_DAEMON_CHILD", "1")
|
|
defer restoreSeams()
|
|
|
|
if err := daemon.MarkStopIntent(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
isDaemonRunning = func() bool { return true }
|
|
_ = runDaemonStart(&cobra.Command{}, nil)
|
|
|
|
// The autostart-spawned child must not erase a stop-intent the user may
|
|
// have written after the autostart decision (the TOCTOU window).
|
|
if !daemon.StopIntentActive() {
|
|
t.Fatal("autostart child must NOT clear the stop-intent marker")
|
|
}
|
|
}
|
|
|
|
func TestRunDaemonStop_UnsupervisedRecordsStopIntent(t *testing.T) {
|
|
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
|
defer restoreServiceSeams()
|
|
|
|
// The reporter's path: no service supervisor installed.
|
|
serviceActive = func() bool { return false }
|
|
// Daemon already down → stop returns via the already-down path after
|
|
// recording intent; no real daemon required.
|
|
if err := runDaemonStop(&cobra.Command{}, nil); err != nil {
|
|
t.Fatalf("runDaemonStop: %v", err)
|
|
}
|
|
if !daemon.StopIntentActive() {
|
|
t.Fatal("an unsupervised `daemon stop` must record stop-intent")
|
|
}
|
|
}
|