58 lines
3.1 KiB
Python
58 lines
3.1 KiB
Python
"""Extended safe diagnostics plus metadata-bound deployment preparation, no credentials."""
|
|
from pathlib import Path
|
|
import importlib.util
|
|
import json
|
|
import shlex
|
|
|
|
|
|
def _base(root):
|
|
spec = importlib.util.spec_from_file_location('private_dify_ops_fixed_base', root / 'artifacts/private_dify_ops_actions_20261027.py')
|
|
module = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(module)
|
|
return module
|
|
|
|
|
|
def run_action(client, action, repo_root):
|
|
root = Path(repo_root).resolve(strict=True)
|
|
base = _base(root)
|
|
if action in base.ACTIONS:
|
|
return base.run_action(client, action, root)
|
|
if action != 'diagnose-imports':
|
|
return {'ok': False, 'action': 'invalid', 'error_code': 'ACTION_NOT_ALLOWED'}
|
|
try:
|
|
transport = client.get_transport()
|
|
base._require(transport is not None and transport.is_active() and transport.is_authenticated(), 'AUTHENTICATED_SSH_REQUIRED')
|
|
base._require(transport.sock.getpeername()[0] == base.HOST, 'SSH_DESTINATION_MISMATCH')
|
|
state = base._load_state(root)
|
|
base._require(state.get('staged') is True, 'STAGE_REQUIRED')
|
|
base._package(root)
|
|
base._bound_metadata(client, state)
|
|
program = (root / 'artifacts/ai_full_verification_20261027/dify_import_diagnostic.py').read_text(encoding='utf-8')
|
|
compile(program, '<safe-import-diagnostic>', 'exec')
|
|
results = []
|
|
for mode in ['baseline', 'candidate']:
|
|
command = 'docker exec ' + base.CONTAINER + ' python -B -c ' + shlex.quote(program)
|
|
command += ' --mode ' + mode + ' --package ' + shlex.quote(state['container_stage'] + '/package')
|
|
command += '; code=$?; test "$code" -le 1'
|
|
result, metadata = base._json_command(client, command, timeout=60, cap=65536)
|
|
base._require(isinstance(result, dict) and result.get('mode') == mode, 'IMPORT_DIAGNOSTIC_RESULT_INVALID')
|
|
results.append(result)
|
|
history = state.setdefault('import_diagnostic_history', [])
|
|
if not history and 'import_diagnostic' in state:
|
|
history.append(state['import_diagnostic'])
|
|
history.append(results)
|
|
state['import_diagnostic'] = results
|
|
# Never promote an import blocked by real side effects into a successful gate.
|
|
state['imports_passed'] = all(r.get('ok') is True and r.get('native_lookup_policy') == 'ctypes-ldconfig-cache-v2'
|
|
and not r.get('blocked_operations') for r in results)
|
|
base._save_state(root, state)
|
|
return {'ok': True, 'action': action, 'results': results,
|
|
'both_imports_clean': state['imports_passed'], 'live_source_changed': False,
|
|
'network_or_worker_start_permitted': False,
|
|
'native_lookup_policy': 'ctypes-ldconfig-cache-v2'}
|
|
except base.OpsError as error:
|
|
return {'ok': False, 'action': action, 'error_code': error.code, 'raw_remote_output_suppressed': True}
|
|
except Exception as error:
|
|
return {'ok': False, 'action': action, 'error_code': 'IMPORT_DIAGNOSTIC_FAILED',
|
|
'error_type': type(error).__name__, 'raw_remote_output_suppressed': True}
|