fix(tdd): detect PR-changed files using merge base, not base branch tip#4072
Merged
Conversation
Agent-Logs-Url: https://github.com/cybersemics/em/sessions/cf3a05d9-645b-4da5-b3ba-0fec7dd2f8f7 Co-authored-by: raineorshine <750276+raineorshine@users.noreply.github.com>
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
raineorshine
approved these changes
Apr 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a contributor's branch is created from an older
mainandmainadvances via other merged PRs, diffingbase.sha..head.shaincorrectly 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
detectjob: computeMERGE_BASE=$(git merge-base "$BASE_SHA" "$HEAD_SHA")and diff from that instead of$BASE_SHA; exposemerge_baseas a job outputunit/puppeteerjobs: replaceBASE_SHAwithneeds.detect.outputs.merge_basein patch-generationgit diffcalls for consistencyfetch-depthfrom100to999to ensure the merge-base commit is available in the shallow cloneOriginal prompt
Fix the TDD workflow in
cybersemics/emso it detects PR-changed files using the merge base between the PR base tip and head commit, rather than diffing directly fromgithub.event.pull_request.base.shatogithub.event.pull_request.head.sha.Context:
.github/workflows/tdd.ymlusesgit diff --name-only "$BASE_SHA" "$HEAD_SHA" --in thedetectjob, whereBASE_SHAis${{ github.event.pull_request.base.sha }}andHEAD_SHAis${{ github.event.pull_request.head.sha }}.mainandmainhas advanced since then.Requested fix:
.github/workflows/tdd.ymlso the workflow computes the merge base withgit merge-base "$BASE_SHA" "$HEAD_SHA"and uses that merge base when detecting changed files.fetch-depthfrom100to999instead of0, to better support merge-base calculation without the cost of a full clone.detectjob 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
mainwith 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:
As Faiz points out, he branched off an older version of
main, but the tdd worklow is name diffing against currentmain. I can see how this would arise, because the PR has a base branch ofmain. 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:
main83948185a88d4df63a07a4c46bca76ec0a11888815b51570e15deb4cee11183147acc9055026c685And the workflow does:
That
github.event.pull_request.base.shais 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 oldermain, andmainmoved forward via other merged PRs,git diff current-main-tip...headwill include all commits that are on Faiz’s branch but not on currentmain—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 tiphead branch tipThat merge ...
This pull request was created from Copilot chat.