Skip to content

Commit 72fedbc

Browse files
sena-labsclaude
andcommitted
test: add response.close() assertions and fix test output wording
- Add 3 unit tests (15o/15p/15q) to verify pipes() always calls response.close() via the finally block: · 15o: auth-error path (HTTP 401) — close() called once · 15p: JSON decode error path — close() called once · 15q: success path — close() called once This prevents future regressions of the connection-pool fix. - Fix TESTING.md §0: replace "Must print 249/249 passed" with the actual output format the runner emits ("All tests passed! ✓" and "✗ Failed: 0"), addressing Copilot review comment. - Update test count from 249 → 252 across README, CONTRIBUTING, TESTING, and PULL_REQUEST_TEMPLATE to reflect the 3 new tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a2a96fb commit 72fedbc

5 files changed

Lines changed: 37 additions & 5 deletions

File tree

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
## Checklist
1414

1515
- [ ] I have read the [CONTRIBUTING.md](../CONTRIBUTING.md) guidelines
16-
- [ ] All tests pass (`python test_pipe.py`249/249 ✓)
16+
- [ ] All tests pass (`python test_pipe.py`252/252 ✓)
1717
- [ ] I have added tests for new functionality (if applicable)
1818
- [ ] I have updated `CHANGELOG.md` under `[Unreleased]`
1919
- [ ] I have updated documentation (if applicable)

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pip install -r requirements.txt
2929
### Running Tests
3030

3131
```bash
32-
python test_pipe.py # Unit tests (249 tests)
32+
python test_pipe.py # Unit tests (252 tests)
3333
python integration_test.py # Live API tests (requires OPENROUTER_API_KEY)
3434
```
3535

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ It also removes `user` when sent as a dict (OWUI format) since OpenRouter expect
216216
OpenRouter-Pipe/
217217
├── openrouter_pipe.py # Main pipe source (install this in Open WebUI)
218218
├── function.json # Open WebUI community manifest (metadata, tags, categories)
219-
├── test_pipe.py # Unit test suite (249 tests)
219+
├── test_pipe.py # Unit test suite (252 tests)
220220
├── integration_test.py # Live API integration tests (47 tests)
221221
├── TESTING.md # Pre-release testing checklist
222222
├── SECURITY.md # Security policy and vulnerability reporting

TESTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Manual checklist to verify every Pipe feature before release.
1212
python test_pipe.py
1313
```
1414

15-
Must print **249/249 passed**. If any test fails, **do not release**.
15+
Must exit with `All tests passed! ✓` and `✗ Failed: 0`. If any test fails, **do not release**.
1616

1717
---
1818

@@ -191,7 +191,7 @@ Must print **249/249 passed**. If any test fails, **do not release**.
191191
## Quick pre-release checklist
192192

193193
```
194-
[ ] python test_pipe.py → 249/249
194+
[ ] python test_pipe.py → 252 passed, 0 failed
195195
[ ] python integration_test.py → 47/47 ✓
196196
[ ] Empty API key → clear error
197197
[ ] Valid API key → 340+ models

test_pipe.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,38 @@ async def _test_pipe_stream() -> str:
10261026
_assert(models[0]["id"] == "error", "pipes provider no match: error id")
10271027
_assert("No models match" in models[0]["name"], "pipes provider no match: correct message")
10281028

1029+
# 15o. response.close() called via finally on auth-error branch (401)
1030+
_close_auth_resp = MagicMock()
1031+
_close_auth_resp.status_code = 401
1032+
_close_auth_resp.json.return_value = {"error": {"message": "Unauthorized"}}
1033+
pipe.valves = Pipe.Valves(OPENROUTER_API_KEY="bad-key")
1034+
pipe._models_cache = None
1035+
with patch.object(pipe._session, "get", return_value=_close_auth_resp):
1036+
pipe.pipes()
1037+
_assert(_close_auth_resp.close.call_count == 1, "pipes response.close(): called after 401 auth error")
1038+
1039+
# 15p. response.close() called via finally when response.json() raises (JSONDecodeError)
1040+
_close_json_err_resp = MagicMock()
1041+
_close_json_err_resp.status_code = 200
1042+
_close_json_err_resp.raise_for_status = MagicMock()
1043+
_close_json_err_resp.json.side_effect = ValueError("No JSON object could be decoded")
1044+
pipe.valves = Pipe.Valves(OPENROUTER_API_KEY="test-key")
1045+
pipe._models_cache = None
1046+
with patch.object(pipe._session, "get", return_value=_close_json_err_resp):
1047+
pipe.pipes()
1048+
_assert(_close_json_err_resp.close.call_count == 1, "pipes response.close(): called after JSON decode error")
1049+
1050+
# 15q. response.close() called via finally on success path
1051+
_close_ok_resp = MagicMock()
1052+
_close_ok_resp.status_code = 200
1053+
_close_ok_resp.raise_for_status = MagicMock()
1054+
_close_ok_resp.json.return_value = {"data": [{"id": "openai/gpt-4o", "name": "GPT-4o"}]}
1055+
pipe.valves = Pipe.Valves(OPENROUTER_API_KEY="test-key")
1056+
pipe._models_cache = None
1057+
with patch.object(pipe._session, "get", return_value=_close_ok_resp):
1058+
pipe.pipes()
1059+
_assert(_close_ok_resp.close.call_count == 1, "pipes response.close(): called after successful listing")
1060+
10291061
# ── 16. Valve json_schema_extra ──────────────────────────────────────────────
10301062

10311063
_section("16. Valve json_schema_extra")

0 commit comments

Comments
 (0)