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
45 changes: 45 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: integration
# SIM-08: this commit's modsim and modpoll against each other, with the conformance model of
# modpoll-wot, over Modbus TCP and RTU on a virtual serial port.

on:
push:
branches: [v2]
paths:
- packages/**
- integration/**
- pyproject.toml
- uv.lock
- .github/workflows/integration.yml
pull_request:
paths:
- packages/**
- integration/**
- pyproject.toml
- uv.lock
- .github/workflows/integration.yml

permissions:
contents: read

jobs:
conformance:
name: integration conformance
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
- uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6
with:
version: 0.11.19
python-version: '3.12'
enable-cache: true
cache-dependency-glob: uv.lock
- name: Install every workspace member
run: uv sync --locked --all-packages --all-extras --all-groups
- name: Read modsim with modpoll
run: uv run --locked --no-sync pytest -q integration --junitxml=integration-results.xml
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
if: always()
with:
name: integration
path: integration-results.xml
20 changes: 10 additions & 10 deletions .github/workflows/modsim-acceptance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [v2]
paths:
- packages/modsim/**
- packages/modpoll/**
- packages/modpoll-wot/**
- pyproject.toml
- uv.lock
Expand All @@ -13,6 +14,7 @@ on:
pull_request:
paths:
- packages/modsim/**
- packages/modpoll/**
- packages/modpoll-wot/**
- pyproject.toml
- uv.lock
Expand Down Expand Up @@ -70,20 +72,18 @@ jobs:
- uses: ./.github/actions/setup-uv
with:
package: modsim
# Unchanged by TOOL-01: the independent clients stay pinned to the modpoll commit and release they used.
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
repository: top-maker/modpoll
ref: 93daa74bc859fe8a5704f3e94e4f6eb0df797ec2
path: packages/modsim/.interop/modpoll
# SIM-08: the independent clients are this commit's modpoll, installed from its wheels apart
# from modsim, and modpoll's pinned node-wot reader.
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: '24'
- run: npm ci --prefix .interop/modpoll/tools/wot-interop --ignore-scripts --no-audit --no-fund
- name: Install independent public modpoll
- run: npm ci --prefix ../modpoll/tools/wot-interop --ignore-scripts --no-audit --no-fund
- name: Install this commit's modpoll in its own environment
run: |
uv build --wheel --no-sources --package modpoll --out-dir "$RUNNER_TEMP/modpoll-dist"
uv build --wheel --no-sources --package modpoll-wot --out-dir "$RUNNER_TEMP/modpoll-dist"
uv venv "$RUNNER_TEMP/modpoll"
uv pip install --python "$RUNNER_TEMP/modpoll/bin/python" 'modpoll==2.0.0a2'
uv pip install --python "$RUNNER_TEMP/modpoll/bin/python" "$RUNNER_TEMP"/modpoll-dist/*.whl
- name: Test fixed public model with independent clients
run: |
uv build --wheel --no-sources --out-dir dist
Expand All @@ -93,7 +93,7 @@ jobs:
mkdir -p "$RUNNER_TEMP/catalog-acceptance/tools" "$RUNNER_TEMP/catalog-acceptance/examples"
cp tools/catalog-interop.py tools/fetch-models.py "$RUNNER_TEMP/catalog-acceptance/tools/"
cp examples/model-source.yaml "$RUNNER_TEMP/catalog-acceptance/examples/"
reader="$PWD/.interop/modpoll/tools/wot-interop/read-write.cjs"
reader="$PWD/../modpoll/tools/wot-interop/read-write.cjs"
cd "$RUNNER_TEMP/catalog-acceptance"
"$RUNNER_TEMP/modsim/bin/python" tools/fetch-models.py --output "$RUNNER_TEMP/catalog-acceptance/inputs"
"$RUNNER_TEMP/modsim/bin/python" tools/catalog-interop.py --modpoll-python "$RUNNER_TEMP/modpoll/bin/python" --node-reader "$reader" --output "$RUNNER_TEMP/catalog-interop.json"
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/modsim.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [v2]
paths:
- packages/modsim/**
- packages/modpoll/**
- packages/modpoll-wot/**
- pyproject.toml
- uv.lock
Expand All @@ -15,6 +16,7 @@ on:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- packages/modsim/**
- packages/modpoll/**
- packages/modpoll-wot/**
- pyproject.toml
- uv.lock
Expand Down Expand Up @@ -88,10 +90,13 @@ jobs:
with:
package: modsim

- name: Install an independent released modpoll
# SIM-08: the client is this commit's modpoll, installed from its wheels apart from modsim.
- name: Install this commit's modpoll in its own environment
run: |
uv build --wheel --no-sources --package modpoll --out-dir "$RUNNER_TEMP/modpoll-dist"
uv build --wheel --no-sources --package modpoll-wot --out-dir "$RUNNER_TEMP/modpoll-dist"
uv venv "$RUNNER_TEMP/modpoll"
uv pip install --python "$RUNNER_TEMP/modpoll/bin/python" 'modpoll==2.0.0a5'
uv pip install --python "$RUNNER_TEMP/modpoll/bin/python" "$RUNNER_TEMP"/modpoll-dist/*.whl

- name: Export with modpoll and replay with modsim
env:
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ uv sync --all-packages --all-extras --all-groups
cd packages/modpoll && uv run pytest
```

Each package keeps its own `Makefile`, tests and release notes. A release is a tag named after the package,
Each package keeps its own `Makefile`, tests and release notes. `integration/` runs this commit's modsim and
modpoll against each other with modpoll-wot's conformance model, over Modbus TCP and RTU on a virtual serial
port (`uv run pytest integration` after the sync above). A release is a tag named after the package,
for example `modsim-v2.0.0a13`, which runs that package's release workflow.
121 changes: 121 additions & 0 deletions integration/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
"""Run the workspace's own modsim and modpoll against each other (SIM-08)."""

from contextlib import contextmanager
import json
import os
from pathlib import Path
import re
import socket
import subprocess
import sys
import time

import pytest

ROOT = Path(__file__).resolve().parents[1]
FIXTURES = ROOT / "packages/modpoll-wot/tests/fixtures"
MODEL = FIXTURES / "conformance.tm.json"
DATA = FIXTURES / "conformance.data.json"


def free_port():
with socket.socket() as reservation:
reservation.bind(("127.0.0.1", 0))
return reservation.getsockname()[1]


@contextmanager
def simulator(tmp_path, transport, model=MODEL, data=DATA):
"""Start modsim on a free TCP port or a virtual serial port; yield the client's address."""
log_path = tmp_path / f"modsim-{transport}.log"
command = [
sys.executable,
"-m",
"modsim",
"--config",
str(model),
"--data",
str(data),
]
port = free_port() if transport == "tcp" else None
command += ["--port", str(port)] if port else ["--serial", "pty"]
with log_path.open("w+") as log:
process = subprocess.Popen(command, stdout=log, stderr=log, cwd=tmp_path)
try:
deadline = time.monotonic() + 30
while True:
if process.poll() is not None:
log.seek(0)
pytest.fail(log.read())
if port:
try:
socket.create_connection(("127.0.0.1", port), timeout=1).close()
address = port
break
except OSError:
pass
else:
log.seek(0)
found = re.search(
r"Virtual serial port for the client: (\S+)", log.read()
)
if found:
address = found.group(1)
break
if time.monotonic() > deadline:
pytest.fail(f"modsim did not start over {transport}")
time.sleep(0.1)
yield address
finally:
process.terminate()
try:
process.wait(timeout=10)
except subprocess.TimeoutExpired:
process.kill()
process.wait()


def endpoint_arguments(transport, address):
if transport == "tcp":
return ["--tcp", "127.0.0.1", "--tcp-port", str(address)]
return ["--rtu", address, "--rtu-baud", "9600"]


def run_modpoll(tmp_path, arguments):
result = subprocess.run(
[sys.executable, "-m", "modpoll", "--once", *arguments],
capture_output=True,
text=True,
timeout=60,
cwd=tmp_path,
stdin=subprocess.DEVNULL,
)
return result


def read_values(tmp_path, transport, address, model=MODEL):
output = tmp_path / f"values-{transport}.json"
result = run_modpoll(
tmp_path,
[
*endpoint_arguments(transport, address),
"--config",
str(model),
"--export",
str(output),
],
)
assert result.returncode == 0, result.stdout + result.stderr
(values,) = json.loads(output.read_text()).values()
return values


TRANSPORTS = [
"tcp",
pytest.param(
"rtu",
marks=pytest.mark.skipif(
os.name == "nt", reason="virtual serial ports need POSIX"
),
),
]
Loading
Loading