Skip to content

Commit 898f453

Browse files
committed
fix: bench-pipeline.sh temp config and Python mutator TOML support
Temp file renamed from config.toml to bench.json so Config::load dispatches to the JSON path — no TOML parse attempt, no migration noise during benchmarking. Python mutator now handles both .toml and .json input: reads TOML via tomllib (Python 3.11+) or tomli fallback, flattens grouped sections to a flat dict, writes JSON to the temp file.
1 parent da691a7 commit 898f453

1 file changed

Lines changed: 32 additions & 8 deletions

File tree

scripts/bench-pipeline.sh

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,40 @@ echo "╚═══════════════════════
4343
echo ""
4444

4545
# Write a temp config with our ports
46-
TEMP_CONFIG="$TMPDIR_BENCH/config.toml"
46+
TEMP_CONFIG="$TMPDIR_BENCH/bench.json"
4747
python3 -c "
48-
import json
49-
with open('$CONFIG') as f:
50-
c = json.load(f)
51-
c['listen_port'] = $HTTP_PORT
52-
c['socks5_port'] = $SOCKS_PORT
48+
import sys, os, json
49+
50+
config_path = '${CONFIG}'
51+
ext = os.path.splitext(config_path)[1].lower()
52+
53+
if ext == '.toml':
54+
if sys.version_info >= (3, 11):
55+
import tomllib
56+
else:
57+
try:
58+
import tomli as tomllib
59+
except ImportError:
60+
sys.exit('ERROR: Python 3.11+ or pip install tomli required to read TOML config')
61+
with open(config_path, 'rb') as f:
62+
t = tomllib.load(f)
63+
c = {}
64+
for section in ('relay', 'network', 'scan', 'logging'):
65+
c.update(t.get(section, {}))
66+
if 'exit_node' in t:
67+
c['exit_node'] = t['exit_node']
68+
if 'fronting_groups' in t:
69+
c['fronting_groups'] = t['fronting_groups']
70+
else:
71+
with open(config_path) as f:
72+
c = json.load(f)
73+
74+
c['listen_port'] = ${HTTP_PORT}
75+
c['socks5_port'] = ${SOCKS_PORT}
5376
c['log_level'] = 'warn'
54-
with open('$TEMP_CONFIG', 'w') as f:
55-
json.dump(c, f)
77+
78+
with open('${TEMP_CONFIG}', 'w') as f:
79+
json.dump(c, f, indent=2)
5680
"
5781

5882
run_test() {

0 commit comments

Comments
 (0)