Repository navigation
157 lines (142 loc) · 8.84 KB
/
Copy pathtest_cli.yml
File metadata and controls
157 lines (142 loc) · 8.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# ┌──────────────────────────────────────────────────────────────────┐
# │ Author: Ivan Murzak (https://github.com/IvanMurzak) │
# │ Repository: GitHub (https://github.com/IvanMurzak/Unity-MCP) │
# │ Copyright (c) 2025 Ivan Murzak │
# │ Licensed under the Apache License, Version 2.0. │
# │ See the LICENSE file in the project root for more information. │
# └──────────────────────────────────────────────────────────────────┘
name: test-cli
on:
workflow_call:
inputs:
# Chain leg contract (chain_feed.py §C1): the caller forwards its workflow_dispatch inputs. Empty on an
# ordinary pull_request run, where the chain feed steps below are no-ops.
lock: { required: false, type: string, default: "" }
lock_hash8: { required: false, type: string, default: "" }
# Optional commit to test. Empty (the default) checks out the ref the caller ran on.
# test_pull_request_manual.yml passes a 40-char SHA it resolved and verified once.
ref: { required: false, type: string, default: "" }
jobs:
test-cli:
runs-on: ubuntu-latest
# The tests take a few minutes; a chain dispatch additionally self-builds ReflectorNet,
# McpPlugin, the linux-x64 GameDev-MCP-Server and cli-core from the lock before them.
timeout-minutes: 30
strategy:
# Every matrix job writes its OWN chain leg record. With the default fail-fast, one leg failing
# (e.g. a lock whose lower-node sha does not exist) cancels its sibling before that sibling's
# record step runs, leaving the chain verdict one record short. Matches test_unity_plugin.yml.
fail-fast: false
matrix:
node-version: [22, 24, 26]
env:
CHAIN_LOCK: ${{ inputs.lock }}
CHAIN_LOCK_HASH8: ${{ inputs.lock_hash8 }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: ${{ inputs.ref }}
# Nothing here uses git with the token, and the tree may be a fork's code.
persist-credentials: false
# --- chain feed (chain_feed.py §C4): a no-op on an ordinary PR run ---------------------------------------
- name: Setup .NET (chain feed)
if: ${{ inputs.lock != '' || contains(join(github.event.pull_request.labels.*.name, ' '), 'train/') }}
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x
9.0.x
10.0.x
# cli-core declares node >= 22.14, so the lower layers are built on 22 regardless of the
# matrix; the matrix Node below is what the unity-mcp-cli tests then run on.
- name: Setup Node.js 22 (chain feed)
if: ${{ inputs.lock != '' || contains(join(github.event.pull_request.labels.*.name, ' '), 'train/') }}
uses: actions/setup-node@v6
with:
node-version: 22
# Chain interpreter (chain_feed.py print-fragment): resolved ONCE per job to an ABSOLUTE,
# space-free sys.executable and invoked through ${{ env.CHAIN_PY }}, never a bare name.
- name: chain python (posix)
if: runner.os != 'Windows' && env.CHAIN_PY == ''
shell: bash
run: |
for c in python3 python; do
exe="$("$c" -c 'import sys, select, zlib, hashlib; sys.version_info >= (3, 9) or sys.exit(1); print(sys.executable.replace(chr(92), chr(47)))' 2>/dev/null)" || continue
case "$exe" in /*) ;; *) continue ;; esac
case "$exe" in *[[:space:]]*) continue ;; esac
[ -f "$exe" ] && [ -x "$exe" ] || continue
echo "CHAIN_PY=$exe" >> "$GITHUB_ENV"; exit 0
done
echo 'chain: no Python 3.9+ on PATH that runs and reports an absolute, space-free sys.executable (tried python3, python)' >&2; exit 2
- name: chain python (windows)
if: runner.os == 'Windows' && env.CHAIN_PY == ''
shell: pwsh
run: |
foreach ($c in 'python', 'python3') {
$cmd = Get-Command $c -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1
if (-not $cmd) { continue }
$global:LASTEXITCODE = $null
try { $out = & $cmd.Source -c 'import sys, select, zlib, hashlib; sys.version_info >= (3, 9) or sys.exit(1); print(sys.executable.replace(chr(92), chr(47)))' 2>$null } catch { continue }
if ($LASTEXITCODE -ne 0) { continue }
$exe = (@($out) -join ' ').Trim()
if ($exe -notmatch '^[A-Za-z]:/\S+\z' -or -not (Test-Path -LiteralPath $exe -PathType Leaf)) { continue }
"CHAIN_PY=$exe" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8; exit 0
}
[Console]::Error.WriteLine('chain: no Python 3.9+ on PATH that runs and reports an absolute, space-free sys.executable (tried python, python3; never py)'); exit 2
# Builds the lock's cli-core tarball and linux-x64 server and exports UNITY_MCP_SERVER_PATH.
# No cli test reads that variable today (only the Unity Editor's McpServerManager does), so
# the server-binary scope is identity-proven here, not exercised.
- name: chain feed
id: chain
run: ${{ env.CHAIN_PY }} .github/scripts/chain_feed.py apply --node unity-mcp --job test-cli-node${{ matrix.node-version }} --edges npm --edges server-binary
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
working-directory: ./cli
run: npm ci
# MUST follow `npm ci`, which would undo a --no-save install.
- name: chain feed (npm)
if: env.CHAIN_ACTIVE == '1'
run: ${{ env.CHAIN_PY }} .github/scripts/chain_feed.py apply-npm --node unity-mcp --dir cli
# UNITY_MCP_SERVER_PATH makes the Unity plugin skip its server version match (docs/mcp-server.md),
# so a lock whose gamedev-mcp-server base version differs from the CLI's pinned
# DEFAULT_SERVER_VERSION is a named caveat in the leg record (a warning — it never turns the leg RED).
- name: chain pin drift (server-binary)
if: env.CHAIN_ACTIVE == '1'
# A caveat, never a gate: an unreadable lock or pin file must not skip the tests below.
continue-on-error: true
shell: bash
run: |
# The lock is dispatch input: only a plain version string may reach $GITHUB_ENV (a newline
# would inject further variables), so anything else is reported as unreadable instead.
locked=$(${{ env.CHAIN_PY }} -c 'import json,os,re; v=(json.load(open(os.environ["CHAIN_LOCK_PATH"]))["nodes"].get("gamedev-mcp-server") or {}).get("base_version", ""); print(v if isinstance(v, str) and re.fullmatch(r"[0-9]+(\.[0-9]+){0,3}(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?", v) else ("unreadable" if v else ""))')
pinned=$(sed -n "s/^export const DEFAULT_SERVER_VERSION = '\([^']*\)'.*/\1/p" cli/src/utils/server-version.ts || true)
echo "gamedev-mcp-server: lock base_version='$locked', cli DEFAULT_SERVER_VERSION='$pinned'"
if [ -n "$locked" ] && [ -z "$pinned" ]; then
echo "CHAIN_PIN_WARN=pin drift not checked: DEFAULT_SERVER_VERSION could not be read from cli/src/utils/server-version.ts (lock base_version $locked)" >> "$GITHUB_ENV"
elif [ -n "$locked" ] && [ "$locked" != "$pinned" ]; then
echo "CHAIN_PIN_WARN=pin drift: gamedev-mcp-server lock base_version $locked != cli/src/utils/server-version.ts DEFAULT_SERVER_VERSION $pinned (UNITY_MCP_SERVER_PATH makes the Unity plugin skip its version match)" >> "$GITHUB_ENV"
fi
- name: Build TypeScript
working-directory: ./cli
run: npm run build
- name: Run tests
working-directory: ./cli
run: npm test
# --- chain leg record (chain_feed.py §C5) ----------------------------------------------------------------
- name: chain leg record
id: chain_record
if: always()
run: ${{ env.CHAIN_PY }} .github/scripts/chain_feed.py record --node unity-mcp --job test-cli-node${{ matrix.node-version }} --edges npm --edges server-binary --warn "$CHAIN_PIN_WARN" --job-status "${{ job.status }}" --out chain-leg.json
# Keyed on the record's own output, not CHAIN_ACTIVE (which only a COMPLETED apply exports),
# so a failed apply's RED record still uploads.
- name: chain leg artifact
if: always() && steps.chain_record.outputs.artifact_name != ''
uses: actions/upload-artifact@v6
with:
name: ${{ steps.chain_record.outputs.artifact_name }}
path: chain-leg.json
retention-days: 1