fix(client): bake the version into the build, so an export can invalidate its cache (T-1241)
current_schema_version() line-scanned res://../project.yaml at runtime. That resolves to the repo root in a dev run and to nothing in an exported build, so a shipped game got the "?.?.?" fallback every time. Since that tag is the Atlas disk cache's ONLY invalidation signal, every exported build stamped and compared the same sentinel: a canvas cached by one build would be served by every later build, forever. T-1239 is what that failure looks like once it happens. loading_screen.gd carried a byte-for-byte copy of the same function, so the version shown to the player was "?.?.?" in exactly the builds where a version string is worth showing. Both call sites now share client/scripts/build_version.gd, which reads application/config/version out of ProjectSettings — a value Godot bakes into the PCK, identical in the editor and in an export by construction rather than by luck. No file IO, no fallback branch. project.yaml stays the source of truth (CLAUDE.md); client/project.godot mirrors it. A mirror nobody checks would be worse than the bug it replaces -- the old code failed loudly everywhere, a stale mirror fails silently -- so tooling/check-client-version compares the two and the pre-push hook runs it unconditionally. Not gated on "were those files in this push": drift persists on main once introduced, and gating would let an existing drift ride along. The test this replaces asserted that current_schema_version() did not return its fallback, and passed -- in the one environment where the code under test worked. Three tests now pin the property that actually matters: a real version, sourced from the baked setting, matching project.yaml. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -370,14 +370,65 @@ func test_mismatched_schema_version_has_reports_false() -> void:
|
||||
assert_bool(cache.has("GJ1c", "District", Vector2i.ZERO, Vector2i(64, 64))).is_false()
|
||||
|
||||
|
||||
func test_current_schema_version_reads_project_yaml() -> void:
|
||||
# project.yaml's version field is "0.4.0" per CLAUDE.md at time of
|
||||
# writing — assert only that a non-placeholder value comes back (not the
|
||||
# exact string, so this test doesn't need updating every version bump).
|
||||
## T-1241. The predecessor of this test asserted that current_schema_version()
|
||||
## did not return its "?.?.?" fallback — and passed, in the ONE environment
|
||||
## where the code under test worked. It read res://../project.yaml, which exists
|
||||
## in a dev run and never in an exported build, so the shipped game got the
|
||||
## fallback for every build, the cache compared a constant sentinel against
|
||||
## itself, and nothing was ever invalidated. A green test said otherwise.
|
||||
##
|
||||
## The version now comes from ProjectSettings, which Godot bakes into the PCK, so
|
||||
## the dev and exported answers are the same value by construction rather than by
|
||||
## luck. These tests assert that construction: a real version, sourced from the
|
||||
## setting, with no file lookup left to differ between environments.
|
||||
func test_current_schema_version_is_a_real_version_not_the_fallback() -> void:
|
||||
var v: String = StepCanvasDiskCache.current_schema_version()
|
||||
assert_str(v).override_failure_message(
|
||||
"current_schema_version() must read a real value from project.yaml, not the '?' fallback"
|
||||
"current_schema_version() must return a real version, never the '?.?.?' fallback"
|
||||
).is_not_equal("?.?.?")
|
||||
assert_str(v).override_failure_message(
|
||||
"current_schema_version() must not be empty — the ProjectSettings key is missing"
|
||||
).is_not_empty()
|
||||
|
||||
|
||||
func test_current_schema_version_comes_from_project_settings() -> void:
|
||||
# The property that makes this export-safe: the value IS the baked setting,
|
||||
# not something re-derived from a file that an export would not contain.
|
||||
var setting: String = str(ProjectSettings.get_setting("application/config/version", ""))
|
||||
assert_str(setting).override_failure_message(
|
||||
"application/config/version must be set in client/project.godot — it is what "
|
||||
+ "survives an export, and the Atlas disk cache's only invalidation signal"
|
||||
).is_not_empty()
|
||||
assert_str(StepCanvasDiskCache.current_schema_version()).is_equal(setting)
|
||||
|
||||
|
||||
func test_baked_version_mirrors_project_yaml() -> void:
|
||||
# Drift guard, dev-only by nature (an export has no project.yaml to compare
|
||||
# against — which is the whole reason the value is baked). project.yaml stays
|
||||
# the source of truth; this catches the bump-one-forget-the-other case from
|
||||
# inside the suite, as well as from tooling/check-client-version in the hook.
|
||||
var yaml_path := ProjectSettings.globalize_path("res://") + "/../project.yaml"
|
||||
if not FileAccess.file_exists(yaml_path):
|
||||
return # exported/packaged run — nothing to compare, and nothing to guard
|
||||
var file := FileAccess.open(yaml_path, FileAccess.READ)
|
||||
assert_object(file).is_not_null()
|
||||
var content := file.get_as_text()
|
||||
file.close()
|
||||
|
||||
var yaml_version := ""
|
||||
for line: String in content.split("\n"):
|
||||
if line.begins_with("version:"):
|
||||
var parts := line.split(":", false, 1)
|
||||
if parts.size() >= 2:
|
||||
yaml_version = parts[1].strip_edges()
|
||||
break
|
||||
assert_str(yaml_version).override_failure_message(
|
||||
"project.yaml must carry a `version:` line — it is the source of truth"
|
||||
).is_not_empty()
|
||||
assert_str(StepCanvasDiskCache.current_schema_version()).override_failure_message(
|
||||
"client/project.godot's config/version has drifted from project.yaml. "
|
||||
+ "Fix with the value in project.yaml; see `make check-client-version`."
|
||||
).is_equal(yaml_version)
|
||||
|
||||
|
||||
# =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user