#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""部署前侦察：tcb 可用性 + iframe 子页在 CDN 上的真实路径。"""
import os
import shutil
import ssl
import subprocess
import urllib.parse
import urllib.request

CDN = 'https://bier-sales-d0gatbvlx288724e9-1458438710.tcloudbaseapp.com'
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE

print('=== tcb CLI 可用性 ===')
for p in ['/Users/liuxinyuan/.npm-global/bin/tcb',
          '/Users/liuxinyuan/.npm-global/lib/node_modules/@cloudbase/cli/bin/tcb',
          '/Users/liuxinyuan/.npm-global/lib/node_modules/@cloudbase/cli/dist/standalone/cli.js']:
    print('  %-72s %s' % (p, '存在' if os.path.exists(p) else '—'))
which = shutil.which('tcb')
print('  which tcb →', which)

print('\n=== 子页在 CDN 上的路径探测（路径也需编码）===')
cands = ['/工具/活动录入.html', '/workbench/工具/活动录入.html',
         '/工具/测试报告定向收集.html', '/workbench/活动录入.html']
for c in cands:
    enc = '/'.join(urllib.parse.quote(seg) if not seg.startswith('http') else seg for seg in c.split('/'))
    try:
        r = urllib.request.urlopen(urllib.request.Request(CDN + enc, headers={'User-Agent': 'probe'}),
                                   timeout=15, context=ctx)
        b = r.read()
        print('  HTTP %s %7d 字节  ← %s' % (r.status, len(b), enc))
    except Exception as e:
        print('  %-40s %s' % (enc, str(e)[:60]))
