fr54-candidate-verify.py
"""Local proposal only: no API calls or configuration writes outside output files."""
import copy,json,argparse
from pathlib import Path
parser=argparse.ArgumentParser()
parser.add_argument('--input',type=Path,default=Path(__file__).with_name('fr54-url-map-fingerprint.json'))
parser.add_argument('--out',type=Path,required=True)
args=parser.parse_args()
args.out.mkdir(parents=True,exist_ok=True)
old=json.loads(args.input.read_text())
new=copy.deepcopy(old)
matcher=next(m for m in new['pathMatchers'] if m['name']=='main-site-matcher')
rule=next(r for r in matcher['pathRules'] if r['paths']==['/blogs','/blogs/*'])
assert rule['service'].endswith('/backendServices/mizoki-blogs-backend')
rule['paths']=['/blogs/*']
matcher['pathRules'].append({'paths':['/blogs','/blogs/'],'service':matcher['defaultService']})
# Invert exactly the proposed edit and prove every other field unchanged.
restored=copy.deepcopy(new)
m=next(m for m in restored['pathMatchers'] if m['name']=='main-site-matcher')
m['pathRules'].pop();next(r for r in m['pathRules'] if r['paths']==['/blogs/*'])['paths']=['/blogs','/blogs/*']
assert restored==old
def route(config,host,path):
rules=config['hostRules']
h=next((h for h in rules if host in h['hosts']),next(h for h in rules if '*' in h['hosts']))
m=next(m for m in config['pathMatchers'] if m['name']==h['pathMatcher'])
matches=[(p,r['service']) for r in m.get('pathRules',[]) for p in r['paths']]
exact=[s for p,s in matches if p==path]
if exact:return exact[0]
wild=[(len(p),s) for p,s in matches if p.endswith('/*') and path.startswith(p[:-1])]
return max(wild)[1] if wild else m['defaultService']
rows=[]
for host in ['mizoki3.com','tech.mizoki3.com','blog.mizoki3.com','mizoki.mizoki3.com']:
for path in ['/blogs','/blogs/','/blogs/x','/blogs/x/y','/blogs.html','/blog','/api/x','/11/']:
a,b=route(old,host,path),route(new,host,path)
changed=host in ['mizoki3.com','tech.mizoki3.com'] and path in ['/blogs','/blogs/']
assert (a!=b)==changed
rows.append({'host':host,'path':path,'old':a.rsplit('/',1)[1],'proposed':b.rsplit('/',1)[1]})
(args.out/'fr54-proposed-url-map.json').write_text(json.dumps(new,indent=2)+'\n')
(args.out/'fr54-structural-checks.json').write_text(json.dumps({'cases':rows,'result':'32 examples pass; inverse-edit structural equality proves unrelated fields unchanged','official_semantics':'https://docs.cloud.google.com/load-balancing/docs/url-map-concepts','limitation':'local simulator, not cloud validation/application'},indent=2)+'\n')
print('PASS32 routing examples; all unrelated structure unchanged')