Skip to content

PipelineBuilder: consider FIFO instead of LIFO for intuitive middleware ordering #437

Description

@JusterZhu

Problem

PipelineBuilder uses ImmutableStack (LIFO) for middleware registration:

// Registration order (developer writes):
builder
    .UseMiddlewareIf<PatchMiddleware>(true)
    .UseMiddleware<CompressMiddleware>()
    .UseMiddleware<HashMiddleware>();

// Actual LIFO execution order: Hash -> Compress -> Patch

A developer naturally expects registration order to match execution order. The LIFO semantics caused a bug in MacStrategy (fixed in #436) where the registration order was wrong because the author expected FIFO behavior.

Proposal

Change ImmutableStack to ImmutableQueue (FIFO) or List<IMiddleware> with forward iteration. This would require reversing the registration order in WindowsStrategy and LinuxStrategy (which currently depend on LIFO to get Hash executed first).

Scope

  • Pipeline/PipelineBuilder.cs
  • Strategy/WindowsStrategy.cs
  • Strategy/LinuxStrategy.cs
  • Related PipelineBuilder tests

Priority

Low — the current code works correctly after #436, but this change would prevent future maintainers from making the same mistake.

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorRefactor some existing code.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions