Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/maintainers.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

CI(`Validate index`)已经自动保证:

- 索引符合 Lithe 插件契约 v0 与本仓库策略(按 `id` 排序、无重复 ID、无 `dev.lithe.*`);
- 索引符合 Lithe 插件契约 v0 与本仓库策略(按 `id` 排序、无重复 ID、无 `dev.lithe.*`;每个条目的 Release 标签都是同一个前缀加上版本号,
同一个仓库的条目前缀互不相同,见[一个仓库发布多个插件](publishing.md#一个仓库发布多个插件));
- 每个新增或变更的下载包可下载、SHA-256 一致;
- 包内恰好一个匹配的 `plugin.json`,`schemaVersion` 与 `pluginAPIVersion` 为 `0`,
`version`、`pluginAPIVersion`、`requires` 与索引一致,
Expand Down
23 changes: 21 additions & 2 deletions docs/publishing.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ Release 资产名必须以平台结尾,自动追踪才能识别:
索引只接受 `https://github.com/<你的仓库>/releases/download/<tag>/<资产>.zip`,
不能指向其他仓库、源码压缩包或其他网站。

Release 标签必须是 `<前缀>MAJOR.MINOR.PATCH`,结尾的版本号与包内 `plugin.json` 的 `version` 相同:

- 前缀可以为空(标签就是 `2.0.0`),常用的是 `v`(`v2.0.0`)。
- 前缀不能以数字或 `.` 结尾,这样每个标签只有一种拆法。
- 同一个插件的所有版本使用同一个前缀。

Lithe 按这个前缀筛选插件的更新日志,自动追踪按它认领新版本。标签不符合约定的 Release 不会被收录。

### 一个仓库发布多个插件

一个仓库可以发布多个插件,每个插件使用自己的标签前缀,例如同一个仓库里的
`codex-v0.0.1` 和 `claude-code-v0.0.1`。同一个仓库的条目(仓库地址不区分大小写)不能使用相同的前缀,
否则校验失败。

- 第二个及以后的插件按下面的“其他仓库”步骤提 PR 首次收录:自动首次收录只看还没有条目的仓库。
- 收录后,自动追踪只认领带自己前缀的 Release,其他插件的 Release 直接忽略,不会下载,也不会报错。
- Lithe 的更新日志和“已安装”标记只显示这个插件自己的 Release。

> Release 发布后**不要替换或删除资产**。索引固定了 SHA-256,替换后用户会安装失败,
> 每周的校验也会把它标记为损坏。需要修复就发一个新的补丁版本。

Expand Down Expand Up @@ -164,7 +182,7 @@ pre-release 的仓库不会被收录。
收录后,新版本**不需要你再提 PR**:

1. 在你的仓库递增 `plugin.json` 的 `version`,打包,发布新的正式 Release(资产命名同上)。
2. `Track plugin releases` 工作流每 6 小时扫描一次已收录插件最近 20 个 Release
2. `Track plugin releases` 工作流每 6 小时扫描一次已收录插件最近 100 个 Release
(Lithe-IDEA 组织尚未收录的 `lithe-plugin-*` 仓库也一起扫描,见 [首次收录](#3-首次收录)),
把新版本写进索引(版本号、`pluginAPIVersion`、`requires` 取自包内 `plugin.json`,
能力表按键排序写入;发布日期取 Release 发布时间,SHA-256 由 CI 计算),
Expand All @@ -185,7 +203,8 @@ pre-release 的仓库不会被收录。
还没收录的 Lithe-IDEA 组织插件会在这时被自动首次收录。调试适配器插件的写法见
[编写调试适配器插件](https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/shared/plugins/guides/debug-adapter-plugin.md)。

自动追踪会在日志中说明归档无法收录的原因:没有符合命名的 zip、包内 `plugin.json`
自动追踪会在日志中说明归档无法收录的原因:标签不是 `<前缀>MAJOR.MINOR.PATCH`、
标签前缀与已收录版本不同、没有符合命名的 zip、包内 `plugin.json`
不匹配或缺失/畸形的能力表、多个资产声明了不同的版本号、插件 API 版本或能力表、
版本号已被别的资产占用。单个发布存在分歧时拒绝整个版本,不只保留其中一个平台包。

Expand Down
168 changes: 152 additions & 16 deletions scripts/store.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import { join } from "node:path";
import { test } from "node:test";
import { END, START, categoryOf, renderOverview, renderReadme, systemsOf, truncate } from "./render-readme.mjs";
import {
addVersion, discoverPlugins, isOrganizationEntry, platformsForAsset, trackIndex, trackingBranch, unlistedPluginRepositories,
versionFromRelease,
addVersion, discoverPlugins, isOrganizationEntry, platformsForAsset, trackEntry, trackIndex, trackingBranch,
unlistedPluginRepositories, versionFromRelease,
} from "./track-releases.mjs";
import {
checkManifest, formatIndex, inspectArchive, readPackageManifests, validateEntry, validateIndex, verifyArchives,
checkManifest, formatIndex, inspectArchive, readPackageManifests, releaseTagConvention, splitReleaseTag, validateEntry,
validateIndex, verifyArchives,
} from "./validate-index.mjs";
import { validateRecommendations } from "./validate-recommendations.mjs";

Expand All @@ -21,6 +22,17 @@ const fixtureIndex = JSON.parse(readFileSync(new URL("./fixtures/index.json", im
const invalidCases = JSON.parse(readFileSync(new URL("./fixtures/invalid-index-entries.json", import.meta.url))).cases;
const validEntry = () => structuredClone(fixtureIndex.plugins[0]);

// Another plugin of the fixture's repository, released under its own tag prefix.
function siblingEntry(id, prefix) {
const entry = { ...validEntry(), id };
for (const version of entry.versions) {
for (const download of version.downloads) {
download.downloadURL = download.downloadURL.replace(`/download/v${version.version}/`, `/download/${prefix}${version.version}/`);
}
}
return entry;
}

function applyEdits(entry, edits) {
for (const { op, path, value } of edits) {
const keys = path.split("/").slice(1);
Expand Down Expand Up @@ -264,7 +276,7 @@ function zigOrganization() {
[release.assets[0].browser_download_url, zigManifest(release.tag_name.slice(1))]));
const fixture = organizationFixture({
[REPOSITORIES_PATH]: [repository, organizationRepository("lithe-plugin-docs")],
"repos/Lithe-IDEA/lithe-plugin-zig/releases?per_page=20": releases,
"repos/Lithe-IDEA/lithe-plugin-zig/releases?per_page=100": releases,
}, manifestsByURL);
return { releases, fixture };
}
Expand All @@ -285,7 +297,7 @@ test("organization discovery considers only active, unlisted lithe-plugin- repos

test("organization discovery lists a new plugin with its stable releases", { timeout: 5_000 }, async () => {
const { releases, fixture } = zigOrganization();
const index = { schemaVersion: 0, plugins: [validEntry(), { ...validEntry(), id: "org.example.zig-tools" }] };
const index = { schemaVersion: 0, plugins: [validEntry(), siblingEntry("org.example.zig-tools", "tools-v")] };
const result = await discoverPlugins(index, fixture);

assert.deepEqual(result.skipped, []);
Expand Down Expand Up @@ -334,12 +346,12 @@ test("organization discovery skips repositories that cannot be listed yet", { ti
const officialRelease = organizationRelease(official, "1.0.0");
const fixture = organizationFixture({
[REPOSITORIES_PATH]: [preview, unlicensed, undescribed, copy, anonymous, official],
"repos/Lithe-IDEA/lithe-plugin-preview/releases?per_page=20": [organizationRelease(preview, "0.1.0", { prerelease: true })],
"repos/Lithe-IDEA/lithe-plugin-unlicensed/releases?per_page=20": [organizationRelease(unlicensed, "1.0.0")],
"repos/Lithe-IDEA/lithe-plugin-undescribed/releases?per_page=20": [organizationRelease(undescribed, "1.0.0")],
"repos/Lithe-IDEA/lithe-plugin-copy/releases?per_page=20": [copyRelease],
"repos/Lithe-IDEA/lithe-plugin-anonymous/releases?per_page=20": [anonymousRelease],
"repos/Lithe-IDEA/lithe-plugin-official/releases?per_page=20": [officialRelease],
"repos/Lithe-IDEA/lithe-plugin-preview/releases?per_page=100": [organizationRelease(preview, "0.1.0", { prerelease: true })],
"repos/Lithe-IDEA/lithe-plugin-unlicensed/releases?per_page=100": [organizationRelease(unlicensed, "1.0.0")],
"repos/Lithe-IDEA/lithe-plugin-undescribed/releases?per_page=100": [organizationRelease(undescribed, "1.0.0")],
"repos/Lithe-IDEA/lithe-plugin-copy/releases?per_page=100": [copyRelease],
"repos/Lithe-IDEA/lithe-plugin-anonymous/releases?per_page=100": [anonymousRelease],
"repos/Lithe-IDEA/lithe-plugin-official/releases?per_page=100": [officialRelease],
}, {
[copyRelease.assets[0].browser_download_url]: { ...zigManifest("1.0.0"), id: "io.example.zig-support" },
[anonymousRelease.assets[0].browser_download_url]: { ...zigManifest("1.0.0"), id: "io.github.lithe-idea.anonymous", vendor: { signatureRequirement: "none" } },
Expand Down Expand Up @@ -386,8 +398,8 @@ function scopedTracking() {
const index = { schemaVersion: 0, plugins: [validEntry(), organizationEntry] };
const fixture = organizationFixture({
[REPOSITORIES_PATH]: [zigRepository],
"repos/Lithe-IDEA/lithe-plugin-zig/releases?per_page=20": [organizationPluginRelease],
"repos/example/lithe-zig/releases?per_page=20": [externalRelease],
"repos/Lithe-IDEA/lithe-plugin-zig/releases?per_page=100": [organizationPluginRelease],
"repos/example/lithe-zig/releases?per_page=100": [externalRelease],
}, {
[organizationPluginRelease.assets[0].browser_download_url]: zigManifest("1.1.0"),
[externalRelease.assets[0].browser_download_url]: { ...zigManifest("9.0.0"), id: "io.example.zig-support" },
Expand Down Expand Up @@ -421,21 +433,109 @@ test("scoped tracking separates organization plugins from external plugins", { t
const organizationRun = await trackIndex(organization.index, { ...organization.archiveIO, scope: "organization" });
assert.deepEqual(organizationRun.skipped, []);
assert.deepEqual(organizationRun.added, [`${ZIG_ID}@1.1.0 (v1.1.0)`]);
assert.deepEqual(organization.requests, ["repos/Lithe-IDEA/lithe-plugin-zig/releases?per_page=20", REPOSITORIES_PATH]);
assert.deepEqual(organization.requests, ["repos/Lithe-IDEA/lithe-plugin-zig/releases?per_page=100", REPOSITORIES_PATH]);

const external = scopedTracking();
const externalRun = await trackIndex(external.index, { ...external.archiveIO, scope: "external" });
assert.deepEqual(externalRun.skipped, []);
assert.deepEqual(externalRun.added, ["io.example.zig-support@9.0.0 (v9.0.0)"]);
assert.deepEqual(externalRun.newPlugins, []);
// The external pass never scans the organization, so it cannot list a plugin for the first time.
assert.deepEqual(external.requests, ["repos/example/lithe-zig/releases?per_page=20"]);
assert.deepEqual(external.requests, ["repos/example/lithe-zig/releases?per_page=100"]);

const unscoped = scopedTracking();
const unscopedRun = await trackIndex(unscoped.index, unscoped.archiveIO);
assert.deepEqual(unscopedRun.added, ["io.example.zig-support@9.0.0 (v9.0.0)", `${ZIG_ID}@1.1.0 (v1.1.0)`]);
});

// Two plugins published from one repository, each under its own tag prefix.
const SHARED_REPOSITORY = "https://github.com/Lithe-IDEA/lithe-ai-plugins";
const CODEX_ID = "io.github.lithe-idea.codex";
const CLAUDE_CODE_ID = "io.github.lithe-idea.claude-code";

function sharedRelease(prefix, name, version) {
const asset = `${name}-${version}-darwin.zip`;
return {
tag_name: `${prefix}${version}`,
draft: false,
prerelease: false,
published_at: "2026-11-02T00:00:00Z",
assets: [{ name: asset, browser_download_url: `${SHARED_REPOSITORY}/releases/download/${prefix}${version}/${asset}` }],
};
}

function sharedEntry(id, prefix, name) {
return {
id,
name,
author: "Lithe Community",
repository: SHARED_REPOSITORY,
description: `${name} for Lithe`,
license: "MIT",
versions: [{
version: "0.1.0",
pluginAPIVersion: 0,
requires: { languageServers: 0, languages: 0 },
releaseDate: "2026-11-01",
downloads: [{
platforms: ["darwin-arm64", "darwin-x64"],
downloadURL: sharedRelease(prefix, name, "0.1.0").assets[0].browser_download_url,
sha256: "0".repeat(64),
}],
}],
};
}

test("plugins sharing a repository each track only the releases with their own tag prefix", { timeout: 5_000 }, async () => {
const releases = [
sharedRelease("codex-v", "codex", "0.3.0"),
sharedRelease("codex-v", "codex", "0.2.0"),
sharedRelease("claude-code-v", "claude-code", "0.2.0"),
{ ...sharedRelease("", "latest", "1.0.0"), tag_name: "latest" },
sharedRelease("other-v", "other", "1.0.0"),
sharedRelease("claude-code-v", "claude-code", "0.1.0"),
sharedRelease("codex-v", "codex", "0.1.0"),
];
const url = (release) => release.assets[0].browser_download_url;
const index = {
schemaVersion: 0,
plugins: [sharedEntry(CLAUDE_CODE_ID, "claude-code-v", "claude-code"), sharedEntry(CODEX_ID, "codex-v", "codex")],
};
const fixture = organizationFixture({
[REPOSITORIES_PATH]: [],
"repos/Lithe-IDEA/lithe-ai-plugins/releases?per_page=100": releases,
}, {
// A plugin.json version that differs from the tag is refused, not listed under either.
[url(releases[0])]: { ...zigManifest("0.3.1"), id: CODEX_ID },
[url(releases[1])]: { ...zigManifest("0.2.0"), id: CODEX_ID },
[url(releases[2])]: { ...zigManifest("0.2.0"), id: CLAUDE_CODE_ID },
});
const result = await trackIndex(index, { ...fixture, scope: "organization" });

assert.deepEqual(result.added, [`${CLAUDE_CODE_ID}@0.2.0 (claude-code-v0.2.0)`, `${CODEX_ID}@0.2.0 (codex-v0.2.0)`]);
// The sibling's releases are neither downloaded nor reported.
assert.deepEqual(fixture.downloads, [url(releases[2]), url(releases[0]), url(releases[1])]);
assert.equal(result.skipped.length, 5);
const log = result.skipped.join("\n");
assert.match(log, new RegExp(`${CODEX_ID} codex-v0\\.3\\.0: .*release tag \`codex-v0\\.3\\.0\` must be <prefix>0\\.3\\.1`));
for (const id of [CLAUDE_CODE_ID, CODEX_ID]) {
assert.match(log, new RegExp(`${id} latest: the tag must be <prefix>MAJOR\\.MINOR\\.PATCH`));
assert.match(log, new RegExp(`${id} other-v1\\.0\\.0: the tag prefix \`other-v\``));
}
assert.deepEqual(index.plugins.map((entry) => entry.versions.map((version) => version.version)), [["0.2.0", "0.1.0"], ["0.2.0", "0.1.0"]]);
assert.deepEqual(validateIndex(index), []);
});

test("an entry without versions keeps the tag prefix of the first release it adds", { timeout: 5_000 }, async () => {
const entry = { ...sharedEntry(CODEX_ID, "codex-v", "codex"), versions: [] };
const releases = [sharedRelease("codex-v", "codex", "0.2.0"), sharedRelease("v", "codex", "0.1.0")];
const fixture = organizationFixture({}, { [releases[0].assets[0].browser_download_url]: { ...zigManifest("0.2.0"), id: CODEX_ID } });
const result = await trackEntry(entry, releases, fixture);
assert.deepEqual(result.added, [`${CODEX_ID}@0.2.0 (codex-v0.2.0)`]);
assert.deepEqual(result.skipped, [`${CODEX_ID} v0.1.0: the tag prefix \`v\` is not \`codex-v\` of the listed versions`]);
assert.deepEqual(releaseTagConvention(entry), { prefix: "codex-v" });
});

test("archive verification rechecks changed manifest expectations for the same URL and hash", { timeout: 5_000 }, async () => {
const entry = capabilityEntry();
const manifest = manifestFor(entry);
Expand Down Expand Up @@ -502,12 +602,48 @@ test("formatting keeps plain arrays inline and round-trips", () => {
});

test("duplicate ids and unsorted plugins fail the store policy", () => {
const second = { ...validEntry(), id: "io.example.another" };
const second = siblingEntry("io.example.another", "another-v");
assert.match(validateIndex({ schemaVersion: 0, plugins: [validEntry(), validEntry()] }).join("\n"), /plugin\.index\.duplicate/);
assert.match(validateIndex({ schemaVersion: 0, plugins: [validEntry(), second] }).join("\n"), /sorted by id/);
assert.deepEqual(validateIndex({ schemaVersion: 0, plugins: [second, validEntry()] }), []);
});

test("release tags split into one prefix and the version they end with, as Lithe's Core splits them", () => {
assert.deepEqual(splitReleaseTag("v1.2.0"), { prefix: "v", version: "1.2.0" });
assert.deepEqual(splitReleaseTag("codex-v0.10.2"), { prefix: "codex-v", version: "0.10.2" });
assert.deepEqual(splitReleaseTag("1.2.0"), { prefix: "", version: "1.2.0" });
// The major number takes every digit, so a prefix never ends in a digit.
assert.deepEqual(splitReleaseTag("a12.3.4"), { prefix: "a", version: "12.3.4" });
for (const tag of ["x1.2.3.4", "1.2.3.4", "v1.2.0-beta.1", "v9", "v1.2", "latest", "", undefined]) {
assert.equal(splitReleaseTag(tag), null, String(tag));
}
});

test("every listing uses one release tag prefix of its own, ending in the listed version", () => {
const index = (...plugins) => ({ schemaVersion: 0, plugins });
assert.deepEqual(releaseTagConvention(validEntry()), { prefix: "v" });

const mismatched = validEntry();
mismatched.versions[0].downloads[0].downloadURL = mismatched.versions[0].downloads[0].downloadURL.replace("/v1.9.0/", "/v1.9.1/");
assert.match(validateIndex(index(mismatched)).join(), /store policy: 1\.9\.0: release tag `v1\.9\.1` must be <prefix>1\.9\.0/);

const mixed = validEntry();
mixed.versions[0].downloads[0].downloadURL = mixed.versions[0].downloads[0].downloadURL.replace("/v1.9.0/", "/zig-v1.9.0/");
assert.match(validateIndex(index(mixed)).join(), /store policy: 2\.0\.0: release tag `v2\.0\.0` does not use the prefix `zig-v`/);

// Lithe derives no prefix from a percent-encoded tag, so the store refuses it.
const encoded = validEntry();
encoded.versions[0].downloads[0].downloadURL = encoded.versions[0].downloads[0].downloadURL.replace("/v1.9.0/", "/v%31.9.0/");
assert.match(validateIndex(index(encoded)).join(), /store policy: 1\.9\.0: release tag `v%31\.9\.0`/);

// Repository names compare in any letter case, like download URLs.
const sameClaim = siblingEntry("io.example.another", "v");
sameClaim.repository = "https://github.com/Example/Lithe-Zig";
assert.match(validateIndex(index(sameClaim, validEntry())).join(),
/plugins\[1\] \(io\.example\.zig-support\): store policy: io\.example\.another already uses release tag prefix `v`/);
assert.deepEqual(validateIndex(index(siblingEntry("io.example.another", ""), validEntry())), []);
});

test("a wrong schema version or extra root field is refused", () => {
for (const schemaVersion of [1, 2, "0", undefined]) {
assert.match(validateIndex({ schemaVersion, plugins: [] }).join(), /plugin\.index\.schemaUnsupported/);
Expand Down
Loading