From 205d0cfbada75228508f5151d8eebf1ddd01d46b Mon Sep 17 00:00:00 2001 From: Maximilian Eibl Date: Fri, 4 Sep 2026 16:10:59 +0200 Subject: [PATCH] Update integration pipeline to test warning persistence and error immediate pass --- tests/test_pipeline.py | 55 +++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index 3f4d8f2..ed0f55a 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -80,20 +80,25 @@ def run_tests(): assert bad_resp.get("status") == "error", f"Expected error, got: {bad_resp}" print(f"[OK] Bad auth rejected correctly: {bad_resp['message']}") - test_signature = "TestServiceCrash" + test_signature = "TestServiceDegraded" candidate_log = [{ "server": "test-edge-node", "os_type": "linux", "signature": test_signature, - "severity": "ERROR", - "message": "Out of memory killer triggered" + "severity": "WARNING", + "message": "Resource usage high warning" }] - print("\n=== [3] Testing Temporal Persistence & 4-Run Rule ===") + print("\n=== [3] Testing Temporal Persistence & 4-Run Rule for Warnings ===") for run_num in range(1, 5): resp = send_socket_batch(candidate_log) assert resp.get("status") == "success", f"Run {run_num} failed: {resp}" - print(f"[Run {run_num}/4] Ingested successfully. Promoted to verified: {resp.get('promoted_verified')}") + promoted = resp.get("promoted_verified", 0) + print(f"[Run {run_num}/4] Ingested successfully. Promoted to verified: {promoted}") + if run_num < 4: + assert promoted == 0, f"Expected 0 promoted on run {run_num} for warning, got {promoted}" + else: + assert promoted == 1, f"Expected 1 promoted on run 4 for warning, got {promoted}" # Inspect SQLite database directly conn = sqlite3.connect(server_conf.get("db_path", "logar_state.db")) @@ -107,7 +112,33 @@ def run_tests(): print(f"[DB Verification] Issue '{test_signature}' -> run_count: {run_count}, status: {status}") assert run_count >= 4, f"Expected run_count >= 4, got {run_count}" assert status == "VERIFIED", f"Expected status 'VERIFIED', got {status}" - print("[OK] 4-Run Rule verified: Transient issue promoted to VERIFIED anomaly!") + print("[OK] 4-Run Rule verified: Warning promoted to VERIFIED anomaly on 4th run!") + + print("\n=== [3b] Testing Immediate Pass for Errors ===") + error_signature = "TestServiceCrashImmediate" + error_log = [{ + "server": "test-edge-node", + "os_type": "linux", + "signature": error_signature, + "severity": "ERROR", + "message": "Fatal process crash occurred" + }] + err_resp = send_socket_batch(error_log) + assert err_resp.get("status") == "success", f"Error run failed: {err_resp}" + print(f"[Run 1/1] Error ingested successfully. Promoted to verified: {err_resp.get('promoted_verified')}") + assert err_resp.get("promoted_verified") == 1, f"Expected error to be promoted to verified immediately on run 1, got {err_resp.get('promoted_verified')}" + + conn = sqlite3.connect(server_conf.get("db_path", "logar_state.db")) + cursor = conn.cursor() + cursor.execute("SELECT run_count, status FROM active_issues WHERE signature = ?", (error_signature,)) + err_row = cursor.fetchone() + conn.close() + assert err_row is not None, "Error issue not found in SQLite" + err_run_count, err_status = err_row + print(f"[DB Verification] Issue '{error_signature}' -> run_count: {err_run_count}, status: {err_status}") + assert err_run_count == 1, f"Expected run_count == 1, got {err_run_count}" + assert err_status == "VERIFIED", f"Expected status 'VERIFIED', got {err_status}" + print("[OK] Immediate pass verified: Error promoted to VERIFIED anomaly immediately!") print("\n=== [4] Testing Hermes Reporting Endpoint (/api/hermes/report) ===") req = urllib.request.Request(f"http://{HERMES_HOST}:{HERMES_PORT}/api/hermes/report") @@ -116,15 +147,21 @@ def run_tests(): hermes_data = json.loads(response.read().decode("utf-8")) print(f"[Hermes API] Returned {len(hermes_data)} verified anomalies:") - found_issue = False + found_warning = False + found_error = False for issue in hermes_data: print(f" - Fingerprint: {issue['fingerprint']} | Consecutive Runs: {issue['consecutive_runs']} | Status: {issue['status']}") if issue["signature"] == test_signature: - found_issue = True + found_warning = True assert issue["verified"] is True assert issue["consecutive_runs"] >= 4 + if issue["signature"] == error_signature: + found_error = True + assert issue["verified"] is True + assert issue["consecutive_runs"] == 1 - assert found_issue, f"Test issue {test_signature} should be in Hermes report" + assert found_warning, f"Warning issue {test_signature} should be in Hermes report" + assert found_error, f"Error issue {error_signature} should be in Hermes report" print("[OK] Hermes reporting validated!") print("\n=== [5] Testing Windows Client Script Integration ===")