WordPress / openverse

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
https://openverse.org
MIT License
216 stars 176 forks source link

Derive Playwright default feature flag states from `feature-flags.json` #4086

Open sarayourfriend opened 3 months ago

sarayourfriend commented 3 months ago

Current Situation

The playwright environment currently hard-codes default feature flag states in a non-obvious location, the navigation utilities:

https://github.com/WordPress/openverse/blob/3ed38fc4b138af2f6ac03fcc065ec633d6905d73/frontend/test/playwright/utils/navigation.ts#L207-L213

Suggested Improvement

It would be more intuitive to move these defaults into feature-flags.json itself. We can do this by adding a new deployment environment, testing.

Steps to implement:

The PR must have:

Benefit

An identical method for deriving feature flag state is identical in all execution environments is clearer, more intuitive, and easier to understand at a glance. It also makes it more likely that we will clean up these default states in tests at the same time (or ideally before) we roll features out to production.

That way when adding or modifying a feature, it's immediately clear what is and is not being testing "by default" in our e2e test suite.

Additional context

Thought of this while reviewing https://github.com/WordPress/openverse/pull/4084. The PR doesn't introduce this issue, it just moves code around I'd never seen before, so it isn't something that PR should address.

An alternative approach I considered is to add a separate, optional key to the feature flag configuration object named defaultStateInTest that can either be disabled or enabled. @WordPress/openverse-frontend do y'all have a preference between the two options? I think adding a new deployment env and changing our test execution to set DEPLOYMENT_ENV=testing would be the cleaner approach, but I could see it being a concern to add a new artificial deployment environment for testing.

obulat commented 3 months ago

I removed these features from the preparePageForTest completely in #8048. This way, we don't set up all of the switchable flags by default. Instead, we only set the cookie value for a flag that we explicitly add to the preparePageForTest parameters. All other values stay as default (i.e., they use the defaultValue of the flag, without specifically setting its preferredValue). This better matches the behavior in prod: if we don't set any values on the /preferences page, we don't have any preferredValues for any flags, and thus we use the defaults.

I think we should also update the featureFlagStore to only save the preferred state of the flag if it was explicitly toggled using a switch (on /preferences for most, and in the sidebar for fetch_sensitive). Currently, whenever a user toggles a switchable feature, we save a cookie with all switchable flag states.

sarayourfriend commented 3 months ago

@obulat I feel like I'm missing some necessary context to your comment. Can you clarify what you're talking about and how it affects or relates to the changes I've proposed in the issue?