Skip to content

Harden test and release quality gates - #33

Merged
JovaniPink merged 1 commit into
masterfrom
quality-gates-hardening
Jul 21, 2026
Merged

Harden test and release quality gates#33
JovaniPink merged 1 commit into
masterfrom
quality-gates-hardening

Conversation

@JovaniPink

Copy link
Copy Markdown
Owner

Summary

  • make composable guards advertise and accept the canonical HandlerArgs contract
  • modernize strict setup() fixtures and canonical examples to HandlerArgs and XState v5 guard
  • replace a permissive guard assertion with an exact context-vs-event regression
  • register the intended action implementation in machine tests instead of tolerating warnings
  • promote every unhandled pytest warning to an error
  • raise the enforced branch-coverage floor from 50% to 90% (current result: 92.04%)
  • add an installed-wheel artifact validator
  • run package metadata, build, and wheel validation in PR CI, release preflight, and release publishing
  • lint scripts/ everywhere contributor and CI commands are documented
  • build once and publish the already-validated artifacts in the release workflow

Why

The suite passed while emitting 17 warnings from stale strict-setup fixtures and an unregistered test action. Canonical examples also still used legacy cond keys and legacy registered handler forms.

A 50% coverage floor did not reflect the repository's actual 92% coverage, and the release path tested the checkout but never proved that the built wheel could be installed and run without source-tree shadowing.

This adopts the artifact-validation pattern used successfully in the neighboring projects: validate what will actually ship, not only the source workspace.

Installed-wheel validation

scripts/validate_distribution.py:

  • resolves the expected wheel from pyproject.toml
  • creates a clean temporary virtual environment
  • installs the local wheel with --no-index --no-deps
  • removes PYTHONPATH and disables user-site imports
  • verifies installed package metadata and version
  • verifies the shipped py.typed marker
  • imports the SCXML entry point
  • starts a machine actor, sends an event, checks the resulting snapshot, and stops it

Test policy

  • unhandled warnings now fail immediately through pytest configuration
  • explicit compatibility-warning tests remain valid because they capture their expected warnings
  • coverage below 90% fails CI
  • the primary and configured SCXML suites currently complete with no warning summary

Release behavior

The release workflow now builds the distribution, validates those exact artifacts, and then runs poetry publish. It no longer rebuilds a different artifact during the publish command.

Validation

  • poetry run python -m pytest tests/ --ignore=tests/test_scxml.py (413 passed, zero warnings)
  • poetry run python -m pytest tests/test_scxml.py (54 passed, zero warnings)
  • poetry run pytest tests/ --ignore=tests/test_scxml.py --cov --cov-report=xml (413 passed, 92.04%)
  • poetry run mypy src/xstate/
  • poetry run ruff format --check src/ tests/ scripts/ docs/examples/
  • poetry run ruff check src/ tests/ scripts/ docs/examples/
  • poetry check --lock
  • poetry build
  • poetry run python scripts/validate_distribution.py
  • full local release preflight with HEAD used as both target and master reference
  • git diff --check

@JovaniPink
JovaniPink merged commit 59e956c into master Jul 21, 2026
4 checks passed
@JovaniPink
JovaniPink deleted the quality-gates-hardening branch July 21, 2026 16:07

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a release artifact validation gate by adding a validate_distribution.py script that builds and tests the wheel in an isolated environment. It also updates documentation, examples, and tests to adopt the HandlerArgs and guard conventions, raises the test coverage threshold to 90%, and treats warnings as errors. The code review feedback suggests improving the robustness of the distribution validation script by capturing both stdout and stderr during failures and using globbing to locate the built wheel to handle PEP 440 version normalization. Additionally, it recommends removing a redundant signature definition in _StateInGuard since it is now inherited from _ComposableGuard.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +82 to +84
details = (completed.stderr or completed.stdout).strip()
if details:
print(details, file=sys.stderr, flush=True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In run_checked, the error reporting logic uses completed.stderr or completed.stdout to extract the command output details. If a command prints useful diagnostic information to stdout but also emits something to stderr, the stdout content will be completely swallowed and omitted from the error message.

It is safer and more robust to capture and print both stdout and stderr if they are present, ensuring no diagnostic output is lost during CI failures.

Suggested change
details = (completed.stderr or completed.stdout).strip()
if details:
print(details, file=sys.stderr, flush=True)
details = []
if completed.stdout:
details.append(completed.stdout.strip())
if completed.stderr:
details.append(completed.stderr.strip())
if details:
print("\n".join(details), file=sys.stderr, flush=True)

Comment on lines +61 to +65
def built_wheel(version: str) -> Path:
wheel = DIST / f"xstate-{version}-py3-none-any.whl"
if not wheel.is_file():
fail(f"expected built wheel {wheel}; run 'poetry build' first")
return wheel

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Constructing the wheel filename directly using f"xstate-{version}-py3-none-any.whl" can be fragile if the version string in pyproject.toml contains prerelease tags or local version identifiers (e.g., 0.7.0-alpha.1). Tools like Poetry normalize these version strings according to PEP 440 when building the wheel (producing filenames like xstate-0.7.0a1-py3-none-any.whl or xstate-0.7.0_alpha.1-py3-none-any.whl), which would cause this exact match to fail.

Falling back to globbing the dist/ directory when an exact match is not found makes the validation script much more resilient.

def built_wheel(version: str) -> Path:
    normalized_version = version.replace("-", "_")
    wheel = DIST / f"xstate-{normalized_version}-py3-none-any.whl"
    if not wheel.is_file():
        wheels = list(DIST.glob("xstate-*.whl"))
        if len(wheels) == 1:
            return wheels[0]
        fail(f"expected built wheel {wheel}; run 'poetry build' first")
    return wheel

Comment thread src/xstate/guards.py
Comment on lines +54 to +61
__signature__ = inspect.Signature(
[
inspect.Parameter(
"args",
inspect.Parameter.POSITIONAL_OR_KEYWORD,
)
]
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since _ComposableGuard now defines __signature__, all subclasses (including _StateInGuard) will automatically inherit this attribute. The explicit definition of __signature__ on _StateInGuard (around line 172) is now redundant and can be safely removed to clean up the codebase and avoid duplication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant