import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'packages' / 'agromatrix-tools'))

from agromatrix_tools import tool_dictionary_review as review


def test_list_pending_open():
    items = review.list_pending(limit=5)
    assert isinstance(items, list)


def test_reject_pending(tmp_path, monkeypatch):
    # skip if no pending
    items = review.list_pending(limit=1)
    if not items:
        return
    ref = items[0]['pending_ref']
    res = review.reject_pending(ref, 'test')
    assert res['decision'] == 'rejected'


def test_apply_idempotent():
    try:
        review.apply_resolutions()
        review.apply_resolutions()
        assert True
    except Exception:
        assert False
