mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 14:05:49 +00:00
test(ci): consolidate NativeAOT verifier restore and publish checks (#12815)
test(evaluation): consolidate NativeAOT retry verification
This commit is contained in:
1 parent
766fb9e78e
commit
b9bcfa4041
1 file changed
+40
-42
@@ -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<typeof buildNativeAotFixture>[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<Run>().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<Run>(() => {
|
||||
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<Run>()
|
||||
.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",
|
||||
]);
|
||||
});
|
||||
Reference in new issue
Block a user