diff --git a/.skills/mcc-integration-testing/SKILL.md b/.skills/mcc-integration-testing/SKILL.md index 2b567cce..ac477c09 100644 --- a/.skills/mcc-integration-testing/SKILL.md +++ b/.skills/mcc-integration-testing/SKILL.md @@ -1,12 +1,14 @@ --- name: mcc-integration-testing -description: Repeatable real-server integration testing for Minecraft Console Client against a local offline Minecraft Java server. Use this whenever the user wants to confirm nothing broke, validate runtime or protocol changes end-to-end, exercise movement, physics, inventory, entity handling, or run a single-version or cross-version MCC regression sweep on a real server. +description: Repeatable real-server integration testing for Minecraft Console Client against a local Minecraft Java server in offline mode or Microsoft online mode. Use this whenever the user wants to confirm nothing broke, validate runtime or protocol changes end-to-end, exercise movement, physics, inventory, entity handling, or run a single-version or cross-version MCC regression sweep on a real server. --- # MCC Integration Testing Use this skill when the task is "prove it still works on a real server", not just "reason about whether it should work." +Read [references/online-mode.md](references/online-mode.md) when the user asks for Microsoft login, device-code auth, or an online-mode server run. + ## Default target - Use `1.21.11-Vanilla` unless the user asks for a different version or a version matrix. @@ -17,8 +19,14 @@ Use this skill when the task is "prove it still works on a real server", not jus - Use a real local server. - Keep version matrices sequential in shared local environments. The tmux server harness is shared state by default. - Prefer temporary MCC configs for scripted runs so one test does not contaminate the next. +- Default to offline auth in generated temp configs. Do not trust the repo-root `MinecraftClient.ini` account defaults. +- If the user explicitly asks for Microsoft online login, honor that request and generate the temp config for Microsoft auth instead of offline mode. +- For Microsoft auth, prefer an interactive TTY launch with `BasicIO-NoColor` so the device code is easy to read and relay to the user. +- Do not use file-input mode during Microsoft auth. Launch interactively first, complete login, then switch to scripted control only if needed. +- For online-mode tests, prefer a clean temp config with no join-time bots or scheduled tasks. Inherited `ScriptScheduler` or `DiscordRpc` settings can pollute the session and send unintended chat right after login. - Legacy and modern command syntax differ. Do not assume one server-command profile fits every version. - Use actual MCC output and actual server logs for assertions. Do not invent success strings. +- Launch MCC against an explicit `localhost:` target for repeatable local tests. ## Choose the test mode @@ -78,10 +86,23 @@ Offline configuration helper: .skills/mcc-integration-testing/scripts/ensure_offline_server.sh 1.21.11-Vanilla ``` +By default, the config helper prepares offline auth. To opt into another auth mode for a specific run, set: + +```bash +MCC_TEST_ACCOUNT_TYPE=microsoft +MCC_TEST_PASSWORD= +``` + +Optionally override the login name with the fourth argument to the config helper. + ## Scripts and tools - `.skills/mcc-integration-testing/scripts/ensure_offline_server.sh` - configures persistent offline mode and RCON +- `.skills/mcc-integration-testing/scripts/prepare_offline_mcc_config.sh` + - copies `MinecraftClient.ini`, prepares offline login by default, and can switch to Microsoft auth when explicitly requested +- `.skills/mcc-integration-testing/scripts/get_server_port.sh` + - resolves the actual local server port from `server.properties` or the latest server log - `.skills/mcc-integration-testing/scripts/run_full_spectrum_test.sh` - single-version deep smoke with built-in assertions - `.skills/mcc-integration-testing/scripts/summarize_test_run.sh` @@ -103,6 +124,13 @@ Always summarize: ## Troubleshooting - If the first RCON command fails, retry it before assuming the setup is broken. +- If MCC reaches Microsoft device-code login during an offline test, stop and inspect the generated temp config before retrying. +- If the user explicitly requests Microsoft online login, set `MCC_TEST_ACCOUNT_TYPE=microsoft` before launching the harness. +- If the user explicitly requests Microsoft online login, use `BasicIO-NoColor` in a real TTY, relay the device code from the TUI, and avoid pressing empty Enter at any auth prompt. +- If the online-mode session sends unexpected chat or commands right after join, inspect inherited bot settings first. `ChatBot.ScriptScheduler` tasks and `ChatBot.DiscordRpc` are common sources of test noise in user-local configs. +- If `dotnet run` cannot see an existing Microsoft session, check whether `SessionCache.db` and `ProfileKeyCache.ini` need to be synced from `MinecraftClient/bin/Release/net10.0/` to the repo root. +- If Microsoft auth keeps prompting even with a valid session cache, verify `Account.Login` matches the cached username exactly. +- If MCC reports `Connection refused`, verify the launched target matches the server's actual `server-port`. - If multiple versions are being tested, do not start them in parallel unless the harness isolates tmux sessions and input files. - If a test assertion fails, inspect the real MCC output before changing the code or weakening the assertion. - If an older server behaves oddly on Linux, check `use-native-transport=false` in `server.properties`. diff --git a/.skills/mcc-integration-testing/references/online-mode.md b/.skills/mcc-integration-testing/references/online-mode.md new file mode 100644 index 00000000..fdd0beda --- /dev/null +++ b/.skills/mcc-integration-testing/references/online-mode.md @@ -0,0 +1,48 @@ +# Online-Mode Notes + +Use this flow only when the user explicitly asks for Microsoft login or wants to validate against an online-mode server. + +## Launch mode + +- Prefer `BasicIO-NoColor` in a real TTY so the Microsoft device-code prompt is easy to read and copy. +- Do not use `MCC_FILE_INPUT=1` during the auth step. It is for scripted command injection, not interactive login. +- Avoid `nohup`. Use `tmux` for long-running sessions that still need a TTY. +- Start from a clean temp config when possible. If the temp config is copied from a user-local `MinecraftClient.ini`, inspect `ChatBot.ScriptScheduler` and `ChatBot.DiscordRpc` before the run. + +## Session cache behavior + +- `dotnet run --project MinecraftClient ...` uses the repo root for `SessionCache.db` and `ProfileKeyCache.ini`. +- The compiled binary under `MinecraftClient/bin//net10.0/` uses that output directory instead. +- If a session exists in one location and not the other, sync the cache files before assuming login is broken. + +## Account settings + +- `Account.Login` must be populated for MCC to look up a cached Microsoft session. +- The cached key is the username form MCC stored, typically the lowercase username, not necessarily the email address. +- MCC rewrites `MinecraftClient.ini` on clean exit, so generate a temp config per run and do not edit it while MCC is still running. + +## Auth prompt handling + +- Do not send a bare Enter to dismiss `Password(invisible):` or `Paste your code here:` prompts. That can trigger offline fallback. +- For interactive online-mode runs, wait for the device code prompt and relay the code to the user exactly as shown. +- After the user completes login, continue the test in the same TTY session or restart into file-driven mode if the workflow requires automation. + +## Join-time noise + +- Real user configs may contain enabled bots or task lists that were harmless in offline testing but are noisy in online-mode validation. +- The most common examples are: + - `ChatBot.ScriptScheduler` task lists that send `/hello`, `/login ...`, or other automatic commands on login or on an interval + - `ChatBot.DiscordRpc`, which is not harmful to server state but adds log noise and extra background activity +- If the goal is protocol or feature validation, suppress these before the run or treat their output as non-test noise. + +## Server settings + +- For realistic online-mode testing, keep `online-mode=true`. +- Keep `enforce-secure-profile=true` unless the test explicitly targets insecure-profile behavior. + +## Command reminders + +- With `InternalCmdChar = "slash"`: + - `/health`, `/pos`, `/inventory`, `/entity` are MCC internal commands. + - `/send /list` and `/send /give ...` are server commands. + - bare text is regular chat sent to the server. diff --git a/.skills/mcc-integration-testing/scripts/get_server_port.sh b/.skills/mcc-integration-testing/scripts/get_server_port.sh new file mode 100644 index 00000000..95bceb1a --- /dev/null +++ b/.skills/mcc-integration-testing/scripts/get_server_port.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +set -euo pipefail + +if [[ $# -ne 1 ]]; then + echo "Usage: $0 " >&2 + exit 1 +fi + +REPO_ROOT="$(cd "$(dirname "$0")/../../.." && pwd)" +SERVER_DIR_NAME="$1" +SERVERS_ROOT="${MCC_SERVERS:-$REPO_ROOT/MinecraftOfficial/downloads}" +SERVER_DIR="$SERVERS_ROOT/$SERVER_DIR_NAME" +PROPS_FILE="$SERVER_DIR/server.properties" +LATEST_LOG="$SERVER_DIR/logs/latest.log" + +if [[ -f "$PROPS_FILE" ]]; then + PORT_LINE="$(grep -E '^server-port=' "$PROPS_FILE" | tail -n 1 || true)" + if [[ -n "$PORT_LINE" ]]; then + PORT="${PORT_LINE#server-port=}" + if [[ "$PORT" =~ ^[0-9]+$ ]]; then + printf '%s\n' "$PORT" + exit 0 + fi + fi +fi + +if [[ -f "$LATEST_LOG" ]]; then + PORT="$(sed -n 's/.*Starting Minecraft server on .*:\([0-9][0-9]*\).*/\1/p' "$LATEST_LOG" | tail -n 1)" + if [[ -n "$PORT" ]]; then + printf '%s\n' "$PORT" + exit 0 + fi +fi + +printf '25565\n' diff --git a/.skills/mcc-integration-testing/scripts/prepare_offline_mcc_config.sh b/.skills/mcc-integration-testing/scripts/prepare_offline_mcc_config.sh new file mode 100644 index 00000000..f36129fa --- /dev/null +++ b/.skills/mcc-integration-testing/scripts/prepare_offline_mcc_config.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash +set -euo pipefail + +if [[ $# -lt 3 || $# -gt 4 ]]; then + echo "Usage: $0 [login]" >&2 + exit 1 +fi + +TEMPLATE_INI="$1" +OUTPUT_INI="$2" +MC_VERSION="$3" +LOGIN_NAME="${4:-CursorBot}" +ACCOUNT_TYPE="${MCC_TEST_ACCOUNT_TYPE:-mojang}" +PASSWORD_VALUE="${MCC_TEST_PASSWORD-}" + +if [[ "$ACCOUNT_TYPE" != "mojang" && "$ACCOUNT_TYPE" != "microsoft" && "$ACCOUNT_TYPE" != "yggdrasil" ]]; then + echo "Unsupported MCC_TEST_ACCOUNT_TYPE: $ACCOUNT_TYPE" >&2 + exit 1 +fi + +if [[ -z "${MCC_TEST_PASSWORD+x}" ]]; then + if [[ "$ACCOUNT_TYPE" == "mojang" ]]; then + PASSWORD_VALUE="-" + else + PASSWORD_VALUE="" + fi +fi + +cp "$TEMPLATE_INI" "$OUTPUT_INI" + +sed -i \ + -e "s#^Account = .*#Account = { Login = \"$LOGIN_NAME\", Password = \"$PASSWORD_VALUE\" }#" \ + -e "s#^AccountType = .*#AccountType = \"$ACCOUNT_TYPE\"#" \ + -e "s#^MinecraftVersion = \"[^\"]*\"\\(.*\\)\$#MinecraftVersion = \"$MC_VERSION\"\\1#" \ + -e 's#^TerrainAndMovements = false#TerrainAndMovements = true#' \ + -e 's#^InventoryHandling = false#InventoryHandling = true#' \ + -e 's#^EntityHandling = false#EntityHandling = true#' \ + -e 's#^AutoRespawn = false#AutoRespawn = true#' \ + "$OUTPUT_INI" + +grep -Fq "AccountType = \"$ACCOUNT_TYPE\"" "$OUTPUT_INI" || { + echo "Failed to enforce account type $ACCOUNT_TYPE in $OUTPUT_INI" >&2 + exit 1 +} + +if [[ "$ACCOUNT_TYPE" == "mojang" ]]; then + grep -Eq '^Account = \{ Login = ".*", Password = "-" \}' "$OUTPUT_INI" || { + echo "Failed to enforce offline account in $OUTPUT_INI" >&2 + exit 1 + } +fi + +printf '%s\n' "$OUTPUT_INI" diff --git a/.skills/mcc-integration-testing/scripts/run_full_spectrum_test.sh b/.skills/mcc-integration-testing/scripts/run_full_spectrum_test.sh index 36a89da8..2db7d2a8 100755 --- a/.skills/mcc-integration-testing/scripts/run_full_spectrum_test.sh +++ b/.skills/mcc-integration-testing/scripts/run_full_spectrum_test.sh @@ -38,24 +38,7 @@ cleanup() { trap cleanup EXIT prepare_config() { - cp "$REPO_ROOT/MinecraftClient.ini" "$CFG" - - sed -i \ - -e 's/Account = { Login = "test", Password = "-" }/Account = { Login = "CursorBot", Password = "-" }/' \ - -e "s/MinecraftVersion = \"auto\"/MinecraftVersion = \"$MC_VERSION\"/" \ - -e 's/TerrainAndMovements = false/TerrainAndMovements = true/' \ - -e 's/InventoryHandling = false/InventoryHandling = true/' \ - -e 's/EntityHandling = false/EntityHandling = true/' \ - -e 's/AutoRespawn = false/AutoRespawn = true/' \ - "$CFG" - - sed -i '/^\[ChatBot.ScriptScheduler\]/,/^\[/ { s/^Enabled = true/Enabled = false/; }' "$CFG" - sed -i '/^\[ChatBot.DiscordRpc\]/,/^\[/ { s/^Enabled = true/Enabled = false/; }' "$CFG" - sed -i '/^\[ChatBot.AntiAFK\]/,/^\[/ { s/^Enabled = true/Enabled = false/; }' "$CFG" - sed -i '/^\[ChatBot.AutoDig\]/,/^\[/ { s/^Enabled = true/Enabled = false/; }' "$CFG" - sed -i '/^\[ChatBot.AutoAttack\]/,/^\[/ { s/^Enabled = true/Enabled = false/; }' "$CFG" - sed -i '/^\[ChatBot.PlayerListLogger\]/,/^\[/ { s/^Enabled = true/Enabled = false/; }' "$CFG" - sed -i '/^\[ChatBot.ReplayCapture\]/,/^\[/ { s/^Enabled = true/Enabled = false/; }' "$CFG" + bash "$SCRIPT_DIR/prepare_offline_mcc_config.sh" "$REPO_ROOT/MinecraftClient.ini" "$CFG" "$MC_VERSION" >/dev/null } wait_for_file_pattern() { @@ -165,6 +148,7 @@ run_mcc_command() { "$SCRIPT_DIR/ensure_offline_server.sh" "$VERSION" prepare_config +SERVER_PORT="$(bash "$SCRIPT_DIR/get_server_port.sh" "$VERSION")" : > "$INPUT_FILE" @@ -178,7 +162,7 @@ wait_for_server_ready || fail "Server did not become ready" echo "Starting MCC..." ( cd "$REPO_ROOT" - MCC_FILE_INPUT=1 dotnet run --project MinecraftClient -c Release --no-build -- "$CFG" > "$MCC_LOG" 2>&1 + MCC_FILE_INPUT=1 dotnet run --project MinecraftClient -c Release --no-build -- "$CFG" CursorBot - "localhost:$SERVER_PORT" > "$MCC_LOG" 2>&1 ) & MCC_PID=$!