Make Git a native feature with an off switch

- Add the native feature runtime in src/lib/features/: the catalog, the switches, the first-start migration, the loader, and the feature sessions.
- Add Settings → Features and the features settings section.
- Add features_legacy. It reads the old plugin packages and changes nothing.
- Move Git from the plugin into src/lib/features/git/, on host internals.
- Remove api.git, the git contribution key, and the SDK Git types.
- Add pnpm check:features. It fails when a feature module loads at start.
- Update the tests, the menu inventory, the docs, and UI-055.
This commit is contained in:
Knotty Wyvern
2026-10-29 15:51:21 -07:00
parent 58f77b2e9f
commit d3218b2501
68 changed files with 2068 additions and 324 deletions
+113
View File
@@ -0,0 +1,113 @@
// The native Git feature: the module loads only at first need, the Source control pane stages, unstages, and commits,
// the diff and graph tabs open, errors show in the pane, and Off removes the feature at once.
// It replaces plugins/gitToolbar, which loaded the old Git plugin from its sibling checkout.
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("features/git", async ({ page }) => {
const output = await outputDir("features/git");
await mockTauri(page, {
commands: test => {
// The handlers run in the page, so the history is defined here.
const commits = [
{ id: "c3".padEnd(40, "3"), parents: ["c1".padEnd(40, "1"), "c2".padEnd(40, "2")], refs: ["HEAD -> main"], summary: "Merge the feature", author: "Ada", date: "2026-10-29" },
{ id: "c2".padEnd(40, "2"), parents: ["c1".padEnd(40, "1")], refs: ["feature"], summary: "Add the feature", author: "Ada", date: "2026-10-28" },
{ id: "c1".padEnd(40, "1"), parents: [], refs: [], summary: "First commit", author: "Ada", date: "2026-10-27" },
];
test.git = { calls: [], changes: [
{ path: "staged.md", index: "M", worktree: " " },
{ path: "changed.md", index: " ", worktree: "M" },
{ path: "new.md", index: "?", worktree: "?" },
] };
const record = (command, value) => { test.git.calls.push([command, value]); return null; };
return {
...test.workspace({ root: "C:\\git-feature", files: { "staged.md": "A\n", "changed.md": "B\n", "new.md": "C\n" } }),
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
spelling_menu_install: () => null,
"plugin:window|is_maximized": () => false,
git_status: () => ({ available: true, repository: true, branch: "main", changes: test.git.changes }),
git_diff: ({ path, staged }) => `diff --git a/${path} b/${path}\n@@ -1 +1 @@\n-old line\n+new line${staged ? " (staged)" : ""}`,
git_stage: ({ paths }) => record("stage", paths),
git_unstage: ({ paths }) => record("unstage", paths),
git_commit: ({ message }) => record("commit", message),
git_push: () => { throw "The branch has no upstream branch."; },
git_pull: () => record("pull", null),
git_graph: () => ({ commits }),
git_commit_details: ({ commit }) => ({ id: commit, parents: commits.find(item => item.id === commit).parents, author: "Ada", date: "2026-10-29", message: "Details", files: [{ path: "one.md", status: "M" }, { path: "two.md", status: "A" }] }),
git_commit_diff: ({ path }) => `@@ -0,0 +1 @@\n+${path}`,
};
},
});
await page.goto(smokeUrl);
await page.locator('[data-tree-rel="staged.md"]').waitFor();
const loaded = () => page.evaluate(() => performance.getEntriesByType("resource").some(entry => new URL(entry.name).pathname === "/src/lib/features/git/index.ts"));
assert.equal(await loaded(), false, "The Git module does not load before first need");
const sourceControl = page.locator(".header-left").getByRole("button", { name: "Source control", exact: true });
await sourceControl.click();
const pane = page.locator(".source-control");
await pane.getByText("main", { exact: true }).waitFor();
assert.equal(await loaded(), true, "The Source control pane loads the Git module");
await pane.getByRole("heading", { name: "Staged changes (1)", exact: true }).waitFor();
await pane.getByRole("heading", { name: "Changes (2)", exact: true }).waitFor();
await pane.getByRole("button", { name: "Stage new.md", exact: true }).click();
await page.waitForFunction(() => window.__TEST__.git.calls.some(([command]) => command === "stage"));
assert.deepEqual(await page.evaluate(() => window.__TEST__.git.calls.at(-1)), ["stage", ["new.md"]]);
await pane.getByRole("button", { name: "Unstage all", exact: true }).click();
await page.waitForFunction(() => window.__TEST__.git.calls.some(([command]) => command === "unstage"));
assert.deepEqual(await page.evaluate(() => window.__TEST__.git.calls.at(-1)), ["unstage", ["staged.md"]]);
const message = pane.getByRole("textbox", { name: "Commit message", exact: true });
const commit = pane.getByRole("button", { name: "Commit staged", exact: true });
assert.equal(await commit.isDisabled(), true, "Commit waits for a message");
await message.fill("Write the notes");
await message.press("Control+Enter");
await pane.getByText("Commit created.", { exact: true }).waitFor();
assert.deepEqual(await page.evaluate(() => window.__TEST__.git.calls.at(-1)), ["commit", "Write the notes"]);
await pane.getByRole("button", { name: "Push to the upstream branch", exact: true }).click();
await pane.locator(".notice.error", { hasText: "no upstream branch" }).waitFor();
for (const theme of ["dark", "light"]) {
await page.evaluate(async mode => { const { saveAppearance } = await import("/src/lib/theme/appearance.ts"); saveAppearance({ theme: "default", mode }); }, theme);
await page.waitForTimeout(100);
await pane.screenshot({ path: path.join(output, `source-control-${theme}.png`) });
}
await pane.getByRole("button", { name: /^changed\.md — Modified$/ }).click();
const diff = page.locator(".git-diff");
await diff.getByText("changed.md · Working tree", { exact: true }).waitFor();
await diff.locator(".line.add", { hasText: "+new line" }).waitFor();
assert.equal(await diff.locator(".line.remove").count(), 1);
await page.screenshot({ path: path.join(output, "diff-tab.png") });
await pane.getByRole("button", { name: "Show Git graph", exact: true }).click();
const graph = page.locator(".git-graph");
const options = graph.getByRole("option");
await options.first().waitFor();
assert.equal(await options.count(), 3);
assert.equal(await options.first().getAttribute("aria-selected"), "true");
await graph.getByRole("button", { name: "one.md", exact: false }).first().waitFor();
await options.first().focus();
await page.keyboard.press("ArrowDown");
await page.waitForFunction(() => document.activeElement?.getAttribute("aria-selected") === "true" && document.activeElement?.textContent?.includes("Add the feature"));
await graph.locator(".line.add", { hasText: "+one.md" }).waitFor();
assert.equal(await graph.locator("path.boundary").count(), 0, "The full history has no dashed boundary line");
await page.screenshot({ path: path.join(output, "graph-tab.png") });
await page.setViewportSize({ width: 640, height: 720 });
await page.screenshot({ path: path.join(output, "graph-tab-640.png") });
await page.setViewportSize({ width: 1280, height: 800 });
// Off closes the Git tabs and the pane, and removes the button. The feature can start again.
await page.evaluate(() => window.__TEST__.writeSettings("features", { git: false }));
await sourceControl.waitFor({ state: "detached" });
await graph.waitFor({ state: "detached" });
await diff.waitFor({ state: "detached" });
await pane.waitFor({ state: "detached" });
await page.evaluate(() => window.__TEST__.writeSettings("features", { git: true }));
await sourceControl.click();
await pane.getByText("main", { exact: true }).waitFor();
console.log("PASS: Git loads at first need, stages, unstages, commits, shows errors, diffs, and the graph, and Off removes it");
}, { timeout: 60000 });
+65
View File
@@ -0,0 +1,65 @@
// Settings → Features: the switch of each native feature, the migration default, search, keyboard use, both themes, and narrow windows.
// A switch in the Settings window changes the main window at once.
import assert from "node:assert/strict";
import path from "node:path";
import { mockTauri, openPage, outputDir, runSmoke, smokeUrl } from "../_harness/index.mjs";
await runSmoke("features/settings", async ({ browser }) => {
const output = await outputDir("features/settings");
const context = await browser.newContext({ viewport: { width: 1152, height: 815 } });
await mockTauri(context, {
commands: test => ({
...test.workspace({ root: "C:\\features-settings", files: { "note.md": "# Note\n" } }),
plugins_snapshot: () => ({ root: "C:/plugins", plugins: [] }),
"plugin:window|is_maximized": () => false,
}),
});
const main = await openPage(context, { timeout: 10000 });
await main.goto(smokeUrl);
await main.locator('[data-tree-rel="note.md"]').waitFor();
const sourceControl = main.locator(".header-left").getByRole("button", { name: "Source control", exact: true });
await sourceControl.waitFor();
// Without an old package, the migration stores the default of each feature.
assert.deepEqual(await main.evaluate(() => window.__TEST__.settings("features")), { git: true });
const settings = await openPage(context, { timeout: 10000 });
await settings.goto(`${smokeUrl}/?settingsWindow=true`);
await settings.getByRole("heading", { name: "General", exact: true }).waitFor();
await settings.getByRole("button", { name: "Features", exact: true }).click();
await settings.getByRole("heading", { name: "Features", exact: true }).waitFor();
const git = settings.getByRole("switch", { name: "Git", exact: true });
assert.equal(await git.isChecked(), true);
assert.match(await git.getAttribute("aria-describedby"), /feature-git-description/);
await git.click();
await sourceControl.waitFor({ state: "detached" });
assert.deepEqual(await main.evaluate(() => window.__TEST__.settings("features")), { git: false });
assert.equal(await settings.getByRole("status").innerText(), "Changes saved.");
await git.focus();
await settings.keyboard.press("Space");
await sourceControl.waitFor();
assert.equal(await git.isChecked(), true);
// The settings search finds the page by the name and the words of a feature.
const search = settings.getByRole("textbox", { name: "Search settings", exact: true });
await search.fill("source control");
assert.deepEqual(await settings.locator('nav[aria-label="Settings categories"] button').allInnerTexts(), ["Features"]);
await search.fill("");
for (const theme of ["dark", "light"]) {
await settings.evaluate(value => { document.documentElement.dataset.theme = value; }, theme);
for (const width of [1152, 540, 360]) {
await settings.setViewportSize({ width, height: width === 1152 ? 815 : 520 });
assert(await settings.evaluate(() => document.documentElement.scrollWidth <= innerWidth), `No horizontal scroll at ${width} pixels`);
const row = settings.locator(".setting-row", { has: git });
const box = await row.boundingBox();
const toggle = await git.boundingBox();
assert(toggle.x + toggle.width <= box.x + box.width + 1, "The switch stays inside its row");
await settings.screenshot({ path: path.join(output, `features-${theme}-${width}.png`) });
}
}
await git.focus();
assert.equal(await git.evaluate(node => node.matches(":focus-visible")), true);
await settings.screenshot({ path: path.join(output, "features-focus.png") });
console.log("PASS: the Features page turns Git off and on in another window, with search, keyboard, both themes, and narrow widths");
}, { timeout: 60000 });