Cover public auth config, catalog policy, official main workflow activation on Postgres, and conn-busy metadata writeback fixes. Co-authored-by: Cursor <cursoragent@cursor.com>
74 lines
1.9 KiB
Go
74 lines
1.9 KiB
Go
package workflowdef_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
|
|
"chat-agent-system/internal/db"
|
|
"chat-agent-system/internal/workflowdef"
|
|
)
|
|
|
|
func openPool(t *testing.T) *pgxpool.Pool {
|
|
t.Helper()
|
|
dsn := db.SkipIfNoTestDatabaseURL(t)
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
defer cancel()
|
|
pool, err := pgxpool.New(ctx, dsn)
|
|
if err != nil {
|
|
t.Skip(err)
|
|
}
|
|
if err := pool.Ping(ctx); err != nil {
|
|
pool.Close()
|
|
t.Skip(err)
|
|
}
|
|
if !workflowdef.TablesReady(ctx, pool) {
|
|
pool.Close()
|
|
t.Skip("workflowdef tables not migrated")
|
|
}
|
|
return pool
|
|
}
|
|
|
|
func TestPublishVersion_ImmutableAfterPublish(t *testing.T) {
|
|
pool := openPool(t)
|
|
if pool == nil {
|
|
return
|
|
}
|
|
defer pool.Close()
|
|
ctx := context.Background()
|
|
svc := workflowdef.NewService(pool, nil)
|
|
key := "test_wf_" + time.Now().Format("150405")
|
|
defer func() {
|
|
_, _ = pool.Exec(ctx, `DELETE FROM workflow_versions WHERE workflow_id IN (SELECT id FROM workflow_definitions WHERE def_key = $1)`, key)
|
|
_, _ = pool.Exec(ctx, `DELETE FROM workflow_definitions WHERE def_key = $1`, key)
|
|
}()
|
|
def, ver, err := svc.CreateDefinition(ctx, workflowdef.CreateDefinitionInput{
|
|
Key: key, Name: "测试工作流",
|
|
Definition: workflowdef.VersionDefinition{
|
|
SchemaVersion: 1,
|
|
Stages: []workflowdef.StageDef{{
|
|
Key: "s1", Position: 0,
|
|
DocTasks: []workflowdef.DocTaskDef{{
|
|
Key: "t1", DefaultEnabled: true, OutputDocType: "d1", OutputDocTitle: "D1",
|
|
}},
|
|
}},
|
|
},
|
|
}, 1)
|
|
if err != nil {
|
|
t.Fatalf("create: %v", err)
|
|
}
|
|
published, err := svc.PublishVersion(ctx, def.ID, ver.Version, 1)
|
|
if err != nil {
|
|
t.Fatalf("publish: %v", err)
|
|
}
|
|
if published.Status != workflowdef.StatusPublished {
|
|
t.Fatalf("expected published, got %s", published.Status)
|
|
}
|
|
_, err = svc.UpdateDraft(ctx, def.ID, ver.Version, published.Definition)
|
|
if err == nil {
|
|
t.Fatal("expected update on published version to fail")
|
|
}
|
|
}
|