@leed-ai/git-gateway-testkit 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.
- package/LICENSE +201 -0
- package/README.md +19 -2
- package/dist/contract-suite/ancestry-cases.d.ts +4 -0
- package/dist/contract-suite/ancestry-cases.js +49 -0
- package/dist/contract-suite/ancestry-cases.js.map +1 -0
- package/dist/contract-suite/backend-case.d.ts +35 -0
- package/dist/contract-suite/backend-case.js +17 -0
- package/dist/contract-suite/backend-case.js.map +1 -0
- package/dist/contract-suite/backend-contract-suite.d.ts +44 -0
- package/dist/contract-suite/backend-contract-suite.js +59 -0
- package/dist/contract-suite/backend-contract-suite.js.map +1 -0
- package/dist/contract-suite/backend-fixtures.d.ts +25 -0
- package/dist/contract-suite/backend-fixtures.js +79 -0
- package/dist/contract-suite/backend-fixtures.js.map +1 -0
- package/dist/contract-suite/content-cases.d.ts +4 -0
- package/dist/contract-suite/content-cases.js +31 -0
- package/dist/contract-suite/content-cases.js.map +1 -0
- package/dist/contract-suite/lifecycle-cases.d.ts +4 -0
- package/dist/contract-suite/lifecycle-cases.js +86 -0
- package/dist/contract-suite/lifecycle-cases.js.map +1 -0
- package/dist/contract-suite/push-cases.d.ts +4 -0
- package/dist/contract-suite/push-cases.js +92 -0
- package/dist/contract-suite/push-cases.js.map +1 -0
- package/dist/contract-suite/push-helpers.d.ts +17 -0
- package/dist/contract-suite/push-helpers.js +47 -0
- package/dist/contract-suite/push-helpers.js.map +1 -0
- package/dist/contract-suite/read-cases.d.ts +4 -0
- package/dist/contract-suite/read-cases.js +186 -0
- package/dist/contract-suite/read-cases.js.map +1 -0
- package/dist/contract-suite/transport-cases.d.ts +4 -0
- package/dist/contract-suite/transport-cases.js +105 -0
- package/dist/contract-suite/transport-cases.js.map +1 -0
- package/dist/git-binary.d.ts +19 -0
- package/dist/git-binary.js +54 -0
- package/dist/git-binary.js.map +1 -0
- package/dist/git-sandbox.d.ts +33 -0
- package/dist/git-sandbox.js +76 -0
- package/dist/git-sandbox.js.map +1 -0
- package/dist/memory/memory-backend.d.ts +45 -0
- package/dist/memory/memory-backend.js +154 -0
- package/dist/memory/memory-backend.js.map +1 -0
- package/dist/memory/memory-reads.d.ts +9 -0
- package/dist/memory/memory-reads.js +39 -0
- package/dist/memory/memory-reads.js.map +1 -0
- package/dist/memory/memory-repository.d.ts +38 -0
- package/dist/memory/memory-repository.js +97 -0
- package/dist/memory/memory-repository.js.map +1 -0
- package/dist/memory/memory-tokens.d.ts +28 -0
- package/dist/memory/memory-tokens.js +59 -0
- package/dist/memory/memory-tokens.js.map +1 -0
- package/dist/memory/pack-selection.d.ts +30 -0
- package/dist/memory/pack-selection.js +104 -0
- package/dist/memory/pack-selection.js.map +1 -0
- package/dist/memory/receive-pack-service.d.ts +15 -0
- package/dist/memory/receive-pack-service.js +126 -0
- package/dist/memory/receive-pack-service.js.map +1 -0
- package/dist/memory/smart-http-server.d.ts +15 -0
- package/dist/memory/smart-http-server.js +65 -0
- package/dist/memory/smart-http-server.js.map +1 -0
- package/dist/memory/upload-pack-service.d.ts +15 -0
- package/dist/memory/upload-pack-service.js +123 -0
- package/dist/memory/upload-pack-service.js.map +1 -0
- package/dist/node/serve-fetch-handler.d.ts +16 -0
- package/dist/node/serve-fetch-handler.js +52 -0
- package/dist/node/serve-fetch-handler.js.map +1 -0
- package/dist/node/serve-streaming.d.ts +16 -0
- package/dist/node/serve-streaming.js +87 -0
- package/dist/node/serve-streaming.js.map +1 -0
- package/package.json +175 -4
- package/src/contract-suite/ancestry-cases.ts +56 -0
- package/src/contract-suite/backend-case.ts +53 -0
- package/src/contract-suite/backend-contract-suite.ts +89 -0
- package/src/contract-suite/backend-fixtures.ts +89 -0
- package/src/contract-suite/content-cases.ts +55 -0
- package/src/contract-suite/lifecycle-cases.ts +121 -0
- package/src/contract-suite/push-cases.ts +123 -0
- package/src/contract-suite/push-helpers.ts +63 -0
- package/src/contract-suite/read-cases.ts +213 -0
- package/src/contract-suite/transport-cases.ts +134 -0
- package/src/git-binary.ts +65 -0
- package/src/git-sandbox.ts +87 -0
- package/src/memory/memory-backend.ts +188 -0
- package/src/memory/memory-reads.ts +52 -0
- package/src/memory/memory-repository.ts +115 -0
- package/src/memory/memory-tokens.ts +64 -0
- package/src/memory/pack-selection.ts +127 -0
- package/src/memory/receive-pack-service.ts +141 -0
- package/src/memory/smart-http-server.ts +78 -0
- package/src/memory/upload-pack-service.ts +132 -0
- package/src/node/serve-fetch-handler.ts +71 -0
- package/src/node/serve-streaming.ts +107 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @leed-ai/git-gateway-testkit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Test kit for git-gateway: in-memory backend, repository fixtures, a real-git conformance harness and the backend contract suite.
|
|
4
|
+
|
|
5
|
+
Part of [git-gateway](https://github.com/leed-ai/git-gateway). Status: in development; see the [design](https://github.com/leed-ai/git-gateway/blob/main/docs/design.md).
|
|
6
|
+
|
|
7
|
+
Peer dependencies: `zod` (`^4`), `cloudflare` (`^5`). Install them alongside this package.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
- `memory/memory-backend` — `MemoryBackend`, a complete `StorageBackend` in memory with a real git smart-HTTP server (`handle(request)`, or `fetch` as a FetchLike). Serve it with `node/serve-fetch-handler` to drive the git binary against it.
|
|
12
|
+
- `contract-suite/backend-contract-suite` — `registerBackendContractSuite({ describe, it }, { createBackend, behaviour, fetch? })` registers the backend contract suite with any test framework; every backend runs it unchanged.
|
|
13
|
+
- `contract-suite/backend-fixtures` — commits built in memory through the core encoders, for tests that push.
|
|
14
|
+
- `git-binary` — locating and versioning the git binary for conformance runs.
|
|
15
|
+
- `git-sandbox` — `GitSandbox`, a scratch directory running the git binary isolated from user and system configuration.
|
|
16
|
+
- `node/serve-streaming` — `serveStreaming(handler, traffic?)`, a loopback HTTP server that streams request and response bodies under backpressure (as Workers does), so git can drive the gateway and tests can see how much it holds at once.
|
|
17
|
+
|
|
18
|
+
## License
|
|
19
|
+
|
|
20
|
+
Apache-2.0
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { backendCase } from "./backend-case.js";
|
|
2
|
+
import { fixtureCommit } from "./backend-fixtures.js";
|
|
3
|
+
import { expectAccepted, newObjects, pushNewBranch, pushRef, seedRepo } from "./push-helpers.js";
|
|
4
|
+
import { assertEqual, expectGatewayError } from "@leed-ai/git-gateway-contract/behaviour/assertions";
|
|
5
|
+
// src/contract-suite/ancestry-cases.ts
|
|
6
|
+
const GROUP = "ancestry";
|
|
7
|
+
const MISSING = "0123456789abcdef0123456789abcdef01234567";
|
|
8
|
+
/** The optional isAncestor capability, or null when the backend does not offer it (the case passes). */
|
|
9
|
+
function capability(context) {
|
|
10
|
+
const { backend } = context;
|
|
11
|
+
if (backend.isAncestor === void 0) return null;
|
|
12
|
+
return async (ancestor, descendant, repo = context.repo) => backend.isAncestor?.(repo, ancestor, descendant);
|
|
13
|
+
}
|
|
14
|
+
/** isAncestor, for backends that offer it; a backend without it passes every case. */
|
|
15
|
+
const ancestryCases = [backendCase(GROUP, "isAncestor answers as git merge-base --is-ancestor does", async (context) => {
|
|
16
|
+
const isAncestor = capability(context);
|
|
17
|
+
if (isAncestor === null) return;
|
|
18
|
+
const root = await seedRepo(context, { "a.txt": "a\n" });
|
|
19
|
+
const second = await fixtureCommit({ "a.txt": "a, revised\n" }, [root.sha], "Second\n");
|
|
20
|
+
expectAccepted(await pushRef(context, "refs/heads/main", root.sha, second.sha, newObjects(second, root)), "refs/heads/main");
|
|
21
|
+
const side = await fixtureCommit({
|
|
22
|
+
"a.txt": "a\n",
|
|
23
|
+
"b.txt": "b\n"
|
|
24
|
+
}, [root.sha], "Side\n");
|
|
25
|
+
const merge = await fixtureCommit({
|
|
26
|
+
"a.txt": "a, revised\n",
|
|
27
|
+
"b.txt": "b\n"
|
|
28
|
+
}, [second.sha, side.sha], "Merge\n");
|
|
29
|
+
await pushNewBranch(context, "topic", {
|
|
30
|
+
...merge,
|
|
31
|
+
objects: [...side.objects, ...merge.objects]
|
|
32
|
+
});
|
|
33
|
+
assertEqual(await isAncestor(root.sha, second.sha), true, "parent of a commit");
|
|
34
|
+
assertEqual(await isAncestor(root.sha, merge.sha), true, "grandparent through a merge");
|
|
35
|
+
assertEqual(await isAncestor(side.sha, merge.sha), true, "second parent of a merge");
|
|
36
|
+
assertEqual(await isAncestor(merge.sha, merge.sha), true, "a commit is its own ancestor");
|
|
37
|
+
assertEqual(await isAncestor(second.sha, side.sha), false, "siblings");
|
|
38
|
+
assertEqual(await isAncestor(merge.sha, root.sha), false, "a descendant is not an ancestor");
|
|
39
|
+
}), backendCase(GROUP, "isAncestor is null for an unknown commit and repo_not_found for a missing repository", async (context) => {
|
|
40
|
+
const isAncestor = capability(context);
|
|
41
|
+
if (isAncestor === null) return;
|
|
42
|
+
const root = await seedRepo(context);
|
|
43
|
+
assertEqual(await isAncestor(MISSING, root.sha), null, "unknown ancestor");
|
|
44
|
+
assertEqual(await isAncestor(root.sha, MISSING), null, "unknown descendant");
|
|
45
|
+
await expectGatewayError(isAncestor(root.sha, root.sha, `${context.repo}-missing`), "repo_not_found");
|
|
46
|
+
})];
|
|
47
|
+
export { ancestryCases };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=ancestry-cases.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ancestry-cases.js","names":[],"sources":["../../src/contract-suite/ancestry-cases.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { assertEqual, expectGatewayError } from '@leed-ai/git-gateway-contract/behaviour/assertions';\n\nimport { backendCase, type BackendCase, type BackendContext } from './backend-case.ts';\nimport { fixtureCommit } from './backend-fixtures.ts';\nimport { expectAccepted, newObjects, pushNewBranch, pushRef, seedRepo } from './push-helpers.ts';\n\nconst GROUP = 'ancestry';\nconst MISSING = '0123456789abcdef0123456789abcdef01234567';\n\n/** The optional isAncestor capability, or null when the backend does not offer it (the case passes). */\nfunction capability(context: BackendContext) {\n const { backend } = context;\n if (backend.isAncestor === undefined) return null;\n return async (ancestor: string, descendant: string, repo = context.repo) =>\n backend.isAncestor?.(repo, ancestor, descendant);\n}\n\n/** isAncestor, for backends that offer it; a backend without it passes every case. */\nexport const ancestryCases: readonly BackendCase[] = [\n backendCase(GROUP, 'isAncestor answers as git merge-base --is-ancestor does', async (context) => {\n const isAncestor = capability(context);\n if (isAncestor === null) return;\n const root = await seedRepo(context, { 'a.txt': 'a\\n' });\n const second = await fixtureCommit({ 'a.txt': 'a, revised\\n' }, [root.sha], 'Second\\n');\n expectAccepted(\n await pushRef(context, 'refs/heads/main', root.sha, second.sha, newObjects(second, root)),\n 'refs/heads/main',\n );\n const side = await fixtureCommit({ 'a.txt': 'a\\n', 'b.txt': 'b\\n' }, [root.sha], 'Side\\n');\n const merge = await fixtureCommit(\n { 'a.txt': 'a, revised\\n', 'b.txt': 'b\\n' },\n [second.sha, side.sha],\n 'Merge\\n',\n );\n await pushNewBranch(context, 'topic', { ...merge, objects: [...side.objects, ...merge.objects] });\n assertEqual(await isAncestor(root.sha, second.sha), true, 'parent of a commit');\n assertEqual(await isAncestor(root.sha, merge.sha), true, 'grandparent through a merge');\n assertEqual(await isAncestor(side.sha, merge.sha), true, 'second parent of a merge');\n assertEqual(await isAncestor(merge.sha, merge.sha), true, 'a commit is its own ancestor');\n assertEqual(await isAncestor(second.sha, side.sha), false, 'siblings');\n assertEqual(await isAncestor(merge.sha, root.sha), false, 'a descendant is not an ancestor');\n }),\n backendCase(\n GROUP,\n 'isAncestor is null for an unknown commit and repo_not_found for a missing repository',\n async (context) => {\n const isAncestor = capability(context);\n if (isAncestor === null) return;\n const root = await seedRepo(context);\n assertEqual(await isAncestor(MISSING, root.sha), null, 'unknown ancestor');\n assertEqual(await isAncestor(root.sha, MISSING), null, 'unknown descendant');\n await expectGatewayError(isAncestor(root.sha, root.sha, `${context.repo}-missing`), 'repo_not_found');\n },\n ),\n];\n"],"mappings":";;;;;AAOA,MAAM,QAAQ;AACd,MAAM,UAAU;;AAGhB,SAAS,WAAW,SAAyB;CAC3C,MAAM,EAAE,YAAY;CACpB,IAAI,QAAQ,eAAe,KAAA,GAAW,OAAO;CAC7C,OAAO,OAAO,UAAkB,YAAoB,OAAO,QAAQ,SACjE,QAAQ,aAAa,MAAM,UAAU,UAAU;AACnD;;AAGA,MAAa,gBAAwC,CACnD,YAAY,OAAO,2DAA2D,OAAO,YAAY;CAC/F,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,eAAe,MAAM;CACzB,MAAM,OAAO,MAAM,SAAS,SAAS,EAAE,SAAS,MAAM,CAAC;CACvD,MAAM,SAAS,MAAM,cAAc,EAAE,SAAS,eAAe,GAAG,CAAC,KAAK,GAAG,GAAG,UAAU;CACtF,eACE,MAAM,QAAQ,SAAS,mBAAmB,KAAK,KAAK,OAAO,KAAK,WAAW,QAAQ,IAAI,CAAC,GACxF,iBACF;CACA,MAAM,OAAO,MAAM,cAAc;EAAE,SAAS;EAAO,SAAS;CAAM,GAAG,CAAC,KAAK,GAAG,GAAG,QAAQ;CACzF,MAAM,QAAQ,MAAM,cAClB;EAAE,SAAS;EAAgB,SAAS;CAAM,GAC1C,CAAC,OAAO,KAAK,KAAK,GAAG,GACrB,SACF;CACA,MAAM,cAAc,SAAS,SAAS;EAAE,GAAG;EAAO,SAAS,CAAC,GAAG,KAAK,SAAS,GAAG,MAAM,OAAO;CAAE,CAAC;CAChG,YAAY,MAAM,WAAW,KAAK,KAAK,OAAO,GAAG,GAAG,MAAM,oBAAoB;CAC9E,YAAY,MAAM,WAAW,KAAK,KAAK,MAAM,GAAG,GAAG,MAAM,6BAA6B;CACtF,YAAY,MAAM,WAAW,KAAK,KAAK,MAAM,GAAG,GAAG,MAAM,0BAA0B;CACnF,YAAY,MAAM,WAAW,MAAM,KAAK,MAAM,GAAG,GAAG,MAAM,8BAA8B;CACxF,YAAY,MAAM,WAAW,OAAO,KAAK,KAAK,GAAG,GAAG,OAAO,UAAU;CACrE,YAAY,MAAM,WAAW,MAAM,KAAK,KAAK,GAAG,GAAG,OAAO,iCAAiC;AAC7F,CAAC,GACD,YACE,OACA,wFACA,OAAO,YAAY;CACjB,MAAM,aAAa,WAAW,OAAO;CACrC,IAAI,eAAe,MAAM;CACzB,MAAM,OAAO,MAAM,SAAS,OAAO;CACnC,YAAY,MAAM,WAAW,SAAS,KAAK,GAAG,GAAG,MAAM,kBAAkB;CACzE,YAAY,MAAM,WAAW,KAAK,KAAK,OAAO,GAAG,MAAM,oBAAoB;CAC3E,MAAM,mBAAmB,WAAW,KAAK,KAAK,KAAK,KAAK,GAAG,QAAQ,KAAK,SAAS,GAAG,gBAAgB;AACtG,CACF,CACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { FetchLike, GitHttpClient } from "@leed-ai/git-gateway-core/smart-http/git-http-client";
|
|
2
|
+
import { GitAccess } from "@leed-ai/git-gateway-contract/storage/git-remote";
|
|
3
|
+
import { StorageBackend } from "@leed-ai/git-gateway-contract/storage/storage-backend";
|
|
4
|
+
/** How a storage host treats pushes the contract leaves to the host. */
|
|
5
|
+
export interface HostBehaviour {
|
|
6
|
+
/**
|
|
7
|
+
* A push whose update names the ref's current id but does not contain it (a non-fast-forward
|
|
8
|
+
* update sent with force): "accepted" (git's default on a bare repository) or "refused".
|
|
9
|
+
*/
|
|
10
|
+
readonly nonFastForward: 'accepted' | 'refused';
|
|
11
|
+
/** gitRemote(…, "read") yields a credential that cannot push. */
|
|
12
|
+
readonly readRemoteCannotPush: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** Everything a backend contract case runs with. */
|
|
15
|
+
export interface BackendContext {
|
|
16
|
+
readonly backend: StorageBackend;
|
|
17
|
+
/** A repository name no other case uses. The case creates it unless it tests creation. */
|
|
18
|
+
readonly repo: string;
|
|
19
|
+
readonly behaviour: HostBehaviour;
|
|
20
|
+
/** Size of the large-file case's file in bytes. */
|
|
21
|
+
readonly largeFileBytes: number;
|
|
22
|
+
/** A smart-HTTP client for a freshly minted remote of the case's repository. */
|
|
23
|
+
client(access: GitAccess): Promise<GitHttpClient>;
|
|
24
|
+
}
|
|
25
|
+
/** One rule of the storage backend contract. */
|
|
26
|
+
export interface BackendCase {
|
|
27
|
+
readonly group: string;
|
|
28
|
+
readonly name: string;
|
|
29
|
+
readonly run: (context: BackendContext) => Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
/** Declares a backend contract case. */
|
|
32
|
+
export declare function backendCase(group: string, name: string, run: (context: BackendContext) => Promise<void>): BackendCase;
|
|
33
|
+
/** A client factory for a backend's remotes, sending requests through `fetch`. */
|
|
34
|
+
export declare function clientFactory(backend: StorageBackend, repo: string, fetch: FetchLike | undefined): (access: GitAccess) => Promise<GitHttpClient>;
|
|
35
|
+
//# sourceMappingURL=backend-case.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GitHttpClient } from "@leed-ai/git-gateway-core/smart-http/git-http-client";
|
|
2
|
+
// src/contract-suite/backend-case.ts
|
|
3
|
+
/** Declares a backend contract case. */
|
|
4
|
+
function backendCase(group, name, run) {
|
|
5
|
+
return {
|
|
6
|
+
group,
|
|
7
|
+
name,
|
|
8
|
+
run
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/** A client factory for a backend's remotes, sending requests through `fetch`. */
|
|
12
|
+
function clientFactory(backend, repo, fetch) {
|
|
13
|
+
return async (access) => new GitHttpClient(await backend.gitRemote(repo, access), fetch === void 0 ? {} : { fetch });
|
|
14
|
+
}
|
|
15
|
+
export { backendCase, clientFactory };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=backend-case.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend-case.js","names":[],"sources":["../../src/contract-suite/backend-case.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { GitAccess } from '@leed-ai/git-gateway-contract/storage/git-remote';\nimport type { StorageBackend } from '@leed-ai/git-gateway-contract/storage/storage-backend';\nimport { GitHttpClient, type FetchLike } from '@leed-ai/git-gateway-core/smart-http/git-http-client';\n\n/** How a storage host treats pushes the contract leaves to the host. */\nexport interface HostBehaviour {\n /**\n * A push whose update names the ref's current id but does not contain it (a non-fast-forward\n * update sent with force): \"accepted\" (git's default on a bare repository) or \"refused\".\n */\n readonly nonFastForward: 'accepted' | 'refused';\n /** gitRemote(…, \"read\") yields a credential that cannot push. */\n readonly readRemoteCannotPush: boolean;\n}\n\n/** Everything a backend contract case runs with. */\nexport interface BackendContext {\n readonly backend: StorageBackend;\n /** A repository name no other case uses. The case creates it unless it tests creation. */\n readonly repo: string;\n readonly behaviour: HostBehaviour;\n /** Size of the large-file case's file in bytes. */\n readonly largeFileBytes: number;\n /** A smart-HTTP client for a freshly minted remote of the case's repository. */\n client(access: GitAccess): Promise<GitHttpClient>;\n}\n\n/** One rule of the storage backend contract. */\nexport interface BackendCase {\n readonly group: string;\n readonly name: string;\n readonly run: (context: BackendContext) => Promise<void>;\n}\n\n/** Declares a backend contract case. */\nexport function backendCase(\n group: string,\n name: string,\n run: (context: BackendContext) => Promise<void>,\n): BackendCase {\n return { group, name, run };\n}\n\n/** A client factory for a backend's remotes, sending requests through `fetch`. */\nexport function clientFactory(\n backend: StorageBackend,\n repo: string,\n fetch: FetchLike | undefined,\n): (access: GitAccess) => Promise<GitHttpClient> {\n return async (access) =>\n new GitHttpClient(await backend.gitRemote(repo, access), fetch === undefined ? {} : { fetch });\n}\n"],"mappings":";;;AAoCA,SAAgB,YACd,OACA,MACA,KACa;CACb,OAAO;EAAE;EAAO;EAAM;CAAI;AAC5B;;AAGA,SAAgB,cACd,SACA,MACA,OAC+C;CAC/C,OAAO,OAAO,WACZ,IAAI,cAAc,MAAM,QAAQ,UAAU,MAAM,MAAM,GAAG,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,MAAM,CAAC;AACjG"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { BackendCase, HostBehaviour } from "./backend-case.js";
|
|
2
|
+
import { FetchLike } from "@leed-ai/git-gateway-core/smart-http/git-http-client";
|
|
3
|
+
import { StorageBackend } from "@leed-ai/git-gateway-contract/storage/storage-backend";
|
|
4
|
+
import { TestRegistrar } from "@leed-ai/git-gateway-contract/behaviour/behaviour-suite";
|
|
5
|
+
/** Every case of the storage backend contract, grouped by area. */
|
|
6
|
+
export declare const BACKEND_CASES: readonly BackendCase[];
|
|
7
|
+
/** How to run the backend contract suite against one backend. */
|
|
8
|
+
export interface BackendSuiteOptions {
|
|
9
|
+
/** Suite title; default "StorageBackend contract". */
|
|
10
|
+
readonly name?: string;
|
|
11
|
+
/** Returns the backend under test; called once per case. */
|
|
12
|
+
readonly createBackend: () => StorageBackend | Promise<StorageBackend>;
|
|
13
|
+
/** How the host treats what the contract leaves to it. */
|
|
14
|
+
readonly behaviour: HostBehaviour;
|
|
15
|
+
/** Sends requests to the backend's git remotes; default the global fetch. */
|
|
16
|
+
readonly fetch?: FetchLike;
|
|
17
|
+
/** Prefix of every repository name the cases create; default "contract". Keep it short. */
|
|
18
|
+
readonly repoPrefix?: string;
|
|
19
|
+
/** Size of the large-file case's file; default 5 MiB. */
|
|
20
|
+
readonly largeFileBytes?: number;
|
|
21
|
+
/** Delete each case's repository when it ends; default true. */
|
|
22
|
+
readonly cleanup?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Which cases to register; default every case. For a backend mode that cannot run a whole group,
|
|
25
|
+
* such as names that createRepo refuses, which the lifecycle group creates.
|
|
26
|
+
*/
|
|
27
|
+
readonly include?: (entry: BackendCase) => boolean;
|
|
28
|
+
}
|
|
29
|
+
/** Runs one case against a fresh backend and a repository name no other case uses. */
|
|
30
|
+
export declare function runBackendCase(entry: BackendCase, options: BackendSuiteOptions): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Registers the storage backend contract suite with a test framework: one test per case, grouped
|
|
33
|
+
* by area. Every backend runs it unchanged — the in-memory backend, the Artifacts local binding
|
|
34
|
+
* and a disposable GitLab project — declaring only how its host treats non-fast-forward pushes
|
|
35
|
+
* and read credentials.
|
|
36
|
+
*
|
|
37
|
+
* registerBackendContractSuite({ describe, it }, {
|
|
38
|
+
* createBackend: () => backend,
|
|
39
|
+
* fetch: backend.fetch,
|
|
40
|
+
* behaviour: { nonFastForward: 'accepted', readRemoteCannotPush: true },
|
|
41
|
+
* });
|
|
42
|
+
*/
|
|
43
|
+
export declare function registerBackendContractSuite(test: TestRegistrar, options: BackendSuiteOptions): void;
|
|
44
|
+
//# sourceMappingURL=backend-contract-suite.d.ts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ancestryCases } from "./ancestry-cases.js";
|
|
2
|
+
import { clientFactory } from "./backend-case.js";
|
|
3
|
+
import { contentCases } from "./content-cases.js";
|
|
4
|
+
import { lifecycleCases } from "./lifecycle-cases.js";
|
|
5
|
+
import { pushCases } from "./push-cases.js";
|
|
6
|
+
import { readCases } from "./read-cases.js";
|
|
7
|
+
import { transportCases } from "./transport-cases.js";
|
|
8
|
+
// src/contract-suite/backend-contract-suite.ts
|
|
9
|
+
/** Every case of the storage backend contract, grouped by area. */
|
|
10
|
+
const BACKEND_CASES = [
|
|
11
|
+
...lifecycleCases,
|
|
12
|
+
...transportCases,
|
|
13
|
+
...readCases,
|
|
14
|
+
...pushCases,
|
|
15
|
+
...contentCases,
|
|
16
|
+
...ancestryCases
|
|
17
|
+
];
|
|
18
|
+
let runCounter = 0;
|
|
19
|
+
/** Runs one case against a fresh backend and a repository name no other case uses. */
|
|
20
|
+
async function runBackendCase(entry, options) {
|
|
21
|
+
runCounter += 1;
|
|
22
|
+
const backend = await options.createBackend();
|
|
23
|
+
const repo = `${options.repoPrefix ?? "contract"}-${runCounter}-${crypto.randomUUID().slice(0, 8)}`;
|
|
24
|
+
try {
|
|
25
|
+
await entry.run({
|
|
26
|
+
backend,
|
|
27
|
+
repo,
|
|
28
|
+
behaviour: options.behaviour,
|
|
29
|
+
largeFileBytes: options.largeFileBytes ?? 5242880,
|
|
30
|
+
client: clientFactory(backend, repo, options.fetch)
|
|
31
|
+
});
|
|
32
|
+
} finally {
|
|
33
|
+
if (options.cleanup !== false) await backend.deleteRepo(repo);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Registers the storage backend contract suite with a test framework: one test per case, grouped
|
|
38
|
+
* by area. Every backend runs it unchanged — the in-memory backend, the Artifacts local binding
|
|
39
|
+
* and a disposable GitLab project — declaring only how its host treats non-fast-forward pushes
|
|
40
|
+
* and read credentials.
|
|
41
|
+
*
|
|
42
|
+
* registerBackendContractSuite({ describe, it }, {
|
|
43
|
+
* createBackend: () => backend,
|
|
44
|
+
* fetch: backend.fetch,
|
|
45
|
+
* behaviour: { nonFastForward: 'accepted', readRemoteCannotPush: true },
|
|
46
|
+
* });
|
|
47
|
+
*/
|
|
48
|
+
function registerBackendContractSuite(test, options) {
|
|
49
|
+
const included = BACKEND_CASES.filter((entry) => options.include?.(entry) ?? true);
|
|
50
|
+
const groups = Map.groupBy(included, (entry) => entry.group);
|
|
51
|
+
test.describe(options.name ?? "StorageBackend contract", () => {
|
|
52
|
+
for (const [group, cases] of groups) test.describe(group, () => {
|
|
53
|
+
for (const entry of cases) test.it(entry.name, () => runBackendCase(entry, options));
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
export { BACKEND_CASES, registerBackendContractSuite, runBackendCase };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=backend-contract-suite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend-contract-suite.js","names":[],"sources":["../../src/contract-suite/backend-contract-suite.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { TestRegistrar } from '@leed-ai/git-gateway-contract/behaviour/behaviour-suite';\nimport type { StorageBackend } from '@leed-ai/git-gateway-contract/storage/storage-backend';\nimport type { FetchLike } from '@leed-ai/git-gateway-core/smart-http/git-http-client';\n\nimport { ancestryCases } from './ancestry-cases.ts';\nimport { clientFactory, type BackendCase, type HostBehaviour } from './backend-case.ts';\nimport { contentCases } from './content-cases.ts';\nimport { lifecycleCases } from './lifecycle-cases.ts';\nimport { pushCases } from './push-cases.ts';\nimport { readCases } from './read-cases.ts';\nimport { transportCases } from './transport-cases.ts';\n\n/** Every case of the storage backend contract, grouped by area. */\nexport const BACKEND_CASES: readonly BackendCase[] = [\n ...lifecycleCases,\n ...transportCases,\n ...readCases,\n ...pushCases,\n ...contentCases,\n ...ancestryCases,\n];\n\n/** How to run the backend contract suite against one backend. */\nexport interface BackendSuiteOptions {\n /** Suite title; default \"StorageBackend contract\". */\n readonly name?: string;\n /** Returns the backend under test; called once per case. */\n readonly createBackend: () => StorageBackend | Promise<StorageBackend>;\n /** How the host treats what the contract leaves to it. */\n readonly behaviour: HostBehaviour;\n /** Sends requests to the backend's git remotes; default the global fetch. */\n readonly fetch?: FetchLike;\n /** Prefix of every repository name the cases create; default \"contract\". Keep it short. */\n readonly repoPrefix?: string;\n /** Size of the large-file case's file; default 5 MiB. */\n readonly largeFileBytes?: number;\n /** Delete each case's repository when it ends; default true. */\n readonly cleanup?: boolean;\n /**\n * Which cases to register; default every case. For a backend mode that cannot run a whole group,\n * such as names that createRepo refuses, which the lifecycle group creates.\n */\n readonly include?: (entry: BackendCase) => boolean;\n}\n\nlet runCounter = 0;\n\n/** Runs one case against a fresh backend and a repository name no other case uses. */\nexport async function runBackendCase(entry: BackendCase, options: BackendSuiteOptions): Promise<void> {\n runCounter += 1;\n const backend = await options.createBackend();\n const repo = `${options.repoPrefix ?? 'contract'}-${runCounter}-${crypto.randomUUID().slice(0, 8)}`;\n try {\n await entry.run({\n backend,\n repo,\n behaviour: options.behaviour,\n largeFileBytes: options.largeFileBytes ?? 5 * 1024 * 1024,\n client: clientFactory(backend, repo, options.fetch),\n });\n } finally {\n if (options.cleanup !== false) await backend.deleteRepo(repo);\n }\n}\n\n/**\n * Registers the storage backend contract suite with a test framework: one test per case, grouped\n * by area. Every backend runs it unchanged — the in-memory backend, the Artifacts local binding\n * and a disposable GitLab project — declaring only how its host treats non-fast-forward pushes\n * and read credentials.\n *\n * registerBackendContractSuite({ describe, it }, {\n * createBackend: () => backend,\n * fetch: backend.fetch,\n * behaviour: { nonFastForward: 'accepted', readRemoteCannotPush: true },\n * });\n */\nexport function registerBackendContractSuite(test: TestRegistrar, options: BackendSuiteOptions): void {\n const included = BACKEND_CASES.filter((entry) => options.include?.(entry) ?? true);\n const groups = Map.groupBy(included, (entry) => entry.group);\n test.describe(options.name ?? 'StorageBackend contract', () => {\n for (const [group, cases] of groups) {\n test.describe(group, () => {\n for (const entry of cases) test.it(entry.name, () => runBackendCase(entry, options));\n });\n }\n });\n}\n"],"mappings":";;;;;;;;;AAcA,MAAa,gBAAwC;CACnD,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;AACL;AAyBA,IAAI,aAAa;;AAGjB,eAAsB,eAAe,OAAoB,SAA6C;CACpG,cAAc;CACd,MAAM,UAAU,MAAM,QAAQ,cAAc;CAC5C,MAAM,OAAO,GAAG,QAAQ,cAAc,WAAW,GAAG,WAAW,GAAG,OAAO,WAAW,CAAC,CAAC,MAAM,GAAG,CAAC;CAChG,IAAI;EACF,MAAM,MAAM,IAAI;GACd;GACA;GACA,WAAW,QAAQ;GACnB,gBAAgB,QAAQ,kBAAkB;GAC1C,QAAQ,cAAc,SAAS,MAAM,QAAQ,KAAK;EACpD,CAAC;CACH,UAAU;EACR,IAAI,QAAQ,YAAY,OAAO,MAAM,QAAQ,WAAW,IAAI;CAC9D;AACF;;;;;;;;;;;;;AAcA,SAAgB,6BAA6B,MAAqB,SAAoC;CACpG,MAAM,WAAW,cAAc,QAAQ,UAAU,QAAQ,UAAU,KAAK,KAAK,IAAI;CACjF,MAAM,SAAS,IAAI,QAAQ,WAAW,UAAU,MAAM,KAAK;CAC3D,KAAK,SAAS,QAAQ,QAAQ,iCAAiC;EAC7D,KAAK,MAAM,CAAC,OAAO,UAAU,QAC3B,KAAK,SAAS,aAAa;GACzB,KAAK,MAAM,SAAS,OAAO,KAAK,GAAG,MAAM,YAAY,eAAe,OAAO,OAAO,CAAC;EACrF,CAAC;CAEL,CAAC;AACH"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Commit } from "@leed-ai/git-gateway-contract/schemas/commit";
|
|
2
|
+
import { GitObject } from "@leed-ai/git-gateway-core/schemas/git-object";
|
|
3
|
+
/** A file of a fixture commit: bytes (or UTF-8 text) and mode. */
|
|
4
|
+
export interface FixtureFile {
|
|
5
|
+
readonly content: Uint8Array | string;
|
|
6
|
+
readonly mode?: '100644' | '100755' | '120000';
|
|
7
|
+
}
|
|
8
|
+
/** A commit built for a test, with every new object it needs. */
|
|
9
|
+
export interface FixtureCommit {
|
|
10
|
+
readonly sha: string;
|
|
11
|
+
readonly commit: Commit;
|
|
12
|
+
/** The commit, its root tree, every subtree and every blob. */
|
|
13
|
+
readonly objects: GitObject[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Builds a commit of exactly `files` (path → content) with the given parents, entirely in
|
|
17
|
+
* memory through the core encoders. Dates are whole seconds in UTC, so a backend that reads the
|
|
18
|
+
* commit back can report it exactly.
|
|
19
|
+
*/
|
|
20
|
+
export declare function fixtureCommit(files: Readonly<Record<string, FixtureFile | string>>, parents?: readonly string[], message?: string): Promise<FixtureCommit>;
|
|
21
|
+
/** Deterministic pseudo-random bytes (xorshift32), so a large binary fixture is reproducible. */
|
|
22
|
+
export declare function pseudoRandomBytes(length: number, seed?: number): Uint8Array;
|
|
23
|
+
/** Every byte value 0–255, twice: the smallest file that exercises all of them. */
|
|
24
|
+
export declare const ALL_BYTES: Uint8Array;
|
|
25
|
+
//# sourceMappingURL=backend-fixtures.d.ts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { createCommit } from "@leed-ai/git-gateway-core/objects/commit-object";
|
|
2
|
+
import { createObject } from "@leed-ai/git-gateway-core/objects/hash-object";
|
|
3
|
+
import { editTree } from "@leed-ai/git-gateway-core/tree/edit-tree";
|
|
4
|
+
import { decodeTree } from "@leed-ai/git-gateway-core/objects/tree-object";
|
|
5
|
+
// src/contract-suite/backend-fixtures.ts
|
|
6
|
+
const encoder = new TextEncoder();
|
|
7
|
+
const AUTHOR = {
|
|
8
|
+
name: "Contract Suite",
|
|
9
|
+
email: "contract@example.com"
|
|
10
|
+
};
|
|
11
|
+
let clock = Date.parse("2026-01-01T00:00:00Z");
|
|
12
|
+
/** A fresh whole-second UTC date, one minute after the last, so histories have distinct dates. */
|
|
13
|
+
function nextDate() {
|
|
14
|
+
clock += 6e4;
|
|
15
|
+
return new Date(clock).toISOString();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Builds a commit of exactly `files` (path → content) with the given parents, entirely in
|
|
19
|
+
* memory through the core encoders. Dates are whole seconds in UTC, so a backend that reads the
|
|
20
|
+
* commit back can report it exactly.
|
|
21
|
+
*/
|
|
22
|
+
async function fixtureCommit(files, parents = [], message = "Contract suite commit\n") {
|
|
23
|
+
const objects = /* @__PURE__ */ new Map();
|
|
24
|
+
const changes = [];
|
|
25
|
+
for (const [path, file] of Object.entries(files)) {
|
|
26
|
+
const spec = typeof file === "string" ? { content: file } : file;
|
|
27
|
+
const blob = await createObject("blob", typeof spec.content === "string" ? encoder.encode(spec.content) : spec.content);
|
|
28
|
+
objects.set(blob.sha, blob);
|
|
29
|
+
changes.push({
|
|
30
|
+
op: "set",
|
|
31
|
+
path,
|
|
32
|
+
mode: spec.mode ?? "100644",
|
|
33
|
+
sha: blob.sha
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const edited = await editTree({
|
|
37
|
+
tree: null,
|
|
38
|
+
changes
|
|
39
|
+
}, { async readTree(sha) {
|
|
40
|
+
const object = objects.get(sha);
|
|
41
|
+
return object?.type === "tree" ? decodeTree(object.data, sha) : null;
|
|
42
|
+
} });
|
|
43
|
+
for (const object of edited.objects) objects.set(object.sha, object);
|
|
44
|
+
const signature = {
|
|
45
|
+
...AUTHOR,
|
|
46
|
+
date: nextDate()
|
|
47
|
+
};
|
|
48
|
+
const created = await createCommit({
|
|
49
|
+
tree: edited.tree,
|
|
50
|
+
parents: [...parents],
|
|
51
|
+
author: signature,
|
|
52
|
+
committer: signature,
|
|
53
|
+
message
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
sha: created.object.sha,
|
|
57
|
+
commit: created.commit,
|
|
58
|
+
objects: [created.object, ...objects.values()]
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** Deterministic pseudo-random bytes (xorshift32), so a large binary fixture is reproducible. */
|
|
62
|
+
function pseudoRandomBytes(length, seed = 2654435769) {
|
|
63
|
+
const out = new Uint8Array(length);
|
|
64
|
+
let state = seed >>> 0 || 1;
|
|
65
|
+
for (let index = 0; index < length; index += 1) {
|
|
66
|
+
state ^= state << 13;
|
|
67
|
+
state >>>= 0;
|
|
68
|
+
state ^= state >>> 17;
|
|
69
|
+
state ^= state << 5;
|
|
70
|
+
state >>>= 0;
|
|
71
|
+
out[index] = state & 255;
|
|
72
|
+
}
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
/** Every byte value 0–255, twice: the smallest file that exercises all of them. */
|
|
76
|
+
const ALL_BYTES = Uint8Array.from({ length: 512 }, (_, index) => index % 256);
|
|
77
|
+
export { ALL_BYTES, fixtureCommit, pseudoRandomBytes };
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=backend-fixtures.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend-fixtures.js","names":[],"sources":["../../src/contract-suite/backend-fixtures.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { Commit } from '@leed-ai/git-gateway-contract/schemas/commit';\nimport { createCommit } from '@leed-ai/git-gateway-core/objects/commit-object';\nimport { createObject } from '@leed-ai/git-gateway-core/objects/hash-object';\nimport type { GitObject, GitTreeEntry } from '@leed-ai/git-gateway-core/schemas/git-object';\nimport { editTree } from '@leed-ai/git-gateway-core/tree/edit-tree';\nimport { decodeTree } from '@leed-ai/git-gateway-core/objects/tree-object';\n\n/** A file of a fixture commit: bytes (or UTF-8 text) and mode. */\nexport interface FixtureFile {\n readonly content: Uint8Array | string;\n readonly mode?: '100644' | '100755' | '120000';\n}\n\n/** A commit built for a test, with every new object it needs. */\nexport interface FixtureCommit {\n readonly sha: string;\n readonly commit: Commit;\n /** The commit, its root tree, every subtree and every blob. */\n readonly objects: GitObject[];\n}\n\nconst encoder = new TextEncoder();\nconst AUTHOR = { name: 'Contract Suite', email: 'contract@example.com' };\nlet clock = Date.parse('2026-01-01T00:00:00Z');\n\n/** A fresh whole-second UTC date, one minute after the last, so histories have distinct dates. */\nfunction nextDate(): string {\n clock += 60_000;\n return new Date(clock).toISOString();\n}\n\n/**\n * Builds a commit of exactly `files` (path → content) with the given parents, entirely in\n * memory through the core encoders. Dates are whole seconds in UTC, so a backend that reads the\n * commit back can report it exactly.\n */\nexport async function fixtureCommit(\n files: Readonly<Record<string, FixtureFile | string>>,\n parents: readonly string[] = [],\n message = 'Contract suite commit\\n',\n): Promise<FixtureCommit> {\n const objects = new Map<string, GitObject>();\n const changes = [];\n for (const [path, file] of Object.entries(files)) {\n const spec = typeof file === 'string' ? { content: file } : file;\n const blob = await createObject(\n 'blob',\n typeof spec.content === 'string' ? encoder.encode(spec.content) : spec.content,\n );\n objects.set(blob.sha, blob);\n changes.push({ op: 'set' as const, path, mode: spec.mode ?? '100644', sha: blob.sha });\n }\n const reader = {\n async readTree(sha: string): Promise<GitTreeEntry[] | null> {\n const object = objects.get(sha);\n return object?.type === 'tree' ? decodeTree(object.data, sha) : null;\n },\n };\n const edited = await editTree({ tree: null, changes }, reader);\n for (const object of edited.objects) objects.set(object.sha, object);\n const signature = { ...AUTHOR, date: nextDate() };\n const created = await createCommit({\n tree: edited.tree,\n parents: [...parents],\n author: signature,\n committer: signature,\n message,\n });\n return { sha: created.object.sha, commit: created.commit, objects: [created.object, ...objects.values()] };\n}\n\n/** Deterministic pseudo-random bytes (xorshift32), so a large binary fixture is reproducible. */\nexport function pseudoRandomBytes(length: number, seed = 0x9e3779b9): Uint8Array {\n const out = new Uint8Array(length);\n let state = seed >>> 0 || 1;\n for (let index = 0; index < length; index += 1) {\n state ^= state << 13;\n state >>>= 0;\n state ^= state >>> 17;\n state ^= state << 5;\n state >>>= 0;\n out[index] = state & 0xff;\n }\n return out;\n}\n\n/** Every byte value 0–255, twice: the smallest file that exercises all of them. */\nexport const ALL_BYTES: Uint8Array = Uint8Array.from({ length: 512 }, (_, index) => index % 256);\n"],"mappings":";;;;;AAsBA,MAAM,UAAU,IAAI,YAAY;AAChC,MAAM,SAAS;CAAE,MAAM;CAAkB,OAAO;AAAuB;AACvE,IAAI,QAAQ,KAAK,MAAM,sBAAsB;;AAG7C,SAAS,WAAmB;CAC1B,SAAS;CACT,OAAO,IAAI,KAAK,KAAK,CAAC,CAAC,YAAY;AACrC;;;;;;AAOA,eAAsB,cACpB,OACA,UAA6B,CAAC,GAC9B,UAAU,2BACc;CACxB,MAAM,0BAAU,IAAI,IAAuB;CAC3C,MAAM,UAAU,CAAC;CACjB,KAAK,MAAM,CAAC,MAAM,SAAS,OAAO,QAAQ,KAAK,GAAG;EAChD,MAAM,OAAO,OAAO,SAAS,WAAW,EAAE,SAAS,KAAK,IAAI;EAC5D,MAAM,OAAO,MAAM,aACjB,QACA,OAAO,KAAK,YAAY,WAAW,QAAQ,OAAO,KAAK,OAAO,IAAI,KAAK,OACzE;EACA,QAAQ,IAAI,KAAK,KAAK,IAAI;EAC1B,QAAQ,KAAK;GAAE,IAAI;GAAgB;GAAM,MAAM,KAAK,QAAQ;GAAU,KAAK,KAAK;EAAI,CAAC;CACvF;CAOA,MAAM,SAAS,MAAM,SAAS;EAAE,MAAM;EAAM;CAAQ,GAAG,EALrD,MAAM,SAAS,KAA6C;EAC1D,MAAM,SAAS,QAAQ,IAAI,GAAG;EAC9B,OAAO,QAAQ,SAAS,SAAS,WAAW,OAAO,MAAM,GAAG,IAAI;CAClE,EAE0D,CAAC;CAC7D,KAAK,MAAM,UAAU,OAAO,SAAS,QAAQ,IAAI,OAAO,KAAK,MAAM;CACnE,MAAM,YAAY;EAAE,GAAG;EAAQ,MAAM,SAAS;CAAE;CAChD,MAAM,UAAU,MAAM,aAAa;EACjC,MAAM,OAAO;EACb,SAAS,CAAC,GAAG,OAAO;EACpB,QAAQ;EACR,WAAW;EACX;CACF,CAAC;CACD,OAAO;EAAE,KAAK,QAAQ,OAAO;EAAK,QAAQ,QAAQ;EAAQ,SAAS,CAAC,QAAQ,QAAQ,GAAG,QAAQ,OAAO,CAAC;CAAE;AAC3G;;AAGA,SAAgB,kBAAkB,QAAgB,OAAO,YAAwB;CAC/E,MAAM,MAAM,IAAI,WAAW,MAAM;CACjC,IAAI,QAAQ,SAAS,KAAK;CAC1B,KAAK,IAAI,QAAQ,GAAG,QAAQ,QAAQ,SAAS,GAAG;EAC9C,SAAS,SAAS;EAClB,WAAW;EACX,SAAS,UAAU;EACnB,SAAS,SAAS;EAClB,WAAW;EACX,IAAI,SAAS,QAAQ;CACvB;CACA,OAAO;AACT;;AAGA,MAAa,YAAwB,WAAW,KAAK,EAAE,QAAQ,IAAI,IAAI,GAAG,UAAU,QAAQ,GAAG"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { backendCase } from "./backend-case.js";
|
|
2
|
+
import { pseudoRandomBytes } from "./backend-fixtures.js";
|
|
3
|
+
import { seedRepo } from "./push-helpers.js";
|
|
4
|
+
import { assertEqual, assertTrue, present } from "@leed-ai/git-gateway-contract/behaviour/assertions";
|
|
5
|
+
import { sameBytes } from "@leed-ai/git-gateway-contract/reference/bytes";
|
|
6
|
+
// src/contract-suite/content-cases.ts
|
|
7
|
+
const GROUP = "content";
|
|
8
|
+
/** Large and binary files, deep trees. */
|
|
9
|
+
const contentCases = [backendCase(GROUP, "a large binary file round-trips through readBlob, readFile and fetch", async (context) => {
|
|
10
|
+
const bytes = pseudoRandomBytes(context.largeFileBytes);
|
|
11
|
+
const seeded = await seedRepo(context, { "assets/large.bin": { content: bytes } });
|
|
12
|
+
const blob = present(seeded.objects.find((object) => object.type === "blob" && object.data.length === bytes.length), "blob");
|
|
13
|
+
const { backend, repo } = context;
|
|
14
|
+
assertTrue(sameBytes(present(await backend.readBlob(repo, blob.sha), "readBlob"), bytes), "readBlob bytes");
|
|
15
|
+
assertTrue(sameBytes(present(await backend.readFile(repo, "main", "assets/large.bin"), "readFile"), bytes), "readFile bytes");
|
|
16
|
+
const fetched = await (await context.client("read")).fetchPack({ wants: [seeded.sha] });
|
|
17
|
+
const got = present(fetched.objects.find((object) => object.sha === blob.sha), "fetched blob");
|
|
18
|
+
assertTrue(sameBytes(got.data, bytes), "fetched bytes");
|
|
19
|
+
}), backendCase(GROUP, "an empty file and a deep tree are stored and read back", async (context) => {
|
|
20
|
+
const deep = Array.from({ length: 24 }, (_, index) => `d${index}`).join("/");
|
|
21
|
+
await seedRepo(context, {
|
|
22
|
+
"empty.txt": "",
|
|
23
|
+
[`${deep}/leaf.txt`]: "leaf\n"
|
|
24
|
+
});
|
|
25
|
+
const { backend, repo } = context;
|
|
26
|
+
assertEqual(present(await backend.readFile(repo, "main", "empty.txt"), "empty file").length, 0, "empty file is empty");
|
|
27
|
+
assertEqual(new TextDecoder().decode(present(await backend.readFile(repo, "main", `${deep}/leaf.txt`), "leaf")), "leaf\n", "deep leaf");
|
|
28
|
+
})];
|
|
29
|
+
export { contentCases };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=content-cases.js.map
|