diff --git a/Taskfile.yml b/Taskfile.yml index 4629d5d..48da8ff 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -67,6 +67,14 @@ tasks: - task: lint - task: test + sdk:check: + desc: 四种 SDK 检查(缺工具链则跳过并提示) + cmds: + - cmd: powershell -NoProfile -File taskfiles/sdk-check.ps1 + platforms: [windows] + - cmd: sh taskfiles/sdk-check.sh + platforms: [linux, darwin] + itest: desc: 运行集成测试(含后台网页 Playwright e2e) cmds: diff --git a/docs/DEVIATIONS.md b/docs/DEVIATIONS.md index b195489..5e9e6be 100644 --- a/docs/DEVIATIONS.md +++ b/docs/DEVIATIONS.md @@ -1198,6 +1198,15 @@ - 备选方案:沿用异常文本回退与 JS 双重翻倍;否决。 - 影响:仅 sdk/java。 +### 复审修复 K-05 + +- 日期:2026-09-30 +- 原条款:issue #62;D30 Go SDK 与服务端 Go 版本相同;TASKS 4.2 Taskfile 由总控维护。 +- 实际做法:`Taskfile.yml` 增加 `sdk:check`,Windows 跑 `taskfiles/sdk-check.ps1`、Unix 跑 `taskfiles/sdk-check.sh`(go fmt/vet/test、js tsc+vitest、python unittest、java mvn test);工具链或 paho-mqtt / node_modules 不存在时打印 skip 不失败。内联 PowerShell 会和 Task 的 `function` 语法冲突,故拆成脚本。`sdk/go/go.mod` 的 `go 1.27.1` 改为 `go 1.27`。`docs/RELEASE.md` 与 `docs/TASKS.md` 第 1 节写明发布前跑 `task sdk:check`。未把 `sdk:check` 挂进根 `task check`(避免无 Node/Maven/Python 的机器无法过服务端门禁)。 +- 原因:根 `go test ./...` 不含独立模块 sdk/go;四套 SDK 原先不在任何检查里。 +- 备选方案:`task check` 强制依赖四套工具链;否决。 +- 影响:Taskfile、sdk/go/go.mod、RELEASE/TASKS 各一行。 + ## SDK 二 S2 ### S2-PY/JAVA 1–3 2026-09-30 diff --git a/docs/RELEASE.md b/docs/RELEASE.md index 93ad1f8..bdc23bb 100644 --- a/docs/RELEASE.md +++ b/docs/RELEASE.md @@ -134,7 +134,7 @@ - 配置项、备份、升级、证书、时钟、指标:[docs/OPS.md](./OPS.md) - 配置样例:`deploy/config.example.yaml`、`deploy/config.docker.yaml` -常用入口:`task check` / `task build`,然后 `admin init` + `serve`(见 README)。 +常用入口:`task check` / `task sdk:check` / `task build`,然后 `admin init` + `serve`(见 README)。发布前须执行 `task sdk:check`。 ## 6. 未发布 SDK 包与镜像的原因 diff --git a/docs/TASKS.md b/docs/TASKS.md index b12b972..7701905 100644 --- a/docs/TASKS.md +++ b/docs/TASKS.md @@ -14,7 +14,7 @@ 下面全部满足才算交付: -1. `main` 上 `task check`(构建、代码检查、单元测试)和全部集成测试通过。 +1. `main` 上 `task check`(构建、代码检查、单元测试)和全部集成测试通过。发布前另跑 `task sdk:check`(四种 SDK;缺工具链则跳过)。 2. PRD 第 10 节 F01–F23 每条都有验收结果:通过;或未测,写明原因,列进交付说明供负责人事后审阅。 3. 四种 SDK 都通过 DEVELOPMENT 第 9 节的接入清单。 4. DEVELOPMENT 第 13 节的弱网、崩溃、压测、端到端测试做完并有报告。 diff --git a/sdk/go/go.mod b/sdk/go/go.mod index 50f480a..f1ae958 100644 --- a/sdk/go/go.mod +++ b/sdk/go/go.mod @@ -1,6 +1,6 @@ module git.asio.asia/nixevol/NixMsg/sdk/go -go 1.27.1 +go 1.27 require ( github.com/eclipse/paho.golang v0.23.0 diff --git a/taskfiles/sdk-check.ps1 b/taskfiles/sdk-check.ps1 new file mode 100644 index 0000000..c37acf5 --- /dev/null +++ b/taskfiles/sdk-check.ps1 @@ -0,0 +1,59 @@ +$Skip = { param($n, $r) Write-Host ("skip " + $n + ": " + $r) } + +if (Get-Command go -ErrorAction SilentlyContinue) { + Push-Location sdk/go + $unfmt = gofmt -l . + if ($unfmt) { + Write-Host $unfmt + Pop-Location + exit 1 + } + go vet ./... + if ($LASTEXITCODE -ne 0) { Pop-Location; exit $LASTEXITCODE } + go test ./... + if ($LASTEXITCODE -ne 0) { Pop-Location; exit $LASTEXITCODE } + Pop-Location +} else { + & $Skip "sdk/go" "no go" +} + +if ((Get-Command node -ErrorAction SilentlyContinue) -and (Test-Path "sdk/js/node_modules")) { + Push-Location sdk/js + npx --no-install tsc --noEmit + if ($LASTEXITCODE -ne 0) { Pop-Location; exit $LASTEXITCODE } + npx --no-install vitest run + if ($LASTEXITCODE -ne 0) { Pop-Location; exit $LASTEXITCODE } + Pop-Location +} else { + & $Skip "sdk/js" "no node or node_modules" +} + +$py = Get-Command python -ErrorAction SilentlyContinue +if (-not $py) { + $py = Get-Command python3 -ErrorAction SilentlyContinue +} +if ($py) { + $env:PYTHONPATH = (Resolve-Path "sdk/python/src").Path + & $py.Source -c "import paho.mqtt.client" + if ($LASTEXITCODE -ne 0) { + & $Skip "sdk/python" "no paho-mqtt" + } else { + & $py.Source -m unittest discover -s sdk/python/tests -t sdk/python + if ($LASTEXITCODE -ne 0) { + Remove-Item Env:PYTHONPATH -ErrorAction SilentlyContinue + exit $LASTEXITCODE + } + } + Remove-Item Env:PYTHONPATH -ErrorAction SilentlyContinue +} else { + & $Skip "sdk/python" "no python" +} + +if (Get-Command mvn -ErrorAction SilentlyContinue) { + Push-Location sdk/java + mvn -q test + if ($LASTEXITCODE -ne 0) { Pop-Location; exit $LASTEXITCODE } + Pop-Location +} else { + & $Skip "sdk/java" "no mvn" +} diff --git a/taskfiles/sdk-check.sh b/taskfiles/sdk-check.sh new file mode 100644 index 0000000..3238a35 --- /dev/null +++ b/taskfiles/sdk-check.sh @@ -0,0 +1,38 @@ +#!/bin/sh +set -e +skip() { echo "skip $1: $2"; } + +if command -v go >/dev/null 2>&1; then + (cd sdk/go && test -z "$(gofmt -l .)" && go vet ./... && go test ./...) +else + skip sdk/go "no go" +fi + +if command -v node >/dev/null 2>&1 && [ -d sdk/js/node_modules ]; then + (cd sdk/js && npx --no-install tsc --noEmit && npx --no-install vitest run) +else + skip sdk/js "no node or node_modules" +fi + +if command -v python3 >/dev/null 2>&1; then + PY=python3 +elif command -v python >/dev/null 2>&1; then + PY=python +else + PY= +fi +if [ -n "$PY" ]; then + if PYTHONPATH=sdk/python/src "$PY" -c "import paho.mqtt.client" >/dev/null 2>&1; then + PYTHONPATH=sdk/python/src "$PY" -m unittest discover -s sdk/python/tests -t sdk/python + else + skip sdk/python "no paho-mqtt" + fi +else + skip sdk/python "no python" +fi + +if command -v mvn >/dev/null 2>&1; then + (cd sdk/java && mvn -q test) +else + skip sdk/java "no mvn" +fi