On this page

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#

modules/my_module/tests/test_my_module.py
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())
HelperGives 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.

LayerTest with
Pure computationPlain functions — fast, and where the subtle bugs live.
Handler wiringFakes for the two or three context members it uses.
Output payloadsShape assertions against the declared shape.
FrontendA 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 targetmate-module equivalentDoes
make test ID=my_moduleuv run mate-module test my_moduleRuns modules/my_module/tests; the CLI passes extra arguments to pytest.
make validateuv run mate-module validate [folders]Checks manifest, HOW_TO_USE.md and layout.json; exit 1 on any problem.
make modulesuv run mate-module listLists 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=yuv run mate-module widget x yAdds a TSX widget and its manifest entry.
make test—The platform suite, incl. module fixtures.
CI for a module
- 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#

ChannelInputBest for
Pull requestThe folder under modules/The default channel for shared instances: reviewed, versioned, shipped with the next deploy.
UploadA .zip, .tar, .tar.gz, or .tgz of the folderLite mode and single-user or air-gapped hosts. Off unless MODULE_UPLOAD_ENABLED=true: uploaded code runs unsandboxed in the API.
Installed packageA package exposing the mate.modules entry pointModules 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 validate passes (manifest, guide, layout.json with no unbound placeholder), and id matches module.py.
  • [ ] log_model matches the log the module can actually handle.
  • [ ] Every emitted topic is in provides:; every subscription and capability call is in consumes: or optional_modules:.
  • [ ] Precompute ordering uses <module_id>.completed (or requirements.modules), not hope; the handler is idempotent and rebuilds from ctx.event_log.
  • [ ] Long jobs use @job(progress=True) and check cancellation at loop boundaries.
  • [ ] Results live in ctx.cache under keys that encode the parameters that change them.
  • [ ] No imports from apps/api/* or apps/web/*.
  • [ ] Widgets use the shared kit and declare min_px_w/min_px_h measured in a browser.
  • [ ] .venv/, .dist/, node_modules/ are gitignored; uv.lock is committed.
  • [ ] make test ID=my_module passes.
  • [ ] Every label, default and limit in HOW_TO_USE.md was 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.