Files
archie/internal/infrastructure/staterpc/usage_grant_test.go
T
sam a971947c39 refactor(state)!: split StateStoreService into per-domain services
One gRPC service per domain in state.v1 (tasks, executions, accounts, identities, packages, captures, bindings, access, orgs, alerts and so on), each with its own server type in staterpc. RPC and message names and numbers are unchanged.
2026-10-25 19:54:27 +11:00

30 lines
831 B
Go

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