Skip to content

Commit 9eff925

Browse files
luisleo526claude
andauthored
test(live): serialize startup replay webhook deliveries (#463)
* test(live): serialize startup replay webhook deliveries * test(live): assert the delivery order of the startup replay webhooks Both reads of #463 found that nothing asserted the order the serialisation exists to preserve: receipts_by_sequence() returns a dict whose equality ignores order. Adds an ordered raw-byte comparison of the received payloads against the ledger ordinals for the initial delivery and the redelivery, with a reversal control that calls the same check, and a comment that --max-attempts is ignored on the routed path. Lane: ci-m463 fix (Codex gpt-6.1-sol). Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]>
1 parent 9c18d41 commit 9eff925

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

‎tests/native_live_startup_e2e.py‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ def base_cmd(strategy, warmup, ledger, config=None, extra=None):
9393
return cmd
9494

9595

96+
def receipts_match_ledger_order(received_bytes, event_rows):
97+
return list(received_bytes) == [row[4] for row in event_rows]
98+
99+
96100
with tempfile.TemporaryDirectory(prefix='pineforge-native-startup-') as raw:
97101
root = Path(raw)
98102
warmup1m = root / 'w1m.csv'
@@ -254,9 +258,23 @@ def log_message(self, *args):
254258
'ts_open': 600000 + i * 60000, 'o': 100, 'h': 102, 'l': 99, 'c': 101, 'v': 0.8,
255259
}} for i in range(40)]
256260
example_feed.write_text(''.join(json.dumps(row) + '\n' for row in feed_rows))
261+
# The byte checks below use receipt order. One in-flight request makes
262+
# both initial delivery and offline redelivery preserve ordinal order.
263+
example_url = f'http://127.0.0.1:{server.server_port}/webhook'
264+
example_routes = root / 'native-example-routes.json'
265+
os.environ['PINEFORGE_NATIVE_STARTUP_HMAC'] = 'native-startup-fixture'
266+
example_routes.write_text(json.dumps({
267+
'schema_version': 1, 'default_target': 'default',
268+
'targets': {'default': {'url': example_url,
269+
'secret_env': 'PINEFORGE_NATIVE_STARTUP_HMAC'}},
270+
'rules': [],
271+
'delivery': {'max_in_flight': 1, 'transport_retries': 0},
272+
}))
273+
# Routed delivery reads transport_retries from this document;
274+
# --max-attempts only configures the non-routed path.
257275
example_cmd = [runner, 'run', '--strategy', native_example, '--warmup', str(example_warmup),
258276
'--mode', 'bars', '--ledger', str(example_ledger),
259-
'--webhook-url', f'http://127.0.0.1:{server.server_port}/webhook',
277+
'--webhook-url', example_url, '--webhook-routes', str(example_routes),
260278
'--allow-insecure-http', '--feed', str(example_feed),
261279
'--native-config', str(cfg), '--name', 'native-example']
262280
failed_delivery = invoke(example_cmd + ['--max-attempts', '1'])
@@ -269,6 +287,9 @@ def log_message(self, *args):
269287
assert all(row[2].isdigit() and int(row[2]) != 0 for row in failed_rows['inputs'])
270288
receipt_sequence = lambda body: json.loads(body)['sequence']
271289
failed_payloads = receipts_by_sequence(received_bytes, receipt_sequence)
290+
assert receipts_match_ledger_order(received_bytes[:2], failed_rows['events'])
291+
assert not receipts_match_ledger_order(
292+
list(reversed(received_bytes[:2])), failed_rows['events'])
272293
assert failed_payloads == receipts_by_sequence(
273294
(row[4] for row in failed_rows['events']), receipt_sequence)
274295

@@ -285,6 +306,7 @@ def log_message(self, *args):
285306
assert len(committed_rows['events']) == 2, committed_rows
286307
assert len(received) == 4, received
287308
replayed_payloads = receipts_by_sequence(received_bytes[2:], receipt_sequence)
309+
assert receipts_match_ledger_order(received_bytes[2:], committed_rows['events'])
288310
assert replayed_payloads == failed_payloads
289311
assert committed_rows['inputs'][:len(failed_rows['inputs'])] == failed_rows['inputs']
290312
assert committed_rows['events'][0][:5] == failed_rows['events'][0][:5]

0 commit comments

Comments
 (0)