create-stitchkit 0.6.23 → 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.
package/template/bun.lock CHANGED
@@ -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",
@@ -145,7 +145,7 @@
145
145
  "zod": "4.6.7",
146
146
  },
147
147
  "catalog": {
148
- "stitchkit": "^0.126.0",
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
 
@@ -1126,7 +1126,7 @@
1126
1126
 
1127
1127
  "std-env": ["std-env@3.10.0", "", {}, "sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg=="],
1128
1128
 
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=="],
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.126.0"
10
+ "stitchkit": "^0.127.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
  }
@@ -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({
@@ -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(
@@ -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",
@@ -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
+ });
@@ -2,7 +2,7 @@ import { systemContract } from '@app/shared';
2
2
  import { createClient, createHttpClient } from 'stitchkit';
3
3
  import { z } from 'zod';
4
4
  import { assertDeploymentIsAnswering } from './deployment-preflight';
5
- import { runSurfaceConformance } from './surface-conformance';
5
+ import { assertLiveSurface } from './surface-snapshot';
6
6
  import { loadToolingEnv } from './tooling-env';
7
7
  import { assertArtifactIsPlacementFree, assertPublicWebSurface } from './web-surface-smoke';
8
8
 
@@ -37,7 +37,7 @@ if (!Object.keys(openApi.paths).includes('/api/system/status')) {
37
37
  throw new Error('System status contract is missing from OpenAPI');
38
38
  }
39
39
 
40
- await runSurfaceConformance({ apiOrigin });
40
+ await assertLiveSurface(apiOrigin);
41
41
  await assertPublicWebSurface(toolingEnv.SMOKE_WEB_ORIGIN);
42
42
  await assertArtifactIsPlacementFree(toolingEnv.SMOKE_WEB_ORIGIN, {
43
43
  origin: toolingEnv.PUBLIC_WEB_ORIGIN,