Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
*.yml text eol=lf
*.yaml text eol=lf
*.properties text eol=lf
*.json text eol=lf
*.ps1 text eol=lf
*.psm1 text eol=lf
gradlew text eol=lf
gradlew.bat text eol=crlf
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.iml
out/
.run/
.test-server/
*.log
*.db
*.db-shm
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ Qualification Reward 與 Inviter Milestone Reward 會先以穩定冪等鍵保存
- `develop`:日常整合分支
- task branch:使用獨立 Worktree,目標分支為 `develop`

## 真實伺服器測試

專案的真實 Spigot/Paper/Folia 測試矩陣位於 [`test-servers/matrix.json`](./test-servers/matrix.json),並使用專案外的共用 TestLab 建立隔離實例。操作方式與 EULA 邊界請參閱 [`docs/testing/test-servers.md`](./docs/testing/test-servers.md)。

## 目前狀態

實作工作記錄於本 repository 的 GitHub Issues。不規劃相容或匯入舊版 InviteCode 的資料與設定。
36 changes: 36 additions & 0 deletions docs/testing/evidence/2026-09-22-da2a1c8-automated-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# `da2a1c8` 自動化伺服器 Smoke 證據

- 受測 InviteCode commit:`da2a1c8`
- JAR SHA-256:`F1C61E0B32F7EF3188DD0EEC0CFA149377B6A012EA86E666A89DC657D6439AE3`
- TestLab commit:`78fd831`
- 測試日期:2026-09-22
- 範圍:不需要真人或玩家互動的啟動、儲存與停機 smoke

## 結果

| Profile | Minecraft | Java | 結果 |
| --- | --- | --- | --- |
| `spigot-1.8.8` | 1.8.8 | `local-8` | 通過 |
| `spigot-1.12.2` | 1.12.2 | `local-8` | 通過 |
| `spigot-1.16.5` | 1.16.5 | `local-8` | 通過 |
| `spigot-latest` | 26.2 | `local-25` | 通過 |
| `paper-1.20.6` | 1.20.6 | `local-21` | 通過 |
| `paper-1.21.8` | 1.21.8 | `local-21` | 通過 |
| `paper-latest` | 26.2 | `local-25` | 通過 |
| `folia-latest` | 26.2 | `local-25` | 未執行:PaperMC 沒有 stable build |

七個可用 profile 均符合下列結果:

- 伺服器到達 `Done`,InviteCode 回報啟用。
- `logs/latest.log` 通過嚴格 UTF-8 解碼。
- 沒有 InviteCode linkage error、未處理例外、SQLite migration 失敗、legacy plugin 警告或 `No key layers`。
- 首次啟動建立 `188416` bytes 的 SQLite DB 與 `32` bytes 的防濫用密鑰。
- 伺服器接受 `stop` 或等價的正常 console 中止,所有矩陣 port 在測試後均已釋放。

另以相同 JAR 在 `spigot-1.8.8` 與 `paper-latest` 完成一次停止後重啟。兩個 profile 的 DB 與防濫用密鑰 SHA-256 在重啟前後保持不變,且第二次啟動沒有再次執行首次初始化。

同一組最低/最新邊界也由 server console 自動執行 `/ic help`、`/ic reload`、`/ic admin doctor` 與 `/ic status`。Help 與 reload 正常回覆;doctor 回報 `Runtime=ACTIVE`、SQLite schema 8、Reward backlog 全為 0,且沒有 Vault/PlaceholderAPI;玩家專屬的 status 從 Console 明確回覆「此指令只能由玩家執行」。兩個 profile 均未產生 command exception 或缺少語系訊息。

## 尚未涵蓋

本次沒有把下列項目標記為通過,統一留待接近完成時的最終真人驗收:玩家與 Console 指令、Tab completion、聊天/Dialog 輸入、客戶端顏色與語系顯示、完整 Claim 流程及實際獎勵體驗。Folia 也尚未取得可用的 stable 測試核心。
80 changes: 80 additions & 0 deletions docs/testing/test-servers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# InviteCode 真實測試伺服器

InviteCode 使用專案外的 `D:\Code\Java\Plugin\TestLab` 共用伺服器核心快取與工具,但每個 profile、Worktree 與驗收版本都建立獨立實例。World、插件設定、SQLite、log 與其他可變狀態不跨實例共用。

## 測試矩陣

正式矩陣定義於 `test-servers/matrix.json`:

| Profile | 用途 | 發行 gate |
| --- | --- | --- |
| `spigot-1.8.8` | 最低支援邊界 | 是 |
| `spigot-1.12.2` | 舊版中間邊界 | 是 |
| `spigot-1.16.5` | Java 8 世代中間版本 | 是 |
| `spigot-latest` | 最新 Spigot | 是 |
| `paper-1.20.6` | 新版 Paper 代表版本 | 是 |
| `paper-1.21.8` | 原生 Dialog 能力邊界 | 是 |
| `paper-latest` | 最新穩定 Paper | 是 |
| `folia-latest` | 實驗性 smoke | 否 |

Folia 測試失敗會阻止宣稱 Folia 相容,但不會單獨阻止 Spigot/Paper 發行。

## 環境檢查

```powershell
pwsh -NoProfile -File .\scripts\test-servers\validate.ps1
pwsh -NoProfile -File .\scripts\test-servers\doctor.ps1
```

若 TestLab foundation 尚未合併,可用 `-TestLabRoot` 指向其 task Worktree。平常也可設定 `PLUGIN_TEST_LAB_HOME`。

## 建立測試實例

先建置受測 JAR:

```powershell
mise exec -- .\gradlew.bat clean check shadowJar
```

建立實例但不代替使用者接受 Minecraft EULA:

```powershell
pwsh -NoProfile -File .\scripts\test-servers\prepare.ps1 `
-Profile paper-latest `
-Artifact .\invitecode-plugin\build\libs\InviteCode-0.1.0-SNAPSHOT.jar
```

使用者確認接受 EULA 後,以 `-AcceptEula -Replace` 重建同一實例:

```powershell
pwsh -NoProfile -File .\scripts\test-servers\prepare.ps1 `
-Profile paper-latest `
-Artifact .\invitecode-plugin\build\libs\InviteCode-0.1.0-SNAPSHOT.jar `
-AcceptEula `
-Replace
```

啟動:

```powershell
pwsh -NoProfile -File .\scripts\test-servers\start.ps1 -Profile paper-latest
```

啟動腳本依 profile 透過 mise 選擇 Java,不依賴系統 `PATH` 的 Java 優先順序。人工測試時應在可見的 PowerShell 7 視窗執行,並在 server console 輸入 `stop` 正常關閉。

## 每個 profile 的最低 smoke

1. 確認 InviteCode 啟用且沒有 linkage error、legacy material warning 或未處理 exception。
2. 確認第一次啟動自動建立 SQLite 與 anti-abuse key,重新啟動後沿用既有資料。
3. 玩家與 Console 驗證 `/ic help`、`/ic reload`、Tab completion 與權限拒絕。
4. 玩家驗證 Invite Code 顯示、Claim、Confirmation、Status 與 Stats。
5. 驗證 `zh_TW`/`en_US`、UTF-8 與 client locale fallback。
6. 驗證離線 Reward 補發與 restart recovery;需要外部整合的 profile 再加入 Vault/PlaceholderAPI。

各次測試應記錄 `workspace.json`、受測 commit、JAR SHA-256、操作結果與 `logs/latest.log`。實際相容性證據尚未取得前,不得只因實例能建立就宣稱該版本受到支援。

## 自動檢查與最終真人驗收

日常開發與各功能階段先由 Agent 執行不需要玩家判斷的檢查,包括 Gradle 測試、JAR 結構與 Java 8 bytecode、伺服器啟動與正常停機、log 錯誤掃描、UTF-8 解碼、SQLite/防濫用密鑰初始化,以及適用時的重啟持久化。這些結果須綁定受測 commit 與 JAR SHA-256。

需要真人觀察或實際玩家操作的項目集中到插件功能接近完成、準備發行候選版本時執行一次完整驗收,包括指令與 Tab completion、聊天及 Dialog 輸入、顏色與語系顯示、Claim/Confirmation/Status/Stats,以及實際獎勵體驗。延後的真人項目維持「待最終真人驗收」,不得因自動 smoke 通過而標記為已通過,也不阻擋仍在開發中的本機 checkpoint。
69 changes: 69 additions & 0 deletions scripts/test-servers/common.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"

function Get-InviteCodeRepositoryRoot {
return [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot "..\.."))
}

function Get-InviteCodeTestMatrix {
$path = Join-Path (Get-InviteCodeRepositoryRoot) "test-servers\matrix.json"
$document = Get-Content -LiteralPath $path -Raw -Encoding UTF8 | ConvertFrom-Json -ErrorAction Stop
if ($document.schemaVersion -ne 1 -or $document.project -cne "InviteCode") {
throw "不支援的 InviteCode test-server matrix。"
}
$profiles = @($document.profiles)
$duplicates = @($profiles | Group-Object id | Where-Object Count -gt 1)
if ($profiles.Count -eq 0 -or $duplicates.Count -gt 0) {
throw "InviteCode test-server matrix 為空或包含重複 profile。"
}
return $document
}

function Get-InviteCodeTestProfile {
param([Parameter(Mandatory = $true)][string] $Id)
$matches = @((Get-InviteCodeTestMatrix).profiles | Where-Object id -CEQ $Id)
if ($matches.Count -ne 1) {
throw "InviteCode matrix 找不到唯一 profile:$Id"
}
return $matches[0]
}

function Resolve-PluginTestLabRoot {
param([AllowNull()][string] $ExplicitRoot)
$candidates = [System.Collections.Generic.List[string]]::new()
if (-not [string]::IsNullOrWhiteSpace($ExplicitRoot)) {
$candidates.Add($ExplicitRoot)
}
if (-not [string]::IsNullOrWhiteSpace($env:PLUGIN_TEST_LAB_HOME)) {
$candidates.Add($env:PLUGIN_TEST_LAB_HOME)
}
$cursor = [System.IO.DirectoryInfo]::new((Get-InviteCodeRepositoryRoot))
while ($null -ne $cursor) {
$candidates.Add((Join-Path $cursor.FullName "TestLab\repo"))
$cursor = $cursor.Parent
}
foreach ($candidate in $candidates) {
$resolved = [System.IO.Path]::GetFullPath($candidate)
if (Test-Path -LiteralPath (Join-Path $resolved "scripts\prepare-instance.ps1") -PathType Leaf) {
return $resolved
}
}
throw "找不到 TestLab。請合併 TestLab foundation、設定 PLUGIN_TEST_LAB_HOME,或傳入 -TestLabRoot。"
}

function Resolve-InviteCodePluginArtifact {
param([AllowNull()][string] $ExplicitArtifact)
if (-not [string]::IsNullOrWhiteSpace($ExplicitArtifact)) {
$resolved = [System.IO.Path]::GetFullPath($ExplicitArtifact)
if (-not (Test-Path -LiteralPath $resolved -PathType Leaf)) {
throw "找不到 InviteCode JAR:$resolved"
}
return $resolved
}
$directory = Join-Path (Get-InviteCodeRepositoryRoot) "invitecode-plugin\build\libs"
$matches = @(Get-ChildItem -LiteralPath $directory -File -Filter "InviteCode-*.jar" -ErrorAction SilentlyContinue)
if ($matches.Count -ne 1) {
throw "無法唯一判定 InviteCode JAR;請先建置或傳入 -Artifact。"
}
return $matches[0].FullName
}
33 changes: 33 additions & 0 deletions scripts/test-servers/doctor.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[CmdletBinding()]
param([AllowNull()][string] $TestLabRoot)

. (Join-Path $PSScriptRoot "common.ps1")
$lab = Resolve-PluginTestLabRoot -ExplicitRoot $TestLabRoot
$matrix = Get-InviteCodeTestMatrix
Import-Module (Join-Path $lab "scripts\TestLab.psm1") -Force
$labProfiles = @(Get-TestLabProfiles)

$rows = foreach ($profile in $matrix.profiles) {
$labProfile = @($labProfiles | Where-Object id -CEQ $profile.id)
$javaAvailable = $false
$javaDetail = "profile missing"
if ($labProfile.Count -eq 1) {
$output = (& mise exec "java@$($labProfile[0].javaAlias)" -- java -version 2>&1 | Out-String).Trim()
$javaAvailable = $LASTEXITCODE -eq 0
$javaDetail = ($output -split "`r?`n" | Select-Object -First 1)
}
[pscustomobject]@{
Profile = $profile.id
Purpose = $profile.purpose
Required = $profile.requiredForRelease
TestLab = $labProfile.Count -eq 1
Java = $javaAvailable
Runtime = $javaDetail
}
}

Write-Host "TestLab:$lab"
$rows | Format-Table -AutoSize
if (@($rows | Where-Object { -not $_.TestLab -or -not $_.Java }).Count -gt 0) {
throw "InviteCode 測試矩陣仍有缺少的 TestLab profile 或 Java runtime。"
}
27 changes: 27 additions & 0 deletions scripts/test-servers/prepare.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)][string] $Profile,
[AllowNull()][string] $Artifact,
[AllowNull()][string] $TestLabRoot,
[AllowNull()][string] $Instance,
[switch] $AcceptEula,
[switch] $Replace
)

. (Join-Path $PSScriptRoot "common.ps1")
$matrixProfile = Get-InviteCodeTestProfile -Id $Profile
$lab = Resolve-PluginTestLabRoot -ExplicitRoot $TestLabRoot
$jar = Resolve-InviteCodePluginArtifact -ExplicitArtifact $Artifact
$instanceName = if ([string]::IsNullOrWhiteSpace($Instance)) { "invitecode-$Profile" } else { $Instance }

& (Join-Path $lab "scripts\prepare-instance.ps1") `
-Project "InviteCode" `
-Instance $instanceName `
-Profile $Profile `
-PluginJar $jar `
-Port $matrixProfile.port `
-AcceptEula:$AcceptEula `
-Replace:$Replace
if ($LASTEXITCODE -ne 0) {
throw "TestLab prepare-instance 失敗,結束碼為 $LASTEXITCODE。"
}
16 changes: 16 additions & 0 deletions scripts/test-servers/start.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)][string] $Profile,
[AllowNull()][string] $TestLabRoot,
[AllowNull()][string] $Instance
)

. (Join-Path $PSScriptRoot "common.ps1")
[void] (Get-InviteCodeTestProfile -Id $Profile)
$lab = Resolve-PluginTestLabRoot -ExplicitRoot $TestLabRoot
$instanceName = if ([string]::IsNullOrWhiteSpace($Instance)) { "invitecode-$Profile" } else { $Instance }

& (Join-Path $lab "scripts\start-instance.ps1") -Project "InviteCode" -Instance $instanceName
if ($LASTEXITCODE -ne 0) {
throw "TestLab start-instance 失敗,結束碼為 $LASTEXITCODE。"
}
17 changes: 17 additions & 0 deletions scripts/test-servers/validate.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
. (Join-Path $PSScriptRoot "common.ps1")

$matrix = Get-InviteCodeTestMatrix
if (@($matrix.profiles).Count -ne 8) {
throw "InviteCode test matrix 預期為 8 個 profile。"
}
$ports = @($matrix.profiles | ForEach-Object { [int] $_.port })
if (@($ports | Group-Object | Where-Object Count -gt 1).Count -gt 0) {
throw "InviteCode test matrix 包含重複 port。"
}
if (@($matrix.profiles | Where-Object { $_.id -ceq "folia-latest" -and $_.requiredForRelease }).Count -ne 0) {
throw "Folia 應維持實驗性,不得標記為必要發行 gate。"
}

Write-Host "InviteCode test-server matrix 驗證通過:8 profiles,port 無衝突。"
54 changes: 54 additions & 0 deletions test-servers/matrix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"schemaVersion": 1,
"project": "InviteCode",
"profiles": [
{
"id": "spigot-1.8.8",
"port": 51888,
"purpose": "最低支援邊界",
"requiredForRelease": true
},
{
"id": "spigot-1.12.2",
"port": 51222,
"purpose": "舊版 Bukkit API 中間邊界",
"requiredForRelease": true
},
{
"id": "spigot-1.16.5",
"port": 51650,
"purpose": "Java 8 世代中間版本",
"requiredForRelease": true
},
{
"id": "spigot-latest",
"port": 52620,
"purpose": "最新 Spigot 邊界",
"requiredForRelease": true
},
{
"id": "paper-1.20.6",
"port": 62060,
"purpose": "新版 Paper 舊映射邊界",
"requiredForRelease": true
},
{
"id": "paper-1.21.8",
"port": 62180,
"purpose": "原生 Dialog 能力邊界",
"requiredForRelease": true
},
{
"id": "paper-latest",
"port": 62620,
"purpose": "最新穩定 Paper",
"requiredForRelease": true
},
{
"id": "folia-latest",
"port": 63620,
"purpose": "實驗性 Folia smoke",
"requiredForRelease": false
}
]
}
Loading