-
Notifications
You must be signed in to change notification settings - Fork 38
fix(server): a raising tuning provider no longer takes down get_merged() for everyone (#899) #904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,72 @@ | ||||||||||||||||||||||||||||||||||||||
| """A raising tuning provider must not take down get_merged() for everyone. (#899) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| `TuningProviderRegistry.get_merged()` wraps each provider in a try/except precisely so one | ||||||||||||||||||||||||||||||||||||||
| misbehaving plugin cannot break tunings for the rest. The handler called `logger.exception` | ||||||||||||||||||||||||||||||||||||||
| — and there is no `logger` in server.py; the module logger is `log`. So the handler MEANT | ||||||||||||||||||||||||||||||||||||||
| to swallow-and-report instead raised NameError, which propagated out of get_merged(). | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| The net effect was the exact opposite of the handler's purpose: one bad provider took the | ||||||||||||||||||||||||||||||||||||||
| whole merged-tunings call down, and the traceback named the wrong problem. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Nothing exercised the failure path, which is why it survived. This is that path. | ||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import importlib | ||||||||||||||||||||||||||||||||||||||
| import logging | ||||||||||||||||||||||||||||||||||||||
| import sys | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import pytest | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| @pytest.fixture() | ||||||||||||||||||||||||||||||||||||||
| def registry(monkeypatch, tmp_path): | ||||||||||||||||||||||||||||||||||||||
| monkeypatch.setenv("CONFIG_DIR", str(tmp_path)) | ||||||||||||||||||||||||||||||||||||||
| sys.modules.pop("server", None) | ||||||||||||||||||||||||||||||||||||||
| mod = importlib.import_module("server") | ||||||||||||||||||||||||||||||||||||||
| yield mod.TuningProviderRegistry() | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def test_a_raising_provider_does_not_break_the_others(registry, caplog): | ||||||||||||||||||||||||||||||||||||||
| """The whole point of the try/except. Before the fix this raised NameError.""" | ||||||||||||||||||||||||||||||||||||||
| def boom(): | ||||||||||||||||||||||||||||||||||||||
| raise RuntimeError("provider exploded") | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def good(): | ||||||||||||||||||||||||||||||||||||||
| return {"guitar": {"My Tuning": [82.41, 110.0, 146.83, 196.0, 246.94, 329.63]}} | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| registry.register("bad-plugin", boom) | ||||||||||||||||||||||||||||||||||||||
| registry.register("good-plugin", good) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| merged = registry.get_merged() # must NOT raise | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| assert "My Tuning" in merged["guitar"], ( | ||||||||||||||||||||||||||||||||||||||
| "the healthy provider's tuning is missing — one raising provider took down the " | ||||||||||||||||||||||||||||||||||||||
| "merged result for everyone" | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
| # and the default tunings survive | ||||||||||||||||||||||||||||||||||||||
| assert merged["guitar"], "default tunings were lost" | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+42
to
+47
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Assert that a known default tuning survives.
Proposed fix+ default_guitar_names = set(registry.get_merged()["guitar"])
registry.register("bad-plugin", boom)
registry.register("good-plugin", good)
merged = registry.get_merged()
...
- # and the default tunings survive
- assert merged["guitar"], "default tunings were lost"
+ assert default_guitar_names <= merged["guitar"].keys(), (
+ "default tunings were lost"
+ )📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| def test_the_failure_is_actually_logged(registry, caplog): | ||||||||||||||||||||||||||||||||||||||
| """Swallowing is only acceptable if it is reported. A NameError in the handler meant | ||||||||||||||||||||||||||||||||||||||
| nothing was ever logged — the failure was both fatal AND silent about its real cause.""" | ||||||||||||||||||||||||||||||||||||||
| def boom(): | ||||||||||||||||||||||||||||||||||||||
| raise RuntimeError("provider exploded") | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| registry.register("bad-plugin", boom) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| # The feedBack logger sets propagate=False, so pytest's root-logger capture sees | ||||||||||||||||||||||||||||||||||||||
| # NOTHING from it. Attach caplog's handler directly. (test_plugins.py has a | ||||||||||||||||||||||||||||||||||||||
| # capture_logger() context manager for this, but it is not importable from here: | ||||||||||||||||||||||||||||||||||||||
| # pyproject pins pythonpath to [".", "lib"], so `tests` is not a package.) | ||||||||||||||||||||||||||||||||||||||
| lg = logging.getLogger("feedBack") | ||||||||||||||||||||||||||||||||||||||
| lg.addHandler(caplog.handler) | ||||||||||||||||||||||||||||||||||||||
| lg.setLevel(logging.ERROR) | ||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||
| registry.get_merged() | ||||||||||||||||||||||||||||||||||||||
| finally: | ||||||||||||||||||||||||||||||||||||||
| lg.removeHandler(caplog.handler) | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+62
to
+68
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win Restore the The test sets a process-global logger level to Proposed fix+ previous_level = lg.level
lg.addHandler(caplog.handler)
lg.setLevel(logging.ERROR)
try:
registry.get_merged()
finally:
lg.removeHandler(caplog.handler)
+ lg.setLevel(previous_level)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| assert any("bad-plugin" in r.getMessage() for r in caplog.records), ( | ||||||||||||||||||||||||||||||||||||||
| "the raising provider was never named in the logs" | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Restore the cached
servermodule after the fixture.Removing
serverfromsys.modulesand leaving the newly imported module cached can contaminate later tests: they may see a module initialized with the temporaryCONFIG_DIR. Usemonkeypatch.delitem(sys.modules, "server", raising=False)or explicitly restore the previous module during teardown.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents