migrate-harness-tests-to-state-transition-test

Installation
SKILL.md

Migrate Harness Tests To State Transition Test

Overview

Guide charm maintainers through replacing deprecated Harness-based unit tests with deterministic state-transition tests that mirror how Juju actually fires events. Use this skill whenever a test still instantiates testing.Harness or chains multiple events inside one fixture.

When To Use

  • ops.testing.Harness (or Scenario Harness helpers) still appear in tests or fixtures.
  • Migration requires modeling relations, containers, secrets, or actions with testing.State.
  • CI must stay green while Harness-only helpers (add_relation, evaluate_status, etc.) are removed.

Preflight Checks

  • Inspect pyproject.toml (or requirements files) before touching code; ensure ops[testing] is present in every dependency group that executes Scenario/state-transition tests. Remove legacy ops-scenario if it lingers.
  • Match the repo’s package manager: use uv add --group unit ops[testing] (and mirror across groups) when [tool.uv] or uv.lock exists; otherwise edit the appropriate requirements.txt, Poetry group, etc.
  • After dependency edits, re-sync the exact groups you touched (uv sync --group unit --group lint, poetry install, etc.) so the virtualenv contains Scenario Context.
  • Re-run the project’s bootstrap entrypoint (uv sync, pip install -r requirements.txt, make setup, …) to align local + CI execution before rewriting tests.
Related skills

More from canonical/copilot-collections

Installs
1
GitHub Stars
25
First Seen
Mar 27, 2026