#!/usr/bin/env bash
# misc_br_explicit_anon — `bug-report --yes --model X.dzn` with
# no explicit anonymize flag: anonymize is the default-on safer
# choice when source is included. Asserts archive has
# `model/model.flat.anon.dzn` (not the raw `.flat.dzn`).
set -euo pipefail

cat > "$NUCTEST_TMPDIR/Foo.dzn" <<'EOF'
interface IFoo { in void e(); behavior { on e: {} } }
component Foo { provides IFoo p; behavior { on p.e(): {} } }
EOF

"$NUCLEOS" bug-report --yes --no-last-panic --no-last-run \
    --model "$NUCTEST_TMPDIR/Foo.dzn" \
    -o "$NUCTEST_TMPDIR/bug.tar.gz" \
    < /dev/null > "$NUCTEST_TMPDIR/out.txt" 2> "$NUCTEST_TMPDIR/err.txt"

listing=$(tar tzf "$NUCTEST_TMPDIR/bug.tar.gz")
if ! echo "$listing" | grep -q '/model/model\.flat\.anon\.dzn$'; then
    echo "FAIL: archive missing model.flat.anon.dzn" >&2
    echo "$listing" >&2
    exit 1
fi
if echo "$listing" | grep -q '/model/model\.flat\.dzn$'; then
    echo "FAIL: archive has raw model.flat.dzn — anonymize-default broke" >&2
    echo "$listing" >&2
    exit 1
fi
