Skip to content

[jsweep] Clean assign_to_user.cjs#19924

Merged
pelikhan merged 2 commits intomainfrom
jsweep/clean-assign-to-user-cc24bec760709146
Mar 7, 2026
Merged

[jsweep] Clean assign_to_user.cjs#19924
pelikhan merged 2 commits intomainfrom
jsweep/clean-assign-to-user-cc24bec760709146

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Mar 7, 2026

Summary

Cleaned actions/setup/js/assign_to_user.cjs as part of the daily jsweep unbloat process.

Context type: github-script (uses core, github, context globals)

Changes

assign_to_user.cjs

  • Use nullish coalescing (??) instead of logical OR (||) for config defaults (allowed, blocked, max) — semantically more precise: defaults apply only when values are null/undefined, not when they're falsy (e.g. max: 0 now correctly means "zero limit" rather than falling back to 10)

assign_to_user.test.cjs

  • Added afterEach to vitest imports (needed for cleanup)
  • Added staged mode test suite with 2 new tests:
    • Verifies that staged mode previews without executing GitHub API calls
    • Verifies that unassign_first is correctly reflected in staged mode preview info

Test Improvements

Before After
21 tests 23 tests (+2)
No staged mode coverage Staged mode fully covered

Validation ✅

All four checks passed:

  • Formatting: npm run format:cjs
  • Linting: npm run lint:cjs
  • Type checking: npm run typecheck ✓ (file already had @ts-check)
  • Tests: npm run test:js ✓ — all 23 assign_to_user tests pass

Generated by jsweep - JavaScript Unbloater ·

Warning

⚠️ Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • proxy.golang.org

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

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

See Network Configuration for more information.

  • expires on Mar 9, 2026, 3:09 AM UTC

- Use nullish coalescing (??) instead of logical OR (||) for config defaults
  (allowed, blocked, max) for more precise null/undefined handling
- Add staged mode test suite (2 new tests covering preview behavior)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review March 7, 2026 03:46
Copilot AI review requested due to automatic review settings March 7, 2026 03:46
@pelikhan pelikhan merged commit 4006bf8 into main Mar 7, 2026
50 checks passed
@pelikhan pelikhan deleted the jsweep/clean-assign-to-user-cc24bec760709146 branch March 7, 2026 03:47
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

Cleans up the assign_to_user safe-output handler defaults and expands test coverage for staged mode behavior.

Changes:

  • Updated assign_to_user.cjs config defaulting to use nullish coalescing (??) instead of ||.
  • Added a staged mode test suite (2 tests) and imported afterEach for env cleanup.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
actions/setup/js/assign_to_user.cjs Uses ?? for config defaults (allowed, blocked, max).
actions/setup/js/assign_to_user.test.cjs Adds staged-mode tests and per-suite env var cleanup.

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

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +488 to +493
beforeEach(() => {
process.env.GH_AW_SAFE_OUTPUTS_STAGED = "true";
});

afterEach(() => {
delete process.env.GH_AW_SAFE_OUTPUTS_STAGED;
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

The staged-mode tests mutate process.env.GH_AW_SAFE_OUTPUTS_STAGED and then delete it in afterEach(). If the env var had a previous value (e.g. set by another test file running in the same worker), deleting it won’t restore the original value and can cause cross-test flakiness. Align with other tests (e.g. add_reviewer.test.cjs) by capturing the original value in beforeEach and restoring it in afterEach/finally.

Suggested change
beforeEach(() => {
process.env.GH_AW_SAFE_OUTPUTS_STAGED = "true";
});
afterEach(() => {
delete process.env.GH_AW_SAFE_OUTPUTS_STAGED;
let originalGhAwSafeOutputsStaged;
beforeEach(() => {
originalGhAwSafeOutputsStaged = process.env.GH_AW_SAFE_OUTPUTS_STAGED;
process.env.GH_AW_SAFE_OUTPUTS_STAGED = "true";
});
afterEach(() => {
if (originalGhAwSafeOutputsStaged === undefined) {
delete process.env.GH_AW_SAFE_OUTPUTS_STAGED;
} else {
process.env.GH_AW_SAFE_OUTPUTS_STAGED = originalGhAwSafeOutputsStaged;
}

Copilot uses AI. Check for mistakes.
Comment on lines +26 to +28
const allowedAssignees = config.allowed ?? [];
const blockedAssignees = config.blocked ?? [];
const maxCount = config.max ?? 10;
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

config.allowed ?? [] / config.blocked ?? [] will now preserve non-nullish falsy values (e.g. false) rather than falling back to an empty array; that can lead to runtime errors later when .length / .join() are used on these variables. Consider normalizing types explicitly (e.g. only accept arrays; otherwise default to []) so misconfigured handler configs fail gracefully instead of throwing.

See below for a potential fix:

 * Normalize the max count configuration value to a non-negative finite number.
 * Falls back to the provided default if the value is nullish or invalid.
 * @param {unknown} value
 * @param {number} defaultValue
 * @returns {number}
 */
function normalizeMaxCount(value, defaultValue) {
  if (value === undefined || value === null) {
    return defaultValue;
  }
  const num = Number(value);
  if (!Number.isFinite(num) || num < 0) {
    return defaultValue;
  }
  return num;
}

/**
 * Main handler factory for assign_to_user
 * Returns a message handler function that processes individual assign_to_user messages
 * @type {HandlerFactoryFunction}
 */
async function main(config = {}) {
  // Extract configuration
  const allowedAssignees = Array.isArray(config.allowed) ? config.allowed : [];
  const blockedAssignees = Array.isArray(config.blocked) ? config.blocked : [];
  const maxCount = normalizeMaxCount(config.max, 10);

Copilot uses AI. Check for mistakes.
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.

2 participants