diff --git a/src/dx_productivity/trial_task_center/discovery_cache.py b/src/dx_productivity/trial_task_center/discovery_cache.py index 1a77c39..a91ab6a 100644 --- a/src/dx_productivity/trial_task_center/discovery_cache.py +++ b/src/dx_productivity/trial_task_center/discovery_cache.py @@ -109,6 +109,10 @@ class DiscoveryCache: and (not collect_components or has_components)): self._entries[key] = entry return deepcopy(discovery) + # Fingerprinting is an optimization: an initially unverifiable + # project still gets fresh native discovery, with no cache reuse. + if before is None: + return loader() # Native first-open may normalize an old database. Discard that # discovery and reopen once; only a verified stable pass is usable. for attempt in range(2): diff --git a/tests/v1_1/test_discovery_cache.py b/tests/v1_1/test_discovery_cache.py index acfe1d6..7e4c2a4 100644 --- a/tests/v1_1/test_discovery_cache.py +++ b/tests/v1_1/test_discovery_cache.py @@ -307,3 +307,24 @@ def test_unstable_rediscovery_never_falls_back_to_cached_negative_matches(tmp_pa preparer._discover_project_sheets = stable assert preparer.discover_project(project, ('old',)).matched_old_parts[('MAIN', '1')] == frozenset({'old'}) assert len(calls) == 4 + + +def test_initially_unverifiable_project_uses_fresh_discovery_without_cache(tmp_path): + project, preparer, calls = prepared(tmp_path) + # A project within the explicit evidence root has no reusable fingerprint. + clone = preparer.for_data_root(project.parent) + clone._discover_project_sheets = preparer._discover_project_sheets + assert clone.discover_project(project, ('old',)).sheets == (('MAIN', '1'),) + assert len(calls) == 1 + assert clone.discover_project(project, ('old',)).sheets == (('MAIN', '1'),) + assert len(calls) == 2 + + +def test_unverifiable_retry_after_known_churn_still_fails_closed(tmp_path, monkeypatch): + from dx_productivity.trial_task_center import discovery_cache as module + project, preparer, calls = prepared(tmp_path) + fingerprints = iter([('before',), ('changed',), None, None]) + monkeypatch.setattr(module, 'project_fingerprint', lambda *args: next(fingerprints)) + with pytest.raises(TaskCenterError, match='changed'): + preparer.discover_project(project, ('old',)) + assert len(calls) == 2