swallowkit 1.0.0-beta.6 → 1.0.0-beta.60

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 (296) hide show
  1. package/README.ja.md +86 -177
  2. package/README.md +86 -178
  3. package/dist/__tests__/fixtures.d.ts +12 -0
  4. package/dist/__tests__/fixtures.d.ts.map +1 -1
  5. package/dist/__tests__/fixtures.js +101 -0
  6. package/dist/__tests__/fixtures.js.map +1 -1
  7. package/dist/cli/commands/add-auth.d.ts +15 -0
  8. package/dist/cli/commands/add-auth.d.ts.map +1 -0
  9. package/dist/cli/commands/add-auth.js +790 -0
  10. package/dist/cli/commands/add-auth.js.map +1 -0
  11. package/dist/cli/commands/add-connector.d.ts +20 -0
  12. package/dist/cli/commands/add-connector.d.ts.map +1 -0
  13. package/dist/cli/commands/add-connector.js +163 -0
  14. package/dist/cli/commands/add-connector.js.map +1 -0
  15. package/dist/cli/commands/cosmos-worktree-isolation.d.ts +25 -0
  16. package/dist/cli/commands/cosmos-worktree-isolation.d.ts.map +1 -0
  17. package/dist/cli/commands/cosmos-worktree-isolation.js +124 -0
  18. package/dist/cli/commands/cosmos-worktree-isolation.js.map +1 -0
  19. package/dist/cli/commands/create-model.d.ts +1 -4
  20. package/dist/cli/commands/create-model.d.ts.map +1 -1
  21. package/dist/cli/commands/create-model.js +19 -81
  22. package/dist/cli/commands/create-model.js.map +1 -1
  23. package/dist/cli/commands/dev-seeds.d.ts +62 -0
  24. package/dist/cli/commands/dev-seeds.d.ts.map +1 -0
  25. package/dist/cli/commands/dev-seeds.js +474 -0
  26. package/dist/cli/commands/dev-seeds.js.map +1 -0
  27. package/dist/cli/commands/dev.d.ts +38 -0
  28. package/dist/cli/commands/dev.d.ts.map +1 -1
  29. package/dist/cli/commands/dev.js +733 -155
  30. package/dist/cli/commands/dev.js.map +1 -1
  31. package/dist/cli/commands/index.d.ts +1 -0
  32. package/dist/cli/commands/index.d.ts.map +1 -1
  33. package/dist/cli/commands/index.js +3 -1
  34. package/dist/cli/commands/index.js.map +1 -1
  35. package/dist/cli/commands/init.d.ts +78 -0
  36. package/dist/cli/commands/init.d.ts.map +1 -1
  37. package/dist/cli/commands/init.js +1453 -898
  38. package/dist/cli/commands/init.js.map +1 -1
  39. package/dist/cli/commands/scaffold.d.ts +24 -0
  40. package/dist/cli/commands/scaffold.d.ts.map +1 -1
  41. package/dist/cli/commands/scaffold.js +473 -90
  42. package/dist/cli/commands/scaffold.js.map +1 -1
  43. package/dist/cli/index.d.ts +5 -1
  44. package/dist/cli/index.d.ts.map +1 -1
  45. package/dist/cli/index.js +333 -55
  46. package/dist/cli/index.js.map +1 -1
  47. package/dist/core/config.d.ts +14 -3
  48. package/dist/core/config.d.ts.map +1 -1
  49. package/dist/core/config.js +179 -8
  50. package/dist/core/config.js.map +1 -1
  51. package/dist/core/mock/connector-mock-server.d.ts +101 -0
  52. package/dist/core/mock/connector-mock-server.d.ts.map +1 -0
  53. package/dist/core/mock/connector-mock-server.js +480 -0
  54. package/dist/core/mock/connector-mock-server.js.map +1 -0
  55. package/dist/core/mock/zod-mock-generator.d.ts +14 -0
  56. package/dist/core/mock/zod-mock-generator.d.ts.map +1 -0
  57. package/dist/core/mock/zod-mock-generator.js +163 -0
  58. package/dist/core/mock/zod-mock-generator.js.map +1 -0
  59. package/dist/core/operations/auth-operations.d.ts +61 -0
  60. package/dist/core/operations/auth-operations.d.ts.map +1 -0
  61. package/dist/core/operations/auth-operations.js +272 -0
  62. package/dist/core/operations/auth-operations.js.map +1 -0
  63. package/dist/core/operations/create-model.d.ts +15 -0
  64. package/dist/core/operations/create-model.d.ts.map +1 -0
  65. package/dist/core/operations/create-model.js +185 -0
  66. package/dist/core/operations/create-model.js.map +1 -0
  67. package/dist/core/operations/file-session.d.ts +56 -0
  68. package/dist/core/operations/file-session.d.ts.map +1 -0
  69. package/dist/core/operations/file-session.js +203 -0
  70. package/dist/core/operations/file-session.js.map +1 -0
  71. package/dist/core/operations/provision-operations.d.ts +52 -0
  72. package/dist/core/operations/provision-operations.d.ts.map +1 -0
  73. package/dist/core/operations/provision-operations.js +211 -0
  74. package/dist/core/operations/provision-operations.js.map +1 -0
  75. package/dist/core/operations/runtime.d.ts +37 -0
  76. package/dist/core/operations/runtime.d.ts.map +1 -0
  77. package/dist/core/operations/runtime.js +248 -0
  78. package/dist/core/operations/runtime.js.map +1 -0
  79. package/dist/core/operations/scaffold-apply.d.ts +21 -0
  80. package/dist/core/operations/scaffold-apply.d.ts.map +1 -0
  81. package/dist/core/operations/scaffold-apply.js +57 -0
  82. package/dist/core/operations/scaffold-apply.js.map +1 -0
  83. package/dist/core/operations/scaffold-machine.d.ts +16 -0
  84. package/dist/core/operations/scaffold-machine.d.ts.map +1 -0
  85. package/dist/core/operations/scaffold-machine.js +51 -0
  86. package/dist/core/operations/scaffold-machine.js.map +1 -0
  87. package/dist/core/operations/scaffold-plan.d.ts +43 -0
  88. package/dist/core/operations/scaffold-plan.d.ts.map +1 -0
  89. package/dist/core/operations/scaffold-plan.js +187 -0
  90. package/dist/core/operations/scaffold-plan.js.map +1 -0
  91. package/dist/core/project/agent-instructions.d.ts +29 -0
  92. package/dist/core/project/agent-instructions.d.ts.map +1 -0
  93. package/dist/core/project/agent-instructions.js +159 -0
  94. package/dist/core/project/agent-instructions.js.map +1 -0
  95. package/dist/core/project/artifacts.d.ts +58 -0
  96. package/dist/core/project/artifacts.d.ts.map +1 -0
  97. package/dist/core/project/artifacts.js +179 -0
  98. package/dist/core/project/artifacts.js.map +1 -0
  99. package/dist/core/project/boundaries.d.ts +50 -0
  100. package/dist/core/project/boundaries.d.ts.map +1 -0
  101. package/dist/core/project/boundaries.js +117 -0
  102. package/dist/core/project/boundaries.js.map +1 -0
  103. package/dist/core/project/capabilities.d.ts +58 -0
  104. package/dist/core/project/capabilities.d.ts.map +1 -0
  105. package/dist/core/project/capabilities.js +135 -0
  106. package/dist/core/project/capabilities.js.map +1 -0
  107. package/dist/core/project/drift.d.ts +29 -0
  108. package/dist/core/project/drift.d.ts.map +1 -0
  109. package/dist/core/project/drift.js +188 -0
  110. package/dist/core/project/drift.js.map +1 -0
  111. package/dist/core/project/infra.d.ts +49 -0
  112. package/dist/core/project/infra.d.ts.map +1 -0
  113. package/dist/core/project/infra.js +167 -0
  114. package/dist/core/project/infra.js.map +1 -0
  115. package/dist/core/project/manifest.d.ts +92 -0
  116. package/dist/core/project/manifest.d.ts.map +1 -0
  117. package/dist/core/project/manifest.js +321 -0
  118. package/dist/core/project/manifest.js.map +1 -0
  119. package/dist/core/project/state.d.ts +15 -0
  120. package/dist/core/project/state.d.ts.map +1 -0
  121. package/dist/core/project/state.js +106 -0
  122. package/dist/core/project/state.js.map +1 -0
  123. package/dist/core/project/validation.d.ts +20 -0
  124. package/dist/core/project/validation.d.ts.map +1 -0
  125. package/dist/core/project/validation.js +274 -0
  126. package/dist/core/project/validation.js.map +1 -0
  127. package/dist/core/project/workflows.d.ts +43 -0
  128. package/dist/core/project/workflows.d.ts.map +1 -0
  129. package/dist/core/project/workflows.js +299 -0
  130. package/dist/core/project/workflows.js.map +1 -0
  131. package/dist/core/scaffold/auth-generator.d.ts +63 -0
  132. package/dist/core/scaffold/auth-generator.d.ts.map +1 -0
  133. package/dist/core/scaffold/auth-generator.js +1774 -0
  134. package/dist/core/scaffold/auth-generator.js.map +1 -0
  135. package/dist/core/scaffold/connector-functions-generator.d.ts +41 -0
  136. package/dist/core/scaffold/connector-functions-generator.d.ts.map +1 -0
  137. package/dist/core/scaffold/connector-functions-generator.js +1029 -0
  138. package/dist/core/scaffold/connector-functions-generator.js.map +1 -0
  139. package/dist/core/scaffold/functions-generator.d.ts +7 -1
  140. package/dist/core/scaffold/functions-generator.d.ts.map +1 -1
  141. package/dist/core/scaffold/functions-generator.js +771 -69
  142. package/dist/core/scaffold/functions-generator.js.map +1 -1
  143. package/dist/core/scaffold/model-parser.d.ts +21 -1
  144. package/dist/core/scaffold/model-parser.d.ts.map +1 -1
  145. package/dist/core/scaffold/model-parser.js +243 -43
  146. package/dist/core/scaffold/model-parser.js.map +1 -1
  147. package/dist/core/scaffold/native-schema-generator.d.ts +19 -0
  148. package/dist/core/scaffold/native-schema-generator.d.ts.map +1 -0
  149. package/dist/core/scaffold/native-schema-generator.js +753 -0
  150. package/dist/core/scaffold/native-schema-generator.js.map +1 -0
  151. package/dist/core/scaffold/nextjs-generator.d.ts +8 -0
  152. package/dist/core/scaffold/nextjs-generator.d.ts.map +1 -1
  153. package/dist/core/scaffold/nextjs-generator.js +153 -9
  154. package/dist/core/scaffold/nextjs-generator.js.map +1 -1
  155. package/dist/core/scaffold/openapi-generator.d.ts +3 -0
  156. package/dist/core/scaffold/openapi-generator.d.ts.map +1 -0
  157. package/dist/core/scaffold/openapi-generator.js +190 -0
  158. package/dist/core/scaffold/openapi-generator.js.map +1 -0
  159. package/dist/core/scaffold/ui-generator.d.ts +17 -4
  160. package/dist/core/scaffold/ui-generator.d.ts.map +1 -1
  161. package/dist/core/scaffold/ui-generator.js +174 -34
  162. package/dist/core/scaffold/ui-generator.js.map +1 -1
  163. package/dist/core/verify/index.d.ts +69 -0
  164. package/dist/core/verify/index.d.ts.map +1 -0
  165. package/dist/core/verify/index.js +412 -0
  166. package/dist/core/verify/index.js.map +1 -0
  167. package/dist/database/base-model.d.ts +3 -3
  168. package/dist/database/base-model.js +3 -3
  169. package/dist/index.d.ts +2 -2
  170. package/dist/index.d.ts.map +1 -1
  171. package/dist/index.js +2 -1
  172. package/dist/index.js.map +1 -1
  173. package/dist/machine/contracts.d.ts +24 -0
  174. package/dist/machine/contracts.d.ts.map +1 -0
  175. package/dist/machine/contracts.js +3 -0
  176. package/dist/machine/contracts.js.map +1 -0
  177. package/dist/machine/errors.d.ts +14 -0
  178. package/dist/machine/errors.d.ts.map +1 -0
  179. package/dist/machine/errors.js +42 -0
  180. package/dist/machine/errors.js.map +1 -0
  181. package/dist/machine/index.d.ts +3 -0
  182. package/dist/machine/index.d.ts.map +1 -0
  183. package/dist/machine/index.js +566 -0
  184. package/dist/machine/index.js.map +1 -0
  185. package/dist/mcp/index.d.ts +25 -0
  186. package/dist/mcp/index.d.ts.map +1 -0
  187. package/dist/mcp/index.js +425 -0
  188. package/dist/mcp/index.js.map +1 -0
  189. package/dist/types/index.d.ts +109 -0
  190. package/dist/types/index.d.ts.map +1 -1
  191. package/dist/utils/package-manager.d.ts +5 -2
  192. package/dist/utils/package-manager.d.ts.map +1 -1
  193. package/dist/utils/package-manager.js +30 -9
  194. package/dist/utils/package-manager.js.map +1 -1
  195. package/dist/utils/python-uv.d.ts +21 -0
  196. package/dist/utils/python-uv.d.ts.map +1 -0
  197. package/dist/utils/python-uv.js +111 -0
  198. package/dist/utils/python-uv.js.map +1 -0
  199. package/dist/version.d.ts +2 -0
  200. package/dist/version.d.ts.map +1 -0
  201. package/dist/version.js +49 -0
  202. package/dist/version.js.map +1 -0
  203. package/package.json +9 -5
  204. package/src/__tests__/__snapshots__/functions-generator.test.ts.snap +1139 -0
  205. package/src/__tests__/__snapshots__/nextjs-generator.test.ts.snap +206 -0
  206. package/src/__tests__/__snapshots__/ui-generator.test.ts.snap +532 -0
  207. package/src/__tests__/agent-instructions.test.ts +237 -0
  208. package/src/__tests__/agent-loop-phase34.test.ts +513 -0
  209. package/src/__tests__/auth.test.ts +770 -0
  210. package/src/__tests__/bff-swa-auth.test.ts +275 -0
  211. package/src/__tests__/config.test.ts +295 -0
  212. package/src/__tests__/connector-functions-generator.test.ts +288 -0
  213. package/src/__tests__/connector-mock-server.test.ts +439 -0
  214. package/src/__tests__/connector-model-bff.test.ts +162 -0
  215. package/src/__tests__/cosmos-worktree-isolation.test.ts +149 -0
  216. package/src/__tests__/dev-seeds.test.ts +236 -0
  217. package/src/__tests__/dev.test.ts +296 -0
  218. package/src/__tests__/file-session.test.ts +98 -0
  219. package/src/__tests__/fixtures.ts +184 -0
  220. package/src/__tests__/functions-generator.test.ts +237 -0
  221. package/src/__tests__/init.test.ts +411 -0
  222. package/src/__tests__/jest-globals.d.ts +8 -0
  223. package/src/__tests__/machine.test.ts +371 -0
  224. package/src/__tests__/mcp.test.ts +253 -0
  225. package/src/__tests__/model-parser.test.ts +81 -0
  226. package/src/__tests__/multi-auth.test.ts +160 -0
  227. package/src/__tests__/nextjs-generator.test.ts +105 -0
  228. package/src/__tests__/openapi-generator.test.ts +43 -0
  229. package/src/__tests__/package-manager.test.ts +227 -0
  230. package/src/__tests__/plan-apply.test.ts +499 -0
  231. package/src/__tests__/python-uv.test.ts +48 -0
  232. package/src/__tests__/scaffold.test.ts +302 -0
  233. package/src/__tests__/string-utils.test.ts +75 -0
  234. package/src/__tests__/tsconfig.json +15 -0
  235. package/src/__tests__/ui-generator.test.ts +248 -0
  236. package/src/__tests__/zod-mock-generator.test.ts +132 -0
  237. package/src/cli/commands/add-auth.ts +853 -0
  238. package/src/cli/commands/add-connector.ts +158 -0
  239. package/src/cli/commands/cosmos-worktree-isolation.ts +130 -0
  240. package/src/cli/commands/create-model.ts +62 -0
  241. package/src/cli/commands/dev-seeds.ts +629 -0
  242. package/src/cli/commands/dev.ts +1252 -0
  243. package/src/cli/commands/index.ts +9 -0
  244. package/src/cli/commands/init.ts +3541 -0
  245. package/src/cli/commands/provision.ts +193 -0
  246. package/src/cli/commands/scaffold.ts +1081 -0
  247. package/src/cli/index.ts +350 -0
  248. package/src/core/config.ts +380 -0
  249. package/src/core/mock/connector-mock-server.ts +555 -0
  250. package/src/core/mock/zod-mock-generator.ts +205 -0
  251. package/src/core/operations/auth-operations.ts +360 -0
  252. package/src/core/operations/create-model.ts +191 -0
  253. package/src/core/operations/file-session.ts +222 -0
  254. package/src/core/operations/provision-operations.ts +297 -0
  255. package/src/core/operations/runtime.ts +258 -0
  256. package/src/core/operations/scaffold-apply.ts +106 -0
  257. package/src/core/operations/scaffold-machine.ts +77 -0
  258. package/src/core/operations/scaffold-plan.ts +215 -0
  259. package/src/core/project/agent-instructions.ts +167 -0
  260. package/src/core/project/agent-templates/AGENTS.md +502 -0
  261. package/src/core/project/agent-templates/CLAUDE.md +31 -0
  262. package/src/core/project/agent-templates/azure-functions.instructions.md +22 -0
  263. package/src/core/project/agent-templates/bff-routes.instructions.md +18 -0
  264. package/src/core/project/agent-templates/copilot-instructions.md +27 -0
  265. package/src/core/project/agent-templates/shared-models.instructions.md +72 -0
  266. package/src/core/project/artifacts.ts +205 -0
  267. package/src/core/project/boundaries.ts +170 -0
  268. package/src/core/project/capabilities.ts +193 -0
  269. package/src/core/project/drift.ts +202 -0
  270. package/src/core/project/infra.ts +196 -0
  271. package/src/core/project/manifest.ts +402 -0
  272. package/src/core/project/state.ts +77 -0
  273. package/src/core/project/validation.ts +295 -0
  274. package/src/core/project/workflows.ts +295 -0
  275. package/src/core/scaffold/auth-generator.ts +1824 -0
  276. package/src/core/scaffold/connector-functions-generator.ts +1133 -0
  277. package/src/core/scaffold/functions-generator.ts +972 -0
  278. package/src/core/scaffold/model-parser.ts +854 -0
  279. package/src/core/scaffold/native-schema-generator.ts +904 -0
  280. package/src/core/scaffold/nextjs-generator.ts +382 -0
  281. package/src/core/scaffold/openapi-generator.ts +212 -0
  282. package/src/core/scaffold/ui-generator.ts +1100 -0
  283. package/src/core/verify/index.ts +468 -0
  284. package/src/database/base-model.ts +184 -0
  285. package/src/database/client.ts +140 -0
  286. package/src/database/repository.ts +104 -0
  287. package/src/database/runtime-check.ts +25 -0
  288. package/src/index.ts +27 -0
  289. package/src/machine/contracts.ts +33 -0
  290. package/src/machine/errors.ts +45 -0
  291. package/src/machine/index.ts +690 -0
  292. package/src/mcp/index.ts +423 -0
  293. package/src/types/index.ts +182 -0
  294. package/src/utils/package-manager.ts +246 -0
  295. package/src/utils/python-uv.ts +96 -0
  296. package/src/version.ts +13 -0
@@ -0,0 +1,149 @@
1
+ import * as fs from "fs";
2
+ import * as os from "os";
3
+ import * as path from "path";
4
+ import {
5
+ createWorktreePathHash,
6
+ resolveCosmosDatabaseNameForWorktree,
7
+ resolveGitWorktreeInfo,
8
+ } from "../cli/commands/cosmos-worktree-isolation";
9
+
10
+ describe("Cosmos DB worktree isolation", () => {
11
+ let tempDir: string;
12
+
13
+ beforeEach(() => {
14
+ tempDir = fs.mkdtempSync(
15
+ path.join(os.tmpdir(), "swallowkit-worktree-isolation-")
16
+ );
17
+ });
18
+
19
+ afterEach(() => {
20
+ fs.rmSync(tempDir, { recursive: true, force: true });
21
+ });
22
+
23
+ it("keeps the base database name in the main worktree", () => {
24
+ const mainRoot = path.join(tempDir, "main");
25
+ const gitDir = path.join(mainRoot, ".git");
26
+ fs.mkdirSync(gitDir, { recursive: true });
27
+ const runGit = jest.fn(() => [mainRoot, gitDir, ".git"].join("\n"));
28
+
29
+ const result = resolveCosmosDatabaseNameForWorktree(
30
+ "MyAppDatabase",
31
+ mainRoot,
32
+ runGit
33
+ );
34
+
35
+ expect(runGit).toHaveBeenCalledWith(
36
+ [
37
+ "rev-parse",
38
+ "--show-toplevel",
39
+ "--absolute-git-dir",
40
+ "--git-common-dir",
41
+ ],
42
+ mainRoot
43
+ );
44
+ expect(result).toEqual({
45
+ databaseName: "MyAppDatabase",
46
+ worktreeIsolationEnabled: false,
47
+ });
48
+ });
49
+
50
+ it("adds an eight-character path hash in a linked worktree", () => {
51
+ const { linkedRoot, gitDir, commonDir } = createLinkedWorktreePaths("one");
52
+
53
+ const result = resolveCosmosDatabaseNameForWorktree(
54
+ "MyAppDatabase",
55
+ linkedRoot,
56
+ () => [linkedRoot, gitDir, commonDir].join("\n")
57
+ );
58
+
59
+ expect(result.worktreeIsolationEnabled).toBe(true);
60
+ expect(result.databaseName).toMatch(/^MyAppDatabase_[a-f0-9]{8}$/);
61
+ expect(result.databaseName).toBe(
62
+ `MyAppDatabase_${createWorktreePathHash(linkedRoot)}`
63
+ );
64
+ });
65
+
66
+ it("generates the same hash for repeated resolution of one worktree", () => {
67
+ const { linkedRoot, gitDir, commonDir } =
68
+ createLinkedWorktreePaths("stable");
69
+ const runGit = () => [linkedRoot, gitDir, commonDir].join("\n");
70
+
71
+ const first = resolveCosmosDatabaseNameForWorktree(
72
+ "MyAppDatabase",
73
+ linkedRoot,
74
+ runGit
75
+ );
76
+ const second = resolveCosmosDatabaseNameForWorktree(
77
+ "MyAppDatabase",
78
+ linkedRoot,
79
+ runGit
80
+ );
81
+
82
+ expect(second.databaseName).toBe(first.databaseName);
83
+ });
84
+
85
+ it("generates different hashes for different worktree roots", () => {
86
+ const firstRoot = path.join(tempDir, "linked-one");
87
+ const secondRoot = path.join(tempDir, "linked-two");
88
+ fs.mkdirSync(firstRoot);
89
+ fs.mkdirSync(secondRoot);
90
+
91
+ expect(createWorktreePathHash(firstRoot)).not.toBe(
92
+ createWorktreePathHash(secondRoot)
93
+ );
94
+ });
95
+
96
+ it("uses the worktree root when invoked from a subdirectory", () => {
97
+ const { linkedRoot, gitDir, commonDir } =
98
+ createLinkedWorktreePaths("nested");
99
+ const nestedDir = path.join(linkedRoot, "apps", "web");
100
+ fs.mkdirSync(nestedDir, { recursive: true });
101
+ const runGit = () => [linkedRoot, gitDir, commonDir].join("\n");
102
+
103
+ const fromRoot = resolveCosmosDatabaseNameForWorktree(
104
+ "MyAppDatabase",
105
+ linkedRoot,
106
+ runGit
107
+ );
108
+ const fromNestedDir = resolveCosmosDatabaseNameForWorktree(
109
+ "MyAppDatabase",
110
+ nestedDir,
111
+ runGit
112
+ );
113
+
114
+ expect(fromNestedDir.databaseName).toBe(fromRoot.databaseName);
115
+ });
116
+
117
+ it("falls back to the base name when Git information cannot be read", () => {
118
+ const result = resolveCosmosDatabaseNameForWorktree(
119
+ "MyAppDatabase",
120
+ tempDir,
121
+ () => {
122
+ throw new Error("git is unavailable");
123
+ }
124
+ );
125
+
126
+ expect(result).toEqual({
127
+ databaseName: "MyAppDatabase",
128
+ worktreeIsolationEnabled: false,
129
+ });
130
+ expect(
131
+ resolveGitWorktreeInfo(tempDir, () => "not enough output")
132
+ ).toBeNull();
133
+ });
134
+
135
+ function createLinkedWorktreePaths(name: string): {
136
+ linkedRoot: string;
137
+ gitDir: string;
138
+ commonDir: string;
139
+ } {
140
+ const mainRoot = path.join(tempDir, `main-${name}`);
141
+ const linkedRoot = path.join(tempDir, `linked-${name}`);
142
+ const commonDir = path.join(mainRoot, ".git");
143
+ const gitDir = path.join(commonDir, "worktrees", name);
144
+ fs.mkdirSync(linkedRoot, { recursive: true });
145
+ fs.mkdirSync(gitDir, { recursive: true });
146
+
147
+ return { linkedRoot, gitDir, commonDir };
148
+ }
149
+ });
@@ -0,0 +1,236 @@
1
+ import * as fs from "fs";
2
+ import * as os from "os";
3
+ import * as path from "path";
4
+ import { CosmosClient } from "@azure/cosmos";
5
+ import { createBasicModelInfo } from "./fixtures";
6
+ import {
7
+ applyDevSeedEnvironment,
8
+ buildDefaultCosmosDatabaseName,
9
+ buildSeedTemplateDocument,
10
+ getContainerNameForModel,
11
+ loadDevSeedFiles,
12
+ normalizeSeedIdentifier,
13
+ parseCosmosConnectionString,
14
+ parseSeedDocuments,
15
+ prepareSeedDocumentsForExport,
16
+ resolveLocalCosmosConnectionInfo,
17
+ } from "../cli/commands/dev-seeds";
18
+
19
+ describe("dev seed helpers", () => {
20
+ const originalCwd = process.cwd();
21
+ let tempDir: string;
22
+
23
+ beforeEach(() => {
24
+ tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "swallowkit-dev-seeds-"));
25
+ process.chdir(tempDir);
26
+ });
27
+
28
+ afterEach(() => {
29
+ process.chdir(originalCwd);
30
+ fs.rmSync(tempDir, { recursive: true, force: true });
31
+ });
32
+
33
+ it("builds Cosmos container names from model names", () => {
34
+ expect(getContainerNameForModel(createBasicModelInfo())).toBe("Todos");
35
+ });
36
+
37
+ it("normalizes seed identifiers across common naming styles", () => {
38
+ expect(normalizeSeedIdentifier("todo-items")).toBe("todoitems");
39
+ expect(normalizeSeedIdentifier("Todo_Items")).toBe("todoitems");
40
+ expect(normalizeSeedIdentifier("todoSchema")).toBe("todoschema");
41
+ });
42
+
43
+ it("wraps a single JSON object into a document array", () => {
44
+ expect(parseSeedDocuments('{"id":"todo-001","title":"Hello"}', "todo.json")).toEqual([
45
+ { id: "todo-001", title: "Hello" },
46
+ ]);
47
+ });
48
+
49
+ it("builds default Cosmos database names from package names", () => {
50
+ expect(buildDefaultCosmosDatabaseName("swallowkit")).toBe("SwallowkitDatabase");
51
+ });
52
+
53
+ it("parses Cosmos DB connection strings", () => {
54
+ expect(parseCosmosConnectionString("AccountEndpoint=https://localhost:8081/;AccountKey=test-key==;")).toEqual({
55
+ endpoint: "https://localhost:8081/",
56
+ key: "test-key==",
57
+ });
58
+ });
59
+
60
+ it("loads matching seed files for an environment", async () => {
61
+ const seedsDir = path.join(tempDir, "dev-seeds", "local");
62
+ fs.mkdirSync(seedsDir, { recursive: true });
63
+ fs.writeFileSync(
64
+ path.join(seedsDir, "todo.json"),
65
+ JSON.stringify([{ id: "todo-001", title: "First task" }], null, 2),
66
+ "utf-8"
67
+ );
68
+ fs.writeFileSync(
69
+ path.join(seedsDir, "ignored.json"),
70
+ JSON.stringify([{ id: "ignored-001" }], null, 2),
71
+ "utf-8"
72
+ );
73
+
74
+ const loaded = await loadDevSeedFiles("local", [createBasicModelInfo()]);
75
+
76
+ expect(loaded).toHaveLength(1);
77
+ expect(loaded[0]).toMatchObject({
78
+ containerName: "Todos",
79
+ documents: [{ id: "todo-001", title: "First task" }],
80
+ });
81
+ });
82
+
83
+ it("rejects seed documents without ids", async () => {
84
+ const seedsDir = path.join(tempDir, "dev-seeds", "local");
85
+ fs.mkdirSync(seedsDir, { recursive: true });
86
+ fs.writeFileSync(path.join(seedsDir, "todo.json"), JSON.stringify([{ title: "Missing id" }], null, 2), "utf-8");
87
+
88
+ await expect(loadDevSeedFiles("local", [createBasicModelInfo()])).rejects.toThrow(/non-empty string id/);
89
+ });
90
+
91
+ it("reads local Cosmos DB settings from local.settings.json", () => {
92
+ const functionsDir = path.join(tempDir, "functions");
93
+ fs.mkdirSync(functionsDir, { recursive: true });
94
+ fs.writeFileSync(
95
+ path.join(functionsDir, "local.settings.json"),
96
+ JSON.stringify(
97
+ {
98
+ Values: {
99
+ CosmosDBConnection: "AccountEndpoint=https://localhost:8081/;AccountKey=test-key==;",
100
+ COSMOS_DB_DATABASE_NAME: "CustomDatabase",
101
+ },
102
+ },
103
+ null,
104
+ 2
105
+ ),
106
+ "utf-8"
107
+ );
108
+
109
+ const result = resolveLocalCosmosConnectionInfo("FallbackDatabase", functionsDir);
110
+
111
+ expect(result).toEqual({
112
+ ok: true,
113
+ value: {
114
+ endpoint: "https://localhost:8081/",
115
+ key: "test-key==",
116
+ databaseName: "CustomDatabase",
117
+ worktreeIsolationEnabled: false,
118
+ localSettingsPath: path.join(functionsDir, "local.settings.json"),
119
+ },
120
+ });
121
+ });
122
+
123
+ it("uses an explicit database name as the isolated seed database in a linked worktree", async () => {
124
+ const functionsDir = path.join(tempDir, "functions");
125
+ const linkedRoot = path.join(tempDir, "linked");
126
+ const commonGitDir = path.join(tempDir, "main", ".git");
127
+ const worktreeGitDir = path.join(commonGitDir, "worktrees", "linked");
128
+ fs.mkdirSync(functionsDir, { recursive: true });
129
+ fs.mkdirSync(linkedRoot, { recursive: true });
130
+ fs.writeFileSync(
131
+ path.join(functionsDir, "local.settings.json"),
132
+ JSON.stringify({
133
+ Values: {
134
+ CosmosDBConnection: "AccountEndpoint=https://localhost:8081/;AccountKey=test-key==;",
135
+ COSMOS_DB_DATABASE_NAME: "ExplicitDatabase",
136
+ },
137
+ }),
138
+ "utf-8"
139
+ );
140
+
141
+ const connectionInfo = resolveLocalCosmosConnectionInfo("FallbackDatabase", functionsDir, {
142
+ cwd: linkedRoot,
143
+ runGit: () => [linkedRoot, worktreeGitDir, commonGitDir].join("\n"),
144
+ });
145
+
146
+ expect(connectionInfo.ok).toBe(true);
147
+ if (!connectionInfo.ok) {
148
+ throw new Error("Expected local Cosmos DB connection info");
149
+ }
150
+ expect(connectionInfo.value.databaseName).toMatch(/^ExplicitDatabase_[a-f0-9]{8}$/);
151
+ expect(connectionInfo.value.worktreeIsolationEnabled).toBe(true);
152
+
153
+ const seedsDir = path.join(tempDir, "dev-seeds", "local");
154
+ fs.mkdirSync(seedsDir, { recursive: true });
155
+ fs.writeFileSync(
156
+ path.join(seedsDir, "todo.json"),
157
+ JSON.stringify([{ id: "todo-001", title: "Isolated" }]),
158
+ "utf-8"
159
+ );
160
+
161
+ const createItem = jest.fn(async () => undefined);
162
+ const container = {
163
+ delete: jest.fn(async () => undefined),
164
+ items: { create: createItem },
165
+ };
166
+ const database = {
167
+ container: jest.fn(() => container),
168
+ containers: { createIfNotExists: jest.fn(async () => undefined) },
169
+ };
170
+ const client = { database: jest.fn(() => database) } as unknown as CosmosClient;
171
+
172
+ await applyDevSeedEnvironment({
173
+ client,
174
+ databaseName: connectionInfo.value.databaseName,
175
+ environment: "local",
176
+ models: [createBasicModelInfo()],
177
+ });
178
+
179
+ expect(client.database).toHaveBeenCalledWith(connectionInfo.value.databaseName);
180
+ expect(createItem).toHaveBeenCalledWith({ id: "todo-001", title: "Isolated" });
181
+ });
182
+
183
+ it("prepares exported seed documents by removing Cosmos metadata and sorting ids", () => {
184
+ expect(
185
+ prepareSeedDocumentsForExport(
186
+ [
187
+ { id: "todo-002", title: "Second", _etag: "etag-2", _ts: 2 },
188
+ { id: "todo-001", title: "First", _rid: "rid-1", _self: "self-1" },
189
+ ],
190
+ "todo.json"
191
+ )
192
+ ).toEqual([
193
+ { id: "todo-001", title: "First" },
194
+ { id: "todo-002", title: "Second" },
195
+ ]);
196
+ });
197
+
198
+ it("builds nested template documents from related schemas", () => {
199
+ const category = createBasicModelInfo({
200
+ name: "Category",
201
+ displayName: "Category",
202
+ schemaName: "categorySchema",
203
+ filePath: "/models/category.ts",
204
+ fields: [
205
+ { name: "id", type: "string", isOptional: false, isArray: false },
206
+ { name: "name", type: "string", isOptional: false, isArray: false },
207
+ ],
208
+ hasCreatedAt: false,
209
+ hasUpdatedAt: false,
210
+ });
211
+ const todo = createBasicModelInfo({
212
+ fields: [
213
+ { name: "id", type: "string", isOptional: false, isArray: false },
214
+ { name: "title", type: "string", isOptional: false, isArray: false },
215
+ {
216
+ name: "category",
217
+ type: "object",
218
+ isOptional: true,
219
+ isArray: false,
220
+ isNestedSchema: true,
221
+ nestedModelName: "Category",
222
+ nestedSchemaName: "categorySchema",
223
+ },
224
+ ],
225
+ });
226
+
227
+ expect(buildSeedTemplateDocument(todo, [todo, category])).toEqual({
228
+ id: "todo-001",
229
+ title: "todo-title-sample",
230
+ category: {
231
+ id: "category-001",
232
+ name: "category-name-sample",
233
+ },
234
+ });
235
+ });
236
+ });
@@ -0,0 +1,296 @@
1
+ import * as http from "http";
2
+ import { readFileSync } from "fs";
3
+ import * as path from "path";
4
+ import {
5
+ buildFunctionsBaseUrl,
6
+ buildFunctionsStartArgs,
7
+ buildFunctionsCoreToolsCommand,
8
+ buildNextDevArgs,
9
+ buildSwaStartArgs,
10
+ buildDevCommand,
11
+ buildFunctionsCosmosEnvironment,
12
+ buildPythonFunctionsEnv,
13
+ compareVersionNumbers,
14
+ DevOptions,
15
+ getFunctionsReadinessTimeoutMs,
16
+ getCSharpFunctionsBuildArtifactPaths,
17
+ getPythonVirtualEnvPaths,
18
+ getSwaCliInstallCommand,
19
+ parseCoreToolsVersion,
20
+ waitForHttpServerReady,
21
+ } from "../cli/commands/dev";
22
+ import { CLI_VERSION, createProgram, normalizeDevCommandArgv } from "../cli/index";
23
+
24
+ const packageVersion = JSON.parse(
25
+ readFileSync(path.resolve(__dirname, "../../package.json"), "utf8")
26
+ ).version as string;
27
+
28
+ describe("dev command helpers", () => {
29
+ it("keeps the CLI version in sync with package.json", () => {
30
+ expect(CLI_VERSION).toBe(packageVersion);
31
+ });
32
+
33
+ it("passes the requested port to Azure Functions Core Tools", () => {
34
+ expect(buildFunctionsStartArgs("7076")).toEqual(["start", "--port", "7076"]);
35
+ });
36
+
37
+ it("parses the Core Tools version from CLI output", () => {
38
+ expect(parseCoreToolsVersion("4.6.0+ab90faafcab539d63cd3d0ce5faf1bca4395fccc")).toBe("4.6.0");
39
+ });
40
+
41
+ it("compares Core Tools versions numerically", () => {
42
+ expect(compareVersionNumbers("4.0.5198", "4.6.0")).toBeLessThan(0);
43
+ expect(compareVersionNumbers("4.6.0", "4.6.0")).toBe(0);
44
+ expect(compareVersionNumbers("4.10.0", "4.6.0")).toBeGreaterThan(0);
45
+ });
46
+
47
+ it("falls back to npm Core Tools for older C# isolated hosts", () => {
48
+ expect(buildFunctionsCoreToolsCommand("csharp", "4.0.5198")).toEqual({
49
+ command: "npm",
50
+ argsPrefix: ["exec", "--yes", "azure-functions-core-tools@4", "--"],
51
+ label: "npm exec azure-functions-core-tools@4 (installed func 4.0.5198 is too old for C# isolated)",
52
+ });
53
+ });
54
+
55
+ it("keeps the installed func command for supported Core Tools versions", () => {
56
+ expect(buildFunctionsCoreToolsCommand("csharp", "4.6.0")).toEqual({
57
+ command: "func",
58
+ argsPrefix: [],
59
+ label: "func 4.6.0",
60
+ });
61
+ });
62
+
63
+ it("uses webpack mode for npm-based Next.js dev", () => {
64
+ expect(buildNextDevArgs("npm", "3012")).toEqual(["next", "dev", "--port", "3012", "--webpack"]);
65
+ });
66
+
67
+ it("uses pnpm exec for pnpm-based Next.js dev", () => {
68
+ expect(buildNextDevArgs("pnpm", "3012")).toEqual(["exec", "next", "dev", "--port", "3012", "--webpack"]);
69
+ });
70
+
71
+ it("builds the Azure Functions base URL from host and port", () => {
72
+ expect(buildFunctionsBaseUrl(undefined, "7071")).toBe("http://localhost:7071");
73
+ expect(buildFunctionsBaseUrl("127.0.0.1", "7072")).toBe("http://127.0.0.1:7072");
74
+ });
75
+
76
+ it("builds SWA CLI arguments without bypassing the Next.js BFF", () => {
77
+ expect(buildSwaStartArgs(undefined, "3000", "4280")).toEqual([
78
+ "start",
79
+ "http://localhost:3000",
80
+ "--swa-config-location",
81
+ ".",
82
+ "--port",
83
+ "4280",
84
+ ]);
85
+ expect(buildSwaStartArgs(undefined, "3000", "4280")).not.toContain("--api-devserver-url");
86
+ });
87
+
88
+ it("provides a project-local SWA CLI install command", () => {
89
+ expect(getSwaCliInstallCommand("pnpm")).toBe("pnpm add -Dw @azure/static-web-apps-cli");
90
+ expect(getSwaCliInstallCommand("npm")).toBe("npm install -D @azure/static-web-apps-cli");
91
+ });
92
+
93
+ it("gives C# more startup time before reporting readiness timeout", () => {
94
+ expect(getFunctionsReadinessTimeoutMs("csharp")).toBeGreaterThan(getFunctionsReadinessTimeoutMs("typescript"));
95
+ expect(getFunctionsReadinessTimeoutMs("csharp")).toBeGreaterThan(getFunctionsReadinessTimeoutMs("python"));
96
+ });
97
+
98
+ it("waits until an HTTP server responds before reporting ready", async () => {
99
+ const server = http.createServer((_request, response) => {
100
+ response.writeHead(404);
101
+ response.end("not found");
102
+ });
103
+
104
+ await new Promise<void>((resolve) => {
105
+ server.listen(0, "127.0.0.1", () => resolve());
106
+ });
107
+
108
+ const address = server.address();
109
+ if (!address || typeof address === "string") {
110
+ throw new Error("Failed to determine ephemeral port.");
111
+ }
112
+
113
+ try {
114
+ await expect(
115
+ waitForHttpServerReady(`http://127.0.0.1:${address.port}`, 2_000, 50)
116
+ ).resolves.toBe(true);
117
+ } finally {
118
+ await new Promise<void>((resolve, reject) => {
119
+ server.close((error) => {
120
+ if (error) {
121
+ reject(error);
122
+ return;
123
+ }
124
+ resolve();
125
+ });
126
+ });
127
+ }
128
+ });
129
+
130
+ it("builds Python virtual environment paths under functions/.venv", () => {
131
+ const functionsDir = path.join("C:\\repo", "functions");
132
+ const paths = getPythonVirtualEnvPaths(functionsDir);
133
+
134
+ expect(paths.venvDir).toBe(path.join(functionsDir, ".venv"));
135
+ expect(paths.binDir.endsWith(process.platform === "win32" ? path.join(".venv", "Scripts") : path.join(".venv", "bin"))).toBe(true);
136
+ expect(paths.pythonExecutable.endsWith(process.platform === "win32" ? path.join("Scripts", "python.exe") : path.join("bin", "python"))).toBe(true);
137
+ });
138
+
139
+ it("targets C# bin and obj directories for build cleanup", () => {
140
+ const functionsDir = path.join("C:\\repo", "functions");
141
+
142
+ expect(getCSharpFunctionsBuildArtifactPaths(functionsDir)).toEqual([
143
+ path.join(functionsDir, "bin"),
144
+ path.join(functionsDir, "obj"),
145
+ ]);
146
+ });
147
+
148
+ it("injects Python virtual environment settings for Functions", () => {
149
+ const functionsDir = path.join("C:\\repo", "functions");
150
+ const env = buildPythonFunctionsEnv({ PATH: "C:\\Windows\\System32" }, functionsDir);
151
+ const expectedBinDir = getPythonVirtualEnvPaths(functionsDir).binDir;
152
+
153
+ expect(env.VIRTUAL_ENV).toBe(path.join(functionsDir, ".venv"));
154
+ expect(env.languageWorkers__python__defaultExecutablePath).toBe(
155
+ getPythonVirtualEnvPaths(functionsDir).pythonExecutable
156
+ );
157
+ expect(env.PATH?.startsWith(`${expectedBinDir}${path.delimiter}`)).toBe(true);
158
+ });
159
+
160
+ it("passes the resolved Cosmos database name to Azure Functions", () => {
161
+ const baseEnv = { PATH: "test-path", COSMOS_DB_DATABASE_NAME: "BaseDatabase" };
162
+ const env = buildFunctionsCosmosEnvironment(baseEnv, "BaseDatabase_a31f92c4");
163
+
164
+ expect(env.COSMOS_DB_DATABASE_NAME).toBe("BaseDatabase_a31f92c4");
165
+ expect(baseEnv.COSMOS_DB_DATABASE_NAME).toBe("BaseDatabase");
166
+ });
167
+ });
168
+
169
+ describe("dev CLI parser", () => {
170
+ it("exposes the Static Web Apps plan option on init", () => {
171
+ const init = createProgram().commands.find((command) => command.name() === "init");
172
+ const option = init?.options.find((candidate) => candidate.long === "--swa-plan");
173
+
174
+ expect(option).toBeDefined();
175
+ expect(option?.description).toContain("free | standard");
176
+ });
177
+
178
+ async function parseDevOptions(argv: string[]): Promise<DevOptions> {
179
+ let capturedOptions: DevOptions | undefined;
180
+ const logSpy = jest.spyOn(console, "log").mockImplementation(() => undefined);
181
+ const program = createProgram(buildDevCommand(async (options) => {
182
+ capturedOptions = options;
183
+ }, () => undefined));
184
+
185
+ program.exitOverride();
186
+
187
+ try {
188
+ await program.parseAsync(normalizeDevCommandArgv(argv));
189
+ } finally {
190
+ logSpy.mockRestore();
191
+ }
192
+
193
+ expect(capturedOptions).toBeDefined();
194
+ return capturedOptions!;
195
+ }
196
+
197
+ it("normalizes dev options placed before the subcommand", () => {
198
+ expect(
199
+ normalizeDevCommandArgv([
200
+ "node",
201
+ "swallowkit",
202
+ "--seed-env",
203
+ "local",
204
+ "--mock-connectors",
205
+ "dev",
206
+ "--port",
207
+ "3001",
208
+ ])
209
+ ).toEqual([
210
+ "node",
211
+ "swallowkit",
212
+ "dev",
213
+ "--seed-env",
214
+ "local",
215
+ "--mock-connectors",
216
+ "--port",
217
+ "3001",
218
+ ]);
219
+ });
220
+
221
+ it("keeps non-dev commands unchanged", () => {
222
+ const argv = ["node", "swallowkit", "create-model", "dev", "--connector", "external"];
223
+ expect(normalizeDevCommandArgv(argv)).toEqual(argv);
224
+ });
225
+
226
+ it("parses the same dev options regardless of whether they appear before or after the subcommand", async () => {
227
+ const expected = {
228
+ port: "3001",
229
+ functionsPort: "7072",
230
+ host: "127.0.0.1",
231
+ open: true,
232
+ verbose: true,
233
+ noFunctions: true,
234
+ seedEnv: "local",
235
+ mockConnectors: true,
236
+ swaPort: "4290",
237
+ noSwa: true,
238
+ };
239
+
240
+ const optionsAfterCommand = await parseDevOptions([
241
+ "node",
242
+ "swallowkit",
243
+ "dev",
244
+ "--port",
245
+ "3001",
246
+ "--functions-port",
247
+ "7072",
248
+ "--host",
249
+ "127.0.0.1",
250
+ "--open",
251
+ "--verbose",
252
+ "--no-functions",
253
+ "--seed-env",
254
+ "local",
255
+ "--mock-connectors",
256
+ "--swa-port",
257
+ "4290",
258
+ "--no-swa",
259
+ ]);
260
+
261
+ const optionsBeforeCommand = await parseDevOptions([
262
+ "node",
263
+ "swallowkit",
264
+ "--verbose",
265
+ "--host",
266
+ "127.0.0.1",
267
+ "--seed-env",
268
+ "local",
269
+ "--mock-connectors",
270
+ "--swa-port",
271
+ "4290",
272
+ "--no-swa",
273
+ "--no-functions",
274
+ "--port",
275
+ "3001",
276
+ "--functions-port",
277
+ "7072",
278
+ "--open",
279
+ "dev",
280
+ ]);
281
+
282
+ expect(optionsAfterCommand).toMatchObject(expected);
283
+ expect(optionsBeforeCommand).toMatchObject(expected);
284
+ expect({ ...optionsBeforeCommand }).toMatchObject({ ...optionsAfterCommand });
285
+ });
286
+
287
+ it("keeps Azure Functions enabled by default", async () => {
288
+ const options = await parseDevOptions([
289
+ "node",
290
+ "swallowkit",
291
+ "dev",
292
+ ]);
293
+
294
+ expect(options.noFunctions).toBe(false);
295
+ });
296
+ });