@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,126 +0,0 @@
1
- /**
2
- * Regression test for descriptor hygiene in the vbundle export path.
3
- *
4
- * `streamExportVBundle` opens every file in the workspace twice — once to hash
5
- * it (Pass 1) and once to stream it into the tar (Pass 2). This test pins the
6
- * invariant that those reads release their descriptors: the number of open
7
- * descriptors held by the process must not grow proportionally to the number
8
- * of files exported. Without that guarantee a workspace-sized export exhausts
9
- * the daemon's descriptor limit (EMFILE) and every subsequent subprocess spawn
10
- * fails.
11
- *
12
- * Descriptor counting uses `/proc/self/fd`, which only exists on Linux. The
13
- * assertion is skipped on platforms without it (e.g. macOS dev machines); CI
14
- * runs on Linux, so the regression stays covered there.
15
- */
16
-
17
- import {
18
- existsSync,
19
- mkdirSync,
20
- readdirSync,
21
- rmSync,
22
- writeFileSync,
23
- } from "node:fs";
24
- import { tmpdir } from "node:os";
25
- import { join } from "node:path";
26
- import { describe, expect, test } from "bun:test";
27
-
28
- import { assertNotLiveDb } from "../../../__tests__/assert-not-live-db.js";
29
- import { streamExportVBundle } from "../vbundle-builder.js";
30
- import { defaultV1Options } from "./v1-test-helpers.js";
31
-
32
- const PROC_SELF_FD = "/proc/self/fd";
33
- const hasProcFd = existsSync(PROC_SELF_FD);
34
-
35
- /** Count the descriptors currently open by this process. */
36
- function openFdCount(): number {
37
- return readdirSync(PROC_SELF_FD).length;
38
- }
39
-
40
- /**
41
- * Build a workspace with enough distinct files (across nested directories) that
42
- * a per-file descriptor leak would be obvious against the assertion bound.
43
- */
44
- function createPopulatedWorkspace(fileCount: number): {
45
- dir: string;
46
- cleanup: () => void;
47
- } {
48
- const dir = join(
49
- tmpdir(),
50
- `vbundle-fd-leak-${Date.now()}-${Math.random().toString(36).slice(2)}`,
51
- );
52
- mkdirSync(dir, { recursive: true });
53
- writeFileSync(join(dir, "config.json"), JSON.stringify({ test: true }));
54
- const dbDir = join(dir, "data", "db");
55
- mkdirSync(dbDir, { recursive: true });
56
- writeFileSync(join(dbDir, "assistant.db"), "fake-db-content");
57
-
58
- // A spread of files under a few nested directories, each with non-trivial
59
- // (multi-chunk) content so the read loop iterates more than once.
60
- const filler = "x".repeat(200 * 1024);
61
- for (let i = 0; i < fileCount; i++) {
62
- const sub = join(dir, "data", "files", `dir-${i % 5}`);
63
- mkdirSync(sub, { recursive: true });
64
- writeFileSync(join(sub, `file-${i}.txt`), `${filler}\n${i}`);
65
- }
66
-
67
- return {
68
- dir,
69
- cleanup: () => {
70
- assertNotLiveDb(dir);
71
- rmSync(dir, { recursive: true, force: true });
72
- },
73
- };
74
- }
75
-
76
- describe("streamExportVBundle — descriptor lifecycle", () => {
77
- test.skipIf(!hasProcFd)(
78
- "does not leak a file descriptor per exported file",
79
- async () => {
80
- const fileCount = 60;
81
- const workspace = createPopulatedWorkspace(fileCount);
82
-
83
- // Warm-up export: first run can open and cache descriptors that legitimately
84
- // persist (loggers, the daemon DB, etc.). Measuring the delta around a
85
- // second export isolates per-file leakage from one-time setup.
86
- let warmup: Awaited<ReturnType<typeof streamExportVBundle>> | undefined;
87
- try {
88
- warmup = await streamExportVBundle({
89
- workspaceDir: workspace.dir,
90
- ...defaultV1Options(),
91
- });
92
- } finally {
93
- await warmup?.cleanup();
94
- }
95
-
96
- const before = openFdCount();
97
-
98
- let result: Awaited<ReturnType<typeof streamExportVBundle>> | undefined;
99
- try {
100
- result = await streamExportVBundle({
101
- workspaceDir: workspace.dir,
102
- ...defaultV1Options(),
103
- });
104
- // Manifest covers every file we wrote — proves the walk actually read
105
- // them (otherwise a no-op export would trivially leak nothing).
106
- expect(result.manifest.contents.length).toBeGreaterThanOrEqual(
107
- fileCount,
108
- );
109
- } finally {
110
- await result?.cleanup();
111
- workspace.cleanup();
112
- }
113
-
114
- const after = openFdCount();
115
- const delta = after - before;
116
-
117
- // Each export reads 2×fileCount files (hash pass + tar pass). A per-file
118
- // leak would push the delta past `fileCount`. Allow a small constant for
119
- // incidental descriptors (temp output file already cleaned up, jitter).
120
- expect(delta).toBeLessThan(8);
121
- },
122
- // Two full exports of a multi-megabyte workspace (hash pass + tar pass each)
123
- // do real disk I/O; the default 5s budget is tight under loaded CI runners.
124
- 30_000,
125
- );
126
- });
@@ -1,253 +0,0 @@
1
- /**
2
- * Verifies that the buffered (`buildVBundle` / `buildExportVBundle`) and
3
- * streaming (`streamExportVBundle`) emit paths both produce manifests
4
- * conforming to the canonical v1 ten-field shape.
5
- *
6
- * Drift between the two emit paths is exactly how the prior schema
7
- * mismatch went unnoticed — these tests pin both paths to the same shape
8
- * and run a round-trip through `validateVBundle` so any future
9
- * canonicalization drift fails loudly.
10
- */
11
-
12
- import { createHash } from "node:crypto";
13
- import { mkdirSync, rmSync, writeFileSync } from "node:fs";
14
- import { tmpdir } from "node:os";
15
- import { join } from "node:path";
16
- import { gunzipSync } from "node:zlib";
17
- import { describe, expect, test } from "bun:test";
18
-
19
- import {
20
- buildExportVBundle,
21
- buildVBundle,
22
- streamExportVBundle,
23
- } from "../vbundle-builder.js";
24
- import { canonicalizeJson, validateVBundle } from "../vbundle-validator.js";
25
- import { defaultV1Options } from "./v1-test-helpers.js";
26
-
27
- function sha256Hex(data: Uint8Array | string): string {
28
- return createHash("sha256").update(data).digest("hex");
29
- }
30
-
31
- function createTestWorkspace(): { dir: string; cleanup: () => void } {
32
- const dir = join(
33
- tmpdir(),
34
- `vbundle-v1-shape-${Date.now()}-${Math.random().toString(36).slice(2)}`,
35
- );
36
- mkdirSync(dir, { recursive: true });
37
- writeFileSync(join(dir, "config.json"), JSON.stringify({ test: true }));
38
- const dbDir = join(dir, "data", "db");
39
- mkdirSync(dbDir, { recursive: true });
40
- writeFileSync(join(dbDir, "assistant.db"), "fake-db-content");
41
- return {
42
- dir,
43
- cleanup: () => rmSync(dir, { recursive: true, force: true }),
44
- };
45
- }
46
-
47
- const UUID_V4_RE =
48
- /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
49
- const ISO_8601_RE =
50
- /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{2}:\d{2})$/;
51
- const SHA256_HEX_RE = /^[0-9a-f]{64}$/;
52
-
53
- describe("buildVBundle — v1 ten-field manifest shape", () => {
54
- test("emits all ten required top-level fields with correct types", () => {
55
- const { manifest } = buildVBundle({
56
- files: [
57
- {
58
- path: "data/db/assistant.db",
59
- data: new TextEncoder().encode("db-bytes"),
60
- },
61
- ],
62
- ...defaultV1Options(),
63
- });
64
-
65
- expect(manifest.schema_version).toBe(1);
66
- expect(typeof manifest.bundle_id).toBe("string");
67
- expect(manifest.bundle_id).toMatch(UUID_V4_RE);
68
- expect(manifest.created_at).toMatch(ISO_8601_RE);
69
- expect(manifest.assistant.id).toBe("self");
70
- expect(manifest.assistant.name).toBe("Test");
71
- expect(manifest.assistant.runtime_version).toBe("0.0.0-test");
72
- expect(manifest.origin.mode).toBe("self-hosted-local");
73
- expect(manifest.compatibility.min_runtime_version).toBe("0.0.0-test");
74
- expect(manifest.compatibility.max_runtime_version).toBeNull();
75
- expect(Array.isArray(manifest.contents)).toBe(true);
76
- expect(manifest.contents.length).toBeGreaterThan(0);
77
- expect(manifest.checksum).toMatch(SHA256_HEX_RE);
78
- expect(typeof manifest.secrets_redacted).toBe("boolean");
79
- expect(typeof manifest.export_options.include_logs).toBe("boolean");
80
- });
81
-
82
- test("contents always declares data/db/assistant.db when the input includes it", () => {
83
- const { manifest } = buildVBundle({
84
- files: [
85
- {
86
- path: "data/db/assistant.db",
87
- data: new TextEncoder().encode("db-bytes"),
88
- },
89
- {
90
- path: "config/settings.json",
91
- data: new TextEncoder().encode("{}"),
92
- },
93
- ],
94
- ...defaultV1Options(),
95
- });
96
-
97
- const dbEntry = manifest.contents.find(
98
- (f) => f.path === "data/db/assistant.db",
99
- );
100
- expect(dbEntry).toBeDefined();
101
- expect(dbEntry!.size_bytes).toBe(
102
- new TextEncoder().encode("db-bytes").length,
103
- );
104
- });
105
-
106
- test("checksum is the sha256 of the canonicalized manifest with checksum=''", () => {
107
- const { manifest } = buildVBundle({
108
- files: [
109
- {
110
- path: "data/db/assistant.db",
111
- data: new TextEncoder().encode("db-bytes"),
112
- },
113
- ],
114
- ...defaultV1Options(),
115
- });
116
-
117
- const expected = sha256Hex(canonicalizeJson({ ...manifest, checksum: "" }));
118
- expect(manifest.checksum).toBe(expected);
119
- });
120
-
121
- test("secrets_redacted reflects the input flag", () => {
122
- const truthy = buildVBundle({
123
- files: [
124
- {
125
- path: "data/db/assistant.db",
126
- data: new TextEncoder().encode("db-bytes"),
127
- },
128
- ],
129
- ...defaultV1Options(),
130
- secretsRedacted: true,
131
- });
132
- expect(truthy.manifest.secrets_redacted).toBe(true);
133
-
134
- const falsey = buildVBundle({
135
- files: [
136
- {
137
- path: "data/db/assistant.db",
138
- data: new TextEncoder().encode("db-bytes"),
139
- },
140
- ],
141
- ...defaultV1Options(),
142
- secretsRedacted: false,
143
- });
144
- expect(falsey.manifest.secrets_redacted).toBe(false);
145
- });
146
-
147
- test("bundle_id is a fresh UUID per export", () => {
148
- const a = buildVBundle({
149
- files: [
150
- {
151
- path: "data/db/assistant.db",
152
- data: new TextEncoder().encode("db-bytes"),
153
- },
154
- ],
155
- ...defaultV1Options(),
156
- });
157
- const b = buildVBundle({
158
- files: [
159
- {
160
- path: "data/db/assistant.db",
161
- data: new TextEncoder().encode("db-bytes"),
162
- },
163
- ],
164
- ...defaultV1Options(),
165
- });
166
- expect(a.manifest.bundle_id).not.toBe(b.manifest.bundle_id);
167
- });
168
- });
169
-
170
- describe("streamExportVBundle — v1 ten-field manifest shape", () => {
171
- test("matches buildExportVBundle's manifest shape (modulo bundle_id and created_at)", async () => {
172
- const workspace = createTestWorkspace();
173
- let streamResult:
174
- | Awaited<ReturnType<typeof streamExportVBundle>>
175
- | undefined;
176
- try {
177
- const sync = buildExportVBundle({
178
- workspaceDir: workspace.dir,
179
- ...defaultV1Options(),
180
- });
181
- streamResult = await streamExportVBundle({
182
- workspaceDir: workspace.dir,
183
- ...defaultV1Options(),
184
- });
185
-
186
- expect(streamResult.manifest.schema_version).toBe(
187
- sync.manifest.schema_version,
188
- );
189
- expect(streamResult.manifest.assistant).toEqual(sync.manifest.assistant);
190
- expect(streamResult.manifest.origin).toEqual(sync.manifest.origin);
191
- expect(streamResult.manifest.compatibility).toEqual(
192
- sync.manifest.compatibility,
193
- );
194
- expect(streamResult.manifest.export_options).toEqual(
195
- sync.manifest.export_options,
196
- );
197
- expect(streamResult.manifest.secrets_redacted).toBe(
198
- sync.manifest.secrets_redacted,
199
- );
200
-
201
- // Same set of files (paths + sha + size).
202
- const sortByPath = (a: { path: string }, b: { path: string }) =>
203
- a.path.localeCompare(b.path);
204
- expect(streamResult.manifest.contents.slice().sort(sortByPath)).toEqual(
205
- sync.manifest.contents.slice().sort(sortByPath),
206
- );
207
- } finally {
208
- await streamResult?.cleanup();
209
- workspace.cleanup();
210
- }
211
- });
212
- });
213
-
214
- describe("buildExportVBundle round-trip", () => {
215
- test("validateVBundle accepts the buffered emit", () => {
216
- const workspace = createTestWorkspace();
217
- try {
218
- const result = buildExportVBundle({
219
- workspaceDir: workspace.dir,
220
- ...defaultV1Options(),
221
- });
222
- const validation = validateVBundle(result.archive);
223
- expect(validation.is_valid).toBe(true);
224
- expect(validation.errors).toHaveLength(0);
225
- expect(validation.manifest?.checksum).toBe(result.manifest.checksum);
226
- } finally {
227
- workspace.cleanup();
228
- }
229
- });
230
-
231
- test("validateVBundle accepts the streaming emit", async () => {
232
- const workspace = createTestWorkspace();
233
- let result: Awaited<ReturnType<typeof streamExportVBundle>> | undefined;
234
- try {
235
- result = await streamExportVBundle({
236
- workspaceDir: workspace.dir,
237
- ...defaultV1Options(),
238
- });
239
- const archive = new Uint8Array(
240
- await Bun.file(result.tempPath).arrayBuffer(),
241
- );
242
- // Sanity: archive is valid gzip of a tar.
243
- expect(gunzipSync(archive).length).toBeGreaterThan(0);
244
- const validation = validateVBundle(archive);
245
- expect(validation.is_valid).toBe(true);
246
- expect(validation.errors).toHaveLength(0);
247
- expect(validation.manifest?.checksum).toBe(result.manifest.checksum);
248
- } finally {
249
- await result?.cleanup();
250
- workspace.cleanup();
251
- }
252
- });
253
- });
@@ -1,208 +0,0 @@
1
- /**
2
- * Tests for credential import from vbundle archives.
3
- *
4
- * Covers:
5
- * - extractCredentialsFromBundle() correctly extracts credential entries
6
- * - DefaultPathResolver skips credentials/ paths (not written to disk)
7
- * - Empty and missing credential entries are handled gracefully
8
- */
9
-
10
- import { describe, expect, test } from "bun:test";
11
-
12
- import { DefaultPathResolver } from "../vbundle-import-analyzer.js";
13
- import { extractCredentialsFromBundle } from "../vbundle-importer.js";
14
- import type { ManifestType, VBundleTarEntry } from "../vbundle-validator.js";
15
-
16
- // ---------------------------------------------------------------------------
17
- // Helpers
18
- // ---------------------------------------------------------------------------
19
-
20
- function makeTarEntry(data: string): VBundleTarEntry {
21
- const encoded = new TextEncoder().encode(data);
22
- return { name: "", data: encoded, size: encoded.length };
23
- }
24
-
25
- function makeManifest(paths: string[]): ManifestType {
26
- return {
27
- schema_version: 1,
28
- bundle_id: "00000000-0000-4000-8000-000000000000",
29
- created_at: new Date().toISOString(),
30
- assistant: { id: "self", name: "Test", runtime_version: "0.0.0-test" },
31
- origin: { mode: "self-hosted-local" },
32
- compatibility: {
33
- min_runtime_version: "0.0.0-test",
34
- max_runtime_version: null,
35
- },
36
- contents: paths.map((path) => ({
37
- path,
38
- size_bytes: 0,
39
- sha256: "test",
40
- })),
41
- checksum:
42
- "0000000000000000000000000000000000000000000000000000000000000000",
43
- secrets_redacted: false,
44
- export_options: {
45
- include_logs: false,
46
- include_browser_state: false,
47
- include_memory_vectors: false,
48
- },
49
- } as unknown as ManifestType;
50
- }
51
-
52
- // ---------------------------------------------------------------------------
53
- // extractCredentialsFromBundle
54
- // ---------------------------------------------------------------------------
55
-
56
- describe("extractCredentialsFromBundle", () => {
57
- test("extracts credential entries from tar entries map", () => {
58
- const entries = new Map<string, VBundleTarEntry>();
59
- entries.set("credentials/openai-key", makeTarEntry("sk-test-123"));
60
- entries.set("credentials/anthropic-key", makeTarEntry("sk-ant-456"));
61
- entries.set("workspace/config.json", makeTarEntry('{"test": true}'));
62
- entries.set("manifest.json", makeTarEntry("{}"));
63
-
64
- const manifest = makeManifest([
65
- "credentials/openai-key",
66
- "credentials/anthropic-key",
67
- "workspace/config.json",
68
- ]);
69
- const credentials = extractCredentialsFromBundle(entries, manifest);
70
-
71
- expect(credentials).toHaveLength(2);
72
- expect(credentials).toContainEqual({
73
- account: "openai-key",
74
- value: "sk-test-123",
75
- });
76
- expect(credentials).toContainEqual({
77
- account: "anthropic-key",
78
- value: "sk-ant-456",
79
- });
80
- });
81
-
82
- test("returns empty array when no credential entries exist", () => {
83
- const entries = new Map<string, VBundleTarEntry>();
84
- entries.set("workspace/config.json", makeTarEntry('{"test": true}'));
85
- entries.set("manifest.json", makeTarEntry("{}"));
86
-
87
- const manifest = makeManifest(["workspace/config.json"]);
88
- const credentials = extractCredentialsFromBundle(entries, manifest);
89
-
90
- expect(credentials).toHaveLength(0);
91
- });
92
-
93
- test("returns empty array for empty entries map", () => {
94
- const entries = new Map<string, VBundleTarEntry>();
95
-
96
- const manifest = makeManifest([]);
97
- const credentials = extractCredentialsFromBundle(entries, manifest);
98
-
99
- expect(credentials).toHaveLength(0);
100
- });
101
-
102
- test("skips bare credentials/ path with no account name", () => {
103
- const entries = new Map<string, VBundleTarEntry>();
104
- entries.set("credentials/", makeTarEntry("some-value"));
105
- entries.set("credentials/valid-key", makeTarEntry("valid-secret"));
106
-
107
- const manifest = makeManifest(["credentials/", "credentials/valid-key"]);
108
- const credentials = extractCredentialsFromBundle(entries, manifest);
109
-
110
- expect(credentials).toHaveLength(1);
111
- expect(credentials[0]).toEqual({
112
- account: "valid-key",
113
- value: "valid-secret",
114
- });
115
- });
116
-
117
- test("ignores credential entries not declared in manifest", () => {
118
- const entries = new Map<string, VBundleTarEntry>();
119
- entries.set("credentials/declared-key", makeTarEntry("declared-secret"));
120
- entries.set(
121
- "credentials/undeclared-key",
122
- makeTarEntry("undeclared-secret"),
123
- );
124
-
125
- const manifest = makeManifest(["credentials/declared-key"]);
126
- const credentials = extractCredentialsFromBundle(entries, manifest);
127
-
128
- expect(credentials).toHaveLength(1);
129
- expect(credentials[0]).toEqual({
130
- account: "declared-key",
131
- value: "declared-secret",
132
- });
133
- });
134
-
135
- test("handles credential values with special characters", () => {
136
- const entries = new Map<string, VBundleTarEntry>();
137
- entries.set(
138
- "credentials/complex-key",
139
- makeTarEntry("value with spaces & special=chars!"),
140
- );
141
-
142
- const manifest = makeManifest(["credentials/complex-key"]);
143
- const credentials = extractCredentialsFromBundle(entries, manifest);
144
-
145
- expect(credentials).toHaveLength(1);
146
- expect(credentials[0]).toEqual({
147
- account: "complex-key",
148
- value: "value with spaces & special=chars!",
149
- });
150
- });
151
-
152
- test("extracts cadet:-prefixed credentials (filtering happens in migration-routes)", () => {
153
- const entries = new Map<string, VBundleTarEntry>();
154
- entries.set("credentials/cadet:assistant_api_key", makeTarEntry("key-123"));
155
- entries.set(
156
- "credentials/cadet:platform_assistant_id",
157
- makeTarEntry("asst-456"),
158
- );
159
- entries.set("credentials/openai-key", makeTarEntry("sk-user-789"));
160
-
161
- const manifest = makeManifest([
162
- "credentials/cadet:assistant_api_key",
163
- "credentials/cadet:platform_assistant_id",
164
- "credentials/openai-key",
165
- ]);
166
- const credentials = extractCredentialsFromBundle(entries, manifest);
167
-
168
- // extractCredentialsFromBundle does NOT filter — it returns all credentials.
169
- // Filtering of cadet:* platform credentials is done in migration-routes.ts.
170
- expect(credentials).toHaveLength(3);
171
- expect(credentials).toContainEqual({
172
- account: "cadet:assistant_api_key",
173
- value: "key-123",
174
- });
175
- expect(credentials).toContainEqual({
176
- account: "cadet:platform_assistant_id",
177
- value: "asst-456",
178
- });
179
- expect(credentials).toContainEqual({
180
- account: "openai-key",
181
- value: "sk-user-789",
182
- });
183
- });
184
- });
185
-
186
- // ---------------------------------------------------------------------------
187
- // DefaultPathResolver — credential path skipping
188
- // ---------------------------------------------------------------------------
189
-
190
- describe("DefaultPathResolver skips credential paths", () => {
191
- test("resolve() returns null for credentials/ paths", () => {
192
- const resolver = new DefaultPathResolver("/tmp/workspace", "/tmp/hooks");
193
-
194
- expect(resolver.resolve("credentials/openai-key")).toBeNull();
195
- expect(resolver.resolve("credentials/anthropic-key")).toBeNull();
196
- expect(resolver.resolve("credentials/")).toBeNull();
197
- });
198
-
199
- test("resolve() still resolves non-credential paths normally", () => {
200
- const resolver = new DefaultPathResolver("/tmp/workspace", "/tmp/hooks");
201
-
202
- // workspace/ paths should resolve
203
- expect(resolver.resolve("workspace/config.json")).not.toBeNull();
204
-
205
- // data/db should resolve
206
- expect(resolver.resolve("data/db/assistant.db")).not.toBeNull();
207
- });
208
- });