create-stitchkit 0.6.23 → 0.8.0

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/README.md +9 -1
  3. package/UPGRADING.md +93 -17
  4. package/dist/cli.js +82 -57
  5. package/examples/repository/packages/backend/src/surface.snapshot.json +175 -88
  6. package/examples/repository/project.json +0 -1
  7. package/examples/repository/scripts/runtime-smoke.ts +156 -126
  8. package/package.json +7 -4
  9. package/template/README.md +12 -2
  10. package/template/_gitignore +1 -0
  11. package/template/bun.lock +5 -10
  12. package/template/docs/ADDING_A_FEATURE.md +21 -7
  13. package/template/package.json +3 -3
  14. package/template/packages/backend/package.json +0 -1
  15. package/template/packages/backend/src/cli.ts +3 -2
  16. package/template/packages/backend/src/index.ts +6 -3
  17. package/template/packages/backend/src/surface.snapshot.json +90 -50
  18. package/template/packages/backend/src/tools.ts +1 -1
  19. package/template/packages/config/package.json +0 -1
  20. package/template/packages/config/src/app-identity.generated.ts +0 -1
  21. package/template/packages/config/src/declaration.ts +10 -0
  22. package/template/packages/db/package.json +0 -1
  23. package/template/packages/frontend/package.json +1 -2
  24. package/template/packages/shared/package.json +0 -1
  25. package/template/project.json +0 -1
  26. package/template/scripts/acceptance-environment.test.ts +59 -0
  27. package/template/scripts/acceptance-environment.ts +52 -0
  28. package/template/scripts/acceptance-local.ts +8 -28
  29. package/template/scripts/declaration.ts +4 -87
  30. package/template/scripts/env-variables.ts +83 -0
  31. package/template/scripts/runtime-smoke.test.ts +49 -0
  32. package/template/scripts/runtime-smoke.ts +2 -2
  33. package/template/scripts/surface-snapshot.ts +135 -14
  34. package/templates/agent/package.json +2 -2
  35. package/templates/agent/project.json +0 -1
  36. package/templates/agent/src/runtime.ts +1 -1
  37. package/templates/telegram-bot/package.json +1 -1
  38. package/templates/telegram-bot/project.json +0 -1
  39. package/template/.data/board.sqlite +0 -0
  40. package/template/packages/backend/src/surface-manifest.test.ts +0 -237
  41. package/template/packages/backend/src/surface-manifest.ts +0 -220
  42. package/template/scripts/surface-conformance.ts +0 -173
package/template/bun.lock CHANGED
@@ -25,7 +25,6 @@
25
25
  },
26
26
  "packages/backend": {
27
27
  "name": "@app/backend",
28
- "version": "0.1.0",
29
28
  "dependencies": {
30
29
  "@app/config": "workspace:*",
31
30
  "@app/db": "workspace:*",
@@ -45,7 +44,6 @@
45
44
  },
46
45
  "packages/config": {
47
46
  "name": "@app/config",
48
- "version": "0.1.0",
49
47
  "dependencies": {
50
48
  "@t3-oss/env-core": "^0.13.11",
51
49
  "dotenv": "^18.0.10",
@@ -59,7 +57,6 @@
59
57
  },
60
58
  "packages/db": {
61
59
  "name": "@app/db",
62
- "version": "0.1.0",
63
60
  "dependencies": {
64
61
  "@app/config": "workspace:*",
65
62
  "@prisma/adapter-pg": "^7.10.1",
@@ -74,7 +71,6 @@
74
71
  },
75
72
  "packages/frontend": {
76
73
  "name": "@app/frontend",
77
- "version": "0.1.0",
78
74
  "dependencies": {
79
75
  "@app/config": "workspace:*",
80
76
  "@app/shared": "workspace:*",
@@ -91,7 +87,7 @@
91
87
  "@radix-ui/react-tooltip": "^1.4.1",
92
88
  "@t3-oss/env-nextjs": "^0.13.11",
93
89
  "@tabler/icons-react": "^3.52.0",
94
- "@tanstack/react-query": "^5.108.0",
90
+ "@tanstack/react-query": "^5.108.4",
95
91
  "@tanstack/react-table": "^9.3.1",
96
92
  "@wrksz/themes": "^2.1.1",
97
93
  "class-variance-authority": "^0.7.1",
@@ -127,7 +123,6 @@
127
123
  },
128
124
  "packages/shared": {
129
125
  "name": "@app/shared",
130
- "version": "0.1.0",
131
126
  "dependencies": {
132
127
  "stitchkit": "catalog:",
133
128
  "zod": "^4.6.7",
@@ -145,7 +140,7 @@
145
140
  "zod": "4.6.7",
146
141
  },
147
142
  "catalog": {
148
- "stitchkit": "^0.126.0",
143
+ "stitchkit": "^0.128.0",
149
144
  },
150
145
  "packages": {
151
146
  "@ai-sdk/gateway": ["@ai-sdk/gateway@4.0.146", "", { "dependencies": { "@ai-sdk/provider": "4.0.38", "@ai-sdk/provider-utils": "5.0.81", "@vercel/oidc": "3.2.0" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-rJ5NQSyjnpo6HSBEYc9Ff6k1EROUuB7KeAfHYVbVDsk68ynY0Eb8JeWflZKXlT6NhYgqyCiBDxE5blXWACXMKQ=="],
@@ -584,9 +579,9 @@
584
579
 
585
580
  "@tailwindcss/postcss": ["@tailwindcss/postcss@4.3.5", "", { "dependencies": { "@alloc/quick-lru": "^5.2.0", "@tailwindcss/node": "4.3.5", "@tailwindcss/oxide": "4.3.5", "postcss": "^8.5.25", "tailwindcss": "4.3.5" } }, "sha512-FAV37Tlx9wBiT/hkfgVD0Q6CWsP2oUX3lf28nrfjW8+ksILjnpuFulUqWDfNR4/ZiEHHDRBX8DUTzD1Rys687A=="],
586
581
 
587
- "@tanstack/query-core": ["@tanstack/query-core@5.108.0", "", {}, "sha512-X9zJUtEV/0D2q9pmGS/Bza8S4bNovSBhZOtdhtu0fzsHwizC6C+Eh/q5CX3MQBchsRMrirWVQmv7Fp4OStzV9g=="],
582
+ "@tanstack/query-core": ["@tanstack/query-core@5.108.4", "", {}, "sha512-2Ks5dlLWz4eXJrthOyG0qW3SLt3xx0RrQmAmN0rnmogiaaOYuWiAe6HAm9KE2b2v8nig+vraNz8fsfZ6fF6zFg=="],
588
583
 
589
- "@tanstack/react-query": ["@tanstack/react-query@5.108.0", "", { "dependencies": { "@tanstack/query-core": "5.108.0" }, "peerDependencies": { "@types/react": "^18 || ^19", "react": "^18 || ^19" }, "optionalPeers": ["@types/react"] }, "sha512-DpMbB8pVorEZcsHRa0Z13KQGfmndqvJbuLy9h+xfP8XpuEZBOxzq+QfXGonQ0fAgRSWhc+QsfoRETSTWxAEAVw=="],
584
+ "@tanstack/react-query": ["@tanstack/react-query@5.108.4", "", { "dependencies": { "@tanstack/query-core": "5.108.4" }, "peerDependencies": { "@types/react": "^18 || ^19", "react": "^18 || ^19" }, "optionalPeers": ["@types/react"] }, "sha512-GlTa94kfEKTVsbzXe58rFA3GZ0ZE7N1aFtbZAfOS3XxMv8YNn4C+8rsz40LorHLazdm5PsqCroWaYAR+ZkMXMQ=="],
590
585
 
591
586
  "@tanstack/react-store": ["@tanstack/react-store@0.11.2", "", { "dependencies": { "@tanstack/store": "0.11.2", "use-sync-external-store": "^1.6.0" }, "peerDependencies": { "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0", "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" } }, "sha512-oj5O5DmiMWE+ih+SioX2ayC1kbK7d3fpLx0B75fPJr9nY3zU+hoW010yr64qXsY/9fyiLVE2bn5mGNV3owm8RQ=="],
592
587
 
@@ -1126,7 +1121,7 @@
1126
1121
 
1127
1122
  "std-env": ["std-env@3.10.0", "", {}, "sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg=="],
1128
1123
 
1129
- "stitchkit": ["stitchkit@0.126.0", "", { "dependencies": { "ky": "^2.2.0" }, "peerDependencies": { "@modelcontextprotocol/ext-apps": "^1.7.2 || ^2.0.0", "@modelcontextprotocol/server": "^2.0.0", "@openrouter/ai-sdk-provider": "^3.1.0", "@opentelemetry/api": "^1.9.0", "@socket.io/bun-engine": "^0.1.2", "@socket.io/component-emitter": "^3.1.2", "@tanstack/react-query": ">=5", "@types/bun": "^1.4.2", "ai": "^7.0.107", "google-auth-library": "^11.1.0", "grammy": "^1.46.0", "maxmind": "^5.0.7", "react": ">=18", "react-query-kit": "^3.3.3", "socket.io": "^4.8.3", "socket.io-client": "^4.8.3", "srvx": "^0.12.5 || ^1.0.5", "web-vitals": "^6.2.3", "zod": "^4.6.5" }, "optionalPeers": ["@modelcontextprotocol/ext-apps", "@modelcontextprotocol/server", "@openrouter/ai-sdk-provider", "@opentelemetry/api", "@socket.io/bun-engine", "@socket.io/component-emitter", "@tanstack/react-query", "@types/bun", "ai", "google-auth-library", "grammy", "maxmind", "react", "react-query-kit", "socket.io", "socket.io-client", "srvx", "web-vitals"], "bin": { "stitchkit": "dist/entrypoints/bin/upgrade-cli.js" } }, "sha512-WbZQcLzDlyqwnol1OZs4kqLUs153nRiOIrYaAsE5WsYcbGyY5X1YS6E1pOhnmFvybG6qzIgxWVexcxh0HrSS2A=="],
1124
+ "stitchkit": ["stitchkit@0.128.0", "", { "dependencies": { "ky": "^2.2.0" }, "peerDependencies": { "@anthropic-ai/claude-agent-sdk": "^0.3.330", "@modelcontextprotocol/ext-apps": "^1.7.2 || ^2.0.0", "@modelcontextprotocol/server": "^2.0.0", "@openrouter/ai-sdk-provider": "^3.1.0", "@opentelemetry/api": "^1.9.0", "@socket.io/bun-engine": "^0.1.2", "@socket.io/component-emitter": "^3.1.2", "@tanstack/react-query": ">=5", "@types/bun": "^1.4.2", "ai": "^7.0.107", "google-auth-library": "^11.1.0", "grammy": "^1.46.0", "maxmind": "^5.0.7", "react": ">=18", "react-query-kit": "^3.3.3", "socket.io": "^4.8.3", "socket.io-client": "^4.8.3", "srvx": "^0.12.5 || ^1.0.5", "web-vitals": "^6.2.3", "zod": "^4.6.5" }, "optionalPeers": ["@anthropic-ai/claude-agent-sdk", "@modelcontextprotocol/ext-apps", "@modelcontextprotocol/server", "@openrouter/ai-sdk-provider", "@opentelemetry/api", "@socket.io/bun-engine", "@socket.io/component-emitter", "@tanstack/react-query", "@types/bun", "ai", "google-auth-library", "grammy", "maxmind", "react", "react-query-kit", "socket.io", "socket.io-client", "srvx", "web-vitals"], "bin": { "stitchkit": "dist/entrypoints/bin/upgrade-cli.js" } }, "sha512-BdcLm/+tQQjY3ET3ilGdBuy5EfdRWXaUFnLgU5/8K8Dh7moPC4owWXFOU3xFifvAPcMcFDv7nGFpQk3b2t4ChQ=="],
1130
1125
 
1131
1126
  "stringify-entities": ["stringify-entities@4.0.4", "", { "dependencies": { "character-entities-html4": "^2.0.0", "character-entities-legacy": "^3.0.0" } }, "sha512-IwfBptatlO+QCJUo19AqvrPNqlVMpW9YEL2LIVY+Rpv2qsjCGxaDLNRgeGsQWJhfItebuJhsGSLjaBbNSQ+ieg=="],
1132
1127
 
@@ -102,15 +102,29 @@ application or maintain a parallel event-map API.
102
102
 
103
103
  Generic smoke already derives expected HTTP operations and MCP tool names from
104
104
  the registered services and compares them with live OpenAPI/MCP discovery. Add
105
- an explicit probe only for handler behavior:
105
+ an explicit probe with `runSurfaceProbes` from `stitchkit/testing` only for
106
+ handler behavior:
106
107
 
107
108
  ```ts
108
- defineSurfaceProbe({
109
- name: 'status update lifecycle',
110
- input: UpdateStatusInputSchema,
111
- fixture: { message: 'Ready' },
112
- output: StatusSchema,
113
- run: (input) => statusClient.update(input),
109
+ import { runSurfaceProbes } from 'stitchkit/testing'
110
+
111
+ await runSurfaceProbes({
112
+ probes: [
113
+ {
114
+ name: 'status update lifecycle',
115
+ fixture: { message: 'Ready' },
116
+ transports: ['HTTP'],
117
+ expected: { HTTP: { outcome: 'success' } },
118
+ },
119
+ ],
120
+ drivers: {
121
+ HTTP: {
122
+ invoke: async (fixture) => {
123
+ StatusSchema.parse(await statusClient.update(UpdateStatusInputSchema.parse(fixture)))
124
+ return { outcome: 'success' }
125
+ },
126
+ },
127
+ },
114
128
  })
115
129
  ```
116
130
 
@@ -7,7 +7,7 @@
7
7
  "packages/*"
8
8
  ],
9
9
  "catalog": {
10
- "stitchkit": "^0.126.0"
10
+ "stitchkit": "^0.128.0"
11
11
  },
12
12
  "overrides": {
13
13
  "@playwright/test": "1.65.1",
@@ -62,8 +62,8 @@
62
62
  "zod": "^4.6.7"
63
63
  },
64
64
  "engines": {
65
- "bun": ">=1.2.0",
66
- "node": ">=22"
65
+ "bun": ">=1.4.0",
66
+ "node": ">=22.3.0"
67
67
  },
68
68
  "packageManager": "bun@1.4.5"
69
69
  }
@@ -1,6 +1,5 @@
1
1
  {
2
2
  "name": "@app/backend",
3
- "version": "0.1.0",
4
3
  "private": true,
5
4
  "type": "module",
6
5
  "scripts": {
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env bun
2
2
 
3
- import { appDeclaration } from '@app/config/declaration';
3
+ import { appDeclaration, appVersion } from '@app/config/declaration';
4
4
  import { createCli } from 'stitchkit/cli';
5
5
  import { createSurface } from './surface';
6
6
 
@@ -9,8 +9,9 @@ const { services, socket } = await createSurface();
9
9
  try {
10
10
  await createCli({
11
11
  name: appDeclaration.identity.slug,
12
- version: appDeclaration.identity.version,
12
+ version: appVersion,
13
13
  services,
14
+ access: { open: 'local-operator' },
14
15
  });
15
16
  } finally {
16
17
  await socket.close();
@@ -1,5 +1,5 @@
1
1
  import { env } from '@app/config';
2
- import { apiRole, appDeclaration } from '@app/config/declaration';
2
+ import { apiRole, appDeclaration, appVersion } from '@app/config/declaration';
3
3
  import { serviceSurfacesAreOpen } from '@app/config/variables';
4
4
  import { wrapInRequestContext } from 'stitchkit/observability';
5
5
  import {
@@ -20,15 +20,18 @@ async function main(): Promise<void> {
20
20
  const mcp = createMcpHandler({
21
21
  serverInfo: {
22
22
  name: appDeclaration.identity.slug,
23
- version: appDeclaration.identity.version,
23
+ version: appVersion,
24
24
  },
25
25
  auth: () => ({ scope: 'public' }),
26
+ // Every starter contract is public; replace with `{ gate: { beforeHandle } }`
27
+ // when adding authenticated scopes so MCP enforces the same gate as HTTP.
28
+ access: { open: 'public' },
26
29
  services,
27
30
  });
28
31
  const openApi = generateOpenApiDocument({
29
32
  info: {
30
33
  title: `${appDeclaration.identity.name} API`,
31
- version: appDeclaration.identity.version,
34
+ version: appVersion,
32
35
  },
33
36
  groups: [{ pathPrefix: '/api', services }],
34
37
  });
@@ -1,50 +1,90 @@
1
- [
2
- {
3
- "service": "board",
4
- "action": "list",
5
- "scope": "public",
6
- "hasInput": false,
7
- "hasOutput": true,
8
- "inputShape": null,
9
- "outputShape": "ce49fe198eb3412f",
10
- "http": [
11
- {
12
- "method": "GET",
13
- "path": "/api/board"
14
- }
15
- ],
16
- "tools": {}
17
- },
18
- {
19
- "service": "board",
20
- "action": "post",
21
- "scope": "public",
22
- "hasInput": true,
23
- "hasOutput": true,
24
- "inputShape": "b1d8eb61c62cafed",
25
- "outputShape": "ce49fe198eb3412f",
26
- "http": [
27
- {
28
- "method": "POST",
29
- "path": "/api/board"
30
- }
31
- ],
32
- "tools": {}
33
- },
34
- {
35
- "service": "system",
36
- "action": "status",
37
- "scope": "public",
38
- "hasInput": false,
39
- "hasOutput": true,
40
- "inputShape": null,
41
- "outputShape": "58b078ade3ee6167",
42
- "http": [
43
- {
44
- "method": "GET",
45
- "path": "/api/system/status"
46
- }
47
- ],
48
- "tools": {}
49
- }
50
- ]
1
+ {
2
+ "manifestVersion": 3,
3
+ "digestVersion": 1,
4
+ "operations": [
5
+ {
6
+ "kind": "contract",
7
+ "service": "board",
8
+ "action": "list",
9
+ "method": "GET",
10
+ "scope": "public",
11
+ "description": "Read the board",
12
+ "schemas": {
13
+ "params": null,
14
+ "input": null,
15
+ "output": "e486aa374f9a13e0",
16
+ "multipart": null
17
+ },
18
+ "mcp": null,
19
+ "http": [
20
+ {
21
+ "method": "GET",
22
+ "path": "/api/board"
23
+ }
24
+ ]
25
+ },
26
+ {
27
+ "kind": "contract",
28
+ "service": "board",
29
+ "action": "post",
30
+ "method": "POST",
31
+ "scope": "public",
32
+ "description": "Add a note to the board",
33
+ "schemas": {
34
+ "params": null,
35
+ "input": "c23c53a4b15afe81",
36
+ "output": "e486aa374f9a13e0",
37
+ "multipart": null
38
+ },
39
+ "mcp": null,
40
+ "http": [
41
+ {
42
+ "method": "POST",
43
+ "path": "/api/board"
44
+ }
45
+ ]
46
+ },
47
+ {
48
+ "kind": "contract",
49
+ "service": "system",
50
+ "action": "status",
51
+ "method": "GET",
52
+ "scope": "public",
53
+ "description": "Read application readiness",
54
+ "schemas": {
55
+ "params": null,
56
+ "input": null,
57
+ "output": "14a186301eeae875",
58
+ "multipart": null
59
+ },
60
+ "mcp": null,
61
+ "http": [
62
+ {
63
+ "method": "GET",
64
+ "path": "/api/system/status"
65
+ }
66
+ ]
67
+ }
68
+ ],
69
+ "toolSurfaces": [
70
+ {
71
+ "transport": "AGENT",
72
+ "surface": null,
73
+ "tools": []
74
+ },
75
+ {
76
+ "transport": "CLI",
77
+ "surface": null,
78
+ "tools": []
79
+ },
80
+ {
81
+ "transport": "MCP",
82
+ "surface": null,
83
+ "tools": []
84
+ }
85
+ ],
86
+ "realtimeContracts": [],
87
+ "realtime": [],
88
+ "cliOnly": [],
89
+ "extensions": []
90
+ }
@@ -6,7 +6,7 @@ const { services, socket } = await createSurface();
6
6
  try {
7
7
  const surface = { services };
8
8
  const toolNames = listToolNames(surface)
9
- .filter((tool) => tool.transports.some((transport) => transport !== 'HTTP'))
9
+ .filter((tool) => tool.expose.some((transport) => transport !== 'HTTP'))
10
10
  .map((tool) => tool.name);
11
11
  console.log(
12
12
  JSON.stringify(
@@ -1,6 +1,5 @@
1
1
  {
2
2
  "name": "@app/config",
3
- "version": "0.1.0",
4
3
  "private": true,
5
4
  "type": "module",
6
5
  "exports": {
@@ -12,7 +12,6 @@
12
12
  export const appIdentity = {
13
13
  "slug": "stitchkit-starter",
14
14
  "name": "Stitchkit Starter",
15
- "version": "0.1.0",
16
15
  "description": {
17
16
  "en": "Stitchkit Starter is a production application built with Stitchkit.",
18
17
  "ru": "Stitchkit Starter — production-приложение на Stitchkit."
@@ -1,6 +1,16 @@
1
1
  import { findProjectRole, parseProjectDeclaration } from 'stitchkit/declaration';
2
+ import { z } from 'zod';
3
+ import rootManifest from '../../../package.json' with { type: 'json' };
2
4
  import source from '../../../project.json' with { type: 'json' };
3
5
 
6
+ /**
7
+ * Single version of the application, read from the root `package.json` so
8
+ * OpenAPI, MCP and the CLI never drift from the release version.
9
+ */
10
+ export const appVersion = z
11
+ .looseObject({ version: z.string().min(1) })
12
+ .parse(rootManifest).version;
13
+
4
14
  /**
5
15
  * What this repository says about itself — the one machine-readable statement
6
16
  * that is true with no machine in existence.
@@ -1,6 +1,5 @@
1
1
  {
2
2
  "name": "@app/db",
3
- "version": "0.1.0",
4
3
  "private": true,
5
4
  "type": "module",
6
5
  "exports": {
@@ -1,6 +1,5 @@
1
1
  {
2
2
  "name": "@app/frontend",
3
- "version": "0.1.0",
4
3
  "private": true,
5
4
  "type": "module",
6
5
  "scripts": {
@@ -26,7 +25,7 @@
26
25
  "@radix-ui/react-tooltip": "^1.4.1",
27
26
  "@t3-oss/env-nextjs": "^0.13.11",
28
27
  "@tabler/icons-react": "^3.52.0",
29
- "@tanstack/react-query": "^5.108.0",
28
+ "@tanstack/react-query": "^5.108.4",
30
29
  "@tanstack/react-table": "^9.3.1",
31
30
  "@wrksz/themes": "^2.1.1",
32
31
  "class-variance-authority": "^0.7.1",
@@ -1,6 +1,5 @@
1
1
  {
2
2
  "name": "@app/shared",
3
- "version": "0.1.0",
4
3
  "private": true,
5
4
  "type": "module",
6
5
  "sideEffects": false,
@@ -4,7 +4,6 @@
4
4
  "identity": {
5
5
  "slug": "stitchkit-starter",
6
6
  "name": "Stitchkit Starter",
7
- "version": "0.1.0",
8
7
  "description": {
9
8
  "en": "Stitchkit Starter is a production application built with Stitchkit.",
10
9
  "ru": "Stitchkit Starter — production-приложение на Stitchkit."
@@ -0,0 +1,59 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import { existsSync, readFileSync } from 'node:fs';
3
+ import { resolve } from 'node:path';
4
+ import { acceptanceEnvironment } from './acceptance-environment';
5
+
6
+ const root = resolve(import.meta.dir, '..');
7
+ const example = readFileSync(
8
+ existsSync(resolve(root, '.env.example'))
9
+ ? resolve(root, '.env.example')
10
+ : resolve(root, '_env.example'),
11
+ 'utf8',
12
+ );
13
+
14
+ /** Every variable `.env.example` assigns, commented-out ones included: a deployment may set them. */
15
+ function exampleVariables(): Map<string, string> {
16
+ const variables = new Map<string, string>();
17
+ for (const line of example.split('\n')) {
18
+ const match = /^#?\s*([A-Z][A-Z0-9_]*)=(.*)$/.exec(line.trim());
19
+ if (match?.[1] && match[2] !== undefined) variables.set(match[1], match[2]);
20
+ }
21
+ return variables;
22
+ }
23
+
24
+ describe('the local acceptance environment', () => {
25
+ const variables = exampleVariables();
26
+ const defaultPorts = [variables.get('API_PORT'), variables.get('WEB_PORT')].filter(
27
+ (port): port is string => port !== undefined,
28
+ );
29
+ const addresses = {
30
+ apiPort: 41001,
31
+ webPort: 41002,
32
+ home: '/tmp/pm2',
33
+ databaseUrl: 'postgres://a',
34
+ };
35
+ const environment = acceptanceEnvironment(Object.fromEntries(variables), addresses);
36
+
37
+ test('reads the deployment ports and the variables that carry them', () => {
38
+ // Proves the scan works before anything is judged by it.
39
+ expect(defaultPorts).toHaveLength(2);
40
+ expect(
41
+ [...variables].filter(([, value]) =>
42
+ defaultPorts.some((port) => value.includes(`:${port}`)),
43
+ ).length,
44
+ ).toBeGreaterThan(3);
45
+ });
46
+
47
+ test('no address copied from .env names a port this run does not own', () => {
48
+ const stale = Object.entries(environment).filter(([, value]) =>
49
+ defaultPorts.some((port) => value.includes(`:${port}`)),
50
+ );
51
+ expect(stale).toEqual([]);
52
+ });
53
+
54
+ test('the browser dials the realtime socket on the API role this run started', () => {
55
+ expect(environment.PUBLIC_REALTIME_ORIGIN).toBe('http://127.0.0.1:41001');
56
+ expect(environment.CORS_ORIGIN).toBe('http://127.0.0.1:41002');
57
+ expect(environment.ACCEPTANCE_DATABASE_URL).toBeUndefined();
58
+ });
59
+ });
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The environment of a local acceptance run: the deployment's own variables,
3
+ * with every address in them replaced by this run's.
4
+ *
5
+ * The roles start on ephemeral ports, so an address copied from `.env` names a
6
+ * port this run does not own — and on a machine where another process listens
7
+ * there, the browser under test talks to that process and the gate passes or
8
+ * fails for someone else's reasons.
9
+ */
10
+ export interface AcceptanceAddresses {
11
+ readonly apiPort: number;
12
+ readonly webPort: number;
13
+ readonly home: string;
14
+ readonly databaseUrl: string;
15
+ }
16
+
17
+ export function acceptanceEnvironment(
18
+ base: Readonly<Record<string, string | undefined>>,
19
+ { apiPort, webPort, home, databaseUrl }: AcceptanceAddresses,
20
+ ): Record<string, string> {
21
+ const apiOrigin = `http://127.0.0.1:${apiPort}`;
22
+ const webOrigin = `http://127.0.0.1:${webPort}`;
23
+ const environment: Record<string, string> = {};
24
+ for (const [name, value] of Object.entries(base)) {
25
+ if (value !== undefined) environment[name] = value;
26
+ }
27
+ delete environment.ACCEPTANCE_DATABASE_URL;
28
+ return Object.assign(environment, {
29
+ NODE_ENV: 'production',
30
+ // The gates read the catalogue and the OpenAPI document; the closed default is
31
+ // proved after them, on the same artifact.
32
+ SERVICE_SURFACES: 'open',
33
+ // The one address every role, every migration and every gate here will see.
34
+ DATABASE_URL: databaseUrl,
35
+ PM2_HOME: home,
36
+ API_PORT: String(apiPort),
37
+ WEB_PORT: String(webPort),
38
+ INTERNAL_API_URL: apiOrigin,
39
+ SMOKE_API_ORIGIN: apiOrigin,
40
+ SMOKE_WEB_ORIGIN: webOrigin,
41
+ PLAYWRIGHT_BASE_URL: webOrigin,
42
+ // Two roles on two loopback ports: the browser dials the socket on the API
43
+ // role directly, and the API role admits the web role's origin.
44
+ PUBLIC_REALTIME_ORIGIN: apiOrigin,
45
+ CORS_ORIGIN: webOrigin,
46
+ // The portability proof asks this deployment to answer as addresses other
47
+ // than the one it is dialled on. Those addresses belong to the CHECK, so
48
+ // they are supplied here rather than written into the project's own
49
+ // `.env.example`, where they would be policy a deployment carries for real.
50
+ PUBLIC_WEB_HOSTS: `127.0.0.1:${webPort},alpha.example,beta.example:8443`,
51
+ });
52
+ }
@@ -8,7 +8,8 @@
8
8
  * A gate may not mutate a deployment; it may only create and destroy its own.
9
9
  *
10
10
  * So everything here is this run's and nothing else's: its own `PM2_HOME`, its
11
- * own ephemeral ports, its own public-host allowlist, its own database, and a
11
+ * own ephemeral ports and every address that names them, its own public-host
12
+ * allowlist, its own database, and a
12
13
  * stop that names the roles the declaration declares rather than deleting
13
14
  * whatever the daemon happened to hold.
14
15
  *
@@ -22,6 +23,7 @@ import { tmpdir } from 'node:os';
22
23
  import { join, resolve } from 'node:path';
23
24
  import { appDeclaration } from '../packages/config/src/declaration';
24
25
  import { resolveAcceptanceDatabase } from './acceptance-database';
26
+ import { acceptanceEnvironment } from './acceptance-environment';
25
27
  import { awaitRolesAnswering, declaredRoleReadiness } from './readiness';
26
28
  import { assertBuildArtifacts, runDeclaredReleaseSteps } from './release-steps';
27
29
  import { deploymentEnvironment } from './tooling-env';
@@ -62,37 +64,15 @@ assertBuildArtifacts();
62
64
  const home = await mkdtemp(join(tmpdir(), 'acceptance-local-'));
63
65
  const apiPort = freePort();
64
66
  const webPort = freePort();
65
- const apiOrigin = `http://127.0.0.1:${apiPort}`;
66
- const webOrigin = `http://127.0.0.1:${webPort}`;
67
67
  const base = deploymentEnvironment(root);
68
68
  // Before anything starts, and before the deployment's own URL is copied into
69
69
  // the child environment: a refusal here costs a message, a missing one costs
70
70
  // rows in someone's database.
71
- const acceptanceDatabaseUrl = resolveAcceptanceDatabase(base);
72
- const environment: Record<string, string> = {};
73
- for (const [name, value] of Object.entries(base)) {
74
- if (value !== undefined) environment[name] = value;
75
- }
76
- delete environment.ACCEPTANCE_DATABASE_URL;
77
- Object.assign(environment, {
78
- NODE_ENV: 'production',
79
- // The gates read the catalogue and the OpenAPI document; the closed default is
80
- // proved after them, on the same artifact.
81
- SERVICE_SURFACES: 'open',
82
- // The one address every role, every migration and every gate here will see.
83
- DATABASE_URL: acceptanceDatabaseUrl,
84
- PM2_HOME: home,
85
- API_PORT: String(apiPort),
86
- WEB_PORT: String(webPort),
87
- INTERNAL_API_URL: apiOrigin,
88
- SMOKE_API_ORIGIN: apiOrigin,
89
- SMOKE_WEB_ORIGIN: webOrigin,
90
- PLAYWRIGHT_BASE_URL: webOrigin,
91
- // The portability proof asks this deployment to answer as addresses other
92
- // than the one it is dialled on. Those addresses belong to the CHECK, so
93
- // they are supplied here rather than written into the project's own
94
- // `.env.example`, where they would be policy a deployment carries for real.
95
- PUBLIC_WEB_HOSTS: `127.0.0.1:${webPort},alpha.example,beta.example:8443`,
71
+ const environment = acceptanceEnvironment(base, {
72
+ apiPort,
73
+ webPort,
74
+ home,
75
+ databaseUrl: resolveAcceptanceDatabase(base),
96
76
  });
97
77
 
98
78
  // Boxed, so a thrown `undefined` is still recorded as a failure.