diff --git a/modules/mesh-delivery-view/files/mesh-delivery-cli b/modules/mesh-delivery-view/files/mesh-delivery-cli new file mode 100644 index 0000000..e430a1f --- /dev/null +++ b/modules/mesh-delivery-view/files/mesh-delivery-cli @@ -0,0 +1,4 @@ +#!/bin/sh +# The operator's command (module mesh-delivery-view, novox/hq ADR 0429 ยง3), written by the mesh. It is a file of its own in +# /usr/local/bin, which mesh-cli declares whole; the program lives in the view's own directory. +exec /usr/local/lib/mesh-delivery-view/mesh-delivery-cli "$@" diff --git a/modules/mesh-delivery-view/manifest_test.go b/modules/mesh-delivery-view/manifest_test.go index 68d69f5..141452f 100644 --- a/modules/mesh-delivery-view/manifest_test.go +++ b/modules/mesh-delivery-view/manifest_test.go @@ -163,8 +163,8 @@ func TestManifestResources(t *testing.T) { // 1134/AC7 t.Errorf("state directory 0700 owned by the user: %v; run directory for the socket 0755: %v", state, run) } a := byType["archive"][0] - if a["artifact"] != "cli" || a["path"] != "/usr/local/bin" { - t.Errorf("archive = %v, want the cli unpacked into /usr/local/bin", a) + if a["artifact"] != "cli" || a["path"] != "/usr/local/lib/mesh-delivery-view" { + t.Errorf("archive = %v, want the cli unpacked into its own directory", a) } } @@ -195,3 +195,28 @@ func TestAliasItem(t *testing.T) { // 1137/AC1 t.Fatalf("files/zsh-normal = %q, want the one line", raw) } } + +// The controller refuses two modules declaring one path (internal/catalogue/resolve.go:1160-1168). mesh-cli (mesh-catalog +// modules/mesh-cli/module.json) declares /usr/local/bin whole, so this module may place only a file below a shared +// directory, never the directory itself. +func TestNoSharedDirectoryIsClaimed(t *testing.T) { // 1134/AC7 + m, _ := load(t) + shared := map[string]bool{"/usr/local/bin": true, "/usr/local/lib": true, "/usr/bin": true, "/usr/local": true, "/usr/lib": true, "/etc": true, "/opt": true} + var binary bool + for _, r := range m.Resources { + p, _ := r["path"].(string) + if shared[strings.TrimRight(p, "/")] { + t.Errorf("resource %v declares the shared directory %s, which mesh-cli and others declare too", r["id"], p) + } + if p == "/usr/local/bin/mesh-delivery-cli" && r["type"] == "file" && r["template"] == "files/mesh-delivery-cli" { + binary = true + } + } + if !binary { + t.Error("the command is placed as the file /usr/local/bin/mesh-delivery-cli") + } + raw, err := os.ReadFile("files/mesh-delivery-cli") + if err != nil || !strings.Contains(string(raw), "exec /usr/local/lib/mesh-delivery-view/mesh-delivery-cli") { + t.Errorf("files/mesh-delivery-cli = %q, %v", raw, err) + } +} diff --git a/modules/mesh-delivery-view/module.json b/modules/mesh-delivery-view/module.json index 8d144fe..e79d77a 100644 --- a/modules/mesh-delivery-view/module.json +++ b/modules/mesh-delivery-view/module.json @@ -53,11 +53,18 @@ } }, { - "id": "command", + "id": "command-program", "type": "archive", "artifact": "cli", - "path": "/usr/local/bin", + "path": "/usr/local/lib/mesh-delivery-view", "unknown": "program" + }, + { + "id": "command", + "type": "file", + "path": "/usr/local/bin/mesh-delivery-cli", + "mode": "0755", + "template": "files/mesh-delivery-cli" } ], "items": [