From 120993f7238c7cf9a7c3af84bbfb7a3084742083 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Fri, 30 Oct 2026 18:06:04 +0000 Subject: [PATCH] Convert diagnostic ID to kebab case --- lib/entry-points.js | 2 +- src/languages/traced.test.ts | 99 ++++++++++++++++++++++++++++++++++++ src/languages/traced.ts | 2 +- 3 files changed, 101 insertions(+), 2 deletions(-) diff --git a/lib/entry-points.js b/lib/entry-points.js index 3a43d4cd5..7740535e8 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -194046,7 +194046,7 @@ function handleUnsupportedVersion(logger2, config, tracedLanguages, abortUnsuppo config, language, makeDiagnostic( - `codeql-action/unsupported-traced-analysis-${product.toLowerCase()}`, + `codeql-action/unsupported-traced-analysis-${product.toLowerCase().replaceAll(" ", "-")}`, `Traced analysis is not supported on this version of ${product}`, { attributes: { diff --git a/src/languages/traced.test.ts b/src/languages/traced.test.ts index 2b9d50dfa..e4b38761c 100644 --- a/src/languages/traced.test.ts +++ b/src/languages/traced.test.ts @@ -1,5 +1,6 @@ import fs from "fs"; +import type { ExecOptions } from "@actions/exec"; import * as toolrunner from "@actions/exec/lib/toolrunner"; import * as io from "@actions/io"; import test from "ava"; @@ -546,6 +547,104 @@ test.serial( }), ); +// `addDiagnostic` changes global state and we must stub it, so this test must be serial. +test.serial( + "checkRunnerSupportsTracedAnalysis logs and adds diagnostic if Xcode SDK version is unsupported", + async (t) => + withTmpDir(async (tmpDir) => { + const logger = new RecordingLogger(); + const env = getTestEnv(); + env.set(ActionsEnvVars.RUNNER_TEMP, tmpDir); + const features = createFeatures([Feature.CheckUnsupportedTracedAnalysis]); + + const readlinkSync = sinon + .stub(fs, "readlinkSync") + .throws(new Error("Not found")); + const which = sinon.stub(io, "which").resolves("/path/to/xcrun"); + + let stdoutListener: ((data: Buffer) => void) | undefined = undefined; + const exec = sinon.stub<[], Promise>().callsFake(async () => { + if (stdoutListener !== undefined) { + stdoutListener(Buffer.from("Xcode 27.5")); + stdoutListener(Buffer.from("Build version 27F9")); + return 0; + } else { + throw new Error("Error to force next fallback"); + } + }); + const runner = sinon.createStubInstance(toolrunner.ToolRunner, { + exec, + }); + const toolrunnerStub = sinon + .stub(toolrunner, "ToolRunner") + .callsFake((_cmd, args: string[], opts: ExecOptions) => { + if (args[0] !== "xcodebuild") { + stdoutListener = opts.listeners?.stdout; + } + return runner; + }); + + const codeql = await getCodeQLWithTracedStub( + "codeql-for-testing", + logger, + env, + ); + sinon.stub(codeql, "getVersion").resolves(makeVersionInfo("2.27.0")); + + const addDiagnostic = sinon.stub(diagnostics, "addDiagnostic"); + + const config = createTestConfig({ + tempDir: tmpDir, + languages: [BuiltInLanguage.swift], + }); + await checkRunnerSupportsTracedAnalysis( + initAllState({ + logger, + platform: "darwin", + osRelease: "26.0.0", + env, + features, + }), + config, + codeql, + ); + + t.is(readlinkSync.callCount, 1); + t.deepEqual(readlinkSync.args[0], [XCODE_SELECT_LINK_PATH]); + + t.is(which.callCount, 2); + t.is(toolrunnerStub.callCount, 2); + t.is(exec.callCount, 2); + + checkExpectedLogMessages(t, logger.messages, [ + "Unable to determine Xcode version from xcodebuild", + "Traced analysis is not supported on Xcode SDK 27", + ]); + + t.is(addDiagnostic.callCount, 1); + t.like(addDiagnostic.args[0], [ + config, + BuiltInLanguage.swift, + { + attributes: { + languages: [BuiltInLanguage.swift], + xcodeSdkVersion: "27.5.0", + }, + severity: "warning", + source: { + id: "codeql-action/unsupported-traced-analysis-xcode-sdk", + name: "Traced analysis is not supported on this version of Xcode SDK", + }, + visibility: { + cliSummaryTable: true, + statusPage: true, + telemetry: true, + }, + } satisfies Partial, + ]); + }), +); + // `addDiagnostic` changes global state and we must stub it, so this test must be serial. test.serial( "checkRunnerSupportsTracedAnalysis throws if Xcode version is unsupported and FF is enabled", diff --git a/src/languages/traced.ts b/src/languages/traced.ts index 96eb5da45..406afc9b3 100644 --- a/src/languages/traced.ts +++ b/src/languages/traced.ts @@ -83,7 +83,7 @@ function handleUnsupportedVersion( config, language, makeDiagnostic( - `codeql-action/unsupported-traced-analysis-${product.toLowerCase()}`, + `codeql-action/unsupported-traced-analysis-${product.toLowerCase().replaceAll(" ", "-")}`, `Traced analysis is not supported on this version of ${product}`, { attributes: {