|
| 1 | +#!/usr/bin/env bash |
| 2 | +# #267/#269: fresh init seeds the mcpplibs-org index URL + artifact source; |
| 3 | +# legacy config.toml / .xlings.json (old org URL, no artifact) are healed in |
| 4 | +# place, idempotently, in both pretty (mcpp writer) and compact (xlings |
| 5 | +# writer) JSON spacings. Unrelated .xlings.json state must survive. |
| 6 | +set -e |
| 7 | + |
| 8 | +TMP=$(mktemp -d) |
| 9 | +trap "rm -rf $TMP" EXIT |
| 10 | + |
| 11 | +export MCPP_HOME="$TMP/mcpp-home" |
| 12 | + |
| 13 | +NEW_URL='https://github.com/mcpplibs/mcpp-index.git' |
| 14 | +OLD_URL='https://github.com/mcpp-community/mcpp-index.git' |
| 15 | +ART='https://github.com/xlings-res/mcpp-index' |
| 16 | +CFG="$MCPP_HOME/config.toml" |
| 17 | +XJ="$MCPP_HOME/registry/.xlings.json" |
| 18 | + |
| 19 | +# 1. Fresh init: new org URL + artifact declaration in both files. |
| 20 | +# (xlings' own bootstrap may re-serialize .xlings.json with its writer, so |
| 21 | +# assert on the key/value pairs, not on mcpp's seed line layout.) |
| 22 | +"$MCPP" self env > /dev/null |
| 23 | +grep -q "url = \"$NEW_URL\"" "$CFG" || { echo "config.toml missing new url"; exit 1; } |
| 24 | +grep -q "artifact = \"$ART\"" "$CFG" || { echo "config.toml missing artifact"; exit 1; } |
| 25 | +grep -q "\"url\": \"$NEW_URL\"" "$XJ" \ |
| 26 | + || { echo "seeded .xlings.json missing new url"; cat "$XJ"; exit 1; } |
| 27 | +grep -q "\"artifact\": \"$ART\"" "$XJ" \ |
| 28 | + || { echo "seeded .xlings.json missing artifact"; cat "$XJ"; exit 1; } |
| 29 | +if grep -q 'mcpp-community/mcpp-index' "$CFG" "$XJ"; then |
| 30 | + echo "old org URL leaked into fresh seed"; exit 1 |
| 31 | +fi |
| 32 | + |
| 33 | +# 2. Legacy heal (pretty spacing): old org URL, no artifact. |
| 34 | +cat > "$CFG" <<EOF |
| 35 | +[xlings] |
| 36 | +binary = "bundled" |
| 37 | +home = "" |
| 38 | +
|
| 39 | +[index] |
| 40 | +default = "mcpplibs" |
| 41 | +
|
| 42 | +[index.repos."mcpplibs"] |
| 43 | +url = "$OLD_URL" |
| 44 | +EOF |
| 45 | +cat > "$XJ" <<EOF |
| 46 | +{ |
| 47 | + "index_repos": [ |
| 48 | + { "name": "mcpplibs", "url": "$OLD_URL" } |
| 49 | + ], |
| 50 | + "subos": "default", |
| 51 | + "lang": "en", |
| 52 | + "mirror": "auto" |
| 53 | +} |
| 54 | +EOF |
| 55 | +"$MCPP" self env > /dev/null |
| 56 | +grep -q "url = \"$NEW_URL\"" "$CFG" || { echo "config.toml url not healed"; cat "$CFG"; exit 1; } |
| 57 | +grep -q "\"url\": \"$NEW_URL\", \"artifact\": \"$ART\"" "$XJ" \ |
| 58 | + || { echo ".xlings.json not healed"; cat "$XJ"; exit 1; } |
| 59 | +grep -q '"subos": "default"' "$XJ" || { echo "unrelated .xlings.json key lost"; exit 1; } |
| 60 | +if grep -q 'mcpp-community/mcpp-index' "$CFG" "$XJ"; then |
| 61 | + echo "old org URL survived heal"; exit 1 |
| 62 | +fi |
| 63 | + |
| 64 | +# Idempotent: a second run must not touch either file again. |
| 65 | +cp "$CFG" "$TMP/cfg1"; cp "$XJ" "$TMP/xj1" |
| 66 | +"$MCPP" self env > /dev/null |
| 67 | +cmp -s "$CFG" "$TMP/cfg1" || { echo "config.toml heal not idempotent"; exit 1; } |
| 68 | +cmp -s "$XJ" "$TMP/xj1" || { echo ".xlings.json heal not idempotent"; exit 1; } |
| 69 | + |
| 70 | +# 3. Legacy heal (compact spacing, old index name): xlings-writer format. |
| 71 | +printf '{"index_repos":[{"name":"mcpp-index","url":"%s"}],"mirror":"auto"}' "$OLD_URL" > "$XJ" |
| 72 | +"$MCPP" self env > /dev/null |
| 73 | +grep -q '"name":"mcpplibs"' "$XJ" || { echo "compact name not healed"; cat "$XJ"; exit 1; } |
| 74 | +grep -q 'xlings-res/mcpp-index' "$XJ" || { echo "compact artifact not injected"; cat "$XJ"; exit 1; } |
| 75 | +if grep -q 'mcpp-community' "$XJ"; then |
| 76 | + echo "compact old org URL survived"; exit 1 |
| 77 | +fi |
| 78 | + |
| 79 | +echo "OK" |
0 commit comments