Skip to content

Commit d38fcd8

Browse files
committed
Enable Feature.DiffInformedQueries
1 parent 6f936b5 commit d38fcd8

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

src/feature-flags.test.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ test.beforeEach(() => {
3333

3434
const testRepositoryNwo = parseRepositoryNwo("github/example");
3535

36-
test(`All features are disabled if running against GHES`, async (t) => {
36+
test(`Return feature defaultValue if running against GHES`, async (t) => {
3737
await withTmpDir(async (tmpDir) => {
3838
const loggedMessages = [];
3939
const features = setUpFeatureFlagTests(
4040
tmpDir,
4141
getRecordingLogger(loggedMessages),
42-
{ type: GitHubVariant.GHES, version: "3.0.0" },
42+
{ type: GitHubVariant.GHES, version: "4.0.0" },
4343
);
4444

4545
for (const feature of Object.values(Feature)) {
@@ -60,6 +60,36 @@ test(`All features are disabled if running against GHES`, async (t) => {
6060
});
6161
});
6262

63+
const DIFF_INFORMED_QUERIES_TEST_CASES = [
64+
{ version: "3.18.0.pre1", expected: false },
65+
{ version: "3.18.5", expected: false },
66+
{ version: "3.19.0.pre1", expected: true },
67+
{ version: "3.19.0.gm1", expected: true },
68+
{ version: "3.19.0.rc1", expected: true },
69+
{ version: "3.19.0", expected: true },
70+
{ version: "3.20.0.pre1", expected: true },
71+
{ version: "3.20.0", expected: true },
72+
];
73+
74+
// Test cases for the minimumGhesVersion field, via Feature.DiffInformedQueries
75+
for (const testCase of DIFF_INFORMED_QUERIES_TEST_CASES) {
76+
const feature = Feature.DiffInformedQueries;
77+
test(`Feature ${feature} is ${testCase.expected ? "enabled" : "disabled"} for GHES ${testCase.version}`, async (t) => {
78+
await withTmpDir(async (tmpDir) => {
79+
const loggedMessages = [];
80+
const features = setUpFeatureFlagTests(
81+
tmpDir,
82+
getRecordingLogger(loggedMessages),
83+
{ type: GitHubVariant.GHES, version: testCase.version },
84+
);
85+
t.is(
86+
await features.getValue(feature, includeCodeQlIfRequired(feature)),
87+
testCase.expected,
88+
);
89+
});
90+
});
91+
}
92+
6393
test(`Feature flags are requested in Proxima`, async (t) => {
6494
await withTmpDir(async (tmpDir) => {
6595
const loggedMessages = [];

src/feature-flags.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ export const featureConfig: Record<
8787
* Prefer using `ToolsFeature`s for future flags.
8888
*/
8989
minimumVersion: string | undefined;
90+
/**
91+
* Minimum version of GitHub Enterprise Server (GHES) for which this feature
92+
* is available.
93+
*
94+
* - If `defaultValue` is `true`, and this field is set, the feature is
95+
* enabled only on GHES versions greater than or equal to this version.
96+
* - If `defaultValue` is `true`, and this field is not set, the feature is
97+
* enabled on all versions of GHES.
98+
* - If `defaultValue` is `false`, the feature is always disabled on GHES.
99+
*/
100+
minimumGhesVersion?: string;
90101
/** Required tools feature, if applicable. */
91102
toolsFeature?: ToolsFeature;
92103
}
@@ -113,9 +124,10 @@ export const featureConfig: Record<
113124
minimumVersion: "2.15.0",
114125
},
115126
[Feature.DiffInformedQueries]: {
116-
defaultValue: false,
127+
defaultValue: true,
117128
envVar: "CODEQL_ACTION_DIFF_INFORMED_QUERIES",
118129
minimumVersion: "2.21.0",
130+
minimumGhesVersion: "3.19.0",
119131
},
120132
[Feature.DisableCombineSarifFiles]: {
121133
defaultValue: false,
@@ -193,7 +205,7 @@ export class Features implements FeatureEnablement {
193205
private gitHubFeatureFlags: GitHubFeatureFlags;
194206

195207
constructor(
196-
gitHubVersion: util.GitHubVersion,
208+
private readonly gitHubVersion: util.GitHubVersion,
197209
repositoryNwo: RepositoryNwo,
198210
tempDir: string,
199211
private readonly logger: Logger,
@@ -303,6 +315,24 @@ export class Features implements FeatureEnablement {
303315
}
304316

305317
const defaultValue = featureConfig[feature].defaultValue;
318+
319+
if (defaultValue && this.gitHubVersion.type === util.GitHubVariant.GHES) {
320+
const minimumGhesVersion = featureConfig[feature].minimumGhesVersion;
321+
if (
322+
minimumGhesVersion &&
323+
semver.lt(
324+
semver.coerce(this.gitHubVersion.version)!,
325+
minimumGhesVersion,
326+
)
327+
) {
328+
this.logger.debug(
329+
`Feature ${feature} is disabled because the GitHub Enterprise Server ` +
330+
`is older than the minimum version ${minimumGhesVersion}.`,
331+
);
332+
return false;
333+
}
334+
}
335+
306336
this.logger.debug(
307337
`Feature ${feature} is ${
308338
defaultValue ? "enabled" : "disabled"

0 commit comments

Comments
 (0)