Route native service commands and configure fresh authoring role
Select native installs only via explicit PIPELINES_PREFIX or the matching owned prefix/bin/pipelines executable. Route enable/status/disable to the existing native supervisor; validate registration ownership, label and command, keep preview read-only, and disable login registration before stopping. Never fall back to a standalone service for an invalid explicit prefix. Fresh native installs explicitly enable authoring, while reinstalls preserve false or missing legacy role settings. Add explicit --allow-authoring/--no-authoring overrides and pass the server flag only for manifest true. Print a copyable native enable command and update installation help/docs. No Docker configuration changes. Checks: 54 mocked native installer/lifecycle tests; 8 entrypoint tests; offline Go installation/CLI tests and vet; gofmt clean; shell syntax and diff checks. No live install, restart, deployment, permission/config changes, or native Linux verification.
This commit is contained in:
@@ -48,3 +48,100 @@ func TestStandaloneGoInstalledCommandHasNoServiceDependency(t *testing.T) {
|
||||
t.Fatal(config, err)
|
||||
}
|
||||
}
|
||||
|
||||
func nativeFixture(t *testing.T) (string, string) {
|
||||
t.Helper()
|
||||
root, err := filepath.EvalSymlinks(t.TempDir())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = os.Mkdir(filepath.Join(root, "bin"), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
binary := filepath.Join(root, "bin", "pipelines")
|
||||
if err = os.WriteFile(binary, []byte("binary"), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
config := Config{Format: 1, Prefix: root, ServerPort: 18080, Python: filepath.Join(root, "python3")}
|
||||
config.Ntfy.Mode = "native"
|
||||
data, _ := json.Marshal(config)
|
||||
if err = os.WriteFile(filepath.Join(root, "pipelines-install.json"), data, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return root, binary
|
||||
}
|
||||
|
||||
func TestNativeExecutableDiscoveryAndExplicitPrefixPrecedence(t *testing.T) {
|
||||
t.Setenv("PIPELINES_PREFIX", "")
|
||||
root, binary := nativeFixture(t)
|
||||
link := filepath.Join(t.TempDir(), "pipelines")
|
||||
if err := os.Symlink(binary, link); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loaded, err := Load(link)
|
||||
if err != nil || loaded == nil || loaded.Prefix != root {
|
||||
t.Fatal("native executable not selected", loaded, err)
|
||||
}
|
||||
other, _ := nativeFixture(t)
|
||||
t.Setenv("PIPELINES_PREFIX", other)
|
||||
loaded, err = Load(link)
|
||||
if err != nil || loaded == nil || loaded.Prefix != other {
|
||||
t.Fatal("explicit selection lost precedence", loaded, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiscoveryNeverGuessesHomeOrLegacyInstallation(t *testing.T) {
|
||||
t.Setenv("PIPELINES_PREFIX", "")
|
||||
root, binary := nativeFixture(t)
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
if err := os.MkdirAll(filepath.Join(home, ".local", "share"), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Symlink(root, filepath.Join(home, ".local", "share", "pipelines")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
unrelated := filepath.Join(t.TempDir(), "pipelines")
|
||||
if err := os.WriteFile(unrelated, []byte("binary"), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
loaded, err := Load(unrelated)
|
||||
if err != nil || loaded != nil {
|
||||
t.Fatal("unrelated executable selected installation", loaded, err)
|
||||
}
|
||||
config := Config{Format: 1, Prefix: root, ServerPort: 18080}
|
||||
data, _ := json.Marshal(config)
|
||||
os.WriteFile(filepath.Join(root, "pipelines-install.json"), data, 0600)
|
||||
loaded, err = Load(binary)
|
||||
if err != nil || loaded != nil {
|
||||
t.Fatal("legacy manifest was inferred", loaded, err)
|
||||
}
|
||||
t.Setenv("PIPELINES_PREFIX", root)
|
||||
loaded, err = Load(binary)
|
||||
if err != nil || loaded == nil {
|
||||
t.Fatal("explicit legacy selection stopped working", loaded, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNativeDiscoveryRejectsSymlinkManifestAndMismatchedPrefix(t *testing.T) {
|
||||
for _, test := range []string{"symlink", "mismatch"} {
|
||||
t.Run(test, func(t *testing.T) {
|
||||
t.Setenv("PIPELINES_PREFIX", "")
|
||||
root, binary := nativeFixture(t)
|
||||
manifest := filepath.Join(root, "pipelines-install.json")
|
||||
if test == "symlink" {
|
||||
target := filepath.Join(root, "other.json")
|
||||
os.Rename(manifest, target)
|
||||
os.Symlink(target, manifest)
|
||||
} else {
|
||||
config := Config{Format: 1, Prefix: "/another/prefix", ServerPort: 18080}
|
||||
config.Ntfy.Mode = "native"
|
||||
data, _ := json.Marshal(config)
|
||||
os.WriteFile(manifest, data, 0600)
|
||||
}
|
||||
if _, err := Load(binary); err == nil {
|
||||
t.Fatal("unsafe manifest was accepted")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user