Skip to content

Refactor Phase 3 tests to use skipIfEndpointUnavailable() utility #227

Closed

Description

@malibio

Refactor Integration Tests to Use skipIfEndpointUnavailable() Utility

Type: Technical Debt / Code Quality
Priority: Low
Effort: Small (~30 minutes)


Current Status (Updated 2025-11-03)

Phase 3 test files no longer exist - they were refactored/renamed.

Current State:

  • Utility function exists and is well-documented at test-node-helpers.ts:142
  • 10 instances of inline error handling remain (down from ~40!)
  • Pattern still duplicated across 3 test files

Problem

The inline error handling pattern is still repeated in current tests:

// Current pattern (repeated 10 times)
catch (error) {
  const errorMessage = error instanceof Error ? error.message : String(error);
  if (errorMessage.includes('405') || errorMessage.includes('500')) {
    console.log('[Test] Container endpoint not yet active - test skipped');
    expect(error).toBeTruthy();
  } else {
    throw error;
  }
}

Issues:

  • Code duplication (10 instances across 3 files)
  • Harder to update error handling logic centrally
  • Violates DRY principle
  • Inconsistent with available utility

Proposed Solution

Refactor inline patterns to use the existing utility:

// After refactoring
catch (error) {
  if (skipIfEndpointUnavailable(error, 'Container endpoint')) {
    expect(error).toBeTruthy();
    return;
  }
  throw error;
}

Files to Update

All located in packages/desktop-app/src/tests/integration/:

  1. regression-prevention.test.ts

    • 6 instances at lines: 179, 263, 325, 384, 434, 491
  2. edge-cases.test.ts

    • 3 instances at lines: 188, 384, 420
  3. integration-scenarios.test.ts

    • 1 instance at line: 127

Implementation Steps

  1. Import the utility in all 3 test files:

    import { skipIfEndpointUnavailable } from '../utils/test-node-helpers';
  2. Replace each inline pattern with utility call (10 replacements total)

  3. Update endpoint names to be descriptive:

    • "Container endpoint"
    • "Mention endpoint"
    • "Node update endpoint"
  4. Run tests to verify no behavioral changes:

    bun run test src/tests/integration/regression-prevention.test.ts
    bun run test src/tests/integration/edge-cases.test.ts
    bun run test src/tests/integration/integration-scenarios.test.ts
  5. Run quality checks:

    bun run quality:fix

Acceptance Criteria

  • Import skipIfEndpointUnavailable added to all 3 test files
  • All 10 inline error handling patterns refactored to use utility
  • Descriptive endpoint names used in all utility calls
  • All tests still passing/skipping as before (no behavioral changes)
  • Code passes bun run quality:fix with zero warnings

Success Metrics

Before:

  • 10 instances of ~10 lines each = ~100 lines of duplicated code
  • 10 locations to update if error handling logic changes

After:

  • 10 instances of ~3 lines each = ~30 lines (70% reduction)
  • Single location (utility function) to update error handling logic

Notes

  • This is a pure refactoring - no functional changes expected
  • Low risk since pattern is well-established
  • Quick win on code quality (~30 minutes)
  • Good first issue for new contributors

Activity

  1. self-assigned this
    on Nov 3, 2025
  2. added a commit that references this issue on Nov 3, 2025
    8e4c77c
  3. added 2 commits that reference this issue on Feb 4, 2026
    d7089a1
    f15bb2f
  4. added a commit that references this issue on Feb 26, 2026
    898faa6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions