Skip to content

[jsweep] Clean add_labels.cjs#35134

Merged
pelikhan merged 3 commits into
mainfrom
signed/jsweep/add-labels-20260527-2ed4d0f9c3682ac1
May 27, 2026
Merged

[jsweep] Clean add_labels.cjs#35134
pelikhan merged 3 commits into
mainfrom
signed/jsweep/add-labels-20260527-2ed4d0f9c3682ac1

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

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

Summary

Improves test coverage for actions/setup/js/add_labels.cjs by adding missing test cases identified during review. No production code was changed.

What changed

actions/setup/js/add_labels.test.cjs (tests only)

  • Added test cases for required_labels filtering behaviour
  • Added test cases for required_title_prefix filtering behaviour
  • Added combined required_labels + required_title_prefix checks to cover interaction between the two filters
  • Updated the default mock to include an issues.get stub that returns both title and labels, enabling the new test scenarios

Why

Prior coverage did not exercise the combined filter path — a PR could satisfy one filter but not the other, and that logic was untested. These additions close the gap surfaced in review feedback.

Testing

All changes are in the test file itself. Run the existing JS test suite to verify:

cd actions/setup/js && npm test

Notes

  • No production logic was modified
  • No breaking changes
  • Scope is limited to a single test file (add_labels.test.cjs)

Generated by PR Description Updater for issue #35134 · sonnet46 894.9K ·

Add tests for required_labels and required_title_prefix filter features,
and add issues.get mock to default setup for these scenarios.

- Add mockGithub.rest.issues.get default mock in beforeEach
- Add 6 new tests covering required_labels filtering (pass/fail)
- Add tests covering required_title_prefix filtering (pass/fail)
- Add test for combined required_labels + required_title_prefix
- Total: 39 → 45 tests (6 added)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review May 27, 2026 10:02
Copilot AI review requested due to automatic review settings May 27, 2026 10:02
@github-actions
Copy link
Copy Markdown
Contributor Author

github-actions Bot commented May 27, 2026

🧪 Test Quality Sentinel completed test quality analysis.

@github-actions
Copy link
Copy Markdown
Contributor Author

github-actions Bot commented May 27, 2026

PR Code Quality Reviewer completed the code quality review.

@github-actions
Copy link
Copy Markdown
Contributor Author

github-actions Bot commented May 27, 2026

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

@github-actions
Copy link
Copy Markdown
Contributor Author

github-actions Bot commented May 27, 2026

Design Decision Gate 🏗️ completed the design decision gate check.

No ADR enforcement needed: PR #35134 does not have the 'implementation' label and has 0 new lines of code in default business logic directories (threshold: 100).

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

This PR improves unit test coverage for the add_labels handler by adding coverage for the required_labels and required_title_prefix filter paths that require github.rest.issues.get.

Changes:

  • Added a default mockGithub.rest.issues.get implementation in the shared beforeEach test setup.
  • Added new tests covering required-label and required-title-prefix filtering behavior (skip vs add labels), including a combined filter scenario.
Show a summary per file
File Description
actions/setup/js/add_labels.test.cjs Adds default issues.get mock and new tests for required_labels / required_title_prefix filter behavior.

Copilot's findings

Tip

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

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

Comment on lines +868 to +872
it("should skip when item does not have all required_labels", async () => {
const handler = await main({ max: 10, required_labels: ["needs-triage"] });

mockGithub.rest.issues.get = async () => ({
data: { title: "Some issue", labels: [{ name: "bug" }] },
@github-actions github-actions Bot mentioned this pull request May 27, 2026
@github-actions
Copy link
Copy Markdown
Contributor Author

🧪 Test Quality Sentinel Report

⚠️ Test Quality Score: 78/100 — Acceptable

Analyzed 5 new JavaScript test(s) in add_labels.test.cjs: 5 design tests, 0 implementation tests, 0 guideline violations.

📊 Metrics & Test Classification (5 tests analyzed)
Metric Value
New/modified tests analyzed 5
✅ Design tests (behavioral contracts) 5 (100%)
⚠️ Implementation tests (low value) 0 (0%)
Tests with error/edge cases 3 (60%)
Duplicate test clusters 0
Test inflation detected ⚠️ Yes (89 lines added to test, 0 to production — PR purpose is test-only coverage)
🚨 Coding-guideline violations 0

Test Classification Details

Test File Classification Issues Detected
should skip when item does not have all required_labels add_labels.test.cjs ✅ Design Verifies skip+error path
should add labels when item has all required_labels add_labels.test.cjs ✅ Design Happy-path only; API side-effect asserted via call capture
should skip when item title does not start with required_title_prefix add_labels.test.cjs ✅ Design Verifies skip+error path
should add labels when item title starts with required_title_prefix add_labels.test.cjs ✅ Design Happy-path only; API side-effect asserted via call capture
should check both required_labels and required_title_prefix together add_labels.test.cjs ✅ Design Verifies combined-condition edge case (one passes, one fails)

Language Support

Tests analyzed:

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

Verdict

Check passed. 0% of new tests are implementation tests (threshold: 30%). All 5 new tests verify observable behavioral contracts for the required_labels and required_title_prefix filtering features.

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

🧪 Test quality analysis by Test Quality Sentinel · sonnet46 1.5M ·

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: 78/100. Test quality is acceptable — 0% of new tests are implementation tests (threshold: 30%).

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 /tdd — approving with minor suggestions on assertion completeness.

📋 Key Themes & Highlights

Observations

  • Payload not asserted: The two "should add labels" tests verify that addLabels was called but not what labels were passed. Adding expect(addLabelsCalls[0].labels).toEqual([...]) would make each test a full specification.
  • Combined-filter happy path missing: The combined required_labels + required_title_prefix test only exercises the failure branch; a matching success case would complete the coverage.

Positive Highlights

  • ✅ Good breadth: all four skip/pass branches of both filters are individually covered
  • beforeEach correctly updated so the default get mock doesn't break existing tests
  • ✅ Clear, readable test names and well-structured Arrange / Act / Assert flow
  • ✅ All 45 tests passing, linting and type-check clean

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 1.4M

addLabelsCalls.push(params);
return {};
};

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.

[/tdd] The assertion only checks that addLabels was called once, not which labels were sent — a bug passing the wrong labels would still pass this test.

💡 Suggested addition
expect(addLabelsCalls[0].labels).toEqual(["enhancement"]);

This makes the test a true specification: it verifies both that the action was taken and that the correct payload was used.

mockGithub.rest.issues.addLabels = async params => {
addLabelsCalls.push(params);
return {};
};
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.

[/tdd] Same as above — addLabelsCalls.length === 1 confirms invocation but not the payload.

💡 Suggested addition
expect(addLabelsCalls[0].labels).toEqual(["automation"]);

data: { title: "Not ready issue", labels: [{ name: "approved" }] },
});

const result = await handler({ item_number: 100, labels: ["bug"] }, {});
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.

[/tdd] The combined-filter test only covers the "passes labels, fails prefix" path. Consider adding a case where both conditions are satisfied to confirm the happy path works end-to-end with both filters active.

💡 Sketch
it("should add labels when both required_labels and required_title_prefix match", async () => {
  const handler = await main({
    max: 10,
    required_labels: ["approved"],
    required_title_prefix: "[Ready]",
  });
  const addLabelsCalls = [];

  mockGithub.rest.issues.get = async () => ({
    data: { title: "[Ready] Deploy v2", labels: [{ name: "approved" }] },
  });
  mockGithub.rest.issues.addLabels = async params => {
    addLabelsCalls.push(params);
    return {};
  };

  const result = await handler({ item_number: 100, labels: ["deploy"] }, {});

  expect(result.success).toBe(true);
  expect(addLabelsCalls.length).toBe(1);
});

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.

COMMENT — test-only changes, no production code modified; one non-blocking gap in combined-filter coverage.

### Findings

Non-blocking: The combined required_labels + required_title_prefix test only exercises one failure mode (labels pass, prefix fails). The "both conditions satisfied → labels added" happy path is not covered under the combined config, which means a regression that erroneously skips when both filters are present would not be caught. Suggested fix included in the inline comment.

Already flagged (existing review): PR description claims +6 tests but the diff adds 5.

🔎 Code quality review by PR Code Quality Reviewer · sonnet46 1.5M

expect(result.success).toBe(false);
expect(result.skipped).toBe(true);
expect(result.error).toContain("required prefix");
});
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.

Combined-filter test is missing the "both conditions pass" happy path, leaving a gap in AND-semantics coverage.

💡 Details

The only combined-config test covers: required_labels ✅ + required_title_prefix ❌ → skipped.

Two paths are untested under the combined config:

  1. labels-fail, prefix-pass — a production bug that skips the labels check when a prefix is also configured would go undetected (the standalone required_labels test uses a config without a prefix, so it can't catch combined-mode regressions).
  2. both pass — no combined-config test verifies that labels are actually added when both filters are satisfied. A bug that erroneously returns skipped: true in the combined path would pass all current tests.

Suggested addition:

it("should add labels when both required_labels and required_title_prefix are satisfied", async () => {
  const handler = await main({
    max: 10,
    required_labels: ["approved"],
    required_title_prefix: "[Ready]",
  });
  mockGithub.rest.issues.get = async () => ({
    data: { title: "[Ready] Approved issue", labels: [{ name: "approved" }] },
  });
  const result = await handler({ item_number: 100, labels: ["bug"] }, {});
  expect(result.success).toBe(true);
  expect(result.skipped).toBeUndefined();
});

@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot review all comments

Copilot AI and others added 2 commits May 27, 2026 10:26
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented May 27, 2026

@copilot review all comments

Reviewed the thread and pushed a follow-up in 33c9269 to address the outstanding mismatch by adding the missing test case (combined required_labels + required_title_prefix success path).

Copilot AI requested a review from pelikhan May 27, 2026 10:30
@pelikhan pelikhan merged commit 31df422 into main May 27, 2026
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