@mycadet/assistant 0.12.10 → 0.13.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 (180) hide show
  1. package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/__tests__/ingress.test.ts +10 -10
  2. package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/ingress.ts +3 -3
  3. package/node_modules/@mycadet/ces-client/src/http-credentials.ts +18 -1
  4. package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/__tests__/ingress.test.ts +10 -10
  5. package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/ingress.ts +3 -3
  6. package/node_modules/@mycadet/gateway-client/src/gateway-ipc-contracts.ts +0 -20
  7. package/node_modules/@mycadet/service-contracts/src/__tests__/ingress.test.ts +10 -10
  8. package/node_modules/@mycadet/service-contracts/src/ingress.ts +3 -3
  9. package/openapi.yaml +2 -708
  10. package/package.json +2 -3
  11. package/scripts/sync-web-search-catalog.ts +1 -2
  12. package/src/__tests__/cloud-profile-guard.test.ts +41 -5
  13. package/src/__tests__/config-schema.test.ts +6 -38
  14. package/src/__tests__/conversation-queue.test.ts +45 -6
  15. package/src/__tests__/db-readiness-http-gate.test.ts +0 -6
  16. package/src/__tests__/persist-onboarding-artifacts.test.ts +0 -1
  17. package/src/__tests__/persona-resolver.test.ts +0 -51
  18. package/src/__tests__/provider-cloud-proxy-integration.test.ts +2 -110
  19. package/src/__tests__/run-due-schedules.test.ts +0 -4
  20. package/src/__tests__/schedule-store.test.ts +0 -12
  21. package/src/__tests__/stt-stream-session.test.ts +4 -4
  22. package/src/__tests__/telephony-tts-guard.test.ts +2 -50
  23. package/src/__tests__/voice-config-update.test.ts +12 -167
  24. package/src/__tests__/web-search-catalog-parity.test.ts +0 -2
  25. package/src/__tests__/workspace-migration-130-speech-mode-to-provider.test.ts +9 -7
  26. package/src/__tests__/workspace-migration-132-web-search-mode-to-provider.test.ts +6 -6
  27. package/src/calls/__tests__/voice-session-bridge.test.ts +1 -4
  28. package/src/calls/resolve-call-tts-provider.ts +6 -25
  29. package/src/calls/telephony-credential-preflight.ts +0 -10
  30. package/src/calls/telephony-tts-capability.ts +1 -17
  31. package/src/cli/commands/tts.ts +1 -2
  32. package/src/cli/index.help.ts +0 -2
  33. package/src/cli/program.ts +0 -2
  34. package/src/config/bundled-skills/settings/tools/voice-config-update.ts +4 -42
  35. package/src/config/schemas/__tests__/stt.test.ts +10 -14
  36. package/src/config/schemas/llm.ts +3 -5
  37. package/src/config/schemas/services.ts +5 -6
  38. package/src/config/schemas/stt.ts +1 -3
  39. package/src/config/schemas/tts.ts +1 -30
  40. package/src/daemon/daemon-readiness.ts +4 -29
  41. package/src/daemon/lifecycle.ts +0 -31
  42. package/src/daemon/providers-setup.ts +0 -8
  43. package/src/heartbeat/__tests__/heartbeat-service.test.ts +0 -1
  44. package/src/heartbeat/heartbeat-service.ts +1 -66
  45. package/src/ipc/__tests__/db-readiness-ipc-gate.test.ts +1 -9
  46. package/src/live-voice/__tests__/live-voice-credential-preflight.test.ts +0 -44
  47. package/src/live-voice/__tests__/live-voice-flux-turn-end.test.ts +4 -6
  48. package/src/live-voice/__tests__/live-voice-stt.test.ts +1 -1
  49. package/src/live-voice/live-voice-credential-preflight.ts +9 -33
  50. package/src/live-voice/live-voice-session.ts +10 -6
  51. package/src/live-voice/live-voice-tts.ts +1 -8
  52. package/src/plugins/defaults/memory/worker.ts +3 -3
  53. package/src/prompts/persona-resolver.ts +0 -35
  54. package/src/providers/__tests__/search-provider-catalog.test.ts +5 -8
  55. package/src/providers/__tests__/voice-error-copy.test.ts +9 -10
  56. package/src/providers/search-provider-catalog.ts +7 -39
  57. package/src/providers/speech-to-text/__tests__/provider-catalog.test.ts +3 -47
  58. package/src/providers/speech-to-text/__tests__/resolve.test.ts +6 -372
  59. package/src/providers/speech-to-text/provider-catalog.ts +2 -73
  60. package/src/providers/speech-to-text/resolve.ts +3 -120
  61. package/src/runtime/http-router-types.ts +1 -3
  62. package/src/runtime/http-server.ts +1 -1
  63. package/src/runtime/routes/__tests__/conversation-query-routes.test.ts +13 -11
  64. package/src/runtime/routes/__tests__/tts-routes.test.ts +2 -6
  65. package/src/runtime/routes/conversation-query-routes.ts +0 -96
  66. package/src/runtime/routes/inbound-stages/transcribe-audio.test.ts +7 -7
  67. package/src/runtime/routes/index.ts +0 -4
  68. package/src/runtime/routes/live-voice-routes.test.ts +4 -11
  69. package/src/runtime/routes/live-voice-routes.ts +8 -11
  70. package/src/runtime/routes/secret-routes.ts +0 -6
  71. package/src/runtime/routes/tts-routes.ts +0 -38
  72. package/src/schedule/__tests__/plugin-schedule-reconciler.test.ts +1 -7
  73. package/src/schedule/__tests__/worker-mcp-readiness.test.ts +0 -4
  74. package/src/schedule/schedule-store.ts +0 -7
  75. package/src/schedule/scheduler.ts +0 -5
  76. package/src/schedule/worker.ts +1 -1
  77. package/src/stt/__tests__/daemon-batch-transcriber.test.ts +2 -10
  78. package/src/stt/daemon-batch-transcriber.ts +4 -38
  79. package/src/stt/types.ts +1 -9
  80. package/src/tools/network/__tests__/web-search.test.ts +3 -250
  81. package/src/tools/network/web-search.ts +4 -165
  82. package/src/tts/__tests__/provider-resolution.test.ts +0 -5
  83. package/src/tts/provider-catalog.ts +0 -4
  84. package/src/tts/types.ts +0 -1
  85. package/src/__tests__/cloud-speech-defaults.test.ts +0 -330
  86. package/src/__tests__/migration-cross-version-compatibility.test.ts +0 -1708
  87. package/src/__tests__/migration-export-http.test.ts +0 -557
  88. package/src/__tests__/migration-export-streaming.test.ts +0 -350
  89. package/src/__tests__/migration-export-to-gcs.test.ts +0 -706
  90. package/src/__tests__/migration-import-commit-http.test.ts +0 -1176
  91. package/src/__tests__/migration-import-from-gcs.test.ts +0 -534
  92. package/src/__tests__/migration-import-from-path.test.ts +0 -324
  93. package/src/__tests__/migration-import-from-url.test.ts +0 -588
  94. package/src/__tests__/migration-import-preflight-http.test.ts +0 -739
  95. package/src/__tests__/migration-jobs-status.test.ts +0 -139
  96. package/src/__tests__/migration-parity-persistence.test.ts +0 -1891
  97. package/src/__tests__/migration-transport.test.ts +0 -1089
  98. package/src/__tests__/migration-validate-http.test.ts +0 -634
  99. package/src/__tests__/migration-wizard.test.ts +0 -1395
  100. package/src/__tests__/rebind-secrets-screen.test.ts +0 -876
  101. package/src/__tests__/sanitize-config-for-transfer.test.ts +0 -259
  102. package/src/__tests__/transfer-progress-screen.test.ts +0 -1217
  103. package/src/__tests__/validation-results-screen.test.ts +0 -1130
  104. package/src/__tests__/vbundle-pax-and-symlink.test.ts +0 -147
  105. package/src/background-wake/background-wake-routes.test.ts +0 -906
  106. package/src/background-wake/cloud-client.test.ts +0 -328
  107. package/src/background-wake/cloud-client.ts +0 -196
  108. package/src/background-wake/next-wake.test.ts +0 -335
  109. package/src/background-wake/next-wake.ts +0 -188
  110. package/src/background-wake/publisher.ts +0 -93
  111. package/src/background-wake/wake-intent-hooks.test.ts +0 -234
  112. package/src/cli/commands/__tests__/backup.test.ts +0 -363
  113. package/src/cli/commands/backup.help.ts +0 -180
  114. package/src/cli/commands/backup.ts +0 -398
  115. package/src/cloud/cloud-speech.test.ts +0 -335
  116. package/src/cloud/cloud-speech.ts +0 -300
  117. package/src/config/cloud-speech-defaults.ts +0 -300
  118. package/src/config/sanitize-for-transfer.ts +0 -111
  119. package/src/live-voice/__tests__/live-voice-cloud-speech-fallback.test.ts +0 -250
  120. package/src/providers/speech-to-text/__tests__/cadet-cloud-realtime.test.ts +0 -457
  121. package/src/providers/speech-to-text/__tests__/cadet-cloud.test.ts +0 -271
  122. package/src/providers/speech-to-text/__tests__/cadet-speech-relay-connection.test.ts +0 -126
  123. package/src/providers/speech-to-text/cadet-cloud-flux-realtime.ts +0 -309
  124. package/src/providers/speech-to-text/cadet-cloud-realtime.ts +0 -315
  125. package/src/providers/speech-to-text/cadet-cloud.ts +0 -108
  126. package/src/providers/speech-to-text/cadet-speech-relay-connection.ts +0 -176
  127. package/src/runtime/migrations/__tests__/gcs-signed-url.test.ts +0 -254
  128. package/src/runtime/migrations/__tests__/job-registry.test.ts +0 -346
  129. package/src/runtime/migrations/__tests__/origin-mode.test.ts +0 -62
  130. package/src/runtime/migrations/__tests__/rebind-secrets-credentials.test.ts +0 -184
  131. package/src/runtime/migrations/__tests__/staged-import-path.test.ts +0 -110
  132. package/src/runtime/migrations/__tests__/v1-test-helpers.ts +0 -112
  133. package/src/runtime/migrations/__tests__/vbundle-builder-credentials.test.ts +0 -285
  134. package/src/runtime/migrations/__tests__/vbundle-builder-fd-leak.test.ts +0 -126
  135. package/src/runtime/migrations/__tests__/vbundle-builder-v1-shape.test.ts +0 -253
  136. package/src/runtime/migrations/__tests__/vbundle-import-credentials.test.ts +0 -208
  137. package/src/runtime/migrations/__tests__/vbundle-import-parity.test.ts +0 -485
  138. package/src/runtime/migrations/__tests__/vbundle-import-policy.test.ts +0 -349
  139. package/src/runtime/migrations/__tests__/vbundle-import-version-compat.test.ts +0 -196
  140. package/src/runtime/migrations/__tests__/vbundle-legacy-user-md.test.ts +0 -551
  141. package/src/runtime/migrations/__tests__/vbundle-metadata-merge-integration.test.ts +0 -428
  142. package/src/runtime/migrations/__tests__/vbundle-metadata-merge.test.ts +0 -220
  143. package/src/runtime/migrations/__tests__/vbundle-streaming-importer.test.ts +0 -1823
  144. package/src/runtime/migrations/__tests__/vbundle-streaming-validator.test.ts +0 -598
  145. package/src/runtime/migrations/__tests__/vbundle-symlink-importer.test.ts +0 -463
  146. package/src/runtime/migrations/__tests__/vbundle-symlink-streaming-importer.test.ts +0 -538
  147. package/src/runtime/migrations/__tests__/vbundle-symlink-streaming.test.ts +0 -515
  148. package/src/runtime/migrations/__tests__/vbundle-symlink-tar.test.ts +0 -453
  149. package/src/runtime/migrations/__tests__/vbundle-symlink-walker.test.ts +0 -319
  150. package/src/runtime/migrations/__tests__/vbundle-tar-stream.test.ts +0 -240
  151. package/src/runtime/migrations/__tests__/vbundle-validator-v1-schema.test.ts +0 -473
  152. package/src/runtime/migrations/gcs-signed-url.ts +0 -190
  153. package/src/runtime/migrations/job-registry.ts +0 -297
  154. package/src/runtime/migrations/migration-transport.ts +0 -612
  155. package/src/runtime/migrations/migration-wizard.ts +0 -747
  156. package/src/runtime/migrations/origin-mode.ts +0 -42
  157. package/src/runtime/migrations/rebind-secrets-screen.ts +0 -412
  158. package/src/runtime/migrations/staged-import-path.ts +0 -116
  159. package/src/runtime/migrations/transfer-progress-screen.ts +0 -323
  160. package/src/runtime/migrations/validation-results-screen.ts +0 -469
  161. package/src/runtime/migrations/vbundle-builder.ts +0 -1382
  162. package/src/runtime/migrations/vbundle-import-analyzer.ts +0 -405
  163. package/src/runtime/migrations/vbundle-import-policy.ts +0 -241
  164. package/src/runtime/migrations/vbundle-importer.ts +0 -826
  165. package/src/runtime/migrations/vbundle-metadata-merge.ts +0 -113
  166. package/src/runtime/migrations/vbundle-streaming-importer.ts +0 -2844
  167. package/src/runtime/migrations/vbundle-streaming-validator.ts +0 -426
  168. package/src/runtime/migrations/vbundle-tar-stream.ts +0 -244
  169. package/src/runtime/migrations/vbundle-validator.ts +0 -724
  170. package/src/runtime/routes/__tests__/migration-cadet-metadata-reconcile.test.ts +0 -227
  171. package/src/runtime/routes/__tests__/migration-export-secrets-redacted.test.ts +0 -54
  172. package/src/runtime/routes/__tests__/migration-import-allowed-hosts-env.test.ts +0 -70
  173. package/src/runtime/routes/__tests__/migration-import-credential-filter.test.ts +0 -257
  174. package/src/runtime/routes/background-wake-routes.ts +0 -387
  175. package/src/runtime/routes/migration-routes.ts +0 -2584
  176. package/src/tools/network/__tests__/cloud-search-proxy.test.ts +0 -282
  177. package/src/tools/network/cloud-search-proxy.ts +0 -211
  178. package/src/tts/__tests__/cadet-provider.test.ts +0 -253
  179. package/src/tts/providers/cadet-provider.ts +0 -244
  180. package/src/types/tar-stream.d.ts +0 -66
@@ -1,324 +0,0 @@
1
- /**
2
- * HTTP tests for JSON `{ path }` on POST /v1/migrations/import and
3
- * POST /v1/migrations/import-preflight.
4
- *
5
- * The daemon only opens a regular `.vbundle` that realpath-resolves
6
- * under `${workspace}/.restore-staging/`.
7
- */
8
-
9
- import {
10
- existsSync,
11
- mkdirSync,
12
- mkdtempSync,
13
- realpathSync,
14
- rmSync,
15
- symlinkSync,
16
- writeFileSync,
17
- } from "node:fs";
18
- import { tmpdir } from "node:os";
19
- import { join } from "node:path";
20
- import {
21
- afterAll,
22
- afterEach,
23
- beforeEach,
24
- describe,
25
- expect,
26
- test,
27
- } from "bun:test";
28
-
29
- process.env.DISABLE_HTTP_AUTH = "true";
30
-
31
- import { defaultV1Options } from "../runtime/migrations/__tests__/v1-test-helpers.js";
32
- import { RESTORE_STAGING_DIRNAME } from "../runtime/migrations/staged-import-path.js";
33
- import { buildVBundle } from "../runtime/migrations/vbundle-builder.js";
34
- import {
35
- handleMigrationImport,
36
- handleMigrationImportPreflight,
37
- } from "../runtime/routes/migration-routes.js";
38
- import { callHandler } from "./helpers/call-route-handler.js";
39
-
40
- const originalWorkspaceDir = process.env.CADET_WORKSPACE_DIR;
41
-
42
- function freshWorkspaceRoot(): string {
43
- const parent = realpathSync(
44
- mkdtempSync(join(tmpdir(), "migration-import-from-path-")),
45
- );
46
- const workspaceDir = join(parent, "workspace");
47
- mkdirSync(workspaceDir, { recursive: true });
48
- return workspaceDir;
49
- }
50
-
51
- function setWorkspaceDir(dir: string): void {
52
- process.env.CADET_WORKSPACE_DIR = dir;
53
- }
54
-
55
- function makeSmallValidBundle(): Uint8Array {
56
- const { archive } = buildVBundle({
57
- files: [
58
- {
59
- path: "workspace/data/db/assistant.db",
60
- data: new TextEncoder().encode("SQLite format 3\0"),
61
- },
62
- {
63
- path: "workspace/config.json",
64
- data: new TextEncoder().encode(
65
- JSON.stringify({ provider: "anthropic", model: "test-model" }),
66
- ),
67
- },
68
- ],
69
- ...defaultV1Options(),
70
- });
71
- return archive;
72
- }
73
-
74
- function stageBundle(workspaceDir: string, archive: Uint8Array): string {
75
- const staging = join(workspaceDir, RESTORE_STAGING_DIRNAME);
76
- mkdirSync(staging, { recursive: true });
77
- const filename = "backup.vbundle";
78
- writeFileSync(join(staging, filename), archive);
79
- return `${RESTORE_STAGING_DIRNAME}/${filename}`;
80
- }
81
-
82
- interface ImportCommitResponse {
83
- success: boolean;
84
- summary: {
85
- total_files: number;
86
- files_created: number;
87
- files_overwritten: number;
88
- files_skipped: number;
89
- backups_created: number;
90
- };
91
- files: Array<{ path: string }>;
92
- manifest: Record<string, unknown>;
93
- }
94
-
95
- interface PreflightResponse {
96
- can_import: boolean;
97
- summary?: {
98
- files_to_create: number;
99
- files_to_overwrite: number;
100
- files_unchanged: number;
101
- total_files: number;
102
- };
103
- validation?: { is_valid: false; errors: Array<{ code: string }> };
104
- }
105
-
106
- interface BadRequestResponse {
107
- error: { code: string; message: string };
108
- }
109
-
110
- let testWorkspaceRoot: string;
111
- let testParent: string;
112
-
113
- beforeEach(() => {
114
- testWorkspaceRoot = freshWorkspaceRoot();
115
- testParent = join(testWorkspaceRoot, "..");
116
- setWorkspaceDir(testWorkspaceRoot);
117
- });
118
-
119
- afterEach(() => {
120
- try {
121
- rmSync(testParent, { recursive: true, force: true });
122
- } catch {
123
- /* best effort */
124
- }
125
- });
126
-
127
- afterAll(() => {
128
- if (originalWorkspaceDir !== undefined) {
129
- process.env.CADET_WORKSPACE_DIR = originalWorkspaceDir;
130
- } else {
131
- delete process.env.CADET_WORKSPACE_DIR;
132
- }
133
- });
134
-
135
- describe("handleMigrationImport — JSON {path} body", () => {
136
- test("happy path: streams a staged .vbundle and imports it", async () => {
137
- const relativePath = stageBundle(testWorkspaceRoot, makeSmallValidBundle());
138
-
139
- const req = new Request("http://localhost/v1/migrations/import", {
140
- method: "POST",
141
- headers: { "Content-Type": "application/json" },
142
- body: JSON.stringify({ path: relativePath }),
143
- });
144
-
145
- const res = await callHandler(handleMigrationImport, req);
146
- const body = (await res.json()) as ImportCommitResponse;
147
-
148
- expect(res.status).toBe(200);
149
- expect(body.success).toBe(true);
150
- expect(body.summary.total_files).toBeGreaterThan(0);
151
- expect(body.files.length).toBeGreaterThan(0);
152
- expect(
153
- existsSync(join(testWorkspaceRoot, "data", "db", "assistant.db")),
154
- ).toBe(true);
155
- expect(existsSync(join(testWorkspaceRoot, "config.json"))).toBe(true);
156
- });
157
-
158
- test("absolute path inside staging is accepted", async () => {
159
- const relativePath = stageBundle(testWorkspaceRoot, makeSmallValidBundle());
160
- const absolutePath = join(testWorkspaceRoot, relativePath);
161
-
162
- const req = new Request("http://localhost/v1/migrations/import", {
163
- method: "POST",
164
- headers: { "Content-Type": "application/json" },
165
- body: JSON.stringify({ path: absolutePath }),
166
- });
167
-
168
- const res = await callHandler(handleMigrationImport, req);
169
- expect(res.status).toBe(200);
170
- const body = (await res.json()) as ImportCommitResponse;
171
- expect(body.success).toBe(true);
172
- });
173
-
174
- test("both url and path returns 400", async () => {
175
- const req = new Request("http://localhost/v1/migrations/import", {
176
- method: "POST",
177
- headers: { "Content-Type": "application/json" },
178
- body: JSON.stringify({
179
- url: "https://storage.googleapis.com/b/o?X-Goog-Signature=x",
180
- path: `${RESTORE_STAGING_DIRNAME}/backup.vbundle`,
181
- }),
182
- });
183
-
184
- const res = await callHandler(handleMigrationImport, req);
185
- const body = (await res.json()) as BadRequestResponse;
186
-
187
- expect(res.status).toBe(400);
188
- expect(body.error.code).toBe("BAD_REQUEST");
189
- expect(body.error.message).toContain("exactly one");
190
- });
191
-
192
- test("missing staged file returns 400", async () => {
193
- const req = new Request("http://localhost/v1/migrations/import", {
194
- method: "POST",
195
- headers: { "Content-Type": "application/json" },
196
- body: JSON.stringify({
197
- path: `${RESTORE_STAGING_DIRNAME}/missing.vbundle`,
198
- }),
199
- });
200
-
201
- const res = await callHandler(handleMigrationImport, req);
202
- const body = (await res.json()) as BadRequestResponse;
203
-
204
- expect(res.status).toBe(400);
205
- expect(body.error.code).toBe("BAD_REQUEST");
206
- expect(body.error.message.toLowerCase()).toContain("not found");
207
- });
208
-
209
- test("traversal out of staging returns 400", async () => {
210
- writeFileSync(join(testWorkspaceRoot, "secret.vbundle"), "nope");
211
-
212
- const req = new Request("http://localhost/v1/migrations/import", {
213
- method: "POST",
214
- headers: { "Content-Type": "application/json" },
215
- body: JSON.stringify({
216
- path: `${RESTORE_STAGING_DIRNAME}/../secret.vbundle`,
217
- }),
218
- });
219
-
220
- const res = await callHandler(handleMigrationImport, req);
221
- const body = (await res.json()) as BadRequestResponse;
222
-
223
- expect(res.status).toBe(400);
224
- expect(body.error.code).toBe("BAD_REQUEST");
225
- expect(body.error.message.toLowerCase()).toContain("staging");
226
- });
227
-
228
- test("path outside the workspace returns 400", async () => {
229
- const outside = join(testParent, "outside.vbundle");
230
- writeFileSync(outside, "nope");
231
-
232
- const req = new Request("http://localhost/v1/migrations/import", {
233
- method: "POST",
234
- headers: { "Content-Type": "application/json" },
235
- body: JSON.stringify({ path: outside }),
236
- });
237
-
238
- const res = await callHandler(handleMigrationImport, req);
239
- const body = (await res.json()) as BadRequestResponse;
240
-
241
- expect(res.status).toBe(400);
242
- expect(body.error.code).toBe("BAD_REQUEST");
243
- expect(body.error.message.toLowerCase()).toContain("staging");
244
- });
245
-
246
- test("symlink in staging returns 400", async () => {
247
- const relativePath = stageBundle(testWorkspaceRoot, makeSmallValidBundle());
248
- const target = join(testWorkspaceRoot, relativePath);
249
- const link = join(
250
- testWorkspaceRoot,
251
- RESTORE_STAGING_DIRNAME,
252
- "alias.vbundle",
253
- );
254
- symlinkSync(target, link);
255
-
256
- const req = new Request("http://localhost/v1/migrations/import", {
257
- method: "POST",
258
- headers: { "Content-Type": "application/json" },
259
- body: JSON.stringify({
260
- path: `${RESTORE_STAGING_DIRNAME}/alias.vbundle`,
261
- }),
262
- });
263
-
264
- const res = await callHandler(handleMigrationImport, req);
265
- const body = (await res.json()) as BadRequestResponse;
266
-
267
- expect(res.status).toBe(400);
268
- expect(body.error.code).toBe("BAD_REQUEST");
269
- expect(body.error.message.toLowerCase()).toContain("symlink");
270
- });
271
- });
272
-
273
- describe("handleMigrationImportPreflight — JSON {path} body", () => {
274
- test("happy path: analyzes a staged .vbundle without writing files", async () => {
275
- const relativePath = stageBundle(testWorkspaceRoot, makeSmallValidBundle());
276
-
277
- const req = new Request("http://localhost/v1/migrations/import-preflight", {
278
- method: "POST",
279
- headers: { "Content-Type": "application/json" },
280
- body: JSON.stringify({ path: relativePath }),
281
- });
282
-
283
- const res = await callHandler(handleMigrationImportPreflight, req);
284
- const body = (await res.json()) as PreflightResponse;
285
-
286
- expect(res.status).toBe(200);
287
- expect(body.can_import).toBe(true);
288
- expect(body.summary?.total_files).toBeGreaterThan(0);
289
- expect(existsSync(join(testWorkspaceRoot, "config.json"))).toBe(false);
290
- });
291
-
292
- test("empty path returns 400", async () => {
293
- const req = new Request("http://localhost/v1/migrations/import-preflight", {
294
- method: "POST",
295
- headers: { "Content-Type": "application/json" },
296
- body: JSON.stringify({ path: "" }),
297
- });
298
-
299
- const res = await callHandler(handleMigrationImportPreflight, req);
300
- const body = (await res.json()) as BadRequestResponse;
301
-
302
- expect(res.status).toBe(400);
303
- expect(body.error.code).toBe("BAD_REQUEST");
304
- });
305
-
306
- test("non-.vbundle staging file returns 400", async () => {
307
- const staging = join(testWorkspaceRoot, RESTORE_STAGING_DIRNAME);
308
- mkdirSync(staging, { recursive: true });
309
- writeFileSync(join(staging, "notes.txt"), "nope");
310
-
311
- const req = new Request("http://localhost/v1/migrations/import-preflight", {
312
- method: "POST",
313
- headers: { "Content-Type": "application/json" },
314
- body: JSON.stringify({ path: `${RESTORE_STAGING_DIRNAME}/notes.txt` }),
315
- });
316
-
317
- const res = await callHandler(handleMigrationImportPreflight, req);
318
- const body = (await res.json()) as BadRequestResponse;
319
-
320
- expect(res.status).toBe(400);
321
- expect(body.error.code).toBe("BAD_REQUEST");
322
- expect(body.error.message.toLowerCase()).toContain(".vbundle");
323
- });
324
- });