import * as fixtureGit from "./support/release-freshness-git.ts"; import { changeset, generatedRelease } from "./support/release-freshness-text.ts"; import assert from "node:assert/strict"; import { execFile } from "node:child_process"; import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import { dirname, join } from "node:path"; import { createRequire } from "node:module"; import test from "node:test"; import { promisify } from "node:util"; import { releasePullRequestFreshnessViolations } from "../scripts/check-release-pr-freshness.mjs"; import { registerReleaseSectionCases } from "./support/release-section-cases.ts"; const execFileAsync = promisify(execFile); const { git, commitRelease, amendFixtureIdentity } = fixtureGit; const packageName = "@agent-teams/engineering-foundation"; const docsPackageName = "@agent-teams/docs-protocol"; const require = createRequire(import.meta.url); const changesetBin = join(dirname(require.resolve("@changesets/cli/package.json")), "bin.js"); registerReleaseSectionCases(packageName, docsPackageName); async function createFixture( summary = "Alpha package change.", { version = "1.0.0", releaseType = "minor" } = {}, ) { const root = await mkdtemp(join(tmpdir(), "foundation-release-freshness-")); await mkdir(join(root, ".changeset"), { recursive: true }); await writeFile( join(root, "package.json"), JSON.stringify({ name: "foundation-freshness-TEST", private: true, version: "0.0.0", workspaces: ["packages/*"], }), ); await writeFile( join(root, ".changeset/config.json"), JSON.stringify({ changelog: "@changesets/cli/changelog", commit: false, fixed: [], access: "public", baseBranch: "main", updateInternalDependencies: "patch", ignore: [], privatePackages: { version: true, tag: false }, }), ); await mkdir(join(root, "packages", "engineering-foundation"), { recursive: true }); await writeFile( join(root, "packages", "engineering-foundation", "package.json"), JSON.stringify({ name: packageName, version }), ); await writeFile( join(root, "packages", "engineering-foundation", "CHANGELOG.md"), "# " + packageName + "\n\n## 1.0.0\n", ); await writeFile(join(root, ".changeset", "alpha.md"), changeset(summary, releaseType)); await git(root, "init", "-b", "main"); await git(root, "config", "core.autocrlf", "false"); await git(root, "config", "user.name", "Foundation Test"); await git(root, "config", "user.email", "foundation-test@example.invalid"); await git(root, "add", "."); await git(root, "commit", "-m", "main A"); return { root, mainA: await git(root, "rev-parse", "HEAD") }; } async function createMultiPackageFixture() { const fixture = await createFixture(); await git(fixture.root, "checkout", "--detach", fixture.mainA); await mkdir(join(fixture.root, "packages", "docs-protocol"), { recursive: true }); await writeFile( join(fixture.root, "packages", "docs-protocol", "package.json"), JSON.stringify({ name: docsPackageName, version: "1.0.0" }), ); await writeFile( join(fixture.root, "packages", "docs-protocol", "CHANGELOG.md"), "# " + docsPackageName + "\n\n## 1.0.0\n", ); await writeFile( join(fixture.root, ".changeset", "alpha.md"), '---\n"' + packageName + '": minor\n"' + docsPackageName + '": minor\n---\n\nUnified protocol.\n', ); await git(fixture.root, "add", "."); await git(fixture.root, "commit", "-m", "add docs protocol package"); return { ...fixture, mainA: await git(fixture.root, "rev-parse", "HEAD") }; } async function createMultiPackageRelease(root, baseRevision) { await git(root, "checkout", "--detach", baseRevision); await rm(join(root, ".changeset", "alpha.md")); const foundation = generatedRelease("1.1.0", ["Unified protocol."]); const docs = generatedRelease("1.1.0", ["Unified protocol."]); await writeFile( join(root, "packages", "engineering-foundation", "package.json"), JSON.stringify({ name: packageName, version: "1.1.0" }), ); await writeFile( join(root, "packages", "engineering-foundation", "CHANGELOG.md"), foundation.changelog, ); await writeFile( join(root, "packages", "docs-protocol", "package.json"), JSON.stringify({ name: docsPackageName, version: "1.1.0" }), ); await writeFile( join(root, "packages", "docs-protocol", "CHANGELOG.md"), docs.changelog.replace("# " + packageName, "# " + docsPackageName), ); await git(root, "add", "."); await commitRelease(root, "-m", "release packages"); return { body: "Generated by Changesets.\n\n# Releases\n" + foundation.body.slice(foundation.body.indexOf("## ")) + "\n\n" + docs.body .slice(docs.body.indexOf("## ")) .replace(packageName + "@1.1.0", docsPackageName + "@1.1.0"), head: await git(root, "rev-parse", "HEAD"), }; } async function createRelease( root, baseRevision, version, summaries, { prereleaseChangesets = [], generated = generatedRelease(version, summaries) } = {}, ) { await git(root, "checkout", "--detach", baseRevision); for (const id of ["alpha", "beta"]) { if (!prereleaseChangesets.includes(id)) { await rm(join(root, ".changeset", id + ".md"), { force: true }); } } if (prereleaseChangesets.length > 0) { await writeFile( join(root, ".changeset", "pre.json"), JSON.stringify({ ...JSON.parse(await readFile(join(root, ".changeset/pre.json"), "utf8")), changesets: prereleaseChangesets, }), ); } await writeFile( join(root, "packages", "engineering-foundation", "package.json"), JSON.stringify({ name: packageName, version }), ); await writeFile( join(root, "packages", "engineering-foundation", "CHANGELOG.md"), generated.changelog, ); await git(root, "add", "."); await commitRelease(root, "-m", "release " + version); return { head: await git(root, "rev-parse", "HEAD"), body: generated.body }; } async function createPrereleaseExit(root, baseRevision, version, summary) { await git(root, "checkout", "--detach", baseRevision); await rm(join(root, ".changeset", "pre.json")); await rm(join(root, ".changeset", "alpha.md")); const baseChangelog = await git( root, "show", baseRevision + ":packages/engineering-foundation/CHANGELOG.md", ); const title = "# " + packageName + "\n\n"; const section = "## " + version + "\n\n### Minor Changes\n\n- " + summary; await writeFile( join(root, "packages", "engineering-foundation", "package.json"), JSON.stringify({ name: packageName, version }), ); await writeFile( join(root, "packages", "engineering-foundation", "CHANGELOG.md"), title + section + "\n\n" + baseChangelog.slice(title.length) + "\n", ); await git(root, "add", "."); await commitRelease(root, "-m", "exit prerelease"); return { head: await git(root, "rev-parse", "HEAD"), body: "# Releases\n" + section.replace("## " + version, "## " + packageName + "@" + version), }; } test("accepts Changesets prerelease consumption recorded in pre.json", async () => { const fixture = await createFixture(); try { await git(fixture.root, "checkout", "--detach", fixture.mainA); await writeFile( join(fixture.root, ".changeset", "pre.json"), JSON.stringify({ mode: "pre", tag: "rc", initialVersions: { [packageName]: "1.0.0" }, changesets: [], }), ); await git(fixture.root, "add", ".changeset/pre.json"); await git(fixture.root, "commit", "-m", "enter prerelease mode"); const prereleaseMain = await git(fixture.root, "rev-parse", "HEAD"); const release = await createRelease( fixture.root, prereleaseMain, "1.1.0-rc.0", ["Alpha package change."], { prereleaseChangesets: ["alpha"] }, ); assert.deepEqual( await violations(fixture.root, prereleaseMain, prereleaseMain, release, release.head), [], ); } finally { await rm(fixture.root, { recursive: true, force: true }); } }); test("accepts only an exact stable release when processed main exits prerelease", async () => { const fixture = await createFixture(); try { await git(fixture.root, "checkout", "--detach", fixture.mainA); await writeFile( join(fixture.root, ".changeset", "pre.json"), JSON.stringify({ mode: "exit", tag: "rc", initialVersions: { [packageName]: "1.0.0" }, changesets: ["alpha"], }), ); await writeFile( join(fixture.root, "packages", "engineering-foundation", "package.json"), JSON.stringify({ name: packageName, version: "1.1.0-rc.0" }), ); await writeFile( join(fixture.root, "packages", "engineering-foundation", "CHANGELOG.md"), "# " + packageName + "\n\n## 1.1.0-rc.0\n\nAlpha package change.\n\n## 1.0.0\n", ); await git(fixture.root, "add", "."); await git(fixture.root, "commit", "-m", "prepare prerelease exit"); const exitMain = await git(fixture.root, "rev-parse", "HEAD"); const release = await createPrereleaseExit( fixture.root, exitMain, "1.1.0", "Alpha package change.", ); assert.deepEqual(await violations(fixture.root, exitMain, exitMain, release, release.head), []); const wrongVersion = await createPrereleaseExit( fixture.root, exitMain, "1.1.1", "Alpha package change.", ); assert.match( (await violations(fixture.root, exitMain, exitMain, wrongVersion, wrongVersion.head)).join( "\n", ), /plan.version-mismatch|exact stable version/u, ); } finally { await rm(fixture.root, { recursive: true, force: true }); } }); test("accepts exact generated sections for the promoted public package catalog", async () => { const fixture = await createMultiPackageFixture(); try { const release = await createMultiPackageRelease(fixture.root, fixture.mainA); assert.deepEqual( await violations(fixture.root, fixture.mainA, fixture.mainA, release, release.head), [], ); } finally { await rm(fixture.root, { recursive: true, force: true }); } }); test("rejects deleting active prerelease state before exit", async () => { const fixture = await createFixture(); try { await git(fixture.root, "checkout", "--detach", fixture.mainA); await writeFile( join(fixture.root, ".changeset", "pre.json"), JSON.stringify({ mode: "pre", tag: "rc", initialVersions: { [packageName]: "1.0.0" }, changesets: [], }), ); await git(fixture.root, "add", "."); await git(fixture.root, "commit", "-m", "active prerelease"); const prereleaseMain = await git(fixture.root, "rev-parse", "HEAD"); const release = await createPrereleaseExit( fixture.root, prereleaseMain, "1.1.0", "Alpha package change.", ); assert.match( (await violations(fixture.root, prereleaseMain, prereleaseMain, release, release.head)).join( "\n", ), /must preserve active Changesets prerelease state/u, ); } finally { await rm(fixture.root, { recursive: true, force: true }); } }); test("prerelease exit leaves the private parser spike untouched", async () => { const root = await mkdtemp(join(tmpdir(), "foundation-private-exit-")); try { await mkdir(join(root, ".changeset"), { recursive: true }); await mkdir(join(root, "packages", "public"), { recursive: true }); await mkdir(join(root, "packages", "private"), { recursive: true }); await writeFile( join(root, "package.json"), JSON.stringify({ private: true, workspaces: ["packages/*"] }), ); await writeFile( join(root, ".changeset", "config.json"), JSON.stringify({ changelog: false, commit: false, fixed: [], linked: [], access: "restricted", baseBranch: "main", updateInternalDependencies: "patch", ignore: [], privatePackages: { version: true, tag: false }, }), ); await writeFile( join(root, ".changeset", "pre.json"), JSON.stringify({ mode: "exit", tag: "rc", initialVersions: { "public-package": "1.0.0", "private-spike": "0.0.0" }, changesets: ["alpha"], }), ); await writeFile( join(root, ".changeset", "alpha.md"), '---\n"public-package": minor\n---\n\nPublic change.\n', ); await writeFile( join(root, "packages", "public", "package.json"), JSON.stringify({ name: "public-package", version: "1.1.0-rc.0" }), ); const privateManifestPath = join(root, "packages", "private", "package.json"); await writeFile( privateManifestPath, JSON.stringify({ name: "private-spike", version: "0.0.0", private: true }), ); await execFileAsync(process.execPath, [changesetBin, "version"], { cwd: root }); assert.equal(JSON.parse(await readFile(privateManifestPath, "utf8")).version, "0.0.0"); } finally { await rm(root, { recursive: true, force: true }); } }); function pullRequest(baseSha, headSha, body, number = 74) { return { user: { login: "777genius", type: "User" }, number, state: "open", headRef: "changeset-release/main", headSha, baseRef: "main", baseSha, body, }; } async function violations(root, processedMainSha, currentMainSha, release, expectedHeadSha) { return releasePullRequestFreshnessViolations( { processedMainSha, currentMainSha, expectedBaseSha: processedMainSha, expectedHeadSha, expectedPullRequestNumber: "74", pullRequest: pullRequest(processedMainSha, release.head, release.body), }, { cwd: root }, ); } test("release identity rejects staging bots and binds both raw Git identities", async (t) => { t.after(fixtureGit.poisonInheritedFixtureGitEnvironment()); const { root, mainA } = await createFixture(); try { const release = await createRelease(root, mainA, "1.1.0", ["Alpha package change."]); const evidence = { processedMainSha: mainA, currentMainSha: mainA, pullRequest: pullRequest(mainA, release.head, release.body), }; assert.deepEqual(await releasePullRequestFreshnessViolations(evidence, { cwd: root }), []); // The contributor-authored parent stays intact; only the generated commit is governed. assert.equal( await git(root, "show", "--no-patch", "--format=%an <%ae>", mainA), "Foundation Test ", ); for (const user of [ { login: "github-actions[bot]", type: "Bot" }, { login: "777genius", type: "Bot" }, { login: "iliyaZelenko", type: "User" }, { login: "external-contributor", type: "User" }, ]) { const result = await releasePullRequestFreshnessViolations( { ...evidence, pullRequest: { ...evidence.pullRequest, user } }, { cwd: root }, ); assert.equal(result.length, 1); assert.match(result[0], /must be authored by the repository owner/u); } for (const [authorName, authorEmail, committerName, committerEmail] of [ ["iliya", "wrong@example.invalid", "iliya", "iliyazelenkog@gmail.com"], ["iliya", "iliyazelenkog@gmail.com", "iliya", "wrong@example.invalid"], [ "github-actions[bot]", "41898282+github-actions[bot]@users.noreply.github.com", "iliya", "iliyazelenkog@gmail.com", ], ["GitHub", "noreply@github.com", "iliya", "iliyazelenkog@gmail.com"], ["iliya", "iliyazelenkog@gmail.com", "GitHub", "noreply@github.com"], ]) { await amendFixtureIdentity(root, authorName, authorEmail, committerName, committerEmail); assert.equal( await git(root, "show", "--no-patch", "--format=%an <%ae>|%cn <%ce>", "HEAD"), `${authorName} <${authorEmail}>|${committerName} <${committerEmail}>`, ); const result = await releasePullRequestFreshnessViolations( { ...evidence, pullRequest: { ...evidence.pullRequest, headSha: await git(root, "rev-parse", "HEAD") }, }, { cwd: root }, ); assert.equal(result.length, 1); assert.match(result[0], /author and committer must both be exactly/u); } } finally { await rm(root, { recursive: true, force: true }); } }); test("release evidence follows the latest processed main across a two-push race", async () => { const fixture = await createFixture(); try { const releaseA = await createRelease(fixture.root, fixture.mainA, "1.1.0", [ "Alpha package change.", ]); assert.deepEqual( await violations(fixture.root, fixture.mainA, fixture.mainA, releaseA, releaseA.head), [], ); await git(fixture.root, "checkout", "--detach", fixture.mainA); await writeFile(join(fixture.root, ".changeset", "beta.md"), changeset("Beta package change.")); await git(fixture.root, "add", "."); await git(fixture.root, "commit", "-m", "main B"); const mainB = await git(fixture.root, "rev-parse", "HEAD"); assert.match( (await violations(fixture.root, fixture.mainA, mainB, releaseA, releaseA.head)).join("\n"), /processed main is stale/u, ); const incompleteReleaseB = await createRelease(fixture.root, mainB, "1.1.0", [ "Alpha package change.", ]); assert.match( ( await violations(fixture.root, mainB, mainB, incompleteReleaseB, incompleteReleaseB.head) ).join("\n"), /missing the summary from \.changeset\/beta\.md/u, ); const releaseB = await createRelease(fixture.root, mainB, "1.1.0", [ "Alpha package change.", "Beta package change.", ]); assert.deepEqual(await violations(fixture.root, mainB, mainB, releaseB, releaseB.head), []); assert.match( (await violations(fixture.root, mainB, mainB, releaseB, incompleteReleaseB.head)).join("\n"), /head changed during attestation/u, ); } finally { await rm(fixture.root, { recursive: true, force: true }); } }); test("official empty Changeset is release-neutral but must be consumed", async () => { const fixture = await createFixture(); try { await git(fixture.root, "checkout", "--detach", fixture.mainA); await writeFile( join(fixture.root, ".changeset", "bootstrap.md"), "---\n---\n\nRecord the bootstrap promotion without a version bump.\n", ); await git(fixture.root, "add", ".changeset/bootstrap.md"); await git(fixture.root, "commit", "-m", "record empty bootstrap changeset"); const main = await git(fixture.root, "rev-parse", "HEAD"); const release = await createRelease(fixture.root, main, "1.1.0", ["Alpha package change."]); assert.match( (await violations(fixture.root, main, main, release, release.head)).join("\n"), /intent.consumption: \.changeset\/bootstrap\.md/u, ); await git(fixture.root, "checkout", "--detach", release.head); await rm(join(fixture.root, ".changeset", "bootstrap.md")); await git(fixture.root, "add", ".changeset/bootstrap.md"); await commitRelease(fixture.root, "--amend", "--no-edit"); const consumedHead = await git(fixture.root, "rev-parse", "HEAD"); assert.deepEqual( await violations(fixture.root, main, main, { ...release, head: consumedHead }, consumedHead), [], ); } finally { await rm(fixture.root, { recursive: true, force: true }); } }); test("an empty Changeset cannot be the generated release PR's only release evidence", async () => { const fixture = await createFixture(); try { await git(fixture.root, "checkout", "--detach", fixture.mainA); await rm(join(fixture.root, ".changeset", "alpha.md")); await writeFile( join(fixture.root, ".changeset", "bootstrap.md"), "---\n---\n\nRecord the bootstrap promotion without a version bump.\n", ); await git(fixture.root, "add", ".changeset"); await git(fixture.root, "commit", "-m", "only empty bootstrap changeset"); const main = await git(fixture.root, "rev-parse", "HEAD"); const release = await createRelease(fixture.root, main, "1.1.0", []); await git(fixture.root, "checkout", "--detach", release.head); await rm(join(fixture.root, ".changeset", "bootstrap.md")); await git(fixture.root, "add", ".changeset/bootstrap.md"); await commitRelease(fixture.root, "--amend", "--no-edit"); const head = await git(fixture.root, "rev-parse", "HEAD"); assert.match( (await violations(fixture.root, main, main, { ...release, head }, head)).join("\n"), /plan.unexpected-version|at least one package release changeset/u, ); } finally { await rm(fixture.root, { recursive: true, force: true }); } }); test("existing release PR binding waits for the post-update revision tuple", async () => { const fixture = await createFixture(); try { const oldRelease = await createRelease(fixture.root, fixture.mainA, "1.1.0", [ "Alpha package change.", ]); await git(fixture.root, "checkout", "--detach", fixture.mainA); await writeFile(join(fixture.root, ".changeset", "beta.md"), changeset("Beta package change.")); await git(fixture.root, "add", "."); await git(fixture.root, "commit", "-m", "main B"); const mainB = await git(fixture.root, "rev-parse", "HEAD"); const newRelease = await createRelease(fixture.root, mainB, "1.1.0", [ "Alpha package change.", "Beta package change.", ]); const staleSnapshot = await releasePullRequestFreshnessViolations( { processedMainSha: mainB, currentMainSha: mainB, expectedBaseSha: mainB, expectedHeadSha: newRelease.head, expectedPullRequestNumber: "74", pullRequest: pullRequest(fixture.mainA, oldRelease.head, oldRelease.body), }, { cwd: fixture.root }, ); assert.match(staleSnapshot.join("\n"), /head changed during attestation/u); assert.match(staleSnapshot.join("\n"), /base changed during attestation/u); assert.deepEqual( await releasePullRequestFreshnessViolations( { processedMainSha: mainB, currentMainSha: mainB, expectedBaseSha: mainB, expectedHeadSha: newRelease.head, expectedPullRequestNumber: "74", pullRequest: pullRequest(mainB, newRelease.head, newRelease.body), }, { cwd: fixture.root }, ), [], ); const wrongNumber = await releasePullRequestFreshnessViolations( { processedMainSha: mainB, currentMainSha: mainB, expectedBaseSha: mainB, expectedHeadSha: newRelease.head, expectedPullRequestNumber: "74", pullRequest: pullRequest(mainB, newRelease.head, newRelease.body, 75), }, { cwd: fixture.root }, ); assert.match(wrongNumber.join("\n"), /number changed during attestation/u); } finally { await rm(fixture.root, { recursive: true, force: true }); } }); // Captured from f61bc034's generated 1.1.1 changelog (release run 34221971848) // and 8823036c's legacy-scaffold-refusal Changeset, without running the formatter. const legacyScaffoldSummary = `Preserve recognized 0.9.0 legacy scaffold evidence by refusing mismatching readers before Foundation lock acquisition. Report incompatible regular locks as manual recovery without an executable route; retain existing barriers and under-lock admission checks. Refs #260 and #271.`; const legacyScaffoldSection = `## 1.1.1 ### Patch Changes - [#276](https://github.com/agent-teams-ai/engineering-foundation/pull/276) [\`8823036\`](https://github.com/agent-teams-ai/engineering-foundation/commit/8823036c0c4c8036f267b1173329e7dd4c51733e) Thanks [@777genius](https://github.com/777genius)! - Preserve recognized 0.9.0 legacy scaffold evidence by refusing mismatching readers before Foundation lock acquisition. Report incompatible regular locks as manual recovery without an executable route; retain existing barriers and under-lock admission checks. Refs [#260](https://github.com/agent-teams-ai/engineering-foundation/issues/260) and [#271](https://github.com/agent-teams-ai/engineering-foundation/issues/271). - [#276](https://github.com/agent-teams-ai/engineering-foundation/pull/276) [\`8823036\`](https://github.com/agent-teams-ai/engineering-foundation/commit/8823036c0c4c8036f267b1173329e7dd4c51733e) Thanks [@777genius](https://github.com/777genius)! - Classify contained baseline replacements during promotion observations as write conflicts while preserving ordinary read and unsafe-target behavior.`; for (const [label, transform, accepted] of [ ["official generated issue links", (value) => value, true], [ "plain issue references", (value) => value.replaceAll( /\[#(260|271)\]\(https:\/\/github\.com\/agent-teams-ai\/engineering-foundation\/issues\/\1\)/gu, "#$1", ), true, ], ["forged destination", (value) => value.replace("issues/260", "issues/999"), false], ["forged label", (value) => value.replace("[#260]", "[#999]"), false], [ "unrelated repository", (value) => value.replace("engineering-foundation/issues/260", "other/issues/260"), false, ], [ "arbitrary destination", (value) => value.replace( "https://github.com/agent-teams-ai/engineering-foundation/issues/260", "https://example.invalid/260", ), false, ], ["pull destination", (value) => value.replace("issues/260", "pull/260"), false], [ "unrelated owner", (value) => value.replace( "agent-teams-ai/engineering-foundation/issues/260", "other/engineering-foundation/issues/260", ), false, ], [ "insecure destination", (value) => value.replace( "https://github.com/agent-teams-ai/engineering-foundation/issues/260", "http://github.com/agent-teams-ai/engineering-foundation/issues/260", ), false, ], ["destination query", (value) => value.replace("issues/260)", "issues/260?forged)"), false], ["destination fragment", (value) => value.replace("issues/260)", "issues/260#forged)"), false], [ "changed summary", (value) => value.replace("without an executable route", "with an executable route"), false, ], [ "missing reference", (value) => value.replace( " and [#271](https://github.com/agent-teams-ai/engineering-foundation/issues/271)", "", ), false, ], ]) { test(`legacy scaffold freshness: ${label}`, async () => { const fixture = await createFixture(legacyScaffoldSummary, { version: "1.1.0", releaseType: "patch", }); try { const section = transform(legacyScaffoldSection); const generated = { changelog: `# ${packageName}\n\n${section}\n\n## 1.0.0\n`, body: `# Releases\n${section.replace("## 1.1.1", `## ${packageName}@1.1.1`)}`, }; const release = await createRelease(fixture.root, fixture.mainA, "1.1.1", [], { generated }); const result = await violations( fixture.root, fixture.mainA, fixture.mainA, release, release.head, ); if (accepted) { assert.deepEqual(result, []); const alteredBody = { ...release, body: release.body.replace("issues/260", "issues/999") }; if (alteredBody.body !== release.body) { assert.match( ( await violations( fixture.root, fixture.mainA, fixture.mainA, alteredBody, release.head, ) ).join("\n"), /does not exactly match all generated changelog entries/u, ); } } else { assert.match(result.join("\n"), /missing the summary from \.changeset\/alpha\.md/u); } } finally { await rm(fixture.root, { recursive: true, force: true }); } }); } // Explicit expected text follows the pinned formatter's per-line link skipping; // these fixtures do not call the formatter or reproduce its replacement regex. const issue260 = "[#260](https://github.com/agent-teams-ai/engineering-foundation/issues/260)"; const issue271 = "[#271](https://github.com/agent-teams-ai/engineering-foundation/issues/271)"; const authoredIssueLink = "See [case #260](https://example.invalid)."; for (const [label, summary, rendered, accepted] of [ ["unchanged authored link", authoredIssueLink, authoredIssueLink, true], [ "authored link collision", authoredIssueLink, `See [case ${issue260}](https://example.invalid).`, false, ], [ "authored destination preserved", "See [case #260](https://example.invalid/#271).", "See [case #260](https://example.invalid/#271).", true, ], [ "authored destination mutation", authoredIssueLink, "See [case #260](https://example.invalid/changed).", false, ], [ "punctuation adjacent references", "Refs (#260). #260,#271", `Refs (${issue260}). ${issue260},${issue271}`, true, ], [ "word boundaries", "Refs x#260 #0 #01 #260suffix (#271).", `Refs x#260 #0 #01 #260suffix (${issue271}).`, true, ], [ "multiline references and authored links", "Refs (#260).\nSee [case #260](https://example.invalid/#271).\n#260,#271", `Refs (${issue260}).\n See [case #260](https://example.invalid/#271).\n ${issue260},${issue271}`, true, ], [ "link skipping does not cross lines", "See [case #260\ncontinued #271](https://example.invalid).", `See [case ${issue260}\n continued ${issue271}](https://example.invalid).`, true, ], ]) { test(`issue reference freshness: ${label}`, async () => { const fixture = await createFixture(summary); try { const release = await createRelease(fixture.root, fixture.mainA, "1.1.0", [rendered]); const result = await violations( fixture.root, fixture.mainA, fixture.mainA, release, release.head, ); if (accepted) { assert.deepEqual(result, []); } else { assert.match(result.join("\n"), /missing the summary from \.changeset\/alpha\.md/u); } } finally { await rm(fixture.root, { recursive: true, force: true }); } }); } test("repeated issue-bearing summaries require one occurrence per Changeset", async () => { const fixture = await createFixture("Refs (#260)."); try { await writeFile(join(fixture.root, ".changeset", "beta.md"), changeset("Refs (#260).")); await git(fixture.root, "add", ".changeset/beta.md"); await git(fixture.root, "commit", "-m", "test: repeat issue-bearing summary"); const main = await git(fixture.root, "rev-parse", "HEAD"); const rendered = `Refs (${issue260}).`; const incomplete = await createRelease(fixture.root, main, "1.1.0", [rendered]); const result = await violations(fixture.root, main, main, incomplete, incomplete.head); assert.equal(result.length, 1); assert.match(result[0], /missing the summary from \.changeset\/(alpha|beta)\.md/u); const complete = await createRelease(fixture.root, main, "1.1.0", [rendered, rendered]); assert.deepEqual(await violations(fixture.root, main, main, complete, complete.head), []); } finally { await rm(fixture.root, { recursive: true, force: true }); } });