feat(flags): add flag dependencies support for local evaluation#2190
Closed
feat(flags): add flag dependencies support for local evaluation#2190
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Contributor
Contributor
|
Size Change: +51.4 kB (+1.08%) Total Size: 4.82 MB
ℹ️ View Unchanged
|
c65ec63 to
ccded7b
Compare
3e50a15 to
6ff7082
Compare
ccded7b to
b184867
Compare
b184867 to
9ce849d
Compare
Implement comprehensive flag dependency support allowing flags to depend on other flag evaluations with proper dependency resolution. Key features: - Dependency graph with cycle detection and topological sorting - Support for simple flag dependencies (true/false) - Support for variant-specific dependencies - Dependency chains and complex hierarchies - Graceful error handling and fallback mechanisms - Performance optimization through result caching - Full backward compatibility with existing flag evaluation Components: - New DependencyGraph class with comprehensive graph operations - Updated FeatureFlagsPoller to integrate dependency-aware evaluation - Enhanced flag evaluation methods to handle dependencies - Comprehensive test suite with 95%+ code coverage This enables complex feature flag configurations while maintaining performance and reliability for local evaluation scenarios.
The CI was failing because unit tests were running without building packages first. The posthog-js-lite and posthog-react-native packages generate their version.ts files during the prebuild step (which runs before build), but the test:unit task had no dependencies in turbo.json. This change makes test:unit depend on build, ensuring that: - All packages are built before tests run - The prebuild scripts generate required version.ts files - Tests can successfully import the version modules The issue was that version.ts files are generated by prebuild scripts but tests were running before build, causing "Cannot find module './version'" errors in CI.
9ce849d to
21d9069
Compare
- Rename remote-config-example.js to remote-config-demo.js for consistency - Update both demos to use .env configuration instead of hardcoded values - Add interactive index.js menu to select and run available demos - Update README with streamlined setup instructions - Add REMOTE_CONFIG_FLAG_KEY to .env.example for remote config demo
19464f5 to
5e835bb
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR implements comprehensive flag dependency support for local evaluation in the PostHog Node.js SDK, allowing flags to depend on other flag evaluations with proper dependency resolution, cycle detection, and topological sorting.
Key changes:
- Added dependency graph infrastructure with cycle detection and topological sorting
- Updated feature flag evaluation to handle dependencies in correct order
- Enhanced playground with interactive demos for testing flag dependencies
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| turbo.json | Adds build dependency for unit tests |
| playground/flags/* | Complete overhaul of playground with dependency demos and improved structure |
| packages/node/src/extensions/feature-flags/dependency-graph.ts | New dependency graph implementation with cycle detection |
| packages/node/src/extensions/feature-flags/feature-flags.ts | Updated feature flag evaluation to support dependencies |
| packages/node/test/* | Comprehensive test coverage for dependency functionality |
…nts in integration tests The integration tests were failing because custom events weren't being captured. This was due to a race condition where the custom event button was clicked before PostHog was fully initialized and ready to capture events. Added await posthog.waitForLoaded() after posthog.init() to ensure PostHog is completely loaded before attempting to capture custom events.
- Add FlagDependencyProperty type for better type constraints - Add type guard in matchFlagProperty to ensure flag dependencies only - Handle unexpected value types gracefully with clear warnings - Convert non-FeatureFlagValue types to string with fallback logic - Maintain backward compatibility while improving type safety
Contributor
|
This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Implement comprehensive flag dependency support allowing flags to depend on other flag evaluations with proper dependency resolution.
This is based on the
posthog-pythonimplementation.Problem
We recently added support for flag dependencies (hidden behind a feature flag). We now need to add support for local evaluation.
Changes
Key features:
Components:
DependencyGraphclass with comprehensive graph operationsFeatureFlagsPollerto integrate dependency-aware evaluationThis enables complex feature flag configurations while maintaining performance and reliability for local evaluation scenarios.
Release info Sub-libraries affected
Libraries affected
Checklist
If releasing new changes
pnpm changesetto generate a changeset file