-
Notifications
You must be signed in to change notification settings - Fork 33
feat: gate agent management rollout #6055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
danielkov
merged 9 commits into
main
from
daniel/aim-190-test-gate-m1-agent-identity-and-setup-authorization
Sep 8, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7feb23c
test: gate M1 agent management rollout
danielkov ec409ca
fix: gate agent management before grant preparation
danielkov cb538b3
fix: preserve authorization error context
danielkov 3b3f27a
fix: simplify agent management rollout gate
danielkov 743aaca
fix: remove repository prefix from rollout flag
danielkov 7833614
docs: generalize agent management flag comment
danielkov 5237a48
fix: remove remaining project shorthand
danielkov 65cb225
test: retain policy creation webhook in ownership assertion
danielkov 1f0a170
test: avoid mutating auth contexts retained by icon discovery
danielkov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| package agentmanagement | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| "goa.design/goa/v3/security" | ||
|
|
||
| gen "github.com/speakeasy-api/gram/server/gen/agents" | ||
| "github.com/speakeasy-api/gram/server/internal/contextvalues" | ||
| "github.com/speakeasy-api/gram/server/internal/feature" | ||
| "github.com/speakeasy-api/gram/server/internal/oops" | ||
| "github.com/speakeasy-api/gram/server/internal/testenv" | ||
| ) | ||
|
|
||
| type staticSessionAuthorizer struct { | ||
| authCtx *contextvalues.AuthContext | ||
| } | ||
|
|
||
| func (a staticSessionAuthorizer) AuthorizeWithPostAuthenticationCheck( | ||
| ctx context.Context, | ||
| _ string, | ||
| _ *security.APIKeyScheme, | ||
| check func(context.Context) error, | ||
| ) (context.Context, error) { | ||
| ctx = contextvalues.SetAuthContext(ctx, a.authCtx) | ||
| return ctx, check(ctx) | ||
| } | ||
|
|
||
| type recordingAgentManagementFeatures struct { | ||
| evaluation feature.Evaluation | ||
| err error | ||
| flag feature.Flag | ||
| distinctID string | ||
| groups map[string]string | ||
| } | ||
|
|
||
| func (*recordingAgentManagementFeatures) IsFlagEnabled(context.Context, feature.Flag, string, map[string]string) (bool, error) { | ||
| return false, nil | ||
| } | ||
|
|
||
| func (*recordingAgentManagementFeatures) IsFlagEnabledLocal(context.Context, feature.Flag, string, map[string]string, map[string]string) (bool, error) { | ||
| return false, nil | ||
| } | ||
|
|
||
| func (*recordingAgentManagementFeatures) FlagPayload(context.Context, feature.Flag, string, map[string]string) ([]byte, error) { | ||
| return nil, nil | ||
| } | ||
|
|
||
| func (f *recordingAgentManagementFeatures) EvaluateFlag(_ context.Context, flag feature.Flag, distinctID string, groups map[string]string) (feature.Evaluation, error) { | ||
| f.flag = flag | ||
| f.distinctID = distinctID | ||
| f.groups = groups | ||
| return f.evaluation, f.err | ||
| } | ||
|
|
||
| func TestAgentManagementRolloutGateRequiresAuthoritativeEnablement(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| backendFailure := errors.New("feature provider unavailable") | ||
| for _, test := range []struct { | ||
| name string | ||
| features feature.Provider | ||
| wantErr bool | ||
| wantLookup bool | ||
| }{ | ||
| {name: "enabled", features: &recordingAgentManagementFeatures{evaluation: feature.EvaluationEnabled}, wantLookup: true}, | ||
| {name: "disabled", features: &recordingAgentManagementFeatures{evaluation: feature.EvaluationDisabled}, wantErr: true, wantLookup: true}, | ||
| {name: "indeterminate", features: &recordingAgentManagementFeatures{evaluation: feature.EvaluationIndeterminate}, wantErr: true, wantLookup: true}, | ||
| {name: "provider error", features: &recordingAgentManagementFeatures{err: backendFailure}, wantErr: true, wantLookup: true}, | ||
| {name: "missing provider", wantErr: true}, | ||
| } { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| service := &Service{logger: testenv.NewLogger(t), features: test.features} | ||
| ctx := contextvalues.SetAuthContext(t.Context(), &contextvalues.AuthContext{ | ||
| ActiveOrganizationID: "organization", | ||
| OrganizationSlug: "organization-slug", | ||
| }) | ||
|
|
||
| err := service.requireAgentManagementEnabled(ctx) | ||
| if test.wantErr { | ||
| requireOopsCode(t, err, oops.CodeNotFound) | ||
| } else { | ||
| require.NoError(t, err) | ||
| } | ||
|
|
||
| flags, ok := test.features.(*recordingAgentManagementFeatures) | ||
| if !test.wantLookup { | ||
| require.False(t, ok) | ||
| return | ||
| } | ||
| require.True(t, ok) | ||
| require.Equal(t, feature.FlagAgentManagement, flags.flag) | ||
| require.Equal(t, "organization", flags.distinctID) | ||
| require.Equal(t, feature.OrgProjectGroups("organization-slug", ""), flags.groups) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestGeneratedAgentManagementEndpointsCannotBypassRolloutGate(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| backendFailure := errors.New("feature provider unavailable") | ||
| for _, test := range []struct { | ||
| name string | ||
| features feature.Provider | ||
| }{ | ||
| {name: "disabled", features: &recordingAgentManagementFeatures{evaluation: feature.EvaluationDisabled}}, | ||
| {name: "indeterminate", features: &recordingAgentManagementFeatures{evaluation: feature.EvaluationIndeterminate}}, | ||
| {name: "provider error", features: &recordingAgentManagementFeatures{err: backendFailure}}, | ||
| {name: "missing provider"}, | ||
| } { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| authCtx := &contextvalues.AuthContext{ | ||
| ActiveOrganizationID: "organization", | ||
| OrganizationSlug: "organization-slug", | ||
| } | ||
| service := &Service{ | ||
| logger: testenv.NewLogger(t), | ||
| auth: staticSessionAuthorizer{authCtx: authCtx}, | ||
| features: test.features, | ||
| } | ||
| endpoint := gen.NewCreateEndpoint(service, service.APIKeyAuth) | ||
|
|
||
| _, err := endpoint(t.Context(), &gen.CreatePayload{Name: "must not be created"}) | ||
| requireOopsCode(t, err, oops.CodeNotFound) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestAgentManagementRolloutGateRejectsMissingTenantContextBeforeEvaluation(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| features := &recordingAgentManagementFeatures{evaluation: feature.EvaluationEnabled} | ||
| service := &Service{logger: testenv.NewLogger(t), features: features} | ||
|
|
||
| requireOopsCode(t, service.requireAgentManagementEnabled(t.Context()), oops.CodeNotFound) | ||
| requireOopsCode(t, service.requireAgentManagementEnabled(contextvalues.SetAuthContext(t.Context(), &contextvalues.AuthContext{})), oops.CodeNotFound) | ||
| require.Empty(t, features.flag) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.