Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: tests

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
test:
name: pytest (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.11", "3.12"]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install package + dev dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"

- name: Run pytest
run: |
pytest tests/ -v --tb=short

- name: Verify CLI wrappers load (no execution)
# The wrappers read from the operator's production dataset by default
# (os.environ.setdefault). We only verify they import cleanly — running
# them would require a dataset, which pytest already covers.
run: |
python -c "from cmdb.api import cmdb_validate; print('cmdb.api OK')"
python -c "import importlib.util, pathlib; spec = importlib.util.spec_from_file_location('w', 'integrations/hermes/tools/cmdb_validate.py'); mod = importlib.util.module_from_spec(spec); print('wrapper import OK')"
28 changes: 28 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
Pytest configuration for knowledge-kernel.

Routes CMDB_DATA_DIR to a bundled test fixture dataset so that:
- CI runs are reproducible (no dependency on user's ~/knowledge/...)
- Local tests do NOT pollute or read the user's production dataset
- Each test run starts from a known, minimal state

The fixture lives at tests/fixtures/dataset/ and contains 3 entities:
- fixture-server-a (asset, with relations)
- fixture-server-b (asset, no relations)
- fixture-software-x (software)

The user can override the dataset for local debugging by setting
CMDB_DATA_DIR explicitly before invoking pytest.
"""

import os
from pathlib import Path

# Locate the fixture dataset relative to this conftest.py
FIXTURE_DATA_DIR = Path(__file__).resolve().parent / "fixtures" / "dataset"


def pytest_configure(config):
"""Set CMDB_DATA_DIR to the fixture dataset unless already overridden."""
if "CMDB_DATA_DIR" not in os.environ:
os.environ["CMDB_DATA_DIR"] = str(FIXTURE_DATA_DIR)
29 changes: 29 additions & 0 deletions tests/fixtures/dataset/asset/fixture-server-a.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
schema_version: 2
id: fixture-server-a
kind: asset
domain: infrastructure
metadata:
name: Fixture Server A
description: Test asset for CI — first entity
primary_ip: 10.0.0.1
hostname: fixture-a
status: operational
provenance:
discovered_by: test_fixture
discovery_method: direct_observation
discovery_run: '2026-01-01T00:00:00Z'
evidence:
source: "CI test fixture — synthetic data"
observed_at: '2026-01-01T00:00:00Z'
confidence: high
method:
- "fixture entity for acceptance tests"
relations:
- target: fixture-software-x
type: runs_on
criticality:
business: low
operational: low
technical: low
tags:
- ci-fixture
27 changes: 27 additions & 0 deletions tests/fixtures/dataset/asset/fixture-server-b.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
schema_version: 2
id: fixture-server-b
kind: asset
domain: infrastructure
metadata:
name: Fixture Server B
description: Test asset for CI — second entity
primary_ip: 10.0.0.2
hostname: fixture-b
status: operational
provenance:
discovered_by: test_fixture
discovery_method: direct_observation
discovery_run: '2026-01-01T00:00:00Z'
evidence:
source: "CI test fixture — synthetic data"
observed_at: '2026-01-01T00:00:00Z'
confidence: high
method:
- "fixture entity for acceptance tests"
relations: []
criticality:
business: low
operational: low
technical: low
tags:
- ci-fixture
26 changes: 26 additions & 0 deletions tests/fixtures/dataset/software/fixture-software-x.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
schema_version: 2
id: fixture-software-x
kind: software
domain: software
metadata:
name: Fixture Software X
description: Test software for CI — runs on fixture-server-a
version: 1.0.0
status: operational
provenance:
discovered_by: test_fixture
discovery_method: direct_observation
discovery_run: '2026-01-01T00:00:00Z'
evidence:
source: "CI test fixture — synthetic data"
observed_at: '2026-01-01T00:00:00Z'
confidence: high
method:
- "fixture entity for acceptance tests"
relations: []
criticality:
business: low
operational: low
technical: low
tags:
- ci-fixture
Loading