Allow portable drafts to publish to the connected server

This commit is contained in:
2026-10-10 02:18:48 +01:00
parent c74f7f3b41
commit 4cae37f950
12 changed files with 242 additions and 20 deletions
+11
View File
@@ -19,6 +19,17 @@ type Draft struct {
BaseVersion int `json:"base_version,omitempty"`
}
// ForServer projects publication scope onto a destination without changing the
// retained draft. Version numbers belong to the origin, not another server.
func (d Draft) ForServer(server string) Draft {
if d.Server != "" && d.Server != server {
d.CreateOnly = true
d.BaseVersion = 0
}
d.Server = server
return d
}
func Directory() (string, error) {
if dir := os.Getenv("PIPELINES_DRAFT_DIR"); dir != "" {
return filepath.Abs(dir)
+23
View File
@@ -0,0 +1,23 @@
package draft
import "testing"
func TestPublicationScopeForServer(t *testing.T) {
original := Draft{Path: "/retained/draft.md", Name: "demo", Server: "ws://origin/connect", BaseVersion: 7}
same := original.ForServer(original.Server)
if same != original {
t.Fatal("same-server version guard changed", same)
}
imported := original.ForServer("ws://destination/connect")
if imported.Server != "ws://destination/connect" || imported.BaseVersion != 0 || !imported.CreateOnly || imported.Path != original.Path || imported.Name != original.Name {
t.Fatal("cross-server scope leaked or draft identity changed", imported)
}
if original.Server != "ws://origin/connect" || original.BaseVersion != 7 || original.CreateOnly {
t.Fatal("projection changed retained draft")
}
legacy := Draft{Name: "legacy", BaseVersion: 2}
bound := legacy.ForServer("ws://destination/connect")
if bound.BaseVersion != 2 || bound.CreateOnly {
t.Fatal("unbound legacy draft lost its version guard", bound)
}
}