Import DxPartReplace 1.2.0-beta.31 and Windows x64 dependencies

This commit is contained in:
Codex committed 2026-11-04 11:35:20 +08:00
1 parent 12895e9868
commit 427095212b
154 files changed
+8079 -267

No files matched your search

+147
View File
@@ -72,6 +72,55 @@ def test_changed_during_discovery_is_not_cached(tmp_path):
assert len(calls) == 4
def test_metadata_only_changes_during_cad_read_do_not_reject_inventory(tmp_path):
import os
project, preparer, calls = prepared(tmp_path)
original = preparer._discover_project_sheets
def touching(*args, **kwargs):
result = original(*args, **kwargs)
sheet = project.parent / 'sch/MAIN.1'
info = sheet.stat()
os.utime(sheet, ns=(info.st_atime_ns, info.st_mtime_ns + 1000000000))
return result
preparer._discover_project_sheets = touching
assert preparer.collect_inventory(project, ('old',))[0].refdes == 'R1'
assert len(calls) == 1
def test_session_address_churn_requires_two_identical_inventories(tmp_path):
project, preparer, calls = prepared(tmp_path)
address = project.parent / 'database/cdbsvr/sAddress.adr'
address.parent.mkdir(parents=True)
address.write_text('session-0')
original = preparer._discover_project_sheets
def changing(*args, **kwargs):
result = original(*args, **kwargs)
address.write_text('session-' + str(len(calls)))
return result
preparer._discover_project_sheets = changing
assert preparer.collect_inventory(project, ('old',))[0].refdes == 'R1'
assert len(calls) == 2
def test_reading_content_changes_reports_specific_filename(tmp_path):
import json
project, preparer, calls = prepared(tmp_path)
original = preparer._discover_project_sheets
def changing(*args, **kwargs):
kwargs.pop('runtime', None)
result = original(*args, **kwargs)
(project.parent / 'sch/MAIN.1').write_text('changed ' + str(len(calls)))
return result
class Runtime:
def release_idle_for_fingerprint(self, path):
return True
preparer._discover_project_sheets = changing
with pytest.raises(TaskCenterError, match='MAIN.1'):
preparer.collect_inventory(project, ('old',), runtime=Runtime())
evidence = next((preparer.data_root / 'discovery-checks').glob('*.json'))
assert any('MAIN.1' in name for name in json.loads(evidence.read_text())['content_changed'])
def test_clone_has_independent_cache_and_configuration(tmp_path):
project, preparer, calls = prepared(tmp_path)
preparer.discover_project(project, ('old',))
@@ -397,3 +446,101 @@ def test_unverifiable_retry_after_known_churn_still_fails_closed(tmp_path, monke
with pytest.raises(TaskCenterError, match='changed'):
preparer.discover_project(project, ('old',))
assert len(calls) == 2
def test_own_idle_cad_releases_database_before_rechecking_fingerprint(tmp_path, monkeypatch):
from dx_productivity.trial_task_center import discovery_cache as module
project, preparer, calls = prepared(tmp_path)
real_fingerprint = module.project_fingerprint
state = {'locked': False, 'released': 0}
def fingerprint(*args, **kwargs):
return None if state['locked'] else real_fingerprint(*args, **kwargs)
monkeypatch.setattr(module, 'project_fingerprint', fingerprint)
class Runtime:
def release_idle_for_fingerprint(self, path):
assert path == project
state['released'] += 1
state['locked'] = False
return True
def loader(path, parts, *, collect_components=False, runtime=None):
calls.append(parts)
state['locked'] = True
return _ProjectDiscovery((('MAIN', '1'),), {('MAIN', '1'): frozenset({'old'})},
(ComponentTarget(path, 'MAIN', '1', 'uid', 'R1', 'old', 'value'),))
preparer._discover_project_sheets = loader
assert preparer.collect_inventory(project, ('old',), runtime=Runtime())[0].refdes == 'R1'
assert state['released'] == 1 and len(calls) == 1
assert preparer.collect_inventory(project, ('old',), runtime=Runtime())[0].refdes == 'R1'
assert len(calls) == 1
def test_unlocking_own_cad_never_hides_actual_project_changes(tmp_path, monkeypatch):
from dx_productivity.trial_task_center import discovery_cache as module
project, preparer, calls = prepared(tmp_path)
real_fingerprint = module.project_fingerprint
state = {'locked': False, 'released': 0}
monkeypatch.setattr(module, 'project_fingerprint', lambda *a, **kw:
None if state['locked'] else real_fingerprint(*a, **kw))
class Runtime:
def release_idle_for_fingerprint(self, path):
state['locked'] = False
state['released'] += 1
return True
def changed(path, parts, *, collect_components=False, runtime=None):
calls.append(parts)
(path.parent / 'sch/MAIN.1').write_text('changed during pass ' + str(len(calls)))
state['locked'] = True
return _ProjectDiscovery((('MAIN', '1'),), {('MAIN', '1'): frozenset({'old'})})
preparer._discover_project_sheets = changed
with pytest.raises(TaskCenterError, match='已跳过'):
preparer.discover_project(project, ('old',), runtime=Runtime())
assert len(calls) == 2 and state['released'] == 2
assert not preparer._discovery_cache._entries
def test_database_session_churn_requires_two_equal_reads_after_each_release(tmp_path, monkeypatch):
from dx_productivity.trial_task_center import discovery_cache as module
project, preparer, calls = prepared(tmp_path)
database = project.parent / 'database/icdb.dat'
database.parent.mkdir()
database.write_text('initial')
real_fingerprint = module.project_fingerprint
state = {'locked': False, 'released': 0}
monkeypatch.setattr(module, 'project_fingerprint', lambda *a, **kw:
None if state['locked'] else real_fingerprint(*a, **kw))
class Runtime:
def release_idle_for_fingerprint(self, path):
state['locked'] = False
state['released'] += 1
return True
def load(path, parts, *, collect_components=False, runtime=None):
calls.append(parts)
database.write_text('CAD session ' + str(len(calls)))
state['locked'] = True
return _ProjectDiscovery((('MAIN', '1'),), {('MAIN', '1'): frozenset({'old'})},
(ComponentTarget(path, 'MAIN', '1', 'uid', 'R1', 'old', 'value'),))
preparer._discover_project_sheets = load
assert preparer.collect_inventory(project, ('old',), runtime=Runtime())[0].refdes == 'R1'
assert len(calls) == 2 and state['released'] == 2
preparer.collect_inventory(project, ('old',), runtime=Runtime())
assert len(calls) == 2
def test_release_failure_never_returns_or_caches_inventory(tmp_path, monkeypatch):
from dx_productivity.trial_task_center import discovery_cache as module
project, preparer, calls = prepared(tmp_path)
real_fingerprint = module.project_fingerprint
state = {'locked': False}
monkeypatch.setattr(module, 'project_fingerprint', lambda *a, **kw:
None if state['locked'] else real_fingerprint(*a, **kw))
class Runtime:
def release_idle_for_fingerprint(self, path):
raise TaskCenterError('batch_resources_pending', 'release failed')
def load(path, parts, *, runtime=None):
calls.append(parts)
state['locked'] = True
return _ProjectDiscovery((('MAIN', '1'),), {('MAIN', '1'): frozenset({'old'})})
preparer._discover_project_sheets = load
with pytest.raises(TaskCenterError, match='release failed'):
preparer.discover_project(project, ('old',), runtime=Runtime())
assert not preparer._discovery_cache._entries