#!/usr/bin/env bash
set -euo pipefail
# Usage: bash seed-marketplace.sh /absolute/path/to/fixture
fixture="$1"
export CLAUDE_CONFIG_DIR="$fixture/claude"
python3 - "$fixture" <<'PYTHON'
from pathlib import Path
import json, sys, os
fixture=Path(sys.argv[1])
config=fixture/'claude'
config.mkdir(parents=True, exist_ok=True)
# Supply connection credentials through the environment; never include them in the script.
settings={'env':{key:os.environ[key] for key in ['ANTHROPIC_BASE_URL','ANTHROPIC_AUTH_TOKEN'] if key in os.environ}}
(config/'settings.json').write_text(json.dumps(settings))
p=fixture/'marketplace' 
(p/'.claude-plugin').mkdir(parents=True, exist_ok=True)
(p/'.claude-plugin/marketplace.json').write_text(json.dumps({'name':'repro-mkt','owner':{'name':'Scenario'},'plugins':[{'name':'collection-a','source':'./','strict':False,'skills':['./skills/skill-one']},{'name':'collection-b','source':'./','strict':False,'skills':['./skills/skill-two']}]}))
for name in ['skill-one','skill-two']:
    d=p/'skills'/name
    d.mkdir(parents=True, exist_ok=True)
    (d/'SKILL.md').write_text(f'---\nname: {name}\ndescription: Synthetic marketplace {name}\n---\nUse this synthetic skill.\n')
PYTHON
git init -q "$fixture/marketplace"
git -C "$fixture/marketplace" add .
git -C "$fixture/marketplace" -c user.name=Scenario -c user.email=scenario@example.invalid commit -qm 'Synthetic marketplace'
claude plugin marketplace add "$fixture/marketplace"
claude plugin install collection-a@repro-mkt
claude plugin install collection-b@repro-mkt
# Run scenarios:prove with CLAUDE_CONFIG_DIR and T3_SCENARIO_INHERIT_ENV=CLAUDE_CONFIG_DIR.
