Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
format
  • Loading branch information
danieljurek committed Jul 23, 2025
commit 10b25628b829f305fb87f0f7615cbe49d38b3d17
10 changes: 5 additions & 5 deletions eng/tools/lint-diff/src/generateReport.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { writeFile } from "node:fs/promises";
import { relative } from "node:path";
import { kebabCase } from "change-case";
Expand Down Expand Up @@ -49,8 +49,8 @@

outputMarkdown += `\n\n`;

for(const [, {before,}] of runCorrelations.entries()) {
if (before && before.error) {
for (const [, { before }] of runCorrelations.entries()) {
if (before && before.error) {
outputMarkdown += `> [!WARNING]\n`;
outputMarkdown += `> Autorest failed checking before state of ${relative(before.rootPath, before.readme.path)} ${before.tag}\n\n`;
}
Expand Down Expand Up @@ -286,9 +286,9 @@
return tag ? `${readmePathRelative}#tag-${tag}` : readmePathRelative;
}

export function getAutoRestFailedMessage(result: AutorestRunResult | null) : string {
if (result?.error) {
export function getAutoRestFailedMessage(result: AutorestRunResult | null): string {
if (result?.error) {
return "Autorest Failed";
}
return "";
}
}
88 changes: 45 additions & 43 deletions eng/tools/lint-diff/test/generateReport.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { beforeEach, test, describe, expect, vi } from "vitest";
import {
compareLintDiffViolations,
Expand Down Expand Up @@ -496,50 +496,52 @@
`);
});

test.skipIf(isWindows())("passes and displays warning if before has errors", async ({ expect }) => {
const afterViolation = {
extensionName: "@microsoft.azure/openapi-validator",
level: "warning",
code: "SomeCode",
message: "A warning occurred",
source: [],
details: {},
};
test.skipIf(isWindows())(
"passes and displays warning if before has errors",
async ({ expect }) => {
const afterViolation = {
extensionName: "@microsoft.azure/openapi-validator",
level: "warning",
code: "SomeCode",
message: "A warning occurred",
source: [],
details: {},
};

const beforeResult = {
error: new Error("Autorest failed"),
stdout: "",
stderr: "",
rootPath: "",
readme: new Readme("file1.md"),
tag: "",
} as AutorestRunResult;
const afterResult = {
error: null,
stdout: JSON.stringify(afterViolation),
stderr: "",
rootPath: "",
readme: new Readme("file1.md"),
tag: "",
} as AutorestRunResult;
const beforeResult = {
error: new Error("Autorest failed"),
stdout: "",
stderr: "",
rootPath: "",
readme: new Readme("file1.md"),
tag: "",
} as AutorestRunResult;
const afterResult = {
error: null,
stdout: JSON.stringify(afterViolation),
stderr: "",
rootPath: "",
readme: new Readme("file1.md"),
tag: "",
} as AutorestRunResult;

const runCorrelations = new Map<string, BeforeAfter>([
["file1.md", { before: beforeResult, after: afterResult }],
]);
const runCorrelations = new Map<string, BeforeAfter>([
["file1.md", { before: beforeResult, after: afterResult }],
]);

const outFile = "test-output-fatal.md";
const actual = await generateLintDiffReport(
runCorrelations,
new Set<string>([
"specification/contosowidgetmanager/data-plane/Azure.Contoso.WidgetManager/stable/2022-12-01/widgets.json",
]),
outFile,
"baseBranch",
"compareSha",
"repo/path",
);
expect(actual).toBe(true);
expect(await readFile(outFile, { encoding: "utf-8" })).toMatchInlineSnapshot(`
const outFile = "test-output-fatal.md";
const actual = await generateLintDiffReport(
runCorrelations,
new Set<string>([
"specification/contosowidgetmanager/data-plane/Azure.Contoso.WidgetManager/stable/2022-12-01/widgets.json",
]),
outFile,
"baseBranch",
"compareSha",
"repo/path",
);
expect(actual).toBe(true);
expect(await readFile(outFile, { encoding: "utf-8" })).toMatchInlineSnapshot(`
"| Compared specs ([v1.0.0](https://www.npmjs.com/package/@microsoft.azure/openapi-validator/v/1.0.0)) | new version | base version |
| --- | --- | --- |
| default | [default](https://github.com/repo/path/blob/compareSha/file1.md) | [default](https://github.com/repo/path/blob/baseBranch/file1.md) Autorest Failed|
Expand All @@ -550,7 +552,8 @@

"
`);
});
},
);

test.skipIf(isWindows())(
"passes if new violations do not include an error (warnings only)",
Expand Down Expand Up @@ -687,4 +690,3 @@
`);
});
});

Loading