Versions 111 to 318
new file, 138 lines
1+import assert from "node:assert/strict"; 2+import { describe, it } from "node:test"; 3+import git from "isomorphic-git"; 4+import { absoVersion } from "../src/ingest.ts"; 5+import { MemoryFS } from "../src/memory-fs.ts"; 6+import { blobOid, commitShared, projectOfRepo, readTreeFiles, repoName } from "../src/push.ts"; 8+it("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"); 14+describe("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); 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); 30+describe("commitShared", () => { 31+ it("batches changed text and preserves pending old files in intermediate commits", async () => { 32+ const fs = new MemoryFS(), 34+ await git.init({ fs, dir, defaultBranch: "main" }); 35+ const first = await commitShared( 39+ { version: 0, files: { "a.txt": "old a", "b.txt": "old b", "gone.txt": "delete" } }, 42+ const parts: string[] = []; 43+ const body = "x".repeat(9 * 1024 * 1024); 44+ const next = await commitShared( 48+ { version: 1, files: { "a.txt": body, "b.txt": body + "b" } }, 53+ new TextDecoder().decode((await git.readBlob({ fs, dir, oid: commit, filepath: "b.txt" })).blob), 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" })); 60+ assert.equal(parts.length, 1); 61+ assert.deepEqual((await git.readCommit({ fs, dir, oid: next.commit })).commit.parent, parts); 63+ new TextDecoder().decode((await git.readBlob({ fs, dir, oid: next.commit, filepath: "b.txt" })).blob), 66+ assert.equal(absoVersion((await git.readCommit({ fs, dir, oid: parts[0]! })).commit.message), 1); 68+ it("reads one lazy file at a time and does not read symlink placeholder text", async (t) => { 69+ const fs = new MemoryFS(); 71+ await git.init({ fs, dir, defaultBranch: "main" }); 73+ const writeBlob = git.writeBlob; 74+ t.mock.method(git, "writeBlob", async (options: Parameters<typeof writeBlob>[0]) => { 75+ const result = await writeBlob(options); 81+ assert.equal(writes, 0); 85+ assert.equal(writes, 1); 89+ throw Error("symlink placeholder text must not be read"); 92+ await commitShared(fs, dir, null, { version: 0, files, modes: { link: { link: "a" } } }, () => null); 93+ assert.equal(writes, 3); 95+ it("writes shared as a commit with its modes, then only what changed", async () => { 96+ const fs = new MemoryFS(); 98+ await git.init({ fs, dir, defaultBranch: "main" }); 99+ const noBlobs = () => null; 100+ const first = await commitShared( 106+ files: { "a.txt": "one\n", "run.sh": "echo hi\n", link: "" }, 107+ modes: { "run.sh": { exec: true }, link: { link: "a.txt" } }, 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])), { 120+ const second = await commitShared( 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" }, 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);