# Test Managed Agent Automations

> Test a Type.com instruction automation in a private thread, and test a code automation with fixtures during each deploy.

Canonical page: https://docs.type.com/automations/testing/

Test a managed agent automation before you use it for recurring work. The test is different for each kind of automation.

| | Instruction automation | Code automation |
| --- | --- | --- |
| How you test | Select **Test** or **Test automation** in the editor. | Write fixtures in `fixtures.json`, or run one fixture with `type-cli automations test-code`. |
| What runs | The managed agent follows the saved instructions in a private thread. | One stage runs, the entry stage of one subscription or a stage the fixture names, with fixed input and fixed responses. |
| When it runs | When you select the button. | During each CLI deploy, or when you run `test-code`. |

## Test an instruction automation

A private test runs the automation in a private thread in its channel. Only you can see the thread. The thread has the name of the automation, and it links back to the automation editor. Read the response, then change the instructions in the editor.

### Start a private test

1. For a scheduled automation, open the automation from **Automations** in the sidebar.
2. Save your changes. The test uses the saved instructions and model settings, so save first.
3. Select **Test**.

For an event automation, open the event automation editor and select **Test automation**.

### What a private test does

- A private test does not wait for a real schedule, webhook, Slack event, or RSS item. Use it to examine the instructions and the behavior of the managed agent before you use live events.
- The test runs as the person who selects **Test**. A scheduled run uses the execution identity, model provider credentials, and model billing context of the automation creator.
- Each test makes a new preview in its private thread. This also occurs if the automation already delivered a result that day.
- A test ignores delivery checkpoints and duplicate-delivery checks.
- A test keeps the access requirements of the source.
- A test does not change external delivery, delivery checkpoints, or recorded automation data.
- A test can save authorized account choices. When new account choices are on for your workspace, another member's private test can save a shared **Team connection**. That member must have access in the test Space, and the automation creator must have access in every destination Space. See [Choose a connected account](https://docs.type.com/automations/managed-agent/index.md#choose-a-connected-account).

### Test checklist

Use this checklist when you test with a real trigger event:

1. Make sure that the Space has the connections that it needs.
2. Send a typical trigger event, or wait for one.
3. Open the thread that the run made.
4. Examine the response and the tool calls of the managed agent.
5. Change the automation instructions if it is necessary.
6. Make sure that the correct people get a notification.

## Test a code automation with fixtures

A fixture is a test case. It gives one subscription a fixed event and fixed responses for each call. You can run fixtures in two ways:

- **At deploy.** `type-cli automations deploy` runs every fixture in `fixtures.json`. If one fails, the deploy fails and the active code does not change. A deploy from Type AI with `create_task` has no fixtures.
- **On saved code.** `type-cli automations test-code` runs one fixture against the saved code of an automation, whether it is on or paused. Any member of its Space can run the fixture test. From Type AI, `test_automation_code` can also test draft code that isn't saved yet; the automation keeps running its saved version. The command uses a fixture rather than a real event. It does not enable the automation, but a passing test can complete a pending **Enable** request.

```sh
type-cli automations test-code <automation-id> --space <space> --arguments-file ./fixture.json --json
```

For `test-code`, the fixture has `subscriptionId` and `payload`, and can have `stage`, `checkpoint`, `matcher`, `environment`, `toolResponses`, and `integrationResponses`. It cannot have `name`, `expectedOutput`, or `expectedError`. Read the result in the command output. A test counts as evidence for enabling only when the stage ran and the fixture includes `toolResponses` or `integrationResponses`. Use `"toolResponses": []` when the stage makes no calls.

### What a fixture runs

A fixture runs one stage: the entry stage of its subscription, or the stage that `stage` names. What happens next depends on the decision that the stage returns:

| The stage returns | In the fixture |
| --- | --- |
| `complete(value)` | The fixture ends. `expectedOutput` is compared with `value`. |
| `blocked(reason, value)` | The fixture ends. `expectedOutput` is compared with `value`. |
| `blocked(reason)` | The fixture ends with no output. |
| `next(stage, input)` | Type.com checks `input` against the destination stage and records the transition. The destination stage does not run. There is no output. |
| An `Err` | The fixture fails, unless `expectedError` matches the error. |

A fixture never starts an agent stage, and it does not follow `next()` to a later stage. To check what a stage passes on, read `transition` in the `test-code` result.

To test a later stage, such as the `onResult` stage of an agent, set `stage` to its name and the input it would receive; see the example below. The matcher does not run, and `payload` is not used. You can also call a stage locally with `runAutomationDefinition` (see [Run a stage in a local test](https://docs.type.com/automations/reference/sdk/index.md#run-a-stage-in-a-local-test)).

For example, this automation sends weekdays to an agent stage and finishes weekends in its entry stage:

```ts title="src/main.ts"
import {
  agent,
  agentResult,
  automation,
  code,
  complete,
  next,
  recurringEventSchema,
} from "@type-dot-com/sdk/automations";

// What the agent stage gets, and what it must submit.
const day = z.object({ day: z.string() });
const incidentSummary = z.object({ summary: z.string().min(1) });

export default automation({
  output: z.object({ day: z.string(), summary: z.string().nullable() }),
  deployment: {
    subscriptions: {
      daily: {
        title: "Daily incident summary",
        description: "Summarize incidents on weekdays",
        source: {
          kind: "recurring",
          schedule: { kind: "interval", everySeconds: 86400 },
        },
        entry: "start",
      },
    },
  },
  stages: {
    // 1. Code: finish weekends here. Send weekdays to the agent.
    start: code({
      input: recurringEventSchema,
      transitions: ["review"],
      run({ input }) {
        const date = input.scheduledAt.slice(0, 10);
        const weekday = new Date(input.scheduledAt).getUTCDay();
        const isWeekend = weekday === 0 || weekday === 6;

        if (isWeekend) {
          return complete({ day: date, summary: null });
        }

        return next("review", { day: date });
      },
    }),

    // 2. Agent: summarize the day's incidents.
    review: agent({
      input: day,
      output: incidentSummary,
      instructions:
        "Summarize the incidents that this Space discussed on the given day in two sentences.",
      onResult: "record",
    }),

    // 3. Code: complete the run with the summary.
    record: code({
      input: agentResult({ input: day, output: incidentSummary }),
      transitions: [],
      run({ input }) {
        return complete({ day: input.taskInput.day, summary: input.result.summary });
      },
    }),
  },
});
```

Its fixtures cover both paths of the entry stage. The weekday fixture has no `expectedOutput`, because the entry stage returns `next()`:

```json title="fixtures.json"
[
  {
    "name": "skips weekends",
    "subscriptionId": "daily",
    "payload": { "scheduledAt": "2026-10-10T09:00:00.000Z" },
    "toolResponses": [],
    "expectedOutput": { "day": "2026-10-10", "summary": null }
  },
  {
    "name": "sends weekdays to the agent",
    "subscriptionId": "daily",
    "payload": { "scheduledAt": "2026-10-12T09:00:00.000Z" },
    "toolResponses": []
  }
]
```

If you add `expectedOutput` to the weekday fixture, even `null`, the fixture fails with "Fixture output did not match expectedOutput". When you run the weekday fixture with `test-code`, `result.output` in the command output shows the transition:

```json
{
  "stage": "start",
  "transition": {
    "kind": "next",
    "next": "review",
    "input": { "day": "2026-10-12" }
  },
  "fixtureExecuted": true
}
```

To test `record` without running the agent, start the fixture at that stage with a mocked agent result. Its input is the `{ taskInput, result, receipt }` envelope that `agentResult()` describes:

```json title="fixtures.json"
[
  {
    "name": "records the agent's summary",
    "subscriptionId": "daily",
    "payload": {},
    "stage": {
      "name": "record",
      "input": {
        "taskInput": { "day": "2026-10-12" },
        "result": { "summary": "Two incidents, both resolved." },
        "receipt": { "taskId": "task_example", "attempt": 1 }
      }
    },
    "toolResponses": [],
    "expectedOutput": { "day": "2026-10-12", "summary": "Two incidents, both resolved." }
  }
]
```

The stage still checks its input, so a mocked result that does not match `incidentSummary` fails the same way a real one would.

### Test environment variables

Fixtures never read saved Space variables or secrets. Supply fake user values in the optional `environment` map to exercise code that reads `process.env`:

```json
{
  "subscriptionId": "tick",
  "payload": { "scheduledAt": "2026-10-07T12:00:00.000Z" },
  "environment": { "SERVICE_TOKEN": "synthetic-test-token" },
  "toolResponses": []
}
```

Use synthetic values only. Fixture files are source-controlled and can appear in test diagnostics. Type removes reserved variable names from the map. Source validation also receives no saved variables; check required configuration inside the stage that runs, after the module has loaded.

### Add a fixture

Put a `fixtures.json` file in the project root. It contains an array of fixtures:

```json title="fixtures.json"
[
  {
    "name": "records the scheduled time",
    "subscriptionId": "hourly",
    "payload": { "scheduledAt": "2026-10-07T12:00:00.000Z" },
    "toolResponses": [],
    "expectedOutput": { "checkedAt": "2026-10-07T12:00:00.000Z" }
  }
]
```

- `name` is unique in the file.
- `subscriptionId` is the key of a subscription in `deployment.subscriptions`. The fixture runs that subscription's entry stage, unless `stage` names another.
- `payload` is the event, in the same shape as a live event.
- `expectedOutput` is the exact value that the stage gives to `complete()` or `blocked()`.

For all fields, see [Project Files](https://docs.type.com/automations/reference/project-files/index.md#fixturesjson).

### Give a response for each call

Fixtures can answer two kinds of calls: integration tool calls and Custom API requests. Each of these calls needs a response in the fixture. Use the real request and the real response envelope. This fixture is for an entry stage that runs `printf automation-ready` with `managed-sandbox` `exec_command`, fails with "Workspace check failed" if the tool returns an error, and completes with the text:

```json
{
  "name": "command output uses the text envelope",
  "subscriptionId": "check",
  "payload": { "scheduledAt": "2026-10-07T00:00:00.000Z" },
  "toolResponses": [
    {
      "request": {
        "service": "managed-sandbox",
        "name": "exec_command",
        "arguments": { "command": "printf automation-ready" }
      },
      "response": { "content": [{ "type": "text", "text": "automation-ready" }] }
    }
  ],
  "expectedOutput": { "text": "automation-ready" }
}
```

| Your code calls | Put the response in | Request fields | Response shape |
| --- | --- | --- | --- |
| `ctx.tools.call`, `ctx.read.call`, `ctx.write.call` | `toolResponses` | `service`, `name`, `arguments`, `organizationIntegrationId`, `rawSlug` | `{ content, structuredContent?, isError? }` |
| `ctx.read.request`, `ctx.write.request` | `integrationResponses` | `organizationIntegrationId`, `method`, `path`, `query`, `headers`, `body` | `{ connection, data, headers, status, statusText, success, truncated }` |

Rules:

- The request must match the call exactly, field by field. Leave out the fields that your code does not send.
- Effect keys are not part of the request. Do not put `effectKey` or `automationEffectKey` in a fixture.
- Type uses each response one time. Two equal calls need two responses.
- A call with no matching response fails the fixture with "Unexpected fixture tool call" or "Unexpected fixture integration request". No live request is sent.
- A response that your code does not use fails the fixture with "Unused fixture tool response" or "Unused fixture integration response".
- For `ctx.read.call` and `ctx.write.call`, the response must have `structuredContent`. JSON in `content[].text` does not count. A response with `"isError": true` returns an error to your code.
- For `ctx.read.request` and `ctx.write.request`, a response with `"success": false` returns an error to your code.
- If your stage makes no calls, set `"toolResponses": []`.

### Calls that fixtures cannot answer

In a fixture, Type rejects calls to other Type APIs. The run fails with "Unexpected fixture API request; only declared tool or integration calls are available".

| Call | In a fixture |
| --- | --- |
| `ctx.tools.call`, `ctx.read.call`, `ctx.write.call` | Supported. Give the response in `toolResponses`. |
| `replyInSlackThread` | Supported. It writes with `slack_post_message`; reactions first read `slack_get_thread_replies`. Supply both responses in `toolResponses`. |
| `ctx.read.request`, `ctx.write.request` | Supported. Give the response in `integrationResponses`. |
| `ctx.action`, `ctx.mutativeAction` | Supported. Type records the steps in the test result. |
| `ctx.saveCheckpoint` | Supported. The test result shows the value as `nextCheckpoint`. Type does not save it. |
| `next()` to a code or agent stage | Supported. Type records the transition but does not run the next stage. |
| `ctx.write.sendMessage` | Not supported. |
| `ctx.read.data` | Not supported. |
| `ctx.read.search` | Not supported. |
| `ctx.tools.find`, `ctx.tools.services` | Not supported. |
| Sandbox tools | Supported only as recorded `toolResponses`. A test never starts the sandbox. |

For code that uses an unsupported call:

- Write fixtures for the paths that end before the call. For example, test a filtered event or an error for bad data.
- Test the path with the call in a live run. Use a test repository, a test channel, or a narrow filter. Then read the run with `type-cli automations history --space <space> --run <run-id> --include-activity`.
- To post in Slack instead of the Space, use `replyInSlackThread` or a Slack tool through `ctx.write.call`. Fixtures can answer those calls.

### Test an error

Use `expectedError` to make sure that a bad response fails the stage:

```json
{
  "name": "provider error is a failed operation",
  "subscriptionId": "check",
  "payload": { "scheduledAt": "2026-10-07T00:00:00.000Z" },
  "toolResponses": [
    {
      "request": { "service": "managed-sandbox", "name": "exec_command", "arguments": { "command": "printf automation-ready" } },
      "response": { "content": [{ "type": "text", "text": "Workspace unavailable" }], "isError": true }
    }
  ],
  "expectedError": "Workspace check failed"
}
```

- `expectedError` passes if the error message contains the text.
- If the stage succeeds, the fixture fails.
- A fixture error, such as a missing or unused response, fails the fixture even if its message contains the text.
- An event that does not match the subscription schema fails with `Invalid subscription event: ...`. You can test it with `expectedError`.
- Do not set both `expectedOutput` and `expectedError` in one fixture.

### Test a filtered event

For an event that a matcher or a `resources` filter skips, omit both `expectedOutput` and `expectedError`. The entry stage does not run, so there is no output. No output is not the same as `null`. Do not supply responses; an empty `toolResponses` array is fine. A filtered fixture with responses fails with "Unused fixture responses: the subscription matcher skipped this event".

For AI questions, give the result in `matcher`. Type does not call the model in a fixture:

```json
{ "matcher": { "decision": "skip" } }
```

If your entry stage filters the event itself and returns `complete(value)`, test it like any other output, with `expectedOutput`.

### Test state

Set `checkpoint` to the value that `ctx.checkpoint.value` has at the start of the stage:

```json
{ "name": "stays quiet when nothing changed", "subscriptionId": "check", "checkpoint": "open", "payload": { "scheduledAt": "2026-10-07T00:00:00.000Z" }, "toolResponses": [] }
```

A fixture does not save checkpoints. Each fixture starts with its own `checkpoint`, or with `null` if you omit it.

### What to cover

Write one fixture for each different path in your entry stage:

- the normal case, with extra provider fields and `null` optional fields,
- each transition to another stage,
- a filtered event,
- a provider error or a response that does not match your schema,
- a missing or wrong required ID.

Do not write many fixtures for the same path.

> **Caution:** Do not check `ctx.identity.purpose` in code to skip calls in tests. Tests must run the same path as live runs. Type supplies the responses.

### Fixture limits

- 20 fixtures in each `fixtures.json` file. Names have 1 to 120 characters.
- 128 tool responses and 128 integration responses in each fixture.
- All fixtures in a deploy share a 4-minute limit. Type runs 4 fixtures at a time.
- A `test-code` run also has a 4-minute limit.

## What tests do not prove

A test that passes does not prove that a live run will succeed.

### Private tests of an instruction automation

- A private test does not prove that real events arrive. It does not verify a webhook signature, an email address, or feed availability. Test real event delivery separately.
- A successful test by another person does not prove that the automation creator has the same credentials or permissions.

After you enable the automation, examine the next run in **Run history**.

### Fixtures of a code automation

- A fixture runs one stage: its entry stage, or the stage that `stage` names. It does not start agent stages or follow `next()` to a later stage.
- Fixtures do not call real APIs. They do not prove that your credentials work, or that the provider sends the response that you wrote.
- Fixtures do not start the sandbox.
- Fixtures do not call the model for AI questions in a matcher. To examine the answers of the model, send real example events.
- Fixtures do not prove that events reach Type.

After the deploy, watch the first live runs with `type-cli automations history --space <space> --automation <automation-id>`.
