Skip to content

Add full-cycle integration test for _on_tick #234

Description

@itsmiso-ai

Problem

_on_tick() in scripts/main.gd (line 1360) is the game's main loop. It orchestrates:

  1. maybe_fire_event() — random events
  2. _clean_stale_reservations() — reservation cleanup
  3. apply_food_upkeep() — food deduction for extra workers
  4. Per-worker: choose_task()step_worker() (which calls do_build, gather, haul, etc.)
  5. GoalProgression.process_tick() — goal completion/rotation
  6. GoalReward.tick_rewards() — reward expiration/trickle
  7. persist() — save state
  8. render_all() — full UI refresh

None of the existing tests exercise this path:

  • tests/test_e2e.gd simulates ticks by incrementing counters manually and testing state persistence — it does NOT instantiate a Control and run _on_tick() with a real timer
  • Individual module tests (test_food_upkeep.gd, test_goal_progression.gd, etc.) test components in isolation

A regression in the tick orchestration (e.g., ordering bug, missing call, double-fire) would not be caught.

Fix

Create tests/test_tick_integration.gd that:

  1. Instantiates the main scene (or a test double with the same script)
  2. Sets up a minimal valid game state (a few tiles, one worker, one resource)
  3. Runs N ticks by calling _on_tick() directly (or via the timer signal)
  4. Asserts the expected state transitions:
    • Worker moves toward a resource
    • Resource is gathered
    • Food upkeep fires at the right interval
    • Events can fire
    • State is persisted (dirty flag cleared)
  5. Test edge cases: starvation, no available tasks, build completion

This will likely require some refactoring of _on_tick() to be testable without a full scene tree — at minimum, extracting the tick logic into a callable that doesn't depend on render_all().

Acceptance criteria

  • tests/test_tick_integration.gd exists and runs in headless mode
  • Test covers at least: worker movement, resource gathering, food upkeep, goal tick
  • Test runs without instantiating the full UI scene (mock or stub render_all)
  • Test is included in test_runner.gd

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions