2d73a3d1db
* fix: keep completed office comments editable Keep the office task detail composer editable after completed sessions load, including projectless office tasks. Update verification tests for SHA-pinned GitHub actions. Extract the dockview main area to satisfy the existing max-lines lint rule. * fix: preserve upload artifact version guard * fix: clarify upload artifact pin check * fix: wake completed office sessions on comments * fix: queue completed office comment runs * fix: preserve dispatcher session lookup errors * fix: resolve office comment wake review issues * fix: stabilize comment wake idempotency * fix: salt custom comment wake keys * fix: address comment wake review cleanup * fix: avoid comment payload allocation overflow pattern * fix: salt comment wake action variants * fix: resolve cross-task primary by target step * fix: resolve cross-task participant roles * fix: surface cross-task comment run status * fix: use target steps for cross-task queue runs * fix: avoid comment run lookup scan regression * fix: cover cross-task queue run edge cases * fix: index comment payload run lookup * fix: support postgres comment run index * fix: tighten queue run target test coverage * fix: route source comment run updates * fix: preserve cross-task comment wakes * fix: tighten comment wake identity * fix: align comment wake routing * fix: remove stale primary resolver * fix: dedupe comment run status * fix: tighten legacy comment wake dedupe * fix: remove unreachable comment wake guard * fix: skip duplicate comment reactivity wakes * fix: route comment wakes synchronously * fix: share comment engine dispatch contracts * fix: preserve comment wake fallbacks * fix: preserve done comment runner * fix: guard empty task runner fallback * fix: handle empty task runner fallback * fix: stabilize completed comment wakes * fix: index comment runner fallback --------- Co-authored-by: root <root@kandev.ts.net>
170 lines
4.8 KiB
Go
170 lines
4.8 KiB
Go
package adapters
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/kandev/kandev/internal/workflow/engine"
|
|
"github.com/kandev/kandev/internal/workflow/models"
|
|
)
|
|
|
|
// fakeRepo is a minimal in-memory WorkflowRepo. The adapters delegate
|
|
// straight to the repo so we only need stub responses to verify the
|
|
// type translation between models / engine packages.
|
|
type fakeRepo struct {
|
|
participants []*models.WorkflowStepParticipant
|
|
decisions []*models.WorkflowStepDecision
|
|
runner string
|
|
taskStepID string
|
|
|
|
listErr error
|
|
recordErr error
|
|
clearErr error
|
|
runnerErr error
|
|
stepErr error
|
|
|
|
recorded *models.WorkflowStepDecision
|
|
cleared bool
|
|
resolvedStepID string
|
|
resolvedTaskID string
|
|
lookedUpTaskID string
|
|
}
|
|
|
|
func (f *fakeRepo) ListStepParticipantsForTask(_ context.Context, _, _ string) ([]*models.WorkflowStepParticipant, error) {
|
|
return f.participants, f.listErr
|
|
}
|
|
func (f *fakeRepo) ListStepDecisions(_ context.Context, _, _ string) ([]*models.WorkflowStepDecision, error) {
|
|
return f.decisions, f.listErr
|
|
}
|
|
func (f *fakeRepo) RecordStepDecision(_ context.Context, d *models.WorkflowStepDecision) error {
|
|
if f.recordErr != nil {
|
|
return f.recordErr
|
|
}
|
|
f.recorded = d
|
|
return nil
|
|
}
|
|
func (f *fakeRepo) ClearStepDecisions(_ context.Context, _, _ string) (int64, error) {
|
|
if f.clearErr != nil {
|
|
return 0, f.clearErr
|
|
}
|
|
f.cleared = true
|
|
return int64(len(f.decisions)), nil
|
|
}
|
|
func (f *fakeRepo) ResolveCurrentRunner(_ context.Context, stepID, taskID string) (string, error) {
|
|
f.resolvedStepID = stepID
|
|
f.resolvedTaskID = taskID
|
|
return f.runner, f.runnerErr
|
|
}
|
|
func (f *fakeRepo) GetTaskWorkflowStepID(_ context.Context, taskID string) (string, error) {
|
|
f.lookedUpTaskID = taskID
|
|
return f.taskStepID, f.stepErr
|
|
}
|
|
|
|
func TestParticipantAdapter_TranslatesModelToEngineInfo(t *testing.T) {
|
|
repo := &fakeRepo{
|
|
participants: []*models.WorkflowStepParticipant{
|
|
{
|
|
ID: "p-1", StepID: "s-1",
|
|
Role: models.ParticipantRoleApprover, AgentProfileID: "ap-1",
|
|
DecisionRequired: true, Position: 0,
|
|
},
|
|
},
|
|
}
|
|
a := NewParticipantAdapter(repo)
|
|
got, err := a.ListStepParticipants(context.Background(), "s-1", "task-1")
|
|
if err != nil {
|
|
t.Fatalf("ListStepParticipants: %v", err)
|
|
}
|
|
if len(got) != 1 {
|
|
t.Fatalf("len = %d, want 1", len(got))
|
|
}
|
|
if got[0].Role != "approver" {
|
|
t.Errorf("role = %q, want approver", got[0].Role)
|
|
}
|
|
if !got[0].DecisionRequired {
|
|
t.Error("decision_required must round-trip true")
|
|
}
|
|
}
|
|
|
|
func TestParticipantAdapter_PropagatesError(t *testing.T) {
|
|
repo := &fakeRepo{listErr: errors.New("boom")}
|
|
a := NewParticipantAdapter(repo)
|
|
if _, err := a.ListStepParticipants(context.Background(), "s", "t"); err == nil {
|
|
t.Fatal("expected error")
|
|
}
|
|
}
|
|
|
|
func TestDecisionAdapter_RecordTranslatesEngineInfoToModel(t *testing.T) {
|
|
repo := &fakeRepo{}
|
|
a := NewDecisionAdapter(repo)
|
|
err := a.RecordStepDecision(context.Background(), engine.DecisionInfo{
|
|
ID: "d-1", TaskID: "t-1", StepID: "s-1",
|
|
ParticipantID: "p-1", Decision: "approved", Note: "lgtm",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("record: %v", err)
|
|
}
|
|
if repo.recorded == nil {
|
|
t.Fatal("repo did not receive the decision")
|
|
}
|
|
if repo.recorded.Decision != "approved" {
|
|
t.Errorf("decision verdict = %q", repo.recorded.Decision)
|
|
}
|
|
}
|
|
|
|
func TestDecisionAdapter_List_TranslatesAllRows(t *testing.T) {
|
|
repo := &fakeRepo{
|
|
decisions: []*models.WorkflowStepDecision{
|
|
{ID: "d-1", Decision: "approved"},
|
|
{ID: "d-2", Decision: "rejected"},
|
|
},
|
|
}
|
|
a := NewDecisionAdapter(repo)
|
|
got, err := a.ListStepDecisions(context.Background(), "t", "s")
|
|
if err != nil {
|
|
t.Fatalf("list: %v", err)
|
|
}
|
|
if len(got) != 2 {
|
|
t.Fatalf("len = %d, want 2", len(got))
|
|
}
|
|
}
|
|
|
|
func TestDecisionAdapter_ClearForwards(t *testing.T) {
|
|
repo := &fakeRepo{decisions: []*models.WorkflowStepDecision{{ID: "d-1"}}}
|
|
a := NewDecisionAdapter(repo)
|
|
n, err := a.ClearStepDecisions(context.Background(), "t", "s")
|
|
if err != nil {
|
|
t.Fatalf("clear: %v", err)
|
|
}
|
|
if !repo.cleared {
|
|
t.Error("repo.ClearStepDecisions not invoked")
|
|
}
|
|
if n != 1 {
|
|
t.Errorf("rows cleared = %d, want 1", n)
|
|
}
|
|
}
|
|
|
|
func TestPrimaryAgentAdapter_ReturnsCurrentRunner(t *testing.T) {
|
|
repo := &fakeRepo{runner: "ap-runner"}
|
|
a := NewPrimaryAgentAdapter(repo)
|
|
got, err := a.PrimaryAgentProfileID(context.Background(), "s-1", "task-1")
|
|
if err != nil {
|
|
t.Fatalf("primary: %v", err)
|
|
}
|
|
if got != "ap-runner" {
|
|
t.Errorf("primary = %q, want ap-runner", got)
|
|
}
|
|
if repo.resolvedStepID != "s-1" || repo.resolvedTaskID != "task-1" {
|
|
t.Errorf("ResolveCurrentRunner called with step=%q task=%q", repo.resolvedStepID, repo.resolvedTaskID)
|
|
}
|
|
}
|
|
|
|
func TestPrimaryAgentAdapter_PropagatesResolveCurrentRunnerError(t *testing.T) {
|
|
repo := &fakeRepo{runnerErr: errors.New("missing")}
|
|
a := NewPrimaryAgentAdapter(repo)
|
|
if _, err := a.PrimaryAgentProfileID(context.Background(), "s-x", "task-x"); err == nil {
|
|
t.Fatal("expected error")
|
|
}
|
|
}
|