Allow portable drafts to publish to the connected server
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user