Files
horizon-airdef/tools/test_remote_fireball_parity.py
T
Ludovic Marie 031f1e58a3 remote_fireball: a slow fireball, sampled from one ctl process
The harness sampled the fireball from a new horizon-ctl process each time,
10-16 ticks apart on a loaded runner: the fireball (~2 blocks a tick) left
the cleared corridor or the guest's tracking range before the sixth sample,
and the harness failed. It now flies slowly (acceleration_power 0.02, under
0.4 blocks a tick) down a longer corridor, and the guest takes 16 samples
in one ctl script (lan_e2e's Game.script returns every reply with every=True).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 22:07:12 +01:00

67 lines
3.3 KiB
Python

#!/usr/bin/env python3
"""A connected client advances ghast fireballs between tracker packets.
AbstractHurtingProjectile.tick/applyInertia run on clients as well as servers.
Like lan_e2e's falling-entity check, sample motion more often than the tracker
interval; an interpolation-only client stalls for most of that interval.
"""
import json
import math
import subprocess
import lab
import lan_e2e as lan
def check_motion(host, guest, out):
x, y, z = (math.floor(v) for v in lan.pos_of(guest))
for game in (host, guest):
game('command', command='gamemode creative')
tag = 'remote_fireball_parity'
# A slow fireball (acceleration_power 0.02: under 0.4 blocks a tick, against ~2 by default) stays in the cleared
# corridor and in the guest's tracking range for every sample, however many ticks a loaded host takes to answer.
host('command', command=f'fill {x + 2} {y + 18} {z - 1} {x + 96} {y + 23} {z + 1} minecraft:air')
host('command', command=f'summon minecraft:fireball {x + 3.5} {y + 20} {z + 0.5} '
f'{{Tags:["{tag}"],Motion:[0.1d,0.0d,0.0d],acceleration_power:0.02d}}')
samples = []
try:
# One ctl process for all samples: a ctl process per sample took 10-16 ticks on a loaded runner, by
# which time the fireball had left the cleared corridor and exploded.
replies = guest.script(['status', 'wait 1'] * 16, every=True)
for status in (reply for reply in replies if 'projectiles' in reply):
balls = [p for p in status['projectiles'] if p['kind'] == 'LargeFireball']
samples.append(balls[0]['position'][0] if balls else None)
finally:
host('command', command=f'kill @e[tag={tag}]')
seen = [p for p in samples if p is not None]
assert len(seen) >= 6, f'fireball visible in only {len(seen)} samples: {samples}'
moves = sum(b != a for a, b in zip(seen, seen[1:]))
assert moves >= len(seen) - 2, f'fireball stalled between tracker updates: {samples}'
return {'positions': samples}
def main():
subprocess.run(['cargo', 'build', '--locked', '--profile', 'fast', '-p', 'horizon-client',
'--bin', 'horizon-client', '--bin', 'horizon-ctl'], cwd=lab.ROOT, check=True)
metadata = json.loads(subprocess.check_output(
['cargo', 'metadata', '--format-version', '1', '--no-deps'], cwd=lab.ROOT, text=True))
ctl = lab.ROOT / metadata['target_directory'] / 'fast' / 'horizon-ctl'
lan.CHECK_FNS['remote-fireball'] = check_motion
# Use the runner's current display (xvfb on Linux), with fresh isolated homes.
lan.game_env = lambda _screen, home: lab.game_env(
HORIZON_HOME=home, HORIZON_TELEMETRY_URL='off')
reports = {}
for threaded in (True, False):
lan.SERVER_THREAD = threaded
mode = 'server-thread' if threaded else 'in-frame'
out = lab.LOCAL / 'remote-fireball-parity' / mode
out.mkdir(parents=True, exist_ok=True)
# lan.Game launches each client with lab.game_env and private scratch homes.
reports[mode] = lan.run(ctl, out, lab.RESOURCES.resolve(), ['remote-fireball'])
lab.write_json(lab.LOCAL / 'remote-fireball-parity' / 'report.json', reports)
assert all(r['pass'] for mode in reports.values() for r in mode.values()), reports
if __name__ == '__main__':
main()