From 0780b8f432fb8cfc3f578d875c640656a4c2d189 Mon Sep 17 00:00:00 2001 From: Justin Halsall Date: Fri, 13 Nov 2026 09:03:15 +0100 Subject: [PATCH 1/2] fix(source-control-entire): preserve descriptions and gate failures --- .../src/server/entireTrailBody.test.ts | 26 +++++++++++++++++++ .../src/server/entireTrailBody.ts | 8 ++++-- .../src/server/entireTrailJson.test.ts | 23 ++++++++++++++++ .../src/server/entireTrailJson.ts | 3 ++- 4 files changed, 57 insertions(+), 3 deletions(-) diff --git a/packages/source-control-entire/src/server/entireTrailBody.test.ts b/packages/source-control-entire/src/server/entireTrailBody.test.ts index 64b2b27006cbc..c80561f8f32d5 100644 --- a/packages/source-control-entire/src/server/entireTrailBody.test.ts +++ b/packages/source-control-entire/src/server/entireTrailBody.test.ts @@ -222,6 +222,32 @@ describe("trailBodyMarkdown", () => { expect(unrenderedContent({ text_snapshot: "Plain" })).toBeNull(); }); + it.each(["inline", "fenced", "later paragraph"])( + "preserves literal self-link markers in %s content", + (kind) => { + const literal = " example "; + const markdown = + kind === "inline" + ? `\`${literal}\`` + : kind === "fenced" + ? `\`\`\`\n${literal}\n\`\`\`` + : `Example\n\n${literal}`; + const content = + kind === "inline" + ? [paragraph(text(literal, [{ type: "code" }]))] + : kind === "fenced" + ? [{ type: "codeBlock", content: [text(literal)] }] + : [paragraph(text("Example")), paragraph(text(literal))]; + for (const document of [ + { text_snapshot: markdown }, + { text_snapshot: "", content_json: { type: "doc", content } }, + ]) { + expect(trailBodyMarkdown(document)).toBe(markdown); + expect(unrenderedContent(document)).toBeNull(); + } + }, + ); + it("falls back to the snapshot without the trail self-link", () => { expect( trailBodyMarkdown({ diff --git a/packages/source-control-entire/src/server/entireTrailBody.ts b/packages/source-control-entire/src/server/entireTrailBody.ts index f425528c07e34..fb470012c1815 100644 --- a/packages/source-control-entire/src/server/entireTrailBody.ts +++ b/packages/source-control-entire/src/server/entireTrailBody.ts @@ -16,7 +16,7 @@ interface ProseMirrorNode { /** Entire's self-link at the top of a trail body is noise inside the trail itself. */ const TRAIL_LINK = - /[\s\S]*?/gu; + /^\s*[\s\S]*?/u; const isNode = (value: unknown): value is ProseMirrorNode => typeof value === "object" && value !== null && !Array.isArray(value); @@ -43,7 +43,11 @@ const longestBacktickRun = (text: string) => * stays as typed, as does `_` inside a word; a partner in a neighbouring node is not looked for. */ function escapeText(text: string): string { - const paired = (char: string) => text.split(char).length > 2; + const counts = new Map(); + for (const char of text.match(/[`*~_]/gu) ?? []) { + counts.set(char, (counts.get(char) ?? 0) + 1); + } + const paired = (char: string) => (counts.get(char) ?? 0) > 1; return text .replace(/\\(?=[!-/:-@[-`{-~])/gu, "\\\\") .replace(/[`*~]/gu, (char) => (paired(char) ? `\\${char}` : char)) diff --git a/packages/source-control-entire/src/server/entireTrailJson.test.ts b/packages/source-control-entire/src/server/entireTrailJson.test.ts index cabe7dfd4f9d9..63ff014c700d7 100644 --- a/packages/source-control-entire/src/server/entireTrailJson.test.ts +++ b/packages/source-control-entire/src/server/entireTrailJson.test.ts @@ -174,6 +174,28 @@ describe("entireTrailJson", () => { ), [], ); + for (const status of ["failed", "pending", "passed"]) { + const gated = decodeDetail({ + ...Fixtures.detail, + mergeability: { + ...Fixtures.detail.mergeability, + gates: [{ gate_type: "checks", gate_key: "checks", status, blocking: true }], + checks: { + ...Fixtures.detail.mergeability.checks, + runs: [Fixtures.detail.mergeability.checks.runs[0]], + }, + }, + }); + const expected = + status === "failed" ? "failing" : status === "passed" ? "passing" : "pending"; + const gatedChecks = Json.toChecks(gated, "gh/acme/web"); + assert.strictEqual(Json.toChecksState(gatedChecks), expected); + assert.strictEqual(Json.toSummaryChecksState(gated, "gh/acme/web"), expected); + assert.strictEqual( + gatedChecks.some((check) => check.name === "Entire: checks"), + status !== "passed", + ); + } assert.strictEqual(Json.headSha(detail), Fixtures.HEAD_SHA); const permissions = Json.toViewerPermissions(detail, "gh/acme/web"); assert.deepStrictEqual(permissions.actions, ["draft", "close", "merge"]); @@ -270,6 +292,7 @@ describe("entireTrailJson", () => { checks.map((check) => [check.name, check.status, check.description]), [ ["Entire: findings", "failure", "Unresolved findings: 1 without a severity"], + ["Entire: checks", "failure", "lint is failing"], ["build", "success", "Buildkite"], ["lint", "pending", null], ["Entire: up_to_date", "success", null], diff --git a/packages/source-control-entire/src/server/entireTrailJson.ts b/packages/source-control-entire/src/server/entireTrailJson.ts index 22fbd775ec61b..5b35bf7799a22 100644 --- a/packages/source-control-entire/src/server/entireTrailJson.ts +++ b/packages/source-control-entire/src/server/entireTrailJson.ts @@ -426,7 +426,8 @@ function gateChecks( return blockingGates(detail) .filter( (gate) => - gate.gate_type !== "approvals" && (gate.gate_type !== "checks" || !runsRead(detail)), + gate.gate_type !== "approvals" && + (gate.gate_type !== "checks" || !runsRead(detail) || gate.status !== "passed"), ) .map((gate) => ({ name: `Entire: ${gate.gate_key}`, From 49872ea18cab3447384c12db0ac05eafea673b86 Mon Sep 17 00:00:00 2001 From: Justin Halsall Date: Fri, 13 Nov 2026 13:03:50 +0100 Subject: [PATCH 2/2] test(source-control-entire): cover errored checks gates --- .../source-control-entire/src/server/entireFixtures.ts | 2 +- .../src/server/entireTrailJson.test.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/source-control-entire/src/server/entireFixtures.ts b/packages/source-control-entire/src/server/entireFixtures.ts index c8feb01525aea..2c0664dd3755e 100644 --- a/packages/source-control-entire/src/server/entireFixtures.ts +++ b/packages/source-control-entire/src/server/entireFixtures.ts @@ -104,7 +104,7 @@ export const blocked = { gates: [ gate("approvals", "failed", "Needs 1 approval"), gate("findings", "failed", "Unresolved findings: 1 without a severity"), - // CI is reported as its own runs; the gate that rolls them up is not shown again. + // CI runs replace a passing checks gate; a non-passing blocking gate is still reported. gate("checks", "failed", "lint is failing"), gate("up_to_date", "passed"), gate("base_checks", "pending"), diff --git a/packages/source-control-entire/src/server/entireTrailJson.test.ts b/packages/source-control-entire/src/server/entireTrailJson.test.ts index 63ff014c700d7..a738ba2df1024 100644 --- a/packages/source-control-entire/src/server/entireTrailJson.test.ts +++ b/packages/source-control-entire/src/server/entireTrailJson.test.ts @@ -174,7 +174,7 @@ describe("entireTrailJson", () => { ), [], ); - for (const status of ["failed", "pending", "passed"]) { + for (const status of ["failed", "error", "pending", "passed"]) { const gated = decodeDetail({ ...Fixtures.detail, mergeability: { @@ -187,7 +187,11 @@ describe("entireTrailJson", () => { }, }); const expected = - status === "failed" ? "failing" : status === "passed" ? "passing" : "pending"; + status === "failed" || status === "error" + ? "failing" + : status === "passed" + ? "passing" + : "pending"; const gatedChecks = Json.toChecks(gated, "gh/acme/web"); assert.strictEqual(Json.toChecksState(gatedChecks), expected); assert.strictEqual(Json.toSummaryChecksState(gated, "gh/acme/web"), expected);