Replace starters with four graded examples seeded into new databases
The template catalog is now Example 1-4: one stage, two stages (handoff), feedback loop (runner-owned limits, retries, timeout) and human decision (type=human approve/revise/abort with notify hooks). All read-only or leave changes uncommitted; none commits, pushes or deploys. A brand-new database (schema created by this Open) gets the examples once at server start, bound to the configured default model and harness. A server_settings marker records the decision, so removed examples never come back and existing installs are marked without any pipeline being added or rewritten.
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
func seedItems() []protocol.Template {
|
||||
return []protocol.Template{
|
||||
{Key: "a", Name: "Example: a", Source: Template([]string{"one"}, true)},
|
||||
{Key: "b", Name: "Example: b", Source: Template([]string{"one", "two"}, true)},
|
||||
}
|
||||
}
|
||||
|
||||
func TestSeedExamplesOnlyIntoABrandNewDatabase(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
path := filepath.Join(t.TempDir(), "new.db")
|
||||
store, err := Open(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
seeded, err := store.SeedExamples(ctx, seedItems())
|
||||
if err != nil || seeded != 2 {
|
||||
t.Fatal("brand-new database not seeded", seeded, err)
|
||||
}
|
||||
items, _ := store.List(ctx)
|
||||
if len(items) != 2 || items[0].Name != "Example: a" || items[0].Version != 1 {
|
||||
t.Fatal("examples are not ordinary version-1 pipelines", items)
|
||||
}
|
||||
// A second call in the same process is a no-op.
|
||||
if seeded, err = store.SeedExamples(ctx, seedItems()); err != nil || seeded != 0 {
|
||||
t.Fatal("seeded twice", seeded, err)
|
||||
}
|
||||
// Removing every example must not bring them back on the next start. There is
|
||||
// no pipeline delete command yet, so remove the rows directly.
|
||||
if _, err := store.db.Exec(`DELETE FROM submissions; DELETE FROM pipeline_versions; DELETE FROM pipelines`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store.Close()
|
||||
store, err = Open(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
if seeded, err = store.SeedExamples(ctx, seedItems()); err != nil || seeded != 0 {
|
||||
t.Fatal("deleted examples came back", seeded, err)
|
||||
}
|
||||
if items, _ = store.List(ctx); len(items) != 0 {
|
||||
t.Fatal("deleted examples came back", items)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSeedExamplesNeverChangesAnExistingInstall(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
for _, name := range []string{"empty", "populated"} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "existing.db")
|
||||
store, err := Open(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if name == "populated" {
|
||||
if _, err := store.Submit(ctx, "mine", Template([]string{"one"}, true)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
// Simulate an install from before seeding existed: no marker.
|
||||
store.Close()
|
||||
store, err = Open(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if seeded, err := store.SeedExamples(ctx, seedItems()); err != nil || seeded != 0 {
|
||||
t.Fatal("upgrade seeded examples", seeded, err)
|
||||
}
|
||||
store.Close()
|
||||
store, err = Open(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
if seeded, err := store.SeedExamples(ctx, seedItems()); err != nil || seeded != 0 {
|
||||
t.Fatal("later start seeded examples", seeded, err)
|
||||
}
|
||||
items, _ := store.List(ctx)
|
||||
if (name == "empty" && len(items) != 0) || (name == "populated" && (len(items) != 1 || items[0].Name != "mine" || items[0].Version != 1)) {
|
||||
t.Fatal("upgrade changed pipelines", items)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user