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:
@@ -4,37 +4,21 @@ import { ExternalSession } from "../../../src/lib/plugins/externalSession.ts";
|
||||
import { ContributionRegistry } from "../../../src/lib/plugins/registry.ts";
|
||||
import type { PluginApi } from "../../../src/lib/plugins/sdk.ts";
|
||||
|
||||
test("Git and file access stop before plugin cleanup", async () => {
|
||||
test("file access stops before plugin cleanup, and plugins get no Git API", async () => {
|
||||
const calls: unknown[] = [];
|
||||
let api!: PluginApi;
|
||||
const registry = new ContributionRegistry();
|
||||
const session = new ExternalSession("test.git", {
|
||||
const session = new ExternalSession("test.files", {
|
||||
workspace: { list: async () => [], read: async () => "", write: async () => {} },
|
||||
settings: { read: async () => null, write: async () => {} }, assets: { read: async () => new Uint8Array() },
|
||||
openFile: async path => { calls.push(path); },
|
||||
git: {
|
||||
status: async () => ({ available: true, repository: true, branch: "main", changes: [] }),
|
||||
diff: async (path, staged) => { calls.push([path, staged]); return "diff"; },
|
||||
stage: async paths => { calls.push(paths); }, unstage: async paths => { calls.push(paths); },
|
||||
commit: async message => { calls.push(message); }, blame: async () => null,
|
||||
push: async () => { calls.push('push'); }, pull: async () => { calls.push('pull'); }, graph: async () => ({ commits: [] }),
|
||||
commitDetails: async () => { throw new Error("not used"); }, commitDiff: async () => "",
|
||||
},
|
||||
}, () => {}, () => {}, registry);
|
||||
await session.start({ activate(value) { api = value; api.contribute("git", { blame: (path, line) => api.git!.blame(path, line) }); } });
|
||||
}, () => {}, () => {}, new ContributionRegistry());
|
||||
await session.start({ activate(value) { api = value; } });
|
||||
// Git is a native feature of RuneStone. The plugin API has no Git member.
|
||||
assert.equal("git" in api, false);
|
||||
await api.openFile!("notes.md");
|
||||
assert.equal(await api.git!.diff("notes.md", true), "diff");
|
||||
await api.git!.stage(["notes.md"]);
|
||||
assert.deepEqual(calls, ["notes.md", ["notes.md", true], ["notes.md"]]);
|
||||
await api.git!.push();
|
||||
await api.git!.pull();
|
||||
assert.deepEqual(await api.git!.graph(), { commits: [] });
|
||||
assert.deepEqual(calls.slice(-2), ['push', 'pull']);
|
||||
assert.deepEqual(calls, ["notes.md"]);
|
||||
await session.stop();
|
||||
assert.equal(registry.get("git"), undefined);
|
||||
assert.throws(() => api.openFile!("notes.md"), /disabled/);
|
||||
for (const action of [() => api.git!.push(), () => api.git!.pull(), () => api.git!.graph()]) assert.throws(action, /disabled/);
|
||||
for (const action of [() => api.git!.status(), () => api.git!.diff("a", false), () => api.git!.stage(["a"]), () => api.git!.unstage(["a"]), () => api.git!.commit("a"), () => api.git!.blame("a", 1)]) assert.throws(action, /disabled/);
|
||||
});
|
||||
|
||||
test("view replacement rejects unknown destinations and stops after disposal", async () => {
|
||||
|
||||
Reference in New Issue
Block a user