Files
dxdesigner-part-replacement/docs/testing/evidence/2026-11-13-pr27/compare-empty-cad-helpers.py
阿白叔 a0f0a4b232
Core regression / Python core, intervention UI and release configuration (push) Successful in 3m52s
Core regression / JavaScript syntax (push) Successful in 5s
Core regression / Python core, intervention UI and release configuration (pull_request) Successful in 4m13s
Core regression / JavaScript syntax (pull_request) Successful in 9s
test: make Windows retry fixture portable and retain live diagnostics
2026-11-13 16:30:07 +08:00

60 lines
3.0 KiB
Python

"""Compare helper/Temp routing on one empty, identity-bound CAD instance."""
import json
import os
from pathlib import Path
import subprocess
import sys
import time
import traceback
out = Path(__file__).resolve().parent
repo = out.parents[1]
sys.path.insert(0, str(repo / 'src'))
from dx_productivity.trial_task_center import isolated_cad
build = json.loads((out / 'build-manifest.json').read_text(encoding='utf-8'))
root = out / 'empty-cad-comparison'
assert not root.exists()
diagnostic = out / 'diagnose_empty_cad.py'
isolated_cad._helper_command = lambda action, evidence, pid: (sys.executable, '-X', 'utf8', str(diagnostic), action, str(evidence), str(pid))
session = isolated_cad.IsolatedCadSession(root)
original_wait = session._wait_process
session._wait_process = lambda process, timeout, phase: original_wait(process, 120, phase)
record = dict(status='running', started_ns=time.time_ns(), project_opened=False,
diagnostic_wait_seconds=120, comparisons=[])
path = out / 'empty-cad-comparison.json'
def persist():
path.write_text(json.dumps(record, ensure_ascii=False, indent=2), encoding='utf-8')
try:
with session:
for mode, custom_temp in [('frozen-default-temp', None),
('frozen-acceptance-temp', repo / 'outputs/pr27-random-final-20261113/process-temp'),
('source-acceptance-temp', repo / 'outputs/pr27-random-final-20261113/process-temp')]:
evidence = root / (mode + '.json')
if mode.startswith('frozen'):
command = (build['exe'], '--private-cad-action', 'checkpoint', '--private-cad-evidence', str(evidence), '--private-cad-pid', str(session.cad.pid))
else:
command = isolated_cad._helper_command('checkpoint', evidence, session.cad.pid)
environment = session.binding.environment()
environment['PYTHONPATH'] = str(repo / 'src')
if custom_temp is not None:
environment.update(TEMP=str(custom_temp), TMP=str(custom_temp))
row = dict(mode=mode, started_ns=time.time_ns(), temp=environment.get('TEMP'))
record['comparisons'].append(row)
persist()
process = session.desktop.start_process(command, env=environment, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
try:
row['exit_code'] = original_wait(process, 120, 'checkpoint')
row['seconds'] = (time.time_ns() - row['started_ns']) / 1e9
row['stderr'] = process.stderr.read().decode('utf-8', errors='replace')
assert row['exit_code'] == 0 and json.loads(evidence.read_text(encoding='utf-8'))['project_closed']
print(json.dumps(row), flush=True)
persist()
finally:
process.close()
record.update(status='completed', cad_record=session.record, finished_ns=time.time_ns())
except BaseException:
record.update(status='failed_preserved', failure=traceback.format_exc(), cad_record=session.record, finished_ns=time.time_ns())
raise
finally:
persist()