48 lines
1.9 KiB
Python
48 lines
1.9 KiB
Python
import hashlib
|
|
import json
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
WIDGET = ROOT / "plugins" / "shd-mcp-plugin" / "widgets" / "active-projects" / "v1"
|
|
|
|
|
|
class WidgetArtifactTests(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.manifest = json.loads((WIDGET / "manifest.json").read_text(encoding="utf-8"))
|
|
cls.resource = next(item for item in cls.manifest["resources"] if item["file"] == "index.html")
|
|
cls.html = (WIDGET / "index.html").read_text(encoding="utf-8")
|
|
|
|
def test_manifest_and_checksums_match_artifact(self):
|
|
digest = hashlib.sha256(self.html.encode("utf-8")).hexdigest()
|
|
self.assertEqual(self.resource["uri"], "ui://shd/active-projects/v1.html")
|
|
self.assertEqual(self.resource["mediaType"], "text/html;profile=mcp-app")
|
|
self.assertEqual(self.resource["bytes"], len(self.html.encode("utf-8")))
|
|
self.assertEqual(self.resource["sha256"], digest)
|
|
|
|
checksum = (WIDGET / "SHA256SUMS").read_text(encoding="utf-8").strip().split()
|
|
self.assertEqual(checksum, [digest, "index.html"])
|
|
|
|
license_path = (WIDGET / self.manifest["license"]).resolve()
|
|
self.assertEqual(license_path, (ROOT / "LICENSE").resolve())
|
|
source_path = (ROOT / self.manifest["source"]["path"]).resolve()
|
|
self.assertEqual(source_path, (WIDGET / "index.html").resolve())
|
|
|
|
def test_widget_uses_portable_bridge_and_no_external_script(self):
|
|
for marker in (
|
|
"ui/initialize",
|
|
"ui/notifications/initialized",
|
|
"ui/notifications/tool-input",
|
|
"ui/notifications/tool-result",
|
|
"tools/call",
|
|
"window.openai",
|
|
):
|
|
self.assertIn(marker, self.html, marker)
|
|
self.assertNotIn("<script src=", self.html.lower())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|