-
Notifications
You must be signed in to change notification settings - Fork 1
445 lines (395 loc) · 19.4 KB
/
Copy pathci.yml
File metadata and controls
445 lines (395 loc) · 19.4 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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
name: CI
on:
workflow_dispatch:
push:
branches: [main, master]
paths:
- 'src/**'
- 'tests/**'
- 'packages/**'
- 'examples/**'
- 'bun.lockb'
- 'tsconfig*.json'
- '.github/workflows/ci.yml'
pull_request:
branches: [main, master]
paths:
- 'src/**'
- 'tests/**'
- 'packages/**'
- 'examples/**'
- 'bun.lockb'
- 'tsconfig*.json'
- '.github/workflows/ci.yml'
jobs:
build:
runs-on: ubuntu-24.04
services:
postgres:
image: postgres:17-alpine
ports:
- 15432:5432
env:
POSTGRES_USER: noorm_test
POSTGRES_PASSWORD: noorm_test
POSTGRES_DB: noorm_test
options: >-
--health-cmd "pg_isready -U noorm_test"
--health-interval 5s
--health-timeout 5s
--health-retries 5
mysql:
image: mysql:8.0
ports:
- 13306:3306
env:
MYSQL_ROOT_PASSWORD: noorm_test
MYSQL_DATABASE: noorm_test
MYSQL_USER: noorm_test
MYSQL_PASSWORD: noorm_test
options: >-
--health-cmd "mysqladmin ping -h localhost"
--health-interval 5s
--health-timeout 5s
--health-retries 5
mssql:
image: mcr.microsoft.com/mssql/server:2022-latest
ports:
- 11433:1433
env:
ACCEPT_EULA: 'Y'
SA_PASSWORD: 'NoOrm_Test123!'
MSSQL_PID: Developer
options: >-
--health-cmd "/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P 'NoOrm_Test123!' -C -Q 'SELECT 1' || exit 1"
--health-interval 10s
--health-timeout 5s
--health-retries 10
--health-start-period 30s
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '24'
- uses: oven-sh/setup-bun@v2
with:
bun-version: '1.3.11'
- name: Create PostgreSQL dest database and deploy schema
run: |
PG_CTR=$(docker ps -q --filter "ancestor=postgres:17-alpine")
docker exec "$PG_CTR" psql -U noorm_test -c "CREATE DATABASE noorm_test_dest;" 2>/dev/null || true
for f in tests/fixtures/sql/postgres/001_tables.sql tests/fixtures/sql/postgres/002_views.sql; do
docker cp "$f" "$PG_CTR:/tmp/$(basename $f)"
docker exec "$PG_CTR" psql -U noorm_test -d noorm_test_dest -f "/tmp/$(basename $f)"
done
- name: Create MySQL dest database
run: |
docker exec $(docker ps -q --filter "ancestor=mysql:8.0") \
mysql -uroot -pnoorm_test -e "CREATE DATABASE IF NOT EXISTS noorm_test_dest;"
docker exec $(docker ps -q --filter "ancestor=mysql:8.0") \
mysql -uroot -pnoorm_test -e "GRANT ALL ON noorm_test_dest.* TO 'noorm_test'@'%';"
- name: Create MSSQL test databases
run: |
docker exec $(docker ps -q --filter "ancestor=mcr.microsoft.com/mssql/server:2022-latest") \
/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P 'NoOrm_Test123!' -C \
-Q "IF NOT EXISTS (SELECT name FROM sys.databases WHERE name = 'noorm_test') CREATE DATABASE [noorm_test]; IF NOT EXISTS (SELECT name FROM sys.databases WHERE name = 'noorm_test_dest') CREATE DATABASE [noorm_test_dest];"
- run: bun install --frozen-lockfile
- run: bun run lint
- run: bun run typecheck
- run: bun run build
# Split test runs to prevent cross-contamination from mock.module
# Tests using mock.module run separately from those that don't
#
# TODO: Remove this split once the runner image regression is resolved.
# GitHub Actions runner ubuntu24/20260406.80 introduced PG connection
# state corruption when transfer tests run in the same bun process as
# the full core suite. Transfer tests pass in isolation. Investigate
# root cause (likely bun test beforeAll error handling or PG pool
# lifecycle change) and reunify into a single "Run core tests" step.
# See: https://github.com/actions/runner-images/releases/tag/ubuntu24%2F20260406.80
- name: Run core tests (non-transfer)
env:
CI: 'false'
FORCE_COLOR: 'true'
run: |
bun test --serial $(find tests/utils tests/core tests/sdk -name '*.test.ts' | grep -v tests/core/transfer | sort | tr '\n' ' ')
- name: Run transfer tests (isolated)
env:
CI: 'false'
FORCE_COLOR: 'true'
run: bun test --serial tests/core/transfer
- name: Run CLI tests
env:
CI: 'false'
FORCE_COLOR: 'true'
run: bun test --serial tests/cli
- name: Run integration tests
env:
CI: 'false'
FORCE_COLOR: 'true'
run: bun test --serial tests/integration
# ───────────────────────────────────────────────────────────────────
# examples/todo-db is a reference CI target: a real Postgres schema
# with soft-deletes, JSONB, TVFs, transactional SPs, cron/feature-flag
# seeds, and an SDK-driven test suite that asserts on the resulting
# state. This job treats it as a stress test for CLI ↔ SDK
# coordination — each `noorm ci` / `noorm db` / `noorm change` step
# below is exactly what an operator would type inside a real pipeline
# that has no access to an operator keychain.
#
# The SDK integration tests run last with NOORM_TEST_PREBUILT=1, which
# tells the test harness to skip its own local bootstrap path and
# instead connect to the database state produced by the steps above.
# That's the coordination we actually care about: can the SDK
# transparently consume state generated by the CLI in a CI session?
# ───────────────────────────────────────────────────────────────────
example-todo-db:
runs-on: ubuntu-24.04
needs: build
services:
postgres:
image: postgres:17-alpine
ports:
- 15432:5432
env:
POSTGRES_USER: noorm_test
POSTGRES_PASSWORD: noorm_test
POSTGRES_DB: noorm_test
options: >-
--health-cmd "pg_isready -U noorm_test"
--health-interval 5s
--health-timeout 5s
--health-retries 5
# Job-level env is visible to every step. NOORM_CONNECTION_* is
# read by both the CLI (during ci init / db create / db reset /
# change ff) and the SDK (during createContext), so setting it
# once here keeps the bootstrap steps flag-free. NOORM_name /
# NOORM_type / NOORM_isTest are mixed-case on purpose — the
# config loader only lowercases all-caps keys, so these land
# onto config.name / config.type / config.isTest as written.
env:
NOORM_CONNECTION_DIALECT: postgres
NOORM_CONNECTION_HOST: localhost
NOORM_CONNECTION_PORT: '15432'
NOORM_CONNECTION_USER: noorm_test
NOORM_CONNECTION_PASSWORD: noorm_test
NOORM_CONNECTION_DATABASE: todo_db_example_test
NOORM_name: todo_db_example_test
NOORM_type: remote
NOORM_isTest: 'true'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '24'
- uses: oven-sh/setup-bun@v2
with:
bun-version: '1.3.11'
- run: bun install --frozen-lockfile
# Builds packages/cli/dist/index.js + packages/sdk/dist/index.js
# via tsup. The wrapper below execs the CLI bundle; the tests
# import the SDK bundle as @noormdev/sdk (workspace link).
- run: bun run build:packages
- name: Expose `noorm` CLI on PATH
run: |
BIN_DIR="$GITHUB_WORKSPACE/.ci-bin"
mkdir -p "$BIN_DIR"
cat > "$BIN_DIR/noorm" <<EOF
#!/usr/bin/env bash
exec node "$GITHUB_WORKSPACE/packages/cli/dist/index.js" "\$@"
EOF
chmod +x "$BIN_DIR/noorm"
echo "$BIN_DIR" >> $GITHUB_PATH
# ────────────────────────────────────────────────────────────
# Bootstrap the example project the way a real CI pipeline
# would. Every step below runs from examples/todo-db/ so the
# CLI discovers the committed .noorm/settings.yml + sql/ +
# changes/ and operates against the example's project root.
# ────────────────────────────────────────────────────────────
- name: noorm ci identity new — mint ephemeral keypair
working-directory: examples/todo-db
run: |
OUT=$(noorm ci identity new \
--name todo-db-ci \
--email ci@noorm.local \
--json)
PRIV=$(echo "$OUT" | jq -r '.data.privateKey // .privateKey')
# Mask the key in any subsequent log output, then export
# NOORM_IDENTITY_* so every later step (ci init, db *,
# change ff, bun test) can decrypt state.enc.
echo "::add-mask::$PRIV"
echo "NOORM_IDENTITY_PRIVATE_KEY=$PRIV" >> "$GITHUB_ENV"
echo "NOORM_IDENTITY_NAME=todo-db-ci" >> "$GITHUB_ENV"
echo "NOORM_IDENTITY_EMAIL=ci@noorm.local" >> "$GITHUB_ENV"
- name: noorm ci init — bootstrap state.enc from env
working-directory: examples/todo-db
run: noorm ci init --name todo_db_example_test --force --json
- name: noorm db create — create target database
working-directory: examples/todo-db
run: noorm db create --json
- name: noorm db reset — teardown + rebuild schema + seeds
working-directory: examples/todo-db
run: noorm db reset --yes --json
- name: noorm change ff — apply forward changes
working-directory: examples/todo-db
run: noorm change ff --yes --json
# ────────────────────────────────────────────────────────────
# SDK side. NOORM_TEST_PREBUILT=1 tells the test harness to
# skip its tmp/ bootstrap and connect the SDK directly against
# the state the steps above just produced. Any failure here is
# a CLI↔SDK coordination failure, not a test-fixture bug.
# ────────────────────────────────────────────────────────────
- name: Run SDK integration tests against prebuilt schema
working-directory: examples/todo-db
env:
CI: 'false'
FORCE_COLOR: 'true'
NOORM_TEST_PREBUILT: '1'
run: bun test
# ───────────────────────────────────────────────────────────────────
# examples/llm-memory-db-mssql is a second e2e target: a 38-table
# LLM-memory schema on SQL Server 2022 that exercises the
# MSSQL-specific surface — table-valued parameters, schema-bound
# validators, role-scoped views, named-procedure calls — plus a
# meta-test that drives `noorm mcp serve` end-to-end. Same shape as
# example-todo-db: bootstrap state.enc with `noorm ci`, build the
# schema, apply the committed change, then run the SDK suite.
#
# Two notable deviations from the todo-db pattern:
#
# 1. We use `noorm run build` instead of `noorm db reset` because
# schema-bound validator UDFs in `sql/03_validators/` lock the
# tables they reference, blocking the teardown step (gap #5 in
# examples/llm-memory-db-mssql/mssql-problems.md).
#
# 2. The test bootstrap is `config: 'test'` with `requireTest: true`,
# so the CI config must be named `test` and carry isTest=true.
# ───────────────────────────────────────────────────────────────────
example-llm-memory-db-mssql:
runs-on: ubuntu-24.04
needs: build
services:
mssql:
image: mcr.microsoft.com/mssql/server:2022-latest
ports:
- 11433:1433
env:
ACCEPT_EULA: 'Y'
SA_PASSWORD: 'NoOrm_Test123!'
MSSQL_PID: Developer
options: >-
--health-cmd "/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P 'NoOrm_Test123!' -C -Q 'SELECT 1' || exit 1"
--health-interval 10s
--health-timeout 5s
--health-retries 10
--health-start-period 30s
# Job-level env shared by every CLI step + the SDK test process.
# NOORM_name=test + NOORM_isTest=true line up with the
# `config: 'test', requireTest: true` call in
# examples/llm-memory-db-mssql/tests/helpers/test-context.ts.
env:
NOORM_CONNECTION_DIALECT: mssql
NOORM_CONNECTION_HOST: localhost
NOORM_CONNECTION_PORT: '11433'
NOORM_CONNECTION_USER: SA
NOORM_CONNECTION_PASSWORD: 'NoOrm_Test123!'
NOORM_CONNECTION_DATABASE: noorm_llm_test
NOORM_name: test
NOORM_type: remote
NOORM_isTest: 'true'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '24'
- uses: oven-sh/setup-bun@v2
with:
bun-version: '1.3.11'
- run: bun install --frozen-lockfile
- run: bun run build:packages
- name: Expose `noorm` CLI on PATH
run: |
BIN_DIR="$GITHUB_WORKSPACE/.ci-bin"
mkdir -p "$BIN_DIR"
cat > "$BIN_DIR/noorm" <<EOF
#!/usr/bin/env bash
exec node "$GITHUB_WORKSPACE/packages/cli/dist/index.js" "\$@"
EOF
chmod +x "$BIN_DIR/noorm"
echo "$BIN_DIR" >> $GITHUB_PATH
- name: noorm ci identity new — mint ephemeral keypair
working-directory: examples/llm-memory-db-mssql
run: |
OUT=$(noorm ci identity new \
--name llm-memory-db-mssql-ci \
--email ci@noorm.local \
--json)
PRIV=$(echo "$OUT" | jq -r '.data.privateKey // .privateKey')
echo "::add-mask::$PRIV"
echo "NOORM_IDENTITY_PRIVATE_KEY=$PRIV" >> "$GITHUB_ENV"
echo "NOORM_IDENTITY_NAME=llm-memory-db-mssql-ci" >> "$GITHUB_ENV"
echo "NOORM_IDENTITY_EMAIL=ci@noorm.local" >> "$GITHUB_ENV"
- name: noorm ci init — bootstrap state.enc from env
working-directory: examples/llm-memory-db-mssql
run: noorm ci init --name test --force --json
- name: noorm db create — create target database
working-directory: examples/llm-memory-db-mssql
run: noorm db create --json
- name: noorm run build — build schema (types, tables, validators, views, procs)
working-directory: examples/llm-memory-db-mssql
run: noorm run build --json
- name: noorm change ff — apply forward changes
working-directory: examples/llm-memory-db-mssql
run: noorm change ff --yes --json
- name: Typecheck example
working-directory: examples/llm-memory-db-mssql
run: bun run typecheck
- name: Run example test suite
working-directory: examples/llm-memory-db-mssql
env:
CI: 'false'
FORCE_COLOR: 'true'
run: bun test
cli-e2e:
runs-on: ubuntu-24.04
needs: build
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '24'
- uses: oven-sh/setup-bun@v2
with:
bun-version: '1.3.11'
- run: bun install --frozen-lockfile
- run: bun run build
# Test: Valid SQL should build successfully (exit 0)
- name: Test valid SQL build
env:
NOORM_CONNECTION_DIALECT: sqlite
NOORM_CONNECTION_DATABASE: ./tmp/ci-success.db
NOORM_PATHS_SQL: ./tests/fixtures/ci/success/sql
NOORM_IDENTITY: ci
run: |
mkdir -p ./tmp
node dist/cli/index.js -H run build
echo "Success: Valid SQL built successfully"
# Test: Invalid SQL should fail (exit 2)
- name: Test invalid SQL build (expect failure)
env:
NOORM_CONNECTION_DIALECT: sqlite
NOORM_CONNECTION_DATABASE: ./tmp/ci-failure.db
NOORM_PATHS_SQL: ./tests/fixtures/ci/failure/sql
NOORM_IDENTITY: ci
run: |
mkdir -p ./tmp
set +e
node dist/cli/index.js -H run build
EXIT_CODE=$?
set -e
if [ $EXIT_CODE -eq 2 ]; then
echo "Success: CLI correctly returned exit code 2 for failed build"
else
echo "Failure: Expected exit code 2, got $EXIT_CODE"
exit 1
fi