Files
archie/internal/infrastructure/staterpc/usage_grant_test.go
T
sam 5ea115746c
deploy / plan (push) Successful in 6s
deploy / archied-image (push) Canceled after 0s
deploy / agent-image (push) Canceled after 0s
deploy / dist-zip (push) Canceled after 0s
deploy / gate (push) Canceled after 5m37s
ci/woodpecker/push/deploy Pipeline was canceled
fix(dashboard): blocked tasks say what they need, and a provider refusal names its fix
2026-11-10 23:19:29 +11:00

32 lines
1.4 KiB
Go

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)
}
})
}
}