This page covers three things: how to write tests for an extension, how to have the Agent run them and read the results of Load a site:
To test the failure branch of a model call, have In tests, The result has three parts.
The result of static validation of the development folder. It doesn’t run extension code. This part is missing before
The preview version running in this session. This part is missing when there’s no preview.
Coming soon
When A command doesn’t appear in the
Plugin commands are listed in the
inspect, and how to find the cause by symptom when an extension doesn’t behave as expected. Testing, preview, and inspection all run through the Agent calling the extension tool. You tell the Agent what to do in the conversation.Write tests
Put test files underhooks/ with names ending in .test.tsx, for example hooks/register.test.tsx. The extension module doesn’t import test files. A test file imports test utilities only from @minimax/mcode-plugin-extension/testing, and imports the register under test from ./register.A test follows these basic steps:- Use
mount()to load the module in a real extension host and draw the given site. - Use
find()to look for elements in the drawn element tree and check what they show. - Use
press()to press buttons, type text, or flip switches the way a user would. - Check
site.state(),site.effects, andsite.diagnostics.
mount() play the session, model, MCP servers, and message box. Wherever the module needs an answer from the host, a fake answers. See Answer for the host: fakes.This page refers to three places in an extension:- Status band: the strip above the message box, inside its border. All plugins share one band, and each draws a line or two in it. Its site name in code is
above-prompt. - Panel: a tab in the conversation’s side panel on the right, next to tabs such as Files and Browser. Its site name in code is
pane. - Backdrop: the backdrop behind the conversation, a layer in the main window under every panel. It replaces the wallpaper while a theme is active. Its site name in code is
backdrop.
Full example
The extension below shows on the status band how many tools this session has called, and a button fills that number into the message box. When the message box already has text, it doesn’t overwrite it and shows a toast instead.hooks/register.tsx
hooks/state.ts
hooks/register.test.tsx
Load a site: mount
To mount a panel, give an
id or a full key. With neither, mount throws. register must be the function imported from ./register.mount activates your plugin, so the session.start hook runs once first (with e.cwd set to '/workspace'). What it does is recorded in site.effects. For example, a panel opened in session.start leaves a ui.open entry. For other observe events (turn.start, tool.call, and so on), state stands in for their effect. Pass a state to mount and test what the screen shows in that state. There are two exceptions: fire turn.complete when a sub-agent finishes with completeAgent, and fire command.run with runCommand.Without mods, your plugin is the only layer on the site in a test, and await next() returns nothing. Coming soon Modules in mods skip validation: code that passes there, such as a ctx.command.register whose name isn’t a literal, is refused by test and preview in a plugin of its own.When mount starts, it takes a snapshot of its arguments. It copies only the object’s own enumerable properties, reads each getter once, and keeps this pointing to the original object when a method is called. So write fakes as plain objects. Methods on a class instance’s prototype aren’t copied.Find elements and press buttons
A
query can match by key, label, text (a string or a regular expression), or type. press also accepts a node returned by find. What press does for each element:ButtoncallsonPress;SwitchcallsonChange. Without avalue, it passes the opposite of the currentchecked;SelectcallsonSelect. You must give the option’svalue;pressworks on these three elements. Calling it on any other element throws an error.
Check the results
Each entry in
site.effects has a type and a plugin. The other fields are:In tests,
ctx.theme.set runs the same checks as the real host: invalid arguments throw ARGUMENT_INVALID, and too little contrast between text and background colors throws THEME_PALETTE_REJECTED. Neither leaves a theme.set entry. So ctx.theme needs no fake. A command’s answer isn’t a ctx.ui.toast and doesn’t appear in site.effects. See Test commands.Write assertions with expect(x). It supports toBe, toEqual, toBeTruthy, toBeDefined, toContain, and toMatch. Put .not in front to negate.Answer for the host: fakes
For example, to test a status band that changes color with context usage, pass
usage like this:model return a reason:ctx.store is an in-memory store and ctx.ui.invalidate redraws as usual. Neither needs a fake.Test sub-agents
completeAgent(site, { agentId, answer, reason? }) simulates a sub-agent finishing and sends turn.complete to the plugin that started it. reason defaults to 'answer' and also sets the event’s status.hooks/register.tsx
hooks/state.ts
hooks/register.test.tsx
Test commands
Coming soonrunCommand(site, name, args?) runs a command as if the user typed /<name> <args>, and returns the command.run hook’s answer { text }, the sentence the UI would show. Without args, it’s ''. listCommands(site) returns the list ctx.command.list() would return. For how to register and answer a command, see Add a slash command.When a run fails, runCommand fails with the same code the user would see:Tests have no Skills, so only built-in command names are taken.The extension below registers a
/todo command and shows its argument on the status band:hooks/register.tsx
hooks/state.ts
hooks/register.test.tsx
Common errors in tests
Run tests
Tell the Agent “run the extension tests” and it calls theextension tool:test has two steps:- It first validates the whole package by the
previewrules. If validation fails, it returns the diagnostics right away (status: 'invalid') and runs no tests. - Once validation passes, it runs every test file in the package in a real extension host, each file on its own. The results list each test’s
passedorfailedby file, with failure messages, diagnostics, and logs, plus totals for passed and failed. If a test file itself fails to compile, that file’s diagnostics are listed and it counts as one failure.
test reads the development folder returned by init. You can also add sourcePath (an absolute path) to test a package in another folder. When sourcePath points outside the development folder, the test would run code that wasn’t written in the development folder, so a permission card appears, as with preview. The tests run only after the user agrees.Type checking
test and preview transpile source to JavaScript and run a static scan. Type checking is a separate step. A type error can still pass validation and only show up at runtime, so check types in either of these ways:- Open the development folder in your editor. The
.minimax-plugin/types/written byinitand thetsconfig.jsonat the root let the editor flag type errors directly. - If TypeScript is installed on your machine, run this in the package folder:
Check state with inspect
After the extension is previewed and the user has pressed buttons or run a turn, have the Agent callinspect:source: what validation saw
The result of static validation of the development folder. It doesn’t run extension code. This part is missing before init.Look at
source.diagnostics first. An error here means the current source can’t load, and the automatic reload at the end of the next turn will also be rejected. Before install, when you tell the user what the extension will do, take the registered sites, events, and called servers from here too.preview: the version running in this session
The preview version running in this session. This part is missing when there’s no preview.runtime: what happened at runtime
The usual order when you troubleshoot:
source.diagnostics → preview.keptReload → runtime.diagnostics → runtime.console. When a placeholder shows in the UI, also check runtime.sites.runtime.sites: parts the window replaced with a placeholder
Coming soonruntime.diagnostics records problems the runtime (the extension process side) found. After a screen reaches the window, the window checks it again and replaces any part it can’t draw with a placeholder. Those records are in runtime.sites, one item per site:Only draws your plugin took part in are listed. Records are in time order, newest last, with at most 16 per site. Old records aren’t cleared after you fix the problem: compare the
renderSeq of the last record with the renderSeq of this site’s latest draw in runtime.traces. Only when they’re equal is the problem still there. These records don’t count toward a pause.Diagnostic shape and the fix loop
A diagnostic from validation is:file, line, and column point to the source location, message describes the problem, fix is the change to make, and level is 'error' or 'warning'. Runtime diagnostics have no source location and use slot and key to identify the site.There’s only one fix loop: make the change in fix, then run the same action again. If test reported it, run test again; if preview reported it, run preview again. For what every diagnostic code means and how to fix it, see Diagnostic codes.EXTENSION_PACKAGE_SKIPPED, EXTENSION_SHADOWING, COMMAND_RETIRED, COMMAND_ANSWER_INVALID, and COMMAND_TEXT_TRUNCATED are warnings and don’t block preview or the current action. Every other diagnostic does.Troubleshoot by symptom
The status band doesn’t show
Other plugins are hidden
Symptom: after your extension appears, other plugins’ status band or panel content disappears.Cause: the draw doesn’t callnext. Several plugins draw a site in layers. await next() returns what the layers after yours drew. If you don’t put it in your element tree, every layer after you is hidden. Validation warns with EXTENSION_SHADOWING.What to do: put await next() in the element tree once, usually as the last child of a column Box. If you don’t want to add anything, return next(). You can call next only once per invocation. A second call reports EXTENSION_NEXT_TWICE. See Render chain.Coming soon Once the status band is drawn in two steps, each plugin’s above-prompt draws its own row on its own and can’t hide other plugins’ rows, so leaving out next there no longer warns. Sites on the render chain, above-prompt-list, pane, and backdrop, still need next. See status band row arrangement.Changes didn’t load
Symptom: you changed a file, but the UI is still the old one.Cause: changes after a preview reload only at the end of a turn. They don’t take effect the moment you save a file. If the new code fails validation, the reload is rejected and the old version keeps running, with no notice in the UI.What to do:- If you’re still in the same turn, wait for it to end.
- Have the Agent
inspect.preview.staleset totruemeans the files are newer than the running version. Apreview.keptReloadmeans the reload was rejected. - Apply the
fixfrom each entry inkeptReload.diagnostics, then let a turn end, orpreviewagain directly.
register throws while loading, it reports EXTENSION_REGISTER_FAILED, and the old version keeps running until you fix it.The extension is paused
Symptom: the status band or panel shows “Paused · this session” with a “Retry” button, and a reason below:If there’s a “Last error” line, it’s the error message from the last failure.Cause: the circuit breaker disabled the hook or the whole plugin. The diagnostic code is
EXTENSION_DISABLED. A pause only affects the current session. Other sessions aren’t affected. When a site has several plugins, the paused layer is skipped and the other plugins draw as usual. The pause notice shows only when every layer is paused.What to do:- Have the Agent
inspect. Checkruntime.disabledHooks,runtime.disabled, andruntime.diagnosticsto find the failing hook. Common diagnostics arethrown(an error was thrown),timeout(synchronous code timed out),EXTENSION_HOOK_EXPIRED(more than 10 seconds), andEXTENSION_WORKER_CRASHED(the process restarted). - After you fix the code,
previewagain, or click “Retry” in the UI. If the retry fails, the UI shows “Retry didn’t go through. Try again later”.
Pressing a button does nothing
Permission denied or call cancelled
ctx.mcp.call follows the Agent’s permission rules. An existing allow rule lets it through, a deny rule denies it, and anything else shows a permission card. The card’s allow option, “Only this chat”, allows only this one call, and the next call asks again. No matter how the user responds, no permission rule is saved.A preview version doesn’t inherit the installed version’s allow rules. So it’s normal for the installed version to show no card while the preview version does.
Call rate exceeded
A toast didn’t appear
Symptom: you calledctx.ui.toast, but no toast appeared and the call didn’t fail.Cause: each plugin can show at most 6 toasts a minute. Extra ones are dropped until the one-minute window rolls over. Each run of consecutive drops records one toast.dropped in runtime.diagnostics when it starts. Text longer than 500 characters is also truncated.What to do: show a toast only when the user needs to know the result. Put state that keeps changing on the status band.prompt.fill didn’t write
When ctx.prompt.fill returns { written: false, reason }, handle it by reason:Even when it returns
written: true, the write is best effort. A replace that happens while the user is typing is dropped to keep the user’s text. If a dialog opens at the moment of the write, both modes are dropped. ctx.prompt.fill only fills in text. Sending is up to the user.Likewise, when ctx.prompt.suggest returns isShown: false, check reason (draft-not-empty, turn-running, dismissed, no-turn, no-composer). When ctx.prompt.read reports PROMPT_READ_UNAVAILABLE, no message box responded within 2 seconds. See Fill text into the message box.A command doesn’t appear in the / menu
Plugin commands are listed in the / menu of the message box after built-in commands and Skills, labeled with the plugin’s display name. If you don’t see your command:If typing
/<name> runs a built-in command or Skill with the same name, a Skill took that name after you registered: when typed, the Skill wins, but picking your item from the menu still runs your command.A command shows no response or an error
After the user runs a command, the UI shows the result in a toast. When something goes wrong, it shows one of these notices (using the command/todo as an example):If the command ran but nothing showed, check the hook’s return value. Returning nothing or
{} shows nothing. A return value other than { text } (with extra keys, or a text that isn’t a string) also shows nothing and records COMMAND_ANSWER_INVALID. An answer longer than 500 characters is truncated and records COMMAND_TEXT_TRUNCATED.The backdrop doesn’t show
If you don’t see the backdrop you drew:A rejected
<Svg> isn’t a failure and doesn’t pause the hook. Once you fix source, the next draw shows it.Setting a theme fails
When the theme is rejected, it stays as it was. Only
ctx.theme.clear() removes a theme.Other cases
Next steps
Diagnostic codes
What each diagnostic code means and how to fix it.
Extensions reference
Quick reference for events, ctx methods, elements, and limits.
Interface: sites and elements
The render chain, keys, and redraw rules.
Extension API
How to use each ctx method and what it returns.