- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/server/test/push.test.ts?format=json
138 linescodex-capacity-chair 51% · speed 49%Last change codex-capacity-chair in version 181, 4 versions changed it
1import assert from "node:assert/strict";
2import { describe, it } from "node:test";
3import git from "isomorphic-git";
4import { absoVersion } from "../src/ingest.ts";
5import { MemoryFS } from "../src/memory-fs.ts";
6import { blobOid, commitShared, projectOfRepo, readTreeFiles, repoName } from "../src/push.ts";
8it("hashes exact Git blob bytes including a nonzero buffer offset", async () => {
9 assert.equal(await blobOid(new Uint8Array()), "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391");
10 const bytes = new TextEncoder().encode("prefixhello\nsuffix");
11 assert.equal(await blobOid(bytes.subarray(6, 12)), "ce013625030ba8dba906f756967f9e9ca394464a");
12});
14describe("repo names", () => {
15 it("names a project's Artifacts repo abso-<project>, and back", () => {
16 assert.equal(repoName("game"), "abso-game");
17 assert.equal(repoName("my.site_2"), "abso-my.site_2");
18 assert.equal(projectOfRepo("abso-game"), "game");
19 assert.equal(projectOfRepo("avcs-game"), null);
20 assert.equal(projectOfRepo("abso-"), null);
21 });
23 it("reads the version a pushed commit carries, under either name", () => {
24 assert.equal(absoVersion("Fix it\n\nabso-version: 12\n"), 12);
25 assert.equal(absoVersion("Fix it\n\navcs-version: 7\n"), 7);
26 assert.equal(absoVersion("a person's own commit"), undefined);
27 });
28});
30describe("commitShared", () => {
31 it("batches changed text and preserves pending old files in intermediate commits", async () => {
32 const fs = new MemoryFS(),
33 dir = "/repo";
34 await git.init({ fs, dir, defaultBranch: "main" });
35 const first = await commitShared(
36 fs,
37 dir,
38 null,
39 { version: 0, files: { "a.txt": "old a", "b.txt": "old b", "gone.txt": "delete" } },
40 () => null,
41 );
42 const parts: string[] = [];
43 const body = "x".repeat(9 * 1024 * 1024);
44 const next = await commitShared(
45 fs,
46 dir,
47 first.commit,
48 { version: 1, files: { "a.txt": body, "b.txt": body + "b" } },
49 () => null,
50 async (commit) => {
51 parts.push(commit);
52 assert.equal(
53 new TextDecoder().decode((await git.readBlob({ fs, dir, oid: commit, filepath: "b.txt" })).blob),
54 "old b",
55 );
56 assert.equal((await git.readBlob({ fs, dir, oid: commit, filepath: "a.txt" })).blob.length, body.length);
57 await assert.rejects(() => git.readBlob({ fs, dir, oid: commit, filepath: "gone.txt" }));
58 },
59 );
60 assert.equal(parts.length, 1);
61 assert.deepEqual((await git.readCommit({ fs, dir, oid: next.commit })).commit.parent, parts);
62 assert.equal(
63 new TextDecoder().decode((await git.readBlob({ fs, dir, oid: next.commit, filepath: "b.txt" })).blob),
64 body + "b",
65 );
66 assert.equal(absoVersion((await git.readCommit({ fs, dir, oid: parts[0]! })).commit.message), 1);
67 });
68 it("reads one lazy file at a time and does not read symlink placeholder text", async (t) => {
69 const fs = new MemoryFS();
70 const dir = "/repo";
71 await git.init({ fs, dir, defaultBranch: "main" });
72 let writes = 0;
73 const writeBlob = git.writeBlob;
74 t.mock.method(git, "writeBlob", async (options: Parameters<typeof writeBlob>[0]) => {
75 const result = await writeBlob(options);
76 writes++;
77 return result;
78 });
79 const files = {
80 get a() {
81 assert.equal(writes, 0);
82 return "first";
83 },
84 get b() {
85 assert.equal(writes, 1);
86 return "second";
87 },
88 get link(): string {
89 throw Error("symlink placeholder text must not be read");
90 },
91 };
92 await commitShared(fs, dir, null, { version: 0, files, modes: { link: { link: "a" } } }, () => null);
93 assert.equal(writes, 3);
94 });
95 it("writes shared as a commit with its modes, then only what changed", async () => {
96 const fs = new MemoryFS();
97 const dir = "/repo";
98 await git.init({ fs, dir, defaultBranch: "main" });
99 const noBlobs = () => null;
100 const first = await commitShared(
101 fs,
102 dir,
103 null,
104 {
105 version: 0,
106 files: { "a.txt": "one\n", "run.sh": "echo hi\n", link: "" },
107 modes: { "run.sh": { exec: true }, link: { link: "a.txt" } },
108 },
109 noBlobs,
110 );
111 assert.equal(first.changed, 3);
112 const commit = (await git.readCommit({ fs, dir, oid: first.commit })).commit;
113 assert.match(commit.message, /^Start the project\n\nabso-version: 0\n$/);
114 const { files } = await readTreeFiles(fs, dir, commit.tree);
115 assert.deepEqual(Object.fromEntries([...files].map(([p, f]) => [p, f.mode])), {
116 "a.txt": "100644",
117 link: "120000",
118 "run.sh": "100755",
119 });
120 const second = await commitShared(
121 fs,
122 dir,
123 first.commit,
124 {
125 version: 1,
126 files: { "a.txt": "one\ntwo\n", "run.sh": "echo hi\n", link: "" },
127 modes: { "run.sh": { exec: true }, link: { link: "a.txt" } },
128 last: { agent: "alice", message: "Add two" },
129 },
130 noBlobs,
131 );
132 assert.equal(second.changed, 1);
133 const next = (await git.readCommit({ fs, dir, oid: second.commit })).commit;
134 assert.equal(next.author.name, "alice");
135 assert.deepEqual(next.parent, [first.commit]);
136 assert.equal(absoVersion(next.message), 1);
137 });
138});