@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
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Commit } from "@leed-ai/git-gateway-contract/schemas/commit";
|
|
2
|
+
import { GitObject, GitTreeEntry } from "@leed-ai/git-gateway-core/schemas/git-object";
|
|
3
|
+
/** One repository held in memory: its objects, its refs and the branch HEAD names. */
|
|
4
|
+
export declare class MemoryRepository {
|
|
5
|
+
#private;
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly defaultBranch: string;
|
|
8
|
+
readonly createdAt: string;
|
|
9
|
+
/** Every object by id. Objects are never removed, like a git repository before gc. */
|
|
10
|
+
readonly objects: Map<string, {
|
|
11
|
+
type: "blob" | "commit" | "tree";
|
|
12
|
+
sha: string;
|
|
13
|
+
data: Uint8Array<ArrayBufferLike>;
|
|
14
|
+
}>;
|
|
15
|
+
/** Every ref by full name ("refs/heads/main") to the id it names. */
|
|
16
|
+
readonly refs: Map<string, string>;
|
|
17
|
+
constructor(name: string, defaultBranch: string, createdAt: string);
|
|
18
|
+
/** The full name of the ref HEAD points at. */
|
|
19
|
+
get headRef(): string;
|
|
20
|
+
/** Stores objects; an id already present is kept as it is. */
|
|
21
|
+
put(objects: readonly GitObject[]): void;
|
|
22
|
+
/** An object of a given type by id, or null. */
|
|
23
|
+
object(sha: string, type?: GitObject['type']): GitObject | null;
|
|
24
|
+
/** A commit by id, decoded, or null. */
|
|
25
|
+
commit(sha: string): Commit | null;
|
|
26
|
+
/** A tree's entries by id, decoded, or null. */
|
|
27
|
+
tree(sha: string): GitTreeEntry[] | null;
|
|
28
|
+
/** The ids an object links to: a commit's tree and parents, a tree's entries (submodules excluded). */
|
|
29
|
+
links(object: GitObject): string[];
|
|
30
|
+
/**
|
|
31
|
+
* The ids of objects reachable from `starts` that are missing, stopping at objects already
|
|
32
|
+
* known complete. Records every fully present closure as complete, so later checks are cheap.
|
|
33
|
+
*/
|
|
34
|
+
missingFrom(starts: readonly string[]): string[];
|
|
35
|
+
/** Every object reachable from `wants`, leaving out everything reachable from `haves`. */
|
|
36
|
+
reachable(wants: readonly string[], haves: readonly string[]): GitObject[];
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=memory-repository.d.ts.map
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { decodeCommit } from "@leed-ai/git-gateway-core/objects/commit-object";
|
|
2
|
+
import { decodeTree } from "@leed-ai/git-gateway-core/objects/tree-object";
|
|
3
|
+
// src/memory/memory-repository.ts
|
|
4
|
+
/** One repository held in memory: its objects, its refs and the branch HEAD names. */
|
|
5
|
+
var MemoryRepository = class {
|
|
6
|
+
name;
|
|
7
|
+
defaultBranch;
|
|
8
|
+
createdAt;
|
|
9
|
+
/** Every object by id. Objects are never removed, like a git repository before gc. */
|
|
10
|
+
objects = /* @__PURE__ */ new Map();
|
|
11
|
+
/** Every ref by full name ("refs/heads/main") to the id it names. */
|
|
12
|
+
refs = /* @__PURE__ */ new Map();
|
|
13
|
+
/** Ids whose whole closure (everything they reach) is known to be present. */
|
|
14
|
+
#complete = /* @__PURE__ */ new Set();
|
|
15
|
+
constructor(name, defaultBranch, createdAt) {
|
|
16
|
+
this.name = name;
|
|
17
|
+
this.defaultBranch = defaultBranch;
|
|
18
|
+
this.createdAt = createdAt;
|
|
19
|
+
}
|
|
20
|
+
/** The full name of the ref HEAD points at. */
|
|
21
|
+
get headRef() {
|
|
22
|
+
return `refs/heads/${this.defaultBranch}`;
|
|
23
|
+
}
|
|
24
|
+
/** Stores objects; an id already present is kept as it is. */
|
|
25
|
+
put(objects) {
|
|
26
|
+
for (const object of objects) if (!this.objects.has(object.sha)) this.objects.set(object.sha, object);
|
|
27
|
+
}
|
|
28
|
+
/** An object of a given type by id, or null. */
|
|
29
|
+
object(sha, type) {
|
|
30
|
+
const object = this.objects.get(sha);
|
|
31
|
+
return object === void 0 || type !== void 0 && object.type !== type ? null : object;
|
|
32
|
+
}
|
|
33
|
+
/** A commit by id, decoded, or null. */
|
|
34
|
+
commit(sha) {
|
|
35
|
+
const object = this.object(sha, "commit");
|
|
36
|
+
return object === null ? null : decodeCommit(sha, object.data);
|
|
37
|
+
}
|
|
38
|
+
/** A tree's entries by id, decoded, or null. */
|
|
39
|
+
tree(sha) {
|
|
40
|
+
const object = this.object(sha, "tree");
|
|
41
|
+
return object === null ? null : decodeTree(object.data, sha);
|
|
42
|
+
}
|
|
43
|
+
/** The ids an object links to: a commit's tree and parents, a tree's entries (submodules excluded). */
|
|
44
|
+
links(object) {
|
|
45
|
+
if (object.type === "commit") {
|
|
46
|
+
const commit = decodeCommit(object.sha, object.data);
|
|
47
|
+
return [commit.tree, ...commit.parents];
|
|
48
|
+
}
|
|
49
|
+
if (object.type === "tree") return decodeTree(object.data, object.sha).filter((entry) => entry.mode !== "160000").map((entry) => entry.sha);
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The ids of objects reachable from `starts` that are missing, stopping at objects already
|
|
54
|
+
* known complete. Records every fully present closure as complete, so later checks are cheap.
|
|
55
|
+
*/
|
|
56
|
+
missingFrom(starts) {
|
|
57
|
+
const missing = [];
|
|
58
|
+
const seen = /* @__PURE__ */ new Set();
|
|
59
|
+
const visited = [];
|
|
60
|
+
const stack = [...starts];
|
|
61
|
+
while (stack.length > 0) {
|
|
62
|
+
const sha = stack.pop() ?? "";
|
|
63
|
+
if (seen.has(sha) || this.#complete.has(sha)) continue;
|
|
64
|
+
seen.add(sha);
|
|
65
|
+
const object = this.objects.get(sha);
|
|
66
|
+
if (object === void 0) {
|
|
67
|
+
missing.push(sha);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
visited.push(sha);
|
|
71
|
+
stack.push(...this.links(object));
|
|
72
|
+
}
|
|
73
|
+
if (missing.length === 0) for (const sha of visited) this.#complete.add(sha);
|
|
74
|
+
return missing;
|
|
75
|
+
}
|
|
76
|
+
/** Every object reachable from `wants`, leaving out everything reachable from `haves`. */
|
|
77
|
+
reachable(wants, haves) {
|
|
78
|
+
const excluded = this.#closure(haves.filter((sha) => this.objects.has(sha)), /* @__PURE__ */ new Set());
|
|
79
|
+
return [...this.#closure(wants, excluded)].flatMap((sha) => this.objects.get(sha) ?? []);
|
|
80
|
+
}
|
|
81
|
+
#closure(starts, stop) {
|
|
82
|
+
const out = /* @__PURE__ */ new Set();
|
|
83
|
+
const stack = [...starts];
|
|
84
|
+
while (stack.length > 0) {
|
|
85
|
+
const sha = stack.pop() ?? "";
|
|
86
|
+
if (out.has(sha) || stop.has(sha)) continue;
|
|
87
|
+
const object = this.objects.get(sha);
|
|
88
|
+
if (object === void 0) continue;
|
|
89
|
+
out.add(sha);
|
|
90
|
+
stack.push(...this.links(object));
|
|
91
|
+
}
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
export { MemoryRepository };
|
|
96
|
+
|
|
97
|
+
//# sourceMappingURL=memory-repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-repository.js","names":[],"sources":["../../src/memory/memory-repository.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { Commit } from '@leed-ai/git-gateway-contract/schemas/commit';\nimport { decodeCommit } from '@leed-ai/git-gateway-core/objects/commit-object';\nimport { decodeTree } from '@leed-ai/git-gateway-core/objects/tree-object';\nimport type { GitObject, GitTreeEntry } from '@leed-ai/git-gateway-core/schemas/git-object';\n\n/** One repository held in memory: its objects, its refs and the branch HEAD names. */\nexport class MemoryRepository {\n readonly name: string;\n readonly defaultBranch: string;\n readonly createdAt: string;\n /** Every object by id. Objects are never removed, like a git repository before gc. */\n readonly objects = new Map<string, GitObject>();\n /** Every ref by full name (\"refs/heads/main\") to the id it names. */\n readonly refs = new Map<string, string>();\n /** Ids whose whole closure (everything they reach) is known to be present. */\n readonly #complete = new Set<string>();\n\n constructor(name: string, defaultBranch: string, createdAt: string) {\n this.name = name;\n this.defaultBranch = defaultBranch;\n this.createdAt = createdAt;\n }\n\n /** The full name of the ref HEAD points at. */\n get headRef(): string {\n return `refs/heads/${this.defaultBranch}`;\n }\n\n /** Stores objects; an id already present is kept as it is. */\n put(objects: readonly GitObject[]): void {\n for (const object of objects) if (!this.objects.has(object.sha)) this.objects.set(object.sha, object);\n }\n\n /** An object of a given type by id, or null. */\n object(sha: string, type?: GitObject['type']): GitObject | null {\n const object = this.objects.get(sha);\n return object === undefined || (type !== undefined && object.type !== type) ? null : object;\n }\n\n /** A commit by id, decoded, or null. */\n commit(sha: string): Commit | null {\n const object = this.object(sha, 'commit');\n return object === null ? null : decodeCommit(sha, object.data);\n }\n\n /** A tree's entries by id, decoded, or null. */\n tree(sha: string): GitTreeEntry[] | null {\n const object = this.object(sha, 'tree');\n return object === null ? null : decodeTree(object.data, sha);\n }\n\n /** The ids an object links to: a commit's tree and parents, a tree's entries (submodules excluded). */\n links(object: GitObject): string[] {\n if (object.type === 'commit') {\n const commit = decodeCommit(object.sha, object.data);\n return [commit.tree, ...commit.parents];\n }\n if (object.type === 'tree') {\n return decodeTree(object.data, object.sha)\n .filter((entry) => entry.mode !== '160000')\n .map((entry) => entry.sha);\n }\n return [];\n }\n\n /**\n * The ids of objects reachable from `starts` that are missing, stopping at objects already\n * known complete. Records every fully present closure as complete, so later checks are cheap.\n */\n missingFrom(starts: readonly string[]): string[] {\n const missing: string[] = [];\n const seen = new Set<string>();\n const visited: string[] = [];\n const stack = [...starts];\n while (stack.length > 0) {\n const sha = stack.pop() ?? '';\n if (seen.has(sha) || this.#complete.has(sha)) continue;\n seen.add(sha);\n const object = this.objects.get(sha);\n if (object === undefined) {\n missing.push(sha);\n continue;\n }\n visited.push(sha);\n stack.push(...this.links(object));\n }\n if (missing.length === 0) for (const sha of visited) this.#complete.add(sha);\n return missing;\n }\n\n /** Every object reachable from `wants`, leaving out everything reachable from `haves`. */\n reachable(wants: readonly string[], haves: readonly string[]): GitObject[] {\n const excluded = this.#closure(\n haves.filter((sha) => this.objects.has(sha)),\n new Set(),\n );\n const included = this.#closure(wants, excluded);\n return [...included].flatMap((sha) => this.objects.get(sha) ?? []);\n }\n\n #closure(starts: readonly string[], stop: ReadonlySet<string>): Set<string> {\n const out = new Set<string>();\n const stack = [...starts];\n while (stack.length > 0) {\n const sha = stack.pop() ?? '';\n if (out.has(sha) || stop.has(sha)) continue;\n const object = this.objects.get(sha);\n if (object === undefined) continue;\n out.add(sha);\n stack.push(...this.links(object));\n }\n return out;\n }\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { GitAccess } from "@leed-ai/git-gateway-contract/storage/git-remote";
|
|
2
|
+
/** A minted credential: which repository it opens, for what, and until when. */
|
|
3
|
+
export interface MemoryGrant {
|
|
4
|
+
readonly repo: string;
|
|
5
|
+
readonly access: GitAccess;
|
|
6
|
+
/** Expiry in milliseconds since the epoch. */
|
|
7
|
+
readonly expiresAt: number;
|
|
8
|
+
}
|
|
9
|
+
/** Short-lived bearer tokens for the in-memory git remotes, scoped to one repository and access level. */
|
|
10
|
+
export declare class MemoryTokens {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(now: () => Date);
|
|
13
|
+
/** Mints a random token for `repo` that lasts `ttlSeconds`. */
|
|
14
|
+
mint(repo: string, access: GitAccess, ttlSeconds: number): {
|
|
15
|
+
token: string;
|
|
16
|
+
expiresAt: Date;
|
|
17
|
+
};
|
|
18
|
+
/** The live grant a token carries, or null when it is unknown or expired. */
|
|
19
|
+
check(token: string): MemoryGrant | null;
|
|
20
|
+
/** Revokes every token of a repository (when it is deleted). */
|
|
21
|
+
revokeRepo(repo: string): void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The credential a request carries: a Bearer token, or the password of HTTP Basic (git sends
|
|
25
|
+
* credentials as Basic; the password is the token). Null when there is none.
|
|
26
|
+
*/
|
|
27
|
+
export declare function credentialOf(request: Request): string | null;
|
|
28
|
+
//# sourceMappingURL=memory-tokens.d.ts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// src/memory/memory-tokens.ts
|
|
2
|
+
/** Short-lived bearer tokens for the in-memory git remotes, scoped to one repository and access level. */
|
|
3
|
+
var MemoryTokens = class {
|
|
4
|
+
#grants = /* @__PURE__ */ new Map();
|
|
5
|
+
#now;
|
|
6
|
+
constructor(now) {
|
|
7
|
+
this.#now = now;
|
|
8
|
+
}
|
|
9
|
+
/** Mints a random token for `repo` that lasts `ttlSeconds`. */
|
|
10
|
+
mint(repo, access, ttlSeconds) {
|
|
11
|
+
const token = `mem_${crypto.randomUUID().replaceAll("-", "")}`;
|
|
12
|
+
const expiresAt = this.#now().getTime() + ttlSeconds * 1e3;
|
|
13
|
+
this.#grants.set(token, {
|
|
14
|
+
repo,
|
|
15
|
+
access,
|
|
16
|
+
expiresAt
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
token,
|
|
20
|
+
expiresAt: new Date(expiresAt)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** The live grant a token carries, or null when it is unknown or expired. */
|
|
24
|
+
check(token) {
|
|
25
|
+
const grant = this.#grants.get(token);
|
|
26
|
+
if (grant === void 0) return null;
|
|
27
|
+
if (grant.expiresAt <= this.#now().getTime()) {
|
|
28
|
+
this.#grants.delete(token);
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
return grant;
|
|
32
|
+
}
|
|
33
|
+
/** Revokes every token of a repository (when it is deleted). */
|
|
34
|
+
revokeRepo(repo) {
|
|
35
|
+
for (const [token, grant] of this.#grants) if (grant.repo === repo) this.#grants.delete(token);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* The credential a request carries: a Bearer token, or the password of HTTP Basic (git sends
|
|
40
|
+
* credentials as Basic; the password is the token). Null when there is none.
|
|
41
|
+
*/
|
|
42
|
+
function credentialOf(request) {
|
|
43
|
+
const header = request.headers.get("Authorization");
|
|
44
|
+
if (header === null) return null;
|
|
45
|
+
const [scheme, value] = header.split(" ", 2);
|
|
46
|
+
if (value === void 0) return null;
|
|
47
|
+
if (scheme?.toLowerCase() === "bearer") return value;
|
|
48
|
+
if (scheme?.toLowerCase() !== "basic") return null;
|
|
49
|
+
try {
|
|
50
|
+
const decoded = atob(value);
|
|
51
|
+
const colon = decoded.indexOf(":");
|
|
52
|
+
return colon === -1 ? null : decoded.slice(colon + 1);
|
|
53
|
+
} catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export { MemoryTokens, credentialOf };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=memory-tokens.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-tokens.js","names":[],"sources":["../../src/memory/memory-tokens.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { GitAccess } from '@leed-ai/git-gateway-contract/storage/git-remote';\n\n/** A minted credential: which repository it opens, for what, and until when. */\nexport interface MemoryGrant {\n readonly repo: string;\n readonly access: GitAccess;\n /** Expiry in milliseconds since the epoch. */\n readonly expiresAt: number;\n}\n\n/** Short-lived bearer tokens for the in-memory git remotes, scoped to one repository and access level. */\nexport class MemoryTokens {\n readonly #grants = new Map<string, MemoryGrant>();\n readonly #now: () => Date;\n\n constructor(now: () => Date) {\n this.#now = now;\n }\n\n /** Mints a random token for `repo` that lasts `ttlSeconds`. */\n mint(repo: string, access: GitAccess, ttlSeconds: number): { token: string; expiresAt: Date } {\n const token = `mem_${crypto.randomUUID().replaceAll('-', '')}`;\n const expiresAt = this.#now().getTime() + ttlSeconds * 1000;\n this.#grants.set(token, { repo, access, expiresAt });\n return { token, expiresAt: new Date(expiresAt) };\n }\n\n /** The live grant a token carries, or null when it is unknown or expired. */\n check(token: string): MemoryGrant | null {\n const grant = this.#grants.get(token);\n if (grant === undefined) return null;\n if (grant.expiresAt <= this.#now().getTime()) {\n this.#grants.delete(token);\n return null;\n }\n return grant;\n }\n\n /** Revokes every token of a repository (when it is deleted). */\n revokeRepo(repo: string): void {\n for (const [token, grant] of this.#grants) if (grant.repo === repo) this.#grants.delete(token);\n }\n}\n\n/**\n * The credential a request carries: a Bearer token, or the password of HTTP Basic (git sends\n * credentials as Basic; the password is the token). Null when there is none.\n */\nexport function credentialOf(request: Request): string | null {\n const header = request.headers.get('Authorization');\n if (header === null) return null;\n const [scheme, value] = header.split(' ', 2);\n if (value === undefined) return null;\n if (scheme?.toLowerCase() === 'bearer') return value;\n if (scheme?.toLowerCase() !== 'basic') return null;\n try {\n const decoded = atob(value);\n const colon = decoded.indexOf(':');\n return colon === -1 ? null : decoded.slice(colon + 1);\n } catch {\n return null;\n }\n}\n"],"mappings":";;AAYA,IAAa,eAAb,MAA0B;CACxB,0BAAmB,IAAI,IAAyB;CAChD;CAEA,YAAY,KAAiB;EAC3B,KAAK,OAAO;CACd;;CAGA,KAAK,MAAc,QAAmB,YAAwD;EAC5F,MAAM,QAAQ,OAAO,OAAO,WAAW,CAAC,CAAC,WAAW,KAAK,EAAE;EAC3D,MAAM,YAAY,KAAK,KAAK,CAAC,CAAC,QAAQ,IAAI,aAAa;EACvD,KAAK,QAAQ,IAAI,OAAO;GAAE;GAAM;GAAQ;EAAU,CAAC;EACnD,OAAO;GAAE;GAAO,WAAW,IAAI,KAAK,SAAS;EAAE;CACjD;;CAGA,MAAM,OAAmC;EACvC,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAK;EACpC,IAAI,UAAU,KAAA,GAAW,OAAO;EAChC,IAAI,MAAM,aAAa,KAAK,KAAK,CAAC,CAAC,QAAQ,GAAG;GAC5C,KAAK,QAAQ,OAAO,KAAK;GACzB,OAAO;EACT;EACA,OAAO;CACT;;CAGA,WAAW,MAAoB;EAC7B,KAAK,MAAM,CAAC,OAAO,UAAU,KAAK,SAAS,IAAI,MAAM,SAAS,MAAM,KAAK,QAAQ,OAAO,KAAK;CAC/F;AACF;;;;;AAMA,SAAgB,aAAa,SAAiC;CAC5D,MAAM,SAAS,QAAQ,QAAQ,IAAI,eAAe;CAClD,IAAI,WAAW,MAAM,OAAO;CAC5B,MAAM,CAAC,QAAQ,SAAS,OAAO,MAAM,KAAK,CAAC;CAC3C,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,IAAI,QAAQ,YAAY,MAAM,UAAU,OAAO;CAC/C,IAAI,QAAQ,YAAY,MAAM,SAAS,OAAO;CAC9C,IAAI;EACF,MAAM,UAAU,KAAK,KAAK;EAC1B,MAAM,QAAQ,QAAQ,QAAQ,GAAG;EACjC,OAAO,UAAU,KAAK,OAAO,QAAQ,MAAM,QAAQ,CAAC;CACtD,QAAQ;EACN,OAAO;CACT;AACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { MemoryRepository } from "./memory-repository.js";
|
|
2
|
+
import { GitObject } from "@leed-ai/git-gateway-core/schemas/git-object";
|
|
3
|
+
/** What an upload-pack request asks to have sent. */
|
|
4
|
+
export interface PackSelection {
|
|
5
|
+
readonly wants: readonly string[];
|
|
6
|
+
readonly haves: readonly string[];
|
|
7
|
+
/** Commits the client says it has without their parents (its "shallow" lines). */
|
|
8
|
+
readonly clientShallow?: readonly string[];
|
|
9
|
+
/** "deepen <n>": commits at most this many generations from each wanted commit. */
|
|
10
|
+
readonly depth?: number;
|
|
11
|
+
/** A partial-clone filter: "blob:none", "blob:limit=<n>[kmg]" or "tree:<depth>". */
|
|
12
|
+
readonly filter?: string;
|
|
13
|
+
}
|
|
14
|
+
/** The objects to send and the shallow boundary to report. */
|
|
15
|
+
export interface SelectedPack {
|
|
16
|
+
readonly objects: GitObject[];
|
|
17
|
+
/** Commits the client must now treat as having no parents (the new deepen boundary). */
|
|
18
|
+
readonly shallow: string[];
|
|
19
|
+
/** Commits of the client's old boundary whose parents are now sent. */
|
|
20
|
+
readonly unshallow: string[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Chooses the objects an upload-pack answer carries: everything reachable from the wants and not
|
|
24
|
+
* from the haves (whose history stops at the client's shallow commits), cut at `depth`
|
|
25
|
+
* generations of commits when deepening, and with the filter
|
|
26
|
+
* applied to trees and blobs (depth counted from each root tree, a wanted tree being a root).
|
|
27
|
+
* Explicitly wanted objects are always sent, as git sends them.
|
|
28
|
+
*/
|
|
29
|
+
export declare function selectPack(repo: MemoryRepository, selection: PackSelection): SelectedPack;
|
|
30
|
+
//# sourceMappingURL=pack-selection.d.ts.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// src/memory/pack-selection.ts
|
|
2
|
+
const UNITS = {
|
|
3
|
+
"": 1,
|
|
4
|
+
k: 1024,
|
|
5
|
+
m: 1024 ** 2,
|
|
6
|
+
g: 1024 ** 3
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Whether an object `depth` levels below a root tree passes the filter. Explicit wants always pass.
|
|
10
|
+
* As in git's list-objects-filter.c, blob:limit=<n> keeps only blobs strictly smaller than n bytes.
|
|
11
|
+
*/
|
|
12
|
+
function passesFilter(filter, object, depth) {
|
|
13
|
+
if (filter === void 0) return true;
|
|
14
|
+
if (filter === "blob:none") return object.type !== "blob";
|
|
15
|
+
const limit = /^blob:limit=(\d+)([kmg]?)$/.exec(filter);
|
|
16
|
+
if (limit !== null) return object.type !== "blob" || object.data.length < Number(limit[1]) * (UNITS[limit[2] ?? ""] ?? 1);
|
|
17
|
+
const tree = /^tree:(\d+)$/.exec(filter);
|
|
18
|
+
return tree === null || depth < Number(tree[1]);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Walks commits from the wants: within `depth` generations when deepening (through commits the
|
|
22
|
+
* client already has, which are not sent), otherwise until reaching what the client has. Returns
|
|
23
|
+
* the commits to send and the boundary commits whose parents are cut off.
|
|
24
|
+
*/
|
|
25
|
+
function selectCommits(repo, wants, depth, excluded) {
|
|
26
|
+
const commits = [];
|
|
27
|
+
const boundary = [];
|
|
28
|
+
const walked = /* @__PURE__ */ new Set();
|
|
29
|
+
let frontier = wants.filter((sha) => repo.object(sha, "commit") !== null);
|
|
30
|
+
for (let generation = 1; frontier.length > 0; generation += 1) {
|
|
31
|
+
const next = [];
|
|
32
|
+
for (const sha of frontier) {
|
|
33
|
+
if (walked.has(sha) || depth === void 0 && excluded.has(sha)) continue;
|
|
34
|
+
walked.add(sha);
|
|
35
|
+
if (!excluded.has(sha)) commits.push(sha);
|
|
36
|
+
const parents = repo.commit(sha)?.parents ?? [];
|
|
37
|
+
if (depth !== void 0 && generation >= depth) {
|
|
38
|
+
if (parents.length > 0) boundary.push(sha);
|
|
39
|
+
} else next.push(...parents);
|
|
40
|
+
}
|
|
41
|
+
frontier = next;
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
commits,
|
|
45
|
+
boundary,
|
|
46
|
+
walked
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** Everything the client has: the closure of its haves, not crossing its shallow boundary. */
|
|
50
|
+
function clientHas(repo, haves, clientShallow) {
|
|
51
|
+
const out = /* @__PURE__ */ new Set();
|
|
52
|
+
const stack = haves.filter((sha) => repo.objects.has(sha));
|
|
53
|
+
while (stack.length > 0) {
|
|
54
|
+
const sha = stack.pop() ?? "";
|
|
55
|
+
if (out.has(sha)) continue;
|
|
56
|
+
const object = repo.objects.get(sha);
|
|
57
|
+
if (object === void 0) continue;
|
|
58
|
+
out.add(sha);
|
|
59
|
+
const links = repo.links(object);
|
|
60
|
+
stack.push(...object.type === "commit" && clientShallow.has(sha) ? links.slice(0, 1) : links);
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Chooses the objects an upload-pack answer carries: everything reachable from the wants and not
|
|
66
|
+
* from the haves (whose history stops at the client's shallow commits), cut at `depth`
|
|
67
|
+
* generations of commits when deepening, and with the filter
|
|
68
|
+
* applied to trees and blobs (depth counted from each root tree, a wanted tree being a root).
|
|
69
|
+
* Explicitly wanted objects are always sent, as git sends them.
|
|
70
|
+
*/
|
|
71
|
+
function selectPack(repo, selection) {
|
|
72
|
+
const clientShallow = new Set(selection.clientShallow ?? []);
|
|
73
|
+
const excluded = clientHas(repo, selection.haves, clientShallow);
|
|
74
|
+
const { commits, boundary, walked } = selectCommits(repo, selection.wants, selection.depth, excluded);
|
|
75
|
+
const shallow = boundary.filter((sha) => !clientShallow.has(sha));
|
|
76
|
+
const unshallow = [...clientShallow].filter((sha) => walked.has(sha) && !boundary.includes(sha));
|
|
77
|
+
const out = /* @__PURE__ */ new Map();
|
|
78
|
+
const visit = (sha, depth, explicit) => {
|
|
79
|
+
if (out.has(sha) || excluded.has(sha)) return;
|
|
80
|
+
const object = repo.object(sha);
|
|
81
|
+
if (object === null || object.type === "commit") return;
|
|
82
|
+
if (!explicit && !passesFilter(selection.filter, object, depth)) return;
|
|
83
|
+
out.set(sha, object);
|
|
84
|
+
if (object.type === "tree") {
|
|
85
|
+
for (const entry of repo.tree(sha) ?? []) if (entry.mode !== "160000") visit(entry.sha, depth + 1, false);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
for (const sha of commits) {
|
|
89
|
+
const commit = repo.commit(sha);
|
|
90
|
+
const object = repo.object(sha, "commit");
|
|
91
|
+
if (commit === null || object === null) continue;
|
|
92
|
+
out.set(sha, object);
|
|
93
|
+
visit(commit.tree, 0, false);
|
|
94
|
+
}
|
|
95
|
+
for (const want of selection.wants) visit(want, 0, true);
|
|
96
|
+
return {
|
|
97
|
+
objects: [...out.values()],
|
|
98
|
+
shallow,
|
|
99
|
+
unshallow
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
export { selectPack };
|
|
103
|
+
|
|
104
|
+
//# sourceMappingURL=pack-selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pack-selection.js","names":[],"sources":["../../src/memory/pack-selection.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { GitObject } from '@leed-ai/git-gateway-core/schemas/git-object';\n\nimport type { MemoryRepository } from './memory-repository.ts';\n\n/** What an upload-pack request asks to have sent. */\nexport interface PackSelection {\n readonly wants: readonly string[];\n readonly haves: readonly string[];\n /** Commits the client says it has without their parents (its \"shallow\" lines). */\n readonly clientShallow?: readonly string[];\n /** \"deepen <n>\": commits at most this many generations from each wanted commit. */\n readonly depth?: number;\n /** A partial-clone filter: \"blob:none\", \"blob:limit=<n>[kmg]\" or \"tree:<depth>\". */\n readonly filter?: string;\n}\n\n/** The objects to send and the shallow boundary to report. */\nexport interface SelectedPack {\n readonly objects: GitObject[];\n /** Commits the client must now treat as having no parents (the new deepen boundary). */\n readonly shallow: string[];\n /** Commits of the client's old boundary whose parents are now sent. */\n readonly unshallow: string[];\n}\n\nconst UNITS: Readonly<Record<string, number>> = { '': 1, k: 1024, m: 1024 ** 2, g: 1024 ** 3 };\n\n/**\n * Whether an object `depth` levels below a root tree passes the filter. Explicit wants always pass.\n * As in git's list-objects-filter.c, blob:limit=<n> keeps only blobs strictly smaller than n bytes.\n */\nfunction passesFilter(filter: string | undefined, object: GitObject, depth: number): boolean {\n if (filter === undefined) return true;\n if (filter === 'blob:none') return object.type !== 'blob';\n const limit = /^blob:limit=(\\d+)([kmg]?)$/.exec(filter);\n if (limit !== null)\n return object.type !== 'blob' || object.data.length < Number(limit[1]) * (UNITS[limit[2] ?? ''] ?? 1);\n const tree = /^tree:(\\d+)$/.exec(filter);\n return tree === null || depth < Number(tree[1]);\n}\n\n/**\n * Walks commits from the wants: within `depth` generations when deepening (through commits the\n * client already has, which are not sent), otherwise until reaching what the client has. Returns\n * the commits to send and the boundary commits whose parents are cut off.\n */\nfunction selectCommits(\n repo: MemoryRepository,\n wants: readonly string[],\n depth: number | undefined,\n excluded: ReadonlySet<string>,\n): { commits: string[]; boundary: string[]; walked: Set<string> } {\n const commits: string[] = [];\n const boundary: string[] = [];\n const walked = new Set<string>();\n let frontier = wants.filter((sha) => repo.object(sha, 'commit') !== null);\n for (let generation = 1; frontier.length > 0; generation += 1) {\n const next: string[] = [];\n for (const sha of frontier) {\n if (walked.has(sha) || (depth === undefined && excluded.has(sha))) continue;\n walked.add(sha);\n if (!excluded.has(sha)) commits.push(sha);\n const parents = repo.commit(sha)?.parents ?? [];\n if (depth !== undefined && generation >= depth) {\n if (parents.length > 0) boundary.push(sha);\n } else next.push(...parents);\n }\n frontier = next;\n }\n return { commits, boundary, walked };\n}\n\n/** Everything the client has: the closure of its haves, not crossing its shallow boundary. */\nfunction clientHas(\n repo: MemoryRepository,\n haves: readonly string[],\n clientShallow: ReadonlySet<string>,\n): Set<string> {\n const out = new Set<string>();\n const stack = haves.filter((sha) => repo.objects.has(sha));\n while (stack.length > 0) {\n const sha = stack.pop() ?? '';\n if (out.has(sha)) continue;\n const object = repo.objects.get(sha);\n if (object === undefined) continue;\n out.add(sha);\n const links = repo.links(object);\n stack.push(...(object.type === 'commit' && clientShallow.has(sha) ? links.slice(0, 1) : links));\n }\n return out;\n}\n\n/**\n * Chooses the objects an upload-pack answer carries: everything reachable from the wants and not\n * from the haves (whose history stops at the client's shallow commits), cut at `depth`\n * generations of commits when deepening, and with the filter\n * applied to trees and blobs (depth counted from each root tree, a wanted tree being a root).\n * Explicitly wanted objects are always sent, as git sends them.\n */\nexport function selectPack(repo: MemoryRepository, selection: PackSelection): SelectedPack {\n const clientShallow = new Set(selection.clientShallow ?? []);\n const excluded = clientHas(repo, selection.haves, clientShallow);\n const { commits, boundary, walked } = selectCommits(repo, selection.wants, selection.depth, excluded);\n const shallow = boundary.filter((sha) => !clientShallow.has(sha));\n const unshallow = [...clientShallow].filter((sha) => walked.has(sha) && !boundary.includes(sha));\n const out = new Map<string, GitObject>();\n const visit = (sha: string, depth: number, explicit: boolean): void => {\n if (out.has(sha) || excluded.has(sha)) return;\n const object = repo.object(sha);\n if (object === null || object.type === 'commit') return;\n if (!explicit && !passesFilter(selection.filter, object, depth)) return;\n out.set(sha, object);\n if (object.type === 'tree')\n for (const entry of repo.tree(sha) ?? [])\n if (entry.mode !== '160000') visit(entry.sha, depth + 1, false);\n };\n for (const sha of commits) {\n const commit = repo.commit(sha);\n const object = repo.object(sha, 'commit');\n if (commit === null || object === null) continue;\n out.set(sha, object);\n visit(commit.tree, 0, false);\n }\n for (const want of selection.wants) visit(want, 0, true);\n return { objects: [...out.values()], shallow, unshallow };\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MemoryRepository } from "./memory-repository.js";
|
|
2
|
+
/** The capabilities the in-memory receive-pack offers, as git's own receive-pack does. */
|
|
3
|
+
export declare const RECEIVE_PACK_CAPABILITIES: readonly string[];
|
|
4
|
+
/** The receive-pack ref advertisement: every ref in name order (no HEAD, as git sends it). */
|
|
5
|
+
export declare function receivePackAdvertisement(repo: MemoryRepository): Uint8Array;
|
|
6
|
+
/**
|
|
7
|
+
* Applies one receive-pack request (protocol v0/v1) to an in-memory repository, the way git's
|
|
8
|
+
* receive-pack does on a bare repository: unpack the pack, then update each ref only if it still
|
|
9
|
+
* names the command's old id (a stale old id is refused with "cannot lock ref"). Non-fast-forward
|
|
10
|
+
* updates with a matching old id are accepted, as git accepts them unless
|
|
11
|
+
* receive.denyNonFastForwards is set. "atomic" applies all commands or none. Ref checks and
|
|
12
|
+
* updates run without an await between them, so concurrent pushes to one ref cannot both win.
|
|
13
|
+
*/
|
|
14
|
+
export declare function answerReceivePack(repo: MemoryRepository, body: Uint8Array): Promise<Uint8Array>;
|
|
15
|
+
//# sourceMappingURL=receive-pack-service.d.ts.map
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { ZERO_SHA } from "@leed-ai/git-gateway-contract/schemas/sha";
|
|
2
|
+
import { isCoreError } from "@leed-ai/git-gateway-core/core-error";
|
|
3
|
+
import { streamOf } from "@leed-ai/git-gateway-core/bytes";
|
|
4
|
+
import { readPack } from "@leed-ai/git-gateway-core/pack/read-pack";
|
|
5
|
+
import { readLengthHeader } from "@leed-ai/git-gateway-core/pkt-line/length-header";
|
|
6
|
+
import { parseReceivePackRequest } from "@leed-ai/git-gateway-core/receive-pack/parse-request";
|
|
7
|
+
import { encodeErrPacket, encodeReportStatus, reportStatusFraming } from "@leed-ai/git-gateway-core/receive-pack/report-status";
|
|
8
|
+
import { encodeRefAdvertisement } from "@leed-ai/git-gateway-core/smart-http/ref-advertisement";
|
|
9
|
+
// src/memory/receive-pack-service.ts
|
|
10
|
+
/** The capabilities the in-memory receive-pack offers, as git's own receive-pack does. */
|
|
11
|
+
const RECEIVE_PACK_CAPABILITIES = [
|
|
12
|
+
"report-status",
|
|
13
|
+
"delete-refs",
|
|
14
|
+
"side-band-64k",
|
|
15
|
+
"quiet",
|
|
16
|
+
"atomic",
|
|
17
|
+
"ofs-delta",
|
|
18
|
+
"push-options",
|
|
19
|
+
"object-format=sha1",
|
|
20
|
+
"agent=git-gateway-testkit"
|
|
21
|
+
];
|
|
22
|
+
/** The receive-pack ref advertisement: every ref in name order (no HEAD, as git sends it). */
|
|
23
|
+
function receivePackAdvertisement(repo) {
|
|
24
|
+
return encodeRefAdvertisement({
|
|
25
|
+
service: "git-receive-pack",
|
|
26
|
+
refs: [...repo.refs.keys()].toSorted().map((name) => ({
|
|
27
|
+
name,
|
|
28
|
+
sha: repo.refs.get(name) ?? "",
|
|
29
|
+
peeled: null
|
|
30
|
+
})),
|
|
31
|
+
capabilities: [...RECEIVE_PACK_CAPABILITIES],
|
|
32
|
+
symrefs: {}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** Where the pack starts: after the shallow lines, the command list and the push options. */
|
|
36
|
+
function packOffset(body, request) {
|
|
37
|
+
let flushes = request.capabilities.includes("push-options") ? 2 : 1;
|
|
38
|
+
let offset = 0;
|
|
39
|
+
while (flushes > 0 && offset + 4 <= body.length) {
|
|
40
|
+
const header = readLengthHeader(body.subarray(offset, offset + 4), offset);
|
|
41
|
+
if (header.kind === "special") {
|
|
42
|
+
flushes -= 1;
|
|
43
|
+
offset += 4;
|
|
44
|
+
} else offset += 4 + header.payloadLength;
|
|
45
|
+
}
|
|
46
|
+
return offset;
|
|
47
|
+
}
|
|
48
|
+
/** Why a command cannot apply to the repository as it stands, or null when it can. */
|
|
49
|
+
function refuse(repo, command) {
|
|
50
|
+
const current = repo.refs.get(command.ref) ?? ZERO_SHA;
|
|
51
|
+
if (command.oldSha === ZERO_SHA && command.newSha === ZERO_SHA) return "nothing to do";
|
|
52
|
+
if (current !== command.oldSha) return `cannot lock ref '${command.ref}': is at ${current} but expected ${command.oldSha}`;
|
|
53
|
+
if (command.newSha === ZERO_SHA) return null;
|
|
54
|
+
const target = repo.object(command.newSha);
|
|
55
|
+
if (target === null) return "missing necessary objects";
|
|
56
|
+
if (command.ref.startsWith("refs/heads/") && target.type !== "commit") return "branch must point at a commit";
|
|
57
|
+
if (repo.missingFrom([command.newSha]).length > 0) return "missing necessary objects";
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
/** Unpacks the pack, if any, into the repository; returns the unpack status line. */
|
|
61
|
+
async function unpack(repo, body, offset, needsPack) {
|
|
62
|
+
const pack = body.subarray(offset);
|
|
63
|
+
if (pack.length === 0) return needsPack ? "unpack-objects abnormal exit" : "ok";
|
|
64
|
+
try {
|
|
65
|
+
repo.put(await readPack(pack, { lookupBase: async (sha) => repo.object(sha) }));
|
|
66
|
+
return "ok";
|
|
67
|
+
} catch (error) {
|
|
68
|
+
return isCoreError(error) ? error.message.replaceAll("\n", " ") : "unpack-objects abnormal exit";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Applies one receive-pack request (protocol v0/v1) to an in-memory repository, the way git's
|
|
73
|
+
* receive-pack does on a bare repository: unpack the pack, then update each ref only if it still
|
|
74
|
+
* names the command's old id (a stale old id is refused with "cannot lock ref"). Non-fast-forward
|
|
75
|
+
* updates with a matching old id are accepted, as git accepts them unless
|
|
76
|
+
* receive.denyNonFastForwards is set. "atomic" applies all commands or none. Ref checks and
|
|
77
|
+
* updates run without an await between them, so concurrent pushes to one ref cannot both win.
|
|
78
|
+
*/
|
|
79
|
+
async function answerReceivePack(repo, body) {
|
|
80
|
+
let request;
|
|
81
|
+
try {
|
|
82
|
+
request = (await parseReceivePackRequest(streamOf(body))).request;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
return encodeErrPacket(error instanceof Error ? error.message : "malformed request");
|
|
85
|
+
}
|
|
86
|
+
const framing = reportStatusFraming(request.capabilities.filter((capability) => RECEIVE_PACK_CAPABILITIES.includes(capability)));
|
|
87
|
+
const needsPack = request.commands.some((command) => command.newSha !== ZERO_SHA);
|
|
88
|
+
const unpackStatus = await unpack(repo, body, packOffset(body, request), needsPack);
|
|
89
|
+
let refs;
|
|
90
|
+
if (unpackStatus !== "ok") refs = request.commands.map((command) => ({
|
|
91
|
+
ref: command.ref,
|
|
92
|
+
status: "ng",
|
|
93
|
+
reason: "unpacker error"
|
|
94
|
+
}));
|
|
95
|
+
else refs = applyCommands(repo, request.commands, request.capabilities.includes("atomic"));
|
|
96
|
+
if (!request.capabilities.includes("report-status")) return /* @__PURE__ */ new Uint8Array(0);
|
|
97
|
+
return encodeReportStatus({
|
|
98
|
+
unpack: unpackStatus,
|
|
99
|
+
refs
|
|
100
|
+
}, framing);
|
|
101
|
+
}
|
|
102
|
+
function applyCommands(repo, commands, atomic) {
|
|
103
|
+
const reasons = commands.map((command) => refuse(repo, command));
|
|
104
|
+
if (atomic && reasons.some((reason) => reason !== null)) return commands.map((command, index) => ({
|
|
105
|
+
ref: command.ref,
|
|
106
|
+
status: "ng",
|
|
107
|
+
reason: reasons[index] ?? "atomic transaction failed"
|
|
108
|
+
}));
|
|
109
|
+
return commands.map((command, index) => {
|
|
110
|
+
const reason = reasons[index];
|
|
111
|
+
if (reason !== null && reason !== void 0) return {
|
|
112
|
+
ref: command.ref,
|
|
113
|
+
status: "ng",
|
|
114
|
+
reason
|
|
115
|
+
};
|
|
116
|
+
if (command.newSha === ZERO_SHA) repo.refs.delete(command.ref);
|
|
117
|
+
else repo.refs.set(command.ref, command.newSha);
|
|
118
|
+
return {
|
|
119
|
+
ref: command.ref,
|
|
120
|
+
status: "ok"
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
export { RECEIVE_PACK_CAPABILITIES, answerReceivePack, receivePackAdvertisement };
|
|
125
|
+
|
|
126
|
+
//# sourceMappingURL=receive-pack-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"receive-pack-service.js","names":[],"sources":["../../src/memory/receive-pack-service.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { ZERO_SHA } from '@leed-ai/git-gateway-contract/schemas/sha';\nimport { streamOf } from '@leed-ai/git-gateway-core/bytes';\nimport { isCoreError } from '@leed-ai/git-gateway-core/core-error';\nimport { readPack } from '@leed-ai/git-gateway-core/pack/read-pack';\nimport { readLengthHeader } from '@leed-ai/git-gateway-core/pkt-line/length-header';\nimport { parseReceivePackRequest } from '@leed-ai/git-gateway-core/receive-pack/parse-request';\nimport {\n encodeErrPacket,\n encodeReportStatus,\n reportStatusFraming,\n} from '@leed-ai/git-gateway-core/receive-pack/report-status';\nimport type { ReceivePackCommand, ReceivePackRequest } from '@leed-ai/git-gateway-core/schemas/receive-pack';\nimport type { RefStatus } from '@leed-ai/git-gateway-core/schemas/report-status';\nimport { encodeRefAdvertisement } from '@leed-ai/git-gateway-core/smart-http/ref-advertisement';\n\nimport type { MemoryRepository } from './memory-repository.ts';\n\n/** The capabilities the in-memory receive-pack offers, as git's own receive-pack does. */\nexport const RECEIVE_PACK_CAPABILITIES: readonly string[] = [\n 'report-status',\n 'delete-refs',\n 'side-band-64k',\n 'quiet',\n 'atomic',\n 'ofs-delta',\n 'push-options',\n 'object-format=sha1',\n 'agent=git-gateway-testkit',\n];\n\n/** The receive-pack ref advertisement: every ref in name order (no HEAD, as git sends it). */\nexport function receivePackAdvertisement(repo: MemoryRepository): Uint8Array {\n return encodeRefAdvertisement({\n service: 'git-receive-pack',\n refs: [...repo.refs.keys()]\n .toSorted()\n .map((name) => ({ name, sha: repo.refs.get(name) ?? '', peeled: null })),\n capabilities: [...RECEIVE_PACK_CAPABILITIES],\n symrefs: {},\n });\n}\n\n/** Where the pack starts: after the shallow lines, the command list and the push options. */\nfunction packOffset(body: Uint8Array, request: ReceivePackRequest): number {\n let flushes = request.capabilities.includes('push-options') ? 2 : 1;\n let offset = 0;\n while (flushes > 0 && offset + 4 <= body.length) {\n const header = readLengthHeader(body.subarray(offset, offset + 4), offset);\n if (header.kind === 'special') {\n flushes -= 1;\n offset += 4;\n } else offset += 4 + header.payloadLength;\n }\n return offset;\n}\n\n/** Why a command cannot apply to the repository as it stands, or null when it can. */\nfunction refuse(repo: MemoryRepository, command: ReceivePackCommand): string | null {\n const current = repo.refs.get(command.ref) ?? ZERO_SHA;\n if (command.oldSha === ZERO_SHA && command.newSha === ZERO_SHA) return 'nothing to do';\n if (current !== command.oldSha) {\n return `cannot lock ref '${command.ref}': is at ${current} but expected ${command.oldSha}`;\n }\n if (command.newSha === ZERO_SHA) return null;\n const target = repo.object(command.newSha);\n if (target === null) return 'missing necessary objects';\n if (command.ref.startsWith('refs/heads/') && target.type !== 'commit')\n return 'branch must point at a commit';\n if (repo.missingFrom([command.newSha]).length > 0) return 'missing necessary objects';\n return null;\n}\n\n/** Unpacks the pack, if any, into the repository; returns the unpack status line. */\nasync function unpack(\n repo: MemoryRepository,\n body: Uint8Array,\n offset: number,\n needsPack: boolean,\n): Promise<string> {\n const pack = body.subarray(offset);\n if (pack.length === 0) return needsPack ? 'unpack-objects abnormal exit' : 'ok';\n try {\n repo.put(await readPack(pack, { lookupBase: async (sha) => repo.object(sha) }));\n return 'ok';\n } catch (error) {\n return isCoreError(error) ? error.message.replaceAll('\\n', ' ') : 'unpack-objects abnormal exit';\n }\n}\n\n/**\n * Applies one receive-pack request (protocol v0/v1) to an in-memory repository, the way git's\n * receive-pack does on a bare repository: unpack the pack, then update each ref only if it still\n * names the command's old id (a stale old id is refused with \"cannot lock ref\"). Non-fast-forward\n * updates with a matching old id are accepted, as git accepts them unless\n * receive.denyNonFastForwards is set. \"atomic\" applies all commands or none. Ref checks and\n * updates run without an await between them, so concurrent pushes to one ref cannot both win.\n */\nexport async function answerReceivePack(repo: MemoryRepository, body: Uint8Array): Promise<Uint8Array> {\n let request: ReceivePackRequest;\n try {\n request = (await parseReceivePackRequest(streamOf(body))).request;\n } catch (error) {\n return encodeErrPacket(error instanceof Error ? error.message : 'malformed request');\n }\n const framing = reportStatusFraming(\n request.capabilities.filter((capability) => RECEIVE_PACK_CAPABILITIES.includes(capability)),\n );\n const needsPack = request.commands.some((command) => command.newSha !== ZERO_SHA);\n const unpackStatus = await unpack(repo, body, packOffset(body, request), needsPack);\n let refs: RefStatus[];\n if (unpackStatus !== 'ok') {\n refs = request.commands.map((command) => ({ ref: command.ref, status: 'ng', reason: 'unpacker error' }));\n } else {\n refs = applyCommands(repo, request.commands, request.capabilities.includes('atomic'));\n }\n if (!request.capabilities.includes('report-status')) return new Uint8Array(0);\n return encodeReportStatus({ unpack: unpackStatus, refs }, framing);\n}\n\nfunction applyCommands(\n repo: MemoryRepository,\n commands: readonly ReceivePackCommand[],\n atomic: boolean,\n): RefStatus[] {\n const reasons = commands.map((command) => refuse(repo, command));\n if (atomic && reasons.some((reason) => reason !== null)) {\n return commands.map((command, index) => ({\n ref: command.ref,\n status: 'ng',\n reason: reasons[index] ?? 'atomic transaction failed',\n }));\n }\n return commands.map((command, index) => {\n const reason = reasons[index];\n if (reason !== null && reason !== undefined) return { ref: command.ref, status: 'ng', reason };\n if (command.newSha === ZERO_SHA) repo.refs.delete(command.ref);\n else repo.refs.set(command.ref, command.newSha);\n return { ref: command.ref, status: 'ok' };\n });\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MemoryRepository } from "./memory-repository.js";
|
|
2
|
+
import { MemoryTokens } from "./memory-tokens.js";
|
|
3
|
+
/** What the smart-HTTP server needs from the backend. */
|
|
4
|
+
export interface SmartHttpHost {
|
|
5
|
+
readonly tokens: MemoryTokens;
|
|
6
|
+
repository(name: string): MemoryRepository | undefined;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Serves git smart HTTP (protocol v0/v1) for the in-memory repositories: GET
|
|
10
|
+
* /<repo>.git/info/refs?service=…, POST /<repo>.git/git-upload-pack and
|
|
11
|
+
* /git-receive-pack. Every request needs a token minted by gitRemote() for that repository —
|
|
12
|
+
* as a Bearer header or the password of HTTP Basic — and a read token cannot push.
|
|
13
|
+
*/
|
|
14
|
+
export declare function serveSmartHttp(host: SmartHttpHost, request: Request): Promise<Response>;
|
|
15
|
+
//# sourceMappingURL=smart-http-server.d.ts.map
|