Testing and publishing
Module tests are ordinary pytest in modules/<id>/tests/; make new writes a first one. mate.sdk.testing builds a fake ModuleContext over a small sample log, so a handler runs without the platform.
Unit tests#
import asyncio
from pathlib import Path
from mate.sdk.testing import build_test_context, load_module, sample_log
MODULE = load_module(Path(__file__).parents[1]) # imports module.py like the loader does
def test_summary_counts_every_event() -> None:
async def check() -> None:
log = sample_log(rows=200)
ctx = await build_test_context(log_id=log.id, module_id="my_module")
out = await MODULE.summary(ctx)
assert sum(row["events"] for row in out["rows"]) == 200
asyncio.run(check())
| Helper | Gives you |
|---|---|
sample_log(rows=None) | The bundled case-centric log (10 cases), tiled to exactly rows events; .id and .frame (pandas). |
build_test_context(log=None, *, log_id=, module_id=, user_id=, config=, workdir=) | ctx.event_log over that log; an in-memory ctx.cache; ctx.progress and ctx.bus that record their calls; a registry that knows no other module. Object-centric logs are not faked. |
load_module(folder) | An instance of module.py, checked against the manifest id. |
Name tests as expectations.
| Layer | Test with |
|---|---|
| Pure computation | Plain functions — fast, and where the subtle bugs live. |
| Handler wiring | Fakes for the two or three context members it uses. |
| Output payloads | Shape assertions against the declared shape. |
| Frontend | A manual pass: loading, empty, and error states; live updates; dark mode and compact density; the card at exactly min_px_w × min_px_h. |
| Make target | mate-module equivalent | Does |
|---|---|---|
make test ID=my_module | uv run mate-module test my_module | Runs modules/my_module/tests; the CLI passes extra arguments to pytest. |
make validate | uv run mate-module validate [folders] | Checks manifest, HOW_TO_USE.md and layout.json; exit 1 on any problem. |
make modules | uv run mate-module list | Lists every module: id, version, name, runtime, UI. |
make new ID=x [PANEL=1] | uv run mate-module new x [--panel] | Scaffolds modules/x/. |
make widget ID=x NAME=y | uv run mate-module widget x y | Adds a TSX widget and its manifest entry. |
make test | — | The platform suite, incl. module fixtures. |
- uses: astral-sh/setup-uv@v5
- run: uv sync --extra dev
- run: uv run mate-module validate modules/my_module
- run: uv run mate-module test my_module
Validating the manifest and the guide first is deliberate: they are the cheapest checks and the most common failures.
Distribution channels#
| Channel | Input | Best for |
|---|---|---|
| Pull request | The folder under modules/ | The default channel for shared instances: reviewed, versioned, shipped with the next deploy. |
| Upload | A .zip, .tar, .tar.gz, or .tgz of the folder | Lite mode and single-user or air-gapped hosts. Off unless MODULE_UPLOAD_ENABLED=true: uploaded code runs unsandboxed in the API. |
| Installed package | A package exposing the mate.modules entry point | Modules shipped through your own infrastructure — discovery picks it up at boot; the UI has no registry browser. |
Install runs as a job and rolls back cleanly on failure. Git-URL and registry channels are specified in docs/INSTRUCTIONS.md but not implemented yet. Package an archive with the manifest, module.py, HOW_TO_USE.md, tests, layout.json, frontend sources, and uv.lock — exclude .venv/, .dist/, node_modules/, and large model files (those belong in model_store). An archive without a valid HOW_TO_USE.md is rejected before anything is written; the install job's error lists what is wrong.
Versioning#
Bump version: whenever results change, not only when code changes. A results-affecting change should invalidate caches — version your cache keys or delete them on first run. Renaming a config_schema property orphans stored values, so add the new name and read both for one release.
Author checklist#
- [ ]
make validatepasses (manifest, guide,layout.jsonwith no unbound placeholder), andidmatchesmodule.py. - [ ]
log_modelmatches the log the module can actually handle. - [ ] Every emitted topic is in
provides:; every subscription and capability call is inconsumes:oroptional_modules:. - [ ] Precompute ordering uses
<module_id>.completed(orrequirements.modules), not hope; the handler is idempotent and rebuilds fromctx.event_log. - [ ] Long jobs use
@job(progress=True)and check cancellation at loop boundaries. - [ ] Results live in
ctx.cacheunder keys that encode the parameters that change them. - [ ] No imports from
apps/api/*orapps/web/*. - [ ] Widgets use the shared kit and declare
min_px_w/min_px_hmeasured in a browser. - [ ]
.venv/,.dist/,node_modules/are gitignored;uv.lockis committed. - [ ]
make test ID=my_modulepasses. - [ ] Every label, default and limit in
HOW_TO_USE.mdwas checked against the module page and the code. - [ ]
README.md, if you keep one, holds developer notes only (provenance, method, any external dependency); what users need to know lives in the guide.
The symptoms and fixes for the failures that remain are in Troubleshooting.