@supatype/cli 0.1.0-alpha.9 → 0.1.1
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 +2 -2
- package/.turbo/turbo-test.log +285 -69
- package/.turbo/turbo-typecheck.log +1 -1
- package/assets/supatype-logo-wordmark.ascii.txt +6 -0
- package/bin/dev-entry.ts +2 -1
- package/dist/app/framework.js +1 -3
- package/dist/app/framework.js.map +1 -1
- package/dist/app/proxy-dev-app.d.ts +14 -0
- package/dist/app/proxy-dev-app.d.ts.map +1 -1
- package/dist/app/proxy-dev-app.js +110 -6
- package/dist/app/proxy-dev-app.js.map +1 -1
- package/dist/app-config.d.ts +10 -0
- package/dist/app-config.d.ts.map +1 -1
- package/dist/app-config.js +72 -0
- package/dist/app-config.js.map +1 -1
- package/dist/assets/supatype-logo-wordmark.ascii.txt +6 -0
- package/dist/binary-cache.d.ts +19 -7
- package/dist/binary-cache.d.ts.map +1 -1
- package/dist/binary-cache.js +92 -46
- package/dist/binary-cache.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +17 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/add.d.ts +3 -0
- package/dist/commands/add.d.ts.map +1 -0
- package/dist/commands/add.js +86 -0
- package/dist/commands/add.js.map +1 -0
- package/dist/commands/admin.d.ts +28 -1
- package/dist/commands/admin.d.ts.map +1 -1
- package/dist/commands/admin.js +297 -149
- package/dist/commands/admin.js.map +1 -1
- package/dist/commands/adopt.d.ts +3 -0
- package/dist/commands/adopt.d.ts.map +1 -0
- package/dist/commands/adopt.js +55 -0
- package/dist/commands/adopt.js.map +1 -0
- package/dist/commands/app.d.ts.map +1 -1
- package/dist/commands/app.js +20 -17
- package/dist/commands/app.js.map +1 -1
- package/dist/commands/cache.d.ts.map +1 -1
- package/dist/commands/cache.js +11 -10
- package/dist/commands/cache.js.map +1 -1
- package/dist/commands/cloud.d.ts +4 -9
- package/dist/commands/cloud.d.ts.map +1 -1
- package/dist/commands/cloud.js +75 -125
- package/dist/commands/cloud.js.map +1 -1
- package/dist/commands/db.d.ts.map +1 -1
- package/dist/commands/db.js +37 -58
- package/dist/commands/db.js.map +1 -1
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +140 -96
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +74 -39
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/diff.d.ts.map +1 -1
- package/dist/commands/diff.js +39 -39
- package/dist/commands/diff.js.map +1 -1
- package/dist/commands/doctor.d.ts +3 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +78 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/engine.d.ts.map +1 -1
- package/dist/commands/engine.js +5 -4
- package/dist/commands/engine.js.map +1 -1
- package/dist/commands/functions.d.ts.map +1 -1
- package/dist/commands/functions.js +172 -119
- package/dist/commands/functions.js.map +1 -1
- package/dist/commands/generate.d.ts.map +1 -1
- package/dist/commands/generate.js +5 -4
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/init.d.ts +35 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +883 -107
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/introspect.d.ts +3 -0
- package/dist/commands/introspect.d.ts.map +1 -0
- package/dist/commands/introspect.js +35 -0
- package/dist/commands/introspect.js.map +1 -0
- package/dist/commands/keys.d.ts +15 -1
- package/dist/commands/keys.d.ts.map +1 -1
- package/dist/commands/keys.js +46 -10
- package/dist/commands/keys.js.map +1 -1
- package/dist/commands/link-helpers.d.ts +15 -0
- package/dist/commands/link-helpers.d.ts.map +1 -0
- package/dist/commands/link-helpers.js +225 -0
- package/dist/commands/link-helpers.js.map +1 -0
- package/dist/commands/logs.d.ts.map +1 -1
- package/dist/commands/logs.js +5 -4
- package/dist/commands/logs.js.map +1 -1
- package/dist/commands/migrate-from-v1.d.ts.map +1 -1
- package/dist/commands/migrate-from-v1.js +3 -2
- package/dist/commands/migrate-from-v1.js.map +1 -1
- package/dist/commands/migrate.d.ts.map +1 -1
- package/dist/commands/migrate.js +119 -26
- package/dist/commands/migrate.js.map +1 -1
- package/dist/commands/pg.d.ts.map +1 -1
- package/dist/commands/pg.js +11 -12
- package/dist/commands/pg.js.map +1 -1
- package/dist/commands/plugins.d.ts.map +1 -1
- package/dist/commands/plugins.js +55 -46
- package/dist/commands/plugins.js.map +1 -1
- package/dist/commands/pull.d.ts.map +1 -1
- package/dist/commands/pull.js +33 -5
- package/dist/commands/pull.js.map +1 -1
- package/dist/commands/push.d.ts.map +1 -1
- package/dist/commands/push.js +111 -138
- package/dist/commands/push.js.map +1 -1
- package/dist/commands/seed.d.ts.map +1 -1
- package/dist/commands/seed.js +4 -3
- package/dist/commands/seed.js.map +1 -1
- package/dist/commands/self-host.d.ts +2 -2
- package/dist/commands/self-host.d.ts.map +1 -1
- package/dist/commands/self-host.js +65 -50
- package/dist/commands/self-host.js.map +1 -1
- package/dist/commands/self-update.d.ts.map +1 -1
- package/dist/commands/self-update.js +3 -2
- package/dist/commands/self-update.js.map +1 -1
- package/dist/commands/status.d.ts +1 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +95 -29
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/commands/types.js +3 -2
- package/dist/commands/types.js.map +1 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +54 -21
- package/dist/commands/update.js.map +1 -1
- package/dist/compose-rename.d.ts +10 -0
- package/dist/compose-rename.d.ts.map +1 -0
- package/dist/compose-rename.js +67 -0
- package/dist/compose-rename.js.map +1 -0
- package/dist/config.d.ts +2 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/dev-compose.d.ts +26 -0
- package/dist/dev-compose.d.ts.map +1 -1
- package/dist/dev-compose.js +357 -79
- package/dist/dev-compose.js.map +1 -1
- 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 +56 -0
- package/dist/dev-logo.js.map +1 -0
- package/dist/dev-ports.d.ts +27 -0
- package/dist/dev-ports.d.ts.map +1 -0
- package/dist/dev-ports.js +171 -0
- package/dist/dev-ports.js.map +1 -0
- package/dist/dev-session-lock.d.ts +25 -0
- package/dist/dev-session-lock.d.ts.map +1 -0
- package/dist/dev-session-lock.js +81 -0
- package/dist/dev-session-lock.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 +25 -0
- package/dist/dev-shutdown.d.ts.map +1 -0
- package/dist/dev-shutdown.js +114 -0
- package/dist/dev-shutdown.js.map +1 -0
- package/dist/dev-task-colors.d.ts +13 -0
- package/dist/dev-task-colors.d.ts.map +1 -0
- package/dist/dev-task-colors.js +43 -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 +5 -1
- package/dist/diff-output.d.ts.map +1 -1
- package/dist/diff-output.js +69 -0
- package/dist/diff-output.js.map +1 -1
- package/dist/docker-runtime.d.ts +30 -0
- package/dist/docker-runtime.d.ts.map +1 -0
- package/dist/docker-runtime.js +118 -0
- package/dist/docker-runtime.js.map +1 -0
- package/dist/engine-client.d.ts +10 -1
- package/dist/engine-client.d.ts.map +1 -1
- package/dist/engine-client.js +76 -17
- package/dist/engine-client.js.map +1 -1
- package/dist/engine-push-output.d.ts +17 -0
- package/dist/engine-push-output.d.ts.map +1 -0
- package/dist/engine-push-output.js +64 -0
- package/dist/engine-push-output.js.map +1 -0
- package/dist/ensure-binary.js +2 -2
- package/dist/ensure-binary.js.map +1 -1
- package/dist/env-file.d.ts +5 -0
- package/dist/env-file.d.ts.map +1 -0
- package/dist/env-file.js +33 -0
- package/dist/env-file.js.map +1 -0
- package/dist/gitignore.d.ts +8 -0
- package/dist/gitignore.d.ts.map +1 -0
- package/dist/gitignore.js +41 -0
- package/dist/gitignore.js.map +1 -0
- package/dist/kong-config.d.ts +9 -0
- package/dist/kong-config.d.ts.map +1 -1
- package/dist/kong-config.js +18 -1
- package/dist/kong-config.js.map +1 -1
- package/dist/link.d.ts +66 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +160 -0
- package/dist/link.js.map +1 -0
- package/dist/process-manager.d.ts +8 -0
- package/dist/process-manager.d.ts.map +1 -1
- package/dist/process-manager.js +53 -9
- package/dist/process-manager.js.map +1 -1
- package/dist/project-config.d.ts +30 -3
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +37 -4
- package/dist/project-config.js.map +1 -1
- package/dist/prompts.d.ts +3 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +3 -0
- package/dist/prompts.js.map +1 -0
- package/dist/pull-utils.d.ts +50 -14
- package/dist/pull-utils.d.ts.map +1 -1
- package/dist/pull-utils.js +152 -12
- package/dist/pull-utils.js.map +1 -1
- package/dist/resolve-target.d.ts +86 -0
- package/dist/resolve-target.d.ts.map +1 -0
- package/dist/resolve-target.js +291 -0
- package/dist/resolve-target.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.map +1 -1
- package/dist/runtime-routes.js +7 -0
- package/dist/runtime-routes.js.map +1 -1
- package/dist/schema-ast-v2.d.ts +1 -1
- package/dist/schema-ast-v2.d.ts.map +1 -1
- package/dist/schema-ast-v2.js +2 -2
- package/dist/schema-ast-v2.js.map +1 -1
- package/dist/schema-sources.d.ts +40 -0
- package/dist/schema-sources.d.ts.map +1 -0
- package/dist/schema-sources.js +183 -0
- package/dist/schema-sources.js.map +1 -0
- package/dist/scripts/postinstall.js +5 -1
- package/dist/scripts/postinstall.js.map +1 -1
- package/dist/self-host-compose.d.ts +37 -1
- package/dist/self-host-compose.d.ts.map +1 -1
- package/dist/self-host-compose.js +234 -43
- package/dist/self-host-compose.js.map +1 -1
- package/dist/storage-provision.d.ts +4 -0
- package/dist/storage-provision.d.ts.map +1 -1
- package/dist/storage-provision.js +24 -2
- package/dist/storage-provision.js.map +1 -1
- 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.js +2 -2
- package/dist/systemd.js.map +1 -1
- package/dist/target-client.d.ts +10 -0
- package/dist/target-client.d.ts.map +1 -0
- package/dist/target-client.js +22 -0
- package/dist/target-client.js.map +1 -0
- package/dist/type-extractor.d.ts +11 -0
- package/dist/type-extractor.d.ts.map +1 -1
- package/dist/type-extractor.js +95 -8
- package/dist/type-extractor.js.map +1 -1
- package/dist/ui/brand.d.ts +9 -0
- package/dist/ui/brand.d.ts.map +1 -0
- package/dist/ui/brand.js +11 -0
- package/dist/ui/brand.js.map +1 -0
- package/dist/ui/confirm.d.ts +12 -0
- package/dist/ui/confirm.d.ts.map +1 -0
- package/dist/ui/confirm.js +28 -0
- package/dist/ui/confirm.js.map +1 -0
- package/dist/ui/fatal.d.ts +10 -0
- package/dist/ui/fatal.d.ts.map +1 -0
- package/dist/ui/fatal.js +34 -0
- package/dist/ui/fatal.js.map +1 -0
- package/dist/ui/index.d.ts +9 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +9 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/interactive.d.ts +3 -0
- package/dist/ui/interactive.d.ts.map +1 -0
- package/dist/ui/interactive.js +5 -0
- package/dist/ui/interactive.js.map +1 -0
- package/dist/ui/messages.d.ts +10 -0
- package/dist/ui/messages.d.ts.map +1 -0
- package/dist/ui/messages.js +35 -0
- package/dist/ui/messages.js.map +1 -0
- package/dist/ui/next-steps.d.ts +3 -0
- package/dist/ui/next-steps.d.ts.map +1 -0
- package/dist/ui/next-steps.js +10 -0
- package/dist/ui/next-steps.js.map +1 -0
- package/dist/ui/progress.d.ts +5 -0
- package/dist/ui/progress.d.ts.map +1 -0
- package/dist/ui/progress.js +24 -0
- package/dist/ui/progress.js.map +1 -0
- package/dist/ui/prompts.d.ts +14 -0
- package/dist/ui/prompts.d.ts.map +1 -0
- package/dist/ui/prompts.js +34 -0
- package/dist/ui/prompts.js.map +1 -0
- package/package.json +5 -2
- package/src/app/framework.ts +1 -3
- package/src/app/proxy-dev-app.ts +114 -6
- package/src/app-config.ts +80 -0
- package/src/binary-cache.ts +102 -52
- package/src/cli.ts +16 -2
- package/src/commands/add.ts +97 -0
- package/src/commands/admin.ts +381 -190
- package/src/commands/adopt.ts +82 -0
- package/src/commands/app.ts +20 -17
- package/src/commands/cache.ts +11 -10
- package/src/commands/cloud.ts +91 -142
- package/src/commands/db.ts +40 -63
- package/src/commands/deploy.ts +186 -126
- package/src/commands/dev.ts +98 -55
- package/src/commands/diff.ts +52 -43
- package/src/commands/doctor.ts +103 -0
- package/src/commands/engine.ts +5 -4
- package/src/commands/functions.ts +187 -123
- package/src/commands/generate.ts +5 -4
- package/src/commands/init.ts +1087 -104
- package/src/commands/introspect.ts +48 -0
- package/src/commands/keys.ts +56 -14
- package/src/commands/link-helpers.ts +273 -0
- package/src/commands/logs.ts +5 -4
- package/src/commands/migrate-from-v1.ts +3 -2
- package/src/commands/migrate.ts +167 -27
- package/src/commands/pg.ts +13 -18
- package/src/commands/plugins.ts +55 -46
- package/src/commands/pull.ts +38 -9
- package/src/commands/push.ts +148 -175
- package/src/commands/seed.ts +5 -4
- package/src/commands/self-host.ts +85 -54
- package/src/commands/self-update.ts +3 -2
- package/src/commands/status.ts +102 -33
- package/src/commands/types.ts +3 -2
- package/src/commands/update.ts +59 -23
- package/src/compose-rename.ts +76 -0
- package/src/config.ts +2 -1
- package/src/dev-compose.ts +462 -76
- package/src/dev-log-bus.ts +101 -0
- package/src/dev-log-filter.ts +32 -0
- package/src/dev-logo.ts +61 -0
- package/src/dev-ports.ts +212 -0
- package/src/dev-session-lock.ts +101 -0
- package/src/dev-session.ts +130 -0
- package/src/dev-shutdown.ts +147 -0
- package/src/dev-task-colors.ts +47 -0
- package/src/dev-tui.ts +232 -0
- package/src/diff-output.ts +79 -1
- package/src/docker-runtime.ts +151 -0
- package/src/engine-client.ts +81 -17
- package/src/engine-push-output.ts +75 -0
- package/src/ensure-binary.ts +2 -2
- package/src/env-file.ts +37 -0
- package/src/gitignore.ts +48 -0
- package/src/kong-config.ts +24 -1
- package/src/link.ts +243 -0
- package/src/process-manager.ts +66 -10
- package/src/project-config.ts +62 -7
- package/src/prompts.ts +2 -0
- package/src/pull-utils.ts +217 -23
- package/src/resolve-target.ts +419 -0
- package/src/restore-system-relation-targets.ts +45 -0
- package/src/runtime-routes.ts +7 -0
- package/src/schema-ast-v2.ts +2 -1
- package/src/schema-sources.ts +248 -0
- package/src/scripts/postinstall.ts +7 -1
- package/src/self-host-compose.ts +262 -46
- package/src/storage-provision.ts +33 -1
- package/src/supatype-eval-1781522769253.mts +1 -0
- package/src/systemd.ts +2 -2
- package/src/target-client.ts +40 -0
- package/src/type-extractor.ts +124 -11
- package/src/ui/README.md +17 -0
- package/src/ui/brand.ts +12 -0
- package/src/ui/confirm.ts +38 -0
- package/src/ui/fatal.ts +43 -0
- package/src/ui/index.ts +8 -0
- package/src/ui/interactive.ts +4 -0
- package/src/ui/messages.ts +43 -0
- package/src/ui/next-steps.ts +10 -0
- package/src/ui/progress.ts +28 -0
- package/src/ui/prompts.ts +40 -0
- package/tests/admin-ensure.test.ts +59 -0
- package/tests/cli-help.test.ts +27 -2
- package/tests/config.test.ts +29 -2
- package/tests/dev-ports.test.ts +41 -0
- package/tests/dev-session-lock.test.ts +54 -0
- package/tests/dev-ui.test.ts +162 -0
- package/tests/docker-runtime.test.ts +236 -0
- package/tests/engine-push-output.test.ts +67 -0
- package/tests/init.test.ts +197 -18
- package/tests/link.test.ts +148 -0
- package/tests/minisign.test.ts +102 -0
- package/tests/proxy-dev-app.test.ts +45 -1
- package/tests/pull-utils.test.ts +5 -4
- package/tests/runtime-contract.test.ts +186 -2
- package/tests/schema-sources.test.ts +119 -0
- package/tests/storage-provision.test.ts +100 -0
- package/tests/ui-confirm.test.ts +41 -0
- package/tests/ui-messages.test.ts +66 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -4,8 +4,8 @@ import { join } from "node:path"
|
|
|
4
4
|
import { tmpdir } from "node:os"
|
|
5
5
|
import { runtimeRouteSpec } from "../src/runtime-routes.js"
|
|
6
6
|
import { buildKongDeclarative } from "../src/kong-config.js"
|
|
7
|
-
import { renderSelfHostCompose, writeSelfHostCompose } from "../src/self-host-compose.js"
|
|
8
|
-
import { updateAppConfigInProject } from "../src/app-config.js"
|
|
7
|
+
import { composeDockerImageEnv, composePullNeedsIgnoreFailures, hasLocalVersionPins, isRegistryPullableImageRef, renderSelfHostCompose, writeSelfHostCompose } from "../src/self-host-compose.js"
|
|
8
|
+
import { updateAppConfigInProject, updateServerConfigInProject } from "../src/app-config.js"
|
|
9
9
|
import type { SupatypeProjectConfig } from "../src/project-config.js"
|
|
10
10
|
import { DENO_RELEASE_PIN } from "../src/release-pins.js"
|
|
11
11
|
|
|
@@ -109,6 +109,68 @@ describe("runtime contract", () => {
|
|
|
109
109
|
expect(compose).toContain("supatype/schema-engine:latest")
|
|
110
110
|
})
|
|
111
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("isRegistryPullableImageRef accepts semver and latest tags", () => {
|
|
132
|
+
expect(isRegistryPullableImageRef("supatype/server:latest")).toBe(true)
|
|
133
|
+
expect(isRegistryPullableImageRef("supatype/schema-engine:v0.4.2")).toBe(true)
|
|
134
|
+
expect(isRegistryPullableImageRef("supatype/postgres:17-latest")).toBe(true)
|
|
135
|
+
expect(isRegistryPullableImageRef("supatype/control-plane:local")).toBe(false)
|
|
136
|
+
expect(isRegistryPullableImageRef("supatype/server:keepsake-local")).toBe(false)
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
it("composePullNeedsIgnoreFailures is false for semver pins only", () => {
|
|
140
|
+
const cwd = mkdtempSync(join(tmpdir(), "supatype-pull-"))
|
|
141
|
+
try {
|
|
142
|
+
writeFileSync(
|
|
143
|
+
join(cwd, ".env"),
|
|
144
|
+
"SUPATYPE_ENGINE_IMAGE=supatype/schema-engine:v0.4.2\n",
|
|
145
|
+
"utf8",
|
|
146
|
+
)
|
|
147
|
+
expect(hasLocalVersionPins(baseConfig)).toBe(false)
|
|
148
|
+
expect(composePullNeedsIgnoreFailures(baseConfig, cwd)).toBe(false)
|
|
149
|
+
} finally {
|
|
150
|
+
rmSync(cwd, { recursive: true, force: true })
|
|
151
|
+
}
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
it("composePullNeedsIgnoreFailures is true for versions.local or custom tags", () => {
|
|
155
|
+
const cwd = mkdtempSync(join(tmpdir(), "supatype-pull-local-"))
|
|
156
|
+
try {
|
|
157
|
+
writeFileSync(
|
|
158
|
+
join(cwd, ".env"),
|
|
159
|
+
"SUPATYPE_CONTROL_PLANE_IMAGE=supatype/control-plane:local\n",
|
|
160
|
+
"utf8",
|
|
161
|
+
)
|
|
162
|
+
expect(
|
|
163
|
+
composePullNeedsIgnoreFailures(
|
|
164
|
+
{ ...baseConfig, versions: { engine: "local" } },
|
|
165
|
+
cwd,
|
|
166
|
+
),
|
|
167
|
+
).toBe(true)
|
|
168
|
+
expect(composePullNeedsIgnoreFailures(baseConfig, cwd)).toBe(true)
|
|
169
|
+
} finally {
|
|
170
|
+
rmSync(cwd, { recursive: true, force: true })
|
|
171
|
+
}
|
|
172
|
+
})
|
|
173
|
+
|
|
112
174
|
it("self-host compose mounts project root at /project (project-directory relative)", () => {
|
|
113
175
|
const compose = renderSelfHostCompose(baseConfig)
|
|
114
176
|
expect(compose).toContain("- .:/project")
|
|
@@ -148,6 +210,18 @@ describe("runtime contract", () => {
|
|
|
148
210
|
expect(compose).toContain("SUPATYPE_APP_UPSTREAM: http://host.docker.internal:4321")
|
|
149
211
|
})
|
|
150
212
|
|
|
213
|
+
it("devLocal compose injects SUPATYPE_VITE_DEV_URL when app.vite_dev_url is set", () => {
|
|
214
|
+
const compose = renderSelfHostCompose(
|
|
215
|
+
{
|
|
216
|
+
...baseConfig,
|
|
217
|
+
app: { mode: "static", static_dir: "./dist", vite_dev_url: "http://127.0.0.1:5173" },
|
|
218
|
+
},
|
|
219
|
+
process.cwd(),
|
|
220
|
+
{ devLocal: true },
|
|
221
|
+
)
|
|
222
|
+
expect(compose).toContain("SUPATYPE_VITE_DEV_URL: http://host.docker.internal:5173")
|
|
223
|
+
})
|
|
224
|
+
|
|
151
225
|
it("devLocal compose omits studio container when overrides.studio is set", () => {
|
|
152
226
|
const compose = renderSelfHostCompose(
|
|
153
227
|
{ ...baseConfig, overrides: { studio: "../supatype/packages/studio" } },
|
|
@@ -314,6 +388,60 @@ export default defineConfig({
|
|
|
314
388
|
}
|
|
315
389
|
})
|
|
316
390
|
|
|
391
|
+
it("server config updater sets standalone mode, domain, and tls (preserving other keys)", () => {
|
|
392
|
+
const dir = mkdtempSync(join(tmpdir(), "supatype-server-config-"))
|
|
393
|
+
try {
|
|
394
|
+
const configPath = join(dir, "supatype.config.ts")
|
|
395
|
+
writeFileSync(
|
|
396
|
+
configPath,
|
|
397
|
+
`import { defineConfig } from "@supatype/cli"
|
|
398
|
+
|
|
399
|
+
export default defineConfig({
|
|
400
|
+
project: { name: "x" },
|
|
401
|
+
database: { provider: "docker" },
|
|
402
|
+
server: { mode: "dev", port: 54321 },
|
|
403
|
+
app: { mode: "none" },
|
|
404
|
+
})
|
|
405
|
+
`,
|
|
406
|
+
"utf8",
|
|
407
|
+
)
|
|
408
|
+
updateServerConfigInProject(dir, { domain: "demo.supatype.com", tlsEmail: "hello@supatype.com" })
|
|
409
|
+
const next = readFileSync(configPath, "utf8")
|
|
410
|
+
expect(next).toContain(`mode: "standalone"`)
|
|
411
|
+
expect(next).toContain(`domain: "demo.supatype.com"`)
|
|
412
|
+
expect(next).toContain(`tls: { email: "hello@supatype.com", provider: "kong" }`)
|
|
413
|
+
expect(next).toContain(`port: 54321`)
|
|
414
|
+
} finally {
|
|
415
|
+
rmSync(dir, { recursive: true, force: true })
|
|
416
|
+
}
|
|
417
|
+
})
|
|
418
|
+
|
|
419
|
+
it("server config updater is idempotent and overwrites a prior domain/email", () => {
|
|
420
|
+
const dir = mkdtempSync(join(tmpdir(), "supatype-server-config-"))
|
|
421
|
+
try {
|
|
422
|
+
const configPath = join(dir, "supatype.config.ts")
|
|
423
|
+
writeFileSync(
|
|
424
|
+
configPath,
|
|
425
|
+
`export default {
|
|
426
|
+
project: { name: "x" },
|
|
427
|
+
database: { provider: "docker" },
|
|
428
|
+
server: { mode: "standalone", domain: "old.example.com", tls: { email: "old@example.com", provider: "kong" } },
|
|
429
|
+
app: { mode: "none" },
|
|
430
|
+
}
|
|
431
|
+
`,
|
|
432
|
+
"utf8",
|
|
433
|
+
)
|
|
434
|
+
updateServerConfigInProject(dir, { domain: "new.supatype.com", tlsEmail: "new@supatype.com" })
|
|
435
|
+
const next = readFileSync(configPath, "utf8")
|
|
436
|
+
expect(next).toContain(`domain: "new.supatype.com"`)
|
|
437
|
+
expect(next).toContain(`email: "new@supatype.com"`)
|
|
438
|
+
expect(next).not.toContain("old.example.com")
|
|
439
|
+
expect(next).not.toContain("old@example.com")
|
|
440
|
+
} finally {
|
|
441
|
+
rmSync(dir, { recursive: true, force: true })
|
|
442
|
+
}
|
|
443
|
+
})
|
|
444
|
+
|
|
317
445
|
it("writes self-host compose artifacts under .supatype/self-host", () => {
|
|
318
446
|
const dir = mkdtempSync(join(tmpdir(), "supatype-compose-"))
|
|
319
447
|
try {
|
|
@@ -337,6 +465,62 @@ export default defineConfig({
|
|
|
337
465
|
}
|
|
338
466
|
})
|
|
339
467
|
|
|
468
|
+
const tlsConfig: SupatypeProjectConfig = {
|
|
469
|
+
...baseConfig,
|
|
470
|
+
server: { mode: "standalone", domain: "api.example.com", tls: { email: "ops@example.com" } },
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
it("self-host compose renders Kong TLS + Valkey when standalone domain + email are set", () => {
|
|
474
|
+
const compose = renderSelfHostCompose(tlsConfig)
|
|
475
|
+
expect(compose).toContain("\n valkey:\n")
|
|
476
|
+
expect(compose).toContain("valkey/valkey:8-alpine")
|
|
477
|
+
expect(compose).toContain('- "80:8000"')
|
|
478
|
+
expect(compose).toContain('- "443:8443"')
|
|
479
|
+
expect(compose).toContain("KONG_PROXY_LISTEN")
|
|
480
|
+
expect(compose).toContain("- valkey")
|
|
481
|
+
expect(compose).toContain("https://api.example.com")
|
|
482
|
+
expect(compose).toMatch(/^\s{2}valkey-data:/m)
|
|
483
|
+
expect(compose).not.toContain("HTTPS is off")
|
|
484
|
+
})
|
|
485
|
+
|
|
486
|
+
it("self-host compose stays plain HTTP with a discoverable hint when TLS is off", () => {
|
|
487
|
+
const compose = renderSelfHostCompose(baseConfig)
|
|
488
|
+
expect(compose).not.toContain("\n valkey:\n")
|
|
489
|
+
expect(compose).not.toContain('- "443:8443"')
|
|
490
|
+
expect(compose).toContain("${SUPATYPE_KONG_PORT:-18473}:8000")
|
|
491
|
+
expect(compose).toContain("HTTPS is off")
|
|
492
|
+
})
|
|
493
|
+
|
|
494
|
+
it("self-host compose does not enable TLS for a domain without an ACME email", () => {
|
|
495
|
+
const compose = renderSelfHostCompose({
|
|
496
|
+
...baseConfig,
|
|
497
|
+
server: { mode: "standalone", domain: "api.example.com" },
|
|
498
|
+
})
|
|
499
|
+
expect(compose).not.toContain("\n valkey:\n")
|
|
500
|
+
expect(compose).not.toContain('- "443:8443"')
|
|
501
|
+
})
|
|
502
|
+
|
|
503
|
+
it("writeSelfHostCompose emits a Kong acme plugin backed by Valkey when TLS is on", () => {
|
|
504
|
+
const dir = mkdtempSync(join(tmpdir(), "supatype-tls-"))
|
|
505
|
+
try {
|
|
506
|
+
const out = writeSelfHostCompose(dir, tlsConfig)
|
|
507
|
+
const kong = readFileSync(out.kongPath, "utf8")
|
|
508
|
+
expect(kong).toContain("name: acme")
|
|
509
|
+
expect(kong).toContain('account_email: "ops@example.com"')
|
|
510
|
+
expect(kong).toContain("tos_accepted: true")
|
|
511
|
+
expect(kong).toContain('- "api.example.com"')
|
|
512
|
+
expect(kong).toContain("storage: redis")
|
|
513
|
+
expect(kong).toContain('host: "valkey"')
|
|
514
|
+
} finally {
|
|
515
|
+
rmSync(dir, { recursive: true, force: true })
|
|
516
|
+
}
|
|
517
|
+
})
|
|
518
|
+
|
|
519
|
+
it("kong declarative omits the acme plugin when no acme options are provided", () => {
|
|
520
|
+
const kong = buildKongDeclarative({ unifiedGateway: true })
|
|
521
|
+
expect(kong).not.toContain("name: acme")
|
|
522
|
+
})
|
|
523
|
+
|
|
340
524
|
it("writes default manifest when missing for compose", () => {
|
|
341
525
|
const dir = mkdtempSync(join(tmpdir(), "supatype-manifest-"))
|
|
342
526
|
try {
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from "vitest"
|
|
2
|
+
import { mkdtempSync, writeFileSync, readFileSync, rmSync, mkdirSync } from "node:fs"
|
|
3
|
+
import { join } from "node:path"
|
|
4
|
+
import { tmpdir } from "node:os"
|
|
5
|
+
import { collectSchemaSourcePaths } from "../src/type-extractor.js"
|
|
6
|
+
import {
|
|
7
|
+
packSchemaSources,
|
|
8
|
+
unpackSchemaSources,
|
|
9
|
+
buildSchemaSourcesPayload,
|
|
10
|
+
restoreSchemaSourcesFromGz,
|
|
11
|
+
findOrphanSchemaFiles,
|
|
12
|
+
} from "../src/schema-sources.js"
|
|
13
|
+
|
|
14
|
+
function writeMultiFileSchema(root: string): void {
|
|
15
|
+
mkdirSync(join(root, "schema", "models"), { recursive: true })
|
|
16
|
+
mkdirSync(join(root, "schema", "shared"), { recursive: true })
|
|
17
|
+
writeFileSync(
|
|
18
|
+
join(root, "schema", "index.ts"),
|
|
19
|
+
`export type { Album } from "./models/album"\nexport type { localeConfig } from "./shared/locale"\n`,
|
|
20
|
+
)
|
|
21
|
+
writeFileSync(
|
|
22
|
+
join(root, "schema", "models", "album.ts"),
|
|
23
|
+
`import type { Nullable } from "../shared/field-types"\nexport type Album = { id: string; title: Nullable<string> }\n`,
|
|
24
|
+
)
|
|
25
|
+
writeFileSync(
|
|
26
|
+
join(root, "schema", "shared", "field-types.ts"),
|
|
27
|
+
`export type Nullable<T> = T | null\n`,
|
|
28
|
+
)
|
|
29
|
+
writeFileSync(
|
|
30
|
+
join(root, "schema", "shared", "locale.ts"),
|
|
31
|
+
`export type localeConfig = { default: string }\n`,
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
describe("schema-sources", () => {
|
|
36
|
+
let tmp: string
|
|
37
|
+
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
tmp = mkdtempSync(join(tmpdir(), "schema-sources-"))
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
rmSync(tmp, { recursive: true, force: true })
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it("discovers multi-file graph from entry point", () => {
|
|
47
|
+
writeMultiFileSchema(tmp)
|
|
48
|
+
const entry = join(tmp, "schema", "index.ts")
|
|
49
|
+
const graph = collectSchemaSourcePaths(entry, tmp)
|
|
50
|
+
const paths = graph.files.map((f) => f.relativePath).sort()
|
|
51
|
+
expect(paths).toEqual([
|
|
52
|
+
"schema/index.ts",
|
|
53
|
+
"schema/models/album.ts",
|
|
54
|
+
"schema/shared/field-types.ts",
|
|
55
|
+
"schema/shared/locale.ts",
|
|
56
|
+
])
|
|
57
|
+
expect(graph.entryPoint).toBe("schema/index.ts")
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it("roundtrips tar+gzip bytes", () => {
|
|
61
|
+
writeMultiFileSchema(tmp)
|
|
62
|
+
const graph = collectSchemaSourcePaths(join(tmp, "schema", "index.ts"), tmp)
|
|
63
|
+
const tar = packSchemaSources(graph)
|
|
64
|
+
const files = unpackSchemaSources(tar, tmp)
|
|
65
|
+
for (const file of graph.files) {
|
|
66
|
+
const original = readFileSync(file.absolutePath)
|
|
67
|
+
const restored = files.get(file.relativePath.replace(/\\/g, "/"))
|
|
68
|
+
expect(restored?.equals(original)).toBe(true)
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it("buildSchemaSourcesPayload includes manifest metadata", () => {
|
|
73
|
+
writeMultiFileSchema(tmp)
|
|
74
|
+
writeFileSync(
|
|
75
|
+
join(tmp, "supatype.config.ts"),
|
|
76
|
+
`export default ${JSON.stringify({
|
|
77
|
+
project: { name: "demo" },
|
|
78
|
+
database: { provider: "docker" },
|
|
79
|
+
server: { mode: "dev" },
|
|
80
|
+
app: { mode: "none" },
|
|
81
|
+
schema: { path: "schema/index.ts", pg_schema: "public" },
|
|
82
|
+
})}\n`,
|
|
83
|
+
)
|
|
84
|
+
const payload = buildSchemaSourcesPayload(tmp, "test@example.com")
|
|
85
|
+
expect(payload).not.toBeNull()
|
|
86
|
+
expect(payload!.manifest.fileCount).toBe(4)
|
|
87
|
+
expect(payload!.manifest.pushedBy).toBe("test@example.com")
|
|
88
|
+
expect(payload!.manifest.compressedBytes).toBeGreaterThan(0)
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it("restore overwrites modified local files", () => {
|
|
92
|
+
writeMultiFileSchema(tmp)
|
|
93
|
+
writeFileSync(
|
|
94
|
+
join(tmp, "supatype.config.ts"),
|
|
95
|
+
`export default ${JSON.stringify({
|
|
96
|
+
project: { name: "demo" },
|
|
97
|
+
database: { provider: "docker" },
|
|
98
|
+
server: { mode: "dev" },
|
|
99
|
+
app: { mode: "none" },
|
|
100
|
+
schema: { path: "schema/index.ts", pg_schema: "public" },
|
|
101
|
+
})}\n`,
|
|
102
|
+
)
|
|
103
|
+
const payload = buildSchemaSourcesPayload(tmp)!
|
|
104
|
+
const albumPath = join(tmp, "schema", "models", "album.ts")
|
|
105
|
+
writeFileSync(albumPath, "// modified\n")
|
|
106
|
+
|
|
107
|
+
restoreSchemaSourcesFromGz(payload.gz, payload.manifest, tmp)
|
|
108
|
+
expect(readFileSync(albumPath, "utf8")).toContain("Nullable")
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it("warns about orphan files not in snapshot", () => {
|
|
112
|
+
writeMultiFileSchema(tmp)
|
|
113
|
+
writeFileSync(join(tmp, "schema", "models", "experimental.ts"), "export type X = {}\n")
|
|
114
|
+
const graph = collectSchemaSourcePaths(join(tmp, "schema", "index.ts"), tmp)
|
|
115
|
+
const manifestPaths = new Set(graph.files.map((f) => f.relativePath))
|
|
116
|
+
const orphans = findOrphanSchemaFiles(tmp, graph.entryPoint, manifestPaths)
|
|
117
|
+
expect(orphans).toContain("schema/models/experimental.ts")
|
|
118
|
+
})
|
|
119
|
+
})
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from "vitest"
|
|
2
|
+
import {
|
|
3
|
+
bucketSpecsFromAst,
|
|
4
|
+
provisionBuckets,
|
|
5
|
+
provisionBucketsFromAst,
|
|
6
|
+
type SchemaStorageBucketAst,
|
|
7
|
+
} from "../src/storage-provision.js"
|
|
8
|
+
|
|
9
|
+
describe("bucketSpecsFromAst", () => {
|
|
10
|
+
it("maps storage bucket AST fields to API bucket specs", () => {
|
|
11
|
+
const buckets: SchemaStorageBucketAst[] = [
|
|
12
|
+
{
|
|
13
|
+
id: "photos",
|
|
14
|
+
public: false,
|
|
15
|
+
accessMode: "private",
|
|
16
|
+
allowedMimeTypes: ["image/jpeg"],
|
|
17
|
+
fileSizeLimit: 5_000_000,
|
|
18
|
+
},
|
|
19
|
+
{ id: "avatars", public: true },
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
expect(bucketSpecsFromAst({ storageBuckets: buckets })).toEqual([
|
|
23
|
+
{
|
|
24
|
+
id: "photos",
|
|
25
|
+
public: false,
|
|
26
|
+
access_mode: "private",
|
|
27
|
+
allowed_mime_types: ["image/jpeg"],
|
|
28
|
+
file_size_limit: 5_000_000,
|
|
29
|
+
},
|
|
30
|
+
{ id: "avatars", public: true },
|
|
31
|
+
])
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it("returns an empty list when no buckets are declared", () => {
|
|
35
|
+
expect(bucketSpecsFromAst({})).toEqual([])
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
describe("provisionBuckets", () => {
|
|
40
|
+
afterEach(() => {
|
|
41
|
+
vi.restoreAllMocks()
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it("POSTs each bucket to the storage API", async () => {
|
|
45
|
+
const fetchMock = vi.fn().mockResolvedValue({ status: 200, ok: true })
|
|
46
|
+
vi.stubGlobal("fetch", fetchMock)
|
|
47
|
+
|
|
48
|
+
await provisionBuckets("http://localhost:54321/storage/v1/", "service-key", [
|
|
49
|
+
{ id: "photos", public: false },
|
|
50
|
+
{ id: "avatars", public: true },
|
|
51
|
+
])
|
|
52
|
+
|
|
53
|
+
expect(fetchMock).toHaveBeenCalledTimes(2)
|
|
54
|
+
expect(fetchMock).toHaveBeenNthCalledWith(
|
|
55
|
+
1,
|
|
56
|
+
"http://localhost:54321/storage/v1/bucket",
|
|
57
|
+
expect.objectContaining({
|
|
58
|
+
method: "POST",
|
|
59
|
+
headers: {
|
|
60
|
+
Authorization: "Bearer service-key",
|
|
61
|
+
"Content-Type": "application/json",
|
|
62
|
+
},
|
|
63
|
+
body: JSON.stringify({ id: "photos", name: "photos", public: false }),
|
|
64
|
+
}),
|
|
65
|
+
)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it("treats 409 Conflict as success (bucket already exists)", async () => {
|
|
69
|
+
const fetchMock = vi.fn().mockResolvedValue({ status: 409, ok: false })
|
|
70
|
+
vi.stubGlobal("fetch", fetchMock)
|
|
71
|
+
|
|
72
|
+
await expect(
|
|
73
|
+
provisionBuckets("http://localhost:54321/storage/v1", "key", [{ id: "photos", public: false }]),
|
|
74
|
+
).resolves.toBeUndefined()
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it("warns and continues when the storage API is unreachable", async () => {
|
|
78
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => undefined)
|
|
79
|
+
vi.stubGlobal("fetch", vi.fn().mockRejectedValue(new Error("ECONNREFUSED")))
|
|
80
|
+
|
|
81
|
+
await provisionBuckets("http://localhost:54321/storage/v1", "key", [{ id: "photos", public: false }])
|
|
82
|
+
|
|
83
|
+
expect(warn).toHaveBeenCalledWith('[storage] Storage API unreachable — skipped bucket "photos"')
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
describe("provisionBucketsFromAst", () => {
|
|
88
|
+
afterEach(() => {
|
|
89
|
+
vi.restoreAllMocks()
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it("skips provisioning when the AST declares no buckets", async () => {
|
|
93
|
+
const fetchMock = vi.fn()
|
|
94
|
+
vi.stubGlobal("fetch", fetchMock)
|
|
95
|
+
|
|
96
|
+
await provisionBucketsFromAst({}, "http://localhost:54321/storage/v1", "key")
|
|
97
|
+
|
|
98
|
+
expect(fetchMock).not.toHaveBeenCalled()
|
|
99
|
+
})
|
|
100
|
+
})
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { describe, expect, it, vi, beforeEach } from "vitest"
|
|
2
|
+
|
|
3
|
+
vi.mock("@clack/prompts", () => ({
|
|
4
|
+
confirm: vi.fn(),
|
|
5
|
+
isCancel: vi.fn((v: unknown) => v === Symbol.for("cancel")),
|
|
6
|
+
cancel: vi.fn(),
|
|
7
|
+
}))
|
|
8
|
+
|
|
9
|
+
vi.mock("../src/ui/interactive.js", () => ({
|
|
10
|
+
isInteractive: vi.fn(() => true),
|
|
11
|
+
}))
|
|
12
|
+
|
|
13
|
+
import * as clack from "@clack/prompts"
|
|
14
|
+
import { confirm, logSkippedConfirm } from "../src/ui/confirm.js"
|
|
15
|
+
import { isInteractive } from "../src/ui/interactive.js"
|
|
16
|
+
|
|
17
|
+
describe("ui confirm", () => {
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
vi.mocked(clack.confirm).mockReset()
|
|
20
|
+
vi.mocked(isInteractive).mockReturnValue(true)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it("returns clack confirm result in TTY mode", async () => {
|
|
24
|
+
vi.mocked(clack.confirm).mockResolvedValue(true)
|
|
25
|
+
await expect(confirm("Proceed?")).resolves.toBe(true)
|
|
26
|
+
expect(clack.confirm).toHaveBeenCalledWith({ message: "Proceed?", initialValue: false })
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it("uses nonInteractive fallback when not a TTY", async () => {
|
|
30
|
+
vi.mocked(isInteractive).mockReturnValue(false)
|
|
31
|
+
await expect(confirm("Proceed?", { nonInteractive: false })).resolves.toBe(false)
|
|
32
|
+
expect(clack.confirm).not.toHaveBeenCalled()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it("logSkippedConfirm mentions --yes", () => {
|
|
36
|
+
const log = vi.spyOn(console, "log").mockImplementation(() => {})
|
|
37
|
+
logSkippedConfirm("3 risky operations")
|
|
38
|
+
expect(log.mock.calls[0]?.[0]).toContain("--yes")
|
|
39
|
+
log.mockRestore()
|
|
40
|
+
})
|
|
41
|
+
})
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { describe, expect, it, vi, beforeEach, afterAll } from "vitest"
|
|
2
|
+
|
|
3
|
+
const isInteractiveMock = vi.hoisted(() => vi.fn(() => false))
|
|
4
|
+
const clackInfoMock = vi.hoisted(() => vi.fn())
|
|
5
|
+
|
|
6
|
+
vi.mock("../src/ui/interactive.js", () => ({
|
|
7
|
+
isInteractive: isInteractiveMock,
|
|
8
|
+
}))
|
|
9
|
+
|
|
10
|
+
vi.mock("@clack/prompts", async (importOriginal) => {
|
|
11
|
+
const original = await importOriginal<typeof import("@clack/prompts")>()
|
|
12
|
+
return {
|
|
13
|
+
...original,
|
|
14
|
+
log: {
|
|
15
|
+
...original.log,
|
|
16
|
+
info: clackInfoMock,
|
|
17
|
+
},
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
import { file, info, plain, step, SUPATYPE_PREFIX } from "../src/ui/messages.js"
|
|
22
|
+
|
|
23
|
+
describe("ui messages", () => {
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
isInteractiveMock.mockReturnValue(false)
|
|
26
|
+
clackInfoMock.mockClear()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it("info prefixes with [supatype] when non-interactive", () => {
|
|
30
|
+
const log = vi.spyOn(console, "log").mockImplementation(() => {})
|
|
31
|
+
info("hello")
|
|
32
|
+
expect(log.mock.calls[0]?.[0]).toBe(`${SUPATYPE_PREFIX} hello`)
|
|
33
|
+
expect(clackInfoMock).not.toHaveBeenCalled()
|
|
34
|
+
log.mockRestore()
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it("info uses Clack log in interactive mode", () => {
|
|
38
|
+
isInteractiveMock.mockReturnValue(true)
|
|
39
|
+
const log = vi.spyOn(console, "log").mockImplementation(() => {})
|
|
40
|
+
info("hello")
|
|
41
|
+
expect(clackInfoMock).toHaveBeenCalledWith("hello")
|
|
42
|
+
expect(log).not.toHaveBeenCalled()
|
|
43
|
+
log.mockRestore()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it("file action uses scaffold-style columns", () => {
|
|
47
|
+
const log = vi.spyOn(console, "log").mockImplementation(() => {})
|
|
48
|
+
file("created", "schema/index.ts")
|
|
49
|
+
expect(log.mock.calls[0]?.[0]).toBe(" created schema/index.ts")
|
|
50
|
+
log.mockRestore()
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it("step prints a titled section", () => {
|
|
54
|
+
const log = vi.spyOn(console, "log").mockImplementation(() => {})
|
|
55
|
+
step("Schema Push")
|
|
56
|
+
expect(log.mock.calls[0]?.[0]).toBe("\nSchema Push")
|
|
57
|
+
log.mockRestore()
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it("plain writes unprefixed lines", () => {
|
|
61
|
+
const log = vi.spyOn(console, "log").mockImplementation(() => {})
|
|
62
|
+
plain("no prefix")
|
|
63
|
+
expect(log.mock.calls[0]?.[0]).toBe("no prefix")
|
|
64
|
+
log.mockRestore()
|
|
65
|
+
})
|
|
66
|
+
})
|