@supatype/cli 0.1.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-test.log +221 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/assets/supatype-logo-wordmark.ascii.txt +6 -0
- package/bin/dev-entry.ts +2 -0
- package/bin/supatype.js +5 -0
- package/dist/app/framework.d.ts +44 -0
- package/dist/app/framework.d.ts.map +1 -0
- package/dist/app/framework.js +200 -0
- package/dist/app/framework.js.map +1 -0
- package/dist/app/proxy-dev-app.d.ts +13 -0
- package/dist/app/proxy-dev-app.d.ts.map +1 -0
- package/dist/app/proxy-dev-app.js +54 -0
- package/dist/app/proxy-dev-app.js.map +1 -0
- package/dist/app-config.d.ts +7 -0
- package/dist/app-config.d.ts.map +1 -0
- package/dist/app-config.js +113 -0
- package/dist/app-config.js.map +1 -0
- package/dist/assets/supatype-logo-wordmark.ascii.txt +6 -0
- package/dist/augmentation-generator.d.ts +2 -0
- package/dist/augmentation-generator.d.ts.map +1 -0
- package/dist/augmentation-generator.js +111 -0
- package/dist/augmentation-generator.js.map +1 -0
- package/dist/binary-cache.d.ts +98 -0
- package/dist/binary-cache.d.ts.map +1 -0
- package/dist/binary-cache.js +687 -0
- package/dist/binary-cache.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +61 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/admin.d.ts +4 -0
- package/dist/commands/admin.d.ts.map +1 -0
- package/dist/commands/admin.js +271 -0
- package/dist/commands/admin.js.map +1 -0
- package/dist/commands/app.d.ts +3 -0
- package/dist/commands/app.d.ts.map +1 -0
- package/dist/commands/app.js +82 -0
- package/dist/commands/app.js.map +1 -0
- package/dist/commands/cache.d.ts +6 -0
- package/dist/commands/cache.d.ts.map +1 -0
- package/dist/commands/cache.js +105 -0
- package/dist/commands/cache.js.map +1 -0
- package/dist/commands/cloud.d.ts +23 -0
- package/dist/commands/cloud.d.ts.map +1 -0
- package/dist/commands/cloud.js +254 -0
- package/dist/commands/cloud.js.map +1 -0
- package/dist/commands/db.d.ts +8 -0
- package/dist/commands/db.d.ts.map +1 -0
- package/dist/commands/db.js +116 -0
- package/dist/commands/db.js.map +1 -0
- package/dist/commands/deploy-types.d.ts +14 -0
- package/dist/commands/deploy-types.d.ts.map +1 -0
- package/dist/commands/deploy-types.js +38 -0
- package/dist/commands/deploy-types.js.map +1 -0
- package/dist/commands/deploy.d.ts +15 -0
- package/dist/commands/deploy.d.ts.map +1 -0
- package/dist/commands/deploy.js +322 -0
- package/dist/commands/deploy.js.map +1 -0
- package/dist/commands/dev.d.ts +14 -0
- package/dist/commands/dev.d.ts.map +1 -0
- package/dist/commands/dev.js +806 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/diff.d.ts +3 -0
- package/dist/commands/diff.d.ts.map +1 -0
- package/dist/commands/diff.js +54 -0
- package/dist/commands/diff.js.map +1 -0
- package/dist/commands/engine.d.ts +7 -0
- package/dist/commands/engine.d.ts.map +1 -0
- package/dist/commands/engine.js +27 -0
- package/dist/commands/engine.js.map +1 -0
- package/dist/commands/functions.d.ts +3 -0
- package/dist/commands/functions.d.ts.map +1 -0
- package/dist/commands/functions.js +749 -0
- package/dist/commands/functions.js.map +1 -0
- package/dist/commands/generate.d.ts +3 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +38 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/init.d.ts +7 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +228 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/keys.d.ts +4 -0
- package/dist/commands/keys.d.ts.map +1 -0
- package/dist/commands/keys.js +57 -0
- package/dist/commands/keys.js.map +1 -0
- package/dist/commands/logs.d.ts +6 -0
- package/dist/commands/logs.d.ts.map +1 -0
- package/dist/commands/logs.js +52 -0
- package/dist/commands/logs.js.map +1 -0
- package/dist/commands/migrate-from-v1.d.ts +5 -0
- package/dist/commands/migrate-from-v1.d.ts.map +1 -0
- package/dist/commands/migrate-from-v1.js +125 -0
- package/dist/commands/migrate-from-v1.js.map +1 -0
- package/dist/commands/migrate.d.ts +3 -0
- package/dist/commands/migrate.d.ts.map +1 -0
- package/dist/commands/migrate.js +75 -0
- package/dist/commands/migrate.js.map +1 -0
- package/dist/commands/pg.d.ts +8 -0
- package/dist/commands/pg.d.ts.map +1 -0
- package/dist/commands/pg.js +102 -0
- package/dist/commands/pg.js.map +1 -0
- package/dist/commands/plugins.d.ts +3 -0
- package/dist/commands/plugins.d.ts.map +1 -0
- package/dist/commands/plugins.js +431 -0
- package/dist/commands/plugins.js.map +1 -0
- package/dist/commands/pull.d.ts +3 -0
- package/dist/commands/pull.d.ts.map +1 -0
- package/dist/commands/pull.js +12 -0
- package/dist/commands/pull.js.map +1 -0
- package/dist/commands/push.d.ts +3 -0
- package/dist/commands/push.d.ts.map +1 -0
- package/dist/commands/push.js +179 -0
- package/dist/commands/push.js.map +1 -0
- package/dist/commands/seed.d.ts +5 -0
- package/dist/commands/seed.d.ts.map +1 -0
- package/dist/commands/seed.js +55 -0
- package/dist/commands/seed.js.map +1 -0
- package/dist/commands/self-host.d.ts +9 -0
- package/dist/commands/self-host.d.ts.map +1 -0
- package/dist/commands/self-host.js +310 -0
- package/dist/commands/self-host.js.map +1 -0
- package/dist/commands/self-update.d.ts +9 -0
- package/dist/commands/self-update.d.ts.map +1 -0
- package/dist/commands/self-update.js +33 -0
- package/dist/commands/self-update.js.map +1 -0
- package/dist/commands/status.d.ts +6 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +70 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/types.d.ts +3 -0
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/commands/types.js +62 -0
- package/dist/commands/types.js.map +1 -0
- package/dist/commands/update.d.ts +7 -0
- package/dist/commands/update.d.ts.map +1 -0
- package/dist/commands/update.js +118 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/components.d.ts +5 -0
- package/dist/components.d.ts.map +1 -0
- package/dist/components.js +3 -0
- package/dist/components.js.map +1 -0
- package/dist/config.d.ts +65 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +134 -0
- package/dist/config.js.map +1 -0
- package/dist/dev-compose.d.ts +19 -0
- package/dist/dev-compose.d.ts.map +1 -0
- package/dist/dev-compose.js +468 -0
- package/dist/dev-compose.js.map +1 -0
- package/dist/dev-log-bus.d.ts +30 -0
- package/dist/dev-log-bus.d.ts.map +1 -0
- package/dist/dev-log-bus.js +87 -0
- package/dist/dev-log-bus.js.map +1 -0
- package/dist/dev-log-filter.d.ts +10 -0
- package/dist/dev-log-filter.d.ts.map +1 -0
- package/dist/dev-log-filter.js +36 -0
- package/dist/dev-log-filter.js.map +1 -0
- package/dist/dev-logo.d.ts +12 -0
- package/dist/dev-logo.d.ts.map +1 -0
- package/dist/dev-logo.js +57 -0
- package/dist/dev-logo.js.map +1 -0
- package/dist/dev-session.d.ts +26 -0
- package/dist/dev-session.d.ts.map +1 -0
- package/dist/dev-session.js +106 -0
- package/dist/dev-session.js.map +1 -0
- package/dist/dev-shutdown.d.ts +9 -0
- package/dist/dev-shutdown.d.ts.map +1 -0
- package/dist/dev-shutdown.js +50 -0
- package/dist/dev-shutdown.js.map +1 -0
- package/dist/dev-task-colors.d.ts +14 -0
- package/dist/dev-task-colors.d.ts.map +1 -0
- package/dist/dev-task-colors.js +44 -0
- package/dist/dev-task-colors.js.map +1 -0
- package/dist/dev-tui.d.ts +24 -0
- package/dist/dev-tui.d.ts.map +1 -0
- package/dist/dev-tui.js +188 -0
- package/dist/dev-tui.js.map +1 -0
- package/dist/diff-output.d.ts +4 -0
- package/dist/diff-output.d.ts.map +1 -0
- package/dist/diff-output.js +12 -0
- package/dist/diff-output.js.map +1 -0
- package/dist/docker-postgres.d.ts +57 -0
- package/dist/docker-postgres.d.ts.map +1 -0
- package/dist/docker-postgres.js +208 -0
- package/dist/docker-postgres.js.map +1 -0
- package/dist/engine-client.d.ts +69 -0
- package/dist/engine-client.d.ts.map +1 -0
- package/dist/engine-client.js +157 -0
- package/dist/engine-client.js.map +1 -0
- package/dist/engine-push-output.d.ts +16 -0
- package/dist/engine-push-output.d.ts.map +1 -0
- package/dist/engine-push-output.js +61 -0
- package/dist/engine-push-output.js.map +1 -0
- package/dist/ensure-binary.d.ts +7 -0
- package/dist/ensure-binary.d.ts.map +1 -0
- package/dist/ensure-binary.js +17 -0
- package/dist/ensure-binary.js.map +1 -0
- package/dist/functions-router-gen.d.ts +14 -0
- package/dist/functions-router-gen.d.ts.map +1 -0
- package/dist/functions-router-gen.js +199 -0
- package/dist/functions-router-gen.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/jwt.d.ts +3 -0
- package/dist/jwt.d.ts.map +1 -0
- package/dist/jwt.js +13 -0
- package/dist/jwt.js.map +1 -0
- package/dist/kong-config.d.ts +25 -0
- package/dist/kong-config.d.ts.map +1 -0
- package/dist/kong-config.js +71 -0
- package/dist/kong-config.js.map +1 -0
- package/dist/local-gateway.d.ts +7 -0
- package/dist/local-gateway.d.ts.map +1 -0
- package/dist/local-gateway.js +9 -0
- package/dist/local-gateway.js.map +1 -0
- package/dist/local-storage.d.ts +8 -0
- package/dist/local-storage.d.ts.map +1 -0
- package/dist/local-storage.js +14 -0
- package/dist/local-storage.js.map +1 -0
- package/dist/pgbouncer-userlist.d.ts +5 -0
- package/dist/pgbouncer-userlist.d.ts.map +1 -0
- package/dist/pgbouncer-userlist.js +14 -0
- package/dist/pgbouncer-userlist.js.map +1 -0
- package/dist/postgres-ctl.d.ts +44 -0
- package/dist/postgres-ctl.d.ts.map +1 -0
- package/dist/postgres-ctl.js +137 -0
- package/dist/postgres-ctl.js.map +1 -0
- package/dist/process-manager.d.ts +49 -0
- package/dist/process-manager.d.ts.map +1 -0
- package/dist/process-manager.js +177 -0
- package/dist/process-manager.js.map +1 -0
- package/dist/project-config.d.ts +238 -0
- package/dist/project-config.d.ts.map +1 -0
- package/dist/project-config.js +159 -0
- package/dist/project-config.js.map +1 -0
- package/dist/pull-utils.d.ts +31 -0
- package/dist/pull-utils.d.ts.map +1 -0
- package/dist/pull-utils.js +77 -0
- package/dist/pull-utils.js.map +1 -0
- package/dist/release-pins.d.ts +7 -0
- package/dist/release-pins.d.ts.map +1 -0
- package/dist/release-pins.js +27 -0
- package/dist/release-pins.js.map +1 -0
- package/dist/release-public-key.d.ts +8 -0
- package/dist/release-public-key.d.ts.map +1 -0
- package/dist/release-public-key.js +13 -0
- package/dist/release-public-key.js.map +1 -0
- package/dist/restore-system-relation-targets.d.ts +3 -0
- package/dist/restore-system-relation-targets.d.ts.map +1 -0
- package/dist/restore-system-relation-targets.js +45 -0
- package/dist/restore-system-relation-targets.js.map +1 -0
- package/dist/runtime-routes.d.ts +34 -0
- package/dist/runtime-routes.d.ts.map +1 -0
- package/dist/runtime-routes.js +252 -0
- package/dist/runtime-routes.js.map +1 -0
- package/dist/schema-ast-v2.d.ts +127 -0
- package/dist/schema-ast-v2.d.ts.map +1 -0
- package/dist/schema-ast-v2.js +226 -0
- package/dist/schema-ast-v2.js.map +1 -0
- package/dist/scripts/postinstall.d.ts +11 -0
- package/dist/scripts/postinstall.d.ts.map +1 -0
- package/dist/scripts/postinstall.js +47 -0
- package/dist/scripts/postinstall.js.map +1 -0
- package/dist/seed.d.ts +8 -0
- package/dist/seed.d.ts.map +1 -0
- package/dist/seed.js +32 -0
- package/dist/seed.js.map +1 -0
- package/dist/self-host-compose.d.ts +43 -0
- package/dist/self-host-compose.d.ts.map +1 -0
- package/dist/self-host-compose.js +400 -0
- package/dist/self-host-compose.js.map +1 -0
- package/dist/storage-provision.d.ts +24 -0
- package/dist/storage-provision.d.ts.map +1 -0
- package/dist/storage-provision.js +44 -0
- package/dist/storage-provision.js.map +1 -0
- package/dist/studio-admin-roles.d.ts +7 -0
- package/dist/studio-admin-roles.d.ts.map +1 -0
- package/dist/studio-admin-roles.js +14 -0
- package/dist/studio-admin-roles.js.map +1 -0
- package/dist/studio-dev-server.d.ts +22 -0
- package/dist/studio-dev-server.d.ts.map +1 -0
- package/dist/studio-dev-server.js +28 -0
- package/dist/studio-dev-server.js.map +1 -0
- package/dist/supatype-eval-1781522769253.d.mts +2 -0
- package/dist/supatype-eval-1781522769253.d.mts.map +1 -0
- package/dist/supatype-eval-1781522769253.mjs +3 -0
- package/dist/supatype-eval-1781522769253.mjs.map +1 -0
- package/dist/systemd.d.ts +26 -0
- package/dist/systemd.d.ts.map +1 -0
- package/dist/systemd.js +102 -0
- package/dist/systemd.js.map +1 -0
- package/dist/tsx-runner.d.ts +18 -0
- package/dist/tsx-runner.d.ts.map +1 -0
- package/dist/tsx-runner.js +69 -0
- package/dist/tsx-runner.js.map +1 -0
- package/dist/type-extractor.d.ts +4 -0
- package/dist/type-extractor.d.ts.map +1 -0
- package/dist/type-extractor.js +1213 -0
- package/dist/type-extractor.js.map +1 -0
- package/dist/type-resolver.d.ts +33 -0
- package/dist/type-resolver.d.ts.map +1 -0
- package/dist/type-resolver.js +338 -0
- package/dist/type-resolver.js.map +1 -0
- package/package.json +41 -0
- package/releases/deno/VERSION +1 -0
- package/scripts/mirror-deno-release.sh +76 -0
- package/src/TYPE-RESOLUTION.md +294 -0
- package/src/app/framework.ts +249 -0
- package/src/app/proxy-dev-app.ts +68 -0
- package/src/app-config.ts +128 -0
- package/src/augmentation-generator.ts +126 -0
- package/src/binary-cache.ts +845 -0
- package/src/cli.ts +63 -0
- package/src/commands/admin.ts +372 -0
- package/src/commands/app.ts +97 -0
- package/src/commands/cache.ts +117 -0
- package/src/commands/cloud.ts +325 -0
- package/src/commands/db.ts +136 -0
- package/src/commands/deploy-types.ts +49 -0
- package/src/commands/deploy.ts +400 -0
- package/src/commands/dev.ts +1009 -0
- package/src/commands/diff.ts +63 -0
- package/src/commands/engine.ts +30 -0
- package/src/commands/functions.ts +901 -0
- package/src/commands/generate.ts +44 -0
- package/src/commands/init.ts +253 -0
- package/src/commands/keys.ts +66 -0
- package/src/commands/logs.ts +58 -0
- package/src/commands/migrate-from-v1.ts +131 -0
- package/src/commands/migrate.ts +87 -0
- package/src/commands/pg.ts +133 -0
- package/src/commands/plugins.ts +508 -0
- package/src/commands/pull.ts +17 -0
- package/src/commands/push.ts +226 -0
- package/src/commands/seed.ts +68 -0
- package/src/commands/self-host.ts +364 -0
- package/src/commands/self-update.ts +45 -0
- package/src/commands/status.ts +84 -0
- package/src/commands/types.ts +76 -0
- package/src/commands/update.ts +136 -0
- package/src/components.ts +6 -0
- package/src/config.ts +223 -0
- package/src/dev-compose.ts +583 -0
- package/src/dev-log-bus.ts +101 -0
- package/src/dev-log-filter.ts +32 -0
- package/src/dev-logo.ts +62 -0
- package/src/dev-session.ts +130 -0
- package/src/dev-shutdown.ts +54 -0
- package/src/dev-task-colors.ts +47 -0
- package/src/dev-tui.ts +232 -0
- package/src/diff-output.ts +12 -0
- package/src/docker-postgres.ts +295 -0
- package/src/engine-client.ts +236 -0
- package/src/engine-push-output.ts +71 -0
- package/src/ensure-binary.ts +28 -0
- package/src/functions-router-gen.ts +224 -0
- package/src/index.ts +11 -0
- package/src/jwt.ts +14 -0
- package/src/kong-config.ts +93 -0
- package/src/local-gateway.ts +9 -0
- package/src/local-storage.ts +14 -0
- package/src/pgbouncer-userlist.ts +15 -0
- package/src/postgres-ctl.ts +171 -0
- package/src/process-manager.ts +220 -0
- package/src/project-config.ts +388 -0
- package/src/pull-utils.ts +81 -0
- package/src/release-pins.ts +31 -0
- package/src/release-public-key.ts +12 -0
- package/src/restore-system-relation-targets.ts +45 -0
- package/src/runtime-routes.ts +291 -0
- package/src/schema-ast-v2.ts +324 -0
- package/src/scripts/postinstall.ts +51 -0
- package/src/seed.ts +43 -0
- package/src/self-host-compose.ts +452 -0
- package/src/storage-provision.ts +58 -0
- package/src/studio-admin-roles.ts +16 -0
- package/src/studio-dev-server.ts +53 -0
- package/src/supatype-eval-1781522769253.mts +1 -0
- package/src/systemd.ts +137 -0
- package/src/tsx-runner.ts +89 -0
- package/src/type-extractor.ts +1479 -0
- package/src/type-resolver.ts +457 -0
- package/tests/app-command.test.ts +54 -0
- package/tests/augmentation-generator.test.ts +59 -0
- package/tests/binary-cache-cloud-overrides.test.ts +123 -0
- package/tests/cached-artifact-format.test.ts +84 -0
- package/tests/cli-help.test.ts +133 -0
- package/tests/config.test.ts +252 -0
- package/tests/dev-ui.test.ts +139 -0
- package/tests/docker-postgres.test.ts +39 -0
- package/tests/engine-distribution.test.ts +418 -0
- package/tests/engine-push-output.test.ts +67 -0
- package/tests/ensure-binary.test.ts +59 -0
- package/tests/init.test.ts +127 -0
- package/tests/keys.test.ts +160 -0
- package/tests/migrate-from-v1.test.ts +29 -0
- package/tests/normalize-admin-config.test.ts +48 -0
- package/tests/pg-spawn-env.test.ts +18 -0
- package/tests/postgres-archive-tag.test.ts +9 -0
- package/tests/proxy-dev-app.test.ts +33 -0
- package/tests/pull-utils.test.ts +150 -0
- package/tests/release-pins.test.ts +28 -0
- package/tests/runtime-contract.test.ts +370 -0
- package/tests/seed-discover.test.ts +31 -0
- package/tests/studio-admin-roles.test.ts +27 -0
- package/tests/tsconfig.json +9 -0
- package/tests/tsx-runner.test.ts +66 -0
- package/tests/type-extractor.test.ts +985 -0
- package/tests/type-resolver.test.ts +59 -0
- package/tsconfig.json +10 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/vitest.config.ts +12 -0
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest"
|
|
2
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"
|
|
3
|
+
import { join } from "node:path"
|
|
4
|
+
import { tmpdir } from "node:os"
|
|
5
|
+
import { runtimeRouteSpec } from "../src/runtime-routes.js"
|
|
6
|
+
import { buildKongDeclarative } from "../src/kong-config.js"
|
|
7
|
+
import { composeDockerImageEnv, renderSelfHostCompose, writeSelfHostCompose } from "../src/self-host-compose.js"
|
|
8
|
+
import { updateAppConfigInProject } from "../src/app-config.js"
|
|
9
|
+
import type { SupatypeProjectConfig } from "../src/project-config.js"
|
|
10
|
+
import { DENO_RELEASE_PIN } from "../src/release-pins.js"
|
|
11
|
+
|
|
12
|
+
const baseConfig: SupatypeProjectConfig = {
|
|
13
|
+
project: { name: "acme" },
|
|
14
|
+
database: { provider: "docker" },
|
|
15
|
+
server: { mode: "dev" },
|
|
16
|
+
app: { mode: "none" },
|
|
17
|
+
versions: {
|
|
18
|
+
engine: "0.4.2",
|
|
19
|
+
server: "0.1.0",
|
|
20
|
+
postgres: "17.2",
|
|
21
|
+
deno: DENO_RELEASE_PIN,
|
|
22
|
+
},
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe("runtime contract", () => {
|
|
26
|
+
it("includes core route families", () => {
|
|
27
|
+
const paths = runtimeRouteSpec().flatMap((r) => r.paths)
|
|
28
|
+
for (const path of ["/rest/v1/", "/auth/v1/", "/storage/v1/", "/realtime/v1/", "/functions/v1/", "/graphql/v1"]) {
|
|
29
|
+
expect(paths).toContain(path)
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it("renders app root route when upstream is provided", () => {
|
|
34
|
+
const paths = runtimeRouteSpec({ appUpstream: "http://app:3000" }).flatMap((r) => r.paths)
|
|
35
|
+
expect(paths).toContain("/")
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it("renders app root route for static service URL", () => {
|
|
39
|
+
const paths = runtimeRouteSpec({ staticAppServiceUrl: "http://static-app:8080" }).flatMap((r) => r.paths)
|
|
40
|
+
expect(paths).toContain("/")
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it("self-host kong uses unified supatype-server gateway", () => {
|
|
44
|
+
const kong = buildKongDeclarative({ unifiedGateway: true })
|
|
45
|
+
expect(kong).toContain("http://server:9999")
|
|
46
|
+
expect(kong).toContain("/rest/v1/")
|
|
47
|
+
expect(kong).toContain("/auth/v1/")
|
|
48
|
+
expect(kong).toContain("/storage/v1/")
|
|
49
|
+
expect(kong).toContain("/realtime/v1/")
|
|
50
|
+
expect(kong).toContain("/functions/v1/")
|
|
51
|
+
expect(kong).toContain("http://postgrest:3000/rpc/graphql")
|
|
52
|
+
expect(kong).toContain("Content-Profile:graphql_public")
|
|
53
|
+
expect(kong).not.toContain("http://storage:5000")
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it("self-host kong routes studio auth and proxy to supatype-server before static studio", () => {
|
|
57
|
+
const kong = buildKongDeclarative({ unifiedGateway: true })
|
|
58
|
+
const studioAuthIdx = kong.indexOf("/studio/auth/")
|
|
59
|
+
const studioProxyIdx = kong.indexOf("/studio/proxy/")
|
|
60
|
+
const studioStaticIdx = kong.lastIndexOf("/studio/")
|
|
61
|
+
expect(studioAuthIdx).toBeGreaterThan(-1)
|
|
62
|
+
expect(studioProxyIdx).toBeGreaterThan(-1)
|
|
63
|
+
expect(studioAuthIdx).toBeLessThan(studioStaticIdx)
|
|
64
|
+
expect(studioProxyIdx).toBeLessThan(studioStaticIdx)
|
|
65
|
+
expect(kong).toContain("name: supatype-server-studio-auth")
|
|
66
|
+
expect(kong).toContain("name: supatype-server-studio-proxy")
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it("self-host kong proxies exact /studio to studio UI", () => {
|
|
70
|
+
const kong = buildKongDeclarative({ unifiedGateway: true })
|
|
71
|
+
expect(kong).toContain("name: studio-exact")
|
|
72
|
+
expect(kong).toContain("~/studio$")
|
|
73
|
+
expect(kong).not.toContain("name: redirect")
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it("kong declarative output contains route contract paths", () => {
|
|
77
|
+
const kong = buildKongDeclarative({ appUpstream: "http://app:3000" })
|
|
78
|
+
expect(kong).toContain("/rest/v1/")
|
|
79
|
+
expect(kong).toContain("/auth/v1/")
|
|
80
|
+
expect(kong).toContain("/storage/v1/")
|
|
81
|
+
expect(kong).toContain("/realtime/v1/")
|
|
82
|
+
expect(kong).toContain("/functions/v1/")
|
|
83
|
+
expect(kong).toContain("- /")
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it("self-host compose render is deterministic for same config", () => {
|
|
87
|
+
const first = renderSelfHostCompose({ ...baseConfig, app: { mode: "proxy", upstream: "http://app:3000" } })
|
|
88
|
+
const second = renderSelfHostCompose({ ...baseConfig, app: { mode: "proxy", upstream: "http://app:3000" } })
|
|
89
|
+
expect(first).toBe(second)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it("self-host compose does not inject a synthetic app-proxy service", () => {
|
|
93
|
+
const compose = renderSelfHostCompose({ ...baseConfig, app: { mode: "proxy", upstream: "http://app:3000" } })
|
|
94
|
+
expect(compose).not.toContain("ghcr.io/supatype/app-proxy")
|
|
95
|
+
expect(compose).not.toContain("\n app:\n")
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it("self-host compose configures static app on supatype-server", () => {
|
|
99
|
+
const compose = renderSelfHostCompose({ ...baseConfig, app: { mode: "static", static_dir: "./public" } })
|
|
100
|
+
expect(compose).toContain('SUPATYPE_APP_MODE: static')
|
|
101
|
+
expect(compose).toContain("SUPATYPE_APP_STATIC_DIR: /project/public")
|
|
102
|
+
expect(compose).not.toContain("static-app:")
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
it("self-host compose includes schema-engine tools profile", () => {
|
|
106
|
+
const compose = renderSelfHostCompose(baseConfig)
|
|
107
|
+
expect(compose).toContain("\n schema-engine:\n")
|
|
108
|
+
expect(compose).toContain('profiles: ["tools"]')
|
|
109
|
+
expect(compose).toContain("supatype/schema-engine:latest")
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it("composeDockerImageEnv maps pinned versions to SUPATYPE_*_IMAGE", () => {
|
|
113
|
+
expect(composeDockerImageEnv(baseConfig)).toEqual({
|
|
114
|
+
SUPATYPE_ENGINE_IMAGE: "supatype/schema-engine:v0.4.2",
|
|
115
|
+
SUPATYPE_SERVER_IMAGE: "supatype/server:v0.1.0",
|
|
116
|
+
SUPATYPE_POSTGRES_IMAGE: "supatype/postgres:17-latest",
|
|
117
|
+
})
|
|
118
|
+
expect(composeDockerImageEnv({ ...baseConfig, versions: undefined })).toEqual({})
|
|
119
|
+
expect(
|
|
120
|
+
composeDockerImageEnv({
|
|
121
|
+
...baseConfig,
|
|
122
|
+
database: { provider: "docker", image: "supatype/postgres:custom" },
|
|
123
|
+
}),
|
|
124
|
+
).toEqual({
|
|
125
|
+
SUPATYPE_ENGINE_IMAGE: "supatype/schema-engine:v0.4.2",
|
|
126
|
+
SUPATYPE_SERVER_IMAGE: "supatype/server:v0.1.0",
|
|
127
|
+
SUPATYPE_POSTGRES_IMAGE: "supatype/postgres:custom",
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
it("self-host compose mounts project root at /project (project-directory relative)", () => {
|
|
132
|
+
const compose = renderSelfHostCompose(baseConfig)
|
|
133
|
+
expect(compose).toContain("- .:/project")
|
|
134
|
+
expect(compose).not.toMatch(/- \.\.\/\.\.:\/project/)
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
it("self-host compose mounts kong.yml from .supatype/self-host (project-directory relative)", () => {
|
|
138
|
+
const compose = renderSelfHostCompose(baseConfig)
|
|
139
|
+
expect(compose).toContain("- .supatype/self-host/kong.yml:/etc/kong/kong.yml:ro")
|
|
140
|
+
expect(compose).not.toContain("- ./kong.yml:/etc/kong/kong.yml:ro")
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it("devLocal compose omits host-published db and server ports", () => {
|
|
144
|
+
const compose = renderSelfHostCompose(baseConfig, process.cwd(), { devLocal: true })
|
|
145
|
+
expect(compose).not.toContain('"5432:5432"')
|
|
146
|
+
expect(compose).not.toContain('"9999:9999"')
|
|
147
|
+
expect(compose).toContain("${SUPATYPE_KONG_PORT:-18473}:8000")
|
|
148
|
+
expect(compose).not.toContain("SUPATYPE_DEV_DB_PORT")
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
it("devLocal compose publishes db to host when overrides.engine is set", () => {
|
|
152
|
+
const compose = renderSelfHostCompose(
|
|
153
|
+
{ ...baseConfig, overrides: { engine: "/tmp/supatype-engine" } },
|
|
154
|
+
process.cwd(),
|
|
155
|
+
{ devLocal: true },
|
|
156
|
+
)
|
|
157
|
+
expect(compose).toContain("127.0.0.1:${SUPATYPE_DEV_DB_PORT:-54329}:5432")
|
|
158
|
+
expect(compose).not.toContain('"5432:5432"')
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
it("devLocal proxy upstream rewrites localhost to host.docker.internal", () => {
|
|
162
|
+
const compose = renderSelfHostCompose(
|
|
163
|
+
{ ...baseConfig, app: { mode: "proxy", upstream: "http://127.0.0.1:4321" } },
|
|
164
|
+
process.cwd(),
|
|
165
|
+
{ devLocal: true },
|
|
166
|
+
)
|
|
167
|
+
expect(compose).toContain("SUPATYPE_APP_UPSTREAM: http://host.docker.internal:4321")
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
it("devLocal compose omits studio container when overrides.studio is set", () => {
|
|
171
|
+
const compose = renderSelfHostCompose(
|
|
172
|
+
{ ...baseConfig, overrides: { studio: "../supatype/packages/studio" } },
|
|
173
|
+
process.cwd(),
|
|
174
|
+
{ devLocal: true },
|
|
175
|
+
)
|
|
176
|
+
expect(compose).not.toContain("\n studio:\n")
|
|
177
|
+
expect(compose).not.toContain("depends_on:\n - server\n - studio")
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
it("devLocal kong routes studio to host Vite when overrides.studio is set", () => {
|
|
181
|
+
const dir = mkdtempSync(join(tmpdir(), "supatype-studio-host-"))
|
|
182
|
+
try {
|
|
183
|
+
writeSelfHostCompose(
|
|
184
|
+
dir,
|
|
185
|
+
{ ...baseConfig, overrides: { studio: "../supatype/packages/studio" } },
|
|
186
|
+
{ devLocal: true },
|
|
187
|
+
)
|
|
188
|
+
const kong = readFileSync(join(dir, ".supatype", "self-host", "kong.yml"), "utf8")
|
|
189
|
+
expect(kong).toContain("http://host.docker.internal:3002")
|
|
190
|
+
expect(kong).not.toContain("http://studio:3002")
|
|
191
|
+
expect(kong).toContain("strip_path: false")
|
|
192
|
+
} finally {
|
|
193
|
+
rmSync(dir, { recursive: true, force: true })
|
|
194
|
+
}
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
it("devLocal compose enables STUDIO_OPEN_DEV on supatype-server", () => {
|
|
198
|
+
const compose = renderSelfHostCompose(baseConfig, process.cwd(), { devLocal: true })
|
|
199
|
+
expect(compose).toContain('STUDIO_OPEN_DEV: "1"')
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
it("production self-host compose does not enable STUDIO_OPEN_DEV", () => {
|
|
203
|
+
const compose = renderSelfHostCompose(baseConfig)
|
|
204
|
+
expect(compose).not.toContain("STUDIO_OPEN_DEV")
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
it("self-host studio SUPATYPE_CLOUD_JSON omits serviceRoleKey", () => {
|
|
208
|
+
const compose = renderSelfHostCompose(baseConfig)
|
|
209
|
+
const match = compose.match(/SUPATYPE_CLOUD_JSON: '([^']+)'/)
|
|
210
|
+
expect(match).not.toBeNull()
|
|
211
|
+
const parsed = JSON.parse(match![1]!) as Record<string, unknown>
|
|
212
|
+
expect(parsed).toHaveProperty("url")
|
|
213
|
+
expect(parsed).toHaveProperty("anonKey")
|
|
214
|
+
expect(parsed).not.toHaveProperty("serviceRoleKey")
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
it("self-host compose runs per-project functions-worker and proxies via server", () => {
|
|
218
|
+
const compose = renderSelfHostCompose(baseConfig)
|
|
219
|
+
expect(compose).toContain("\n functions-worker:\n")
|
|
220
|
+
expect(compose).toContain("SUPATYPE_FUNCTIONS_WORKER_URL: http://functions-worker:8001")
|
|
221
|
+
expect(compose).toContain("SUPATYPE_FUNCTIONS_ROOT: /project/functions")
|
|
222
|
+
expect(compose).not.toContain("deploy/functions")
|
|
223
|
+
expect(compose).not.toContain("supatype-functions")
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
it("app config updater writes proxy mode intent", () => {
|
|
227
|
+
const dir = mkdtempSync(join(tmpdir(), "supatype-app-config-"))
|
|
228
|
+
try {
|
|
229
|
+
const configPath = join(dir, "supatype.config.ts")
|
|
230
|
+
writeFileSync(
|
|
231
|
+
configPath,
|
|
232
|
+
`export default {
|
|
233
|
+
project: { name: "x" },
|
|
234
|
+
database: { provider: "docker" },
|
|
235
|
+
server: { mode: "dev" },
|
|
236
|
+
app: {
|
|
237
|
+
mode: "none",
|
|
238
|
+
// mode: "static", static_dir: "./dist",
|
|
239
|
+
// mode: "proxy", upstream: "http://localhost:3000",
|
|
240
|
+
},
|
|
241
|
+
versions: { engine: "0", server: "0", postgres: "0", deno: "0" },
|
|
242
|
+
}
|
|
243
|
+
`,
|
|
244
|
+
"utf8",
|
|
245
|
+
)
|
|
246
|
+
updateAppConfigInProject(dir, { mode: "proxy", upstream: "http://localhost:7777" })
|
|
247
|
+
const next = readFileSync(configPath, "utf8")
|
|
248
|
+
expect(next).toContain(`mode: "proxy"`)
|
|
249
|
+
expect(next).toContain(`upstream: "http://localhost:7777"`)
|
|
250
|
+
} finally {
|
|
251
|
+
rmSync(dir, { recursive: true, force: true })
|
|
252
|
+
}
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
it("app config updater handles defineConfig wrappers", () => {
|
|
256
|
+
const dir = mkdtempSync(join(tmpdir(), "supatype-app-config-"))
|
|
257
|
+
try {
|
|
258
|
+
const configPath = join(dir, "supatype.config.ts")
|
|
259
|
+
writeFileSync(
|
|
260
|
+
configPath,
|
|
261
|
+
`import { defineConfig } from "@supatype/cli"
|
|
262
|
+
|
|
263
|
+
export default defineConfig({
|
|
264
|
+
project: { name: "x" },
|
|
265
|
+
database: { provider: "docker" },
|
|
266
|
+
server: { mode: "dev" },
|
|
267
|
+
app: { mode: "none" },
|
|
268
|
+
versions: { engine: "0", server: "0", postgres: "0", deno: "0" },
|
|
269
|
+
})
|
|
270
|
+
`,
|
|
271
|
+
"utf8",
|
|
272
|
+
)
|
|
273
|
+
updateAppConfigInProject(dir, { mode: "static", staticDir: "./site" })
|
|
274
|
+
const next = readFileSync(configPath, "utf8")
|
|
275
|
+
expect(next).toContain(`mode: "static"`)
|
|
276
|
+
expect(next).toContain(`static_dir: "./site"`)
|
|
277
|
+
} finally {
|
|
278
|
+
rmSync(dir, { recursive: true, force: true })
|
|
279
|
+
}
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
it("app config updater inserts app block when missing", () => {
|
|
283
|
+
const dir = mkdtempSync(join(tmpdir(), "supatype-app-config-"))
|
|
284
|
+
try {
|
|
285
|
+
const configPath = join(dir, "supatype.config.ts")
|
|
286
|
+
writeFileSync(
|
|
287
|
+
configPath,
|
|
288
|
+
`export default {
|
|
289
|
+
project: { name: "x" },
|
|
290
|
+
database: { provider: "docker" },
|
|
291
|
+
server: { mode: "dev" },
|
|
292
|
+
versions: { engine: "0", server: "0", postgres: "0", deno: "0" },
|
|
293
|
+
}
|
|
294
|
+
`,
|
|
295
|
+
"utf8",
|
|
296
|
+
)
|
|
297
|
+
updateAppConfigInProject(dir, { mode: "none" })
|
|
298
|
+
const next = readFileSync(configPath, "utf8")
|
|
299
|
+
expect(next).toContain("app:")
|
|
300
|
+
expect(next).toContain(`mode: "none"`)
|
|
301
|
+
} finally {
|
|
302
|
+
rmSync(dir, { recursive: true, force: true })
|
|
303
|
+
}
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
it("app config updater preserves unrelated app keys", () => {
|
|
307
|
+
const dir = mkdtempSync(join(tmpdir(), "supatype-app-config-"))
|
|
308
|
+
try {
|
|
309
|
+
const configPath = join(dir, "supatype.config.ts")
|
|
310
|
+
writeFileSync(
|
|
311
|
+
configPath,
|
|
312
|
+
`export default {
|
|
313
|
+
project: { name: "x" },
|
|
314
|
+
database: { provider: "docker" },
|
|
315
|
+
server: { mode: "dev" },
|
|
316
|
+
app: {
|
|
317
|
+
mode: "proxy",
|
|
318
|
+
upstream: "http://localhost:3000",
|
|
319
|
+
headers: { "x-feature": "on" },
|
|
320
|
+
},
|
|
321
|
+
versions: { engine: "0", server: "0", postgres: "0", deno: "0" },
|
|
322
|
+
}
|
|
323
|
+
`,
|
|
324
|
+
"utf8",
|
|
325
|
+
)
|
|
326
|
+
updateAppConfigInProject(dir, { mode: "proxy", upstream: "http://localhost:8080" })
|
|
327
|
+
const next = readFileSync(configPath, "utf8")
|
|
328
|
+
expect(next).toContain(`upstream: "http://localhost:8080"`)
|
|
329
|
+
expect(next).toContain(`headers`)
|
|
330
|
+
expect(next).toContain(`"x-feature"`)
|
|
331
|
+
} finally {
|
|
332
|
+
rmSync(dir, { recursive: true, force: true })
|
|
333
|
+
}
|
|
334
|
+
})
|
|
335
|
+
|
|
336
|
+
it("writes self-host compose artifacts under .supatype/self-host", () => {
|
|
337
|
+
const dir = mkdtempSync(join(tmpdir(), "supatype-compose-"))
|
|
338
|
+
try {
|
|
339
|
+
const out = writeSelfHostCompose(dir, { ...baseConfig, app: { mode: "none" } })
|
|
340
|
+
expect(out.composePath).toContain(".supatype")
|
|
341
|
+
expect(readFileSync(out.composePath, "utf8")).toContain("services:")
|
|
342
|
+
expect(readFileSync(out.kongPath, "utf8")).toContain("/rest/v1/")
|
|
343
|
+
const compose = readFileSync(out.composePath, "utf8")
|
|
344
|
+
expect(compose).toContain("${SUPATYPE_POSTGRES_IMAGE:-supatype/postgres:latest}")
|
|
345
|
+
expect(compose).toContain("${SUPATYPE_SERVER_IMAGE:-${SUPATYPE_AUTH_IMAGE:-supatype/server:latest}}")
|
|
346
|
+
expect(compose).toContain("${SUPATYPE_STORAGE_IMAGE:-supatype/storage:latest}")
|
|
347
|
+
expect(compose).toContain("${SUPATYPE_STUDIO_IMAGE:-supatype/studio:latest}")
|
|
348
|
+
expect(compose).toContain("SUPATYPE_POSTGREST_URL: http://postgrest:3000")
|
|
349
|
+
expect(compose).toContain("unified gateway")
|
|
350
|
+
const kong = readFileSync(out.kongPath, "utf8")
|
|
351
|
+
expect(kong).toContain("http://server:9999")
|
|
352
|
+
expect(kong).toContain("http://postgrest:3000/rpc/graphql")
|
|
353
|
+
expect(kong).toContain("Content-Profile:graphql_public")
|
|
354
|
+
} finally {
|
|
355
|
+
rmSync(dir, { recursive: true, force: true })
|
|
356
|
+
}
|
|
357
|
+
})
|
|
358
|
+
|
|
359
|
+
it("writes default manifest when missing for compose", () => {
|
|
360
|
+
const dir = mkdtempSync(join(tmpdir(), "supatype-manifest-"))
|
|
361
|
+
try {
|
|
362
|
+
writeSelfHostCompose(dir, { ...baseConfig, app: { mode: "none" } })
|
|
363
|
+
const manifest = readFileSync(join(dir, ".supatype", "manifest.json"), "utf8")
|
|
364
|
+
expect(manifest).toContain("postgrest_url")
|
|
365
|
+
expect(manifest).toContain("http://postgrest:3000")
|
|
366
|
+
} finally {
|
|
367
|
+
rmSync(dir, { recursive: true, force: true })
|
|
368
|
+
}
|
|
369
|
+
})
|
|
370
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from "vitest"
|
|
2
|
+
import { mkdirSync, writeFileSync, rmSync } from "node:fs"
|
|
3
|
+
import { join } from "node:path"
|
|
4
|
+
import { tmpdir } from "node:os"
|
|
5
|
+
import { discoverSeedsDir } from "../src/commands/seed.js"
|
|
6
|
+
|
|
7
|
+
let tmp: string
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
tmp = join(tmpdir(), `supatype-seed-${Date.now()}`)
|
|
10
|
+
mkdirSync(join(tmp, "seeds"), { recursive: true })
|
|
11
|
+
})
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
rmSync(tmp, { recursive: true, force: true })
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
describe("discoverSeedsDir", () => {
|
|
17
|
+
it("returns sorted paths for seeds/*.ts", () => {
|
|
18
|
+
writeFileSync(join(tmp, "seeds", "z_first.ts"), "//")
|
|
19
|
+
writeFileSync(join(tmp, "seeds", "a_second.ts"), "//")
|
|
20
|
+
const paths = discoverSeedsDir(tmp, join(tmp, "seeds"))
|
|
21
|
+
expect(paths.map((p) => p.replace(/\\/g, "/"))).toEqual([
|
|
22
|
+
join(tmp, "seeds", "a_second.ts").replace(/\\/g, "/"),
|
|
23
|
+
join(tmp, "seeds", "z_first.ts").replace(/\\/g, "/"),
|
|
24
|
+
])
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it("returns empty when seeds dir missing", () => {
|
|
28
|
+
const empty = join(tmp, "no-seeds")
|
|
29
|
+
expect(discoverSeedsDir(tmp, empty)).toEqual([])
|
|
30
|
+
})
|
|
31
|
+
})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest"
|
|
2
|
+
import { DEFAULT_STUDIO_ADMIN_ROLES, studioAdminRoles, withAdminRoles } from "../src/studio-admin-roles.js"
|
|
3
|
+
import type { SupatypeProjectConfig } from "../src/project-config.js"
|
|
4
|
+
|
|
5
|
+
const baseConfig: SupatypeProjectConfig = {
|
|
6
|
+
project: { name: "acme" },
|
|
7
|
+
database: { provider: "docker" },
|
|
8
|
+
server: { mode: "dev" },
|
|
9
|
+
app: { mode: "none" },
|
|
10
|
+
versions: { engine: "0", server: "0", postgres: "0", deno: "0" },
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
describe("studioAdminRoles", () => {
|
|
14
|
+
it("returns defaults when admin.roles is omitted", () => {
|
|
15
|
+
expect(studioAdminRoles(baseConfig)).toEqual([...DEFAULT_STUDIO_ADMIN_ROLES])
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it("uses admin.roles from config when set", () => {
|
|
19
|
+
const roles = studioAdminRoles({ ...baseConfig, admin: { roles: ["custom_admin"] } })
|
|
20
|
+
expect(roles).toEqual(["custom_admin"])
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it("merges adminRoles into engine admin JSON", () => {
|
|
24
|
+
const merged = withAdminRoles({ models: [] }, { ...baseConfig, admin: { roles: ["ops"] } })
|
|
25
|
+
expect(merged).toEqual({ models: [], adminRoles: ["ops"] })
|
|
26
|
+
})
|
|
27
|
+
})
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest"
|
|
2
|
+
import { existsSync } from "node:fs"
|
|
3
|
+
import { evalTsSnippet, runTsFile } from "../src/tsx-runner.js"
|
|
4
|
+
import { writeFileSync, unlinkSync } from "node:fs"
|
|
5
|
+
import { join } from "node:path"
|
|
6
|
+
import { tmpdir } from "node:os"
|
|
7
|
+
|
|
8
|
+
describe("tsx-runner", () => {
|
|
9
|
+
describe("evalTsSnippet()", () => {
|
|
10
|
+
it("evaluates a simple expression and returns stdout", () => {
|
|
11
|
+
const result = evalTsSnippet(
|
|
12
|
+
`process.stdout.write("hello from tsx")`,
|
|
13
|
+
)
|
|
14
|
+
expect(result.exitCode).toBe(0)
|
|
15
|
+
expect(result.stdout).toBe("hello from tsx")
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it("evaluates TypeScript syntax (type annotations)", () => {
|
|
19
|
+
const result = evalTsSnippet(
|
|
20
|
+
`const x: number = 42\nprocess.stdout.write(String(x))`,
|
|
21
|
+
)
|
|
22
|
+
expect(result.exitCode).toBe(0)
|
|
23
|
+
expect(result.stdout).toBe("42")
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it("can serialize a JSON object to stdout", () => {
|
|
27
|
+
const result = evalTsSnippet(
|
|
28
|
+
`const obj = { a: 1, b: "two" }\nprocess.stdout.write(JSON.stringify(obj))`,
|
|
29
|
+
)
|
|
30
|
+
expect(result.exitCode).toBe(0)
|
|
31
|
+
expect(JSON.parse(result.stdout)).toEqual({ a: 1, b: "two" })
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it("returns non-zero exit code on syntax error", () => {
|
|
35
|
+
const result = evalTsSnippet(`const x: = broken syntax !!!`)
|
|
36
|
+
expect(result.exitCode).not.toBe(0)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it("returns non-zero exit code on runtime error", () => {
|
|
40
|
+
const result = evalTsSnippet(`throw new Error("intentional")`)
|
|
41
|
+
expect(result.exitCode).not.toBe(0)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it("captures stderr separately from stdout", () => {
|
|
45
|
+
const result = evalTsSnippet(
|
|
46
|
+
`process.stderr.write("err")\nprocess.stdout.write("out")`,
|
|
47
|
+
)
|
|
48
|
+
expect(result.stdout).toBe("out")
|
|
49
|
+
expect(result.stderr).toContain("err")
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
describe("runTsFile()", () => {
|
|
54
|
+
it("runs a .ts file and returns its stdout", () => {
|
|
55
|
+
const tmp = join(tmpdir(), `dt-tsx-test-${Date.now()}.ts`)
|
|
56
|
+
writeFileSync(tmp, `const n: number = 7\nprocess.stdout.write(String(n))`)
|
|
57
|
+
try {
|
|
58
|
+
const result = runTsFile(tmp)
|
|
59
|
+
expect(result.exitCode).toBe(0)
|
|
60
|
+
expect(result.stdout).toBe("7")
|
|
61
|
+
} finally {
|
|
62
|
+
unlinkSync(tmp)
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
})
|