Skip to content

Commit d6df966

Browse files
Scottcjnclaude
andcommitted
fix(ci): unblock test_beacon_atlas_behavior.py + sqlite3.Row.get() bug
Two related fixes that together unblock Rustchain CI on main (red since 2026-05-04, blocking 7+ paid PRs across multiple authors). Test fix (tests/test_beacon_atlas_behavior.py): - Seed 4 test agents (bcn_alice_test, bcn_bob_test, bcn_test_from, bcn_test_to) into relay_agents in setUp so the create_contract route's existence check passes - Add X-Agent-Key headers to POST /api/contracts and PUT /api/contracts/<id> client calls - For PUT to 'active' (offered → active), authenticate as to_agent (bcn_bob_test) since recipient-only transition Production fix (node/beacon_api.py:539): - contract.get('to_agent', '') would AttributeError on sqlite3.Row (no .get() method) → 500 in update_contract - Replaced with bracket access using .keys() membership check Codex consensus reviewed the test patch and validated the diagnosis + safety. Production fix surfaced when applying the test fix locally — 401→201 worked but PUT then 500'd. Both fixes are required. Verification: - Full tests/test_beacon_atlas_behavior.py: 15/15 pass locally - No production behavior change beyond fixing the AttributeError path Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ab8a01f commit d6df966

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

node/beacon_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ def update_contract(contract_id):
536536
return jsonify({'error': 'Missing X-Agent-Key header — authentication required'}), 401
537537

538538
from_agent = contract['from_agent']
539-
to_agent = contract.get('to_agent', '')
539+
to_agent = contract['to_agent'] if 'to_agent' in contract.keys() else ''
540540

541541
# Caller must be either the from_agent or to_agent
542542
if agent_key != from_agent and agent_key != to_agent:

tests/test_beacon_atlas_behavior.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,21 @@ def setUp(self):
6969
conn.execute("DELETE FROM beacon_bounties")
7070
conn.execute("DELETE FROM beacon_reputation")
7171
conn.execute("DELETE FROM beacon_chat")
72+
conn.execute("DELETE FROM relay_agents")
73+
now = int(time.time())
74+
conn.executemany(
75+
"""
76+
INSERT INTO relay_agents
77+
(agent_id, pubkey_hex, name, status, created_at, updated_at)
78+
VALUES (?, ?, ?, ?, ?, ?)
79+
""",
80+
[
81+
('bcn_alice_test', '0x' + '11' * 32, 'Alice Test', 'active', now, now),
82+
('bcn_bob_test', '0x' + '22' * 32, 'Bob Test', 'active', now, now),
83+
('bcn_test_from', '0x' + '33' * 32, 'From Test', 'active', now, now),
84+
('bcn_test_to', '0x' + '44' * 32, 'To Test', 'active', now, now),
85+
],
86+
)
7287
conn.commit()
7388

7489
def test_health_endpoint_returns_ok(self):
@@ -95,7 +110,8 @@ def test_create_contract_workflow(self):
95110
create_response = self.client.post(
96111
'/api/contracts',
97112
data=json.dumps(contract_data),
98-
content_type='application/json'
113+
content_type='application/json',
114+
headers={'X-Agent-Key': 'bcn_alice_test'},
99115
)
100116
self.assertEqual(create_response.status_code, 201)
101117

@@ -118,7 +134,8 @@ def test_create_contract_workflow(self):
118134
update_response = self.client.put(
119135
f'/api/contracts/{contract_id}',
120136
data=json.dumps({'state': 'active'}),
121-
content_type='application/json'
137+
content_type='application/json',
138+
headers={'X-Agent-Key': 'bcn_bob_test'},
122139
)
123140
self.assertEqual(update_response.status_code, 200)
124141

@@ -249,15 +266,17 @@ def test_invalid_state_update_rejected(self):
249266
create_response = self.client.post(
250267
'/api/contracts',
251268
data=json.dumps(contract_data),
252-
content_type='application/json'
269+
content_type='application/json',
270+
headers={'X-Agent-Key': 'bcn_test_from'},
253271
)
254272
contract_id = json.loads(create_response.data)['id']
255273

256274
# Try invalid state
257275
update_response = self.client.put(
258276
f'/api/contracts/{contract_id}',
259277
data=json.dumps({'state': 'invalid_state'}),
260-
content_type='application/json'
278+
content_type='application/json',
279+
headers={'X-Agent-Key': 'bcn_test_from'},
261280
)
262281
self.assertEqual(update_response.status_code, 400)
263282

0 commit comments

Comments
 (0)