Skip to content

refactor: extract credential loading helpers from test/record.sh#1348

Merged
louisgv merged 1 commit intomainfrom
refactor/complexity-test-helpers-1771283441
Feb 17, 2026
Merged

refactor: extract credential loading helpers from test/record.sh#1348
louisgv merged 1 commit intomainfrom
refactor/complexity-test-helpers-1771283441

Conversation

@la14-1
Copy link
Member

@la14-1 la14-1 commented Feb 16, 2026

Summary

Extracted credential-loading logic into focused helper functions to reduce complexity and improve maintainability.

Functions refactored:

  • try_load_config: 39 → 28 lines (28% reduction)
  • _load_multi_config_from_file: 38 → 26 lines (32% reduction)

New helpers:

  • _export_env_vars_from_fields (16 lines): Centralizes env var export logic with security validation
  • _load_single_token_config (14 lines): Extracts single-token loading from config files

Changes

  • Eliminated duplicate env var validation logic across functions
  • Improved readability with clear separation of concerns
  • Maintained all security checks and error handling
  • All 80 tests passing

Test plan

  • All 80 unit tests pass
  • Bash syntax validation passes
  • No functional changes (refactor only)

-- refactor/complexity-hunter

…test/record.sh

Split credential loading logic into focused helper functions:
- _export_env_vars_from_fields: Extract array export logic (16 lines)
- _load_single_token_config: Extract single-token loading (14 lines)

Changes:
- try_load_config reduced from 39 to 28 lines (28% reduction)
- _load_multi_config_from_file reduced from 38 to 26 lines (32% reduction)
- Eliminated duplicate env var validation logic
- Improved readability with clear separation of concerns

All 80 tests passing. No functional changes.

Agent: complexity-hunter
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copy link
Member

@louisgv louisgv left a comment

Choose a reason for hiding this comment

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

Security Review

Verdict: APPROVED

Findings

No security issues found. This is a clean refactoring that:

  • Extracts duplicate credential-loading logic into focused helper functions
  • Maintains all existing security validation (env var name regex checks)
  • Reduces complexity without changing behavior
  • Improves code maintainability

New helper functions:

  • _export_env_vars_from_fields (lines 89-105): Centralizes env var export with validation
  • _load_single_token_config (lines 174-191): Extracts single-token loading logic

Security validations preserved:

  • All env var names validated against ^[A-Z_][A-Z0-9_]*$ regex before export
  • All error handling and return codes maintained
  • No changes to privilege boundaries or data flow

Tests

  • bash -n: PASS (syntax valid)
  • bun test: N/A (no TypeScript changes)
  • curl|bash: N/A (test-only file, not executed remotely)
  • macOS compat: OK (no bash 4.x features used)
  • Test suite: PASS (80/80 tests passing)

Code Quality

  • Line count reduction: 28-32% in refactored functions
  • DRY principle applied correctly
  • No functional changes (refactor only)

-- security/pr-reviewer-1348

@louisgv louisgv merged commit 5f39b03 into main Feb 17, 2026
3 checks passed
@louisgv louisgv deleted the refactor/complexity-test-helpers-1771283441 branch February 17, 2026 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants