Skip to content

test(pipelineascode): assert on queued check-run status for pending PipelineRuns - #2904

Open
pujitha24 wants to merge 2 commits into
tektoncd:mainfrom
pujitha24:auto/issue-1957
Open

test(pipelineascode): assert on queued check-run status for pending PipelineRuns#2904
pujitha24 wants to merge 2 commits into
tektoncd:mainfrom
pujitha24:auto/issue-1957

Conversation

@pujitha24

@pujitha24 pujitha24 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

📝 Description of the Change

The check-run mock helper in pkg/pipelineascode/pipelineascode_test.go only asserted on a check-run write when its status was "completed", silently ignoring every other status. Two testcases exercise a PipelineRun left in the Pending spec state, which never reaches "completed" in this code path — it only ever emits a "queued" check-run. Because those two testcases also left finalStatus/finalStatusText unset, they passed without validating anything at all.

This adds an opt-in queuedStatusText field so those two testcases now assert the "queued" check-run text contains "has been queued". The assertion is opt-in (only applied when the field is non-empty) so it doesn't affect any other testcase, including an unrelated access-denied flow that also uses the "queued" status with different text.

This is a narrow fix, not a full resolution of #1957. As pointed out in review, the linked issue also asks for: (1) asserting on the "in_progress" status, not just "completed"/"queued", and (2) splitting the monolithic table-driven test into focused, individual tests. Neither of those is done here — this PR only closes the specific vacuous-assertion gap for the two pending-state testcases. #1957 should stay open to track the remaining in_progress coverage and the structural refactor.

🔗 Linked GitHub Issue

Relates to #1957 (does not close it — see scope note above; remaining work should stay tracked there)

🧪 Testing Strategy

  • Unit tests
  • Integration tests
  • End-to-end tests
  • Manual testing
  • Not Applicable

🤖 AI Assistance

AI assistance can be used for various tasks, such as code generation,
documentation, or testing.

Please indicate whether you have used AI assistance
for this PR and provide details if applicable.

  • I have not used any AI assistance for this PR.
  • I have used AI assistance for this PR.

Important

Slop will be simply rejected, if you are using AI assistance you need to make sure you
understand the code generated and that it meets the project's standards. you
need at least know how to run the code and deploy it (if needed). See
startpaac to make it easy
to deploy and test your code changes.

If the majority of the code in this PR was generated by an AI, please add a Co-authored-by trailer to your commit message.
For example:

Co-authored-by: Claude noreply@anthropic.com

✅ Submitter Checklist

  • 📝 My commit messages are clear, informative, and follow the project's How to write a git commit message guide. The Gitlint linter ensures in CI it's properly validated
  • ✨ I have ensured my commit message prefix (e.g., fix:, feat:) matches the "Type of Change" I selected above.
  • ♽ I have run make test and make lint locally to check for and fix any
    issues. For an efficient workflow, I have considered installing
    pre-commit and running pre-commit install to
    automate these checks.
  • 📖 I have added or updated documentation for any user-facing changes.
  • 🧪 I have added sufficient unit tests for my code changes.
  • 🎁 I have added end-to-end tests where feasible. See README for more details.
  • 🔎 I have addressed any CI test flakiness or provided a clear reason to bypass it.
  • If adding a provider feature, I have filled in the following and updated the provider documentation:
    • GitHub App
    • GitHub Webhook
    • Gitea/Forgejo
    • GitLab
    • Bitbucket Cloud
    • Bitbucket Data Center

AI assistance: this change was drafted with Claude Code.

Copilot AI lite review requested due to automatic review settings August 4, 2026 21:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Strengthens pkg/pipelineascode unit tests by ensuring GitHub check-run writes are asserted for PipelineRuns that remain in Pending and therefore only emit a queued check-run status, closing a gap where those test cases previously passed without validating any check-run content.

Changes:

  • Extend the shared GitHub replies test helper to optionally assert check-run output text when status is queued.
  • Add a queuedStatusText opt-in field to the table-driven tests and populate it for the pending PipelineRun scenarios.
  • Keep existing behavior unchanged for other test cases (including other queued flows) by only asserting when the new field is set.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@theakshaypant theakshaypant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this @pujitha24!

The fix for the two pending-state assertions is correct. However, I don't think this sufficiently addresses the linked issue to close it. The issue raises two problems:

  1. The test only validates "completed" status: queued, in_progress, and error states are not checked
  2. The test structure is a monolithic table-driven test that tries to do too much and should be split into focused tests

This PR addresses a narrow slice of problem 1 but the broader described gaps remain:

  • in_progress is still silently ignored
  • No status lifecycle tracking
  • No structural refactor

I'd suggest either expanding the scope here or keeping #1957 open for the remaining work.

// testcases that expect that outcome opt into checking the "queued" status
// text instead via queuedStatusText.
switch created.GetStatus() {
case "completed":

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] Similar to queuedStatus on line 101, consider using a constant in place of the literal here.

pujitha24 added a commit to pujitha24/pipelines-as-code that referenced this pull request Aug 7, 2026
… in test switch

Addresses review nit on PR tektoncd#2904: use the existing CompletedStatus
constant for the completed case, matching the queuedStatus constant
already used in the same switch.

Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
@pujitha24

Copy link
Copy Markdown
Contributor Author

Thanks for the review! The constant nit is already handled — the latest commit (1b22e5a) replaced the "completed" literal with the CompletedStatus constant, matching queuedStatus on the next case.

On scope: agreed, I'd rather not stretch this PR to cover in_progress coverage and the test-splitting refactor — those are more involved changes that deserve their own focused PR and review. I'll leave #1957 open to track that remaining work, as noted in the PR description. Let me know if you'd prefer it handled differently.

@theakshaypant

Copy link
Copy Markdown
Member

/ok-to-test

zakisk pushed a commit to pujitha24/pipelines-as-code that referenced this pull request Aug 11, 2026
… in test switch

Addresses review nit on PR tektoncd#2904: use the existing CompletedStatus
constant for the completed case, matching the queuedStatus constant
already used in the same switch.

Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
@zakisk

zakisk commented Aug 11, 2026

Copy link
Copy Markdown
Member

/ok-to-test

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.66%. Comparing base (d799937) to head (ade1510).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2904   +/-   ##
=======================================
  Coverage   80.66%   80.66%           
=======================================
  Files         164      164           
  Lines       13910    13910           
=======================================
  Hits        11221    11221           
  Misses       1967     1967           
  Partials      722      722           
Flag Coverage Δ
unit-tests 80.66% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pujitha24

Copy link
Copy Markdown
Contributor Author

Could a maintainer add the ok-to-test label when you get a chance? The e2e jobs are all waiting on it — happy to fix anything they surface.

@chmouel

chmouel commented Aug 12, 2026

Copy link
Copy Markdown
Member

/ok-to-test

zakisk pushed a commit to pujitha24/pipelines-as-code that referenced this pull request Aug 14, 2026
… in test switch

Addresses review nit on PR tektoncd#2904: use the existing CompletedStatus
constant for the completed case, matching the queuedStatus constant
already used in the same switch.

Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
@zakisk

zakisk commented Aug 14, 2026

Copy link
Copy Markdown
Member

/ok-to-test

pujitha24 added a commit to pujitha24/pipelines-as-code that referenced this pull request Aug 14, 2026
… in test switch

Addresses review nit on PR tektoncd#2904: use the existing CompletedStatus
constant for the completed case, matching the queuedStatus constant
already used in the same switch.

Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
@pujitha24

Copy link
Copy Markdown
Contributor Author

For anyone re-triggering this: the nine failing e2e tests legs aren't a test failure. They all stop at step 3, "Check user permissions on PRs" (pipelines-as-code/ok-to-test@v1, gated on TARGET_TEAM_SLUGS), and every step after it is skipped — hence the uniform 13-26s failures. That check is team-membership based, so the /ok-to-test comments above don't satisfy it and re-running won't change the result while I'm outside the org.

Flagging it so nobody spends more time re-triggering. The diff itself is test-only (asserting queued check-run status for pending PipelineRuns) and unit tests pass. Happy to leave this open or close it, whichever is less overhead for you.

zakisk pushed a commit to pujitha24/pipelines-as-code that referenced this pull request Aug 19, 2026
… in test switch

Addresses review nit on PR tektoncd#2904: use the existing CompletedStatus
constant for the completed case, matching the queuedStatus constant
already used in the same switch.

Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
@zakisk

zakisk commented Aug 19, 2026

Copy link
Copy Markdown
Member

/ok-to-test

@zakisk

zakisk commented Aug 19, 2026

Copy link
Copy Markdown
Member

For anyone re-triggering this: the nine failing e2e tests legs aren't a test failure. They all stop at step 3, "Check user permissions on PRs" (pipelines-as-code/ok-to-test@v1, gated on TARGET_TEAM_SLUGS), and every step after it is skipped — hence the uniform 13-26s failures. That check is team-membership based, so the /ok-to-test comments above don't satisfy it and re-running won't change the result while I'm outside the org.

Flagging it so nobody spends more time re-triggering. The diff itself is test-only (asserting queued check-run status for pending PipelineRuns) and unit tests pass. Happy to leave this open or close it, whichever is less overhead for you.

yeah, only unit test are required. triggered

@zakisk

zakisk commented Aug 19, 2026

Copy link
Copy Markdown
Member

/ok-to-test

@zakisk

zakisk commented Aug 20, 2026

Copy link
Copy Markdown
Member

/test go-testing

@zakisk

zakisk commented Aug 25, 2026

Copy link
Copy Markdown
Member

/ok-to-test

Motivation:
The check-run mock in pkg/pipelineascode/pipelineascode_test.go only
asserted on a check-run write when its status was "completed", silently
ignoring any other status (e.g. "queued"). Two testcases -
"pull request/pipelinerun created in pending state (state changed by
other controller)" and its "without installationID" variant - exercise
a PipelineRun left in the Pending spec state, which never reaches
"completed" in this code path (it only ever emits a "queued" check-run
with the queuing-template text). Because those two testcases also left
finalStatus/finalStatusText unset, they passed without validating
anything at all.

Approach:
Added an opt-in queuedStatusText field to the testcase struct and a
matching parameter to testSetupCommonGhReplies. The check-run handler
now switches on status: the existing "completed" assertion is
unchanged, and a new "queued" case asserts the check-run text contains
queuedStatusText, but only when that field is non-empty - so none of
the other testcases change behavior. The two pending-PipelineRun
testcases now set queuedStatusText to "has been queued", closing the
specific vacuous-assertion gap. This is a targeted fix, not the full
per-status-transition refactor also suggested for this test file;
splitting the table-driven test into smaller individual tests is left
out of scope.

Note the "queued" status is also used by an unrelated access-denied
flow ("pending approval, waiting for an /ok-to-test") in
pkg/pipelineascode/match.go, so the assertion is opt-in rather than
unconditional to avoid asserting an unrelated message text on that
path.

Validation:
- go build ./...
- go test ./pkg/pipelineascode/... (full package, including TestRun)
- go vet ./pkg/pipelineascode/...
- gofmt -l and gofumpt -l on the changed file (clean)
- Confirmed the new assertion has teeth: temporarily corrupted the
  "queued" status text in pkg/formatting/templates/queuing.go.tmpl
  (the HTML template actually used by the GitHub provider) and
  reran the two pending-PipelineRun subtests, which failed with a
  clear assertion message; restored the template and reran to
  confirm they pass again.

Report: tektoncd#1957
Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
@zakisk

zakisk commented Aug 31, 2026

Copy link
Copy Markdown
Member

/ok-to-test

@zakisk

zakisk commented Aug 31, 2026

Copy link
Copy Markdown
Member

/test go-testing

Comment on lines 90 to 106
// We create multiple statuses over the life of a testcase (e.g. queued,
// in_progress, completed), but "completed" is the only one guaranteed to
// be sent for every testcase, so it's asserted unconditionally. PipelineRuns
// left pending by an external controller never reach "completed" here, so
// testcases that expect that outcome opt into checking the "queued" status
// text instead via queuedStatusText.
switch created.GetStatus() {
case CompletedStatus:
assert.Equal(t, created.GetConclusion(), finalStatus, "we got the status `%s` but we should have get the status `%s`", created.GetConclusion(), finalStatus)
assert.Assert(t, strings.Contains(created.GetOutput().GetText(), finalStatusText),
"GetStatus/CheckRun %s != %s", created.GetOutput().GetText(), finalStatusText)
case queuedStatus:
if queuedStatusText != "" {
assert.Assert(t, strings.Contains(created.GetOutput().GetText(), queuedStatusText),
"GetStatus/CheckRun queued text %q does not contain %q", created.GetOutput().GetText(), queuedStatusText)
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this can be flattened — the nested if inside the queued case only exists to make that assertion opt-in, which two plain guard clauses express more directly than a switch:

Suggested change
// We create multiple statuses over the life of a testcase (e.g. queued,
// in_progress, completed), but "completed" is the only one guaranteed to
// be sent for every testcase, so it's asserted unconditionally. PipelineRuns
// left pending by an external controller never reach "completed" here, so
// testcases that expect that outcome opt into checking the "queued" status
// text instead via queuedStatusText.
switch created.GetStatus() {
case CompletedStatus:
assert.Equal(t, created.GetConclusion(), finalStatus, "we got the status `%s` but we should have get the status `%s`", created.GetConclusion(), finalStatus)
assert.Assert(t, strings.Contains(created.GetOutput().GetText(), finalStatusText),
"GetStatus/CheckRun %s != %s", created.GetOutput().GetText(), finalStatusText)
case queuedStatus:
if queuedStatusText != "" {
assert.Assert(t, strings.Contains(created.GetOutput().GetText(), queuedStatusText),
"GetStatus/CheckRun queued text %q does not contain %q", created.GetOutput().GetText(), queuedStatusText)
}
}
// "completed" is asserted unconditionally; "queued" is opt-in via queuedStatusText,
// since PipelineRuns left pending by another controller never reach "completed" here.
status := created.GetStatus()
if status == CompletedStatus {
assert.Equal(t, created.GetConclusion(), finalStatus, "we got the status `%s` but we should have get the status `%s`", created.GetConclusion(), finalStatus)
assert.Assert(t, strings.Contains(created.GetOutput().GetText(), finalStatusText),
"GetStatus/CheckRun %s != %s", created.GetOutput().GetText(), finalStatusText)
}
if status == queuedStatus && queuedStatusText != "" {
assert.Assert(t, strings.Contains(created.GetOutput().GetText(), queuedStatusText),
"GetStatus/CheckRun queued text %q does not contain %q", created.GetOutput().GetText(), queuedStatusText)
}

assert.Assert(t, strings.Contains(created.GetOutput().GetText(), finalStatusText),
"GetStatus/CheckRun %s != %s", created.GetOutput().GetText(), finalStatusText)
case queuedStatus:
if queuedStatusText != "" {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

queuedStatusText only validates the payload if a queued request happens to arrive. If a regression stops emitting the queued check-run entirely, this handler is never invoked for that status and both pending-state tests still pass. Please record whether the expected queued update was received and assert that after Run completes, so these tests verify both the request and its text.

…us was sent

Flattens the completed/queued check into two guard clauses per review
feedback, and has testSetupCommonGhReplies report whether a queued
check-run request was actually received so the pending-state testcases
fail if that update stops being sent, instead of only validating its
text when one happens to arrive.

Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
@pujitha24

Copy link
Copy Markdown
Contributor Author

Fixed both. Flattened the switch into two guard clauses like you suggested, and testSetupCommonGhReplies now returns a closure that reports whether a queued check-run was actually received — the pending-state cases assert that after Run returns, so they'd fail if the queued update stopped being sent entirely, not just if its text were wrong.

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.

6 participants