Skip to content
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

chore(config): check test environment for feature flags #1665

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ajohn25
Copy link
Contributor

@ajohn25 ajohn25 commented Aug 17, 2023

Description

This modifies the config file to enable feature flags for running tests.

Motivation and Context

#1663 (comment)

How Has This Been Tested?

Tests are still passing

Screenshots (if appropriate):

Documentation Changes

Checklist:

  • My change requires a change to the documentation.
  • I have included updates for the documentation accordingly.

Copy link
Member

@bchrobot bchrobot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I was not clear enough in my comment #1663 (comment). The envvar definitions have to remain in the validators object -- they are only meaningful if passed through envalid.cleanEnv().

Separating the config from the parsed envvars allows something like:

const config = {
  allowSendAll: env.isTest || env.ALLOW_SEND_ALL
};

@ajohn25
Copy link
Contributor Author

ajohn25 commented Aug 17, 2023

they are only meaningful if passed through envalid.cleanEnv()

Got you! Can you say more about what meaningful refers to here? Is it that the validators aren't really validating anymore because they're not being passed through? The failing test for #1663 passed after this commit so i jumped the gun and took that as success 😅

@bchrobot
Copy link
Member

bchrobot commented Aug 17, 2023

they are only meaningful if passed through envalid.cleanEnv()

Got you! Can you say more about what meaningful refers to here? Is it that the validators aren't really validating anymore because they're not being passed through? The failing test for #1663 passed after this commit so i jumped the gun and took that as success 😅

The validator (e.g. bool()) is just a spec for how envalid.cleanEnv() should process an environment variable value. So the typing of const env = envalid.cleanEnv() is:

type CleanEnvOutput = {
  isProd: boolean;
  ALLOW_SEND_ALL: boolean;
};

but the shape of the const config = { ...env, ALLOW_SEND_ALL: bool({ ... }), with your changes would be:

type MixedConfigType = {
  isProd: boolean;
  ALLOW_SEND_ALL: ValidatorSpec<boolean>;
};

The tests likely passed because ValidatorSpec<boolean> is truthy. If the feature flag checked if (config.ALLOW_SEND_ALL === true) {} then a) TS would have complained that ValidatorSpec<boolean> cannot be assigned to boolean or something like that, and b) it would evaluate to false and the unit tests would have failed.

It might be helpful to look at the whole src/config.ts in Switchboard to see how the two interact.

@ajohn25
Copy link
Contributor Author

ajohn25 commented Aug 17, 2023

then a) TS would have complained that ValidatorSpec cannot be assigned to boolean or something like that

Got it! Maybe I'll briefly check whether I can easily convert the Spoke config to TS without breaking anything too 😅

@ajohn25 ajohn25 marked this pull request as draft August 17, 2023 19:42
@bchrobot
Copy link
Member

then a) TS would have complained that ValidatorSpec cannot be assigned to boolean or something like that

Got it! Maybe I'll briefly check whether I can easily convert the Spoke config to TS without breaking anything too 😅

I don't think you need to convert to TS to move forward with this. But I think the types are a good way of understanding what is happening?

@ajohn25
Copy link
Contributor Author

ajohn25 commented Aug 17, 2023

I don't think you need to convert to TS to move forward with this. But I think the types are a good way of understanding what is happening?

yeah i agree!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants