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

Function TestManagerTaskBlockAgentSessionScope

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

Source from the content-addressed store, hash-verified

4682}
4683
4684func TestManagerTaskBlockAgentSessionScope(t *testing.T) {
4685 t.Parallel()
4686
4687 t.Run(
4688 "Should constrain agent-session block lifecycle to the active leased task",
4689 func(t *testing.T) {
4690 t.Parallel()
4691
4692 ctx := context.Background()
4693 store := newInMemoryManagerStore()
4694 manager := newTaskManagerForTest(t, store)
4695 operator := validActorContext()
4696 agent := agentSessionActorContext("sess-block-scope")
4697
4698 leasedTask, err := manager.CreateTask(
4699 ctx,
4700 CreateTask{Scope: ScopeGlobal, Title: "leased task"},
4701 operator,
4702 )
4703 if err != nil {
4704 t.Fatalf("CreateTask(leased) error = %v", err)
4705 }
4706 foreignTask, err := manager.CreateTask(
4707 ctx,
4708 CreateTask{Scope: ScopeGlobal, Title: "foreign task"},
4709 operator,
4710 )
4711 if err != nil {
4712 t.Fatalf("CreateTask(foreign) error = %v", err)
4713 }
4714 if _, err := manager.EnqueueRun(ctx, EnqueueRun{TaskID: leasedTask.ID}, operator); err != nil {
4715 t.Fatalf("EnqueueRun(leased) error = %v", err)
4716 }
4717 claim, err := manager.ClaimNextRun(ctx, ClaimCriteria{
4718 Scope: ScopeGlobal,
4719 ClaimerSessionID: "sess-block-scope",
4720 LeaseDuration: time.Minute,
4721 }, agent)
4722 if err != nil {
4723 t.Fatalf("ClaimNextRun() error = %v", err)
4724 }
4725
4726 leasedBlock, err := manager.BlockTask(ctx, BlockRequest{
4727 TaskID: leasedTask.ID,
4728 Kind: BlockKindNeedsInput,
4729 Reason: "missing input",
4730 }, agent)
4731 if err != nil {
4732 t.Fatalf("BlockTask(leased agent) error = %v", err)
4733 }
4734 blocks, err := manager.ListTaskBlocks(ctx, leasedTask.ID, true, agent)
4735 if err != nil {
4736 t.Fatalf("ListTaskBlocks(leased agent) error = %v", err)
4737 }
4738 if got, want := len(blocks), 1; got != want {
4739 t.Fatalf("len(leased blocks) = %d, want %d", got, want)
4740 }
4741 if blocks[0].ID != leasedBlock.ID {

Callers

nothing calls this directly

Calls 14

newInMemoryManagerStoreFunction · 0.85
newTaskManagerForTestFunction · 0.85
validActorContextFunction · 0.85
agentSessionActorContextFunction · 0.85
assertAutonomyReasonFunction · 0.85
RunMethod · 0.65
CreateTaskMethod · 0.65
EnqueueRunMethod · 0.65
ClaimNextRunMethod · 0.65
BlockTaskMethod · 0.65
ListTaskBlocksMethod · 0.65
ClearTaskBlockMethod · 0.65

Tested by

no test coverage detected