check "1: ... and plans to write the TLS block"'grep -qF " + write $F/runway-data/external/application.yml (tls=yes port=443" "$OUT"'
# --- 2. The reproduction: an upgrade re-run with --port N over an existing file is refused -----------
E="$ROOT/existing"; existing "$E"
install_dry "$E" --port 9090
check "2: --port 9090 on an existing install fails"'[ "$RC" -ne 0 ]'
check "2: ... saying the file exists and why that matters"'grep -qF "$E/runway-data/external/application.yml already exists, so this is an existing install" "$OUT" && grep -q "superadmin pin" "$OUT"'
check "2: ... naming the flag and the key to edit instead"'grep -q -- "--port 9090 is a first-install option" "$OUT" && grep -q "edit server.port in that file" "$OUT"'
check "2: ... before any action is planned (nothing ran)"'! grep -q "^ + " "$OUT"'
check "2: ... and says nothing was changed"'grep -q "Nothing was changed" "$OUT"'
check "2: the file is byte-identical (pin kept)"'unchanged "$E"'
# --- 3. --tls-keystore on an existing install: refused, naming runway.tls.* -----------------------------------
check "3: --tls-keystore on an existing install fails"'[ "$RC" -ne 0 ]'
check "3: ... naming only the flag given (not the implied port) and the runway.tls keys"'grep -q -- ": --tls-keystore is a first-install option" "$OUT" && grep -q "runway.tls.\* (enabled, keystore, keystore-password, key-alias, redirect-http) in that file" "$OUT"'
check "3: ... and the keystore is not copied either"'! grep -q "copy keystore" "$OUT" && [ ! -e "$E/runway-data/external/tls" ]'
check "3: the file is byte-identical"'unchanged "$E"'
# --- 4. Both flags at once: both named ------------------------------------------------------------------------
check "4: ... naming both flags and both keys"'grep -q -- "--port 9443 and --tls-keystore are first-install options" "$OUT" && grep -q "edit server.port and runway.tls" "$OUT"'
# --- 5. What an upgrade is meant to be run with still works, and says the file is kept ------------------------
install_dry "$E"
check "5: a plain -y upgrade over an existing install exits 0"'[ "$RC" -eq 0 ]'
check "5: ... plans no write of application.yml"'! grep -q "write .*application.yml" "$OUT"'
check "5: ... and says the port/TLS come from that file, kept"'grep -qF "port / tls : as configured in $E/runway-data/external/application.yml (kept" "$OUT"'
install_dry "$E" --port 8080 --open-firewall
check "5: --port 8080 (the default, never written) is still accepted on an existing install"'[ "$RC" -eq 0 ] && ! grep -q "write .*application.yml" "$OUT"'
install_dry "$E" --firewall-ports 80,443
check "5: --firewall-ports (ADMINISTRATION §7.1 suggests a re-run with it) is still accepted"'[ "$RC" -eq 0 ]'
check "5: the file is byte-identical after all of it"'unchanged "$E"'
# --- 6. An existing install whose file is a symlink (an operator keeping config elsewhere) is existing too -----
check "7: write_app_config over an existing file fails"'[ "$RC" -ne 0 ]'
check "7: ... with its own refusal (not a later install(1) error)"'grep -q "refusing to replace the existing $X/runway-data/external/application.yml" "$OUT" && ! grep -q "^\[install\] writing" "$OUT"'
check "7: ... and the file is byte-identical (the defect left only server.port: 9090)"'unchanged "$X"'