Skip to content

Commit

Permalink
chore(flags): remove unused VX_CONVERTER flag (#5699)
Browse files Browse the repository at this point in the history
  • Loading branch information
eventualbuddha authored Dec 9, 2024
1 parent 6d46c01 commit e8d22b9
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 123 deletions.
1 change: 0 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ REACT_APP_VX_USE_MOCK_PDI_SCANNER=FALSE
REACT_APP_VX_SKIP_CVR_BALLOT_HASH_CHECK=FALSE
REACT_APP_VX_SKIP_ELECTION_PACKAGE_AUTHENTICATION=FALSE
REACT_APP_VX_SKIP_CAST_VOTE_RECORDS_AUTHENTICATION=FALSE
REACT_APP_VX_CONVERTER=ms-sems
REACT_APP_VX_USE_MOCK_PAPER_HANDLER=FALSE
REACT_APP_VX_MARK_SCAN_USE_BMD_150=TRUE
REACT_APP_VX_ENABLE_CLOUD_TRANSLATION_AND_SPEECH_SYNTHESIS=TRUE
Expand Down
1 change: 0 additions & 1 deletion libs/utils/src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ declare namespace NodeJS {
REACT_APP_VX_SKIP_CVR_BALLOT_HASH_CHECK?: string;
REACT_APP_VX_SKIP_ELECTION_PACKAGE_AUTHENTICATION?: string;
REACT_APP_VX_SKIP_CAST_VOTE_RECORDS_AUTHENTICATION?: string;
REACT_APP_VX_CONVERTER?: string;
REACT_APP_VX_USE_MOCK_PAPER_HANDLER?: string;
REACT_APP_VX_MARK_SCAN_USE_BMD_150?: string;
REACT_APP_VX_ENABLE_CLOUD_TRANSLATION_AND_SPEECH_SYNTHESIS?: string;
Expand Down
12 changes: 0 additions & 12 deletions libs/utils/src/environment_variable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import {
BooleanEnvironmentVariableName,
getEnvironmentVariable,
getBooleanEnvVarConfig,
getStringEnvVarConfig,
StringEnvironmentVariableName,
} from './environment_variable';

describe('environment flags', () => {
Expand All @@ -21,20 +19,10 @@ describe('environment flags', () => {
}
});

it('gets string env var details as expected', () => {
for (const flag of Object.values(StringEnvironmentVariableName)) {
const details = getStringEnvVarConfig(flag);
expect(details.name).toEqual(flag);
}
});

it('flags are undefined by default', () => {
for (const flag of Object.values(BooleanEnvironmentVariableName)) {
expect(getEnvironmentVariable(flag)).toEqual(undefined);
}
for (const flag of Object.values(StringEnvironmentVariableName)) {
expect(getEnvironmentVariable(flag)).toEqual(undefined);
}
});

it('flags are true as appropriate', () => {
Expand Down
28 changes: 1 addition & 27 deletions libs/utils/src/environment_variable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ConverterClientTypeSchema } from '@votingworks/types';
import { ZodSchema } from 'zod';
import { throwIllegalValue } from '@votingworks/basics';
import { asBoolean } from './as_boolean';
Expand Down Expand Up @@ -81,12 +80,6 @@ export enum BooleanEnvironmentVariableName {
HIDE_CURSOR = 'REACT_APP_VX_HIDE_CURSOR',
}

// This is not fully generic since string variables may want the getter to return a custom type.
export enum StringEnvironmentVariableName {
/** Converter for input/output files in VxAdmin */
CONVERTER = 'REACT_APP_VX_CONVERTER',
}

export interface BooleanEnvironmentConfig {
name: BooleanEnvironmentVariableName;
/**
Expand All @@ -105,7 +98,6 @@ export interface BooleanEnvironmentConfig {
}

export interface StringEnvironmentConfig {
name: StringEnvironmentVariableName;
defaultValue: string; // Default value for autogenerated .env files
zodSchema?: ZodSchema;
}
Expand All @@ -115,7 +107,7 @@ export interface StringEnvironmentConfig {
* which will check the env var's config and convert it to a boolean.
*/
export function getEnvironmentVariable(
name: BooleanEnvironmentVariableName | StringEnvironmentVariableName
name: BooleanEnvironmentVariableName
): string | undefined {
switch (name) {
case BooleanEnvironmentVariableName.WRITE_IN_ADJUDICATION:
Expand All @@ -142,8 +134,6 @@ export function getEnvironmentVariable(
return process.env.REACT_APP_VX_SKIP_ELECTION_PACKAGE_AUTHENTICATION;
case BooleanEnvironmentVariableName.SKIP_CAST_VOTE_RECORDS_AUTHENTICATION:
return process.env.REACT_APP_VX_SKIP_CAST_VOTE_RECORDS_AUTHENTICATION;
case StringEnvironmentVariableName.CONVERTER:
return process.env.REACT_APP_VX_CONVERTER;
case BooleanEnvironmentVariableName.USE_MOCK_PAPER_HANDLER:
return process.env.REACT_APP_VX_USE_MOCK_PAPER_HANDLER;
case BooleanEnvironmentVariableName.MARK_SCAN_USE_BMD_150:
Expand Down Expand Up @@ -290,22 +280,6 @@ export function getBooleanEnvVarConfig(
}
}

export function getStringEnvVarConfig(
name: StringEnvironmentVariableName
): StringEnvironmentConfig {
switch (name) {
case StringEnvironmentVariableName.CONVERTER:
return {
name,
defaultValue: 'ms-sems',
zodSchema: ConverterClientTypeSchema,
};
/* istanbul ignore next */
default:
throwIllegalValue(name);
}
}

/**
* We use a custom environment variable for this instead of overloading NODE_ENV, e.g.
* NODE_ENV=test or NODE_ENV=integration-test, because we want integration tests to use
Expand Down
20 changes: 1 addition & 19 deletions libs/utils/src/features.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { BooleanEnvironmentVariableName } from './environment_variable';
import {
getConverterClientType,
isFeatureFlagEnabled,
isVxDev,
} from './features';
import { isFeatureFlagEnabled, isVxDev } from './features';

describe('features', () => {
const { env } = process;
Expand Down Expand Up @@ -68,20 +64,6 @@ describe('features', () => {
).toEqual(false);
});

it('getConverterClientType returns value when set', () => {
process.env.REACT_APP_VX_CONVERTER = 'ms-sems';
expect(getConverterClientType()).toEqual('ms-sems');
});

it('getConverterClientType returns undefined when not set', () => {
expect(getConverterClientType()).toEqual(undefined);
});

it('getConverterClientType throws error when set to invalid value', () => {
process.env.REACT_APP_VX_CONVERTER = 'invalid';
expect(() => getConverterClientType()).toThrowError();
});

afterEach(() => {
process.env = env;
});
Expand Down
18 changes: 0 additions & 18 deletions libs/utils/src/features.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import {
ConverterClientType,
ConverterClientTypeSchema,
unsafeParse,
} from '@votingworks/types';
import { asBoolean } from './as_boolean';
import {
BooleanEnvironmentVariableName,
Expand All @@ -27,16 +22,3 @@ export function isFeatureFlagEnabled(
asBoolean(getEnvironmentVariable(flag))
);
}

/**
* Determines which converter client to use, if any.
*/
export function getConverterClientType(): ConverterClientType | undefined {
const rawConverterClientType = process.env.REACT_APP_VX_CONVERTER;

if (!rawConverterClientType) {
return;
}

return unsafeParse(ConverterClientTypeSchema, rawConverterClientType);
}
45 changes: 0 additions & 45 deletions libs/utils/src/scripts/generate_env_file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ import * as readline from 'node:readline';
import * as fs from 'node:fs';
import { join } from 'node:path';
import yargs from 'yargs';
import { ZodSchema } from 'zod';
import { safeParse } from '@votingworks/types';
import {
BooleanEnvironmentVariableName,
getBooleanEnvVarConfig,
getStringEnvVarConfig,
StringEnvironmentVariableName,
} from '../environment_variable';

const rl = readline.createInterface({
Expand Down Expand Up @@ -41,42 +37,11 @@ function boolQuestion(flagName: string, enable: boolean) {
});
}

const stringVariableOptions: Map<string, string> = new Map();
function stringQuestion(
varName: string,
defaultVal: string,
schema?: ZodSchema
) {
return new Promise<void>((resolve) => {
rl.question(`Value for ${varName}? (Default: ${defaultVal}):`, (answer) => {
if (answer === '') {
stringVariableOptions.set(varName, defaultVal);
} else if (!schema) {
stringVariableOptions.set(varName, answer);
} else {
const parsed = safeParse(schema, answer);
if (parsed.isOk()) {
stringVariableOptions.set(varName, parsed.ok());
}
if (parsed.isErr()) {
// eslint-disable-next-line no-console
console.log('Invalid input, Please try again.');
process.exit(1);
}
}
resolve();
});
});
}

function getEnvFileContents(isVxDev: boolean): string {
let output = '';
for (const flagName of flagOptions.keys()) {
output += `${flagName}=${flagOptions.get(flagName) ? 'TRUE' : 'FALSE'}\n`;
}
for (const varName of stringVariableOptions.keys()) {
output += `${varName}=${stringVariableOptions.get(varName)}\n`;
}
if (isVxDev) {
output += 'REACT_APP_VX_DEV=true';
}
Expand All @@ -93,16 +58,6 @@ async function generateEnvFile(filePath: string, isVexDev: boolean) {
flag.autoEnableInVxDev ?? flag.autoEnableInDevelopment
);
}
const stringDetails = Object.values(StringEnvironmentVariableName).map(
(variable) => getStringEnvVarConfig(variable)
);
for (const stringVar of stringDetails) {
await stringQuestion(
stringVar.name,
stringVar.defaultValue,
stringVar.zodSchema
);
}
fs.writeFileSync(filePath, getEnvFileContents(isVexDev));
rl.close();
}
Expand Down

0 comments on commit e8d22b9

Please sign in to comment.