Skip to content

Commit 84f8412

Browse files
committed
breaking: Change default middleware priority from 0 to 100 as per PROTOCOL_SPEC §11.2, updating the base middleware class, tests, and changelog.
1 parent 8cce3b3 commit 84f8412

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- **Middleware priority**`Middleware` base class now accepts `priority: int` (0-1000, default 0). Higher priority executes first; equal priority preserves registration order. `BeforeMiddleware` and `AfterMiddleware` adapters also accept `priority`.
1212
- **Priority range validation**`ValueError` raised for priority values outside 0-1000
1313

14+
### Breaking Changes
15+
- Middleware default priority changed from `0` to `100` per PROTOCOL_SPEC §11.2. Middleware without explicit priority will now execute before priority-0 middleware.
16+
17+
1418
## [0.13.2] - 2026-03-22
1519

1620
### Changed

src/apcore/middleware/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ class Middleware:
1616
Attributes:
1717
priority: Execution priority (0-1000). Higher priority executes first.
1818
Middlewares with equal priority preserve registration order.
19-
Defaults to 0 for backward compatibility.
19+
Defaults to 100 per PROTOCOL_SPEC §11.2.
2020
"""
2121

22-
priority: int = 0
22+
priority: int = 100
2323

24-
def __init__(self, *, priority: int = 0) -> None:
24+
def __init__(self, *, priority: int = 100) -> None:
2525
if not (0 <= priority <= 1000):
2626
raise ValueError(f"priority must be between 0 and 1000, got {priority}")
2727
self.priority = priority

tests/test_middleware.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ def test_callback_receives_correct_args(self) -> None:
178178
class TestMiddlewarePriority:
179179
"""Tests for middleware priority ordering in MiddlewareManager."""
180180

181-
def test_default_priority_is_zero(self) -> None:
182-
"""Middleware instances default to priority 0."""
181+
def test_default_priority_is_100(self) -> None:
182+
"""Middleware instances default to priority 100 per PROTOCOL_SPEC."""
183183
mw = Middleware()
184-
assert mw.priority == 0
184+
assert mw.priority == 100
185185

186186
def test_custom_priority(self) -> None:
187187
"""Middleware accepts a custom priority via constructor."""
@@ -235,7 +235,7 @@ def test_mixed_priorities_with_ties(self) -> None:
235235
assert snapshot == [d, a, c, b, e]
236236

237237
def test_default_priority_backward_compatible(self) -> None:
238-
"""Middlewares without explicit priority still work (default 0)."""
238+
"""Middlewares without explicit priority still work (default 100)."""
239239
manager = MiddlewareManager()
240240
mw1 = Middleware()
241241
mw2 = Middleware()
@@ -248,15 +248,15 @@ def test_default_priority_backward_compatible(self) -> None:
248248
snapshot = manager.snapshot()
249249
assert snapshot == [mw1, mw2, mw3]
250250

251-
def test_subclass_without_super_init_defaults_to_zero(self) -> None:
252-
"""Subclasses that don't call super().__init__() still have priority 0."""
251+
def test_subclass_without_super_init_defaults_to_100(self) -> None:
252+
"""Subclasses that don't call super().__init__() still have class default priority 100."""
253253

254254
class CustomMiddleware(Middleware):
255255
def __init__(self) -> None:
256256
self.custom_field = "hello"
257257

258258
mw = CustomMiddleware()
259-
assert mw.priority == 0
259+
assert mw.priority == 100
260260

261261
def test_remove_preserves_priority_order(self) -> None:
262262
"""Removing a middleware preserves the priority-sorted order."""

0 commit comments

Comments
 (0)