Implement controlled app launch (T-401)

This commit is contained in:
ila
2026-07-19 21:10:59 +08:00
parent d0cf333394
commit 87083c387f
32 changed files with 1802 additions and 31 deletions
+35
View File
@@ -57,6 +57,41 @@ func TestSwitcherRemovesFailedInitialInstall(t *testing.T) {
assertMissing(t, filepath.Join(root, transactionFileName))
}
func TestSwitcherPreSwitchCheckPreventsUpdateAndCleansStaging(t *testing.T) {
root := makeInstallRoot(t, "old", "new")
checkErr := errors.New("target is running")
switcher := NewSwitcherWithPreSwitchCheck(
func(string) error { return nil },
func() error {
assertVersion(t, filepath.Join(root, "current"), "old")
assertVersion(t, filepath.Join(root, "staging"), "new")
return checkErr
},
)
err := switcher.Switch(root)
if !errors.Is(err, checkErr) {
t.Fatalf("Switch() error = %v, want %v", err, checkErr)
}
assertVersion(t, filepath.Join(root, "current"), "old")
assertMissing(t, filepath.Join(root, "staging"))
assertMissing(t, filepath.Join(root, "backup"))
assertMissing(t, filepath.Join(root, transactionFileName))
}
func TestSwitcherSkipsPreSwitchCheckForInitialInstall(t *testing.T) {
root := makeInstallRoot(t, "", "new")
switcher := NewSwitcherWithPreSwitchCheck(
func(string) error { return nil },
func() error { return errors.New("must not run") },
)
if err := switcher.Switch(root); err != nil {
t.Fatalf("Switch() error = %v", err)
}
assertVersion(t, filepath.Join(root, "current"), "new")
}
func TestRecoverInterruptedSwitch(t *testing.T) {
tests := []struct {
name string