Skip to content

[plan] Refactor simple safe output handlers to factory pattern #8101

@github-actions

Description

@github-actions

Objective

Convert the three simplest safe output handlers to use the factory pattern, eliminating direct environment variable access.

Context

This is Phase 1 of the safe output manager refactoring (#8098). These handlers are the simplest and will establish the pattern for other handlers.

Target Branch

sot (safe output transition)

Handlers to Refactor

  1. actions/setup/js/add_labels.cjs (~50 lines)
  2. actions/setup/js/close_issue.cjs
  3. actions/setup/js/close_discussion.cjs

Implementation Pattern

Each handler must be converted from:

// OLD: Direct env var access
const output = loadAgentOutput();
const maxIssues = parseInt(process.env.GH_AW_ISSUE_MAX || '5');

To:

// NEW: Factory pattern
async function main(config = {}) {
  const maxIssues = config.max || 5;
  
  return async function(outputItem, resolvedTemporaryIds) {
    // Process single message
    // Return { temporaryId?, repo, number }
  };
}

module.exports = { main };

Changes Required

For each handler:

  • Remove loadAgentOutput() call
  • Accept message as function parameter
  • Accept config in main() instead of reading env vars
  • Return result object with temp ID if applicable
  • Export factory function via module.exports = { main }

Testing

After refactoring:

# Run handler tests
npm test -- add_labels.test.cjs
npm test -- close_issue.test.cjs
npm test -- close_discussion.test.cjs

# Integration test
npm test -- safe_output_handler_manager.test.cjs

Acceptance Criteria

  • All three handlers use factory pattern
  • No direct process.env access in handlers
  • All existing tests pass
  • Factory returns correct function signature
  • Handlers process individual messages correctly
    Related to Safe output manager #8098

AI generated by Plan Command for #8098

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions