-
Notifications
You must be signed in to change notification settings - Fork 5
feat(platform): wire feature flags resolver and add governance tab #1375
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1eb7c35
feat(platform): wire feature flags resolver and add governance tab
yannickmonney e83c322
test(platform): add feature flag enforcement tests for startAgentChat
yannickmonney 917e25f
fix(platform): address CodeRabbit review findings for feature flags
yannickmonney d86eaa8
fix(platform): consolidate duplicate governance i18n keys
larryro b8a2273
feat(platform): expose resolved feature flags to frontend and hide up…
larryro 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
26 changes: 26 additions & 0 deletions
26
...ces/platform/app/features/settings/governance/components/feature-flags-editor.stories.tsx
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,26 @@ | ||
| import type { Meta, StoryObj } from '@storybook/react'; | ||
|
|
||
| import { FeatureFlagsEditor } from './feature-flags-editor'; | ||
|
|
||
| const meta: Meta<typeof FeatureFlagsEditor> = { | ||
| title: 'Settings/Governance/FeatureFlagsEditor', | ||
| component: FeatureFlagsEditor, | ||
| tags: ['autodocs'], | ||
| parameters: { | ||
| layout: 'padded', | ||
| }, | ||
| args: { | ||
| organizationId: 'org_test', | ||
| }, | ||
| }; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof FeatureFlagsEditor>; | ||
|
|
||
| export const Default: Story = {}; | ||
|
|
||
| export const WithOrganization: Story = { | ||
| args: { | ||
| organizationId: 'org_demo', | ||
| }, | ||
| }; |
158 changes: 158 additions & 0 deletions
158
services/platform/app/features/settings/governance/components/feature-flags-editor.test.tsx
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,158 @@ | ||
| import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
|
|
||
| import { checkAccessibility } from '@/test/utils/a11y'; | ||
| import { render, screen } from '@/test/utils/render'; | ||
|
|
||
| vi.mock('@/app/hooks/use-organization-id', () => ({ | ||
| useOrganizationId: () => 'org_test', | ||
| })); | ||
|
|
||
| vi.mock('@/app/hooks/use-ability', () => ({ | ||
| useAbility: () => ({ | ||
| can: () => true, | ||
| cannot: () => false, | ||
| }), | ||
| })); | ||
|
|
||
| vi.mock('@/app/hooks/use-toast', () => ({ | ||
| useToast: () => ({ | ||
| toast: vi.fn(), | ||
| }), | ||
| })); | ||
|
|
||
| vi.mock('../hooks/queries', () => ({ | ||
| useGovernancePolicy: vi.fn().mockReturnValue({ | ||
| data: null, | ||
| isLoading: false, | ||
| }), | ||
| })); | ||
|
|
||
| vi.mock('../hooks/mutations', () => ({ | ||
| useUpsertGovernancePolicy: () => ({ | ||
| mutateAsync: vi.fn(), | ||
| isPending: false, | ||
| }), | ||
| })); | ||
|
|
||
| vi.mock('@/app/features/settings/organization/hooks/queries', () => ({ | ||
| useMembers: () => ({ | ||
| members: [ | ||
| { userId: 'user_1', displayName: 'Alice', email: 'alice@test.com' }, | ||
| { userId: 'user_2', displayName: 'Bob', email: 'bob@test.com' }, | ||
| ], | ||
| }), | ||
| })); | ||
|
|
||
| vi.mock('@/app/features/settings/teams/hooks/queries', () => ({ | ||
| useOrgTeams: () => ({ | ||
| teams: [ | ||
| { id: 'team_1', name: 'Engineering' }, | ||
| { id: 'team_2', name: 'Marketing' }, | ||
| ], | ||
| }), | ||
| })); | ||
|
|
||
| const { useGovernancePolicy } = await import('../hooks/queries'); | ||
| const mockedUseGovernancePolicy = vi.mocked(useGovernancePolicy); | ||
|
|
||
| const { FeatureFlagsEditor } = await import('./feature-flags-editor'); | ||
|
|
||
| describe('FeatureFlagsEditor', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| mockedUseGovernancePolicy.mockReturnValue({ | ||
| data: null, | ||
| isLoading: false, | ||
| } as never); | ||
| }); | ||
|
|
||
| it('renders empty state when no rules exist', () => { | ||
| render(<FeatureFlagsEditor organizationId="org_1" />); | ||
|
|
||
| expect( | ||
| screen.getByText(/no feature control rules configured/i), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders rules table when rules exist', () => { | ||
| mockedUseGovernancePolicy.mockReturnValue({ | ||
| data: { | ||
| config: { | ||
| enabled: true, | ||
| rules: [ | ||
| { | ||
| scope: 'default', | ||
| webSearch: true, | ||
| codeExecution: false, | ||
| fileUpload: true, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| isLoading: false, | ||
| } as never); | ||
|
|
||
| render(<FeatureFlagsEditor organizationId="org_1" />); | ||
|
|
||
| expect(screen.getByText('default')).toBeInTheDocument(); | ||
| expect(screen.getByText('\u2718')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders add rule button', () => { | ||
| render(<FeatureFlagsEditor organizationId="org_1" />); | ||
|
|
||
| expect( | ||
| screen.getByRole('button', { name: /add rule/i }), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders enabled toggle', () => { | ||
| render(<FeatureFlagsEditor organizationId="org_1" />); | ||
|
|
||
| expect(screen.getByRole('switch')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders loading skeleton while loading', () => { | ||
| mockedUseGovernancePolicy.mockReturnValue({ | ||
| data: null, | ||
| isLoading: true, | ||
| } as never); | ||
|
|
||
| const { container } = render(<FeatureFlagsEditor organizationId="org_1" />); | ||
|
|
||
| expect(container.querySelector('[aria-busy="true"]')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| describe('accessibility', () => { | ||
| it('passes axe audit with empty state', async () => { | ||
| const { container } = render( | ||
| <FeatureFlagsEditor organizationId="org_1" />, | ||
| ); | ||
| await checkAccessibility(container); | ||
| }); | ||
|
|
||
| it('passes axe audit with rules table', async () => { | ||
| mockedUseGovernancePolicy.mockReturnValue({ | ||
| data: { | ||
| config: { | ||
| enabled: true, | ||
| rules: [ | ||
| { | ||
| scope: 'default', | ||
| webSearch: true, | ||
| codeExecution: true, | ||
| fileUpload: true, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| isLoading: false, | ||
| } as never); | ||
|
|
||
| const { container } = render( | ||
| <FeatureFlagsEditor organizationId="org_1" />, | ||
| ); | ||
| await checkAccessibility(container); | ||
| }); | ||
| }); | ||
| }); | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Prefer typed mock fixtures over
as never.These casts erase the
useGovernancePolicycontract, so the tests will still compile if the hook return shape drifts. A small typed factory orsatisfieskeeps the mocks honest without losing inference. Based on learnings, "In TypeScript test fixtures ... prefer the 'satisfies' operator over 'as' type assertions for config objects and test data."Also applies to: 78-93, 116-119, 135-150
🤖 Prompt for AI Agents