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
+12 -13
View File
@@ -6,8 +6,8 @@ import type { PluginApi } from "../../../src/lib/plugins/sdk.ts";
import type { Contributions } from "../../../src/lib/plugins/contracts.ts";
// A small test-only package. It contributes a feature, as the optional plugins do.
const blame: Contributions["git"] = { blame: async () => null };
const activate = (api: PluginApi) => { api.contribute("git", blame); };
const terminal: Contributions["terminal"] = { mount: () => ({ update() {}, command() {}, dispose() {} }), shortcut: () => null };
const activate = (api: PluginApi) => { api.contribute("terminal", terminal); };
const services = {
workspace: { list: async () => [], read: async () => "", write: async () => {} },
@@ -38,23 +38,22 @@ test("optional workspace creation and reads stop when the plugin is disabled", a
});
test("core starts without optional features and package contributions end with their session", async () => {
assert.equal(pluginHost.get("terminal"), undefined);
assert.equal(pluginHost.get("git"), undefined);
const registry = new ContributionRegistry();
const session = new ExternalSession("org.test.feature", services, () => {}, () => {}, registry);
await session.start({ activate });
assert.equal(registry.get("git"), blame);
assert.equal(registry.get("terminal"), terminal);
await session.stop();
assert.equal(registry.get("git"), undefined);
assert.equal(registry.get("terminal"), undefined);
const next = new ExternalSession("org.test.feature", services, () => {}, () => {}, registry);
await next.start({ activate });
assert.equal(registry.get("git"), blame);
assert.equal(registry.get("terminal"), terminal);
await next.stop();
assert.equal(registry.get("git"), undefined);
assert.equal(registry.get("terminal"), undefined);
});
test("unknown contribution keys are rejected", () => {
const registry = new ContributionRegistry();
assert.throws(() => registry.register("old", "tableFormulas" as keyof Contributions, blame as never), /Unknown plugin contribution/);
for (const key of ["tableFormulas", "git"]) assert.throws(() => registry.register("old", key as keyof Contributions, terminal as never), /Unknown plugin contribution/);
});
test("package contribution conflicts preserve the first owner and revoke access before cleanup", async () => {
@@ -63,13 +62,13 @@ test("package contribution conflicts preserve the first owner and revoke access
const second = new ExternalSession("second", services, () => {}, () => {}, registry);
let api!: PluginApi;
await first.start({ activate(value) { api = value; activate(api); } });
const contribution = registry.get("git");
const contribution = registry.get("terminal");
await assert.rejects(second.start({ activate }), /already registered/);
await second.stop();
assert.equal(registry.get("git"), contribution);
assert.equal(registry.get("terminal"), contribution);
api.onDispose(() => {
assert.equal(registry.get("git"), undefined);
assert.throws(() => api.contribute("git", contribution!), /disabled/);
assert.equal(registry.get("terminal"), undefined);
assert.throws(() => api.contribute("terminal", contribution!), /disabled/);
});
await first.stop();
});
@@ -83,5 +82,5 @@ test("partial activation and failed cleanup cannot retain feature contributions"
throw new Error("Activation failed");
} }), /Activation failed/);
await assert.rejects(session.stop(), /Cleanup failed/);
assert.equal(registry.get("git"), undefined);
assert.equal(registry.get("terminal"), undefined);
});