branchkit 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {branchkit-0.2.0 → branchkit-0.3.0}/PKG-INFO +1 -1
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/plugin.py +25 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit.egg-info/PKG-INFO +1 -1
- {branchkit-0.2.0 → branchkit-0.3.0}/pyproject.toml +1 -1
- {branchkit-0.2.0 → branchkit-0.3.0}/tests/test_settings_tabs.py +16 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/LICENSE +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/README.md +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/__init__.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/actor.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/closed_vocab_gen.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/collection.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/collection_log.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/commands.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/contracts_gen.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/correlation.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/debug.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/effects.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/harness.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/hud.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/listen.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/log.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/log_events_gen.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/methods_gen.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/mirror.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/proxy.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/settings.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/settings_route.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/types_gen.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/ui.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit/upstream.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit.egg-info/SOURCES.txt +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit.egg-info/dependency_links.txt +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/branchkit.egg-info/top_level.txt +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/setup.cfg +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/tests/test_collection.py +0 -0
- {branchkit-0.2.0 → branchkit-0.3.0}/tests/test_kernel.py +0 -0
|
@@ -211,6 +211,31 @@ class PluginCore:
|
|
|
211
211
|
self._action_handlers[action] = fn
|
|
212
212
|
return fn
|
|
213
213
|
|
|
214
|
+
def handle_command(self, method: str, fn: Callable | None = None):
|
|
215
|
+
"""Register a command: a method a settings control posts to. A
|
|
216
|
+
command changes state and returns nothing — the platform's method
|
|
217
|
+
proxy answers the post with 204 and re-renders the tab through its
|
|
218
|
+
stream, and refuses any result with 422 and the
|
|
219
|
+
settings-method-result diagnostic. Whatever `fn` returns is dropped
|
|
220
|
+
here; the response carries ``"result": null``. Usable directly or
|
|
221
|
+
as a decorator (``@plugin.handle_command("set_volume")``); plain
|
|
222
|
+
``def`` or ``async def``, as with ``handle``.
|
|
223
|
+
|
|
224
|
+
Use ``handle`` for a method whose result another caller reads — a
|
|
225
|
+
platform hook, or another plugin — never for a settings control."""
|
|
226
|
+
if fn is None:
|
|
227
|
+
def deco(f):
|
|
228
|
+
self.handle_command(method, f)
|
|
229
|
+
return f
|
|
230
|
+
return deco
|
|
231
|
+
|
|
232
|
+
async def command(params):
|
|
233
|
+
await self._invoke(fn, params if params is not None else {})
|
|
234
|
+
return None
|
|
235
|
+
|
|
236
|
+
self.handle(method, command)
|
|
237
|
+
return fn
|
|
238
|
+
|
|
214
239
|
# The design-doc registration idiom (`@plugin.action("…")`) — an alias
|
|
215
240
|
# of handle_action, which keeps the Go/TS name greppable too.
|
|
216
241
|
action = handle_action
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
registered stylesheet on every response, an error for a key nobody
|
|
3
3
|
registered, and every settings mirror refreshed before the tab draws."""
|
|
4
4
|
|
|
5
|
+
import asyncio
|
|
5
6
|
import unittest
|
|
6
7
|
|
|
7
8
|
import branchkit
|
|
@@ -71,6 +72,21 @@ class TestSettingsTabs(unittest.IsolatedAsyncioTestCase):
|
|
|
71
72
|
with self.assertRaisesRegex(RuntimeError, "settings_tab"):
|
|
72
73
|
b.handle("render_settings", lambda params: {})
|
|
73
74
|
|
|
75
|
+
# A command answers with no result however its handler is written — the
|
|
76
|
+
# proxy refuses anything else with 422; this is the SDK's half.
|
|
77
|
+
def test_handle_command_drops_the_return_value(self):
|
|
78
|
+
p = fake_plugin({})
|
|
79
|
+
seen = {}
|
|
80
|
+
|
|
81
|
+
@p.handle_command("set_volume")
|
|
82
|
+
def set_volume(req):
|
|
83
|
+
seen["volume"] = req["volume"]
|
|
84
|
+
return {"leak": True}
|
|
85
|
+
|
|
86
|
+
fn = p._handlers["set_volume"]
|
|
87
|
+
self.assertIsNone(asyncio.run(fn({"volume": 3})))
|
|
88
|
+
self.assertEqual(seen, {"volume": 3})
|
|
89
|
+
|
|
74
90
|
|
|
75
91
|
if __name__ == "__main__":
|
|
76
92
|
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|