"""Compare a narrow edit with the full snapshot formerly embedded in its reply. Run with a prebuilt ALBEDO_TEST_DAEMON and CLI, using nix develop: python3 e2e/run.py ../test/manual/api_configuration_payload.py The measurement is written to /tmp/albedo-api-configuration-payload.json. The full snapshot is a lower bound on the former envelope, not a timed baseline. The shared harness owns and stops the private daemon and provider. """ import json from pathlib import Path import sys import unittest sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "e2e")) from harness import Albedo, Provider, text # noqa: E402 def main(): provider = Provider(lambda _: text("response " * 1000)) try: with Albedo(provider) as app: session = app.session() for _ in range(4): app.prompt(session, "history " * 1000).close() app.idle(session) route = f"/sessions/{session}" measurements = {} for name, intent in { "rename": {"name": "payload measurement"}, "effort": {"effort": "inherit"}, "window": {"context_window": 32000}, }.items(): with app.api(route + "/configuration") as response: etag = response.headers["ETag"] with app.api( route + "/configuration", intent, method="PATCH", headers={"If-Match": etag}, ) as response: patch = response.read() with app.api(route) as response: snapshot = response.read() measurements[name] = { "configuration_patch_bytes": len(patch), "full_snapshot_bytes": len(snapshot), "reduction_vs_snapshot_percent": round( 100 * (1 - len(patch) / len(snapshot)), 2 ), "configuration_write_requests_with_observed_etag": 1, "post_patch_configuration_reads": 0, } Path("/tmp/albedo-api-configuration-payload.json").write_text( json.dumps(measurements, indent=2) ) finally: provider.close() class ConfigurationPayload(unittest.TestCase): def test_measure_payload(self): main()