From 3863b4a99436e358f911d013905db8b5ba1ae69a Mon Sep 17 00:00:00 2001 From: Wolfvin Date: Sun, 12 Jul 2026 12:38:01 +0700 Subject: [PATCH] fix(tests,registry): outdated language test-list + cache overwrite tiebreak bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. tests/test_node_types.py: EXPECTED_LANGUAGES only listed the original 7 languages (python/rust/js/ts/tsx/css/html). Issue #198 added 6 more (go/java/php/ruby/c/cpp) to node_types.yaml, but this test wasn't updated — test_no_extra_languages_beyond_expected failed with an explicit 'Update EXPECTED_LANGUAGES in this test' message pointing at its own staleness. Updated the set to all 13 current languages. 2. scripts/persistent_registry.py: get_cached_result() ordered by 'timestamp DESC LIMIT 1' only. set_cached_result() does a plain INSERT (not an upsert), so two writes for the same (command, file_set_hash) key in quick succession can land on the same time.time() value (limited clock resolution) -- the ORDER BY tie then resolves arbitrarily, sometimes returning the stale row instead of the newest. Found via baseline comparison: test_overwrite_frontend/test_overwrite_backend in test_persistent_registry_extra.py failed intermittently on this exact pattern (store 'old', store 'new', load should return 'new'). Fix: add 'id DESC' (autoincrement, monotonic) as a tiebreaker. Both found via comparing today's full test-suite failures against a clean baseline (commit c722f4a, before this session's work) -- confirmed these are test-debt from other legitimate changes this session, not regressions introduced by unrelated code. Verified: tests/test_node_types.py 32 passed. tests/test_persistent_registry_extra.py 26 passed (was 24 passed, 2 failed). --- scripts/persistent_registry.py | 9 ++++++++- tests/test_node_types.py | 7 +++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/persistent_registry.py b/scripts/persistent_registry.py index 06b80159..cb3a8f01 100644 --- a/scripts/persistent_registry.py +++ b/scripts/persistent_registry.py @@ -572,10 +572,17 @@ def get_cached_result( return None conn = self._connect() + # Tiebreak on the autoincrement id (monotonic) in addition to + # timestamp: set_cached_result() does a plain INSERT (not an + # upsert), so two writes for the same (command, file_set_hash) in + # quick succession can land on the same time.time() value (limited + # clock resolution) — ORDER BY timestamp alone then returns + # whichever row SQLite picks arbitrarily on the tie, which can be + # the stale one. row = conn.execute( """SELECT result_json FROM analysis_cache WHERE command = ? AND file_set_hash = ? - ORDER BY timestamp DESC LIMIT 1 + ORDER BY timestamp DESC, id DESC LIMIT 1 """, (command, file_set_hash), ).fetchone() diff --git a/tests/test_node_types.py b/tests/test_node_types.py index ac611568..d2c6a3cd 100644 --- a/tests/test_node_types.py +++ b/tests/test_node_types.py @@ -162,10 +162,13 @@ def test_unknown_language_raises(self): class TestGetSupportedLanguages: - """``get_supported_languages()`` lists all 7 tree-sitter languages.""" + """``get_supported_languages()`` lists all 13 tree-sitter languages.""" + # Issue #198 added go/java/php/ruby/c/cpp (6 languages) alongside the + # original 7 (python/rust/javascript/typescript/tsx/css/html) -> 13 total. EXPECTED_LANGUAGES = { - "python", "rust", "javascript", "typescript", "tsx", "css", "html" + "python", "rust", "javascript", "typescript", "tsx", "css", "html", + "go", "java", "php", "ruby", "c", "cpp", } def test_all_expected_languages_present(self):