Skip to content

fix(tdd): detect PR-changed files using merge base, not base branch tip#4072

Merged
raineorshine merged 2 commits into
mainfrom
copilot/fix-tdd-workflow-merge-base
Apr 10, 2026
Merged

fix(tdd): detect PR-changed files using merge base, not base branch tip#4072
raineorshine merged 2 commits into
mainfrom
copilot/fix-tdd-workflow-merge-base

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 10, 2026

When a contributor's branch is created from an older main and main advances via other merged PRs, diffing base.sha..head.sha incorrectly includes files from those other PRs. GitHub's "Files changed" tab is correct because it diffs from the merge base, not the current base branch tip.

Changes

  • detect job: compute MERGE_BASE=$(git merge-base "$BASE_SHA" "$HEAD_SHA") and diff from that instead of $BASE_SHA; expose merge_base as a job output
  • unit / puppeteer jobs: replace BASE_SHA with needs.detect.outputs.merge_base in patch-generation git diff calls for consistency
  • All three jobs: increase fetch-depth from 100 to 999 to ensure the merge-base commit is available in the shallow clone
# Before
CHANGED_FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" --)

# After
MERGE_BASE=$(git merge-base "$BASE_SHA" "$HEAD_SHA")
CHANGED_FILES=$(git diff --name-only "$MERGE_BASE" "$HEAD_SHA" --)
Original prompt

Fix the TDD workflow in cybersemics/em so it detects PR-changed files using the merge base between the PR base tip and head commit, rather than diffing directly from github.event.pull_request.base.sha to github.event.pull_request.head.sha.

Context:

  • The current workflow in .github/workflows/tdd.yml uses git diff --name-only "$BASE_SHA" "$HEAD_SHA" -- in the detect job, where BASE_SHA is ${{ github.event.pull_request.base.sha }} and HEAD_SHA is ${{ github.event.pull_request.head.sha }}.
  • This incorrectly includes files from other merged PRs when a contributor’s branch was created from an older main and main has advanced since then.
  • GitHub’s PR UI correctly shows only the PR’s changes because it effectively compares from the merge base.

Requested fix:

  1. Update .github/workflows/tdd.yml so the workflow computes the merge base with git merge-base "$BASE_SHA" "$HEAD_SHA" and uses that merge base when detecting changed files.
  2. Reuse the same merge-base logic in downstream jobs that generate/apply test diffs, so patch generation also reflects only files changed in the PR.
  3. Increase checkout fetch-depth from 100 to 999 instead of 0, to better support merge-base calculation without the cost of a full clone.
  4. Keep changes minimal and consistent with existing shell/YAML style.
  5. If appropriate, expose the merge base as a detect job output so downstream jobs can use the same value.

Please implement the code change, run any relevant checks you can, and open a pull request against main with a concise descriptive title and a summary of the fix and why it was needed.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: https://github.com/cybersemics/em/actions/runs/24207832405/job/70668313025?pr=4048#logs

The tdd workflow incorrectly detected changed files from other merged PRs:

Base SHA: 83948185a88d4df63a07a4c46bca76ec0a118888
Head SHA: 15b51570e15deb4cee11183147acc9055026c685
=== All changed files ===
.github/agents/worker-bee.agent.md
.github/skills/puppeteer-update-snapshots/SKILL.md
package.json
packages/webview/package.json
src/actions/__tests__/swapParent.ts
src/actions/formatSelection.ts
src/actions/moveThought.ts
src/colors.config.ts
src/commands/newUncle.ts
src/commands/note.ts
src/commands/undo.ts
src/components/ColorPicker.tsx
src/components/Note.tsx
src/components/VirtualThought.tsx
src/e2e/puppeteer/__tests__/color.ts
src/selectors/getSortedRank.ts
src/util/compareThought.ts
src/util/noteValue.ts
yarn.lock

=== Unit test files ===
src/actions/__tests__/swapParent.ts

=== Puppeteer test files ===
src/e2e/puppeteer/__tests__/color.ts

=== iOS test files ===


=== Non-test application files ===
src/actions/formatSelection.ts
src/actions/moveThought.ts
src/colors.config.ts
src/commands/newUncle.ts
src/commands/note.ts
src/commands/undo.ts
src/components/ColorPicker.tsx
src/components/Note.tsx
src/components/VirtualThought.tsx
src/selectors/getSortedRank.ts
src/util/compareThought.ts
src/util/noteValue.ts

=== Summary ===
Has unit tests: true
Has puppeteer tests: true
Has iOS tests: false
Has app code changes: true

As Faiz points out, he branched off an older version of main, but the tdd worklow is name diffing against current main. I can see how this would arise, because the PR has a base branch of main. I don't see the original commit that it was branched off, yet that information must be available because the "Commits" tab and "Files changed" tab correctly only show Faiz's commits.

Assistant: The workflow is using the current PR base tip SHA, not the merge base between the PR branch and main. That’s why it picked up files from already-merged PRs.

In PR #4048, GitHub reports:

  • base ref: main
  • base SHA: 83948185a88d4df63a07a4c46bca76ec0a118888
  • head SHA: 15b51570e15deb4cee11183147acc9055026c685

And the workflow does:

BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"

echo "Base SHA: $BASE_SHA"
echo "Head SHA: $HEAD_SHA"

# All changed files in the PR
CHANGED_FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" --)

That github.event.pull_request.base.sha is the current SHA of the base branch in the PR event, not “the commit this branch originally forked from.” So if Faiz branched from an older main, and main moved forward via other merged PRs, git diff current-main-tip...head will include all commits that are on Faiz’s branch but not on current main—including commits from old base history relationships that GitHub’s PR UI filters out via merge-base logic.

Why GitHub’s “Files changed” tab is correct

GitHub PR views effectively compare the PR head against the merge base of:

  • base branch tip
  • head branch tip

That merge ...

This pull request was created from Copilot chat.

Copilot AI changed the title [WIP] Fix TDD workflow to use merge base for detecting changed files fix(tdd): detect PR-changed files using merge base, not base branch tip Apr 10, 2026
Copilot AI requested a review from raineorshine April 10, 2026 00:35
@raineorshine raineorshine marked this pull request as ready for review April 10, 2026 00:35
@raineorshine raineorshine merged commit 8f597f8 into main Apr 10, 2026
9 checks passed
@raineorshine raineorshine deleted the copilot/fix-tdd-workflow-merge-base branch April 10, 2026 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants