Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

display CI Conductor link for failing tests (#79601)

Chris Vandoodewaard7abb55964b24
diff --git a/release/ci-conductor/src/quarantine.test.ts b/release/ci-conductor/src/quarantine.test.ts
index e24b5e045e9..a4dea25eba6 100644
--- a/release/ci-conductor/src/quarantine.test.ts
+++ b/release/ci-conductor/src/quarantine.test.ts
@@ -12,6 +12,7 @@ import {
matchKey,
quarantinedSuiteGlob,
suiteMatchesGlob,
+ testSearchUrl,
} from "./quarantine.ts";
const failed = (
@@ -24,7 +25,14 @@ const quarantined = (
test_name: string,
test_path = "Suite",
file_path = "e2e/test/foo.cy.spec.ts",
-): QuarantineEntry => ({ test_name, test_path, file_path, test_suite: "e2e" });
+ permalink = `https://conductor.example.com/tests/${test_name}`,
+): QuarantineEntry => ({
+ test_name,
+ test_path,
+ file_path,
+ permalink,
+ test_suite: "e2e",
+});
describe("compareFailedToQuarantine", () => {
it("puts every failure in `unquarantined` when nothing is quarantined", () => {
@@ -39,32 +47,44 @@ describe("compareFailedToQuarantine", () => {
expect(unquarantined).toEqual(failures);
});
- it("puts every failure in `quarantined` when all are listed", () => {
- const failures = [failed("a"), failed("b")];
+ it("puts every failure in `quarantined` when all are listed, as list entries", () => {
+ const entries = [quarantined("a"), quarantined("b")];
const { quarantined: q, unquarantined } = compareFailedToQuarantine(
- failures,
- [quarantined("a"), quarantined("b")],
+ [failed("a"), failed("b")],
+ entries,
);
- expect(q).toEqual(failures);
+ expect(q).toEqual(entries);
expect(unquarantined).toEqual([]);
});
it("partitions a mixed set", () => {
- const a = failed("a");
const b = failed("b");
- const c = failed("c");
+ const entryA = quarantined("a");
+ const entryC = quarantined("c");
const { quarantined: q, unquarantined } = compareFailedToQuarantine(
- [a, b, c],
- [quarantined("a"), quarantined("c")],
+ [failed("a"), b, failed("c")],
+ [entryA, entryC],
);
- expect(q).toEqual([a, c]);
+ expect(q).toEqual([entryA, entryC]);
expect(unquarantined).toEqual([b]);
});
+ it("returns matches in the order the failures came in", () => {
+ const entryA = quarantined("a");
+ const entryB = quarantined("b");
+
+ const { quarantined: q } = compareFailedToQuarantine(
+ [failed("b"), failed("a")],
+ [entryA, entryB],
+ );
+
+ expect(q).toEqual([entryB, entryA]);
+ });
+
it("returns two empty buckets for no failures", () => {
expect(compareFailedToQuarantine([], [quarantined("a")])).toEqual({
quarantined: [],
@@ -95,14 +115,14 @@ describe("compareFailedToQuarantine", () => {
});
it("treats a null path on the failure as an empty string for matching", () => {
- const failure = failed("a", null, null);
+ const entry = quarantined("a", "", "");
const { quarantined: q } = compareFailedToQuarantine(
- [failure],
- [quarantined("a", "", "")],
+ [failed("a", null, null)],
+ [entry],
);
- expect(q).toEqual([failure]);
+ expect(q).toEqual([entry]);
});
});
@@ -121,6 +141,42 @@ describe("matchKey", () => {
});
});
+describe("testSearchUrl", () => {
+ const base = "https://conductor.coredev.metabase.com";
+
+ it("searches the full `test_path › test_name` title", () => {
+ expect(
+ testSearchUrl(
+ base,
+ failed(
+ "should be able to view and revert document revisions",
+ "documents › revision history",
+ ),
+ ),
+ ).toBe(
+ "https://conductor.coredev.metabase.com/tests?q=should+be+able+to+view+and+revert+document+revisions",
+ );
+ });
+
+ it("takes a quarantine entry just as happily as a failure", () => {
+ expect(testSearchUrl(base, quarantined("a test", "Suite"))).toBe(
+ `${base}/tests?q=a+test`,
+ );
+ });
+
+ it("trims a trailing slash off the base url", () => {
+ expect(testSearchUrl(`${base}//`, failed("a test", null))).toBe(
+ `${base}/tests?q=a+test`,
+ );
+ });
+
+ it("escapes characters that would otherwise break out of the query string", () => {
+ expect(testSearchUrl(base, failed(`#1 "a" & b`, null))).toBe(
+ `${base}/tests?q=%231+%22a%22+%26+b`,
+ );
+ });
+});
+
describe("junitFailuresToFailedTests", () => {
it("renames name/path/file to the gate's identity fields", () => {
const tests: NormalizedTest[] = [
diff --git a/release/ci-conductor/src/quarantine.ts b/release/ci-conductor/src/quarantine.ts
index 38b2509601e..9ecea5b6945 100644
--- a/release/ci-conductor/src/quarantine.ts
+++ b/release/ci-conductor/src/quarantine.ts
@@ -21,6 +21,7 @@ export type QuarantineEntry = {
test_suite: string;
test_path: string;
file_path: string;
+ permalink: string;
};
/**
@@ -77,27 +78,27 @@ export function matchKey(opts: {
export function compareFailedToQuarantine(
failedTests: FailedTest[],
quarantineEntries: QuarantineEntry[],
-): { quarantined: FailedTest[]; unquarantined: FailedTest[] } {
- const quarantinedKeys = new Set(
+): { quarantined: QuarantineEntry[]; unquarantined: FailedTest[] } {
+ const quarantinedByKeys = new Map(
quarantineEntries.map((q) =>
- matchKey({
+ [matchKey({
filePath: q.file_path,
testPath: q.test_path,
testName: q.test_name,
- }),
+ }), q],
),
);
- const quarantined: FailedTest[] = [];
+ const quarantined: QuarantineEntry[] = [];
const unquarantined: FailedTest[] = [];
for (const test of failedTests) {
- const isQuarantined = quarantinedKeys.has(
+ const quarantineEntry = quarantinedByKeys.get(
matchKey({
filePath: test.file_path,
testPath: test.test_path,
testName: test.test_name,
}),
);
- (isQuarantined ? quarantined : unquarantined).push(test);
+ quarantineEntry ? quarantined.push(quarantineEntry) : unquarantined.push(test);
}
return { quarantined, unquarantined };
}
@@ -244,6 +245,18 @@ function title(test: FailedTest): string {
return test.test_path ? `${test.test_path} › ${test.test_name}` : test.test_name;
}
+/**
+ * Fallback to building a search link for a given test if we don't have a permalink,
+ * expected if this test isn't on the quarantine list. Properly escape all the special
+ * characters.
+ */
+export function testSearchUrl(
+ baseUrl: string,
+ test: FailedTest | QuarantineEntry,
+): string {
+ return `${baseUrl.replace(/\/+$/, "")}/tests?${new URLSearchParams({ q: test.test_name })}`;
+}
+
/** Print the verdict (+ dry-run footer) and return the gate result. */
function finish(opts: {
shouldFail: boolean;
@@ -346,10 +359,16 @@ export async function checkQuarantineGate(opts: {
for (const test of quarantined) {
log(` 🔒 quarantined ${title(test)}`);
log(` ↳ ${test.file_path ?? "(no file)"}`);
+ log(
+ ` ↳ View test in CI Conductor: ${test.permalink || testSearchUrl(baseUrl, test)}`,
+ );
}
for (const test of unquarantined) {
log(` 🚨 NOT quarantined ${title(test)}`);
- log(` ↳ ${test.file_path ?? "(no file)"}`);
+ log(` ↳ ${test.file_path ?? "(no file)"}`);
+ log(
+ ` ↳ View test in CI Conductor: ${testSearchUrl(baseUrl, test)}`,
+ );
}
return finish({