RuneStone 1.0.0

This commit is contained in:
Knotty Wyvern
2026-11-03 00:23:07 -07:00
commit 5557443ed1
818 changed files with 239368 additions and 0 deletions
+67
View File
@@ -0,0 +1,67 @@
// The Git feature model. These tests come from the Git plugin (`RuneStone_Git/test/model.test.mjs`).
import { test } from "node:test";
import assert from "node:assert/strict";
import { changeLabel, diffLineKind, graphLayout, groups, isConflict, pathsFor } from "../../../src/lib/features/git/model.ts";
import type { GitChange, GitGraphCommit } from "../../../src/lib/git/contracts.ts";
const commit = (id: string, parents: string[]): GitGraphCommit => ({ id, parents, refs: [], summary: id, author: "Test", date: "2026-10-29" });
test("partially staged files occur in both groups, with conflicts only in working files", () => {
const changes: GitChange[] = [
{ path: "both.txt", index: "M", worktree: "M" },
{ path: "new.txt", index: "?", worktree: "?" },
{ path: "conflict.txt", index: "U", worktree: "U" },
{ path: "deleted.txt", index: "D", worktree: " " },
];
assert.deepEqual(groups(changes).staged.map(change => change.path), ["both.txt", "deleted.txt"]);
assert.deepEqual(groups(changes).working.map(change => change.path), ["both.txt", "new.txt", "conflict.txt"]);
assert.equal(isConflict({ path: "a", index: "A", worktree: "A" }), true);
assert.equal(changeLabel(changes[2], false), "Conflict");
assert.equal(changeLabel(changes[1], false), "New");
assert.equal(changeLabel(changes[3], true), "Deleted");
assert.equal(changeLabel({ path: "x", index: "X", worktree: " " }, true), "X");
});
test("rename actions include old and new paths exactly once", () => {
assert.deepEqual(pathsFor([{ path: "new.txt", originalPath: "old.txt", index: "R", worktree: " " }, { path: "old.txt", index: "M", worktree: " " }]), ["old.txt", "new.txt"]);
});
test("diff lines get their kind from the first character", () => {
assert.deepEqual(["+add", "-remove", "+++ b/file", "--- a/file", "@@ -1 +1 @@", " same", ""].map(diffLineKind),
["add", "remove", "context", "context", "range", "context", "context"]);
});
test("graph lanes preserve merge parents, forks, and truncated history", () => {
const layout = graphLayout({ commits: [commit("merge", ["main", "feature"]), commit("feature", ["root"]), commit("main", ["root"]), commit("root", ["older"])] });
assert.deepEqual(layout.nodes.map(node => node.lane), [0, 1, 0, 1]);
assert.equal(layout.edges.length, 5);
assert.deepEqual(layout.edges.filter(edge => edge.from === "merge").map(edge => [edge.to, edge.endRow]), [["main", 2], ["feature", 1]]);
assert.equal(layout.edges.at(-1)!.outside, true);
assert.equal(layout.edges.at(-1)!.endRow, 4);
assert.deepEqual(graphLayout({ commits: [] }).nodes, []);
assert.deepEqual(graphLayout(null).nodes, []);
});
test("graph track colors survive lane changes, joins, and history boundaries", () => {
const history = { commits: [commit("merge", ["main", "feature"]), commit("feature", ["feature-old"]), commit("main", ["root"]), commit("feature-old", ["root"]), commit("root", ["older"])] };
const layout = graphLayout(history);
const node = (id: string) => layout.nodes.find(item => item.id === id)!;
const edge = (from: string, to: string) => layout.edges.find(item => item.from === from && item.to === to)!;
assert.notEqual(node("main").color, node("feature").color);
assert.equal(node("merge").color, node("main").color);
assert.equal(node("feature").color, node("feature-old").color);
assert.equal(edge("merge", "feature").color, node("feature").color);
assert.equal(edge("feature-old", "root").color, node("feature-old").color);
assert.equal(edge("root", "older").color, node("root").color);
assert.deepEqual(graphLayout(history), layout);
const shifted = graphLayout({ commits: [commit("merge", ["main", "feature"]), commit("main", []), commit("feature", ["feature-old"]), commit("feature-old", [])] });
assert.notEqual(shifted.nodes[2].lane, shifted.nodes[3].lane);
assert.equal(shifted.nodes[2].color, shifted.nodes[3].color);
});
test("six concurrent graph tracks use six colors before palette reuse", () => {
const parents = ["a", "b", "c", "d", "e", "f"];
const layout = graphLayout({ commits: [commit("merge", parents), ...parents.map(id => commit(id, []))] });
assert.equal(new Set(layout.nodes.slice(1).map(node => node.color)).size, 6);
assert.equal(new Set(layout.edges.map(edge => edge.color)).size, 6);
});