MCPcopy Create free account
hub / github.com/compozy/agh / TestManagerForceRunOperations

Function TestManagerForceRunOperations

internal/task/manager_test.go:6726–7240  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6724}
6725
6726func TestManagerForceRunOperations(t *testing.T) {
6727 t.Parallel()
6728
6729 t.Run(
6730 "Should force release claimed run and invalidate queued session input",
6731 func(t *testing.T) {
6732 t.Parallel()
6733
6734 store := newForceInputStore()
6735 store.pendingCancelCounts["sess-force"] = 2
6736 manager := newTaskManagerForTest(t, store)
6737 actor := validActorContext()
6738
6739 taskRecord, err := manager.CreateTask(context.Background(), CreateTask{
6740 Scope: ScopeGlobal,
6741 Title: "Force release",
6742 }, actor)
6743 if err != nil {
6744 t.Fatalf("CreateTask() error = %v", err)
6745 }
6746 run, err := manager.EnqueueRun(
6747 context.Background(),
6748 EnqueueRun{TaskID: taskRecord.ID},
6749 actor,
6750 )
6751 if err != nil {
6752 t.Fatalf("EnqueueRun() error = %v", err)
6753 }
6754 run, err = manager.ClaimRun(context.Background(), run.ID, ClaimRun{}, actor)
6755 if err != nil {
6756 t.Fatalf("ClaimRun() error = %v", err)
6757 }
6758 storedRun := store.runs[run.ID]
6759 storedRun.SessionID = "sess-force"
6760 store.runs[run.ID] = storedRun
6761
6762 released, err := manager.ForceReleaseRun(context.Background(), run.ID, ForceReleaseRun{
6763 Reason: "handoff",
6764 }, actor)
6765 if err != nil {
6766 t.Fatalf("ForceReleaseRun() error = %v", err)
6767 }
6768 if got, want := released.Status, TaskRunStatusQueued; got != want {
6769 t.Fatalf("ForceReleaseRun().Status = %q, want %q", got, want)
6770 }
6771 if released.SessionID != "" || released.ClaimTokenHash != "" ||
6772 !released.LeaseUntil.IsZero() {
6773 t.Fatalf("released run retained claim fields: %#v", released)
6774 }
6775 if len(store.advanceCalls) != 1 || store.advanceCalls[0] != "sess-force" {
6776 t.Fatalf("advanceCalls = %#v, want sess-force", store.advanceCalls)
6777 }
6778 if len(store.cancelCalls) != 1 ||
6779 store.cancelCalls[0].SessionID != "sess-force" ||
6780 store.cancelCalls[0].Generation != 1 ||
6781 store.cancelCalls[0].CanceledInputs != 2 {
6782 t.Fatalf(
6783 "cancelCalls = %#v, want session generation cancellation",

Callers

nothing calls this directly

Calls 15

newForceInputStoreFunction · 0.85
newTaskManagerForTestFunction · 0.85
validActorContextFunction · 0.85
newInMemoryManagerStoreFunction · 0.85
WithTaskRunHooksFunction · 0.85
appendFunction · 0.85
WithForceRecoveryOptionsFunction · 0.85
RecordRunStarvedMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected