"""Shared fixtures for node-agent tests."""
from __future__ import annotations

import os
import sys
import tempfile
from pathlib import Path

import pytest

_SRC = Path(__file__).resolve().parents[1] / "src"
sys.path.insert(0, str(_SRC))

# node_agent.py reads RUNTIME_PATH/NODE_NAME as module-level constants at
# import time, so these must be set before the first `import node_agent`.
_RUNTIME = Path(tempfile.mkdtemp(prefix="node-agent-test-"))
os.environ.setdefault("RUNTIME_PATH", str(_RUNTIME))
os.environ.setdefault("NODE_NAME", "test-node")

import node_agent  # noqa: E402


@pytest.fixture
def agent(monkeypatch):
    monkeypatch.setattr(node_agent, "VPS_EVENTS_HOST", "vps.example.com")
    monkeypatch.setattr(node_agent, "VPS_EVENTS_USER", "oskar")
    monkeypatch.setattr(node_agent, "VPS_EVENTS_PATH", "/opt/homelab/events")
    return node_agent.NodeAgent()
