Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions edge-server/internal/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/agenthub/edge-server/internal/hub"
"github.com/agenthub/edge-server/internal/lifecycle"
"github.com/agenthub/edge-server/internal/metrics"
"github.com/agenthub/edge-server/internal/permission"
"github.com/agenthub/edge-server/internal/runners"
"github.com/agenthub/edge-server/internal/security"
"github.com/agenthub/edge-server/internal/skills"
Expand Down Expand Up @@ -55,7 +56,7 @@ type Handler struct {
DurableSnapshot(afterSeq uint64) ([]hub.DeliveryJournalEntry, error)
}

PermissionRegistry *PermissionRegistry
PermissionRegistry *permission.PermissionRegistry
PermissionBroker *adapters.PermissionDecisionBroker

// PlanApprovalBroker manages pending orchestrator plans and connects
Expand Down Expand Up @@ -183,11 +184,11 @@ func ensurePreviewRunner(h *Handler, repository store.Repository) lifecycle.Prev
return h.PreviewRunner
}

func (h *Handler) ensurePermissionRegistry() *PermissionRegistry {
func (h *Handler) ensurePermissionRegistry() *permission.PermissionRegistry {
h.permissionRegistryMu.Lock()
defer h.permissionRegistryMu.Unlock()
if h.PermissionRegistry == nil {
h.PermissionRegistry = NewPermissionRegistry(0)
h.PermissionRegistry = permission.NewPermissionRegistry(0)
}
if h.PermissionBroker == nil {
h.PermissionBroker = adapters.NewPermissionDecisionBroker()
Expand Down
7 changes: 4 additions & 3 deletions edge-server/internal/api/handlers_approvals.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/agenthub/edge-server/internal/adapters"
"github.com/agenthub/edge-server/internal/errcode"
"github.com/agenthub/edge-server/internal/permission"
)

// Handler holds dependencies for HTTP and WebSocket handlers.
Expand Down Expand Up @@ -74,15 +75,15 @@ func (h *Handler) PostPermissionDecide(w http.ResponseWriter, r *http.Request) {
writeSuccess(w, http.StatusOK, map[string]any{"status": "ok"})
}

func pendingPermissionFromBroker(broker *adapters.PermissionDecisionBroker, runID, requestID, decision, reason string) (PendingPermission, bool) {
func pendingPermissionFromBroker(broker *adapters.PermissionDecisionBroker, runID, requestID, decision, reason string) (permission.PendingPermission, bool) {
pending, ok := broker.Decide(runID, requestID, adapters.PermissionDecision{
Behavior: decision,
Message: reason,
})
if !ok {
return PendingPermission{}, false
return permission.PendingPermission{}, false
}
return PendingPermission{
return permission.PendingPermission{
ProjectID: pending.ProjectID,
ThreadID: pending.ThreadID,
RunID: pending.RunID,
Expand Down
12 changes: 6 additions & 6 deletions edge-server/internal/api/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/agenthub/edge-server/internal/hub"
"github.com/agenthub/edge-server/internal/jwtutil"
"github.com/agenthub/edge-server/internal/lifecycle"
"github.com/agenthub/edge-server/internal/permission"
"github.com/agenthub/edge-server/internal/runners"
"github.com/agenthub/edge-server/internal/store"
"github.com/golang-jwt/jwt/v5"
Expand Down Expand Up @@ -1985,7 +1986,7 @@ func TestPostPermissionDecideRejectsUnknownRequest(t *testing.T) {

func TestPostPermissionDecideRejectsWrongRun(t *testing.T) {
h := newTestHandler()
h.ensurePermissionRegistry().Register(PendingPermission{
h.ensurePermissionRegistry().Register(permission.PendingPermission{
RunID: "run_real",
RequestID: "req_1",
})
Expand All @@ -2005,7 +2006,7 @@ func TestPostPermissionDecideRejectsWrongRun(t *testing.T) {

func TestPostPermissionDecideConsumesPendingRequestAndPublishesEvent(t *testing.T) {
h := newTestHandler()
h.ensurePermissionRegistry().Register(PendingPermission{
h.ensurePermissionRegistry().Register(permission.PendingPermission{
ProjectID: "proj_1",
ThreadID: "thread_1",
RunID: "run_1",
Expand Down Expand Up @@ -2165,7 +2166,7 @@ func TestRegisterRoutesInstallsPermissionBrokerOnClaudeAdapter(t *testing.T) {

func TestPostPermissionDecideRejectsSecondDecision(t *testing.T) {
h := newTestHandler()
h.ensurePermissionRegistry().Register(PendingPermission{
h.ensurePermissionRegistry().Register(permission.PendingPermission{
RunID: "run_1",
RequestID: "req_1",
})
Expand All @@ -2189,10 +2190,9 @@ func TestPostPermissionDecideRejectsSecondDecision(t *testing.T) {
func TestPostPermissionDecideRejectsExpiredRequestWithoutPublishing(t *testing.T) {
h := newTestHandler()
now := time.Date(2026, 5, 29, 8, 0, 0, 0, time.UTC)
registry := NewPermissionRegistry(time.Minute)
registry.now = func() time.Time { return now }
registry := permission.NewPermissionRegistryWithClock(time.Minute, func() time.Time { return now })
h.PermissionRegistry = registry
h.PermissionRegistry.Register(PendingPermission{
h.PermissionRegistry.Register(permission.PendingPermission{
ProjectID: "proj_1",
ThreadID: "thread_1",
RunID: "run_1",
Expand Down
Loading
Loading