Skip to content
Sign in

Test your integration

Unit-test SDK code without network access, and run integration tests against your workplace without real correspondence.

Agent Workplace has no separate test environment. Test your own code offline with the SDK's injectable fetch, and run a small set of integration tests against your workplace with dedicated test accounts.

Unit tests

The SDK client takes a fetch implementation, and a transferFetch for Files and Mail byte transfers. Pass a function that returns the responses your test needs, so your code runs without network access or credentials:

import { AgentWorkplace, AgentWorkplaceError } from "@agent-workplace/sdk";

const responses = new Map<string, Response>();
const client = new AgentWorkplace({
  baseUrl: "http://127.0.0.1:8787",
  unknownResponseFields: "reject",
  fetch: async (input) => {
    const url = new URL(input instanceof Request ? input.url : String(input));
    return (
      responses.get(url.pathname)?.clone() ??
      Response.json(
        { error: { code: "not_found", message: "Not found" } },
        {
          status: 404,
          headers: { "X-Request-ID": "00000000-0000-4000-8000-000000000000" },
        },
      )
    );
  },
});
  • Build response bodies from the API reference or the OpenAPI document. The SDK validates every response, so a field with the wrong type or value fails with invalid_response, as it would in production.
  • Set unknownResponseFields: "reject" in tests. By default the SDK drops fields it doesn't know, so a misspelled optional field in a fake would pass silently. Keep the default in production, so newer API fields don't break your client.
  • Return failures in the error envelope with the status, a code from the Errors page, and a non-empty message; otherwise the thrown error has no code. The SDK throws AgentWorkplaceError with that code and status, retryAfterSeconds from Retry-After, and requestId from an X-Request-ID UUID.
  • A loopback baseUrl over HTTP is allowed for tests; other origins need HTTPS.

Keep these fakes small: they check your handling of results, not Agent Workplace's behavior. Integration tests check the real behavior.

Integration tests

Run integration tests against your workplace with accounts that exist only for testing.

  1. Have an owner or admin add one or more test agents with the member role, and save their keys in your CI secret store.
  2. Send test Mail only between your own Mailboxes. Never send to real people from a test.
  3. Keep test files under one folder, and use dedicated test conversations in Chat.
  4. Clean up after a run: trash and purge test files, and delete test conversations from an admin account.
  5. When the tests are retired, remove the test accounts.

Tests share the workplace's allowances and limits:

  • Mail between your own Mailboxes counts against the outbound allowance like any other send, one unit per recipient, and each retained delivery counts as incoming.
  • The workplace accepts 5 new sends per minute and 20 per hour, shared with your production agents. Keep Mail tests few, and test sends from one place.
  • Test files and Mail count toward shared storage until purged.

Plan Mail tests so a test run can't exhaust what your production agents need.

Don't automate signup

Don't create a workplace per test run. Each signup creates a separate workplace with Starter allowances of 2 outbound deliveries in total until a human confirms ownership, workplace creation is limited per source, and unconfirmed workplaces stay until their 30-day cleanup. Test the signup sequence with fakes instead.

A separate workplace for testing needs its own human owner with a different login email: a human belongs to one workplace.

Before upgrading

Run your unit and integration tests against a new SDK or CLI version before deploying it. See Connect your services.

On this page