From 07439164c2defe5fb0cb8ee3a571b3c062b40c0e Mon Sep 17 00:00:00 2001 From: Gabriella Gerges Date: Wed, 5 Nov 2025 12:37:46 -0400 Subject: [PATCH 1/3] fix: match variable aliases using transformed constant names --- src/commands/diff/index.ts | 7 ++++++- src/commands/generate/types.ts | 4 ++-- src/utils/keyToConstant.ts | 11 +++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 src/utils/keyToConstant.ts diff --git a/src/commands/diff/index.ts b/src/commands/diff/index.ts index e21b5f287..e29f825b7 100644 --- a/src/commands/diff/index.ts +++ b/src/commands/diff/index.ts @@ -14,6 +14,7 @@ import VarAliasFlag, { getVariableAliases } from '../../flags/var-alias' import ShowRegexFlag, { showRegex } from '../../flags/show-regex' import { Variable } from '../../api/schemas' import { FileFilters } from '../../utils/FileFilters' +import { keyToConstant } from '../../utils/keyToConstant' const EMOJI = { add: '🟢', @@ -162,7 +163,11 @@ export default class Diff extends Base { Object.values(matchesBySdk).forEach((matches) => { matches.forEach((m) => { const match = { ...m } - const aliasedName = aliasMap[match.name] + // Try to find alias by direct match first, then by transformed constant name + // This handles cases where the generated types file creates constants like MY_VARIABLE + // for a variable key like 'my-variable' + const aliasedName = + aliasMap[match.name] || aliasMap[keyToConstant(match.name)] if (match.isUnknown && aliasedName) { match.alias = match.name match.name = aliasedName diff --git a/src/commands/generate/types.ts b/src/commands/generate/types.ts index 18ccd80be..84d704303 100644 --- a/src/commands/generate/types.ts +++ b/src/commands/generate/types.ts @@ -4,9 +4,9 @@ import { fetchAllVariables } from '../../api/variables' import { Flags } from '@oclif/core' import { Feature, Project, Variable, CustomProperty } from '../../api/schemas' import { OrganizationMember, fetchOrganizationMembers } from '../../api/members' -import { upperCase } from 'lodash' import { createHash } from 'crypto' import path from 'path' +import { keyToConstant } from '../../utils/keyToConstant' import { fetchAllCompletedOrArchivedFeatures, fetchFeatures, @@ -353,7 +353,7 @@ export const ${constantName} = '${hashedKey}' as const` } getVariableGeneratedName(variable: Variable) { - let constantName = upperCase(variable.key).replace(/\s/g, '_') + let constantName = keyToConstant(variable.key) if (this.methodNames[constantName]?.length) { constantName = `${constantName}_${this.methodNames[constantName].length}` diff --git a/src/utils/keyToConstant.ts b/src/utils/keyToConstant.ts new file mode 100644 index 000000000..a7ac5fc76 --- /dev/null +++ b/src/utils/keyToConstant.ts @@ -0,0 +1,11 @@ +import { upperCase } from 'lodash' + +/** + * Transforms a variable key into the constant name format used by the generate command. + * This matches the logic in src/commands/generate/types.ts getVariableGeneratedName() + * + * Example: 'my-variable' -> 'MY_VARIABLE' + */ +export function keyToConstant(variableKey: string): string { + return upperCase(variableKey).replace(/\s/g, '_') +} From 34075eee4830b224d8bd2f67ef3458358f8230f9 Mon Sep 17 00:00:00 2001 From: Gabriella Gerges Date: Wed, 5 Nov 2025 13:09:46 -0400 Subject: [PATCH 2/3] fix: update comment in keyToConstant.ts --- src/utils/keyToConstant.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/utils/keyToConstant.ts b/src/utils/keyToConstant.ts index a7ac5fc76..695b5c027 100644 --- a/src/utils/keyToConstant.ts +++ b/src/utils/keyToConstant.ts @@ -1,8 +1,7 @@ import { upperCase } from 'lodash' /** - * Transforms a variable key into the constant name format used by the generate command. - * This matches the logic in src/commands/generate/types.ts getVariableGeneratedName() + * Converts a variable key to its generated constant name format. * * Example: 'my-variable' -> 'MY_VARIABLE' */ From a1f10cf962a706bfa492142168316e9473718302 Mon Sep 17 00:00:00 2001 From: Gabriella Gerges Date: Wed, 5 Nov 2025 17:54:21 -0400 Subject: [PATCH 3/3] chore: test for update functionality --- src/commands/diff/diff.test.ts | 21 +++++++++++++++++++ .../fixtures/configs/autoAliasConfig.yml | 13 ++++++++++++ test-utils/fixtures/configs/mockTypes.ts | 5 +++++ test-utils/fixtures/diff/auto-alias-transform | 17 +++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 test-utils/fixtures/configs/autoAliasConfig.yml create mode 100644 test-utils/fixtures/configs/mockTypes.ts create mode 100644 test-utils/fixtures/diff/auto-alias-transform diff --git a/src/commands/diff/diff.test.ts b/src/commands/diff/diff.test.ts index b2343aff2..e36c6a0d7 100644 --- a/src/commands/diff/diff.test.ts +++ b/src/commands/diff/diff.test.ts @@ -292,6 +292,27 @@ describe('diff', () => { .it('identifies aliased variables specified in config file', (ctx) => { expect(ctx.stdout).toMatchSnapshot() }) + + test.stdout() + .command([ + 'diff', + '--file', + 'test-utils/fixtures/diff/auto-alias-transform', + '--no-api', + '--repo-config-path', + './test-utils/fixtures/configs/autoAliasConfig.yml', + ]) + .it( + 'resolves aliases from generated types file using key transformation', + (ctx) => { + // Should NOT show "could not be identified" warnings + expect(ctx.stdout).not.toContain('could not be identified') + // Should identify the variables + expect(ctx.stdout).toContain('my-test-variable') + expect(ctx.stdout).toContain('enable-feature') + expect(ctx.stdout).toContain('removed-variable') + }, + ) test.stdout() .command([ 'diff', diff --git a/test-utils/fixtures/configs/autoAliasConfig.yml b/test-utils/fixtures/configs/autoAliasConfig.yml new file mode 100644 index 000000000..e661ab79d --- /dev/null +++ b/test-utils/fixtures/configs/autoAliasConfig.yml @@ -0,0 +1,13 @@ +project: "test-project" +org: + id: "org_test" + name: "test-org" + +typeGenerator: + outputPath: "./test-utils/fixtures/configs/mockTypes.ts" + +codeInsights: + matchPatterns: + ts: + - ":\\s*([a-z][a-z0-9-]*)" + diff --git a/test-utils/fixtures/configs/mockTypes.ts b/test-utils/fixtures/configs/mockTypes.ts new file mode 100644 index 000000000..fc53f9a7f --- /dev/null +++ b/test-utils/fixtures/configs/mockTypes.ts @@ -0,0 +1,5 @@ +// Mock generated types file for testing auto-alias resolution +export const MY_TEST_VARIABLE = 'my-test-variable' as const +export const ENABLE_FEATURE = 'enable-feature' as const +export const REMOVED_VARIABLE = 'removed-variable' as const + diff --git a/test-utils/fixtures/diff/auto-alias-transform b/test-utils/fixtures/diff/auto-alias-transform new file mode 100644 index 000000000..fddf67db5 --- /dev/null +++ b/test-utils/fixtures/diff/auto-alias-transform @@ -0,0 +1,17 @@ +diff --git a/test-utils/fixtures/diff/sampleDiff b/test-utils/fixtures/diff/sampleDiff +new file mode 100644 +index 00000000..e69de29b +diff --git a/test-utils/fixtures/diff/sampleDiff.ts b/test-utils/fixtures/diff/sampleDiff.ts +new file mode 100644 +index 00000000..ed8ee4ab +--- /dev/null ++++ b/test-utils/fixtures/diff/sampleDiff.ts +@@ -1,1 +1,21 @@ ++const config = { ++ feature: my-test-variable, ++ beta: enable-feature ++} +-const old = { +- feature: removed-variable +-} +