Skip to content

Route add_comment to PR review thread replies on pull_request_review_comment triggers (including relayed workflow contexts)#27838

Merged
pelikhan merged 4 commits intomainfrom
copilot/fix-reply-comment-thread
Apr 22, 2026
Merged

Route add_comment to PR review thread replies on pull_request_review_comment triggers (including relayed workflow contexts)#27838
pelikhan merged 4 commits intomainfrom
copilot/fix-reply-comment-thread

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 22, 2026

add_comment was posting top-level PR comments even when invoked from an inline review comment trigger, which detached agent responses from the review thread. This change makes default add_comment behavior thread-aware for pull_request_review_comment events.

  • Handler behavior update

    • In actions/setup/js/add_comment.cjs, add_comment now detects:
      • effective pull_request_review_comment context
      • no explicit item_number in the message
    • In that path, it replies to the triggering review comment via pulls.createReplyForReviewComment(...) instead of issues.createComment(...).
  • Relayed context support added

    • add_comment now resolves effective event context for forwarded invocations, including:
      • workflow_dispatch relays using inputs.event_name + inputs.event_payload
      • workflow_call/relay cases using inputs.aw_context fallback
    • This ensures inline review-thread replies still work when the original trigger context is forwarded rather than native.
  • Explicit target override preserved

    • If item_number is explicitly provided, behavior remains unchanged: add_comment posts a top-level issue/PR comment using issues.createComment(...).
  • Coverage added for routing and relayed contexts

    • In actions/setup/js/add_comment.test.cjs, added focused tests for:
      • inline reply routing on native pull_request_review_comment without explicit item_number
      • top-level comment behavior when explicit item_number is provided
      • inline reply routing when pull_request_review_comment context is forwarded via workflow_dispatch inputs
      • inline reply routing when context is forwarded via workflow_call aw_context
if (effectiveContext.eventName === "pull_request_review_comment" && explicitItemNumber === undefined) {
  await githubClient.rest.pulls.createReplyForReviewComment({
    owner,
    repo,
    pull_number: itemNumber,
    comment_id: Number(effectiveContext.payload?.comment?.id),
    body: processedBody,
  });
}

Copilot AI changed the title [WIP] Fix add_comment to reply in pull request review thread Route add_comment to PR review thread replies on pull_request_review_comment triggers Apr 22, 2026
Copilot AI requested a review from pelikhan April 22, 2026 13:46
Comment thread actions/setup/js/add_comment.cjs Outdated
});
comment = data;
const shouldReplyToTriggeringPRReviewComment = context.eventName === "pull_request_review_comment" && explicitItemNumber === undefined;
const triggeringReviewCommentId = Number(context.payload?.comment?.id);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot handle context that may be coming from workflow_dispatch or workflow_call

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Implemented in 76dff46 (plus precedence clarification in 9f90ce8). add_comment now resolves relayed context for workflow_dispatch and workflow_call (via aw_context) and correctly replies inline to the triggering PR review comment when applicable.

@pelikhan pelikhan marked this pull request as ready for review April 22, 2026 13:54
Copilot AI review requested due to automatic review settings April 22, 2026 13:54
@github-actions github-actions Bot mentioned this pull request Apr 22, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates add_comment so that when invoked from a pull_request_review_comment trigger (and no explicit item_number is supplied), it replies inline in the originating review thread instead of posting a detached top-level PR comment.

Changes:

  • Route add_comment to pulls.createReplyForReviewComment(...) for pull_request_review_comment events when item_number isn’t explicitly provided.
  • Preserve existing top-level comment behavior when item_number is explicitly provided.
  • Add targeted tests to verify inline-reply routing vs explicit top-level routing.
Show a summary per file
File Description
actions/setup/js/add_comment.cjs Adds thread-aware routing logic for pull_request_review_comment triggers with fallback to top-level comments.
actions/setup/js/add_comment.test.cjs Adds tests validating inline reply behavior and explicit override behavior.

Copilot's findings

Tip

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Comment thread actions/setup/js/add_comment.cjs Outdated
Comment on lines +620 to +630
const shouldReplyToTriggeringPRReviewComment = context.eventName === "pull_request_review_comment" && explicitItemNumber === undefined;
const triggeringReviewCommentId = Number(context.payload?.comment?.id);

if (shouldReplyToTriggeringPRReviewComment && Number.isInteger(triggeringReviewCommentId) && triggeringReviewCommentId > 0) {
core.info(`Replying inline to triggering PR review comment ID: ${triggeringReviewCommentId}`);
const { data } = await githubClient.rest.pulls.createReplyForReviewComment({
owner: repoParts.owner,
repo: repoParts.repo,
pull_number: itemNumber,
comment_id: triggeringReviewCommentId,
body: processedBody,
@github-actions
Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel Report

Test Quality Score: 75/100

⚠️ Acceptable — with suggestions

Metric Value
New/modified tests analyzed 2
✅ Design tests (behavioral contracts) 2 (100%)
⚠️ Implementation tests (low value) 0 (0%)
Tests with error/edge cases 1 (50%)
Duplicate test clusters 0
Test inflation detected Yes (114 / 26 = 4.38× — exceeds 2:1 threshold)
🚨 Coding-guideline violations 0

Test Classification Details

View Per-Test Classification
Test File Classification Issues Detected
should reply inline to triggering PR review comment when item_number is not provided actions/setup/js/add_comment.test.cjs:363 ✅ Design Happy-path only; fallback (invalid comment ID) not covered; no assertion messages
should keep top-level comment behavior for pull_request_review_comment when item_number is explicitly provided actions/setup/js/add_comment.test.cjs:430 ✅ Design Explicitly tests override edge case (explicit item_number bypasses routing); no assertion messages

Flagged Tests — Requires Review

⚠️ Test inflation (add_comment.test.cjs)

Issue: 114 lines added to the test file vs. 26 lines added to the production file (4.38:1 ratio, threshold 2:1).

Context: The production change introduces a branching decision with 3 code paths, and two of the three are tested. The high line count is partly explained by verbose mock setup in each test (re-declaring createReplyForReviewComment and createComment inline rather than sharing a helper). This is a style concern more than a quality concern — the tests themselves are behaviorally sound.

Suggestion: Extract shared mock setup into a local helper or use beforeEach to reduce per-test boilerplate.


⚠️ Missing edge case: invalid/absent comment ID fallback (add_comment.test.cjs)

Classification: Missing branch
Issue: The production code has an explicit fallback branch:

if (shouldReplyToTriggeringPRReviewComment) {
  core.warning("Triggering PR review comment ID is missing or invalid; falling back to top-level PR comment");
}
// → falls back to issues.createComment

This path is exercised when context.payload?.comment?.id is undefined, null, 0, or non-numeric. No test covers it.

What would break if undetected? If this fallback branch is broken, a pull_request_review_comment trigger with an absent comment ID would either throw or silently fail instead of posting a top-level comment.

Suggested improvement: Add a third test case:

it("should fall back to top-level PR comment when review comment ID is missing", async () => {
  mockContext.eventName = "pull_request_review_comment";
  mockContext.payload = { pull_request: { number: 8535 } }; // no comment.id

  let issueCommentCalled = false;
  let reviewReplyCalled = false;
  mockGithub.rest.issues.createComment = async params => {
    issueCommentCalled = true;
    return { data: { id: 1, html_url: "..." } };
  };
  mockGithub.rest.pulls.createReplyForReviewComment = async () => {
    reviewReplyCalled = true;
    return { data: { id: 2, html_url: "..." } };
  };

  const handler = await eval(`(async () => { \$\{addCommentScript}; return await main({ target: 'triggering' }); })()`);
  const result = await handler({ type: "add_comment", body: "fallback test" }, {});

  expect(result.success, "should succeed even with missing comment ID").toBe(true);
  expect(issueCommentCalled, "should fall back to issues.createComment").toBe(true);
  expect(reviewReplyCalled, "should not attempt inline reply").toBe(false);
  expect(warningCalls.some(m => m.includes("missing or invalid")), "should warn about fallback").toBe(true);
});

i️ Assertion messages missing

Neither new test provides descriptive messages to expect() calls (e.g., expect(result.success).toBe(true) — no message argument). While vitest allows messagelessly assertions, the project guideline asks for descriptive messages to aid debugging. Low priority, but worth aligning with the rest of the codebase.


Language Support

Tests analyzed:

  • 🟨 JavaScript (*.test.cjs): 2 tests (vitest)
  • 🐹 Go (*_test.go): 0 tests (no Go test files changed)

Score Breakdown

Component Points Earned Max Notes
Behavioral Coverage 40 40 2/2 design tests
Error/Edge Case Coverage 15 30 1/2 tests has explicit edge case (explicit item_number override); fallback branch uncovered
Low Duplication 20 20 No duplicate clusters
Proportional Growth 0 10 4.38:1 inflation ratio exceeds 2:1 threshold
Total 75 100

Verdict

Check passed. 0% of new tests are implementation tests (threshold: 30%). The two new tests verify genuine behavioral contracts — routing to inline reply vs. top-level comment — and are high value. Suggestions above (fallback branch coverage, assertion messages) would improve confidence further but do not block merging.


📖 Understanding Test Classifications

Design Tests (High Value) verify what the system does:

  • Assert on observable outputs, return values, or state changes
  • Cover error paths and boundary conditions
  • Would catch a behavioral regression if deleted
  • Remain valid even after internal refactoring

Implementation Tests (Low Value) verify how the system does it:

  • Assert on internal function calls (mocking internals)
  • Only test the happy path with typical inputs
  • Break during legitimate refactoring even when behavior is correct
  • Give false assurance: they pass even when the system is wrong

Goal: Shift toward tests that describe the system's behavioral contract — the promises it makes to its users and collaborators.

References: §24782289324

🧪 Test quality analysis by Test Quality Sentinel · ● 518.9K ·

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

✅ Test Quality Sentinel: 75/100. Test quality is acceptable — 0% of new tests are implementation tests (threshold: 30%). Both new tests verify behavioral contracts (routing to inline reply vs. top-level comment). See the comment above for suggestions on improving edge case coverage (missing comment ID fallback path).

@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot review all comments

Copilot AI and others added 2 commits April 22, 2026 14:27
Copilot AI changed the title Route add_comment to PR review thread replies on pull_request_review_comment triggers Route add_comment to PR review thread replies on pull_request_review_comment triggers (including relayed workflow contexts) Apr 22, 2026
Copilot AI requested a review from pelikhan April 22, 2026 14:32
@pelikhan pelikhan merged commit 191f28e into main Apr 22, 2026
39 checks passed
@pelikhan pelikhan deleted the copilot/fix-reply-comment-thread branch April 22, 2026 14:49
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.

add_comment: reply to pull_request_review_comment in the review thread, not at PR level

3 participants