Files
archie/internal/infrastructure/staterpc/usage_grant_test.go
T
sam e4ea2eaabc feat(statestore): record a usage row for every model call
Task agent runs and MCP sampling record against their task (billed to the
task's org); gateway chat turns, titles, sampling and curators record
against the system org. Rows carry source, workflow, step, alias,
provider/model and tokens for later chargeback.
2026-10-10 18:32:43 +11:00

30 lines
834 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{OrgId: "org-sys"}, false},
{"no record", nil, false},
} {
t.Run(tt.name, func(t *testing.T) {
req := &pb.RecordUsageRequest{Record: tt.record}
if got := authorizesTaskScopedCall(pb.StateStoreService_RecordUsage_FullMethodName, req, 7); got != tt.allowed {
t.Fatalf("authorized = %v, want %v", got, tt.allowed)
}
})
}
}