Make Table Formulas a built-in feature

The formula engine, the rendered results, and the formula help now
come from src/lib/formulas/. The editor and the renderer call this
module directly. The tableFormulas contribution type is removed.

- Add the tableFormulas general setting (default on) and a switch in
  Settings > General. When it is off, formulas show as source text.
- Do not load an installed runestone.table-formulas package. Settings
  > Plug-ins marks it as included with RuneStone and tells the user
  that it can be removed. The user's files stay in place.
- Translate the formula help and the error descriptions into French,
  Japanese, and Simplified Chinese.
- Port the plugin unit tests. Test the setting and use a test-only
  contribution for the generic plugin lifecycle tests.
- Smoke tests load only Terminal. The formula and lifecycle tests use
  the built-in feature and its setting.
- Remove scripts/buildPlugins.mjs, the build:plugins script, and the
  plugin-packages requirement of the smoke runner.
- Remove RuneStone_Table_Formulas from the menu audit scope. It had no
  menu surfaces.
- Update the README, the user guides, and the developer references.
This commit is contained in:
Knotty Wyvern
2026-10-28 01:05:43 -07:00
parent 72671e5d01
commit 5e1533c371
43 changed files with 580 additions and 198 deletions
+26 -28
View File
@@ -2,14 +2,12 @@ import test from "node:test";
import assert from "node:assert/strict";
import { ContributionRegistry, pluginHost } from "../../../src/lib/plugins/registry.ts";
import { ExternalSession } from "../../../src/lib/plugins/externalSession.ts";
import { existsSync } from "node:fs";
// The Table Formulas package comes from a sibling repository. Run `pnpm build:plugins` to build it.
const tableFormulasEntry = new URL("../../../plugin-packages/table-formulas/main.js", import.meta.url);
const tableFormulas = existsSync(tableFormulasEntry) ? await import(tableFormulasEntry.href) : undefined;
const activate = tableFormulas?.activate;
const needsTableFormulas = { skip: tableFormulas ? false : "the Table Formulas package is not built; run pnpm build:plugins" };
import { renderMarkdownHtml, renderMarkdownSections } from "../../../src/lib/workspace/noteHtml.ts";
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 services = {
workspace: { list: async () => [], read: async () => "", write: async () => {} },
@@ -38,45 +36,45 @@ test("optional workspace creation and reads stop when the plugin is disabled", a
assert.throws(() => api.workspace.readOptional!("board.json"), /disabled/);
assert.equal(files.size, 1);
});
test("core starts without optional features and formula packages preserve source when stopped", needsTableFormulas, async () => {
test("core starts without optional features and package contributions end with their session", async () => {
assert.equal(pluginHost.get("terminal"), undefined);
assert.equal(pluginHost.get("tableFormulas"), undefined);
const source = "| A | B |\n| --- | --- |\n| 2 | =A2*3 |\n";
assert.doesNotMatch(renderMarkdownHtml(source, new Map()), /md-table-formula/);
const session = new ExternalSession("runestone.table-formulas", services, () => {}, () => {});
assert.equal(pluginHost.get("git"), undefined);
const registry = new ContributionRegistry();
const session = new ExternalSession("org.test.feature", services, () => {}, () => {}, registry);
await session.start({ activate });
const enabled = renderMarkdownHtml(source, new Map());
assert.match(enabled, />6<\/span>/);
assert.equal(registry.get("git"), blame);
await session.stop();
for (const html of [renderMarkdownHtml(source, new Map()), ...renderMarkdownSections(source, new Map()).map(section => section.html)]) {
assert.doesNotMatch(html, /md-table-formula/);
assert.match(html, /=A2\*3/);
assert.match(html, /<table>/);
}
const next = new ExternalSession("runestone.table-formulas", services, () => {}, () => {});
assert.equal(registry.get("git"), undefined);
const next = new ExternalSession("org.test.feature", services, () => {}, () => {}, registry);
await next.start({ activate });
assert.equal(renderMarkdownHtml(source, new Map()), enabled);
assert.equal(registry.get("git"), blame);
await next.stop();
assert.equal(registry.get("git"), undefined);
});
test("package contribution conflicts preserve the first owner and revoke access before cleanup", needsTableFormulas, async () => {
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/);
});
test("package contribution conflicts preserve the first owner and revoke access before cleanup", async () => {
const registry = new ContributionRegistry();
const first = new ExternalSession("first", services, () => {}, () => {}, registry);
const second = new ExternalSession("second", services, () => {}, () => {}, registry);
let api!: PluginApi;
await first.start({ activate(value) { api = value; activate(api); } });
const contribution = registry.get("tableFormulas");
const contribution = registry.get("git");
await assert.rejects(second.start({ activate }), /already registered/);
await second.stop();
assert.equal(registry.get("tableFormulas"), contribution);
assert.equal(registry.get("git"), contribution);
api.onDispose(() => {
assert.equal(registry.get("tableFormulas"), undefined);
assert.throws(() => api.contribute("tableFormulas", contribution!), /disabled/);
assert.equal(registry.get("git"), undefined);
assert.throws(() => api.contribute("git", contribution!), /disabled/);
});
await first.stop();
});
test("partial activation and failed cleanup cannot retain feature contributions", needsTableFormulas, async () => {
test("partial activation and failed cleanup cannot retain feature contributions", async () => {
const registry = new ContributionRegistry();
const session = new ExternalSession("failed", services, () => {}, () => {}, registry);
await assert.rejects(session.start({ activate(api) {
@@ -85,5 +83,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("tableFormulas"), undefined);
assert.equal(registry.get("git"), undefined);
});