Skip to content

Fix issue #9: Distinguish pipe tokens from regular objects with .run() method - #12

Merged
irony merged 2 commits into
mainfrom
copilot/create-unit-tests-issue-9
Oct 11, 2025
Merged

Fix issue #9: Distinguish pipe tokens from regular objects with .run() method#12
irony merged 2 commits into
mainfrom
copilot/create-unit-tests-issue-9

Conversation

Copilot AI commented Oct 9, 2025

Copy link
Copy Markdown
Contributor

Problem

The aspipes library was incorrectly treating any object with a .run() method as a pipe token, automatically calling that method during pipeline execution. This made it impossible for users to return objects that legitimately have a run method, such as task objects, command objects, or job objects.

For example, this would fail:

const { pipe, asPipe } = createAsPipes();

const task = {
  id: 'task-123',
  name: 'ProcessData',
  status: 'pending',
  async run() {
    return 'task executed';
  }
};

const getTask = asPipe((x) => task);
const result = pipe('input');
result | getTask;

await result.run();  // Would return 'task executed' instead of the task object

Root Cause

The implementation checked if (result && typeof result.run === 'function') to detect composed pipes that should be unwrapped. However, this check was too broad and couldn't distinguish between:

  1. Actual pipe tokens (created by pipe()) that should be auto-executed
  2. Regular user objects that happen to have a .run() method

Solution

Added a unique Symbol (PIPE_TOKEN) to mark objects as actual pipe tokens. The library now checks for both the presence of .run() and the PIPE_TOKEN marker before unwrapping:

// Only auto-execute if it's actually a pipe token
if (result && result[PIPE_TOKEN] && typeof result.run === 'function')
  return await result.run();

This allows the library to correctly handle both scenarios:

  • Regular objects with .run() method are returned as-is ✓
  • Pipe tokens (composed pipes) are still properly unwrapped and executed ✓

Changes

  • Modified index.js: Added Symbol marker and updated auto-execution checks (10 lines changed)
  • Added comprehensive tests in test.js: 4 new unit tests covering various scenarios (107 lines added)

Testing

All 48 tests pass (44 existing + 4 new), confirming:

  • ✅ Regular objects with .run() are preserved
  • ✅ Pipe token composition still works correctly
  • ✅ No breaking changes - full backward compatibility
  • ✅ Examples run successfully

The fix is minimal, surgical, and maintains the library's existing behavior while enabling the new use case.

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/repos/irony/aspipes/issues/9
    • Triggering command: curl -s REDACTED (http block)

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

Original prompt

Create unit tests to illustrate the problem in #9 and try to find a suitable way to solve it?


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…) method

Co-authored-by: irony <395843+irony@users.noreply.github.com>
@irony
irony marked this pull request as ready for review October 9, 2025 20:15
Copilot AI review requested due to automatic review settings October 9, 2025 20:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses issue #9 by implementing a solution to distinguish between pipe tokens and regular objects that have a .run() method. The problem was that the library automatically executed .run() on any object containing this method, preventing users from returning legitimate objects like tasks or commands.

  • Added a PIPE_TOKEN Symbol to mark actual pipe tokens for proper identification
  • Modified the auto-execution logic to only call .run() on objects marked with the symbol
  • Created comprehensive unit tests to verify the fix and prevent regression

Reviewed Changes

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

File Description
index.js Added PIPE_TOKEN Symbol and updated auto-execution checks to distinguish pipe tokens from regular objects
test.js Added 4 unit tests covering various scenarios of objects with .run() methods and pipe token behavior

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copilot AI changed the title [WIP] Add unit tests for issue #9 and propose solution Fix issue #9: Distinguish pipe tokens from regular objects with .run() method Oct 9, 2025
Copilot AI requested a review from irony October 9, 2025 20:15
@irony
irony merged commit 8e35a22 into main Oct 11, 2025
6 checks passed
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.

3 participants