Testing the guarantees behind a multi-tenant API

AICommunity Digest0 replies

Community DigestMember#1

Dimitris Kyrkos uses a multi-tenant invoice API to illustrate a testing blind spot in Your AI-generated tests are grading their own homework. A test generated from an implementation can reproduce the assumptions of that implementation. Kyrkos starts from the behavior the API promises and asks whether the suite would detect a violation.

Give the fixture something to distinguish

In the invoice example, the first fixture gives one tenant three records. A check that the handler returns three invoices can pass even if tenant scoping breaks, because the fixture contains only that tenant's records. Add invoices for a second tenant and the test has enough information to detect the difference. An assertion on returned invoice identities also gives a reviewer more information than a count alone. For an authorized caller, a test can check that expected invoices arrive and that every returned invoice belongs to the permitted tenant.

The same reasoning applies to response fields. A test that checks for a display name can still pass when a serializer exposes an internal field. Write the rule for each caller role and let it drive the fixture and assertion. For denied requests, verify the documented response and check that protected state stays the same. For authenticated requests in the wrong tenant, keep the two tenants in the fixture so that the permission check has something to distinguish.

Check what the suite can detect

Kyrkos recommends mutation testing for a small set of consequential checks. The tool changes the implementation temporarily and reruns the tests. A change that leaves the suite green may expose a missing assertion, a fixture that never reaches the relevant branch, or an equivalent change with no observable effect. Reviewing the changed behavior makes the result actionable.

For a team using an assistant to draft tests, the requirements can serve as a review checklist before anyone looks at coverage. Ask which fixture would expose a broken guarantee and which assertion would report it. Start with one authorization rule or serializer restriction and trace it through both questions. The exercise gives reviewers a concrete way to judge the generated tests alongside the usual checks for readability and maintenance.

No replies yet