check "5: dry run changes nothing on disk"'diff -r "$ROOT/c5-before" "$D" > /dev/null'
: > "$OUT"; seed_bundled_plugins "$ROOT/b2""$D"
check "5: a new file is installed without a warning"'[ -f "$D/external/plugins/protection/i18n/messages_fr.properties" ] && ! grep -q WARNING "$OUT"'
check "5: a file the operator never had is in the new manifest"'[ -n "$(_ps_manifest_hash "$D/external/plugin-manifests/protection.sha256" "i18n/messages_fr.properties")" ]'
check "6: the new descriptor (with its requiresSpi floor) is installed"'grep -q "version: v2" "$P/plugin.yml" && grep -q "^requiresSpi: \">=1.0.0\"$" "$P/plugin.yml"'
check "6: the new jar is installed"'[ "$(cat "$P/runway-plugin-protection.jar")" = "jar-v2" ]'
check "6: a hand-set enabled: false does not survive (a disabled essential plugin fails closed)"'! grep -q "enabled: false" "$P/plugin.yml"'
check "6: ... but is kept, with the old descriptor, in plugin.yml.bak"'grep -q "version: v1" "$P/plugin.yml.bak" && grep -q "enabled: false" "$P/plugin.yml.bak"'
check "6: templates and i18n are refreshed too"'grep -q "dos v2" "$P/$T" && grep -q "Protection v2" "$P/$I"'
check "6: the operator is told the plugin is refreshed"'grep -q "refreshing bundled plugin .protection. from this release" "$OUT"'
check "6: the operator is told where the previous descriptor and jar are"'grep -q "plugin.yml replaced (the previous one kept as plugin.yml.bak" "$OUT" && grep -q "runway-plugin-protection.jar replaced (the previous one kept as runway-plugin-protection.jar.bak" "$OUT"'
check "6: no warning (nothing was edited)"'! grep -q WARNING "$OUT"'
check "6: no 'nothing changed' line on a real upgrade"'! grep -q "nothing changed" "$OUT"'
check "6: settings (outside the folder) are untouched"'cmp -s "$ROOT/c6-settings" "$D/external/plugin-settings/protection.yml"'
check "6: the old 'leaving it as-is' path is gone"'! grep -q "leaving it as-is" "$OUT"'
# --- 7. The previous jar AND descriptor are kept for a rollback, and a re-run never overwrites them -----------
# A rollback is a symlink flip back to the older kernel, which then meets the refreshed plugin folder. The new jar
check "7: the previous descriptor is kept as plugin.yml.bak"'grep -q "version: v1" "$P/plugin.yml.bak"'
check "7: the previous jar is kept as .jar.bak"'[ "$(cat "$P/runway-plugin-protection.jar.bak")" = "jar-v1" ]'
check "7: the new descriptor and jar are installed"'grep -q "version: v2" "$P/plugin.yml" && [ "$(cat "$P/runway-plugin-protection.jar")" = "jar-v2" ]'
: > "$OUT"; seed_bundled_plugins "$ROOT/b2""$D"
check "7: re-running the same release keeps the PREVIOUS release in plugin.yml.bak"'grep -q "version: v1" "$P/plugin.yml.bak"'
check "7: re-running the same release keeps the PREVIOUS release in .jar.bak"'[ "$(cat "$P/runway-plugin-protection.jar.bak")" = "jar-v1" ]'
check "8: after an upgrade, a re-run keeps the same .bak files, byte for byte"'[ -s "$ROOT/c8-bak-before" ] && cmp -s "$ROOT/c8-bak-before" "$ROOT/c8-bak-after"'
check "8: after an upgrade, a re-run warns about nothing and says nothing changed"'! grep -q WARNING "$OUT" && grep -q "nothing changed" "$OUT"'
# --- 9. install.sh: the refresh needs no flag, and --update-essential-plugins is still accepted -------------
# Runs the real installer in --dry-run (no root needed) from a bundle laid out like the dist zip, over a data dir
# that already holds an older protection: the upgrade case. Dry run writes nothing, so the output is the evidence.
check "9: --help no longer offers the flag as an opt-in"'grep -q "Accepted and ignored" "$INSTALL_OUT" && grep -q "ALWAYS refreshed" "$INSTALL_OUT" && ! grep -q "plugins are never touched on upgrade" "$INSTALL_OUT"'
# --- 10. install.sh keeps the bundle's seed/ in the release, the repair copy the kernel's message points at ------
# Reuses case 9's bundle and prefix; dry run, so the printed plan is the evidence.
DEST9="$PREFIX9/runway-9.9.9"
if install_dry;then pass;else fail "10: install.sh exits 0"; sed 's/^/ | /'"$INSTALL_OUT" >&2;fi
check "10: the plan names the repair copy under the current link"'grep -qF "repair copy : the bundled plugins also kept in the release, $PREFIX9/runway/seed/plugins/" "$INSTALL_OUT"'
check "10: seed/ is copied into the release"'grep -qxF " + cp -R $B/seed $DEST9/seed" "$INSTALL_OUT"'
check "10: ... after the old one is removed (replaced whole, never nested as seed/seed)"'[ "$(grep -nxF " + rm -rf $DEST9/seed" "$INSTALL_OUT" | cut -d: -f1)" -lt "$(grep -nxF " + cp -R $B/seed $DEST9/seed" "$INSTALL_OUT" | cut -d: -f1)" ]'
check "10: ... before the release is chowned (same ownership as bin/ and scripts/)"'[ "$(grep -nxF " + cp -R $B/seed $DEST9/seed" "$INSTALL_OUT" | cut -d: -f1)" -lt "$(grep -nxF " + chown -R runway:runway $DEST9" "$INSTALL_OUT" | cut -d: -f1)" ]'
ifcommand -v restorecon > /dev/null 2>&1;then
check "10: ... and before the SELinux relabel of the release"'[ "$(grep -nxF " + cp -R $B/seed $DEST9/seed" "$INSTALL_OUT" | cut -d: -f1)" -lt "$(grep -nF " + restorecon -RF $DEST9 " "$INSTALL_OUT" | cut -d: -f1)" ]'
fi
check "10: the plugin is still seeded into the data dir as well"'grep -q "refreshing bundled plugin .protection." "$INSTALL_OUT"'
check "10: dry run left the prefix without a release dir"'[ ! -e "$DEST9" ]'
# The installer re-run from an installed release: its bundle IS the release dir, so seed/ must not be removed.
mkdir -p "$DEST9"; cp -a "$B/bin""$B/scripts""$B/seed""$DEST9/"
check "10: --help says where the repair copy is"'grep -q "The bundle.s copy also stays in the release, <prefix>/runway/seed/plugins/<id>/" "$INSTALL_OUT"'