An open source design system that's fully customizable and agent ready
TypeScript
ci(spec-owner): an unchanged renamed record's base text reuses its head text (#9269)
Cindy Zhang1e8f797c2424
diff --git a/.github/scripts/spec-owner-reconcile.cjs b/.github/scripts/spec-owner-reconcile.cjsindex 54196acaa1..90bd938443 100644--- a/.github/scripts/spec-owner-reconcile.cjs+++ b/.github/scripts/spec-owner-reconcile.cjs@@ -308,6 +308,31 @@ async function reconcileSpecOwnerGate({}}+ /**+ * Every file's blob at `ref`, from one tree read. Empty when GitHub cuts+ * the tree short or the read fails, so each base text is then read.+ */+ async function readBaseBlobs(fullName, ref) {+ const [repoOwner, repoName] = fullName.split('/');+ try {+ const {data} = await github.rest.git.getTree({+ owner: repoOwner,+ repo: repoName,+ tree_sha: ref,+ recursive: 'true',+ });+ if (data.truncated) return new Map();+ return new Map(+ (data.tree ?? [])+ .filter(entry => entry.type === 'blob')+ .map(entry => [entry.path, entry.sha]),+ );+ } catch (error) {+ core.warning(`Could not read the base tree: ${error.message}`);+ return new Map();+ }+ }+/** A spec path's text at `ref`, or null when the path is absent there. */async function readSpecContent(fullName, ref, filePath) {const [repoOwner, repoName] = fullName.split('/');@@ -537,30 +562,44 @@ async function reconcileSpecOwnerGate({classifyChanges([{filename: file.previous_filename}]).touchesKnowledgeRecords)),);+ // A renamed record whose head blob is its old path's blob at the base has+ // the same text at both, so its base text needs no read of its own.+ const baseBlobs = knowledgeChanges.some(file => file.status === 'renamed')+ ? await readBaseBlobs(after.base.repo.full_name, after.base.sha)+ : new Map();const records = await Promise.all(knowledgeChanges.map(async file => {const previousPath = file.previous_filename || file.filename;const baseIsTextRecord = previousPath.endsWith('.md');const headIsTextRecord = file.filename.endsWith('.md');+ const headContent =+ !headIsTextRecord || file.status === 'removed'+ ? null+ : await readText(+ after.head.repo.full_name,+ after.head.sha,+ file.filename,+ );+ const unchangedRename =+ headContent != null &&+ baseIsTextRecord &&+ file.status === 'renamed' &&+ file.sha != null &&+ baseBlobs.get(previousPath) === file.sha;return {path: file.filename,previousPath,baseContent:!baseIsTextRecord || file.status === 'added'? null- : await readText(- after.base.repo.full_name,- after.base.sha,- previousPath,- ),- headContent:- !headIsTextRecord || file.status === 'removed'- ? null- : await readText(- after.head.repo.full_name,- after.head.sha,- file.filename,- ),+ : unchangedRename+ ? headContent+ : await readText(+ after.base.repo.full_name,+ after.base.sha,+ previousPath,+ ),+ headContent,};}),);diff --git a/.github/scripts/spec-owner-reconcile.test.mjs b/.github/scripts/spec-owner-reconcile.test.mjsindex ee1bfa63a0..5f723601f9 100644--- a/.github/scripts/spec-owner-reconcile.test.mjs+++ b/.github/scripts/spec-owner-reconcile.test.mjs@@ -1542,6 +1542,72 @@ describe('spec owner workflow reconciliation', () => {});});+ describe('renamed records', () => {+ const moved = Array.from({length: 300}, (_, i) => ({+ filename: `docs/specs/components/C${i}/C${i}.spec.md`,+ previous_filename: `packages/core/src/C${i}/C${i}.spec.md`,+ status: 'renamed',+ changes: 0,+ sha: `blob-${i}`,+ }));+ const baseTree = moved.map(file => ({+ path: file.previous_filename,+ type: 'blob',+ sha: file.sha,+ }));++ async function reconcileCounting({tree, edited = null}) {+ const harness = createHarness({+ changedFiles: moved,+ headContent: currentRecord,+ baseContent: currentRecord,+ comments: [ownerComment(`/approve-spec ${head}`)],+ });+ harness.github.rest.git = {+ getTree: async () => {+ if (!tree) throw new Error('Not available');+ return {+ data: {+ tree: tree.map(entry =>+ entry.path === edited+ ? {...entry, sha: 'blob-edited'}+ : entry,+ ),+ truncated: false,+ },+ };+ },+ };+ const counter = {reads: 0};+ const getContent = harness.github.rest.repos.getContent;+ harness.github.rest.repos.getContent = async input => {+ counter.reads += 1;+ return getContent(input);+ };+ await run(harness, context({runId: 100n}));+ return {reads: counter.reads, gate: latestReviewGate(harness.state)};+ }++ it('reuses the head text as the base text of an unchanged rename', async () => {+ const withoutTree = await reconcileCounting({tree: null});+ const withTree = await reconcileCounting({tree: baseTree});++ expect(withTree.gate).toEqual(withoutTree.gate);+ expect(withTree.gate.state).toBe('success');+ expect(withoutTree.reads - withTree.reads).toBe(300);+ });++ it('still reads the base text when the base changed the old path', async () => {+ const withoutTree = await reconcileCounting({tree: null});+ const oneEdited = await reconcileCounting({+ tree: baseTree,+ edited: moved[7].previous_filename,+ });++ expect(withoutTree.reads - oneEdited.reads).toBe(299);+ });+ });+it('reads a spec wait as satisfied code review, not an older code wait', async () => {const harness = createHarness({headContent: currentRecord,