From b9bcfa4041d01746534974dbb4c8658920906a7a Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Fri, 20 Nov 2026 07:56:09 -0500 Subject: [PATCH] test(ci): consolidate NativeAOT verifier restore and publish checks (#12815) test(evaluation): consolidate NativeAOT retry verification --- .../evaluation/package/nativeAotBuild.test.ts | 82 +++++++++---------- 1 file changed, 40 insertions(+), 42 deletions(-) diff --git a/tests/evaluation/package/nativeAotBuild.test.ts b/tests/evaluation/package/nativeAotBuild.test.ts index cfd36c8942..68136aa1f4 100644 --- a/tests/evaluation/package/nativeAotBuild.test.ts +++ b/tests/evaluation/package/nativeAotBuild.test.ts @@ -5,84 +5,82 @@ import { expect, it, vi } from "vitest"; import { buildNativeAotFixture } from "../../../scripts/lib/nativeaot-build.mjs"; const options = { - dotnet: "dotnet", + dotnet: "fixture-dotnet", project: "fixture.csproj", runtime: "win-x64", output: "fixture-output", }; +type Run = Parameters[0]; -it("restores the exact publish target before compiling without network restore", async () => { - const run = vi.fn<(command: string, args: string[]) => void>(); - await buildNativeAotFixture(run, options); - expect(run).toHaveBeenCalledTimes(2); - const restore = run.mock.calls[0]?.[1] ?? []; - const publish = run.mock.calls[1]?.[1] ?? []; - expect(restore[0]).toBe("restore"); - expect(publish[0]).toBe("publish"); - expect(publish).toContain("--no-restore"); - for (const argument of [ - options.project, - options.runtime, - "-p:Configuration=Release", - `-p:BaseIntermediateOutputPath=${join(options.output, "obj")}/`, - ]) { - expect(restore).toContain(argument); - expect(publish).toContain(argument); - } -}); - -it("retries without logging credential-bearing restore diagnostics", async () => { +it("retries the publish target's restore without logging credentials and publishes without restoring again", async () => { const logged = vi.spyOn(console, "error").mockImplementation(() => {}); const timeout = Object.assign( new Error( "dotnet restore ETIMEDOUT https://fixture-user:fixture-password@feed.invalid/v3/index.json", ), - { - code: "ETIMEDOUT", - }, + { code: "ETIMEDOUT" }, ); - const run = vi - .fn<(command: string, args: string[]) => void>() - .mockImplementationOnce(() => { - throw timeout; - }); + const run = vi.fn().mockImplementationOnce(() => { + throw timeout; + }); try { await buildNativeAotFixture(run, options); const output = logged.mock.calls.flat(); expect(logged).toHaveBeenCalledWith(expect.stringContaining("attempt 2/2")); expect(output.every((value) => typeof value === "string")).toBe(true); - expect(output.join("\n")).not.toContain("fixture-password"); + expect(output.join("\n")).not.toMatch(/fixture-(?:user|password)/u); } finally { logged.mockRestore(); } - expect(run.mock.calls.map((call) => call[1][0])).toEqual([ - "restore", - "restore", - "publish", + expect( + run.mock.calls.map(([command, [operation]]) => [command, operation]), + ).toEqual([ + [options.dotnet, "restore"], + [options.dotnet, "restore"], + [options.dotnet, "publish"], ]); + const [restore, retry, publish] = run.mock.calls.map(([, args]) => args); + const target = [ + options.project, + options.runtime, + "-p:Configuration=Release", + `-p:BaseIntermediateOutputPath=${join(options.output, "obj")}/`, + ]; + expect(restore).toEqual(expect.arrayContaining(target)); + expect(retry).toEqual(restore); + expect(publish).toEqual(expect.arrayContaining([...target, "--no-restore"])); }); it("stops after two restore failures and preserves the final diagnostic", async () => { const failure = new Error("NuGet source unavailable"); - const run = vi.fn<(command: string, args: string[]) => void>(() => { - throw failure; - }); + const run = vi + .fn(() => { + throw failure; + }) + .mockImplementationOnce(() => { + throw new Error("Initial restore timeout"); + }); await expect(buildNativeAotFixture(run, options)).rejects.toMatchObject({ message: "NativeAOT dependency restore failed after two attempts", cause: failure, }); - expect(run).toHaveBeenCalledTimes(2); - expect(run.mock.calls.every((call) => call[1][0] === "restore")).toBe(true); + expect(run.mock.calls.map(([, [operation]]) => operation)).toEqual([ + "restore", + "restore", + ]); }); it("does not retry compilation failures", async () => { const failure = new Error("Native compiler rejected the fixture"); const run = vi - .fn<(command: string, args: string[]) => void>() + .fn() .mockImplementationOnce(() => {}) .mockImplementationOnce(() => { throw failure; }); await expect(buildNativeAotFixture(run, options)).rejects.toBe(failure); - expect(run).toHaveBeenCalledTimes(2); + expect(run.mock.calls.map(([, [operation]]) => operation)).toEqual([ + "restore", + "publish", + ]); });