Allow portable drafts to publish to the connected server
This commit is contained in:
+11
-5
@@ -465,9 +465,9 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
if metaErr != nil && !os.IsNotExist(metaErr) {
|
||||
return metaErr
|
||||
}
|
||||
if d.Server != "" && d.Server != o.url {
|
||||
return fmt.Errorf("draft belongs to server %s; select it with --url", d.Server)
|
||||
}
|
||||
origin := d
|
||||
crossServer := d.Server != "" && d.Server != o.url
|
||||
d = d.ForServer(o.url)
|
||||
name := o.name
|
||||
if name == "" {
|
||||
name = d.Name
|
||||
@@ -482,8 +482,14 @@ func (a App) Run(ctx context.Context, args []string) error {
|
||||
if o.force {
|
||||
expected = 0
|
||||
}
|
||||
request = protocol.Message{Type: protocol.Submit, Name: name, Source: source, CreateOnly: d.CreateOnly || o.createOnly, ExpectedVersion: expected}
|
||||
if err := a.confirmAction("Publish "+name+" as an immutable version? Included schedules activate on acceptance.", o.yes); err != nil {
|
||||
createOnly := d.CreateOnly || o.createOnly
|
||||
// An explicit destination version (or force) permits intentional
|
||||
// updates from an edit draft; never inherit the origin version.
|
||||
if crossServer && (o.expected > 0 || o.force) {
|
||||
createOnly = origin.CreateOnly || o.createOnly
|
||||
}
|
||||
request = protocol.Message{Type: protocol.Submit, Name: name, Source: source, CreateOnly: createOnly, ExpectedVersion: expected}
|
||||
if err := a.confirmAction("Publish "+name+" to "+o.url+" as an immutable version? Included schedules activate on acceptance.", o.yes); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,13 +214,13 @@ func TestCLIAuthorOpenCodeReferencesGlobalSkillAndLeavesDraft(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCLIBoundedFilesServerMismatchAndNoninteractiveGuards(t *testing.T) {
|
||||
func TestCLIBoundedFilesPortableDraftsAndNoninteractiveGuards(t *testing.T) {
|
||||
run, _, url := setup(t)
|
||||
d, err := draft.Create("test", pipeline.Template([]string{"worker"}, true), url+"-other", true, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = run("submit", d.Path); err == nil || !strings.Contains(err.Error(), "belongs") {
|
||||
if _, err = run("submit", d.Path); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
os.WriteFile(d.Path, bytes.Repeat([]byte("x"), (1<<20)+1), 0600)
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package cli_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/draft"
|
||||
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
||||
)
|
||||
|
||||
func TestCLIEditDraftCanPublishToAnotherServerWithoutOriginVersion(t *testing.T) {
|
||||
_, origin, originURL := setup(t)
|
||||
run, destination, _ := setup(t)
|
||||
ctx := context.Background()
|
||||
source := pipeline.Template([]string{"worker"}, true)
|
||||
for i := 0; i < 7; i++ {
|
||||
if _, err := origin.Submit(ctx, "portable", pipeline.Template([]string{fmt.Sprintf("origin_v%d", i+1)}, true)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
d, err := draft.Create("portable", source, originURL, false, 7)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
metadata, err := os.ReadFile(d.Path + ".json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := run("submit", d.Path); err != nil {
|
||||
t.Fatal("cross-server publication blocked", err)
|
||||
}
|
||||
items, err := destination.List(ctx)
|
||||
if err != nil || len(items) != 1 || items[0].Version != 1 {
|
||||
t.Fatal("origin base version leaked to destination", items, err)
|
||||
}
|
||||
updated := pipeline.Template([]string{"worker", "reviewer"}, true)
|
||||
if err := os.WriteFile(d.Path, []byte(updated), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := run("submit", d.Path); err == nil {
|
||||
t.Fatal("import overwrote existing destination name without approval")
|
||||
}
|
||||
items, _ = destination.List(ctx)
|
||||
if items[0].Version != 1 {
|
||||
t.Fatal("destination collision changed published history")
|
||||
}
|
||||
if _, err := run("submit", d.Path, "--expected-version", "1"); err != nil {
|
||||
t.Fatal("explicit destination version update blocked", err)
|
||||
}
|
||||
items, _ = destination.List(ctx)
|
||||
if items[0].Version != 2 {
|
||||
t.Fatal("explicit destination update did not publish a version", items)
|
||||
}
|
||||
updated = pipeline.Template([]string{"worker", "reviewer", "publisher"}, true)
|
||||
if err := os.WriteFile(d.Path, []byte(updated), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := run("submit", d.Path, "--expected-version", "99"); err == nil {
|
||||
t.Fatal("wrong explicit destination version accepted")
|
||||
}
|
||||
if _, err := run("submit", d.Path, "--force"); err != nil {
|
||||
t.Fatal("explicit forced destination update blocked", err)
|
||||
}
|
||||
items, _ = destination.List(ctx)
|
||||
if items[0].Version != 3 {
|
||||
t.Fatal("forced destination update did not publish a version", items)
|
||||
}
|
||||
items, _ = origin.List(ctx)
|
||||
if len(items) != 1 || items[0].Version != 7 {
|
||||
t.Fatal("origin pipeline was modified", items)
|
||||
}
|
||||
retained, err := os.ReadFile(d.Path + ".json")
|
||||
if err != nil || string(retained) != string(metadata) {
|
||||
t.Fatal("import rewrote original draft metadata", err)
|
||||
}
|
||||
text, err := draft.Read(d.Path)
|
||||
if err != nil || text != updated {
|
||||
t.Fatal("publication changed retained source", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user