Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/server/test/git-export-http.test.ts?format=json
128 linescodex-capacity-chair 100%Last change codex-capacity-chair in version 180, 1 version changed it
1import assert from "node:assert/strict";
2import { execFileSync, spawn } from "node:child_process";
3import { randomBytes } from "node:crypto";
4import { mkdtempSync, rmSync } from "node:fs";
5import { createServer } from "node:http";
6import { tmpdir } from "node:os";
7import { join } from "node:path";
8import { test } from "node:test";
9import { pushShared } from "../src/push.ts";
10import { memoryStorage } from "./helpers.ts";
12test("disk export streams to real Git receive-pack and preserves remote ancestry", async (t) => {
13 const root = mkdtempSync(join(tmpdir(), "abso-export-"));
14 t.after(() => rmSync(root, { recursive: true, force: true }));
15 const repo = join(root, "fixture.git");
16 const command = (...args: string[]) => execFileSync("git", args);
17 command("init", "--bare", "--initial-branch=main", repo);
18 command("--git-dir", repo, "config", "http.receivepack", "true");
19 let uploads = 0;
20 let rejectClone = false;
21 const server = createServer((request, response) => {
22 const url = new URL(request.url!, "http://fixture.invalid");
23 if (rejectClone && url.pathname.endsWith("git-upload-pack")) {
24 response.writeHead(503).end("injected upload-pack failure");
25 return;
26 }
27 if (url.pathname.endsWith("git-receive-pack")) uploads++;
28 const child = spawn("git", ["http-backend"], {
29 env: {
30 ...process.env,
31 GIT_PROJECT_ROOT: root,
32 GIT_HTTP_EXPORT_ALL: "1",
33 PATH_INFO: url.pathname,
34 QUERY_STRING: url.search.slice(1),
35 REQUEST_METHOD: request.method!,
36 CONTENT_TYPE: request.headers["content-type"] ?? "",
37 REMOTE_USER: "fixture",
38 SERVER_PROTOCOL: "HTTP/1.1",
39 },
40 });
41 request.pipe(child.stdin);
42 let headers = Buffer.alloc(0),
43 started = false;
44 child.stdout.on("data", (chunk: Buffer) => {
45 if (started) {
46 response.write(chunk);
47 return;
48 }
49 headers = Buffer.concat([headers, chunk]);
50 const boundary = headers.indexOf("\r\n\r\n");
51 if (boundary < 0) return;
52 for (const line of headers.subarray(0, boundary).toString().split("\r\n")) {
53 const colon = line.indexOf(":");
54 const key = line.slice(0, colon),
55 value = line.slice(colon + 1).trim();
56 if (key.toLowerCase() === "status") response.statusCode = Number(value.split(" ")[0]);
57 else response.setHeader(key, value);
58 }
59 started = true;
60 response.write(headers.subarray(boundary + 4));
61 headers = Buffer.alloc(0);
62 });
63 child.stdout.on("end", () => response.end());
64 child.on("error", (error) => response.destroy(error));
65 child.stderr.resume();
66 });
67 await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
68 t.after(() => {
69 server.closeAllConnections();
70 return new Promise<void>((resolve) => server.close(() => resolve()));
71 });
72 const address = server.address() as { port: number };
73 const remote = `http://127.0.0.1:${address.port}/fixture.git`;
74 const artifacts = {
75 get: async () => ({
76 info: async () => ({ remote }),
77 createToken: async () => ({ plaintext: "synthetic-token" }),
78 [Symbol.dispose]() {},
79 }),
80 };
81 const storage = memoryStorage();
82 t.after(() => storage.db.close());
83 const disk = { storage, maxPackBytes: 8000000, maxObjectBytes: 4000000, maxDecodedBytes: 16000000 };
84 const binary = randomBytes(1500000);
85 const first = await pushShared(
86 artifacts as never,
87 "fixture",
88 {
89 version: 1,
90 files: { "a.txt": "first\n" },
91 blobs: { "large.bin": "binary" },
92 },
93 () => binary,
94 disk,
95 );
96 const second = await pushShared(
97 artifacts as never,
98 "fixture",
99 {
100 version: 2,
101 files: { "a.txt": "second\n", "new.txt": "new\n" },
102 blobs: { "large.bin": "binary" },
103 },
104 () => binary,
105 disk,
106 );
107 assert.equal(command("--git-dir", repo, "rev-parse", "main^").toString().trim(), first.commit);
108 assert.equal(command("--git-dir", repo, "rev-parse", "main").toString().trim(), second.commit);
109 assert.equal(command("--git-dir", repo, "show", "main:a.txt").toString(), "second\n");
110 assert.deepEqual(execFileSync("git", ["--git-dir", repo, "show", "main:large.bin"], { maxBuffer: 4000000 }), binary);
111 assert.equal(uploads, 2);
112 rejectClone = true;
113 await assert.rejects(() =>
114 pushShared(artifacts as never, "fixture", { version: 3, files: { "bad.txt": "must not push" } }, undefined, disk),
115 );
116 assert.equal(uploads, 2, "failed clone must never become an empty-repository push");
117 for (const table of [
118 "git_fs_chunks",
119 "git_fs_meta",
120 "git_fs_budget",
121 "git_pack_spool",
122 "git_pack_resolve",
123 "git_object_bytes",
124 "git_object_meta",
125 "git_object_budget",
126 ])
127 assert.equal(storage.db.prepare(`SELECT COUNT(*) AS n FROM ${table}`).get()!.n, 0, table);
128});