The first rc.3 perf comparison reused the old workload commands but switched them to `run/call --output json`, so the candidate was timed while producing thousands of structural events that the beta baseline never emitted. The result was a reproducible +240..+375% p50 and +130% RSS delta caused by the measurement, not by the program's execution cost. - Give each run/call workload a correctness command (current Observation snapshot, full contract digest) and a measurement command (plain execution path, committed text digest). - Verify the correctness digest once per workload and the measurement digest on every timed sample; a wrong or changed output is never timed. - Re-record the expected digests and extend the tooling tests. - A protocol document that is produced only on request must not be billed as an execution regression.
145 lines
5.3 KiB
Python
145 lines
5.3 KiB
Python
"""Tests for the performance workload catalogue and correctness digest.
|
|
|
|
The G4 release gate runs one fixed release binary over nine workloads. A
|
|
retired CLI option or a digest that changes per invocation silently turns a
|
|
correctness-verified measurement into CORRECTNESS_FAIL, so both are pinned
|
|
here.
|
|
"""
|
|
|
|
import importlib.util
|
|
import json
|
|
import pathlib
|
|
import unittest
|
|
|
|
ROOT = pathlib.Path(__file__).resolve().parents[2]
|
|
WORKLOADS = ROOT / "tools" / "perf" / "workloads.json"
|
|
RUNNER = ROOT / "tools" / "perf" / "runner.py"
|
|
|
|
|
|
def load_runner():
|
|
spec = importlib.util.spec_from_file_location("marqdo_perf_runner", RUNNER)
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
def snapshot(run_id: str, status: str, value, extra_file: str = "/tmp/index.mq.md"):
|
|
return {
|
|
"schema": "marqdo.observation",
|
|
"schema_version": 1,
|
|
"run": {"id": run_id, "status": status, "source": None},
|
|
"capture": {},
|
|
"events": [
|
|
{
|
|
"schema": "marqdo.observation",
|
|
"schema_version": 1,
|
|
"run_id": run_id,
|
|
"seq": 0,
|
|
"kind": "stream.opened",
|
|
"payload": {"producer": {"name": "marqdo", "version": "3.0.0-rc.3"}},
|
|
},
|
|
{
|
|
"schema": "marqdo.observation",
|
|
"schema_version": 1,
|
|
"run_id": run_id,
|
|
"seq": 1,
|
|
"kind": "run.started",
|
|
"payload": {"entry": "e::index.mq.md::main", "started_unix_ms": 1795523668882},
|
|
},
|
|
{
|
|
"schema": "marqdo.observation",
|
|
"schema_version": 1,
|
|
"run_id": run_id,
|
|
"seq": 2,
|
|
"kind": "run.completed",
|
|
"payload": {"status": status, "value": value, "value_type": "Int"},
|
|
},
|
|
],
|
|
}
|
|
|
|
|
|
class WorkloadCatalogueTest(unittest.TestCase):
|
|
def test_run_and_call_workloads_use_the_current_output_option(self):
|
|
catalogue = json.loads(WORKLOADS.read_text(encoding="utf-8"))
|
|
workloads = catalogue["workloads"]
|
|
self.assertEqual(len(workloads), 9)
|
|
for workload in workloads:
|
|
argv = workload["argv"]
|
|
if workload["kind"] in ("run", "call"):
|
|
self.assertIn(
|
|
["--output", "json"],
|
|
[argv[index : index + 2] for index in range(len(argv))],
|
|
f"{workload['name']} must request the current Observation snapshot",
|
|
)
|
|
self.assertNotIn(
|
|
"--json",
|
|
argv,
|
|
f"{workload['name']} still passes the retired run/call flag",
|
|
)
|
|
else:
|
|
self.assertIn("--json", argv)
|
|
|
|
|
|
class DualCommandWorkloadTest(unittest.TestCase):
|
|
def test_run_and_call_workloads_separate_correctness_from_timing(self):
|
|
catalogue = json.loads(WORKLOADS.read_text(encoding="utf-8"))
|
|
for workload in catalogue["workloads"]:
|
|
if workload["kind"] not in ("run", "call"):
|
|
self.assertNotIn("measure_argv", workload)
|
|
continue
|
|
measure = workload.get("measure_argv")
|
|
self.assertIsNotNone(measure, f"{workload['name']} lacks measure_argv")
|
|
self.assertNotIn("--output", measure)
|
|
self.assertNotIn("--json", measure)
|
|
self.assertEqual(measure[0], workload["argv"][0])
|
|
|
|
|
|
class DigestStabilityTest(unittest.TestCase):
|
|
def setUp(self):
|
|
self.runner = load_runner()
|
|
|
|
def test_observation_digest_ignores_run_identity_and_paths(self):
|
|
first = self.runner.wire_digest(snapshot("run-1", "ok", 120))
|
|
second = self.runner.wire_digest(
|
|
snapshot("run-2", "ok", 120, extra_file="/other/host/index.mq.md")
|
|
)
|
|
self.assertEqual(first, second)
|
|
|
|
def test_observation_digest_tracks_the_result(self):
|
|
ok = self.runner.wire_digest(snapshot("run-1", "ok", 120))
|
|
wrong = self.runner.wire_digest(snapshot("run-1", "ok", 121))
|
|
failed = self.runner.wire_digest(snapshot("run-1", "error", 120))
|
|
self.assertNotEqual(ok, wrong)
|
|
self.assertNotEqual(ok, failed)
|
|
|
|
def test_observation_digest_tracks_the_event_stream(self):
|
|
document = snapshot("run-1", "ok", 120)
|
|
truncated = dict(document)
|
|
truncated["events"] = document["events"][:2]
|
|
self.assertNotEqual(
|
|
self.runner.wire_digest(document), self.runner.wire_digest(truncated)
|
|
)
|
|
|
|
def test_measured_text_digest_ignores_the_checkout_path(self):
|
|
runner = self.runner
|
|
first = runner.text_digest(b"output 120\n")
|
|
second = runner.text_digest(b"output 120\n")
|
|
self.assertEqual(first, second)
|
|
self.assertNotEqual(first, runner.text_digest(b"output 121\n"))
|
|
|
|
def test_check_document_keeps_the_command_digest(self):
|
|
report = {
|
|
"command": "check",
|
|
"success": True,
|
|
"diagnostics": [{"code": "sem.x", "severity": "error", "line": 1, "column": 2, "message": "m"}],
|
|
"stdout": "",
|
|
"stderr": "",
|
|
}
|
|
normalized = self.runner.normalize(report)
|
|
self.assertEqual(normalized["command"], "check")
|
|
self.assertEqual(len(normalized["diagnostics"]), 1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|