fc7dbb0ac0
Server: drop ntfy publishing (stage hooks, run outbox, chat attention, chat tool notify, auto-switch and schedule notices), the chat push outbox (its table is dropped at startup), ntfy status/endpoints and PIPELINES_NTFY_*. The app_notifications stream, subscribe/clear and kinds are unchanged. Notification settings keep run_finished/chat_needs_you/chat_reply_finished; ntfy_enabled is accepted and ignored and its stored row is never read. Stage type=ntfy is rejected: "ntfy stages were removed; notifications go to the Pipelines apps — use the stage notify hook". The notify hook remains. Installer: no ntfy build, accounts, config or supervisor child; manifest gets top-level "mode" (legacy ntfy.mode still read). Reinstall retires an old ntfy (safe PID-file stop, deletes binary, config, data dir, token, log, with a note in logs/install.log); uninstall cleans leftovers. App: ntfy settings section replaced by "Notification events"; texts updated. Docs: docs/ntfy.md folded into docs/notifications.md; install, docker, cli, author skill references updated; security review M1 marked resolved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
196 lines
6.7 KiB
Go
196 lines
6.7 KiB
Go
package installation
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestCompiledCommandFindsManifestThroughSystemLink(t *testing.T) {
|
|
t.Setenv("PIPELINES_PREFIX", "")
|
|
root, _ := filepath.EvalSymlinks(t.TempDir())
|
|
os.Mkdir(filepath.Join(root, "bin"), 0700)
|
|
binary := filepath.Join(root, "bin/pipelines")
|
|
os.WriteFile(binary, []byte("binary"), 0700)
|
|
config := Config{Format: 1, Prefix: root, ServerPort: 18080, OpenCode: "/host/opencode", Path: "/usr/bin"}
|
|
data, _ := json.Marshal(config)
|
|
os.WriteFile(filepath.Join(root, "pipelines-install.json"), data, 0600)
|
|
link := filepath.Join(t.TempDir(), "pipelines")
|
|
os.Symlink(binary, link)
|
|
t.Setenv("PIPELINES_PREFIX", root)
|
|
loaded, err := Load(link)
|
|
if err != nil || loaded == nil || loaded.Prefix != root {
|
|
t.Fatal(loaded, err)
|
|
}
|
|
t.Setenv("PIPELINES_URL", "")
|
|
t.Setenv("PIPELINES_OPENCODE", "")
|
|
t.Setenv("PATH", os.Getenv("PATH"))
|
|
if err = loaded.Environment(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if os.Getenv("PIPELINES_URL") != "ws://127.0.0.1:18080/connect" {
|
|
t.Fatal("wrong installation selected")
|
|
}
|
|
t.Setenv("PIPELINES_URL", "ws://explicit/connect")
|
|
loaded.Environment()
|
|
if os.Getenv("PIPELINES_URL") != "ws://explicit/connect" {
|
|
t.Fatal("explicit server overridden")
|
|
}
|
|
}
|
|
|
|
func TestEnvironmentPointsLocalClientsAtTheServerToken(t *testing.T) {
|
|
var config Config
|
|
if err := json.Unmarshal([]byte(`{"server_port":18080,"web":{"server_token_file":"/home/u/.config/pipelines/server-token"}}`), &config); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Setenv("PIPELINES_URL", "")
|
|
t.Setenv("PIPELINES_OPENCODE", "")
|
|
t.Setenv("PIPELINES_SERVER_TOKEN_FILE", "")
|
|
if err := config.Environment(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := os.Getenv("PIPELINES_SERVER_TOKEN_FILE"); got != "/home/u/.config/pipelines/server-token" {
|
|
t.Fatalf("token file = %q", got)
|
|
}
|
|
// A manifest from before the token existed sets nothing.
|
|
t.Setenv("PIPELINES_SERVER_TOKEN_FILE", "")
|
|
if err := (Config{ServerPort: 18080}).Environment(); err != nil || os.Getenv("PIPELINES_SERVER_TOKEN_FILE") != "" {
|
|
t.Fatalf("legacy manifest set a token file: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestStandaloneGoInstalledCommandHasNoServiceDependency(t *testing.T) {
|
|
t.Setenv("PIPELINES_PREFIX", "")
|
|
binary := filepath.Join(t.TempDir(), "pipelines")
|
|
os.WriteFile(binary, []byte("binary"), 0700)
|
|
config, err := Load(binary)
|
|
if err != nil || config != nil {
|
|
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.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.Mode = "native"
|
|
data, _ := json.Marshal(config)
|
|
os.WriteFile(manifest, data, 0600)
|
|
}
|
|
if _, err := Load(binary); err == nil {
|
|
t.Fatal("unsafe manifest was accepted")
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// A manifest written before ntfy was removed marks a native installation as
|
|
// ntfy.mode "native" (with the rest of the old ntfy block); it must still be
|
|
// selected until a reinstall rewrites it with the top-level mode.
|
|
func TestLegacyNtfyManifestStillSelectsNativeInstallation(t *testing.T) {
|
|
t.Setenv("PIPELINES_PREFIX", "")
|
|
root, binary := nativeFixture(t)
|
|
legacy := map[string]any{"format": 1, "prefix": root, "server_port": 18080, "python": filepath.Join(root, "python3"),
|
|
"ntfy_port": 8090, "topic": "pipelines", "username": "phone-reader",
|
|
"ntfy": map[string]any{"mode": "native", "bin": filepath.Join(root, "bin", "ntfy"), "config": filepath.Join(root, "data", "ntfy", "server.yml"), "version": "v2.38.1"}}
|
|
data, _ := json.Marshal(legacy)
|
|
if err := os.WriteFile(filepath.Join(root, "pipelines-install.json"), data, 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
loaded, err := Load(binary)
|
|
if err != nil || loaded == nil || !loaded.Native() {
|
|
t.Fatal("legacy native manifest not selected", loaded, err)
|
|
}
|
|
docker := Config{Mode: "docker"}
|
|
docker.LegacyNtfy.Mode = "native"
|
|
if docker.Native() {
|
|
t.Fatal("explicit docker mode overridden by the legacy block")
|
|
}
|
|
if !(Config{Mode: "native"}).Native() || (Config{}).Native() {
|
|
t.Fatal("top-level mode not honoured")
|
|
}
|
|
}
|