Files
Termix/scripts/check-sdk-guide.test.ts
T
62ac931468 v26.10.1 (#1599)
* feat: AI translations at release, 7 new languages and regional fallback

* fix: proper plural forms for count strings and full translations

* fix: plural forms for selected, hidden and active counts

* fix: synced plugin updates failing on desktop and server-only plugins shown as stopped

* fix: restore rounded corners on app icons and favicon

* feat: desktop app auto updates with automatic, ask first or never modes

* feat: community and custom plugin registries

* feat: plugin guide for AI tools in the SDK with a lint check

* fix: keep the terminal WebSocket open past nginx's 60s default (#1588)

* chore: update changelog

* feat: show plugin download counts only and stop CI builds inflating them

* feat: hide installed plugins in the browse tab by default

* chore: pin bundled plugins to latest releases

* chore: update translations

* fix: focusing a saved password field and saving no longer erases it

* fix: tell desktop users when their 2.8 data needs 2.9 first

* fix: point windows update info at the x64 installer

* fix: keep desktop client tunnel sockets alive behind proxies

* chore: pin bundled plugins to latest releases

* fix: cover client tunnel keepalive in the c2s runtime tests

* fix: typing after opening a host no longer goes to the host search

* fix: accept tab and = separators in SSH config import (#1598)

* chore: update changelog

* chore: drop plugin versions from core changelog

* chore: update translations

* chore: lint, format, and bump version to 26.10.1

---------

Co-authored-by: Darnel Hunter <68697450+innotelinc@users.noreply.github.com>
Co-authored-by: Iain <Iain1970@protonmail.com>
2026-10-12 11:35:48 -05:00

114 lines
3.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
const { cliCommands, capabilityIds, entryPoints, apiVersion, findProblems } =
require("./check-sdk-guide.cjs") as {
cliCommands: (source: string) => string[];
capabilityIds: (source: string) => string[];
entryPoints: (pkg: { exports?: Record<string, unknown> }) => string[];
apiVersion: (source: string) => string | null;
findProblems: (input: {
guide: string;
commands: string[];
capabilities: string[];
entries: string[];
sdkVersion: string;
api: string | null;
}) => string[];
};
const GUIDE = [
"# Guide",
"",
"SDK 1.2.3 | Plugin API 1.4.0",
"",
"| `build` | builds |",
"| `sign <file>` | signs |",
"| `db:own` | tables |",
"| `@termix-ssh/plugin-sdk/db` | tables |",
].join("\n");
const input = {
guide: GUIDE,
commands: ["build", "sign"],
capabilities: ["db:own"],
entries: ["@termix-ssh/plugin-sdk/db"],
sdkVersion: "1.2.3",
api: "1.4.0",
};
describe("readers", () => {
it("reads command names from the COMMANDS map", () => {
const source = [
"const COMMANDS = {",
" build,",
" patch: async () => {},",
" test: async (options) => {",
" return run(options);",
" },",
" verify,",
"};",
].join("\n");
expect(cliCommands(source)).toEqual(["build", "patch", "test", "verify"]);
});
it("reads capability ids once each", () => {
const source =
'entry("db:own", "low"),\nentry("ssh:connect", "high"),\nentry("db:own", "low")';
expect(capabilityIds(source)).toEqual(["db:own", "ssh:connect"]);
});
it("skips the root and internal exports", () => {
expect(
entryPoints({
exports: {
".": {},
"./db": {},
"./testing/setup": {},
"./theme.css": "",
},
}),
).toEqual(["@termix-ssh/plugin-sdk/db"]);
});
it("reads the plugin API version", () => {
expect(apiVersion('export const PLUGIN_API_VERSION = "1.2.0";')).toBe(
"1.2.0",
);
});
});
describe("findProblems", () => {
it("passes a guide that covers everything", () => {
expect(findProblems(input)).toEqual([]);
});
it("names what is missing", () => {
expect(
findProblems({
...input,
commands: ["build", "dev"],
capabilities: ["db:own", "kv:own"],
entries: ["@termix-ssh/plugin-sdk/ui"],
}),
).toEqual([
'CLI command "dev" is not covered',
'capability "kv:own" is not covered',
'entry point "@termix-ssh/plugin-sdk/ui" is not covered',
]);
});
it("fails when the header is behind the SDK", () => {
expect(
findProblems({ ...input, sdkVersion: "1.2.4", api: "1.5.0" }),
).toEqual([
"header says SDK 1.2.3, package is 1.2.4",
"header says Plugin API 1.4.0, SDK has 1.5.0",
]);
expect(findProblems({ ...input, guide: "no header" })).toContain(
'missing the "SDK x.y.z | Plugin API x.y.z" header line',
);
});
});