-
Notifications
You must be signed in to change notification settings - Fork 1
275 lines (227 loc) · 9.34 KB
/
ha-dev-plugin-tests.yml
File metadata and controls
275 lines (227 loc) · 9.34 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
name: HA Dev Plugin Tests
on:
push:
branches: [main, testing]
paths:
- 'plugins/home-assistant-dev/**'
pull_request:
branches: [main]
paths:
- 'plugins/home-assistant-dev/**'
defaults:
run:
working-directory: plugins/home-assistant-dev
jobs:
python-tests:
name: Python Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Install dependencies
run: |
pip install pytest pytest-asyncio pytest-cov pyyaml
- name: Run unit tests
run: python3 -m pytest tests/scripts/ -v -m unit --tb=short --cov=scripts --cov-report=term-missing
- name: Run validation tests
run: python3 -m pytest tests/validation/ -v --tb=short
- name: Run structural tests
run: python3 -m pytest tests/test_plugin_structure.py -v --tb=short
integration-tests:
name: Script Integration Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Run scripts against examples
run: bash tests/integration/test_scripts_against_examples.sh
- name: Validate example manifests
run: |
for example in polling-hub minimal-sensor push-integration; do
echo "Validating $example..."
python3 scripts/validate-manifest.py \
examples/$example/custom_components/*/manifest.json
done
typescript-tests:
name: TypeScript Tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: plugins/home-assistant-dev/mcp-server
steps:
- uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: plugins/home-assistant-dev/mcp-server/package-lock.json
- name: Install dependencies
run: npm ci
- name: Type check
run: npm run typecheck
- name: Run tests with coverage
run: npm run test:coverage
- name: Build
run: npm run build
structural-validation:
name: Plugin Structure
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Install dependencies
run: pip install pytest pyyaml
- name: Validate plugin structure
run: python3 -m pytest tests/test_plugin_structure.py -v --tb=long
- name: Validate skill frontmatter
run: |
for skill in skills/*/SKILL.md; do
head -1 "$skill" | grep -q '^---' || { echo "FAIL: $skill missing frontmatter"; exit 1; }
done
echo "All skill frontmatters valid"
- name: Validate hooks.json
run: python3 -c "import json; json.load(open('hooks/hooks.json')); print('hooks.json valid')"
mcp-e2e-tests:
name: MCP E2E Tests (HA Container)
runs-on: ubuntu-latest
# Only run on main branch merges or when explicitly labeled
if: github.ref == 'refs/heads/main' || contains(github.event.pull_request.labels.*.name, 'run-e2e')
services:
homeassistant:
image: ghcr.io/home-assistant/home-assistant:stable
ports:
- 8123:8123
options: >-
--health-cmd "curl -sf http://localhost:8123/ -o /dev/null || exit 1"
--health-interval 5s
--health-timeout 3s
--health-retries 60
--health-start-period 60s
steps:
- uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: '20'
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Install dependencies
run: |
pip install aiohttp
cd mcp-server && npm ci
- name: Write HA configuration
run: |
# The HA service container needs configuration
# Since we can't easily mount files, use the API after onboarding
echo "HA container starting..."
- name: Complete HA onboarding
run: |
set -e
HA_BASE="http://localhost:8123"
# Wait for HA to be fully ready (healthcheck may pass before onboarding is available)
for i in $(seq 1 30); do
if curl -sf "$HA_BASE/api/onboarding/users" -X POST \
-H "Content-Type: application/json" \
-d '{"client_id":"'"$HA_BASE"'/","name":"Test","username":"test","password":"test1234","language":"en"}' \
> /tmp/ha-onboard.json 2>/dev/null; then
break
fi
echo "Waiting for onboarding endpoint... ($i/30)"
sleep 5
done
AUTH_CODE=$(python3 -c "import json; print(json.load(open('/tmp/ha-onboard.json'))['auth_code'])")
curl -sf -X POST "$HA_BASE/auth/token" \
-d "grant_type=authorization_code&code=$AUTH_CODE&client_id=$HA_BASE/" \
> /tmp/ha-tokens.json
ACCESS_TOKEN=$(python3 -c "import json; print(json.load(open('/tmp/ha-tokens.json'))['access_token'])")
curl -sf -X POST "$HA_BASE/api/onboarding/core_config" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" -d '{}'
curl -sf -X POST "$HA_BASE/api/onboarding/analytics" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" -d '{}'
curl -sf -X POST "$HA_BASE/api/onboarding/integration" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"client_id":"'"$HA_BASE"'/","redirect_uri":"'"$HA_BASE"'/"}'
# Create LLAT via WebSocket
LLAT=$(python3 << 'PYEOF'
import asyncio, aiohttp, json
async def create_llat():
async with aiohttp.ClientSession() as session:
async with session.ws_connect("ws://localhost:8123/api/websocket") as ws:
await ws.receive_json()
token = json.load(open("/tmp/ha-tokens.json"))["access_token"]
await ws.send_json({"type": "auth", "access_token": token})
await ws.receive_json()
await ws.send_json({
"id": 1, "type": "auth/long_lived_access_token",
"client_name": "CI Test", "lifespan": 1
})
msg = await ws.receive_json()
print(msg["result"])
asyncio.run(create_llat())
PYEOF
)
# Write MCP config
mkdir -p ~/.config/ha-dev-mcp
cat > ~/.config/ha-dev-mcp/config.json << EOF
{
"homeAssistant": { "url": "$HA_BASE", "token": "$LLAT" },
"safety": {
"allowServiceCalls": true, "requireDryRun": false,
"blockedServices": ["homeassistant.restart","homeassistant.stop"]
},
"features": { "docs": true, "validation": true }
}
EOF
echo "Onboarding complete. HA version:"
curl -sf "$HA_BASE/api/config" -H "Authorization: Bearer $LLAT" | python3 -c "import sys,json; print(json.load(sys.stdin)['version'])"
- name: Configure demo integration
run: |
set -e
HA_BASE="http://localhost:8123"
TOKEN=$(python3 -c "import json,os; c=json.load(open(os.path.expanduser('~/.config/ha-dev-mcp/config.json'))); print(c['homeAssistant']['token'])")
# Initiate demo config flow — capture response body and HTTP status for diagnostics
HTTP_STATUS=$(curl -s -o /tmp/demo_flow.json -w "%{http_code}" \
-X POST "$HA_BASE/api/config/config_entries/flow" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"handler":"demo"}')
echo "Config flow HTTP $HTTP_STATUS:"
cat /tmp/demo_flow.json && echo ""
if [ "$HTTP_STATUS" -lt 200 ] || [ "$HTTP_STATUS" -ge 300 ]; then
echo "ERROR: Failed to initiate demo config flow (HTTP $HTTP_STATUS)"
exit 1
fi
FLOW_ID=$(python3 -c "import json; print(json.load(open('/tmp/demo_flow.json'))['flow_id'])")
echo "Flow ID: $FLOW_ID"
# Complete the flow (demo requires no user input)
HTTP_STATUS2=$(curl -s -o /tmp/demo_result.json -w "%{http_code}" \
-X POST "$HA_BASE/api/config/config_entries/flow/$FLOW_ID" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{}')
echo "Flow completion HTTP $HTTP_STATUS2:"
cat /tmp/demo_result.json && echo ""
python3 -c "import json; r=json.load(open('/tmp/demo_result.json')); print(f'Demo setup result: {r.get(\"type\", \"unknown\")}')"
- name: Build MCP server
run: cd mcp-server && npx tsc
- name: Wait for demo entities
run: sleep 30
- name: Run REST API tests
run: node tests/e2e/test-mcp-rest.mjs
- name: Run WebSocket tests
run: node tests/e2e/test-mcp-websocket.mjs