feat: add guarded generic startup apply

Co-authored-by: GPT-6 <gpt-6@openai.com>
This commit is contained in:
ZeusinaandGPT-6 Bot committed 2026-10-14 22:02:00 +03:00
1 parent 3743cdbd3e
commit de453ed2c8
11 files changed
+1255 -49

No files matched your search

+35
View File
@@ -27,7 +27,15 @@ with tempfile.TemporaryDirectory(prefix='target-config-') as tmp:
ZAPRET_AUTOTUNE_YOUTUBE_SERVICE='0', ZAPRET_AUTOTUNE_GOOGLEVIDEO_MODE='cold',
ZAPRET_AUTOTUNE_VIDEO_ID='dQw4w9WgXcQ',
ZAPRET_AUTOTUNE_GOOGLEVIDEO_VIDEO_IDS='["dQw4w9WgXcQ"]',
ZAPRET_AUTOTUNE_TARGET_ROLE='managed-test',
ZAPRET_AUTOTUNE_TARGET_ID='zapret-autotune-managed-v1',
ZAPRET_AUTOTUNE_TARGET_DIR='/var/lib/zapret-autotune/target',
ZAPRET_CONFIG='/var/lib/zapret-autotune/target/config',
SOCKS_PORT='1080',
ZAPRET_AUTOTUNE_SOCKS_PROXY='socks5h://127.0.0.1:1080')
for name in ('ZAPRET_AUTOTUNE_RESOURCE_APPLY', 'ZAPRET_AUTOTUNE_RESOURCE_CONFIG',
'ZAPRET_AUTOTUNE_QUALIFY_CONFIG', 'ZAPRET_AUTOTUNE_STRATEGY_CONFIG'):
base.pop(name, None)
for dns, valid in (('', True), ('8.8.8.8', True), ('2001:4860:4860::8888', True),
('example.org', False), ('8.8.8.8\n', False), ('-d 8.8.8.8', False)):
for path in private.iterdir():
@@ -61,6 +69,23 @@ with tempfile.TemporaryDirectory(prefix='target-config-') as tmp:
assert base['SS_PASSWORD'].encode() not in result.stdout + result.stderr
if not valid:
assert not list(private.iterdir())
for overrides, valid in (
({'ZAPRET_AUTOTUNE_RESOURCE_APPLY': '1'}, False),
({'ZAPRET_AUTOTUNE_RESOURCE_APPLY': 'yes'}, False),
({'ZAPRET_AUTOTUNE_RESOURCE_APPLY': '1', 'ZAPRET_AUTOTUNE_RESOURCE_CONFIG': '/private/resources.json'}, True),
({'ZAPRET_AUTOTUNE_RESOURCE_APPLY': '1', 'ZAPRET_AUTOTUNE_RESOURCE_CONFIG': '/private/resources.json',
'ZAPRET_AUTOTUNE_TARGET_ROLE': ''}, False),
({'ZAPRET_AUTOTUNE_RESOURCE_APPLY': '1', 'ZAPRET_AUTOTUNE_RESOURCE_CONFIG': '/private/resources.json',
'SOCKS_PORT': '1081'}, False),
({'ZAPRET_AUTOTUNE_RESOURCE_APPLY': '1', 'ZAPRET_AUTOTUNE_RESOURCE_CONFIG': '/private/resources.json',
'ZAPRET_AUTOTUNE_QUALIFY_CONFIG': '/private/resources.json', 'ZAPRET_AUTOTUNE_STRATEGY_CONFIG': '/private/strategies.json'}, False),
):
for path in private.iterdir():
path.unlink()
result = subprocess.run(['sh', str(entry)], env=dict(base, **overrides), capture_output=True, timeout=5)
assert result.returncode == (0 if valid else 64), result.stderr
if not valid:
assert not list(private.iterdir()), 'Invalid apply mode created service configs'
# Render privately, never print the config/password; config does not deploy.
compose_env = {k: v for k, v in base.items() if not k.startswith('ZAPRET_AUTOTUNE_')}
factory_cases = []
@@ -100,6 +125,16 @@ with tempfile.TemporaryDirectory(prefix='target-config-') as tmp:
factory_cases.append({'environment': {k: v for k, v in settings.items()
if k.startswith('ZAPRET_AUTOTUNE_')}, 'ids': ids})
# Validate the actual rendered DNS environment, not an invented equivalent.
result = subprocess.run(['docker', 'compose', '--env-file', '/dev/null', '-f',
str(ROOT / 'deploy/managed-target/compose.yaml'), 'config', '--format', 'json'],
env=dict(compose_env, ZAPRET_AUTOTUNE_RESOURCE_APPLY='1',
ZAPRET_AUTOTUNE_RESOURCE_CONFIG='/private/resources.json',
ZAPRET_AUTOTUNE_STOP_GRACE_PERIOD='90s'), capture_output=True, timeout=10)
assert result.returncode == 0, 'Generic Compose config failed (output suppressed)'
target = json.loads(result.stdout)['services']['target']
assert target['environment']['ZAPRET_AUTOTUNE_RESOURCE_APPLY'] == '1'
assert target['environment']['ZAPRET_AUTOTUNE_RESOURCE_CONFIG'] == '/private/resources.json'
assert target['stop_grace_period'] == '1m30s'
# Compose must not inject Google bootstrap into a custom-provider request.
for service in ('0', '1'):
for provider in ({}, {'ZAPRET_AUTOTUNE_DOH_URL': 'https://secret.invalid/token'}):