fix(db): sort corp-HQ body iteration for determinism (#951)

Review (Tyre) caught a determinism hole: corp-HQ→city matching iterated a
Python set (sys_body_ids), so on a name collision across bodies in the same
system, which row received corp_id depended on set order — nondeterministic
output landing in the committed DB (violates D-010 #4). Iterate sorted().

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-23 08:09:14 +02:00
co-authored by Claude Opus 4.7
parent abcb41deaa
commit 6e70647e69
+3 -1
View File
@@ -1374,7 +1374,9 @@ def populate_atlas_city_names_corps(conn: sqlite3.Connection, dry_run: bool) ->
# Try to find a matching atlas_city_names row in the same system
body_ids_in_sys = sys_body_ids.get(headquarters_system, set())
match_id: int | None = None
for body_id in body_ids_in_sys:
# sorted() for determinism: on a name collision across bodies in the
# same system, set iteration order is not stable (D-010 #4).
for body_id in sorted(body_ids_in_sys):
key = (body_id, city_name.lower())
if key in existing:
match_id = existing[key]