fix(operator-gate): repair test ledger mock and newline parsing in nostur adapter
This commit is contained in:
@@ -30,30 +30,39 @@ class TestIdempotency(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
self.tmpdir.cleanup()
|
||||
|
||||
@patch("gitea_gate._LEDGER_PATH")
|
||||
def test_replay_returns_prior_ack(self, mock_path):
|
||||
@patch("gitea_gate._ledger_load")
|
||||
@patch("gitea_gate._ledger_append")
|
||||
@patch("gitea_gate._api_request")
|
||||
def test_replay_returns_prior_ack(self, mock_api, mock_append, mock_load):
|
||||
"""Same command executed twice must return prior_execution=True on second call."""
|
||||
mock_path.__str__ = lambda self: self.ledger_override
|
||||
# We mock the API call to avoid network
|
||||
with patch("gitea_gate._api_request") as mock_api:
|
||||
mock_api.return_value = {"number": 999, "title": "Test Issue", "html_url": "http://test/999"}
|
||||
mock_api.return_value = {"number": 999, "title": "Test Issue", "html_url": "http://test/999"}
|
||||
ledger = {}
|
||||
|
||||
cmd = Command(
|
||||
source="nostr:test",
|
||||
action="create_issue",
|
||||
repo="Timmy_Foundation/test",
|
||||
payload={"title": "Test Issue", "body": "body"},
|
||||
timestamp_utc="2026-04-06T14:00:00Z",
|
||||
)
|
||||
def load():
|
||||
return ledger.copy()
|
||||
|
||||
ack1 = self.gate.execute(cmd)
|
||||
self.assertTrue(ack1.success)
|
||||
self.assertFalse(ack1.prior_execution)
|
||||
def append(entry):
|
||||
ledger[entry["idempotency_key"]] = entry
|
||||
|
||||
ack2 = self.gate.execute(cmd)
|
||||
self.assertTrue(ack2.success)
|
||||
self.assertTrue(ack2.prior_execution)
|
||||
self.assertEqual(ack2.gitea_number, 999)
|
||||
mock_load.side_effect = load
|
||||
mock_append.side_effect = append
|
||||
|
||||
cmd = Command(
|
||||
source="nostr:test",
|
||||
action="create_issue",
|
||||
repo="Timmy_Foundation/test",
|
||||
payload={"title": "Test Issue", "body": "body"},
|
||||
timestamp_utc="2026-04-06T14:00:00Z",
|
||||
)
|
||||
|
||||
ack1 = self.gate.execute(cmd)
|
||||
self.assertTrue(ack1.success)
|
||||
self.assertFalse(ack1.prior_execution)
|
||||
|
||||
ack2 = self.gate.execute(cmd)
|
||||
self.assertTrue(ack2.success)
|
||||
self.assertTrue(ack2.prior_execution)
|
||||
self.assertEqual(ack2.gitea_number, 999)
|
||||
|
||||
def test_idempotency_key_determinism(self):
|
||||
"""Identical commands must produce identical keys."""
|
||||
|
||||
Reference in New Issue
Block a user