package staterpc import ( "testing" pb "github.com/samcharles93/archie-core/internal/contracts/state/v1" ) // A run credential acts only on its own task: it records usage and parks // against task 7, so one tenant's task cannot bill or park another's. func TestTaskScopedCallAuthority(t *testing.T) { for _, tt := range []struct { name string method string req any allowed bool }{ {"usage on own task", pb.ExecutionService_RecordUsage_FullMethodName, &pb.RecordUsageRequest{Record: &pb.UsageRecord{TaskId: 7}}, true}, {"usage on another task", pb.ExecutionService_RecordUsage_FullMethodName, &pb.RecordUsageRequest{Record: &pb.UsageRecord{TaskId: 8}}, false}, {"usage with no task", pb.ExecutionService_RecordUsage_FullMethodName, &pb.RecordUsageRequest{Record: &pb.UsageRecord{Source: "chat"}}, false}, {"usage with no record", pb.ExecutionService_RecordUsage_FullMethodName, &pb.RecordUsageRequest{}, false}, {"park own task", pb.TaskService_ParkTask_FullMethodName, &pb.ParkTaskRequest{TaskId: 7, Blocker: "model_credit"}, true}, {"park another task", pb.TaskService_ParkTask_FullMethodName, &pb.ParkTaskRequest{TaskId: 8, Blocker: "model_credit"}, false}, } { t.Run(tt.name, func(t *testing.T) { if got := authorizesTaskScopedCall(tt.method, tt.req, 7); got != tt.allowed { t.Fatalf("authorized = %v, want %v", got, tt.allowed) } }) } }