Skip to content

observe: a branch's first push analyses only its last commit (head^..head), missing earlier commits in the push #308

Closed

Description

@FredApps

What went wrong?

DiffCI left out a test that should have run (a miss).

On the first push of a new branch (push event with before = forty zeros), the commit range falls back to head^..head (packages/diffci-cli/src/client/context.ts, the event === "push" branch of resolveCommitRange; the GitLab push branch of resolveGitlabRange does the same with CI_COMMIT_BEFORE_SHA). A push that creates a branch usually carries several commits, so a change made in any commit before the last one is never analysed.

The range is labelled source: "head-parent", and enforce mode already distrusts it (enforce-policy.ts: "range is the head commit's parent, not the full push"). Nothing else does: the observation is OBSERVED/SELECTIVE, and the Action's full-suite-required output (action/impact.mjs impactOutputs, and the Azure task's outputsFor) is "false", with affected-tests missing the tests for the earlier commits. A workflow that narrows on full-suite-required, as the outputs docs describe, runs too few tests, and verify: "true" (fed DIFFCI_FULL from the same output) passes.

docs/design/gitlab-component.md says the first-push case should "use the existing merge-base-with-default-branch logic, or head-parent, as GitHub does", but the GitHub path has no merge-base logic, only head-parent.

DiffCI version

main at 40aa308 (CLI 0.3.54)

Command you ran

A repository with "test": "node --test", src/alpha.js and src/beta.js, test/alpha.test.js and test/beta.test.js (each test imports its own source), origin/main at the initial commit. A new branch feature with two commits: the first changes src/alpha.js so test/alpha.test.js fails, the second only touches src/beta.js. Event payload {"before":"0000000000000000000000000000000000000000","ref":"refs/heads/feature","created":true,"repository":{"default_branch":"main"}}.

GITHUB_EVENT_NAME=push GITHUB_SHA=<head> GITHUB_EVENT_PATH=push.json diffci observe --no-send --out report.json

Environment

Linux, Node 24, npm, CLI built from main.

Output

"commitRange": { "baseSha": "507397d…", "headSha": "0cefcc4…", "source": "head-parent" },
"mode": "SELECTIVE",
"changedFiles": ["src/beta.js"],
"selectedTests": ["test/beta.test.js"]

impactOutputs(report):
{ 'full-suite-required': 'false', 'affected-tests': '["test/beta.test.js"]', 'affected-test-count': '1', 'total-test-count': '2' }

The full suite at the head fails (✖ alpha); the selected test/beta.test.js passes.

Expected

The range covers every commit the push brought: the merge base of the head with the default branch's remote-tracking ref (repository.default_branch on GitHub, CI_DEFAULT_BRANCH on GitLab), the same range a pull request from the branch gets, with head-parent kept only as the fallback when that ref is not in the checkout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions