From cbec03fbcc4cee025513491c1116cb647a6d5b24 Mon Sep 17 00:00:00 2001 From: alzimmermsft <48699787+alzimmermsft@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:47:29 -0400 Subject: [PATCH 1/5] Add Java Maven caching and test publishing --- .../UpdateTargetVersions-2026-9-29-10-7-0.md | 7 ++ .../templates/steps/maven-authenticate.yml | 15 ++- eng/emitters/pipelines/java-ci.test.ts | 101 ++++++++++++++++++ .../pipelines/templates/steps/build-step.yml | 14 +++ .../pipelines/templates/steps/test-step.yml | 16 +++ .../eng/scripts/Test-Packages.ps1 | 2 +- 6 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 .chronus/changes/UpdateTargetVersions-2026-9-29-10-7-0.md create mode 100644 eng/emitters/pipelines/java-ci.test.ts diff --git a/.chronus/changes/UpdateTargetVersions-2026-9-29-10-7-0.md b/.chronus/changes/UpdateTargetVersions-2026-9-29-10-7-0.md new file mode 100644 index 00000000000..e1a2454df9d --- /dev/null +++ b/.chronus/changes/UpdateTargetVersions-2026-9-29-10-7-0.md @@ -0,0 +1,7 @@ +--- +changeKind: internal +packages: + - "@typespec/http-client-java" +--- + +Cache Maven dependencies in Java CI and publish generator, emitter, and Spector test results to Azure DevOps, including failed test runs. \ No newline at end of file diff --git a/eng/common/pipelines/templates/steps/maven-authenticate.yml b/eng/common/pipelines/templates/steps/maven-authenticate.yml index 1b84e984add..9911c1aece5 100644 --- a/eng/common/pipelines/templates/steps/maven-authenticate.yml +++ b/eng/common/pipelines/templates/steps/maven-authenticate.yml @@ -5,10 +5,23 @@ steps: # Copy mirror settings to default Maven location so all requests go through CFS - pwsh: | $m2Dir = if ($env:USERPROFILE) { "$env:USERPROFILE\.m2" } else { "$HOME/.m2" } - New-Item -ItemType Directory -Force -Path $m2Dir | Out-Null + $mavenRepositoryPath = Join-Path $m2Dir "repository" + New-Item -ItemType Directory -Force -Path $mavenRepositoryPath | Out-Null + Write-Host "##vso[task.setvariable variable=MavenRepositoryPath]$mavenRepositoryPath" Copy-Item -Path "${{ parameters.SourceDirectory }}/eng/settings.xml" -Destination "$m2Dir/settings.xml" displayName: "Setup Maven mirror settings" + # Cache artifacts only; settings.xml contains feed credentials. + # Include the stage so test jobs can save dependencies absent from build caches. + - task: Cache@2 + displayName: "Cache Maven repository" + inputs: + key: '"maven" | "$(Agent.OS)" | "$(System.StageName)" | ${{ parameters.SourceDirectory }}/**/pom.xml' + restoreKeys: | + "maven" | "$(Agent.OS)" | "$(System.StageName)" + "maven" | "$(Agent.OS)" + path: $(MavenRepositoryPath) + # Authenticate with Azure Artifacts feeds # MavenAuthenticate adds entries to ~/.m2/settings.xml matching mirror id 'azure-sdk-for-java' - task: MavenAuthenticate@0 diff --git a/eng/emitters/pipelines/java-ci.test.ts b/eng/emitters/pipelines/java-ci.test.ts new file mode 100644 index 00000000000..de835bf98e8 --- /dev/null +++ b/eng/emitters/pipelines/java-ci.test.ts @@ -0,0 +1,101 @@ +import { readFileSync } from "node:fs"; +import { describe, expect, it } from "vitest"; +import { parse } from "yaml"; + +interface Step { + task?: string; + template?: string; + displayName?: string; + pwsh?: string; + condition?: string; + inputs?: Record; + [condition: `\${{ ${string} }}`]: Step[]; +} + +function loadTemplate(path: string): { steps: Step[] } { + return parse(readFileSync(new URL(path, import.meta.url), "utf8")); +} + +const javaOnly = "${{ if eq(parameters.LanguageShortName, 'java') }}"; + +describe("Java CI", () => { + it("caches Maven dependencies by OS, stage, and POM contents", () => { + const { steps } = loadTemplate("../../common/pipelines/templates/steps/maven-authenticate.yml"); + const cache = steps.find((step) => step.task === "Cache@2"); + + expect(cache?.inputs).toMatchObject({ + key: '"maven" | "$(Agent.OS)" | "$(System.StageName)" | ${{ parameters.SourceDirectory }}/**/pom.xml', + restoreKeys: expect.stringContaining('"maven" | "$(Agent.OS)" | "$(System.StageName)"'), + path: "$(MavenRepositoryPath)", + }); + }); + + it("caches the default Maven repository without caching feed credentials", () => { + const { steps } = loadTemplate("../../common/pipelines/templates/steps/maven-authenticate.yml"); + + expect(steps[0].pwsh).toContain('Join-Path $m2Dir "repository"'); + expect(steps[0].pwsh).toContain( + "##vso[task.setvariable variable=MavenRepositoryPath]$mavenRepositoryPath", + ); + expect(steps.findIndex((step) => step.task === "Cache@2")).toBeGreaterThan(0); + }); + + it.each(["build", "test"])("initializes Maven caching in Java %s jobs", (kind) => { + const { steps } = loadTemplate(`./templates/steps/${kind}-step.yml`); + const javaSteps = steps.flatMap((step) => step[javaOnly] ?? []); + + expect(javaSteps).toContainEqual({ + template: "/eng/common/pipelines/templates/steps/maven-authenticate.yml", + }); + }); + + it.each(["build", "test"])("publishes Maven results after Java %s failures", (kind) => { + const { steps } = loadTemplate(`./templates/steps/${kind}-step.yml`); + const javaSteps = steps.flatMap((step) => step[javaOnly] ?? []); + const publisher = javaSteps.find((step) => step.task === "PublishTestResults@2"); + + expect(publisher).toMatchObject({ + condition: + kind === "test" + ? "and(succeededOrFailed(), contains('${{ parameters.TestArgs }}', '-UnitTests'))" + : "succeededOrFailed()", + inputs: { + testResultsFormat: "JUnit", + searchFolder: "$(selfRepositoryPath)${{ parameters.PackagePath }}", + testResultsFiles: expect.stringContaining( + "generator/**/target/surefire-reports/TEST-*.xml", + ), + mergeTestResults: true, + failTaskOnFailedTests: true, + failTaskOnFailureToPublishResults: true, + failTaskOnMissingResultsFile: true, + }, + }); + + const publisherIndex = steps.findIndex((step) => + step[javaOnly]?.some((nested) => nested.task === "PublishTestResults@2"), + ); + const scriptIndex = steps.findIndex((step) => step.displayName === `Run ${kind} script`); + expect(scriptIndex).toBeGreaterThanOrEqual(0); + expect(publisherIndex).toBeGreaterThan(scriptIndex); + }); + + it("collects emitter JUnit results alongside Spector results", () => { + const { steps } = loadTemplate("./templates/steps/test-step.yml"); + const publisher = steps + .flatMap((step) => step[javaOnly] ?? []) + .find((step) => step.task === "PublishTestResults@2"); + + expect(publisher?.inputs?.testResultsFiles).toContain("test-results.xml"); + }); + + it("runs emitter tests with console and JUnit reporters", () => { + const script = readFileSync( + new URL("../../../packages/http-client-java/eng/scripts/Test-Packages.ps1", import.meta.url), + "utf8", + ); + + expect(script).toContain("npm run test:emitter"); + expect(script).toContain("-- --reporter=default --reporter=junit"); + }); +}); diff --git a/eng/emitters/pipelines/templates/steps/build-step.yml b/eng/emitters/pipelines/templates/steps/build-step.yml index 580889faae7..a0de7dccf3f 100644 --- a/eng/emitters/pipelines/templates/steps/build-step.yml +++ b/eng/emitters/pipelines/templates/steps/build-step.yml @@ -110,3 +110,17 @@ steps: -PublishType:"${{ parameters.Publish }}" -Prerelease:$${{ parameters.BuildPrereleaseVersion }} workingDirectory: $(selfRepositoryPath) + + - ${{ if eq(parameters.LanguageShortName, 'java') }}: + - task: PublishTestResults@2 + displayName: "Publish Java generator test results" + condition: succeededOrFailed() + inputs: + testResultsFormat: JUnit + testResultsFiles: "generator/**/target/surefire-reports/TEST-*.xml" + searchFolder: $(selfRepositoryPath)${{ parameters.PackagePath }} + mergeTestResults: true + testRunTitle: Java generator $(Agent.JobName) + failTaskOnFailedTests: true + failTaskOnFailureToPublishResults: true + failTaskOnMissingResultsFile: true diff --git a/eng/emitters/pipelines/templates/steps/test-step.yml b/eng/emitters/pipelines/templates/steps/test-step.yml index b7ca2b5a14e..ab4d63cc0ec 100644 --- a/eng/emitters/pipelines/templates/steps/test-step.yml +++ b/eng/emitters/pipelines/templates/steps/test-step.yml @@ -97,6 +97,22 @@ steps: arguments: ${{ parameters.TestArgs }} workingDirectory: $(selfRepositoryPath) + - ${{ if eq(parameters.LanguageShortName, 'java') }}: + - task: PublishTestResults@2 + displayName: "Publish Java test results" + condition: and(succeededOrFailed(), contains('${{ parameters.TestArgs }}', '-UnitTests')) + inputs: + testResultsFormat: JUnit + testResultsFiles: | + generator/**/target/surefire-reports/TEST-*.xml + test-results.xml + searchFolder: $(selfRepositoryPath)${{ parameters.PackagePath }} + mergeTestResults: true + testRunTitle: Java $(Agent.JobName) + failTaskOnFailedTests: true + failTaskOnFailureToPublishResults: true + failTaskOnMissingResultsFile: true + - ${{ if and(eq(variables['System.TeamProject'], 'internal'), eq(parameters.EnableCadlRanchReport, true)) }}: - task: AzureCLI@2 displayName: "Upload Cadl Ranch Standard Coverage Report" diff --git a/packages/http-client-java/eng/scripts/Test-Packages.ps1 b/packages/http-client-java/eng/scripts/Test-Packages.ps1 index eff80b1ba56..1673f7992a2 100644 --- a/packages/http-client-java/eng/scripts/Test-Packages.ps1 +++ b/packages/http-client-java/eng/scripts/Test-Packages.ps1 @@ -21,7 +21,7 @@ Push-Location $packageRoot try { if ($UnitTests) { Invoke-LoggedCommand "npm run typecheck" - Invoke-LoggedCommand "npm run test" + Invoke-LoggedCommand "npm run test:emitter --registry=https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-js/npm/registry/ -- --reporter=default --reporter=junit" Write-Host "Emitter unit tests passed" Write-Host "Current PATH: $env:PATH" From 056f16c62f9fcff17ff382fceea3c9fd58781e39 Mon Sep 17 00:00:00 2001 From: alzimmermsft <48699787+alzimmermsft@users.noreply.github.com> Date: Thu, 29 Oct 2026 14:22:33 -0400 Subject: [PATCH 2/5] Broaden test publishing --- ...hingAndTestPublishing-2026-9-29-11-43-1.md | 8 + eng/emitters/pipelines/emitter-ci.test.ts | 258 ++++++++++++++++++ eng/emitters/pipelines/java-ci.test.ts | 101 ------- .../pipelines/templates/steps/test-step.yml | 34 ++- .../eng/scripts/Get-Spector-Coverage.ps1 | 2 +- .../eng/scripts/Test-Packages.ps1 | 4 +- .../emitter/vitest.config.ts | 9 +- .../eng/scripts/Test-Packages.ps1 | 3 + packages/http-client-python/tests/tox.ini | 6 +- 9 files changed, 310 insertions(+), 115 deletions(-) create mode 100644 .chronus/changes/CiCachingAndTestPublishing-2026-9-29-11-43-1.md create mode 100644 eng/emitters/pipelines/emitter-ci.test.ts delete mode 100644 eng/emitters/pipelines/java-ci.test.ts diff --git a/.chronus/changes/CiCachingAndTestPublishing-2026-9-29-11-43-1.md b/.chronus/changes/CiCachingAndTestPublishing-2026-9-29-11-43-1.md new file mode 100644 index 00000000000..eb0d6e78527 --- /dev/null +++ b/.chronus/changes/CiCachingAndTestPublishing-2026-9-29-11-43-1.md @@ -0,0 +1,8 @@ +--- +changeKind: internal +packages: + - "@typespec/http-client-java" + - "@typespec/http-client-python" +--- + +Publish Azure DevOps test results after the shared test script for all language emitters. \ No newline at end of file diff --git a/eng/emitters/pipelines/emitter-ci.test.ts b/eng/emitters/pipelines/emitter-ci.test.ts new file mode 100644 index 00000000000..55f24477933 --- /dev/null +++ b/eng/emitters/pipelines/emitter-ci.test.ts @@ -0,0 +1,258 @@ +import { readFileSync } from "node:fs"; +import { runInNewContext } from "node:vm"; +import { describe, expect, it, vi } from "vitest"; +import { parse } from "yaml"; + +interface Step { + task?: string; + template?: string; + displayName?: string; + pwsh?: string; + condition?: string; + inputs?: Record; + [condition: `\${{ ${string} }}`]: Step[] | Step; +} + +function loadTemplate(path: string): { steps: Step[] } { + return parse(readFileSync(new URL(path, import.meta.url), "utf8")); +} + +function languageSteps(kind: string, language: string): Step[] { + const { steps } = loadTemplate(`./templates/steps/${kind}-step.yml`); + const condition: `\${{ ${string} }}` = `\${{ if eq(parameters.LanguageShortName, '${language}') }}`; + return steps.flatMap((step) => { + const branch = step[condition]; + return Array.isArray(branch) ? branch : [step]; + }); +} + +function publisherFor(kind: string, language: string, format: string): Step { + const publisher = languageSteps(kind, language).find( + (step) => step.task === "PublishTestResults@2" && step.inputs?.testResultsFormat === format, + ); + if (!publisher) { + throw new Error(`Missing ${format} publisher for ${language} ${kind} jobs.`); + } + return publisher; +} + +function shouldPublish(publisher: Step, language: string, args: string, outcome: string): boolean { + const branch = + publisher[ + language === "python" + ? "${{ if eq(parameters.LanguageShortName, 'python') }}" + : language === "java" + ? "${{ elseif eq(parameters.LanguageShortName, 'java') }}" + : "${{ else }}" + ]; + const condition = !Array.isArray(branch) ? (branch?.condition ?? publisher.condition) : undefined; + if (!condition) { + throw new Error("Missing test publishing condition."); + } + const result: unknown = runInNewContext( + condition + .replaceAll("${{ parameters.TestArgs }}", "$(TestArguments)") + .replaceAll("$(TestArguments)", args), + { + and: (...values: boolean[]) => values.every(Boolean), + or: (...values: boolean[]) => values.some(Boolean), + contains: (value: string, fragment: string) => + value.toLowerCase().includes(fragment.toLowerCase()), + succeededOrFailed: () => outcome === "succeeded" || outcome === "failed", + }, + ); + if (typeof result !== "boolean") { + throw new Error("Publishing conditions must evaluate to a boolean."); + } + return result; +} + +function readSource(path: string): string { + return readFileSync(new URL(`../../../packages/${path}`, import.meta.url), "utf8"); +} + +describe("Emitter CI", () => { + it("caches Maven dependencies by OS, stage, and POM contents", () => { + const { steps } = loadTemplate("../../common/pipelines/templates/steps/maven-authenticate.yml"); + const cache = steps.find((step) => step.task === "Cache@2"); + + expect(cache?.inputs).toMatchObject({ + key: '"maven" | "$(Agent.OS)" | "$(System.StageName)" | ${{ parameters.SourceDirectory }}/**/pom.xml', + restoreKeys: expect.stringContaining('"maven" | "$(Agent.OS)" | "$(System.StageName)"'), + path: "$(MavenRepositoryPath)", + }); + }); + + it("caches the default Maven repository without caching feed credentials", () => { + const { steps } = loadTemplate("../../common/pipelines/templates/steps/maven-authenticate.yml"); + + expect(steps[0].pwsh).toContain('Join-Path $m2Dir "repository"'); + expect(steps[0].pwsh).toContain( + "##vso[task.setvariable variable=MavenRepositoryPath]$mavenRepositoryPath", + ); + expect(steps.findIndex((step) => step.task === "Cache@2")).toBeGreaterThan(0); + }); + + it.each(["build", "test"])("initializes Maven caching in Java %s jobs", (kind) => { + const javaSteps = languageSteps(kind, "java"); + + expect(javaSteps).toContainEqual({ + template: "/eng/common/pipelines/templates/steps/maven-authenticate.yml", + }); + }); + + it("publishes generator results after Java build failures", () => { + const publisher = publisherFor("build", "java", "JUnit"); + expect(publisher).toMatchObject({ + condition: "succeededOrFailed()", + inputs: { + testResultsFormat: "JUnit", + searchFolder: "$(selfRepositoryPath)${{ parameters.PackagePath }}", + testResultsFiles: expect.stringContaining( + "generator/**/target/surefire-reports/TEST-*.xml", + ), + mergeTestResults: true, + failTaskOnFailedTests: true, + failTaskOnFailureToPublishResults: true, + failTaskOnMissingResultsFile: true, + }, + }); + }); + + it.each([ + ["java", "generator/**/target/surefire-reports/TEST-*.xml"], + ["csharp", "test-results.xml"], + ["python", "tests/test-results/*.xml"], + ])("collects JUnit results immediately after %s test scripts", (language, reports) => { + const publisher = publisherFor("test", language, "JUnit"); + expect(publisher.inputs).toMatchObject({ + testResultsFormat: "JUnit", + testResultsFiles: expect.stringContaining(reports), + searchFolder: "$(selfRepositoryPath)${{ parameters.PackagePath }}", + mergeTestResults: true, + failTaskOnFailedTests: true, + failTaskOnFailureToPublishResults: true, + failTaskOnMissingResultsFile: true, + }); + expect(publisher.inputs?.testResultsFiles).toContain("test-results.xml"); + + const steps = languageSteps("test", language); + const scriptIndex = steps.findIndex((step) => step.displayName === "Run test script"); + const publisherIndex = steps.findIndex( + (step) => step.task === "PublishTestResults@2" && step.inputs?.testResultsFormat === "JUnit", + ); + expect(scriptIndex).toBeGreaterThanOrEqual(0); + expect(publisherIndex).toBe(scriptIndex + 1); + }); + + it("selects the actual testing mode for each emitter", () => { + const { steps } = loadTemplate("./templates/steps/test-step.yml"); + const publisher = steps.find( + (step) => step.task === "PublishTestResults@2" && step.inputs?.testResultsFormat === "JUnit", + ); + expect(publisher).toMatchObject({ + "${{ if eq(parameters.LanguageShortName, 'python') }}": { + condition: + "and(succeededOrFailed(), contains('${{ parameters.TestArgs }}', '-GenerationChecks'))", + }, + "${{ elseif eq(parameters.LanguageShortName, 'java') }}": { + condition: + "and(succeededOrFailed(), or(contains('${{ parameters.TestArgs }}', '-UnitTests'), contains('${{ parameters.TestArgs }}', '-GenerationChecks')))", + }, + "${{ else }}": { + condition: "and(succeededOrFailed(), contains('${{ parameters.TestArgs }}', '-UnitTests'))", + }, + }); + }); + + it.each([ + { language: "java", args: "-UnitTests", expected: true }, + { language: "java", args: "-GenerationChecks", expected: true }, + { language: "csharp", args: "-UnitTests", expected: true }, + { language: "csharp", args: "-GenerationChecks", expected: false }, + { language: "python", args: "-UnitTests", expected: false }, + { language: "python", args: "-GenerationChecks", expected: true }, + ])( + "publishes only test-producing $language $args jobs, including failures", + ({ language, args, expected }) => { + const publisher = publisherFor("test", language, "JUnit"); + for (const outcome of ["succeeded", "failed", "canceled"]) { + expect(shouldPublish(publisher, language, args, outcome)).toBe( + outcome === "canceled" ? false : expected, + ); + } + }, + ); + + it("publishes C# generator and Spector TRX results after failures", () => { + const publisher = publisherFor("test", "csharp", "VSTest"); + expect(publisher).toMatchObject({ + condition: "and(succeededOrFailed(), contains('${{ parameters.TestArgs }}', '-UnitTests'))", + inputs: { + testResultsFormat: "VSTest", + testResultsFiles: "generator/**/TestResults/*.trx", + searchFolder: "$(selfRepositoryPath)${{ parameters.PackagePath }}", + mergeTestResults: true, + failTaskOnFailedTests: true, + failTaskOnFailureToPublishResults: true, + failTaskOnMissingResultsFile: true, + }, + }); + expect(shouldPublish(publisher, "csharp", "-UnitTests", "failed")).toBe(true); + expect(shouldPublish(publisher, "csharp", "-GenerationChecks", "succeeded")).toBe(false); + }); + + it("enables JUnit output for C# emitter tests", () => { + expect(readSource("http-client-csharp/eng/scripts/Test-Packages.ps1")).toContain( + "npm run test:emitter -- --reporter=default --reporter=junit", + ); + }); + + it("enables TRX output for both C# test invocations", () => { + expect(readSource("http-client-csharp/eng/scripts/Test-Packages.ps1")).toContain( + "dotnet test ./generator --logger trx", + ); + expect(readSource("http-client-csharp/eng/scripts/Get-Spector-Coverage.ps1")).toContain( + "dotnet test $spectorCsproj --logger trx", + ); + }); + + it.each([ + { tfBuild: "True", reporters: ["default", "junit"] }, + { tfBuild: undefined, reporters: undefined }, + ])("selects Python emitter reporters with TF_BUILD=$tfBuild", async ({ tfBuild, reporters }) => { + vi.stubEnv("TF_BUILD", tfBuild); + vi.resetModules(); + try { + const config: { test: { reporters?: unknown; outputFile?: unknown } } = ( + await import( + new URL("../../../packages/http-client-python/emitter/vitest.config.ts", import.meta.url) + .href + ) + ).default; + expect(config.test.reporters).toEqual(reporters); + expect(config.test.outputFile).toEqual({ junit: "./test-results.xml" }); + } finally { + vi.unstubAllEnvs(); + vi.resetModules(); + } + }); + + it("isolates pytest reports for parallel tox environments", () => { + const commands = readSource("http-client-python/tests/tox.ini") + .split(/\r?\n/) + .map((line) => line.trim()) + .filter((line) => line.startsWith("pytest ")); + expect(commands).toHaveLength(3); + for (const command of commands) { + expect(command).toContain("--junitxml={tox_root}/test-results/{envname}.xml"); + } + }); + + it("runs Java emitter tests with console and JUnit reporters", () => { + const script = readSource("http-client-java/eng/scripts/Test-Packages.ps1"); + + expect(script).toContain("npm run test:emitter"); + expect(script).toContain("-- --reporter=default --reporter=junit"); + }); +}); diff --git a/eng/emitters/pipelines/java-ci.test.ts b/eng/emitters/pipelines/java-ci.test.ts deleted file mode 100644 index de835bf98e8..00000000000 --- a/eng/emitters/pipelines/java-ci.test.ts +++ /dev/null @@ -1,101 +0,0 @@ -import { readFileSync } from "node:fs"; -import { describe, expect, it } from "vitest"; -import { parse } from "yaml"; - -interface Step { - task?: string; - template?: string; - displayName?: string; - pwsh?: string; - condition?: string; - inputs?: Record; - [condition: `\${{ ${string} }}`]: Step[]; -} - -function loadTemplate(path: string): { steps: Step[] } { - return parse(readFileSync(new URL(path, import.meta.url), "utf8")); -} - -const javaOnly = "${{ if eq(parameters.LanguageShortName, 'java') }}"; - -describe("Java CI", () => { - it("caches Maven dependencies by OS, stage, and POM contents", () => { - const { steps } = loadTemplate("../../common/pipelines/templates/steps/maven-authenticate.yml"); - const cache = steps.find((step) => step.task === "Cache@2"); - - expect(cache?.inputs).toMatchObject({ - key: '"maven" | "$(Agent.OS)" | "$(System.StageName)" | ${{ parameters.SourceDirectory }}/**/pom.xml', - restoreKeys: expect.stringContaining('"maven" | "$(Agent.OS)" | "$(System.StageName)"'), - path: "$(MavenRepositoryPath)", - }); - }); - - it("caches the default Maven repository without caching feed credentials", () => { - const { steps } = loadTemplate("../../common/pipelines/templates/steps/maven-authenticate.yml"); - - expect(steps[0].pwsh).toContain('Join-Path $m2Dir "repository"'); - expect(steps[0].pwsh).toContain( - "##vso[task.setvariable variable=MavenRepositoryPath]$mavenRepositoryPath", - ); - expect(steps.findIndex((step) => step.task === "Cache@2")).toBeGreaterThan(0); - }); - - it.each(["build", "test"])("initializes Maven caching in Java %s jobs", (kind) => { - const { steps } = loadTemplate(`./templates/steps/${kind}-step.yml`); - const javaSteps = steps.flatMap((step) => step[javaOnly] ?? []); - - expect(javaSteps).toContainEqual({ - template: "/eng/common/pipelines/templates/steps/maven-authenticate.yml", - }); - }); - - it.each(["build", "test"])("publishes Maven results after Java %s failures", (kind) => { - const { steps } = loadTemplate(`./templates/steps/${kind}-step.yml`); - const javaSteps = steps.flatMap((step) => step[javaOnly] ?? []); - const publisher = javaSteps.find((step) => step.task === "PublishTestResults@2"); - - expect(publisher).toMatchObject({ - condition: - kind === "test" - ? "and(succeededOrFailed(), contains('${{ parameters.TestArgs }}', '-UnitTests'))" - : "succeededOrFailed()", - inputs: { - testResultsFormat: "JUnit", - searchFolder: "$(selfRepositoryPath)${{ parameters.PackagePath }}", - testResultsFiles: expect.stringContaining( - "generator/**/target/surefire-reports/TEST-*.xml", - ), - mergeTestResults: true, - failTaskOnFailedTests: true, - failTaskOnFailureToPublishResults: true, - failTaskOnMissingResultsFile: true, - }, - }); - - const publisherIndex = steps.findIndex((step) => - step[javaOnly]?.some((nested) => nested.task === "PublishTestResults@2"), - ); - const scriptIndex = steps.findIndex((step) => step.displayName === `Run ${kind} script`); - expect(scriptIndex).toBeGreaterThanOrEqual(0); - expect(publisherIndex).toBeGreaterThan(scriptIndex); - }); - - it("collects emitter JUnit results alongside Spector results", () => { - const { steps } = loadTemplate("./templates/steps/test-step.yml"); - const publisher = steps - .flatMap((step) => step[javaOnly] ?? []) - .find((step) => step.task === "PublishTestResults@2"); - - expect(publisher?.inputs?.testResultsFiles).toContain("test-results.xml"); - }); - - it("runs emitter tests with console and JUnit reporters", () => { - const script = readFileSync( - new URL("../../../packages/http-client-java/eng/scripts/Test-Packages.ps1", import.meta.url), - "utf8", - ); - - expect(script).toContain("npm run test:emitter"); - expect(script).toContain("-- --reporter=default --reporter=junit"); - }); -}); diff --git a/eng/emitters/pipelines/templates/steps/test-step.yml b/eng/emitters/pipelines/templates/steps/test-step.yml index ab4d63cc0ec..97446cea510 100644 --- a/eng/emitters/pipelines/templates/steps/test-step.yml +++ b/eng/emitters/pipelines/templates/steps/test-step.yml @@ -97,18 +97,38 @@ steps: arguments: ${{ parameters.TestArgs }} workingDirectory: $(selfRepositoryPath) - - ${{ if eq(parameters.LanguageShortName, 'java') }}: + - task: PublishTestResults@2 + displayName: "Publish ${{ parameters.LanguageShortName }} test script results" + ${{ if eq(parameters.LanguageShortName, 'python') }}: + condition: and(succeededOrFailed(), contains('${{ parameters.TestArgs }}', '-GenerationChecks')) + ${{ elseif eq(parameters.LanguageShortName, 'java') }}: + # Regeneration also rebuilds the Java generator and runs its Maven tests. + condition: and(succeededOrFailed(), or(contains('${{ parameters.TestArgs }}', '-UnitTests'), contains('${{ parameters.TestArgs }}', '-GenerationChecks'))) + ${{ else }}: + condition: and(succeededOrFailed(), contains('${{ parameters.TestArgs }}', '-UnitTests')) + inputs: + testResultsFormat: JUnit + testResultsFiles: | + test-results.xml + generator/**/target/surefire-reports/TEST-*.xml + tests/test-results/*.xml + searchFolder: $(selfRepositoryPath)${{ parameters.PackagePath }} + mergeTestResults: true + testRunTitle: ${{ parameters.LanguageShortName }} $(Agent.JobName) + failTaskOnFailedTests: true + failTaskOnFailureToPublishResults: true + failTaskOnMissingResultsFile: true + + - ${{ if eq(parameters.LanguageShortName, 'csharp') }}: - task: PublishTestResults@2 - displayName: "Publish Java test results" + displayName: "Publish C# generator and Spector test results" condition: and(succeededOrFailed(), contains('${{ parameters.TestArgs }}', '-UnitTests')) inputs: - testResultsFormat: JUnit - testResultsFiles: | - generator/**/target/surefire-reports/TEST-*.xml - test-results.xml + testResultsFormat: VSTest + testResultsFiles: "generator/**/TestResults/*.trx" searchFolder: $(selfRepositoryPath)${{ parameters.PackagePath }} mergeTestResults: true - testRunTitle: Java $(Agent.JobName) + testRunTitle: C# generator $(Agent.JobName) failTaskOnFailedTests: true failTaskOnFailureToPublishResults: true failTaskOnMissingResultsFile: true diff --git a/packages/http-client-csharp/eng/scripts/Get-Spector-Coverage.ps1 b/packages/http-client-csharp/eng/scripts/Get-Spector-Coverage.ps1 index 8cd8dbc92e2..45845642682 100644 --- a/packages/http-client-csharp/eng/scripts/Get-Spector-Coverage.ps1 +++ b/packages/http-client-csharp/eng/scripts/Get-Spector-Coverage.ps1 @@ -56,7 +56,7 @@ $specs = Get-Sorted-Specs # test all Write-Host "Generating Spector coverage" -ForegroundColor Cyan - $command = "dotnet test $spectorCsproj" + $command = "dotnet test $spectorCsproj --logger trx" Invoke $command # exit if the testing failed if ($LASTEXITCODE -ne 0) { diff --git a/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 b/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 index 4a33a3081ef..34593cc7780 100644 --- a/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 +++ b/packages/http-client-csharp/eng/scripts/Test-Packages.ps1 @@ -33,13 +33,13 @@ try { # test the emitter Invoke-LoggedCommand "npm run build" -GroupOutput - Invoke-LoggedCommand "npm run test:emitter" -GroupOutput + Invoke-LoggedCommand "npm run test:emitter -- --reporter=default --reporter=junit" -GroupOutput # enforce cop static-analysis rules on the generator sources Invoke-LoggedCommand "./eng/scripts/Invoke-Cop.ps1" -GroupOutput # test the generator - Invoke-LoggedCommand "dotnet test ./generator -p:RestoreConfigFile=`"$nugetConfigPath`" $ciNugetAuditArg" -GroupOutput + Invoke-LoggedCommand "dotnet test ./generator --logger trx -p:RestoreConfigFile=`"$nugetConfigPath`" $ciNugetAuditArg" -GroupOutput Invoke-LoggedCommand "./eng/scripts/Get-Spector-Coverage.ps1" -GroupOutput } diff --git a/packages/http-client-python/emitter/vitest.config.ts b/packages/http-client-python/emitter/vitest.config.ts index 4c95a78261f..182ccba2116 100644 --- a/packages/http-client-python/emitter/vitest.config.ts +++ b/packages/http-client-python/emitter/vitest.config.ts @@ -1,4 +1,11 @@ import { defineConfig, mergeConfig } from "vitest/config"; import { defaultTypeSpecVitestConfig } from "../../../vitest.config.js"; -export default mergeConfig(defaultTypeSpecVitestConfig, defineConfig({})); +export default mergeConfig( + defaultTypeSpecVitestConfig, + defineConfig({ + test: { + reporters: process.env.TF_BUILD ? ["default", "junit"] : undefined, + }, + }), +); diff --git a/packages/http-client-python/eng/scripts/Test-Packages.ps1 b/packages/http-client-python/eng/scripts/Test-Packages.ps1 index 05ea968b8cb..1ecbdae0381 100644 --- a/packages/http-client-python/eng/scripts/Test-Packages.ps1 +++ b/packages/http-client-python/eng/scripts/Test-Packages.ps1 @@ -15,6 +15,9 @@ - Runs Check-GitChanges.ps1 (verify no uncommitted changes) - Runs npm run ci (full test suite: pytest, lint, mypy, pyright) + Azure DevOps collects emitter JUnit results from test-results.xml and + pytest JUnit results from tests/test-results/*.xml. + .PARAMETER UnitTests Run unit tests only (just builds the project). diff --git a/packages/http-client-python/tests/tox.ini b/packages/http-client-python/tests/tox.ini index 29dde03686a..28965b87279 100644 --- a/packages/http-client-python/tests/tox.ini +++ b/packages/http-client-python/tests/tox.ini @@ -34,7 +34,7 @@ deps = -e {tox_root}/../generator commands = python {tox_root}/install_packages.py azure {tox_root} - pytest mock_api/azure mock_api/shared -v -n auto {posargs} + pytest mock_api/azure mock_api/shared -v -n auto --junitxml={tox_root}/test-results/{envname}.xml {posargs} [testenv:test-unbranded] description = Run tests for unbranded flavor @@ -47,7 +47,7 @@ deps = -e {tox_root}/../generator commands = python {tox_root}/install_packages.py unbranded {tox_root} - pytest mock_api/unbranded mock_api/shared -v -n auto {posargs} + pytest mock_api/unbranded mock_api/shared -v -n auto --junitxml={tox_root}/test-results/{envname}.xml {posargs} [testenv:unittest] description = Run unit tests for pygen internals @@ -57,7 +57,7 @@ deps = -e {tox_root}/../generator commands = python {tox_root}/install_packages.py unbranded {tox_root} - pytest unit/ -v -n auto {posargs} + pytest unit/ -v -n auto --junitxml={tox_root}/test-results/{envname}.xml {posargs} # ============================================================================= # Lint, type checking, and static analysis environments From d16670b610f91ab181607fc8d7106a5b79c220cd Mon Sep 17 00:00:00 2001 From: alzimmermsft <48699787+alzimmermsft@users.noreply.github.com> Date: Thu, 29 Oct 2026 14:39:00 -0400 Subject: [PATCH 3/5] Clean up transfer progress in Java --- .../CiCachingAndTestPublishing-2026-9-29-14-33-2.md | 7 +++++++ packages/http-client-java/eng/scripts/Build-Packages.ps1 | 2 +- .../http-client-generator-clientcore-test/Generate.ps1 | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .chronus/changes/CiCachingAndTestPublishing-2026-9-29-14-33-2.md diff --git a/.chronus/changes/CiCachingAndTestPublishing-2026-9-29-14-33-2.md b/.chronus/changes/CiCachingAndTestPublishing-2026-9-29-14-33-2.md new file mode 100644 index 00000000000..19aba689d6e --- /dev/null +++ b/.chronus/changes/CiCachingAndTestPublishing-2026-9-29-14-33-2.md @@ -0,0 +1,7 @@ +--- +changeKind: internal +packages: + - "@typespec/http-client-java" +--- + +Suppress Maven transfer progress during Java CI formatting checks and smoke-project builds while retaining normal build logs. \ No newline at end of file diff --git a/packages/http-client-java/eng/scripts/Build-Packages.ps1 b/packages/http-client-java/eng/scripts/Build-Packages.ps1 index 1a2e3172bf2..96ffcfb2617 100644 --- a/packages/http-client-java/eng/scripts/Build-Packages.ps1 +++ b/packages/http-client-java/eng/scripts/Build-Packages.ps1 @@ -61,7 +61,7 @@ try { Invoke-LoggedCommand "mvn -version" # check code format, before package - Invoke-LoggedCommand "mvn spotless:check --activate-profiles test" + Invoke-LoggedCommand "mvn spotless:check --no-transfer-progress --activate-profiles test" Invoke-LoggedCommand "mvn clean install --no-transfer-progress -T 1C -f ./pom.xml" } diff --git a/packages/http-client-java/generator/http-client-generator-clientcore-test/Generate.ps1 b/packages/http-client-java/generator/http-client-generator-clientcore-test/Generate.ps1 index 3782432f6bf..ec1cd24bc89 100644 --- a/packages/http-client-java/generator/http-client-generator-clientcore-test/Generate.ps1 +++ b/packages/http-client-java/generator/http-client-generator-clientcore-test/Generate.ps1 @@ -69,7 +69,7 @@ function Generate-Compile ($folder) { Push-Location $folder try { - mvn package + mvn package --no-transfer-progress if ($LASTEXITCODE -ne 0) { throw "Failed to compile smoke test of $folder" } From 01d1bb8feb006894485a0a9b2a91aca93136029e Mon Sep 17 00:00:00 2001 From: alzimmermsft <48699787+alzimmermsft@users.noreply.github.com> Date: Fri, 30 Oct 2026 13:44:31 -0400 Subject: [PATCH 4/5] PR feedback and CI fix --- .../templates/steps/maven-authenticate.yml | 18 +- eng/emitters/pipelines/emitter-ci.test.ts | 258 ------------------ 2 files changed, 17 insertions(+), 259 deletions(-) delete mode 100644 eng/emitters/pipelines/emitter-ci.test.ts diff --git a/eng/common/pipelines/templates/steps/maven-authenticate.yml b/eng/common/pipelines/templates/steps/maven-authenticate.yml index 9911c1aece5..53b314fae18 100644 --- a/eng/common/pipelines/templates/steps/maven-authenticate.yml +++ b/eng/common/pipelines/templates/steps/maven-authenticate.yml @@ -9,6 +9,22 @@ steps: New-Item -ItemType Directory -Force -Path $mavenRepositoryPath | Out-Null Write-Host "##vso[task.setvariable variable=MavenRepositoryPath]$mavenRepositoryPath" Copy-Item -Path "${{ parameters.SourceDirectory }}/eng/settings.xml" -Destination "$m2Dir/settings.xml" + + # Hash tracked POMs to avoid circular npm links and keep the cache key bounded. + $pomFiles = git -C "${{ parameters.SourceDirectory }}" ls-files -- "**/pom.xml" + if ($LASTEXITCODE -ne 0) { + throw "Failed to list tracked Maven POM files." + } + if (-not $pomFiles) { + throw "No tracked Maven POM files found." + } + $pomHashes = $pomFiles | ForEach-Object { + $path = Join-Path "${{ parameters.SourceDirectory }}" $_ + "$_=$((Get-FileHash -LiteralPath $path -Algorithm SHA256).Hash)" + } + $pomHashInput = [System.Text.Encoding]::UTF8.GetBytes($pomHashes -join "`n") + $pomHash = [Convert]::ToHexString([System.Security.Cryptography.SHA256]::HashData($pomHashInput)) + Write-Host "##vso[task.setvariable variable=MavenPomHash]$pomHash" displayName: "Setup Maven mirror settings" # Cache artifacts only; settings.xml contains feed credentials. @@ -16,7 +32,7 @@ steps: - task: Cache@2 displayName: "Cache Maven repository" inputs: - key: '"maven" | "$(Agent.OS)" | "$(System.StageName)" | ${{ parameters.SourceDirectory }}/**/pom.xml' + key: '"maven" | "$(Agent.OS)" | "$(System.StageName)" | "$(MavenPomHash)"' restoreKeys: | "maven" | "$(Agent.OS)" | "$(System.StageName)" "maven" | "$(Agent.OS)" diff --git a/eng/emitters/pipelines/emitter-ci.test.ts b/eng/emitters/pipelines/emitter-ci.test.ts deleted file mode 100644 index 55f24477933..00000000000 --- a/eng/emitters/pipelines/emitter-ci.test.ts +++ /dev/null @@ -1,258 +0,0 @@ -import { readFileSync } from "node:fs"; -import { runInNewContext } from "node:vm"; -import { describe, expect, it, vi } from "vitest"; -import { parse } from "yaml"; - -interface Step { - task?: string; - template?: string; - displayName?: string; - pwsh?: string; - condition?: string; - inputs?: Record; - [condition: `\${{ ${string} }}`]: Step[] | Step; -} - -function loadTemplate(path: string): { steps: Step[] } { - return parse(readFileSync(new URL(path, import.meta.url), "utf8")); -} - -function languageSteps(kind: string, language: string): Step[] { - const { steps } = loadTemplate(`./templates/steps/${kind}-step.yml`); - const condition: `\${{ ${string} }}` = `\${{ if eq(parameters.LanguageShortName, '${language}') }}`; - return steps.flatMap((step) => { - const branch = step[condition]; - return Array.isArray(branch) ? branch : [step]; - }); -} - -function publisherFor(kind: string, language: string, format: string): Step { - const publisher = languageSteps(kind, language).find( - (step) => step.task === "PublishTestResults@2" && step.inputs?.testResultsFormat === format, - ); - if (!publisher) { - throw new Error(`Missing ${format} publisher for ${language} ${kind} jobs.`); - } - return publisher; -} - -function shouldPublish(publisher: Step, language: string, args: string, outcome: string): boolean { - const branch = - publisher[ - language === "python" - ? "${{ if eq(parameters.LanguageShortName, 'python') }}" - : language === "java" - ? "${{ elseif eq(parameters.LanguageShortName, 'java') }}" - : "${{ else }}" - ]; - const condition = !Array.isArray(branch) ? (branch?.condition ?? publisher.condition) : undefined; - if (!condition) { - throw new Error("Missing test publishing condition."); - } - const result: unknown = runInNewContext( - condition - .replaceAll("${{ parameters.TestArgs }}", "$(TestArguments)") - .replaceAll("$(TestArguments)", args), - { - and: (...values: boolean[]) => values.every(Boolean), - or: (...values: boolean[]) => values.some(Boolean), - contains: (value: string, fragment: string) => - value.toLowerCase().includes(fragment.toLowerCase()), - succeededOrFailed: () => outcome === "succeeded" || outcome === "failed", - }, - ); - if (typeof result !== "boolean") { - throw new Error("Publishing conditions must evaluate to a boolean."); - } - return result; -} - -function readSource(path: string): string { - return readFileSync(new URL(`../../../packages/${path}`, import.meta.url), "utf8"); -} - -describe("Emitter CI", () => { - it("caches Maven dependencies by OS, stage, and POM contents", () => { - const { steps } = loadTemplate("../../common/pipelines/templates/steps/maven-authenticate.yml"); - const cache = steps.find((step) => step.task === "Cache@2"); - - expect(cache?.inputs).toMatchObject({ - key: '"maven" | "$(Agent.OS)" | "$(System.StageName)" | ${{ parameters.SourceDirectory }}/**/pom.xml', - restoreKeys: expect.stringContaining('"maven" | "$(Agent.OS)" | "$(System.StageName)"'), - path: "$(MavenRepositoryPath)", - }); - }); - - it("caches the default Maven repository without caching feed credentials", () => { - const { steps } = loadTemplate("../../common/pipelines/templates/steps/maven-authenticate.yml"); - - expect(steps[0].pwsh).toContain('Join-Path $m2Dir "repository"'); - expect(steps[0].pwsh).toContain( - "##vso[task.setvariable variable=MavenRepositoryPath]$mavenRepositoryPath", - ); - expect(steps.findIndex((step) => step.task === "Cache@2")).toBeGreaterThan(0); - }); - - it.each(["build", "test"])("initializes Maven caching in Java %s jobs", (kind) => { - const javaSteps = languageSteps(kind, "java"); - - expect(javaSteps).toContainEqual({ - template: "/eng/common/pipelines/templates/steps/maven-authenticate.yml", - }); - }); - - it("publishes generator results after Java build failures", () => { - const publisher = publisherFor("build", "java", "JUnit"); - expect(publisher).toMatchObject({ - condition: "succeededOrFailed()", - inputs: { - testResultsFormat: "JUnit", - searchFolder: "$(selfRepositoryPath)${{ parameters.PackagePath }}", - testResultsFiles: expect.stringContaining( - "generator/**/target/surefire-reports/TEST-*.xml", - ), - mergeTestResults: true, - failTaskOnFailedTests: true, - failTaskOnFailureToPublishResults: true, - failTaskOnMissingResultsFile: true, - }, - }); - }); - - it.each([ - ["java", "generator/**/target/surefire-reports/TEST-*.xml"], - ["csharp", "test-results.xml"], - ["python", "tests/test-results/*.xml"], - ])("collects JUnit results immediately after %s test scripts", (language, reports) => { - const publisher = publisherFor("test", language, "JUnit"); - expect(publisher.inputs).toMatchObject({ - testResultsFormat: "JUnit", - testResultsFiles: expect.stringContaining(reports), - searchFolder: "$(selfRepositoryPath)${{ parameters.PackagePath }}", - mergeTestResults: true, - failTaskOnFailedTests: true, - failTaskOnFailureToPublishResults: true, - failTaskOnMissingResultsFile: true, - }); - expect(publisher.inputs?.testResultsFiles).toContain("test-results.xml"); - - const steps = languageSteps("test", language); - const scriptIndex = steps.findIndex((step) => step.displayName === "Run test script"); - const publisherIndex = steps.findIndex( - (step) => step.task === "PublishTestResults@2" && step.inputs?.testResultsFormat === "JUnit", - ); - expect(scriptIndex).toBeGreaterThanOrEqual(0); - expect(publisherIndex).toBe(scriptIndex + 1); - }); - - it("selects the actual testing mode for each emitter", () => { - const { steps } = loadTemplate("./templates/steps/test-step.yml"); - const publisher = steps.find( - (step) => step.task === "PublishTestResults@2" && step.inputs?.testResultsFormat === "JUnit", - ); - expect(publisher).toMatchObject({ - "${{ if eq(parameters.LanguageShortName, 'python') }}": { - condition: - "and(succeededOrFailed(), contains('${{ parameters.TestArgs }}', '-GenerationChecks'))", - }, - "${{ elseif eq(parameters.LanguageShortName, 'java') }}": { - condition: - "and(succeededOrFailed(), or(contains('${{ parameters.TestArgs }}', '-UnitTests'), contains('${{ parameters.TestArgs }}', '-GenerationChecks')))", - }, - "${{ else }}": { - condition: "and(succeededOrFailed(), contains('${{ parameters.TestArgs }}', '-UnitTests'))", - }, - }); - }); - - it.each([ - { language: "java", args: "-UnitTests", expected: true }, - { language: "java", args: "-GenerationChecks", expected: true }, - { language: "csharp", args: "-UnitTests", expected: true }, - { language: "csharp", args: "-GenerationChecks", expected: false }, - { language: "python", args: "-UnitTests", expected: false }, - { language: "python", args: "-GenerationChecks", expected: true }, - ])( - "publishes only test-producing $language $args jobs, including failures", - ({ language, args, expected }) => { - const publisher = publisherFor("test", language, "JUnit"); - for (const outcome of ["succeeded", "failed", "canceled"]) { - expect(shouldPublish(publisher, language, args, outcome)).toBe( - outcome === "canceled" ? false : expected, - ); - } - }, - ); - - it("publishes C# generator and Spector TRX results after failures", () => { - const publisher = publisherFor("test", "csharp", "VSTest"); - expect(publisher).toMatchObject({ - condition: "and(succeededOrFailed(), contains('${{ parameters.TestArgs }}', '-UnitTests'))", - inputs: { - testResultsFormat: "VSTest", - testResultsFiles: "generator/**/TestResults/*.trx", - searchFolder: "$(selfRepositoryPath)${{ parameters.PackagePath }}", - mergeTestResults: true, - failTaskOnFailedTests: true, - failTaskOnFailureToPublishResults: true, - failTaskOnMissingResultsFile: true, - }, - }); - expect(shouldPublish(publisher, "csharp", "-UnitTests", "failed")).toBe(true); - expect(shouldPublish(publisher, "csharp", "-GenerationChecks", "succeeded")).toBe(false); - }); - - it("enables JUnit output for C# emitter tests", () => { - expect(readSource("http-client-csharp/eng/scripts/Test-Packages.ps1")).toContain( - "npm run test:emitter -- --reporter=default --reporter=junit", - ); - }); - - it("enables TRX output for both C# test invocations", () => { - expect(readSource("http-client-csharp/eng/scripts/Test-Packages.ps1")).toContain( - "dotnet test ./generator --logger trx", - ); - expect(readSource("http-client-csharp/eng/scripts/Get-Spector-Coverage.ps1")).toContain( - "dotnet test $spectorCsproj --logger trx", - ); - }); - - it.each([ - { tfBuild: "True", reporters: ["default", "junit"] }, - { tfBuild: undefined, reporters: undefined }, - ])("selects Python emitter reporters with TF_BUILD=$tfBuild", async ({ tfBuild, reporters }) => { - vi.stubEnv("TF_BUILD", tfBuild); - vi.resetModules(); - try { - const config: { test: { reporters?: unknown; outputFile?: unknown } } = ( - await import( - new URL("../../../packages/http-client-python/emitter/vitest.config.ts", import.meta.url) - .href - ) - ).default; - expect(config.test.reporters).toEqual(reporters); - expect(config.test.outputFile).toEqual({ junit: "./test-results.xml" }); - } finally { - vi.unstubAllEnvs(); - vi.resetModules(); - } - }); - - it("isolates pytest reports for parallel tox environments", () => { - const commands = readSource("http-client-python/tests/tox.ini") - .split(/\r?\n/) - .map((line) => line.trim()) - .filter((line) => line.startsWith("pytest ")); - expect(commands).toHaveLength(3); - for (const command of commands) { - expect(command).toContain("--junitxml={tox_root}/test-results/{envname}.xml"); - } - }); - - it("runs Java emitter tests with console and JUnit reporters", () => { - const script = readSource("http-client-java/eng/scripts/Test-Packages.ps1"); - - expect(script).toContain("npm run test:emitter"); - expect(script).toContain("-- --reporter=default --reporter=junit"); - }); -}); From 45765848b30ef9309219fe556703a5fdba3a1c80 Mon Sep 17 00:00:00 2001 From: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com> Date: Fri, 30 Oct 2026 15:40:06 -0400 Subject: [PATCH 5/5] Refactor conditions for test result publishing Updated conditions to use coalesce for TestArguments variable. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- eng/emitters/pipelines/templates/steps/test-step.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/emitters/pipelines/templates/steps/test-step.yml b/eng/emitters/pipelines/templates/steps/test-step.yml index 97446cea510..1bc5c6bc095 100644 --- a/eng/emitters/pipelines/templates/steps/test-step.yml +++ b/eng/emitters/pipelines/templates/steps/test-step.yml @@ -100,10 +100,10 @@ steps: - task: PublishTestResults@2 displayName: "Publish ${{ parameters.LanguageShortName }} test script results" ${{ if eq(parameters.LanguageShortName, 'python') }}: - condition: and(succeededOrFailed(), contains('${{ parameters.TestArgs }}', '-GenerationChecks')) + condition: and(succeededOrFailed(), contains(coalesce(variables['TestArguments'], '${{ parameters.TestArgs }}'), '-GenerationChecks')) ${{ elseif eq(parameters.LanguageShortName, 'java') }}: # Regeneration also rebuilds the Java generator and runs its Maven tests. - condition: and(succeededOrFailed(), or(contains('${{ parameters.TestArgs }}', '-UnitTests'), contains('${{ parameters.TestArgs }}', '-GenerationChecks'))) + condition: and(succeededOrFailed(), or(contains(coalesce(variables['TestArguments'], '${{ parameters.TestArgs }}'), '-UnitTests'), contains(coalesce(variables['TestArguments'], '${{ parameters.TestArgs }}'), '-GenerationChecks'))) ${{ else }}: condition: and(succeededOrFailed(), contains('${{ parameters.TestArgs }}', '-UnitTests')) inputs: