2618f0d244
Track each active run's resolved workspace alongside its cancel function in a single runner.active struct map. A new request key is now refused only when an already-active run is changing the same resolved workspace; the refusal names the conflicting run id and advises waiting or using a different workspace. Workspace resolution is unchanged (default cwd, absolute request workspace, EvalSymlinks), so two spellings of one directory still compare equal. The conflict check and registration stay inside the existing r.mu critical section, so concurrent starts for one workspace cannot both pass. Idempotent repeats of an active request key and the restart-recovery guard are unchanged. Add concurrency_test.go covering concurrent different-workspace runs, same-workspace refusal, symlink/default-cwd equivalence, idempotent repeats, restart recovery and retry workspace scoping; strengthen the runner_test.go refusal assertion. Update docs/cli.md, docs/first-version-testing.md and the packaged operations skill reference to describe per-workspace concurrency. Assisted-by: DeepSeek V4.1 Flash
58 lines
1.9 KiB
Go
58 lines
1.9 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.a-wan.net/alan/pipelines/internal/pipeline"
|
|
"git.a-wan.net/alan/pipelines/internal/protocol"
|
|
"git.a-wan.net/alan/pipelines/internal/stage"
|
|
)
|
|
|
|
func TestRetryWaitsForExecutionCleanupEvenAfterTerminalStatus(t *testing.T) {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
store, err := pipeline.Open(filepath.Join(t.TempDir(), "cleanup.db"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer store.Close()
|
|
store.Submit(ctx, "workflow", pipeline.Template([]string{"one"}, true))
|
|
items, _ := store.List(ctx)
|
|
d, _ := store.Get(ctx, items[0].ID, 1)
|
|
r, err := newRunner(ctx, store)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
id, _, err := store.CreateRun(ctx, d, "original", t.TempDir(), false, nil, map[string]any{"prompt": "task"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := store.FinishRun(ctx, id, "failed", "error", "failure", nil); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// Simulate the interval between persisting terminal status and final cleanup.
|
|
r.active[id] = activeRun{cancel: func() {}}
|
|
detail, err := r.getRun(id)
|
|
if err != nil || !detail.Executing {
|
|
t.Fatal("terminal run not marked executing during cleanup", detail, err)
|
|
}
|
|
runs, err := r.listRuns()
|
|
if err != nil || !runs[0].Executing {
|
|
t.Fatal("list advertised stopped run during cleanup", runs, err)
|
|
}
|
|
if _, err := r.retry(protocol.Message{RunID: id, RequestKey: "retry"}); err == nil || !strings.Contains(err.Error(), "still executing") {
|
|
t.Fatal("retry accepted during execution cleanup", err)
|
|
}
|
|
delete(r.active, id)
|
|
r.execute = func(context.Context, stage.Definition, stage.Values) (stage.Result, error) {
|
|
return stage.Result{Outcome: "success", Output: stage.Values{"summary": "done"}}, nil
|
|
}
|
|
if _, err := r.retry(protocol.Message{RunID: id, RequestKey: "retry"}); err != nil {
|
|
t.Fatal("retry rejected after cleanup", err)
|
|
}
|
|
r.wg.Wait()
|
|
}
|