Ss14 tests authoring

From space-sunrise/lust-station · View interactive version

Ss14 tests authoring is an AI agent skill from the GitHub repository space-sunrise/lust-station. Practical workflow for writing your own unit/integration tests in the Space Station 14 architecture: from choosing a strategy to stable assertions and test maintenance.

How to use this skill

Skill file

Writing your own tests in SS14

When to use

Use this skill when needed:

The internals of PoolManager/TestPair are discussed in detail in ss14-tests-poolmanager. Here the emphasis is on the author's workflow and the quality of tests as an artifact.

Short decision tree

  1. Are you testing pure logic without network/tick/IoC?
  1. Do you need real synchronization client↔server, UI/BUI, prediction or input?
  1. Does the test change the global state, which does not survive reuse well?

Basic workflow of the author 🧪

  1. Fix the invariants:
  1. Select minimal environment settings:
  1. Arrange:
  1. Act:
  1. Assert:
  1. Cleanup:

Pattern 1: standard content integration test

[Test]
public async Task MyScenario_Works()
{
    await using var pair = await PoolManager.GetServerClient(new PoolSettings
    {
        Connected = true,
        Dirty = false,
    });

    var server = pair.Server;
    EntityUid subject = default;

    await server.WaitPost(() =>
    {
        // Arrange: create a test entity.
        subject = server.EntMan.SpawnEntity("MobHuman", MapCoordinates.Nullspace);
    });

    await pair.RunTicksSync(5);
    await pair.SyncTicks(targetDelta: 1);

    await server.WaitAssertion(() =>
    {
        // Assert: check after stabilization.
        Assert.That(server.EntMan.EntityExists(subject), Is.True);
    });

    await pair.CleanReturnAsync();
}

Pattern 2: inline prototypes inside a test

[TestPrototypes]
private const string Prototypes = @"
- type: entity
  id: MyTestTarget
  components:
  - type: Physics
";

[Test]
public async Task UsesInlinePrototype()
{
    await using var pair = await PoolManager.GetServerClient();

    await pair.Server.WaitAssertion(() =>
    {
        Assert.That(pair.Server.ProtoMan.HasIndex<EntityPrototype>("MyTestTarget"), Is.True);
    });

    await pair.CleanReturnAsync();
}

Pattern 3: isolated special case without a pool

Use when the case involves global registrations/deep isolation.

var server = StartServer(new ServerIntegrationOptions
{
    Pool = false,
    ExtraPrototypes = Prototypes,
});
var client = StartClient(new ClientIntegrationOptions
{
    Pool = false,
    ExtraPrototypes = Prototypes,
});

await Task.WhenAll(server.WaitIdleAsync(), client.WaitIdleAsync());
Assert.DoesNotThrow(() => client.SetConnectTarget(server));
await client.WaitPost(() => client.ResolveDependency<IClientNetManager>().ClientConnect(null!, 0, null!));

Good test patterns :)

Anti-patterns

Examples from actual code

Example A: scenario where lobby/in-round transitions are needed

await using var pair = await PoolManager.GetServerClient(new PoolSettings
{
    Dirty = true,       // the test changes the phase of the game
    DummyTicker = false,
    Connected = true,
    InLobby = true,
});

var ticker = pair.Server.System<GameTicker>();
await pair.Server.WaitAssertion(() =>
{
    Assert.That(ticker.RunLevel, Is.EqualTo(GameRunLevel.PreRoundLobby));
});

Example B: Testing Interaction via System Call

await server.WaitPost(() =>
{
    // Act: server-side user interaction with the target.
    interactionSystem.UserInteraction(user, server.Transform(target).Coordinates, target);
});

await server.WaitAssertion(() =>
{
    // Assert: the expected handler actually worked.
    Assert.That(interactHand, Is.True);
});

Example C: UI/BUI steps considering network RTT

await client.WaitPost(() => bui.SendMessage(message));

// We give time for client->server->client processing.
await pair.RunTicksSync(15);

await client.WaitAssertion(() =>
{
    Assert.That(expectedUiState, Is.True);
});

Mini checklist before PR

Practical notes from docs

Use this as an operational note, but always check the final decision against the current implementation of the code.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.