-
Notifications
You must be signed in to change notification settings - Fork 39
feat(feature-flags): add framework-aware wizard program #1037
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
Open
hacktivist123
wants to merge
8
commits into
PostHog:main
Choose a base branch
from
hacktivist123:feature-flags-wizard
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a82edae
feat(feature-flags): add framework-aware wizard program
hacktivist123 8e683a5
feat(feature-flags): guard setup and guide verification
hacktivist123 c087cda
fix(feature-flags): remove unused subagent access
hacktivist123 cbafd8b
fix(feature-flags): confirm changes before writes
hacktivist123 c01d62c
fix(feature-flags): fit learn deck on narrow terminals
hacktivist123 95c0d6d
feat(feature-flags): expand the learn deck
hacktivist123 834b617
feat(feature-flags): explain when to run the program
hacktivist123 856becd
fix(feature-flags): clarify rollout timing
hacktivist123 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import { featureFlagsConfig } from '@lib/programs/feature-flags/index'; | ||
|
|
||
| import type { Command } from './command'; | ||
| import { nativeCommandFactory } from './factories/native-command-factory'; | ||
|
|
||
| export const featureFlagsCommand: Command = | ||
| nativeCommandFactory(featureFlagsConfig); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /** | ||
| * Layout guard for the narrowest LearnCard split view. At 80 terminal columns, | ||
| * the feature-flags deck receives a 37-character pane. | ||
| */ | ||
|
|
||
| import type { ReactElement, ReactNode } from 'react'; | ||
| import { getContentBlocks } from '@lib/programs/feature-flags/content/index'; | ||
|
|
||
| const PANE_WIDTH_80COL = 37; | ||
|
|
||
| function textOf(node: ReactNode): string { | ||
| if (node == null || typeof node === 'boolean') return ''; | ||
| if (typeof node === 'string' || typeof node === 'number') return String(node); | ||
| if (Array.isArray(node)) return node.map(textOf).join(''); | ||
| const element = node as ReactElement<{ children?: ReactNode }>; | ||
| return textOf(element.props?.children); | ||
| } | ||
|
|
||
| describe('feature-flags learn deck', () => { | ||
| it('keeps fixed-layout lines within the 80-column pane', () => { | ||
| const wideLines: string[] = []; | ||
|
|
||
| for (const block of getContentBlocks()) { | ||
| if ( | ||
| typeof block !== 'object' || | ||
| !('type' in block) || | ||
| block.type !== 'lines' | ||
| ) { | ||
| continue; | ||
| } | ||
|
|
||
| for (const line of block.lines) { | ||
| const text = textOf(line); | ||
| if ([...text].length > PANE_WIDTH_80COL) wideLines.push(text); | ||
| } | ||
| } | ||
|
|
||
| expect(wideLines).toEqual([]); | ||
| }); | ||
| }); |
110 changes: 110 additions & 0 deletions
110
src/lib/programs/__tests__/feature-flags-prompt.test.ts
|
hacktivist123 marked this conversation as resolved.
|
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,110 @@ | ||
| import { featureFlagsConfig } from '@lib/programs/feature-flags'; | ||
|
|
||
| function getRun() { | ||
| const run = featureFlagsConfig.run; | ||
| expect(run).toBeDefined(); | ||
| expect(typeof run).not.toBe('function'); | ||
|
|
||
| if (!run || typeof run === 'function') { | ||
| throw new Error('Expected a static feature flags run configuration'); | ||
| } | ||
|
|
||
| return run; | ||
| } | ||
|
|
||
| describe('feature flags program', () => { | ||
| it('installs the skill before planning, then gates writes on confirmation', () => { | ||
| const prompt = getRun().customPrompt?.({} as never) ?? ''; | ||
|
|
||
| const installSkill = prompt.indexOf('Call `install_skill`'); | ||
| const createTasks = prompt.indexOf('`TaskCreate` calls'); | ||
| const confirmProposal = prompt.indexOf( | ||
| 'The proposal is an interactive decision gate', | ||
| ); | ||
|
|
||
| expect(installSkill).toBeGreaterThan(-1); | ||
| expect(createTasks).toBeGreaterThan(installSkill); | ||
| expect(confirmProposal).toBeGreaterThan(createTasks); | ||
| expect(prompt).toContain('category: "feature-flags"'); | ||
| expect(prompt).toContain('one call per workflow stage'); | ||
| expect(prompt).toMatch( | ||
| /Do not call `TaskUpdate`, run\s+another tool, or start workflow work until every initial task exists/, | ||
| ); | ||
| expect(prompt).toMatch( | ||
| /Before any PostHog write or\s+application source edit, call `wizard_ask`/, | ||
| ); | ||
| expect(prompt).toContain( | ||
| '[ABORT] Feature flag proposal confirmation is required.', | ||
| ); | ||
| expect(prompt).toContain( | ||
| '[ABORT] A matching PostHog feature flag skill could not be installed.', | ||
| ); | ||
| }); | ||
|
|
||
| it('keeps SDK and environment inspection inside the installed workflow', () => { | ||
| const prompt = getRun().customPrompt?.({} as never) ?? ''; | ||
|
|
||
| expect(prompt).toContain( | ||
| 'do not install, reinstall, or upgrade a PostHog SDK package', | ||
| ); | ||
| expect(prompt).toMatch( | ||
| /Never\s+open, read, or search value-bearing `\.env\*` files/, | ||
| ); | ||
| expect(prompt).toContain('use `check_env_keys`'); | ||
| expect(prompt).toContain( | ||
| 'The installed skill owns the feature-flag workflow', | ||
| ); | ||
| }); | ||
|
|
||
| it('ends with a project-specific flag verification handoff', () => { | ||
| const outro = getRun().buildOutroData?.( | ||
| {} as never, | ||
| { | ||
| projectId: 532532, | ||
| host: { appHost: 'https://us.posthog.com/' }, | ||
| } as never, | ||
| ); | ||
|
|
||
| expect(outro).toMatchObject({ | ||
| message: 'Your feature flag is ready to test', | ||
| primaryLink: { | ||
| label: 'Open Feature Flags', | ||
| url: 'https://us.posthog.com/project/532532/feature_flags', | ||
| }, | ||
| nextSteps: { | ||
| heading: 'Try your flag:', | ||
| items: [ | ||
| 'Exercise the control experience', | ||
| 'Enable the flag for your test person and exercise the flagged experience', | ||
| 'Confirm the live evaluation in PostHog, then restore the safe rollout', | ||
| ], | ||
| }, | ||
| reportFile: 'posthog-feature-flags-report.md', | ||
| docsUrl: 'https://posthog.com/docs/feature-flags', | ||
| }); | ||
| expect(outro?.handoffPrompt).toContain( | ||
| 'complete any blocked or not-run checks', | ||
| ); | ||
| expect(outro?.handoffPrompt).toContain( | ||
| 'get my approval before changing the flag rollout', | ||
| ); | ||
| }); | ||
|
|
||
| it('maps every Wizard and Context Mill abort contract', () => { | ||
| const abortCases = getRun().abortCases ?? []; | ||
| const emittedSignals = [ | ||
| 'A working PostHog SDK integration is required.', | ||
| 'A matching PostHog feature flag skill could not be installed.', | ||
| 'Feature flag proposal confirmation is required.', | ||
| 'PostHog feature flag access is required.', | ||
| 'The selected feature flag skill does not match this application.', | ||
| ]; | ||
|
|
||
| for (const signal of emittedSignals) { | ||
| expect( | ||
| abortCases.some((abortCase) => abortCase.match.test(signal)), | ||
| `Missing abort case for: ${signal}`, | ||
| ).toBe(true); | ||
| } | ||
| }); | ||
| }); |
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.
did you try running this with the other harnesses and models? just curious
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.
no not at all, I didn't have the time to test it with others but i tried to follow the patterns in the codebase to make it work with other harnesses. If i had more time, that's something I'd love to do as i use Pi as my daily driver.