@leed-ai/git-gateway-contract 0.0.0-stage → 0.1.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 (286) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +50 -2
  3. package/dist/behaviour/assertions.d.ts +23 -0
  4. package/dist/behaviour/assertions.js +56 -0
  5. package/dist/behaviour/assertions.js.map +1 -0
  6. package/dist/behaviour/behaviour-case.d.ts +19 -0
  7. package/dist/behaviour/behaviour-case.js +12 -0
  8. package/dist/behaviour/behaviour-case.js.map +1 -0
  9. package/dist/behaviour/behaviour-suite.d.ts +30 -0
  10. package/dist/behaviour/behaviour-suite.js +50 -0
  11. package/dist/behaviour/behaviour-suite.js.map +1 -0
  12. package/dist/behaviour/commit-action-cases.d.ts +4 -0
  13. package/dist/behaviour/commit-action-cases.js +342 -0
  14. package/dist/behaviour/commit-action-cases.js.map +1 -0
  15. package/dist/behaviour/commit-write-cases.d.ts +4 -0
  16. package/dist/behaviour/commit-write-cases.js +234 -0
  17. package/dist/behaviour/commit-write-cases.js.map +1 -0
  18. package/dist/behaviour/fixtures.d.ts +29 -0
  19. package/dist/behaviour/fixtures.js +83 -0
  20. package/dist/behaviour/fixtures.js.map +1 -0
  21. package/dist/behaviour/lifecycle-cases.d.ts +4 -0
  22. package/dist/behaviour/lifecycle-cases.js +158 -0
  23. package/dist/behaviour/lifecycle-cases.js.map +1 -0
  24. package/dist/behaviour/promote-cases.d.ts +4 -0
  25. package/dist/behaviour/promote-cases.js +122 -0
  26. package/dist/behaviour/promote-cases.js.map +1 -0
  27. package/dist/behaviour/read-cases.d.ts +4 -0
  28. package/dist/behaviour/read-cases.js +248 -0
  29. package/dist/behaviour/read-cases.js.map +1 -0
  30. package/dist/behaviour/sync-cases.d.ts +4 -0
  31. package/dist/behaviour/sync-cases.js +205 -0
  32. package/dist/behaviour/sync-cases.js.map +1 -0
  33. package/dist/clock-B3MlpmVY.d.ts +10 -0
  34. package/dist/commit-BEZmeAOl.d.ts +23 -0
  35. package/dist/file-map-CxUveLWz.d.ts +18 -0
  36. package/dist/gateway-config-oVsdTEeK.d.ts +39 -0
  37. package/dist/gateway-error-body-BWzZFAQI.d.ts +214 -0
  38. package/dist/gateway-error.d.ts +30 -0
  39. package/dist/gateway-error.js +63 -0
  40. package/dist/gateway-error.js.map +1 -0
  41. package/dist/git-gateway-VA9Tc5tn.d.ts +358 -0
  42. package/dist/git-gateway.d.ts +2 -0
  43. package/dist/git-gateway.js +65 -0
  44. package/dist/git-gateway.js.map +1 -0
  45. package/dist/health.d.ts +9 -0
  46. package/dist/health.js +18 -0
  47. package/dist/health.js.map +1 -0
  48. package/dist/history-CqvHaUE-.d.ts +20 -0
  49. package/dist/package-name.d.ts +3 -0
  50. package/dist/package-name.js +6 -0
  51. package/dist/package-name.js.map +1 -0
  52. package/dist/proxy/audit-event.d.ts +61 -0
  53. package/dist/proxy/audit-event.js +97 -0
  54. package/dist/proxy/audit-event.js.map +1 -0
  55. package/dist/proxy/branch-rule.d.ts +72 -0
  56. package/dist/proxy/branch-rule.js +106 -0
  57. package/dist/proxy/branch-rule.js.map +1 -0
  58. package/dist/proxy/gateway-hooks.d.ts +58 -0
  59. package/dist/proxy/gateway-hooks.js +0 -0
  60. package/dist/proxy/git-operation.d.ts +17 -0
  61. package/dist/proxy/git-operation.js +32 -0
  62. package/dist/proxy/git-operation.js.map +1 -0
  63. package/dist/proxy/policy-result.d.ts +51 -0
  64. package/dist/proxy/policy-result.js +90 -0
  65. package/dist/proxy/policy-result.js.map +1 -0
  66. package/dist/proxy/principal.d.ts +18 -0
  67. package/dist/proxy/principal.js +32 -0
  68. package/dist/proxy/principal.js.map +1 -0
  69. package/dist/proxy/push-policy-result.d.ts +34 -0
  70. package/dist/proxy/push-policy-result.js +48 -0
  71. package/dist/proxy/push-policy-result.js.map +1 -0
  72. package/dist/proxy/push-policy.d.ts +146 -0
  73. package/dist/proxy/push-policy.js +112 -0
  74. package/dist/proxy/push-policy.js.map +1 -0
  75. package/dist/proxy/request-credential.d.ts +22 -0
  76. package/dist/proxy/request-credential.js +46 -0
  77. package/dist/proxy/request-credential.js.map +1 -0
  78. package/dist/proxy/smart-http-config.d.ts +22 -0
  79. package/dist/proxy/smart-http-config.js +40 -0
  80. package/dist/proxy/smart-http-config.js.map +1 -0
  81. package/dist/reference/apply-actions.d.ts +9 -0
  82. package/dist/reference/apply-actions.js +84 -0
  83. package/dist/reference/apply-actions.js.map +1 -0
  84. package/dist/reference/branch-methods.d.ts +7 -0
  85. package/dist/reference/branch-methods.js +105 -0
  86. package/dist/reference/branch-methods.js.map +1 -0
  87. package/dist/reference/bytes.d.ts +22 -0
  88. package/dist/reference/bytes.js +62 -0
  89. package/dist/reference/bytes.js.map +1 -0
  90. package/dist/reference/clock.d.ts +2 -0
  91. package/dist/reference/clock.js +18 -0
  92. package/dist/reference/clock.js.map +1 -0
  93. package/dist/reference/commit-method.d.ts +5 -0
  94. package/dist/reference/commit-method.js +83 -0
  95. package/dist/reference/commit-method.js.map +1 -0
  96. package/dist/reference/file-map.d.ts +2 -0
  97. package/dist/reference/file-map.js +24 -0
  98. package/dist/reference/file-map.js.map +1 -0
  99. package/dist/reference/hash.d.ts +10 -0
  100. package/dist/reference/hash.js +25 -0
  101. package/dist/reference/hash.js.map +1 -0
  102. package/dist/reference/history.d.ts +2 -0
  103. package/dist/reference/history.js +65 -0
  104. package/dist/reference/history.js.map +1 -0
  105. package/dist/reference/lifecycle-methods.d.ts +9 -0
  106. package/dist/reference/lifecycle-methods.js +48 -0
  107. package/dist/reference/lifecycle-methods.js.map +1 -0
  108. package/dist/reference/read-methods.d.ts +13 -0
  109. package/dist/reference/read-methods.js +68 -0
  110. package/dist/reference/read-methods.js.map +1 -0
  111. package/dist/reference/reference-gateway.d.ts +18 -0
  112. package/dist/reference/reference-gateway.js +35 -0
  113. package/dist/reference/reference-gateway.js.map +1 -0
  114. package/dist/reference/repo-state.d.ts +43 -0
  115. package/dist/reference/repo-state.js +45 -0
  116. package/dist/reference/repo-state.js.map +1 -0
  117. package/dist/reference/run-method.d.ts +13 -0
  118. package/dist/reference/run-method.js +15 -0
  119. package/dist/reference/run-method.js.map +1 -0
  120. package/dist/reference/three-way-merge.d.ts +16 -0
  121. package/dist/reference/three-way-merge.js +45 -0
  122. package/dist/reference/three-way-merge.js.map +1 -0
  123. package/dist/reference/trailer.d.ts +7 -0
  124. package/dist/reference/trailer.js +16 -0
  125. package/dist/reference/trailer.js.map +1 -0
  126. package/dist/reference/tree-index.d.ts +2 -0
  127. package/dist/reference/tree-index.js +66 -0
  128. package/dist/reference/tree-index.js.map +1 -0
  129. package/dist/reference/write-commit.d.ts +15 -0
  130. package/dist/reference/write-commit.js +44 -0
  131. package/dist/reference/write-commit.js.map +1 -0
  132. package/dist/rpc/commit-exists.d.ts +16 -0
  133. package/dist/rpc/commit-exists.js +30 -0
  134. package/dist/rpc/commit-exists.js.map +1 -0
  135. package/dist/rpc/commit.d.ts +172 -0
  136. package/dist/rpc/commit.js +115 -0
  137. package/dist/rpc/commit.js.map +1 -0
  138. package/dist/rpc/list-tree.d.ts +59 -0
  139. package/dist/rpc/list-tree.js +54 -0
  140. package/dist/rpc/list-tree.js.map +1 -0
  141. package/dist/rpc/log.d.ts +35 -0
  142. package/dist/rpc/log.js +41 -0
  143. package/dist/rpc/log.js.map +1 -0
  144. package/dist/rpc/mint-read-token.d.ts +17 -0
  145. package/dist/rpc/mint-read-token.js +36 -0
  146. package/dist/rpc/mint-read-token.js.map +1 -0
  147. package/dist/rpc/promote.d.ts +39 -0
  148. package/dist/rpc/promote.js +69 -0
  149. package/dist/rpc/promote.js.map +1 -0
  150. package/dist/rpc/read-file.d.ts +44 -0
  151. package/dist/rpc/read-file.js +56 -0
  152. package/dist/rpc/read-file.js.map +1 -0
  153. package/dist/rpc/repo-lifecycle.d.ts +39 -0
  154. package/dist/rpc/repo-lifecycle.js +64 -0
  155. package/dist/rpc/repo-lifecycle.js.map +1 -0
  156. package/dist/rpc/resolve-ref.d.ts +15 -0
  157. package/dist/rpc/resolve-ref.js +28 -0
  158. package/dist/rpc/resolve-ref.js.map +1 -0
  159. package/dist/rpc/sync-branch.d.ts +107 -0
  160. package/dist/rpc/sync-branch.js +114 -0
  161. package/dist/rpc/sync-branch.js.map +1 -0
  162. package/dist/schemas/commit-action.d.ts +100 -0
  163. package/dist/schemas/commit-action.js +138 -0
  164. package/dist/schemas/commit-action.js.map +1 -0
  165. package/dist/schemas/commit.d.ts +2 -0
  166. package/dist/schemas/commit.js +24 -0
  167. package/dist/schemas/commit.js.map +1 -0
  168. package/dist/schemas/content-encoding.d.ts +24 -0
  169. package/dist/schemas/content-encoding.js +41 -0
  170. package/dist/schemas/content-encoding.js.map +1 -0
  171. package/dist/schemas/examples.d.ts +38 -0
  172. package/dist/schemas/examples.js +32 -0
  173. package/dist/schemas/examples.js.map +1 -0
  174. package/dist/schemas/gateway-config.d.ts +2 -0
  175. package/dist/schemas/gateway-config.js +72 -0
  176. package/dist/schemas/gateway-config.js.map +1 -0
  177. package/dist/schemas/gateway-error-body.d.ts +2 -0
  178. package/dist/schemas/gateway-error-body.js +188 -0
  179. package/dist/schemas/gateway-error-body.js.map +1 -0
  180. package/dist/schemas/identity.d.ts +21 -0
  181. package/dist/schemas/identity.js +40 -0
  182. package/dist/schemas/identity.js.map +1 -0
  183. package/dist/schemas/names.d.ts +26 -0
  184. package/dist/schemas/names.js +58 -0
  185. package/dist/schemas/names.js.map +1 -0
  186. package/dist/schemas/ref-update.d.ts +10 -0
  187. package/dist/schemas/ref-update.js +25 -0
  188. package/dist/schemas/ref-update.js.map +1 -0
  189. package/dist/schemas/sha.d.ts +8 -0
  190. package/dist/schemas/sha.js +14 -0
  191. package/dist/schemas/sha.js.map +1 -0
  192. package/dist/schemas/tree-entry.d.ts +2 -0
  193. package/dist/schemas/tree-entry.js +62 -0
  194. package/dist/schemas/tree-entry.js.map +1 -0
  195. package/dist/storage/git-remote.d.ts +17 -0
  196. package/dist/storage/git-remote.js +31 -0
  197. package/dist/storage/git-remote.js.map +1 -0
  198. package/dist/storage/storage-backend.d.ts +61 -0
  199. package/dist/storage/storage-backend.js +0 -0
  200. package/dist/storage/storage-errors.d.ts +12 -0
  201. package/dist/storage/storage-errors.js +22 -0
  202. package/dist/storage/storage-errors.js.map +1 -0
  203. package/dist/storage/storage-input.d.ts +7 -0
  204. package/dist/storage/storage-input.js +14 -0
  205. package/dist/storage/storage-input.js.map +1 -0
  206. package/dist/storage/storage-read.d.ts +13 -0
  207. package/dist/storage/storage-read.js +30 -0
  208. package/dist/storage/storage-read.js.map +1 -0
  209. package/dist/storage/storage-repo-info.d.ts +16 -0
  210. package/dist/storage/storage-repo-info.js +30 -0
  211. package/dist/storage/storage-repo-info.js.map +1 -0
  212. package/dist/storage/storage-tree-entry.d.ts +21 -0
  213. package/dist/storage/storage-tree-entry.js +17 -0
  214. package/dist/storage/storage-tree-entry.js.map +1 -0
  215. package/dist/tree-entry-BM_1gou1.d.ts +41 -0
  216. package/dist/tree-index-Bk721Phv.d.ts +14 -0
  217. package/package.json +401 -4
  218. package/src/behaviour/assertions.ts +75 -0
  219. package/src/behaviour/behaviour-case.ts +28 -0
  220. package/src/behaviour/behaviour-suite.ts +76 -0
  221. package/src/behaviour/commit-action-cases.ts +253 -0
  222. package/src/behaviour/commit-write-cases.ts +205 -0
  223. package/src/behaviour/fixtures.ts +103 -0
  224. package/src/behaviour/lifecycle-cases.ts +104 -0
  225. package/src/behaviour/promote-cases.ts +78 -0
  226. package/src/behaviour/read-cases.ts +176 -0
  227. package/src/behaviour/sync-cases.ts +156 -0
  228. package/src/gateway-error.ts +72 -0
  229. package/src/git-gateway.ts +76 -0
  230. package/src/health.ts +26 -0
  231. package/src/package-name.ts +4 -0
  232. package/src/proxy/audit-event.ts +135 -0
  233. package/src/proxy/branch-rule.ts +190 -0
  234. package/src/proxy/gateway-hooks.ts +67 -0
  235. package/src/proxy/git-operation.ts +36 -0
  236. package/src/proxy/policy-result.ts +127 -0
  237. package/src/proxy/principal.ts +81 -0
  238. package/src/proxy/push-policy-result.ts +86 -0
  239. package/src/proxy/push-policy.ts +158 -0
  240. package/src/proxy/request-credential.ts +47 -0
  241. package/src/proxy/smart-http-config.ts +158 -0
  242. package/src/reference/apply-actions.ts +96 -0
  243. package/src/reference/branch-methods.ts +105 -0
  244. package/src/reference/bytes.ts +66 -0
  245. package/src/reference/clock.ts +19 -0
  246. package/src/reference/commit-method.ts +97 -0
  247. package/src/reference/file-map.ts +35 -0
  248. package/src/reference/hash.ts +25 -0
  249. package/src/reference/history.ts +78 -0
  250. package/src/reference/lifecycle-methods.ts +52 -0
  251. package/src/reference/read-methods.ts +87 -0
  252. package/src/reference/reference-gateway.ts +50 -0
  253. package/src/reference/repo-state.ts +83 -0
  254. package/src/reference/run-method.ts +25 -0
  255. package/src/reference/three-way-merge.ts +42 -0
  256. package/src/reference/trailer.ts +18 -0
  257. package/src/reference/tree-index.ts +65 -0
  258. package/src/reference/write-commit.ts +44 -0
  259. package/src/rpc/commit-exists.ts +46 -0
  260. package/src/rpc/commit.ts +156 -0
  261. package/src/rpc/list-tree.ts +78 -0
  262. package/src/rpc/log.ts +51 -0
  263. package/src/rpc/mint-read-token.ts +59 -0
  264. package/src/rpc/promote.ts +72 -0
  265. package/src/rpc/read-file.ts +75 -0
  266. package/src/rpc/repo-lifecycle.ts +103 -0
  267. package/src/rpc/resolve-ref.ts +41 -0
  268. package/src/rpc/sync-branch.ts +149 -0
  269. package/src/schemas/commit-action.ts +157 -0
  270. package/src/schemas/commit.ts +43 -0
  271. package/src/schemas/content-encoding.ts +58 -0
  272. package/src/schemas/examples.ts +24 -0
  273. package/src/schemas/gateway-config.ts +116 -0
  274. package/src/schemas/gateway-error-body.ts +230 -0
  275. package/src/schemas/identity.ts +57 -0
  276. package/src/schemas/names.ts +126 -0
  277. package/src/schemas/ref-update.ts +38 -0
  278. package/src/schemas/sha.ts +20 -0
  279. package/src/schemas/tree-entry.ts +72 -0
  280. package/src/storage/git-remote.ts +58 -0
  281. package/src/storage/storage-backend.ts +65 -0
  282. package/src/storage/storage-errors.ts +24 -0
  283. package/src/storage/storage-input.ts +14 -0
  284. package/src/storage/storage-read.ts +45 -0
  285. package/src/storage/storage-repo-info.ts +46 -0
  286. package/src/storage/storage-tree-entry.ts +20 -0
@@ -0,0 +1,342 @@
1
+ import { assertEqual, assertTrue, expectGatewayError } from "./assertions.js";
2
+ import { behaviourCase } from "./behaviour-case.js";
3
+ import { AUTHOR, commitActions, filePaths, freshKey, readText, requireHead, seedRepo } from "./fixtures.js";
4
+ // src/behaviour/commit-action-cases.ts
5
+ const GROUP = "commit actions";
6
+ /** git's id for the empty blob. */
7
+ const EMPTY_BLOB = "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391";
8
+ const SEED = {
9
+ "docs/a.md": "a\n",
10
+ "docs/b.md": "b\n",
11
+ "top.txt": "top\n"
12
+ };
13
+ /** Every rule of the commit-action table: create, update, upsert, delete, move, chmod. */
14
+ const commitActionCases = [
15
+ behaviourCase(GROUP, "create adds a new file", async ({ gateway, repo }) => {
16
+ await seedRepo(gateway, repo, SEED);
17
+ await commitActions(gateway, repo, "main", [{
18
+ action: "create",
19
+ path: "docs/c.md",
20
+ content: "c\n"
21
+ }]);
22
+ assertEqual(await readText(gateway, repo, "main", "docs/c.md"), "c\n", "created file content");
23
+ }),
24
+ behaviourCase(GROUP, "create fails with path_exists when the file exists", async ({ gateway, repo }) => {
25
+ await seedRepo(gateway, repo, SEED);
26
+ const error = await expectGatewayError(commitActions(gateway, repo, "main", [{
27
+ action: "create",
28
+ path: "docs/a.md",
29
+ content: "x"
30
+ }]), "path_exists");
31
+ assertEqual(error.details.path, "docs/a.md", "path_exists names the path");
32
+ }),
33
+ behaviourCase(GROUP, "create fails with path_exists when the path is a directory", async ({ gateway, repo }) => {
34
+ await seedRepo(gateway, repo, SEED);
35
+ await expectGatewayError(commitActions(gateway, repo, "main", [{
36
+ action: "create",
37
+ path: "docs",
38
+ content: "x"
39
+ }]), "path_exists");
40
+ }),
41
+ behaviourCase(GROUP, "create fails with path_conflict beneath a file", async ({ gateway, repo }) => {
42
+ await seedRepo(gateway, repo, SEED);
43
+ const error = await expectGatewayError(commitActions(gateway, repo, "main", [{
44
+ action: "create",
45
+ path: "top.txt/inner.md",
46
+ content: "x"
47
+ }]), "path_conflict");
48
+ assertEqual(error.details, {
49
+ path: "top.txt/inner.md",
50
+ conflictingPath: "top.txt"
51
+ }, "conflict details");
52
+ }),
53
+ behaviourCase(GROUP, "update replaces an existing file", async ({ gateway, repo }) => {
54
+ await seedRepo(gateway, repo, SEED);
55
+ await commitActions(gateway, repo, "main", [{
56
+ action: "update",
57
+ path: "docs/a.md",
58
+ content: "A\n"
59
+ }]);
60
+ assertEqual(await readText(gateway, repo, "main", "docs/a.md"), "A\n", "updated content");
61
+ }),
62
+ behaviourCase(GROUP, "update fails with path_not_found when the file is absent", async ({ gateway, repo }) => {
63
+ await seedRepo(gateway, repo, SEED);
64
+ const error = await expectGatewayError(commitActions(gateway, repo, "main", [{
65
+ action: "update",
66
+ path: "docs/zz.md",
67
+ content: "x"
68
+ }]), "path_not_found");
69
+ assertEqual(error.details.path, "docs/zz.md", "path_not_found names the path");
70
+ }),
71
+ behaviourCase(GROUP, "update fails with path_not_found on a directory", async ({ gateway, repo }) => {
72
+ await seedRepo(gateway, repo, SEED);
73
+ await expectGatewayError(commitActions(gateway, repo, "main", [{
74
+ action: "update",
75
+ path: "docs",
76
+ content: "x"
77
+ }]), "path_not_found");
78
+ }),
79
+ behaviourCase(GROUP, "upsert creates a missing file and replaces an existing one", async ({ gateway, repo }) => {
80
+ await seedRepo(gateway, repo, SEED);
81
+ await commitActions(gateway, repo, "main", [{
82
+ action: "upsert",
83
+ path: "docs/new.md",
84
+ content: "new\n"
85
+ }, {
86
+ action: "upsert",
87
+ path: "docs/a.md",
88
+ content: "replaced\n"
89
+ }]);
90
+ assertEqual(await readText(gateway, repo, "main", "docs/new.md"), "new\n", "upsert created");
91
+ assertEqual(await readText(gateway, repo, "main", "docs/a.md"), "replaced\n", "upsert replaced");
92
+ }),
93
+ behaviourCase(GROUP, "upsert fails with path_exists on a directory", async ({ gateway, repo }) => {
94
+ await seedRepo(gateway, repo, SEED);
95
+ await expectGatewayError(commitActions(gateway, repo, "main", [{
96
+ action: "upsert",
97
+ path: "docs",
98
+ content: "x"
99
+ }]), "path_exists");
100
+ }),
101
+ behaviourCase(GROUP, "delete removes a file and empty directories vanish", async ({ gateway, repo }) => {
102
+ await seedRepo(gateway, repo, {
103
+ "only/one.md": "1",
104
+ "keep.md": "k"
105
+ });
106
+ await commitActions(gateway, repo, "main", [{
107
+ action: "delete",
108
+ path: "only/one.md"
109
+ }]);
110
+ assertEqual(await filePaths(gateway, repo, "main"), ["keep.md"], "remaining files");
111
+ assertEqual(await gateway.listTree({
112
+ repo,
113
+ ref: "main",
114
+ path: "only"
115
+ }), null, "empty directory is gone");
116
+ }),
117
+ behaviourCase(GROUP, "delete fails with path_not_found when the file is absent", async ({ gateway, repo }) => {
118
+ await seedRepo(gateway, repo, SEED);
119
+ await expectGatewayError(commitActions(gateway, repo, "main", [{
120
+ action: "delete",
121
+ path: "nope.md"
122
+ }]), "path_not_found");
123
+ }),
124
+ behaviourCase(GROUP, "move renames a file, keeping content and mode", async ({ gateway, repo }) => {
125
+ await seedRepo(gateway, repo, SEED);
126
+ await commitActions(gateway, repo, "main", [{
127
+ action: "chmod",
128
+ path: "top.txt",
129
+ executeFilemode: true
130
+ }, {
131
+ action: "move",
132
+ previousPath: "top.txt",
133
+ path: "bin/top.sh"
134
+ }]);
135
+ const moved = await gateway.readFile({
136
+ repo,
137
+ ref: "main",
138
+ path: "bin/top.sh"
139
+ });
140
+ assertEqual(moved?.content, "top\n", "content kept");
141
+ assertEqual(moved?.executable, true, "executable bit kept");
142
+ assertEqual(await readText(gateway, repo, "main", "top.txt"), null, "old path gone");
143
+ }),
144
+ behaviourCase(GROUP, "move with content replaces the content", async ({ gateway, repo }) => {
145
+ await seedRepo(gateway, repo, SEED);
146
+ await commitActions(gateway, repo, "main", [{
147
+ action: "move",
148
+ previousPath: "docs/a.md",
149
+ path: "docs/a2.md",
150
+ content: "moved\n"
151
+ }]);
152
+ assertEqual(await readText(gateway, repo, "main", "docs/a2.md"), "moved\n", "new content");
153
+ }),
154
+ behaviourCase(GROUP, "move fails with path_not_found when previousPath is absent", async ({ gateway, repo }) => {
155
+ await seedRepo(gateway, repo, SEED);
156
+ const error = await expectGatewayError(commitActions(gateway, repo, "main", [{
157
+ action: "move",
158
+ previousPath: "gone.md",
159
+ path: "x.md"
160
+ }]), "path_not_found");
161
+ assertEqual(error.details.path, "gone.md", "names previousPath");
162
+ }),
163
+ behaviourCase(GROUP, "move fails with path_exists when path exists", async ({ gateway, repo }) => {
164
+ await seedRepo(gateway, repo, SEED);
165
+ await expectGatewayError(commitActions(gateway, repo, "main", [{
166
+ action: "move",
167
+ previousPath: "docs/a.md",
168
+ path: "docs/b.md"
169
+ }]), "path_exists");
170
+ }),
171
+ behaviourCase(GROUP, "move may place a file beneath its own old path", async ({ gateway, repo }) => {
172
+ await seedRepo(gateway, repo, SEED);
173
+ await commitActions(gateway, repo, "main", [{
174
+ action: "move",
175
+ previousPath: "top.txt",
176
+ path: "top.txt/x"
177
+ }]);
178
+ assertEqual(await readText(gateway, repo, "main", "top.txt/x"), "top\n", "moved beneath old path");
179
+ }),
180
+ behaviourCase(GROUP, "chmod sets and clears the executable bit", async ({ gateway, repo }) => {
181
+ await seedRepo(gateway, repo, SEED);
182
+ await commitActions(gateway, repo, "main", [{
183
+ action: "chmod",
184
+ path: "top.txt",
185
+ executeFilemode: true
186
+ }]);
187
+ const entry = (await gateway.listTree({
188
+ repo,
189
+ ref: "main"
190
+ }))?.entries.find((candidate) => candidate.path === "top.txt");
191
+ assertEqual(entry?.mode, "100755", "mode after setting");
192
+ await commitActions(gateway, repo, "main", [{
193
+ action: "chmod",
194
+ path: "top.txt",
195
+ executeFilemode: false
196
+ }]);
197
+ assertEqual((await gateway.readFile({
198
+ repo,
199
+ ref: "main",
200
+ path: "top.txt"
201
+ }))?.executable, false, "cleared");
202
+ }),
203
+ behaviourCase(GROUP, "chmod fails with path_not_found when the file is absent", async ({ gateway, repo }) => {
204
+ await seedRepo(gateway, repo, SEED);
205
+ await expectGatewayError(commitActions(gateway, repo, "main", [{
206
+ action: "chmod",
207
+ path: "nope",
208
+ executeFilemode: true
209
+ }]), "path_not_found");
210
+ }),
211
+ behaviourCase(GROUP, "update keeps the executable bit", async ({ gateway, repo }) => {
212
+ await seedRepo(gateway, repo, SEED);
213
+ await commitActions(gateway, repo, "main", [{
214
+ action: "chmod",
215
+ path: "top.txt",
216
+ executeFilemode: true
217
+ }, {
218
+ action: "update",
219
+ path: "top.txt",
220
+ content: "changed\n"
221
+ }]);
222
+ assertEqual((await gateway.readFile({
223
+ repo,
224
+ ref: "main",
225
+ path: "top.txt"
226
+ }))?.executable, true, "kept");
227
+ }),
228
+ behaviourCase(GROUP, "actions apply in order, each to the result of the one before", async ({ gateway, repo }) => {
229
+ await seedRepo(gateway, repo, SEED);
230
+ await commitActions(gateway, repo, "main", [
231
+ {
232
+ action: "create",
233
+ path: "seq.md",
234
+ content: "1"
235
+ },
236
+ {
237
+ action: "update",
238
+ path: "seq.md",
239
+ content: "2"
240
+ },
241
+ {
242
+ action: "move",
243
+ previousPath: "seq.md",
244
+ path: "seq2.md"
245
+ }
246
+ ]);
247
+ assertEqual(await readText(gateway, repo, "main", "seq2.md"), "2", "final state of the sequence");
248
+ }),
249
+ behaviourCase(GROUP, "a failing action writes nothing at all", async ({ gateway, repo }) => {
250
+ const seed = await seedRepo(gateway, repo, SEED);
251
+ await expectGatewayError(commitActions(gateway, repo, "main", [{
252
+ action: "create",
253
+ path: "fresh.md",
254
+ content: "x"
255
+ }, {
256
+ action: "delete",
257
+ path: "missing.md"
258
+ }]), "path_not_found");
259
+ assertEqual(await requireHead(gateway, repo, "main"), seed.sha, "head unchanged");
260
+ assertEqual(await readText(gateway, repo, "main", "fresh.md"), null, "earlier action not applied");
261
+ }),
262
+ behaviourCase(GROUP, "base64 content round-trips binary bytes", async ({ gateway, repo }) => {
263
+ await seedRepo(gateway, repo, SEED);
264
+ const binary = "/wD+AQ==";
265
+ await commitActions(gateway, repo, "main", [{
266
+ action: "create",
267
+ path: "bin.dat",
268
+ content: binary,
269
+ encoding: "base64"
270
+ }]);
271
+ const asText = await gateway.readFile({
272
+ repo,
273
+ ref: "main",
274
+ path: "bin.dat",
275
+ encoding: "text"
276
+ });
277
+ assertEqual([
278
+ asText?.encoding,
279
+ asText?.content,
280
+ asText?.size
281
+ ], [
282
+ "base64",
283
+ binary,
284
+ 4
285
+ ], "non-UTF-8 → base64");
286
+ const asBase64 = await gateway.readFile({
287
+ repo,
288
+ ref: "main",
289
+ path: "top.txt",
290
+ encoding: "base64"
291
+ });
292
+ assertEqual([asBase64?.encoding, asBase64?.content], ["base64", "dG9wCg=="], "base64 on request");
293
+ }),
294
+ behaviourCase(GROUP, "invalid base64 content is refused as invalid_input", async ({ gateway, repo }) => {
295
+ await seedRepo(gateway, repo, SEED);
296
+ const call = gateway.commit({
297
+ repo,
298
+ branch: "main",
299
+ message: "bad",
300
+ author: AUTHOR,
301
+ idempotencyKey: freshKey(),
302
+ actions: [{
303
+ action: "create",
304
+ path: "x.bin",
305
+ content: "not base64!",
306
+ encoding: "base64"
307
+ }]
308
+ });
309
+ const error = await expectGatewayError(call, "invalid_input");
310
+ assertTrue(error.details.issues.length > 0, "issues listed");
311
+ }),
312
+ behaviourCase(GROUP, "unicode paths, unicode text and empty files round-trip", async ({ gateway, repo }) => {
313
+ await seedRepo(gateway, repo, SEED);
314
+ await commitActions(gateway, repo, "main", [{
315
+ action: "create",
316
+ path: "données/résumé ✓.md",
317
+ content: "héllo 🌍\n"
318
+ }, {
319
+ action: "create",
320
+ path: "empty.txt",
321
+ content: ""
322
+ }]);
323
+ assertEqual(await readText(gateway, repo, "main", "données/résumé ✓.md"), "héllo 🌍\n", "unicode");
324
+ const empty = await gateway.readFile({
325
+ repo,
326
+ ref: "main",
327
+ path: "empty.txt"
328
+ });
329
+ assertEqual([
330
+ empty?.content,
331
+ empty?.size,
332
+ empty?.sha
333
+ ], [
334
+ "",
335
+ 0,
336
+ EMPTY_BLOB
337
+ ], "empty file");
338
+ })
339
+ ];
340
+ export { commitActionCases };
341
+
342
+ //# sourceMappingURL=commit-action-cases.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit-action-cases.js","names":[],"sources":["../../src/behaviour/commit-action-cases.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { assertEqual, assertTrue, expectGatewayError } from './assertions.ts';\nimport { behaviourCase, type BehaviourCase } from './behaviour-case.ts';\nimport { AUTHOR, commitActions, filePaths, freshKey, readText, requireHead, seedRepo } from './fixtures.ts';\n\nconst GROUP = 'commit actions';\n/** git's id for the empty blob. */\nconst EMPTY_BLOB = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391';\nconst SEED = { 'docs/a.md': 'a\\n', 'docs/b.md': 'b\\n', 'top.txt': 'top\\n' };\n\n/** Every rule of the commit-action table: create, update, upsert, delete, move, chmod. */\nexport const commitActionCases: readonly BehaviourCase[] = [\n behaviourCase(GROUP, 'create adds a new file', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, SEED);\n await commitActions(gateway, repo, 'main', [{ action: 'create', path: 'docs/c.md', content: 'c\\n' }]);\n assertEqual(await readText(gateway, repo, 'main', 'docs/c.md'), 'c\\n', 'created file content');\n }),\n behaviourCase(GROUP, 'create fails with path_exists when the file exists', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, SEED);\n const error = await expectGatewayError(\n commitActions(gateway, repo, 'main', [{ action: 'create', path: 'docs/a.md', content: 'x' }]),\n 'path_exists',\n );\n assertEqual(error.details.path, 'docs/a.md', 'path_exists names the path');\n }),\n behaviourCase(\n GROUP,\n 'create fails with path_exists when the path is a directory',\n async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, SEED);\n await expectGatewayError(\n commitActions(gateway, repo, 'main', [{ action: 'create', path: 'docs', content: 'x' }]),\n 'path_exists',\n );\n },\n ),\n behaviourCase(GROUP, 'create fails with path_conflict beneath a file', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, SEED);\n const error = await expectGatewayError(\n commitActions(gateway, repo, 'main', [{ action: 'create', path: 'top.txt/inner.md', content: 'x' }]),\n 'path_conflict',\n );\n assertEqual(error.details, { path: 'top.txt/inner.md', conflictingPath: 'top.txt' }, 'conflict details');\n }),\n behaviourCase(GROUP, 'update replaces an existing file', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, SEED);\n await commitActions(gateway, repo, 'main', [{ action: 'update', path: 'docs/a.md', content: 'A\\n' }]);\n assertEqual(await readText(gateway, repo, 'main', 'docs/a.md'), 'A\\n', 'updated content');\n }),\n behaviourCase(\n GROUP,\n 'update fails with path_not_found when the file is absent',\n async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, SEED);\n const error = await expectGatewayError(\n commitActions(gateway, repo, 'main', [{ action: 'update', path: 'docs/zz.md', content: 'x' }]),\n 'path_not_found',\n );\n assertEqual(error.details.path, 'docs/zz.md', 'path_not_found names the path');\n },\n ),\n behaviourCase(GROUP, 'update fails with path_not_found on a directory', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, SEED);\n await expectGatewayError(\n commitActions(gateway, repo, 'main', [{ action: 'update', path: 'docs', content: 'x' }]),\n 'path_not_found',\n );\n }),\n behaviourCase(\n GROUP,\n 'upsert creates a missing file and replaces an existing one',\n async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, SEED);\n await commitActions(gateway, repo, 'main', [\n { action: 'upsert', path: 'docs/new.md', content: 'new\\n' },\n { action: 'upsert', path: 'docs/a.md', content: 'replaced\\n' },\n ]);\n assertEqual(await readText(gateway, repo, 'main', 'docs/new.md'), 'new\\n', 'upsert created');\n assertEqual(await readText(gateway, repo, 'main', 'docs/a.md'), 'replaced\\n', 'upsert replaced');\n },\n ),\n behaviourCase(GROUP, 'upsert fails with path_exists on a directory', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, SEED);\n await expectGatewayError(\n commitActions(gateway, repo, 'main', [{ action: 'upsert', path: 'docs', content: 'x' }]),\n 'path_exists',\n );\n }),\n behaviourCase(GROUP, 'delete removes a file and empty directories vanish', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, { 'only/one.md': '1', 'keep.md': 'k' });\n await commitActions(gateway, repo, 'main', [{ action: 'delete', path: 'only/one.md' }]);\n assertEqual(await filePaths(gateway, repo, 'main'), ['keep.md'], 'remaining files');\n assertEqual(await gateway.listTree({ repo, ref: 'main', path: 'only' }), null, 'empty directory is gone');\n }),\n behaviourCase(\n GROUP,\n 'delete fails with path_not_found when the file is absent',\n async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, SEED);\n await expectGatewayError(\n commitActions(gateway, repo, 'main', [{ action: 'delete', path: 'nope.md' }]),\n 'path_not_found',\n );\n },\n ),\n behaviourCase(GROUP, 'move renames a file, keeping content and mode', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, SEED);\n await commitActions(gateway, repo, 'main', [\n { action: 'chmod', path: 'top.txt', executeFilemode: true },\n { action: 'move', previousPath: 'top.txt', path: 'bin/top.sh' },\n ]);\n const moved = await gateway.readFile({ repo, ref: 'main', path: 'bin/top.sh' });\n assertEqual(moved?.content, 'top\\n', 'content kept');\n assertEqual(moved?.executable, true, 'executable bit kept');\n assertEqual(await readText(gateway, repo, 'main', 'top.txt'), null, 'old path gone');\n }),\n behaviourCase(GROUP, 'move with content replaces the content', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, SEED);\n await commitActions(gateway, repo, 'main', [\n { action: 'move', previousPath: 'docs/a.md', path: 'docs/a2.md', content: 'moved\\n' },\n ]);\n assertEqual(await readText(gateway, repo, 'main', 'docs/a2.md'), 'moved\\n', 'new content');\n }),\n behaviourCase(\n GROUP,\n 'move fails with path_not_found when previousPath is absent',\n async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, SEED);\n const error = await expectGatewayError(\n commitActions(gateway, repo, 'main', [{ action: 'move', previousPath: 'gone.md', path: 'x.md' }]),\n 'path_not_found',\n );\n assertEqual(error.details.path, 'gone.md', 'names previousPath');\n },\n ),\n behaviourCase(GROUP, 'move fails with path_exists when path exists', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, SEED);\n await expectGatewayError(\n commitActions(gateway, repo, 'main', [\n { action: 'move', previousPath: 'docs/a.md', path: 'docs/b.md' },\n ]),\n 'path_exists',\n );\n }),\n behaviourCase(GROUP, 'move may place a file beneath its own old path', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, SEED);\n await commitActions(gateway, repo, 'main', [\n { action: 'move', previousPath: 'top.txt', path: 'top.txt/x' },\n ]);\n assertEqual(await readText(gateway, repo, 'main', 'top.txt/x'), 'top\\n', 'moved beneath old path');\n }),\n behaviourCase(GROUP, 'chmod sets and clears the executable bit', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, SEED);\n await commitActions(gateway, repo, 'main', [{ action: 'chmod', path: 'top.txt', executeFilemode: true }]);\n const listing = await gateway.listTree({ repo, ref: 'main' });\n const entry = listing?.entries.find((candidate) => candidate.path === 'top.txt');\n assertEqual(entry?.mode, '100755', 'mode after setting');\n await commitActions(gateway, repo, 'main', [\n { action: 'chmod', path: 'top.txt', executeFilemode: false },\n ]);\n assertEqual(\n (await gateway.readFile({ repo, ref: 'main', path: 'top.txt' }))?.executable,\n false,\n 'cleared',\n );\n }),\n behaviourCase(\n GROUP,\n 'chmod fails with path_not_found when the file is absent',\n async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, SEED);\n await expectGatewayError(\n commitActions(gateway, repo, 'main', [{ action: 'chmod', path: 'nope', executeFilemode: true }]),\n 'path_not_found',\n );\n },\n ),\n behaviourCase(GROUP, 'update keeps the executable bit', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, SEED);\n await commitActions(gateway, repo, 'main', [\n { action: 'chmod', path: 'top.txt', executeFilemode: true },\n { action: 'update', path: 'top.txt', content: 'changed\\n' },\n ]);\n assertEqual((await gateway.readFile({ repo, ref: 'main', path: 'top.txt' }))?.executable, true, 'kept');\n }),\n behaviourCase(\n GROUP,\n 'actions apply in order, each to the result of the one before',\n async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, SEED);\n await commitActions(gateway, repo, 'main', [\n { action: 'create', path: 'seq.md', content: '1' },\n { action: 'update', path: 'seq.md', content: '2' },\n { action: 'move', previousPath: 'seq.md', path: 'seq2.md' },\n ]);\n assertEqual(await readText(gateway, repo, 'main', 'seq2.md'), '2', 'final state of the sequence');\n },\n ),\n behaviourCase(GROUP, 'a failing action writes nothing at all', async ({ gateway, repo }) => {\n const seed = await seedRepo(gateway, repo, SEED);\n await expectGatewayError(\n commitActions(gateway, repo, 'main', [\n { action: 'create', path: 'fresh.md', content: 'x' },\n { action: 'delete', path: 'missing.md' },\n ]),\n 'path_not_found',\n );\n assertEqual(await requireHead(gateway, repo, 'main'), seed.sha, 'head unchanged');\n assertEqual(await readText(gateway, repo, 'main', 'fresh.md'), null, 'earlier action not applied');\n }),\n behaviourCase(GROUP, 'base64 content round-trips binary bytes', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, SEED);\n const binary = '/wD+AQ==';\n await commitActions(gateway, repo, 'main', [\n { action: 'create', path: 'bin.dat', content: binary, encoding: 'base64' },\n ]);\n const asText = await gateway.readFile({ repo, ref: 'main', path: 'bin.dat', encoding: 'text' });\n assertEqual(\n [asText?.encoding, asText?.content, asText?.size],\n ['base64', binary, 4],\n 'non-UTF-8 → base64',\n );\n const asBase64 = await gateway.readFile({ repo, ref: 'main', path: 'top.txt', encoding: 'base64' });\n assertEqual([asBase64?.encoding, asBase64?.content], ['base64', 'dG9wCg=='], 'base64 on request');\n }),\n behaviourCase(GROUP, 'invalid base64 content is refused as invalid_input', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, SEED);\n const call = gateway.commit({\n repo,\n branch: 'main',\n message: 'bad',\n author: AUTHOR,\n idempotencyKey: freshKey(),\n actions: [{ action: 'create', path: 'x.bin', content: 'not base64!', encoding: 'base64' }],\n });\n const error = await expectGatewayError(call, 'invalid_input');\n assertTrue(error.details.issues.length > 0, 'issues listed');\n }),\n behaviourCase(\n GROUP,\n 'unicode paths, unicode text and empty files round-trip',\n async ({ gateway, repo }) => {\n await seedRepo(gateway, repo, SEED);\n await commitActions(gateway, repo, 'main', [\n { action: 'create', path: 'données/résumé ✓.md', content: 'héllo 🌍\\n' },\n { action: 'create', path: 'empty.txt', content: '' },\n ]);\n assertEqual(await readText(gateway, repo, 'main', 'données/résumé ✓.md'), 'héllo 🌍\\n', 'unicode');\n const empty = await gateway.readFile({ repo, ref: 'main', path: 'empty.txt' });\n assertEqual([empty?.content, empty?.size, empty?.sha], ['', 0, EMPTY_BLOB], 'empty file');\n },\n ),\n];\n"],"mappings":";;;;AAKA,MAAM,QAAQ;;AAEd,MAAM,aAAa;AACnB,MAAM,OAAO;CAAE,aAAa;CAAO,aAAa;CAAO,WAAW;AAAQ;;AAG1E,MAAa,oBAA8C;CACzD,cAAc,OAAO,0BAA0B,OAAO,EAAE,SAAS,WAAW;EAC1E,MAAM,SAAS,SAAS,MAAM,IAAI;EAClC,MAAM,cAAc,SAAS,MAAM,QAAQ,CAAC;GAAE,QAAQ;GAAU,MAAM;GAAa,SAAS;EAAM,CAAC,CAAC;EACpG,YAAY,MAAM,SAAS,SAAS,MAAM,QAAQ,WAAW,GAAG,OAAO,sBAAsB;CAC/F,CAAC;CACD,cAAc,OAAO,sDAAsD,OAAO,EAAE,SAAS,WAAW;EACtG,MAAM,SAAS,SAAS,MAAM,IAAI;EAClC,MAAM,QAAQ,MAAM,mBAClB,cAAc,SAAS,MAAM,QAAQ,CAAC;GAAE,QAAQ;GAAU,MAAM;GAAa,SAAS;EAAI,CAAC,CAAC,GAC5F,aACF;EACA,YAAY,MAAM,QAAQ,MAAM,aAAa,4BAA4B;C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idempotency, stale-head refusal and attribution. */
3
+ export declare const commitWriteCases: readonly BehaviourCase[];
4
+ //# sourceMappingURL=commit-write-cases.d.ts.map
@@ -0,0 +1,234 @@
1
+ import { ZERO_SHA } from "../schemas/sha.js";
2
+ import { assertEqual, assertTrue, expectGatewayError, expectStatus } from "./assertions.js";
3
+ import { behaviourCase } from "./behaviour-case.js";
4
+ import { AUTHOR, commitActions, freshKey, readText, requireHead, seedRepo, writeFiles } from "./fixtures.js";
5
+ // src/behaviour/commit-write-cases.ts
6
+ const GROUP = "commit";
7
+ /** Branch creation, no-op detection, idempotency, stale-head refusal and attribution. */
8
+ const commitWriteCases = [
9
+ behaviourCase(GROUP, "the first commit to an empty repository is a root commit", async ({ gateway, repo }) => {
10
+ await gateway.createRepo({ repo });
11
+ const output = await gateway.commit({
12
+ repo,
13
+ branch: "main",
14
+ message: "Initial",
15
+ author: AUTHOR,
16
+ idempotencyKey: freshKey(),
17
+ actions: [{
18
+ action: "create",
19
+ path: "a.md",
20
+ content: "a"
21
+ }]
22
+ });
23
+ const { commit, refUpdate } = expectStatus(output, "committed");
24
+ assertEqual(commit.parents, [], "root commit has no parents");
25
+ assertEqual(refUpdate, {
26
+ ref: "refs/heads/main",
27
+ oldSha: ZERO_SHA,
28
+ newSha: commit.sha
29
+ }, "branch created");
30
+ assertEqual(await requireHead(gateway, repo, "main"), commit.sha, "branch points at the commit");
31
+ }),
32
+ behaviourCase(GROUP, "a commit names its parent and moves the branch", async ({ gateway, repo }) => {
33
+ const seed = await seedRepo(gateway, repo);
34
+ const output = await gateway.commit({
35
+ repo,
36
+ branch: "main",
37
+ message: "Second",
38
+ author: AUTHOR,
39
+ idempotencyKey: freshKey(),
40
+ actions: [{
41
+ action: "create",
42
+ path: "b.md",
43
+ content: "b"
44
+ }]
45
+ });
46
+ const { commit, refUpdate } = expectStatus(output, "committed");
47
+ assertEqual(commit.parents, [seed.sha], "parent is the old head");
48
+ assertEqual(refUpdate.oldSha, seed.sha, "ref update names the old head");
49
+ assertTrue(commit.tree !== seed.tree, "tree changed");
50
+ }),
51
+ behaviourCase(GROUP, "a missing branch is created from startBranch", async ({ gateway, repo }) => {
52
+ const seed = await seedRepo(gateway, repo);
53
+ const commit = await writeFiles(gateway, repo, "feature", { "f.md": "f" }, { startBranch: "main" });
54
+ assertEqual(commit.parents, [seed.sha], "parent is the start branch head");
55
+ assertEqual(await requireHead(gateway, repo, "main"), seed.sha, "start branch unchanged");
56
+ }),
57
+ behaviourCase(GROUP, "startBranch is ignored when the branch exists", async ({ gateway, repo }) => {
58
+ await seedRepo(gateway, repo);
59
+ const feature = await writeFiles(gateway, repo, "feature", { "f.md": "f" }, { startBranch: "main" });
60
+ const next = await writeFiles(gateway, repo, "feature", { "g.md": "g" }, { startBranch: "main" });
61
+ assertEqual(next.parents, [feature.sha], "built on the existing branch");
62
+ }),
63
+ behaviourCase(GROUP, "a missing branch without startBranch is ref_not_found", async ({ gateway, repo }) => {
64
+ await seedRepo(gateway, repo);
65
+ const error = await expectGatewayError(writeFiles(gateway, repo, "other", { "x.md": "x" }), "ref_not_found");
66
+ assertEqual(error.details.ref, "other", "names the branch");
67
+ }),
68
+ behaviourCase(GROUP, "a missing startBranch is ref_not_found", async ({ gateway, repo }) => {
69
+ await seedRepo(gateway, repo);
70
+ const call = writeFiles(gateway, repo, "other", { "x.md": "x" }, { startBranch: "nope" });
71
+ assertEqual((await expectGatewayError(call, "ref_not_found")).details.ref, "nope", "names startBranch");
72
+ }),
73
+ behaviourCase(GROUP, "a commit that changes nothing is a noop", async ({ gateway, repo }) => {
74
+ const seed = await seedRepo(gateway, repo, { "a.md": "same" });
75
+ for (const actions of [
76
+ [{
77
+ action: "update",
78
+ path: "a.md",
79
+ content: "same"
80
+ }],
81
+ [{
82
+ action: "chmod",
83
+ path: "a.md",
84
+ executeFilemode: false
85
+ }],
86
+ [{
87
+ action: "create",
88
+ path: "tmp.md",
89
+ content: "t"
90
+ }, {
91
+ action: "delete",
92
+ path: "tmp.md"
93
+ }]
94
+ ]) {
95
+ const output = await gateway.commit({
96
+ repo,
97
+ branch: "main",
98
+ message: "noop",
99
+ author: AUTHOR,
100
+ idempotencyKey: freshKey(),
101
+ actions
102
+ });
103
+ assertEqual(output, {
104
+ status: "noop",
105
+ head: seed.sha
106
+ }, `noop for ${actions[0]?.action}`);
107
+ }
108
+ const log = await gateway.log({
109
+ repo,
110
+ ref: "main"
111
+ });
112
+ assertEqual(log.commits.length, 1, "no commit written");
113
+ }),
114
+ behaviourCase(GROUP, "a repeated idempotency key replays the first commit", async ({ gateway, repo }) => {
115
+ await seedRepo(gateway, repo);
116
+ const key = freshKey("replay");
117
+ const first = await writeFiles(gateway, repo, "main", { "a.md": "1" }, { idempotencyKey: key });
118
+ const again = await gateway.commit({
119
+ repo,
120
+ branch: "main",
121
+ message: "retry with other content",
122
+ author: AUTHOR,
123
+ idempotencyKey: key,
124
+ actions: [{
125
+ action: "upsert",
126
+ path: "a.md",
127
+ content: "2"
128
+ }]
129
+ });
130
+ assertEqual(again, {
131
+ status: "replayed",
132
+ commit: first
133
+ }, "the earlier commit is returned");
134
+ assertEqual(await readText(gateway, repo, "main", "a.md"), "1", "nothing new written");
135
+ }),
136
+ behaviourCase(GROUP, "replay is found behind later commits and wins over a stale head", async ({ gateway, repo }) => {
137
+ const seed = await seedRepo(gateway, repo);
138
+ const key = freshKey("replay");
139
+ const first = await writeFiles(gateway, repo, "main", { "a.md": "1" }, { idempotencyKey: key });
140
+ await writeFiles(gateway, repo, "main", { "b.md": "2" });
141
+ const again = await gateway.commit({
142
+ repo,
143
+ branch: "main",
144
+ message: "retry",
145
+ author: AUTHOR,
146
+ expectedHead: seed.sha,
147
+ idempotencyKey: key,
148
+ actions: [{
149
+ action: "upsert",
150
+ path: "a.md",
151
+ content: "1"
152
+ }]
153
+ });
154
+ assertEqual(again, {
155
+ status: "replayed",
156
+ commit: first
157
+ }, "replayed, not stale_head");
158
+ }),
159
+ behaviourCase(GROUP, "the idempotency key is recorded as a message trailer", async ({ gateway, repo }) => {
160
+ await seedRepo(gateway, repo);
161
+ const key = freshKey("trailer");
162
+ const commit = await writeFiles(gateway, repo, "main", { "a.md": "1" }, {
163
+ idempotencyKey: key,
164
+ message: "Hello"
165
+ });
166
+ assertEqual(commit.idempotencyKey, key, "parsed key");
167
+ assertTrue(commit.message.startsWith("Hello"), "message kept");
168
+ assertTrue(commit.message.includes(`Gateway-Idempotency-Key: ${key}`), "trailer present");
169
+ }),
170
+ behaviourCase(GROUP, "a stale expectedHead is refused with stale_head", async ({ gateway, repo }) => {
171
+ const seed = await seedRepo(gateway, repo);
172
+ const moved = await writeFiles(gateway, repo, "main", { "a.md": "1" });
173
+ const call = writeFiles(gateway, repo, "main", { "b.md": "2" }, { expectedHead: seed.sha });
174
+ const error = await expectGatewayError(call, "stale_head");
175
+ assertEqual(error.details, {
176
+ branch: "main",
177
+ expectedHead: seed.sha,
178
+ actualHead: moved.sha
179
+ }, "details");
180
+ assertEqual(await readText(gateway, repo, "main", "b.md"), null, "nothing written");
181
+ }),
182
+ behaviourCase(GROUP, "expectedHead null requires the branch not to exist", async ({ gateway, repo }) => {
183
+ const seed = await seedRepo(gateway, repo);
184
+ const call = writeFiles(gateway, repo, "main", { "b.md": "2" }, { expectedHead: null });
185
+ assertEqual((await expectGatewayError(call, "stale_head")).details.actualHead, seed.sha, "actual head");
186
+ const created = await writeFiles(gateway, repo, "fresh", { "c.md": "3" }, {
187
+ expectedHead: null,
188
+ startBranch: "main"
189
+ });
190
+ assertEqual(created.parents, [seed.sha], "new branch accepted with expectedHead null");
191
+ }),
192
+ behaviourCase(GROUP, "a matching expectedHead commits", async ({ gateway, repo }) => {
193
+ const seed = await seedRepo(gateway, repo);
194
+ const commit = await writeFiles(gateway, repo, "main", { "a.md": "1" }, { expectedHead: seed.sha });
195
+ assertEqual(commit.parents, [seed.sha], "committed on the expected head");
196
+ }),
197
+ behaviourCase(GROUP, "the committer defaults to the author and may be set", async ({ gateway, repo }) => {
198
+ const seed = await seedRepo(gateway, repo);
199
+ assertEqual([seed.committer.name, seed.committer.email], [AUTHOR.name, AUTHOR.email], "defaulted");
200
+ const commit = await writeFiles(gateway, repo, "main", { "a.md": "1" }, { committer: {
201
+ name: "Robot",
202
+ email: "robot@example.com"
203
+ } });
204
+ assertEqual([commit.author.name, commit.committer.name], [AUTHOR.name, "Robot"], "explicit committer");
205
+ }),
206
+ behaviourCase(GROUP, "concurrent commits without expectedHead all land", async ({ gateway, repo }) => {
207
+ await seedRepo(gateway, repo);
208
+ const outputs = await Promise.all([
209
+ "x",
210
+ "y",
211
+ "z"
212
+ ].map((name) => commitActions(gateway, repo, "main", [{
213
+ action: "create",
214
+ path: `${name}.md`,
215
+ content: name
216
+ }])));
217
+ assertEqual(new Set(outputs.map((commit) => commit.sha)).size, 3, "three distinct commits");
218
+ for (const name of [
219
+ "x",
220
+ "y",
221
+ "z"
222
+ ]) assertEqual(await readText(gateway, repo, "main", `${name}.md`), name, name);
223
+ }),
224
+ behaviourCase(GROUP, "concurrent commits on the same expectedHead: exactly one wins", async ({ gateway, repo }) => {
225
+ const seed = await seedRepo(gateway, repo);
226
+ const results = await Promise.allSettled(["x", "y"].map((name) => writeFiles(gateway, repo, "main", { [`${name}.md`]: name }, { expectedHead: seed.sha })));
227
+ assertEqual(results.filter((result) => result.status === "fulfilled").length, 1, "one commit lands");
228
+ const rejected = results.find((result) => result.status === "rejected");
229
+ await expectGatewayError(Promise.reject(rejected?.reason), "stale_head");
230
+ })
231
+ ];
232
+ export { commitWriteCases };
233
+
234
+ //# sourceMappingURL=commit-write-cases.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit-write-cases.js","names":[],"sources":["../../src/behaviour/commit-write-cases.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { ZERO_SHA } from '../schemas/sha.ts';\nimport { assertEqual, assertTrue, expectGatewayError, expectStatus } from './assertions.ts';\nimport { behaviourCase, type BehaviourCase } from './behaviour-case.ts';\nimport { AUTHOR, commitActions, freshKey, readText, requireHead, seedRepo, writeFiles } from './fixtures.ts';\n\nconst GROUP = 'commit';\n\n/** Branch creation, no-op detection, idempotency, stale-head refusal and attribution. */\nexport const commitWriteCases: readonly BehaviourCase[] = [\n behaviourCase(\n GROUP,\n 'the first commit to an empty repository is a root commit',\n async ({ gateway, repo }) => {\n await gateway.createRepo({ repo });\n const output = await gateway.commit({\n repo,\n branch: 'main',\n message: 'Initial',\n author: AUTHOR,\n idempotencyKey: freshKey(),\n actions: [{ action: 'create', path: 'a.md', content: 'a' }],\n });\n const { commit, refUpdate } = expectStatus(output, 'committed');\n assertEqual(commit.parents, [], 'root commit has no parents');\n assertEqual(\n refUpdate,\n { ref: 'refs/heads/main', oldSha: ZERO_SHA, newSha: commit.sha },\n 'branch created',\n );\n assertEqual(await requireHead(gateway, repo, 'main'), commit.sha, 'branch points at the commit');\n },\n ),\n behaviourCase(GROUP, 'a commit names its parent and moves the branch', async ({ gateway, repo }) => {\n const seed = await seedRepo(gateway, repo);\n const output = await gateway.commit({\n repo,\n branch: 'main',\n message: 'Second',\n author: AUTHOR,\n idempotencyKey: freshKey(),\n actions: [{ action: 'create', path: 'b.md', content: 'b' }],\n });\n const { commit, refUpdate } = expectStatus(output, 'committed');\n assertEqual(commit.parents, [seed.sha], 'parent is the old head');\n assertEqual(refUpdate.oldSha, seed.sha, 'ref update names the old head');\n assertTrue(commit.tree !== seed.tree, 'tree changed');\n }),\n behaviourCase(GROUP, 'a missing branch is created from startBranch', async ({ gateway, repo }) => {\n const seed = await seedRepo(gateway, repo);\n const commit = await writeFiles(gateway, repo, 'feature', { 'f.md': 'f' }, { startBranch: 'main' });\n assertEqual(commit.parents, [seed.sha], 'parent is the start branch head');\n assertEqual(await requireHead(gateway, repo, 'main'), seed.sha, 'start branch unchanged');\n }),\n behaviourCase(GROUP, 'startBranch is ignored when the branch exists', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo);\n const feature = await writeFiles(gateway, repo, 'feature', { 'f.md': 'f' }, { startBranch: 'main' });\n const next = await writeFiles(gateway, repo, 'feature', { 'g.md': 'g' }, { startBranch: 'main' });\n assertEqual(next.parents, [feature.sha], 'built on the existing branch');\n }),\n behaviourCase(GROUP, 'a missing branch without startBranch is ref_not_found', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo);\n const error = await expectGatewayError(\n writeFiles(gateway, repo, 'other', { 'x.md': 'x' }),\n 'ref_not_found',\n );\n assertEqual(error.details.ref, 'other', 'names the branch');\n }),\n behaviourCase(GROUP, 'a missing startBranch is ref_not_found', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo);\n const call = writeFiles(gateway, repo, 'other', { 'x.md': 'x' }, { startBranch: 'nope' });\n assertEqual((await expectGatewayError(call, 'ref_not_found')).details.ref, 'nope', 'names startBranch');\n }),\n behaviourCase(GROUP, 'a commit that changes nothing is a noop', async ({ gateway, repo }) => {\n const seed = await seedRepo(gateway, repo, { 'a.md': 'same' });\n for (const actions of [\n [{ action: 'update' as const, path: 'a.md', content: 'same' }],\n [{ action: 'chmod' as const, path: 'a.md', executeFilemode: false }],\n [\n { action: 'create' as const, path: 'tmp.md', content: 't' },\n { action: 'delete' as const, path: 'tmp.md' },\n ],\n ]) {\n const output = await gateway.commit({\n repo,\n branch: 'main',\n message: 'noop',\n author: AUTHOR,\n idempotencyKey: freshKey(),\n actions,\n });\n assertEqual(output, { status: 'noop', head: seed.sha }, `noop for ${actions[0]?.action}`);\n }\n const log = await gateway.log({ repo, ref: 'main' });\n assertEqual(log.commits.length, 1, 'no commit written');\n }),\n behaviourCase(GROUP, 'a repeated idempotency key replays the first commit', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo);\n const key = freshKey('replay');\n const first = await writeFiles(gateway, repo, 'main', { 'a.md': '1' }, { idempotencyKey: key });\n const again = await gateway.commit({\n repo,\n branch: 'main',\n message: 'retry with other content',\n author: AUTHOR,\n idempotencyKey: key,\n actions: [{ action: 'upsert', path: 'a.md', content: '2' }],\n });\n assertEqual(again, { status: 'replayed', commit: first }, 'the earlier commit is returned');\n assertEqual(await readText(gateway, repo, 'main', 'a.md'), '1', 'nothing new written');\n }),\n behaviourCase(\n GROUP,\n 'replay is found behind later commits and wins over a stale head',\n async ({ gateway, repo }) => {\n const seed = await seedRepo(gateway, repo);\n const key = freshKey('replay');\n const first = await writeFiles(gateway, repo, 'main', { 'a.md': '1' }, { idempotencyKey: key });\n await writeFiles(gateway, repo, 'main', { 'b.md': '2' });\n const again = await gateway.commit({\n repo,\n branch: 'main',\n message: 'retry',\n author: AUTHOR,\n expectedHead: seed.sha,\n idempotencyKey: key,\n actions: [{ action: 'upsert', path: 'a.md', content: '1' }],\n });\n assertEqual(again, { status: 'replayed', commit: first }, 'replayed, not stale_head');\n },\n ),\n behaviourCase(GROUP, 'the idempotency key is recorded as a message trailer', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo);\n const key = freshKey('trailer');\n const commit = await writeFiles(\n gateway,\n repo,\n 'main',\n { 'a.md': '1' },\n { idempotencyKey: key, message: 'Hello' },\n );\n assertEqual(commit.idempotencyKey, key, 'parsed key');\n assertTrue(commit.message.startsWith('Hello'), 'message kept');\n assertTrue(commit.message.includes(`Gateway-Idempotency-Key: ${key}`), 'trailer present');\n }),\n behaviourCase(GROUP, 'a stale expectedHead is refused with stale_head', async ({ gateway, repo }) => {\n const seed = await seedRepo(gateway, repo);\n const moved = await writeFiles(gateway, repo, 'main', { 'a.md': '1' });\n const call = writeFiles(gateway, repo, 'main', { 'b.md': '2' }, { expectedHead: seed.sha });\n const error = await expectGatewayError(call, 'stale_head');\n assertEqual(error.details, { branch: 'main', expectedHead: seed.sha, actualHead: moved.sha }, 'details');\n assertEqual(await readText(gateway, repo, 'main', 'b.md'), null, 'nothing written');\n }),\n behaviourCase(GROUP, 'expectedHead null requires the branch not to exist', async ({ gateway, repo }) => {\n const seed = await seedRepo(gateway, repo);\n const call = writeFiles(gateway, repo, 'main', { 'b.md': '2' }, { expectedHead: null });\n assertEqual((await expectGatewayError(call, 'stale_head')).details.actualHead, seed.sha, 'actual head');\n const created = await writeFiles(\n gateway,\n repo,\n 'fresh',\n { 'c.md': '3' },\n { expectedHead: null, startBranch: 'main' },\n );\n assertEqual(created.parents, [seed.sha], 'new branch accepted with expectedHead null');\n }),\n behaviourCase(GROUP, 'a matching expectedHead commits', async ({ gateway, repo }) => {\n const seed = await seedRepo(gateway, repo);\n const commit = await writeFiles(gateway, repo, 'main', { 'a.md': '1' }, { expectedHead: seed.sha });\n assertEqual(commit.parents, [seed.sha], 'committed on the expected head');\n }),\n behaviourCase(GROUP, 'the committer defaults to the author and may be set', async ({ gateway, repo }) => {\n const seed = await seedRepo(gateway, repo);\n assertEqual([seed.committer.name, seed.committer.email], [AUTHOR.name, AUTHOR.email], 'defaulted');\n const committer = { name: 'Robot', email: 'robot@example.com' };\n const commit = await writeFiles(gateway, repo, 'main', { 'a.md': '1' }, { committer });\n assertEqual([commit.author.name, commit.committer.name], [AUTHOR.name, 'Robot'], 'explicit committer');\n }),\n behaviourCase(GROUP, 'concurrent commits without expectedHead all land', async ({ gateway, repo }) => {\n await seedRepo(gateway, repo);\n const outputs = await Promise.all(\n ['x', 'y', 'z'].map((name) =>\n commitActions(gateway, repo, 'main', [{ action: 'create', path: `${name}.md`, content: name }]),\n ),\n );\n assertEqual(new Set(outputs.map((commit) => commit.sha)).size, 3, 'three distinct commits');\n for (const name of ['x', 'y', 'z'])\n assertEqual(await readText(gateway, repo, 'main', `${name}.md`), name, name);\n }),\n behaviourCase(\n GROUP,\n 'concurrent commits on the same expectedHead: exactly one wins',\n async ({ gateway, repo }) => {\n const seed = await seedRepo(gateway, repo);\n const results = await Promise.allSettled(\n ['x', 'y'].map((name) =>\n writeFiles(gateway, repo, 'main', { [`${name}.md`]: name }, { expectedHead: seed.sha }),\n ),\n );\n assertEqual(results.filter((result) => result.status === 'fulfilled').length, 1, 'one commit lands');\n const rejected = results.find((result) => result.status === 'rejected');\n await expectGatewayError(Promise.reject(rejected?.reason), 'stale_head');\n },\n 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