PDFLUMINOUSBehaveTests/study/corpus/pages/luminous-behave-test-suite.html
Test Suite · Behave
LUMINOUS Behave Test Suite
Below are the files for a Behave-based test suite that exercises the entire LUMINOUS wheel universe.
Author: David William Sylvester
Format: PDF → HTML
Scope: 5 source files
Notes

This page contains only the PDF's extracted contents, formatted into sections with copy-friendly code blocks.

src/luminous_behave/init.py

"""LUMINOUS Behave meta-package.

This package contains Behave features and step definitions that validate:

* All LUMINOUS wheels build successfully

* Core CLIs are callable and return successful exit codes
* Selected REPL and pipeline utilities are discoverable

"""

from importlib.metadata import version, PackageNotFoundError

__all__ = [

"get_package_version",

]

def get_package_version(name: str) -> str:

"""Return the installed version of a package, or "unknown" if not found."""

try:

return version(name)

except PackageNotFoundError:

return "unknown"

src/luminous_behave/paths.py

"""Shared path helpers for Behave tests.

These helpers assume the following mono-repo layout (Windows example):

E:\\luminous\  

    luminous_core\  

    luminous_corpus\  

    luminous_cli\  

1

    luminous-nebula\  

    sqlite\  

    selenium\  

    playwrite\  

    ngnix\  

    monitoring\  

    modelfile\  

    keydb\  

    JanusGraph\  

    compose-ui\  

    behave\  

The helpers are careful to resolve paths relative to this file, so the

suite works when invoked from the repo root with::

    behave -k src/luminous_behave/features

"""

from __future__ import annotations

import os

from pathlib import Path

from typing import Dict, Iterable, List

# Names of all wheel-bearing packages in the LUMINOUS universe.

WHEEL_PACKAGES: List[str] = [

"luminous_core",

"luminous_corpus",

"luminous_cli",

"luminous-nebula",

"sqlite",

"selenium",

"playwrite",

"ngnix",

"monitoring",

"modelfile",

"keydb",

"JanusGraph",

"compose-ui",

"behave",

# meta-wheel, hosts this suite

]

def find_repo_root() -> Path:

"""Return the mono-repo root.

    Strategy:

2

    * Start from this file

    * Walk upward until we see a sentinel like `luminous_core` or

      `pyproject.toml` in the directory.

    """

here = Path(__file__).resolve()

for candidate in [here] + list(here.parents):

if (candidate / "luminous_core").is_dir() and (candidate /

"pyproject.toml").exists():

return candidate

# Fallback to current working directory if detection fails

return Path.cwd().resolve()

def iter_package_dirs() -> Dict[str, Path]:

"""Return a mapping of wheel package name to directory path.

    Only entries that actually exist on disk are returned.

    """

root = find_repo_root()

mapping: Dict[str, Path] = {}

for name in WHEEL_PACKAGES:

path = root / name

if path.is_dir():

mapping[name] = path

return mapping

def get_package_dir(name: str) -> Path:

"""Return the directory for a given wheel package name.

    Raises FileNotFoundError if no directory exists.

    """

mapping = iter_package_dirs()

try:

return mapping[name]

except KeyError as exc:

raise FileNotFoundError(f"No package directory for {name!r} under repo 

root {find_repo_root()}" ) from exc

def list_pyproject_packages() -> Dict[str, Path]:

"""Auto-discover any subdirectories that contain a pyproject.toml.

3

    This is used by the wheel universe tests to verify that we cover all

    buildable wheels, even when new ones are added.

    """

root = find_repo_root()

candidates: Dict[str, Path] = {}

for child in root.iterdir():

if not child.is_dir():

continue

if (child / "pyproject.toml").exists():

candidates[child.name] = child

return candidates

src/luminous_behave/features/wheel_universe.feature

Feature: LUMINOUS wheel universe builds successfully

  All wheel-bearing packages in the LUMINOUS mono-repo must build

  a wheel artifact without errors.

Background:

    Given the LUMINOUS mono-repo root is detected

  # Explicitly test the curated universe list

Scenario Outline: Curated wheel package builds cleanly

    Given the package "<package_name>" has a pyproject

When I build a wheel for that package

Then the build should succeed

And the package dist directory should contain at least one wheel

Examples:

      | package_name   |

      | luminous_core  |

      | luminous_corpus|

      | luminous_cli   |

      | luminous-nebula|

      | sqlite         |

      | selenium       |

      | playwrite      |

      | ngnix          |

      | monitoring     |

      | modelfile      |

      | keydb          |

4

      | JanusGraph     |

      | compose-ui     |

      | behave         |

  # Also assert that all auto-detected pyproject packages are buildable.

Scenario: All auto-discovered pyproject packages build cleanly

    Given I have auto-discovered all pyproject packages in the repo

When I build wheels for each discovered package

Then every discovered package should have at least one built wheel

src/luminous_behave/features/cli_universe.feature

Feature: LUMINOUS CLI entrypoints respond successfully

  All top-level CLIs and important entrypoints should return a zero

  exit status and show helpful text when invoked with --help.

Background:

    Given the LUMINOUS mono-repo root is detected

Scenario Outline: Core CLI entrypoints run with --help

    When I run the command "<command>" from the repo root

Then the command should succeed

And the command stdout should contain "<expected>"

Examples:

      | command                                         | expected   |

      | python -m luminous_cli.main --help              | usage      |

      | python -m luminous_core.engine_context --help   | Engine     |

      | python -m luminous_core.loader --help           | LUMINOUS   |

      | python -m luminous_core.registry --help         | registry   |

Scenario Outline: Wheel helper CLIs respond

    When I run the command "<command>" from the repo root

Then the command should succeed

Examples:

      | command                                      |

      | python build_all_wheels.py                  |

      | python enhanced_wheel_linter.py --summary   |

      | python wheel_bundle_generator.py --dry-run  |

5

FILE: src/luminous_behave/features/repl_and_pipeline.feature

Feature: REPL and pipeline utilities are discoverable

  The OmniNix REPLs and pipeline scripts should be invocable enough

  to show their introductory banners or help text.

Background:

    Given the LUMINOUS mono-repo root is detected

Scenario Outline: OmniNix REPL scripts are importable

    When I import the module "<module_name>"

Then the import should succeed

Examples:

      | module_name               |

      | omnix_repl                |

      | omnix_repl_v2             |

      | omnix_repl_v3             |

      | omnihydra_repl           |

Scenario Outline: Pipeline helper scripts expose main entry point

    When I import the module "<module_name>"

Then the module should define a callable "main"

Examples:

      | module_name                          |

      | phase_1_to_mkgx_converter            |

      | endgame_authoring_templates_generator|

      | endgame_authored_packager            |

src/luminous_behave/features/steps/common_steps.py

from __future__ import annotations

import os

import runpy

import subprocess

import sys

from importlib import import_module

from pathlib import Path

from typing import Dict, List

from behave import given, when, then

6

from luminous_behave.paths import (

find_repo_root,

get_package_dir,

list_pyproject_packages,

)

@given("the LUMINOUS mono-repo root is detected")

def step_detect_repo_root(context):

"""Detect and remember the LUMINOUS mono-repo root directory."""

repo_root = find_repo_root()

if not repo_root.exists():

raise AssertionError("Repo root does not exist: %s" % repo_root)

context.repo_root = repo_root

# Ensure src paths for core wheels are importable

sys.path.insert(0, str(repo_root / "luminous_core" / "src"))

sys.path.insert(0, str(repo_root / "luminous_corpus" / "src"))

sys.path.insert(0, str(repo_root / "luminous_cli" / "src"))

@given('the package "{package_name}" has a pyproject')

def step_package_has_pyproject(context, package_name: str):

"""Ensure a given package directory exists and has pyproject.toml."""

repo_root: Path = getattr(context, "repo_root", find_repo_root())

pkg_dir = repo_root / package_name

if not pkg_dir.is_dir():

raise AssertionError(f"Package directory not found: {pkg_dir}")

pyproject = pkg_dir / "pyproject.toml"

if not pyproject.exists():

raise AssertionError(f"pyproject.toml not found in {pkg_dir}")

context.current_package_name = package_name

context.current_package_dir = pkg_dir

@given("I have auto-discovered all pyproject packages in the repo")

def step_discover_pyproject_packages(context):

"""Discover all subdirectories with a pyproject.toml file."""

mapping = list_pyproject_packages()

if not mapping:

7

raise AssertionError("No pyproject-bearing packages discovered in repo")

context.discovered_packages = mapping

@when("I build a wheel for that package")

def step_build_wheel_for_current_package(context):

"""Invoke python -m build --wheel for the current package directory."""

pkg_dir: Path = context.current_package_dir

dist_dir = pkg_dir / "dist"

if dist_dir.exists():

for child in dist_dir.iterdir():

if child.is_file():

child.unlink()

cmd = [sys.executable, "-m", "build", "--wheel"]

result = subprocess.run(

cmd,

cwd=str(pkg_dir),

capture_output=True,

text=True,

)

context.build_result = result

context.dist_dir = dist_dir

@when("I build wheels for each discovered package")

def step_build_wheels_for_all_discovered(context):

"""Build wheels for all discovered pyproject-bearing packages."""

discovered: Dict[str, Path] = context.discovered_packages

results: Dict[str, subprocess.CompletedProcess] = {}

for name, pkg_dir in discovered.items():

dist_dir = pkg_dir / "dist"

if dist_dir.exists():

for child in dist_dir.iterdir():

if child.is_file():

child.unlink()

cmd = [sys.executable, "-m", "build", "--wheel"]

result = subprocess.run(

cmd,

cwd=str(pkg_dir),

capture_output=True,

8

text=True,

)

results[name] = result

context.multi_build_results = results

@when('I run the command "{command}" from the repo root')

def step_run_command_from_root(context, command: str):

"""Run an arbitrary shell command from the repo root."""

repo_root: Path = getattr(context, "repo_root", find_repo_root())

result = subprocess.run(

command,

shell=True,

cwd=str(repo_root),

capture_output=True,

text=True,

)

context.command = command

context.command_result = result

@when('I import the module "{module_name}"')

def step_import_module(context, module_name: str):

"""Attempt to import a module by name.

    The repo root and key src directories are already injected into sys.path

    by the repo-root step.

    """

try:

module = import_module(module_name)

except Exception as exc:

# noqa: BLE001

context.import_error = exc

context.imported_module = None

else:

context.import_error = None

context.imported_module = module

@then("the build should succeed")

def step_build_should_succeed(context):

result: subprocess.CompletedProcess = context.build_result

if result.returncode != 0:

message = [

9

f"Build failed with exit code {result.returncode}",

"STDOUT:",

result.stdout,

"STDERR:",

result.stderr,

]

raise AssertionError("\n".join(message))

@then("the package dist directory should contain at least one wheel")

def step_package_dist_has_wheel(context):

dist_dir: Path = context.dist_dir

if not dist_dir.exists():

raise AssertionError(f"dist directory does not exist: {dist_dir}")

wheels = [p for p in dist_dir.iterdir() if p.suffix == ".whl"]

if not wheels:

raise AssertionError(f"No wheel files found in {dist_dir}")

@then("every discovered package should have at least one built wheel")

def step_every_discovered_has_wheel(context):

results: Dict[str, subprocess.CompletedProcess] =

context.multi_build_results

failures: List[str] = []

for name, result in results.items():

pkg_dir = list_pyproject_packages()[name]

dist_dir = pkg_dir / "dist"

wheels = [p for p in dist_dir.iterdir() if p.suffix == ".whl"]

if result.returncode != 0 or not wheels:

failures.append(

f"{name}: exit={result.returncode}, wheels={len(wheels)}"

)

if failures:

joined = "\n".join(failures)

raise AssertionError(

"Some discovered packages failed to build wheels:\n" + joined

)

@then("the command should succeed")

def step_command_should_succeed(context):

result: subprocess.CompletedProcess = context.command_result

if result.returncode != 0:

message = [

10

f"Command failed: {context.command}",

f"Exit code: {result.returncode}",

"STDOUT:",

result.stdout,

"STDERR:",

result.stderr,

]

raise AssertionError("\n".join(message))

@then('the command stdout should contain "{expected}"')

def step_command_stdout_contains(context, expected: str):

result: subprocess.CompletedProcess = context.command_result

stdout_lower = result.stdout.lower()

if expected.lower() not in stdout_lower:

message = [

f"Expected substring {expected!r} not found in stdout.",

"STDOUT:",

result.stdout,

]

raise AssertionError("\n".join(message))

@then("the import should succeed")

def step_import_should_succeed(context):

if context.import_error is not None:

raise AssertionError(f"Import failed: {context.import_error!r}")

if context.imported_module is None:

raise AssertionError("Import did not yield a module object")

@then('the module should define a callable "main"')

def step_module_has_callable_main(context):

module = context.imported_module

if module is None:

raise AssertionError("No imported module available in context")

if not hasattr(module, "main"):

raise AssertionError(f"Module {module.__name__} has no attribute 

'main'")

if not callable(getattr(module, "main")):

raise AssertionError(f"Attribute main on {module.__name__} is not 

callable")

11

FILE: src/luminous_behave/features/environment.py

"""Behave environment hooks.

The primary responsibility here is to ensure that the LUMINOUS mono-repo

root is on the path before any steps are executed, so that imports such as

`luminous_core` and `luminous_corpus` succeed.

"""

from __future__ import annotations

import sys

from pathlib import Path

from luminous_behave.paths import find_repo_root

def before_all(context):

repo_root = find_repo_root()

context.repo_root = repo_root

# Make sure mono-repo packages are importable via src layout

sys.path.insert(0, str(repo_root / "luminous_core" / "src"))

sys.path.insert(0, str(repo_root / "luminous_corpus" / "src"))

sys.path.insert(0, str(repo_root / "luminous_cli" / "src"))

def before_scenario(context, scenario):

# Ensure each scenario starts with a clean command/import state

for attr in [

"current_package_name",

"current_package_dir",

"build_result",

"dist_dir",

"discovered_packages",

"command",

"command_result",

"imported_module",

"import_error",

]:

if hasattr(context, attr):

delattr(context, attr)

12