#!/usr/bin/env python3
"""Prepare private glab fixtures; never upload generated config.yml files.
Requires PyYAML. Removes null defaults, which glab otherwise treats as literal paths.
"""
import pathlib,yaml
root=pathlib.Path('/tmp/lead-27840-r1/capture')
src=yaml.safe_load(pathlib.Path('/home/ubuntu/.config/glab-cli/config.yml').read_text())
def clean(x):
    return {k:clean(v) for k,v in x.items() if v is not None} if isinstance(x,dict) else x
for name in ['two-host','signed-out','signed-in']:
    p=root/name/'glab';p.mkdir(parents=True,exist_ok=True)
    d=clean({**src,'hosts':dict(src.get('hosts',{}))})
    if name=='signed-out':d['hosts']={}
    if name!='signed-in':
        d['hosts']['gitlab.invalid.example']={'token':'deliberately-invalid-fixture-token','api_host':'gitlab.invalid.example','api_protocol':'https','git_protocol':'https'}
        d['host']='gitlab.invalid.example'
    else:d['host']='gitlab.com'
    f=p/'config.yml';f.write_text(yaml.safe_dump(d));f.chmod(0o600)
