Files
aetherbound-guild/runtime/tests/p10_1/content_registry_test.gd
T

112 lines
5.2 KiB
GDScript

extends SceneTree
const Content = preload("res://p10_1/content_registry.gd")
var failures: Array[String] = []
var rejected_cases := 0
func _initialize() -> void:
call_deferred("run_test")
func run_test() -> void:
var first := Content.snapshot()
var second := Content.snapshot()
var validation := Content.validate(first)
expect(validation.ok, "canonical Siltwake registry validates: %s" % str(validation.errors))
expect(first == second, "catalog loading and enrichment are byte-identical")
expect(String(first.catalog_hash).length() == 64, "catalog has a canonical SHA-256")
verify_counts_and_identity(first)
verify_runtime_authority(first)
verify_negative_boundaries(first)
if failures.is_empty():
print("ABG_P10_1_CONTENT_REGISTRY_OK region=1 contract=1 equipment=8 enemies=7 boss_metadata=1 routes=3 localized=21 source=exact negative_cases=%d" % rejected_cases)
quit(0)
else:
for failure in failures:
push_error(failure)
quit(1)
func verify_counts_and_identity(content: Dictionary) -> void:
expect(content.region.id == "RG-02", "Region identity is exact")
expect(content.contract.id == "CTR-R2-01" and content.contract.region_id == "RG-02", "first Contract identity and Region reference are exact")
expect(content.equipment.size() == 8, "EQ-041..EQ-048 are exposed")
expect(content.enemies.size() == 7, "EN-R2-01..EN-R2-07 are exposed")
expect(content.routes.size() == 3, "three first-Market routes are exposed")
expect(content.boss.id == "BO-R2-01" and not content.boss.executable and not content.contract.boss_executable, "Boss is reference-only")
expect(content.contract.market_count == 12 and content.contract.slice_end_market == 2, "full Contract and bounded slice end remain distinct")
expect(content.names_zh.size() == 21, "every bounded content identity has zh_CN authority")
expect(content.source == Content.SOURCE_AUTHORITY, "three source blobs are bound exactly")
func verify_runtime_authority(content: Dictionary) -> void:
var ids := {}
for singleton in [content.region, content.contract, content.boss]:
verify_row(singleton, ids)
for family in [content.equipment, content.enemies, content.routes]:
for row in family:
verify_row(row, ids)
expect(ids.size() == 21, "all runtime identities are unique")
expect(content.region.tide.position_count == 4 and content.region.tide.fixed_tick_ms == 100, "tide uses four positions and the fixed battle clock")
expect(content.region.tide.shift_tick == 50 and content.region.tide.warning_ticks == 20, "tide countdown is exact")
expect(content.routes.map(func(row): return int(row.risk)) == [0, 1, 2], "route risks are ordered 0/1/2")
expect(content.routes[0].enemy_ids == ["EN-R2-01", "EN-R2-07"], "safe route combines pull and side-step pressure")
expect(content.routes[1].enemy_ids == ["EN-R2-02", "EN-R2-06"], "middle route combines healing denial and timed hindrance")
expect(content.routes[2].enemy_ids == ["EN-R2-01", "EN-R2-02", "EN-R2-04"], "high route combines pull, healing denial and indexed mud")
func verify_row(row: Dictionary, ids: Dictionary) -> void:
expect(not ids.has(row.id), "%s is globally unique" % row.id)
ids[row.id] = true
expect(not String(row.name_en).is_empty() and not String(row.name_zh).is_empty(), "%s has both names" % row.id)
expect(not String(row.preview).is_empty() and row.response_tags.size() >= 3, "%s has preview and response tags" % row.id)
expect(String(row.execution_key).begins_with("execute.") and String(row.mechanic_signature).length() == 64, "%s has runtime dispatch and signature" % row.id)
func verify_negative_boundaries(canonical: Dictionary) -> void:
var source_drift := canonical.duplicate(true)
source_drift.source.enemy_catalog_blob = "0".repeat(40)
expect_rejected(source_drift, "source drift", "source:enemy_catalog_blob")
var locale_missing := canonical.duplicate(true)
locale_missing.names_zh.erase("EQ-048")
expect_rejected(locale_missing, "missing locale", "names_zh_ids")
var duplicate_item := canonical.duplicate(true)
duplicate_item.equipment[1].id = "EQ-041"
expect_rejected(duplicate_item, "duplicate item", "duplicate_global_id:EQ-041")
var unknown_enemy := canonical.duplicate(true)
unknown_enemy.routes[0].enemy_ids[0] = "EN-R2-99"
expect_rejected(unknown_enemy, "unknown route enemy", "route_composition:RO-R2-01")
var executable_boss := canonical.duplicate(true)
executable_boss.boss.executable = true
expect_rejected(executable_boss, "Boss execution leak", "boss_boundary")
var hidden_countdown := canonical.duplicate(true)
hidden_countdown.region.tide.warning_ticks = 0
expect_rejected(hidden_countdown, "hidden tide countdown", "tide_countdown")
var filler := canonical.duplicate(true)
filler.enemies[0].rule = "TODO placeholder"
expect_rejected(filler, "filler mechanic", "filler:EN-R2-01:todo")
func expect_rejected(content: Dictionary, label: String, expected_error: String) -> void:
var result := Content.validate(content)
var found := false
for error in result.errors:
if String(error).begins_with(expected_error):
found = true
expect(not result.ok and found, "%s rejects with %s; got %s" % [label, expected_error, str(result.errors)])
if not result.ok and found:
rejected_cases += 1
func expect(condition: bool, message: String) -> void:
if not condition:
failures.append("P10.1 content registry: %s" % message)