The core still hard-coded links into plugin pages (Files → Goals / Skills / Agents / Forms cards and drawer links, Dashboards → Performance, Settings → What's new and its editor, the home Analytics icon, skill/agent pills) and ~25 old addresses that forwarded to them (/goals, /skills, /dashboards/plan, /whats-new, /memories/<slug>…). On a hub without those plugins (raw-hub) they opened 404 pages. Now every link to a plugin page comes from its manifest: - bottom-bar drawers: every `files` / `dashboards` plugin page joins its section's drawer (past five slots into the stash), key `<section>/p:<plugin>:<page>`; saved slots of the core's old links map to the plugins' (SUB_RENAMED); - Files landing: the plugins' Files pages are its cards; Files panel: the hard-coded Goals row is gone; - What's new + editor leave the settings registry (the plugin's own `nav: "settings"` pages); - new optional page fields (written only when set — `ui` is in the approval fingerprint): `perm` (the page reaches its holders only), `header: "home"` (a button in the home page's head — Analytics), `tag` (the tag kind whose pills open the page at <page>/<slug> — skill, agent), `feature` (the App usage id its visits count under, so a former core page keeps its history; else plugin.<plugin>.<page>, in the frontend and telemetry/views.registry); - the old addresses and their redirect components are dropped; the owner's usage rings, the burn gauge and the Stats redirect link nowhere into a plugin; the plan-usage and /tmp-full pushes open /dashboards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
106 lines
4.6 KiB
Python
106 lines
4.6 KiB
Python
"""The ``telemetry.read`` capability — what the App usage plugin reads since
|
|
the Usage dashboard left the core (2026-11-25). The counting stays core
|
|
(telemetry/); only the page moved."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import pathlib
|
|
import tempfile
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
import main
|
|
from plugins.manifest import capability_summary, requires_operator, validate_manifest
|
|
from plugins.store import OWNER_UID, PluginStore
|
|
from telemetry import views
|
|
from toolproxy import access
|
|
|
|
MANIFEST = {
|
|
"schema": 1, "id": "au", "name": "App usage",
|
|
"ui": {"pages": [{"id": "usage", "label": "App usage", "nav": "dashboards", "html": "ui/u.html"}]},
|
|
"actions": {"usage": {"script": "handlers/u.py"}},
|
|
"capabilities": ["telemetry.read"],
|
|
}
|
|
|
|
|
|
def _write(root: pathlib.Path) -> pathlib.Path:
|
|
root.mkdir(parents=True, exist_ok=True)
|
|
(root / "plugin.json").write_text(json.dumps(MANIFEST), encoding="utf-8")
|
|
(root / "ui").mkdir(exist_ok=True)
|
|
(root / "ui" / "u.html").write_text("<p>u</p>", encoding="utf-8")
|
|
(root / "handlers").mkdir(exist_ok=True)
|
|
(root / "handlers" / "u.py").write_text("print('{}')\n", encoding="utf-8")
|
|
return root
|
|
|
|
|
|
class TestTelemetryRead(unittest.TestCase):
|
|
def setUp(self):
|
|
self.tc = TestClient(main.app)
|
|
self.deps = main.app.state.ai
|
|
|
|
def _store(self, td):
|
|
store = PluginStore(pathlib.Path(td) / "data")
|
|
store.install(OWNER_UID, str(_write(pathlib.Path(td) / "src")), is_owner=True, approve=True)
|
|
return store
|
|
|
|
def test_privileged(self):
|
|
with tempfile.TemporaryDirectory() as td:
|
|
mf = validate_manifest(_write(pathlib.Path(td) / "au"))
|
|
self.assertTrue(requires_operator(mf))
|
|
self.assertTrue([c for c in capability_summary(mf) if c["kind"] == "capability"][0]["privileged"])
|
|
|
|
def test_registry_is_the_apps(self):
|
|
reg = {f["id"]: f for f in views.registry()}
|
|
self.assertEqual(reg["dash.overview"]["label"], "Dashboard")
|
|
self.assertEqual(reg["split.open"]["kind"], "event")
|
|
self.assertTrue(reg["settings.users"]["ownerOnly"])
|
|
|
|
def test_owner_reads_usage_and_registry(self):
|
|
with tempfile.TemporaryDirectory() as td:
|
|
tok = access.mint_handler(OWNER_UID, "au", ttl=600)
|
|
with patch.object(self.deps, "plugin_store", self._store(td)), \
|
|
patch("telemetry.views.usage", return_value={"features": [], "people": []}) as u:
|
|
r = self.tc.get("/proxy/tools/plugins/au/hub/telemetry/usage?range=7d&who=guests",
|
|
headers={"Authorization": f"Bearer {tok}"})
|
|
self.assertEqual(r.status_code, 200, r.text)
|
|
self.assertEqual(u.call_args.args[1:], ("7d", "guests"))
|
|
self.assertTrue(any(f["id"] == "dash.overview" for f in r.json()["registry"]))
|
|
|
|
def test_bad_range(self):
|
|
with tempfile.TemporaryDirectory() as td:
|
|
tok = access.mint_handler(OWNER_UID, "au", ttl=600)
|
|
with patch.object(self.deps, "plugin_store", self._store(td)):
|
|
r = self.tc.get("/proxy/tools/plugins/au/hub/telemetry/usage?range=1y",
|
|
headers={"Authorization": f"Bearer {tok}"})
|
|
self.assertEqual(r.status_code, 400)
|
|
|
|
def test_a_guest_never_does(self):
|
|
with tempfile.TemporaryDirectory() as td:
|
|
tok = access.mint("cel", ttl=600)
|
|
with patch.object(self.deps, "plugin_store", self._store(td)), \
|
|
patch("telemetry.views.usage") as u:
|
|
r = self.tc.get("/proxy/tools/plugins/au/hub/telemetry/usage",
|
|
headers={"Authorization": f"Bearer {tok}"})
|
|
self.assertEqual(r.status_code, 403)
|
|
u.assert_not_called()
|
|
|
|
def test_plugin_without_the_capability_is_refused(self):
|
|
with tempfile.TemporaryDirectory() as td:
|
|
store = PluginStore(pathlib.Path(td) / "data")
|
|
m = dict(MANIFEST, capabilities=[])
|
|
root = _write(pathlib.Path(td) / "src")
|
|
(root / "plugin.json").write_text(json.dumps(m), encoding="utf-8")
|
|
store.install(OWNER_UID, str(root), is_owner=True, approve=True)
|
|
tok = access.mint_handler(OWNER_UID, "au", ttl=600)
|
|
with patch.object(self.deps, "plugin_store", store):
|
|
r = self.tc.get("/proxy/tools/plugins/au/hub/telemetry/usage",
|
|
headers={"Authorization": f"Bearer {tok}"})
|
|
self.assertEqual(r.status_code, 403)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|