create-stitchkit 0.6.22 → 0.7.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 (34) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +9 -1
  3. package/UPGRADING.md +84 -16
  4. package/dist/cli.js +83 -56
  5. package/examples/repository/packages/backend/src/surface.snapshot.json +175 -88
  6. package/examples/repository/scripts/runtime-smoke.ts +156 -126
  7. package/package.json +12 -9
  8. package/template/README.md +12 -2
  9. package/template/_gitignore +1 -0
  10. package/template/bun.lock +12 -12
  11. package/template/docs/ADDING_A_FEATURE.md +21 -7
  12. package/template/package.json +5 -5
  13. package/template/packages/backend/package.json +1 -1
  14. package/template/packages/backend/src/cli.ts +1 -0
  15. package/template/packages/backend/src/index.ts +3 -0
  16. package/template/packages/backend/src/lib/live.ts +3 -1
  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 +1 -1
  20. package/template/packages/frontend/package.json +2 -2
  21. package/template/packages/shared/package.json +1 -1
  22. package/template/scripts/acceptance-environment.test.ts +59 -0
  23. package/template/scripts/acceptance-environment.ts +52 -0
  24. package/template/scripts/acceptance-local.ts +8 -28
  25. package/template/scripts/runtime-smoke.test.ts +49 -0
  26. package/template/scripts/runtime-smoke.ts +2 -2
  27. package/template/scripts/surface-snapshot.ts +135 -14
  28. package/templates/agent/package.json +7 -7
  29. package/templates/agent/src/runtime.ts +1 -1
  30. package/templates/telegram-bot/package.json +3 -3
  31. package/template/.data/board.sqlite +0 -0
  32. package/template/packages/backend/src/surface-manifest.test.ts +0 -237
  33. package/template/packages/backend/src/surface-manifest.ts +0 -220
  34. package/template/scripts/surface-conformance.ts +0 -173
package/template/bun.lock CHANGED
@@ -14,7 +14,7 @@
14
14
  "@biomejs/biome": "2.6.8",
15
15
  "@modelcontextprotocol/client": "^2.4.0",
16
16
  "@playwright/test": "^1.65.1",
17
- "@types/bun": "^1.4.4",
17
+ "@types/bun": "^1.4.5",
18
18
  "@types/node": "^26.6.6",
19
19
  "oxc-parser": "^0.159.0",
20
20
  "socket.io-client": "^4.8.4",
@@ -39,7 +39,7 @@
39
39
  "zod": "^4.6.7",
40
40
  },
41
41
  "devDependencies": {
42
- "@types/bun": "^1.4.4",
42
+ "@types/bun": "^1.4.5",
43
43
  "typescript": "^7.0.2",
44
44
  },
45
45
  },
@@ -53,7 +53,7 @@
53
53
  "zod": "^4.6.7",
54
54
  },
55
55
  "devDependencies": {
56
- "@types/bun": "^1.4.4",
56
+ "@types/bun": "^1.4.5",
57
57
  "typescript": "^7.0.2",
58
58
  },
59
59
  },
@@ -91,7 +91,7 @@
91
91
  "@radix-ui/react-tooltip": "^1.4.1",
92
92
  "@t3-oss/env-nextjs": "^0.13.11",
93
93
  "@tabler/icons-react": "^3.52.0",
94
- "@tanstack/react-query": "^5.108.0",
94
+ "@tanstack/react-query": "^5.108.4",
95
95
  "@tanstack/react-table": "^9.3.1",
96
96
  "@wrksz/themes": "^2.1.1",
97
97
  "class-variance-authority": "^0.7.1",
@@ -115,7 +115,7 @@
115
115
  },
116
116
  "devDependencies": {
117
117
  "@tailwindcss/postcss": "^4.3.5",
118
- "@types/bun": "^1.4.4",
118
+ "@types/bun": "^1.4.5",
119
119
  "@types/node": "^26.6.6",
120
120
  "@types/react": "^19.3.0",
121
121
  "@types/react-dom": "^19.3.0",
@@ -133,7 +133,7 @@
133
133
  "zod": "^4.6.7",
134
134
  },
135
135
  "devDependencies": {
136
- "@types/bun": "^1.4.4",
136
+ "@types/bun": "^1.4.5",
137
137
  "typescript": "^7.0.2",
138
138
  },
139
139
  },
@@ -145,7 +145,7 @@
145
145
  "zod": "4.6.7",
146
146
  },
147
147
  "catalog": {
148
- "stitchkit": "^0.124.2",
148
+ "stitchkit": "^0.127.0",
149
149
  },
150
150
  "packages": {
151
151
  "@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 +584,9 @@
584
584
 
585
585
  "@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
586
 
587
- "@tanstack/query-core": ["@tanstack/query-core@5.108.0", "", {}, "sha512-X9zJUtEV/0D2q9pmGS/Bza8S4bNovSBhZOtdhtu0fzsHwizC6C+Eh/q5CX3MQBchsRMrirWVQmv7Fp4OStzV9g=="],
587
+ "@tanstack/query-core": ["@tanstack/query-core@5.108.4", "", {}, "sha512-2Ks5dlLWz4eXJrthOyG0qW3SLt3xx0RrQmAmN0rnmogiaaOYuWiAe6HAm9KE2b2v8nig+vraNz8fsfZ6fF6zFg=="],
588
588
 
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=="],
589
+ "@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
590
 
591
591
  "@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
592
 
@@ -596,7 +596,7 @@
596
596
 
597
597
  "@tanstack/table-core": ["@tanstack/table-core@9.3.1", "", { "dependencies": { "@tanstack/store": "^0.11.2" } }, "sha512-zQvlxSNi2qGM3L4jh85Z6hqMfdIR5qOfD9KHOU32nuKFJGN0RlJ7UvV1lsPb1fPVhpFYI0VP3jJGxLdLDpTKjQ=="],
598
598
 
599
- "@types/bun": ["@types/bun@1.4.4", "", { "dependencies": { "bun-types": "1.4.4" } }, "sha512-9wkRDXUXK124pEnAutE6n/l18j+i9GC5IAHK8TmX/2nlySETmky0OU6yL5U8pW1AoKh++AN9auDCr647BfurjQ=="],
599
+ "@types/bun": ["@types/bun@1.4.5", "", { "dependencies": { "bun-types": "1.4.5" } }, "sha512-DpgwNI9z0L1S0gtb45QLCWgwCUcMLnsHYMJHQvpNj7erGiCGBvpggltAIeARrtobNMKMuy0UP7i56tKKgwFs/Q=="],
600
600
 
601
601
  "@types/cors": ["@types/cors@2.8.19", "", { "dependencies": { "@types/node": "*" } }, "sha512-mFNylyeyqN93lfe/9CSxOGREz8cpzAhH+E93xJ4xWQf62V8sQ/24reV2nyzUWM6H6Xji+GGHpkbLe7pVoUEskg=="],
602
602
 
@@ -732,7 +732,7 @@
732
732
 
733
733
  "better-result": ["better-result@2.10.0", "", {}, "sha512-oQhh0y1qo2/ZKdAAEvHZAqKKiHOFU5k/bW96fE2ScgQOVkJRiHwB+nOS1SgFsYqRlxMDWvefXi9Q3px7QvgNDw=="],
734
734
 
735
- "bun-types": ["bun-types@1.4.4", "", { "dependencies": { "@types/node": "*", "undici-types": "*" } }, "sha512-yjrJh5oGX7mMPKGd19YXyIjmEuj4G4zNC30bs7PM9Az7NQ3ndF3j6hbeRdvJTRQEhJ/FYQwW0a2moweEi2hMxQ=="],
735
+ "bun-types": ["bun-types@1.4.5", "", { "dependencies": { "@types/node": "*", "undici-types": "*" } }, "sha512-ECHn+9dhL3wv0G6u0+7dQvrnaimXiRDxxerYBmhTaLyJEEuvTPWk2Fye3XIf5Y++JIIiHKfQw4Z7V5D8KuiXbg=="],
736
736
 
737
737
  "c12": ["c12@3.3.4", "", { "dependencies": { "chokidar": "^5.0.0", "confbox": "^0.2.4", "defu": "^6.1.6", "dotenv": "^17.3.1", "exsolve": "^1.0.8", "giget": "^3.2.0", "jiti": "^2.6.1", "ohash": "^2.0.11", "pathe": "^2.0.3", "perfect-debounce": "^2.1.0", "pkg-types": "^2.3.0", "rc9": "^3.0.1" }, "peerDependencies": { "magicast": "*" }, "optionalPeers": ["magicast"] }, "sha512-cM0ApFQSBXuourJejzwv/AuPRvAxordTyParRVcHjjtXirtkzM0uK2L9TTn9s0cXZbG7E55jCivRQzoxYmRAlA=="],
738
738
 
@@ -1126,7 +1126,7 @@
1126
1126
 
1127
1127
  "std-env": ["std-env@3.10.0", "", {}, "sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg=="],
1128
1128
 
1129
- "stitchkit": ["stitchkit@0.124.2", "", { "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-U8iXUsovUCUuOLF9klRSV81JfIMRL2KdTJeVRoCKpqxKBaBh5JsdBzVQ49om6OGZc4L7n4vM88129WFPFfqh/Q=="],
1129
+ "stitchkit": ["stitchkit@0.127.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-Bx0ZgKWOWWiit/OLmKXOJ5a4i40Wyn8DYd6/Jl82bOHcVhRL6FiTs7AAUIPmW39/Zl6modYyXz6BnUnUoK5m7A=="],
1130
1130
 
1131
1131
  "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
1132
 
@@ -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.124.2"
10
+ "stitchkit": "^0.127.0"
11
11
  },
12
12
  "overrides": {
13
13
  "@playwright/test": "1.65.1",
@@ -53,7 +53,7 @@
53
53
  "@biomejs/biome": "2.6.8",
54
54
  "@modelcontextprotocol/client": "^2.4.0",
55
55
  "@playwright/test": "^1.65.1",
56
- "@types/bun": "^1.4.4",
56
+ "@types/bun": "^1.4.5",
57
57
  "@types/node": "^26.6.6",
58
58
  "oxc-parser": "^0.159.0",
59
59
  "socket.io-client": "^4.8.4",
@@ -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
- "packageManager": "bun@1.4.4"
68
+ "packageManager": "bun@1.4.5"
69
69
  }
@@ -25,7 +25,7 @@
25
25
  "zod": "^4.6.7"
26
26
  },
27
27
  "devDependencies": {
28
- "@types/bun": "^1.4.4",
28
+ "@types/bun": "^1.4.5",
29
29
  "typescript": "^7.0.2"
30
30
  }
31
31
  }
@@ -11,6 +11,7 @@ try {
11
11
  name: appDeclaration.identity.slug,
12
12
  version: appDeclaration.identity.version,
13
13
  services,
14
+ access: { open: 'local-operator' },
14
15
  });
15
16
  } finally {
16
17
  await socket.close();
@@ -23,6 +23,9 @@ async function main(): Promise<void> {
23
23
  version: appDeclaration.identity.version,
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({
@@ -25,7 +25,9 @@ export function bindLive(board: BoardRuntime, handle: RealtimeServerHandle): Liv
25
25
  const hub = createWatchHub({
26
26
  // The hub does not dispatch; it asks the application. One reader for the
27
27
  // watched answer and the plain `GET` alike, so the two cannot disagree.
28
- read: async (operation) => {
28
+ // The request also carries a `signal` that aborts when the last watcher
29
+ // leaves; a read that calls the network or a slow query passes it on.
30
+ read: async ({ operation }) => {
29
31
  if (operation.action !== 'list') {
30
32
  throw new Error(`${operation.service}.${operation.action} is not readable here`);
31
33
  }
@@ -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(
@@ -21,7 +21,7 @@
21
21
  "zod": "^4.6.7"
22
22
  },
23
23
  "devDependencies": {
24
- "@types/bun": "^1.4.4",
24
+ "@types/bun": "^1.4.5",
25
25
  "typescript": "^7.0.2"
26
26
  }
27
27
  }
@@ -26,7 +26,7 @@
26
26
  "@radix-ui/react-tooltip": "^1.4.1",
27
27
  "@t3-oss/env-nextjs": "^0.13.11",
28
28
  "@tabler/icons-react": "^3.52.0",
29
- "@tanstack/react-query": "^5.108.0",
29
+ "@tanstack/react-query": "^5.108.4",
30
30
  "@tanstack/react-table": "^9.3.1",
31
31
  "@wrksz/themes": "^2.1.1",
32
32
  "class-variance-authority": "^0.7.1",
@@ -50,7 +50,7 @@
50
50
  },
51
51
  "devDependencies": {
52
52
  "@tailwindcss/postcss": "^4.3.5",
53
- "@types/bun": "^1.4.4",
53
+ "@types/bun": "^1.4.5",
54
54
  "@types/node": "^26.6.6",
55
55
  "@types/react": "^19.3.0",
56
56
  "@types/react-dom": "^19.3.0",
@@ -16,7 +16,7 @@
16
16
  "zod": "^4.6.7"
17
17
  },
18
18
  "devDependencies": {
19
- "@types/bun": "^1.4.4",
19
+ "@types/bun": "^1.4.5",
20
20
  "typescript": "^7.0.2"
21
21
  }
22
22
  }
@@ -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.
@@ -1,8 +1,20 @@
1
1
  import { describe, expect, test } from 'bun:test';
2
2
  import { readFileSync } from 'node:fs';
3
3
  import { resolve } from 'node:path';
4
+ import {
5
+ assertSurfaceDiscovery,
6
+ assertSurfaceManifestSnapshot,
7
+ SurfaceManifestSchema,
8
+ } from 'stitchkit/testing';
9
+ import { createSurface } from '../packages/backend/src/surface';
4
10
  import { appDeclaration } from '../packages/config/src/declaration';
5
11
  import { declaredRoleReadiness } from './readiness';
12
+ import {
13
+ buildAppSurfaceManifest,
14
+ discoverCliCommands,
15
+ discoverMcpTools,
16
+ SURFACE_SNAPSHOT_PATH,
17
+ } from './surface-snapshot';
6
18
  import { planPortabilityCheck } from './web-surface-smoke';
7
19
 
8
20
  const dialled = 'http://127.0.0.1:3210';
@@ -175,3 +187,40 @@ describe('a role is ready when it answers, not when it is spawned', () => {
175
187
  ).toThrow(/WEB_PORT/);
176
188
  });
177
189
  });
190
+
191
+ describe('committed surface snapshot', () => {
192
+ const root = resolve(import.meta.dir, '..');
193
+
194
+ test('the committed snapshot matches the live contract manifest', async () => {
195
+ const snapshot = SurfaceManifestSchema.parse(
196
+ JSON.parse(readFileSync(resolve(root, SURFACE_SNAPSHOT_PATH), 'utf8')),
197
+ );
198
+ const { services, socket, hub, board } = await createSurface();
199
+ try {
200
+ const manifest = buildAppSurfaceManifest(services);
201
+ expect(() => assertSurfaceManifestSnapshot(manifest, snapshot)).not.toThrow();
202
+ } finally {
203
+ await Promise.allSettled([hub.close(), board.close(), socket.close()]);
204
+ }
205
+ });
206
+
207
+ test('the CLI surface observed from the spawned process matches the committed snapshot', async () => {
208
+ const snapshot = SurfaceManifestSchema.parse(
209
+ JSON.parse(readFileSync(resolve(root, SURFACE_SNAPSHOT_PATH), 'utf8')),
210
+ );
211
+ const commands = await discoverCliCommands(root);
212
+ expect(() => assertSurfaceDiscovery(snapshot, { CLI: commands })).not.toThrow();
213
+ });
214
+
215
+ test('a broken /mcp endpoint rejects discovery even when zero tools are expected', async () => {
216
+ const broken = Bun.serve({
217
+ port: 0,
218
+ fetch: () => new Response('not the MCP endpoint', { status: 404 }),
219
+ });
220
+ try {
221
+ await expect(discoverMcpTools(`http://127.0.0.1:${broken.port}`)).rejects.toThrow();
222
+ } finally {
223
+ broken.stop(true);
224
+ }
225
+ });
226
+ });