Skip to content

[jsweep] Clean add_labels.cjs#22366

Merged
pelikhan merged 3 commits intomainfrom
jsweep/add-labels-cleanup-869ba564f0c6992b
Mar 23, 2026
Merged

[jsweep] Clean add_labels.cjs#22366
pelikhan merged 3 commits intomainfrom
jsweep/add-labels-cleanup-869ba564f0c6992b

Conversation

@github-actions
Copy link
Contributor

Summary

Analyzed and improved add_labels.cjs (github-script context handler for adding labels to issues/PRs).

Analysis

The add_labels.cjs file is already clean and modern — @ts-check enabled, optional chaining, proper JSDoc types, no unnecessary try/catch. The HANDLER_TYPE constant, while seemingly unused in logic, is intentionally required by the safe_outputs_type_validation.test.cjs type-marker test and must be retained.

The main opportunity was test coverage gaps for three untested code paths.

Changes

add_labels.test.cjs — Added 4 new tests (25 → 29 tests):

New Test What it covers
should preview labels in staged mode without calling API Staged mode returns { success: true, staged: true, previewInfo } without making GitHub API call
should count staged calls toward processedCount Staged mode still increments processedCount, enforcing the max limit
should filter out labels matching blocked patterns blocked: ["internal-*", "~*"] correctly removes matching labels while keeping valid ones
should succeed with empty labelsAdded when all labels filtered by allowed list When all requested labels are not in the allowed list, returns { success: true, labelsAdded: [], message: "No valid labels found" }

Context

  • Execution context: github-script (uses core, github, context globals)
  • Key dependencies: validateLabels, isStagedMode, resolveAndValidateRepo, tryEnforceArrayLimit

Validation ✅

All checks passed:

  • Formatting: npm run format:cjs
  • Linting: npm run lint:cjs
  • Type checking: npm run typecheck
  • Tests: npx vitest run add_labels.test.cjs safe_outputs_type_validation.test.cjs — 42 tests passed ✓

Warning

**⚠️ Firewall blocked 2 domains**

The following domains were blocked by the firewall during workflow execution:

  • invalid.example.invalid
  • proxy.golang.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "invalid.example.invalid"
    - "proxy.golang.org"

See Network Configuration for more information.

Generated by jsweep - JavaScript Unbloater ·

  • expires on Mar 25, 2026, 3:26 AM UTC

…ltered labels

- Add test for staged mode preview without calling API
- Add test that staged calls count toward processedCount limit
- Add test for blocked pattern filtering (removes matching labels)
- Add test for when all labels are filtered out by allowed list (succeeds with empty labelsAdded)

Total: 25 → 29 tests for add_labels handler

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

Improves confidence in the add_labels.cjs handler by adding tests for previously untested execution paths (staged mode behavior and label filtering scenarios).

Changes:

  • Added tests verifying staged mode returns preview info and does not call the GitHub API.
  • Added tests ensuring staged mode still counts toward the max processed limit.
  • Added tests covering blocked-pattern filtering and the “no valid labels” success path.

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

);

expect(result.success).toBe(true);
expect(result.labelsAdded).toEqual(["bug", "enhancement"]);
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

This test assumes the GitHub API is called exactly once, but it never asserts the call count. Adding an explicit assertion (e.g., that addLabelsCalls has length 1) would prevent the test from passing if the handler accidentally performs multiple addLabels calls.

Suggested change
expect(result.labelsAdded).toEqual(["bug", "enhancement"]);
expect(result.labelsAdded).toEqual(["bug", "enhancement"]);
expect(addLabelsCalls).toHaveLength(1);

Copilot uses AI. Check for mistakes.
Comment on lines +649 to +652
expect(result.success).toBe(true);
expect(result.labelsAdded).toEqual([]);
expect(result.message).toContain("No valid labels");
});
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

This test doesn’t verify that the handler avoids calling github.rest.issues.addLabels when no valid labels remain after filtering. Consider stubbing addLabels (as in other tests) and asserting it was not called, so the behavior remains protected against regressions.

Copilot uses AI. Check for mistakes.
@pelikhan
Copy link
Contributor

Copy link
Contributor

Copilot AI commented Mar 23, 2026

@copilot fix https://github.com/github/gh-aw/actions/runs/23420415449/job/68124164769

Fixed in fd58d1d. The TestLabelTriggerIntegrationSimple failure was a mismatch in label_trigger_parser.go where item_number was set to required: false but the test expected required: true. Changed it to required: true (also removed the now-unnecessary default: "") and recompiled the affected lock file (refiner.lock.yml).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw (http block)
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw 2dnbhUlAbVwI (http block)
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw ire (http block)
  • https://api.github.com/repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b
    • Triggering command: /usr/bin/gh gh api /repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b --jq .object.sha h ../../../.pret.prettierignore (http block)
  • https://api.github.com/repos/github/gh-aw
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw --jq .visibility (http block)
  • https://api.github.com/repos/githubnext/agentics/git/ref/tags/
    • Triggering command: /usr/bin/gh gh api /repos/githubnext/agentics/git/ref/tags/# --jq .object.sha (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from pelikhan March 23, 2026 03:54
@pelikhan
Copy link
Contributor

…se for item_number input

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/531637cf-d8c8-415b-8b02-277e0e917422
Copy link
Contributor

Copilot AI commented Mar 23, 2026

@copilot fix https://github.com/github/gh-aw/actions/runs/23420694869/job/68125125011

Fixed in 62acaad. The issue was that TestLabelTriggerIntegrationSimple had an incorrect assertion expecting required: true, while both the production code and TestExpandLabelTriggerShorthand unit tests use required: false. Fixed the integration test to match the actual behavior. label_trigger_parser.go and refiner.lock.yml are back to their original state.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw (http block)
    • Triggering command: /usr/bin/gh /usr/bin/gh api graphql -f query=query($owner: String!, $name: String!) { repository(owner: $owner, name: $name) { hasDiscussionsEnabled } } -f owner=github -f name=gh-aw /tmp/go-build3850348696/b001/importcfg -pack /tmp/go-build3850348696/b001/_testmain.go (http block)
  • https://api.github.com/repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b
    • Triggering command: /usr/bin/gh gh api /repos/astral-sh/setup-uv/git/ref/tags/eac588ad8def6316056a12d4907a9d4d84ff7a3b --jq .object.sha (http block)
  • https://api.github.com/repos/github/gh-aw
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw --jq .visibility (http block)
  • https://api.github.com/repos/githubnext/agentics/git/ref/tags/
    • Triggering command: /usr/bin/gh gh api /repos/githubnext/agentics/git/ref/tags/# --jq .object.sha (http block)

If you need me to access, download, or install something from one of these locations, you can either:

@pelikhan pelikhan merged commit 2d7781d into main Mar 23, 2026
53 checks passed
@pelikhan pelikhan deleted the jsweep/add-labels-cleanup-869ba564f0c6992b branch March 23, 2026 04:23
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