Skip to content

[jsweep] Clean add_reaction_and_edit_comment.cjs#30756

Merged
pelikhan merged 2 commits intomainfrom
jsweep/add-reaction-and-edit-comment-b8ed33c4970c1183
May 7, 2026
Merged

[jsweep] Clean add_reaction_and_edit_comment.cjs#30756
pelikhan merged 2 commits intomainfrom
jsweep/add-reaction-and-edit-comment-b8ed33c4970c1183

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented May 7, 2026

Summary

Cleaned actions/setup/js/add_reaction_and_edit_comment.cjs as part of the jsweep unbloat initiative.

Changes

Context: github-script

This file runs in the github-script action context with access to core, github, and context globals.

Code Improvements

  • Extracted resolveEventEndpoints() helper — The 90-line switch statement in main() was extracted into a dedicated async function that returns {reactionEndpoint, commentUpdateEndpoint} | null, making main() cleaner and the endpoint logic independently testable
  • Module-level VALID_REACTIONS constant — Moved from inside main() to module scope where it belongs; it never changes between calls
  • Removed redundant if (commentUpdateEndpoint) guard — After the refactored switch, commentUpdateEndpoint is always set (all returning paths are handled by resolveEventEndpoints returning null), so the guard was unnecessary
  • Added Record<string, string> type annotation to EVENT_TYPE_DESCRIPTIONS for clarity
  • Exported resolveEventEndpoints and VALID_REACTIONS to enable direct unit testing

Test Improvements

Added 9 new tests (35 → 44 total):

  • resolveEventEndpoints() for issues, pull_request, issue_comment, pull_request_review_comment, discussion, discussion_comment events
  • resolveEventEndpoints() returns null + calls setFailed when required fields missing
  • resolveEventEndpoints() returns null for unknown event type
  • VALID_REACTIONS exports the expected list

Validation

  • Formatting: npm run format:cjs
  • Linting: npm run lint:cjs
  • Type checking: npm run typecheck
  • Tests: npm run test:js44 tests passed

Generated by jsweep - JavaScript Unbloater · ● 16.2M ·

  • expires on May 9, 2026, 4:54 AM UTC

- Extract large switch statement into resolveEventEndpoints() helper
- Move validReactions to module-level VALID_REACTIONS constant
- Remove redundant if (commentUpdateEndpoint) guard after switch
- Add explicit Record<string, string> type for EVENT_TYPE_DESCRIPTIONS
- Export resolveEventEndpoints and VALID_REACTIONS for direct testing
- Add 9 new tests for resolveEventEndpoints and VALID_REACTIONS (35 → 44)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review May 7, 2026 14:40
Copilot AI review requested due to automatic review settings May 7, 2026 14:40
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

Refactors add_reaction_and_edit_comment.cjs to reduce complexity and improve testability as part of the jsweep unbloat initiative, while expanding unit test coverage for the new extraction points.

Changes:

  • Extracted event-to-endpoint resolution into resolveEventEndpoints() and exported it for direct testing.
  • Moved the reaction allowlist to a module-level exported VALID_REACTIONS constant and simplified main() accordingly.
  • Added targeted unit tests for resolveEventEndpoints() across supported events and for VALID_REACTIONS.
Show a summary per file
File Description
actions/setup/js/add_reaction_and_edit_comment.cjs Extracts endpoint resolution into a helper, promotes reaction allowlist to module scope, and exports both for testing.
actions/setup/js/add_reaction_and_edit_comment.test.cjs Adds tests for the new exports and verifies endpoint resolution behavior for multiple event types and error cases.

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

};

/** Valid GitHub reaction types */
const VALID_REACTIONS = ["+1", "-1", "laugh", "confused", "heart", "hooray", "rocket", "eyes"];
@github-actions github-actions Bot mentioned this pull request May 7, 2026
@github-actions
Copy link
Copy Markdown
Contributor Author

github-actions Bot commented May 7, 2026

🧪 Test Quality Sentinel Report

Test Quality Score: 77/100

⚠️ Acceptable, with suggestions

Metric Value
New/modified tests analyzed 9
✅ Design tests (behavioral contracts) 9 (100%)
⚠️ Implementation tests (low value) 0 (0%)
Tests with error/edge cases 2 (22%)
Duplicate test clusters 0
Test inflation detected No
🚨 Coding-guideline violations None

Test Classification Details

View all 9 test classifications
Test File Classification Issues Detected
should export the list of valid reaction types add_reaction_and_edit_comment.test.cjs ✅ Design None — verifies exported constant value
should resolve endpoints for issues event add_reaction_and_edit_comment.test.cjs ✅ Design Happy-path only
should return null and call setFailed when issue number is missing add_reaction_and_edit_comment.test.cjs ✅ Design ✅ Error/edge case covered
should resolve endpoints for pull_request event add_reaction_and_edit_comment.test.cjs ✅ Design Happy-path only
should resolve endpoints for issue_comment event add_reaction_and_edit_comment.test.cjs ✅ Design Happy-path only
should resolve endpoints for pull_request_review_comment event add_reaction_and_edit_comment.test.cjs ✅ Design Happy-path only
should resolve endpoints for discussion event using GraphQL node ID add_reaction_and_edit_comment.test.cjs ✅ Design Uses mockGithub.graphql (acceptable: external I/O)
should resolve endpoints for discussion_comment event add_reaction_and_edit_comment.test.cjs ✅ Design Happy-path only
should return null and call setFailed for unknown event type add_reaction_and_edit_comment.test.cjs ✅ Design ✅ Error/edge case covered

Scoring Breakdown

Component Score Notes
Behavioral Coverage (40 pts) 40/40 100% design tests
Error/Edge Case Coverage (30 pts) ~7/30 2 of 9 tests cover error paths (22%)
Low Duplication (20 pts) 20/20 No copy-paste patterns detected
Proportional Growth (10 pts) 10/10 +86 test lines vs +123 production lines (ratio: 0.70)

Suggestions for Improvement

The tests are well-structured behavioral tests — they all assert on observable outputs (return values and setFailed side effects), and the resolveEventEndpoints() suite provides good coverage across all supported event types. The score penalty comes from the relatively low proportion of explicit error/edge case tests. Some suggestions:

  1. Missing-number cases for other event types: The test currently covers missing issue.number for the issues event. Consider adding similar null/missing-field tests for pull_request, issue_comment, and pull_request_review_comment events (e.g., payload missing comment.id).

  2. GraphQL failure path for discussion event: The discussion endpoint test mocks a successful GraphQL response; a test for a rejected/null GraphQL response would round out error coverage for that branch.

  3. VALID_REACTIONS constant test: Good sanity check, though consider also testing that the module rejects (or warns on) an invalid reaction string in the places that consume VALID_REACTIONS.


Language Support

Tests analyzed:

  • 🟨 JavaScript (*.test.cjs): 9 tests (vitest)

Verdict

Check passed. 0% of new tests are implementation tests (threshold: 30%). All 9 new tests assert on observable outputs and behavioral contracts. No coding-guideline violations detected.


📖 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: §25502775257

🧪 Test quality analysis by Test Quality Sentinel · ● 5.2M ·

Copy link
Copy Markdown
Contributor Author

@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: 77/100. Test quality is acceptable — 0% of new tests are implementation tests (threshold: 30%). All 9 new tests assert on observable outputs and behavioral contracts.

Copy link
Copy Markdown
Contributor Author

@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.

Skills-Based Review 🧠

Applied /zoom-out — this is a focused refactor/cleanup PR.

Key Themes

  • Missing failure-path tests: The extracted resolveEventEndpoints() has 6+ error branches that have no test coverage. The happy-path tests are solid, but the failure paths (missing IDs for issue_comment, pull_request_review_comment, discussion, and missing node_id for discussion_comment) are untested.
  • Side-effect in resolver: resolveEventEndpoints calls core.setFailed internally, coupling it to the GitHub Actions runtime. This is a minor separation-of-concerns issue — the function is testable today (with the existing mock), but a throw-based approach would make it cleaner.

Positive Highlights

  • ✅ Clean extraction of the 90-line switch into a named, independently testable function
  • VALID_REACTIONS promoted to module scope — correct move
  • ✅ Removal of the now-redundant if (commentUpdateEndpoint) guard is well-reasoned
  • ✅ Good JSDoc on the new function including return type annotation
  • ✅ Destructured assignment const { owner, repo } = invocationContext.eventRepo is a nice minor improvement

Verdict

Commenting only — no blocking issues. The failure-path test gap is the most actionable suggestion; the side-effect concern is a design preference to consider for future extractions.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · ● 3.8M

expect(mockCore.setFailed).toHaveBeenCalledWith(expect.stringContaining(ERR_VALIDATION));
});
});
});
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.

[/zoom-out] The new resolveEventEndpoints() tests cover happy paths and the most common failure cases, but several error branches remain untested:

  • issue_comment with missing commentIdERR_VALIDATION
  • issue_comment with missing issueNumberERR_NOT_FOUND
  • pull_request_review_comment with missing reviewCommentId or prNumber
  • discussion with missing discussionNumber
  • discussion_comment with missing node_id

Since the stated goal of extracting this function is to make the logic independently testable, covering these failure paths would complete the picture:

it('returns null and calls setFailed when issue_comment is missing commentId', async () => {
  const { resolveEventEndpoints } = await loadModule();
  const result = await resolveEventEndpoints('issue_comment', 'owner', 'repo', { issue: { number: 1 } });
  expect(result).toBeNull();
  expect(mockCore.setFailed).toHaveBeenCalledWith(expect.stringContaining(ERR_VALIDATION));
});

if (!issueNumber) {
core.setFailed(`${ERR_NOT_FOUND}: Issue number not found in event payload`);
return null;
}
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.

[/zoom-out] resolveEventEndpoints calls core.setFailed directly, coupling a pure endpoint-resolver to the GitHub Actions runtime. This makes the function harder to reuse or test without mocking core. Consider letting it throw a typed error and keeping the core.setFailed call in main():

// resolveEventEndpoints throws on invalid input
// main() catches and calls core.setFailed
try {
  const endpoints = await resolveEventEndpoints(eventName, owner, repo, payload);
  ...
} catch (err) {
  core.setFailed(err.message);
  return;
}

Minor point given the existing pattern in the file — feel free to defer.

@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented May 7, 2026

@copilot review all comments

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/fb12d090-f298-4a07-b4d3-b03e8e2d7d6a

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented May 7, 2026

@copilot review all comments

Applied the freeze suggestion from the review — VALID_REACTIONS is now Object.freeze([...]) (commit 5f1995f). All 44 tests still pass.

Copilot AI requested a review from pelikhan May 7, 2026 17:47
@pelikhan pelikhan merged commit 6eeb1f7 into main May 7, 2026
@pelikhan pelikhan deleted the jsweep/add-reaction-and-edit-comment-b8ed33c4970c1183 branch May 7, 2026 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants