Files
cleveragents-core/robot/helper_m5_e2e_support.py
T
HAL9000 80bc9c552d
CI / benchmark-publish (pull_request) Has been skipped
CI / push-validation (pull_request) Successful in 33s
CI / helm (pull_request) Successful in 45s
CI / build (pull_request) Successful in 1m4s
CI / lint (pull_request) Successful in 1m13s
CI / typecheck (pull_request) Successful in 1m31s
CI / quality (pull_request) Successful in 1m37s
CI / security (pull_request) Successful in 1m49s
CI / integration_tests (pull_request) Successful in 3m34s
CI / e2e_tests (pull_request) Successful in 5m6s
CI / unit_tests (pull_request) Successful in 6m14s
CI / docker (pull_request) Successful in 1m36s
CI / coverage (pull_request) Successful in 12m27s
CI / status-check (push) Blocked by required conditions
CI / coverage (push) Blocked by required conditions
CI / docker (push) Blocked by required conditions
CI / unit_tests (push) Has started running
CI / status-check (pull_request) Successful in 4s
CI / helm (push) Successful in 31s
CI / build (push) Successful in 53s
CI / lint (push) Successful in 1m3s
CI / quality (push) Successful in 1m13s
CI / typecheck (push) Successful in 1m46s
CI / security (push) Successful in 1m46s
CI / push-validation (push) Successful in 20s
CI / benchmark-publish (push) Failing after 43s
CI / e2e_tests (push) Successful in 4m9s
CI / integration_tests (push) Successful in 6m57s
test: restore and enhance e2e test coverage
Fix malformed imports in helper_m1_e2e_verification.py and
helper_m4_e2e_cli.py where 'from helpers_common import reset_global_state'
was incorrectly inserted inside a parenthesized import block, causing
Python syntax errors and breaking the lint and unit_tests CI gates.

Also fix import ordering in helper_m2_e2e_verification.py,
helper_m5_e2e_context.py, helper_m5_e2e_support.py, and
helper_m5_e2e_verification.py to satisfy ruff I001 import-sort rules
by placing helpers_common imports in the correct group alongside other
local robot/ helper imports.

ISSUES CLOSED: #8459
2026-05-01 00:59:02 +00:00

98 lines
2.9 KiB
Python

"""Shared helpers for the M5 Robot E2E verification commands."""
from __future__ import annotations
import sys
from pathlib import Path
from typing import Any, NoReturn, cast
from helpers_common import reset_global_state
from sqlalchemy import create_engine
from sqlalchemy.orm import Session, sessionmaker
from cleveragents.application.services.resource_registry_service import (
ResourceRegistryService,
)
from cleveragents.domain.models.core.project import (
NamespacedProject,
parse_namespaced_name,
)
from cleveragents.infrastructure.database.models import Base
from cleveragents.infrastructure.database.repositories import (
NamespacedProjectRepository,
ProjectResourceLinkRepository,
)
def _fail(msg: str) -> NoReturn:
"""Print failure message to stderr and exit with code 1."""
print(f"FAIL: {msg}", file=sys.stderr)
raise SystemExit(1)
class _NoClose:
"""Session wrapper that suppresses ``close()`` for in-memory SQLite."""
def __init__(self, session: object) -> None:
object.__setattr__(self, "_s", session)
def close(self) -> None:
pass
def __getattr__(self, name: str) -> Any:
return getattr(object.__getattribute__(self, "_s"), name)
def _setup_db() -> tuple[
NamespacedProjectRepository,
ProjectResourceLinkRepository,
ResourceRegistryService,
Any,
]:
"""Create an in-memory SQLite DB with all tables."""
reset_global_state()
engine = create_engine("sqlite:///:memory:", echo=False)
Base.metadata.create_all(engine)
session = sessionmaker(bind=engine, expire_on_commit=False)()
wrapper = _NoClose(session)
def factory() -> Session:
return cast(Session, wrapper)
proj_repo = NamespacedProjectRepository(session_factory=factory)
link_repo = ProjectResourceLinkRepository(session_factory=factory)
svc = ResourceRegistryService(session_factory=factory)
svc.bootstrap_builtin_types()
return proj_repo, link_repo, svc, factory
def _create_project(
repo: NamespacedProjectRepository,
name: str,
description: str | None = None,
) -> NamespacedProject:
"""Create and return a NamespacedProject via the repository."""
reset_global_state()
parsed = parse_namespaced_name(name)
proj = NamespacedProject(
name=parsed.name,
namespace=parsed.namespace,
description=description,
)
repo.create(proj)
return repo.get(proj.namespaced_name)
def _create_large_python_repo(root: Path) -> int:
"""Populate *root* with 10,000 small Python files and return the count."""
file_count = 0
for i in range(100):
module_dir = root / f"module_{i:03d}"
module_dir.mkdir(parents=True, exist_ok=True)
for j in range(100):
(module_dir / f"file_{j:03d}.py").write_text(
f"def f_{i}_{j}():\n return {i + j}\n"
)
file_count += 1
return file_count