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
1 change: 1 addition & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 20 additions & 5 deletions rust/contracts/github.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ GitHub sign-in unavailable rather than asking the user for a personal token.
- `github.requestPlan` accepts an `operation` and typed operation fields. It
returns `host`, uppercase `method`, absolute `path`, ordered `query`, optional
JSON `body`, and `requiresAuthentication`.
- `github.normalizeResponse` accepts `operation`, HTTP `status`, and raw UTF-8
JSON `body`. It returns a normalized value or the standard Core error.
- `github.normalizeResponse` accepts `operation`, HTTP `status`, raw UTF-8
JSON `body`, and, for `listReleases`, the optional `tagPrefix` the request was
planned with. It returns a normalized value or the standard Core error.
- `github.deviceAuthorizationTransition` accepts `event`, `expiresIn`,
`interval`, `elapsedMilliseconds`, and optional `suggestedInterval`. It
returns `action`, `intervalSeconds`, and `waitMilliseconds`; it accepts no
Expand Down Expand Up @@ -100,9 +101,23 @@ leading `-` and the revision operators `~ ^ : ? * [ \` are refused) and returns
Hosts use it to pin a marketplace index to a commit, because raw file URLs of a
branch are cached for minutes (see `plugins.marketplace.resolveSource`).
`listReleases` (`GET /repos/{owner}/{name}/releases`, first page of 20) returns
`[{ tagName, name, body, publishedAt, prerelease, url }]` newest publication
first, ties ordered by tag; drafts are dropped, an empty title is `null` and
missing notes are `""`.
`[{ tagName, version, name, body, publishedAt, prerelease, url }]` newest
publication first, ties ordered by tag; drafts are dropped, an empty title is
`null` and missing notes are `""`. `version` is the `MAJOR.MINOR.PATCH` the tag
ends with, or `null`: the major number takes every digit before it and a
prefix ending in `.` has no split, so `v1.2.0`, `codex-v1.2.0` and `1.2.0` all
read `1.2.0` while `x1.2.3.4` and `v1.2.0-beta.1` read `null`. Hosts compare it
with an installed plugin version.

A repository that publishes several plugins tags each plugin's releases with
its own prefix (`codex-v0.1.0`, `claude-code-v0.1.0`). Pass the plugin's prefix
as `tagPrefix` (the marketplace entry's `releaseTagPrefix`) to both
`github.requestPlan` and `github.normalizeResponse`: the plan reads one page of
100, and normalization keeps only tags that split into exactly that prefix and
a version, newest first, at most 20. The empty prefix keeps bare
`MAJOR.MINOR.PATCH` tags; an absent `tagPrefix` keeps every release. A prefix
ending in a digit or `.`, or containing whitespace or a control character, can
never match and is refused with `invalid_request` (details `tagPrefix`).

`listReviewComments` (`GET /repos/{owner}/{name}/pulls/{number}/comments`, first
page of 100) needs `pullNumber` and returns a flat array of
Expand Down
133 changes: 131 additions & 2 deletions rust/crates/core/src/tests/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,35 @@ fn request_plan_reads_the_newest_commit_and_releases_without_credentials() {
assert_eq!(response["data"]["query"], json!({"per_page": "20"}));
assert_eq!(response["data"]["requiresAuthentication"], false);

// A plugin sharing its repository reads GitHub's largest page, so its
// own releases remain after the siblings' are filtered out.
for prefix in ["codex-v", ""] {
let response = execute(
"github.requestPlan",
json!({
"operation": "listReleases",
"repository": {"owner": "example", "name": "lithe-ai-plugins"},
"tagPrefix": prefix
}),
);
assert_eq!(response["ok"], true, "{prefix}: {response:?}");
assert_eq!(response["data"]["query"], json!({"per_page": "100"}));
}
// A prefix ending in a digit or "." never splits off a tag, so it is
// refused instead of answering with an empty changelog.
for prefix in ["codex-1", "codex-v.", "codex v", "a\nb"] {
let response = execute(
"github.requestPlan",
json!({
"operation": "listReleases",
"repository": {"owner": "example", "name": "lithe-ai-plugins"},
"tagPrefix": prefix
}),
);
assert_eq!(response["ok"], false, "{prefix}: {response:?}");
assert_eq!(response["error"]["code"], "invalid_request");
}

for git_ref in ["", "main..x", "-x", "main x", "HEAD~1", "a:b"] {
let response = execute(
"github.requestPlan",
Expand Down Expand Up @@ -499,12 +528,12 @@ fn normalizes_releases_newest_first_without_drafts() {
response["data"],
json!([
{
"tagName": "v0.1.1", "name": null, "body": "## Fixes\n- One.",
"tagName": "v0.1.1", "version": "0.1.1", "name": null, "body": "## Fixes\n- One.",
"publishedAt": "2026-11-22T13:31:49Z", "prerelease": false,
"url": "https://github.com/example/p/releases/tag/v0.1.1"
},
{
"tagName": "v0.1.0", "name": "v0.1.0", "body": "First.",
"tagName": "v0.1.0", "version": "0.1.0", "name": "v0.1.0", "body": "First.",
"publishedAt": "2026-11-21T08:00:00Z", "prerelease": true,
"url": "https://github.com/example/p/releases/tag/v0.1.0"
}
Expand All @@ -518,3 +547,103 @@ fn normalizes_releases_newest_first_without_drafts() {
assert_eq!(response["ok"], false, "{response:?}");
assert_eq!(response["error"]["code"], "invalid_request");
}

#[test]
fn release_tags_split_into_one_prefix_and_version() {
use lithe_github::split_release_tag;
assert_eq!(split_release_tag("v1.2.0"), Some(("v", "1.2.0")));
assert_eq!(
split_release_tag("codex-v0.1.0"),
Some(("codex-v", "0.1.0"))
);
assert_eq!(split_release_tag("1.2.0"), Some(("", "1.2.0")));
// The major number takes every digit, so "v10" never reads as prefix "v1".
assert_eq!(split_release_tag("v10.0.0"), Some(("v", "10.0.0")));
assert_eq!(
split_release_tag("plugin-2-v1.0.0"),
Some(("plugin-2-v", "1.0.0"))
);
// Four parts would make "x1." a prefix; refusing it keeps the split unique.
for tag in ["x1.2.3.4", "v1.2", "v1.2.3-beta.1", "1.2.", "v.1.2", ""] {
assert_eq!(split_release_tag(tag), None, "{tag}");
}
}

#[test]
fn a_tag_prefix_keeps_only_that_plugins_releases() {
let release = |tag: &str, published: &str| {
json!({
"tag_name": tag, "name": tag, "body": "", "draft": false, "prerelease": false,
"published_at": published,
"html_url": format!("https://github.com/example/lithe-ai-plugins/releases/tag/{tag}")
})
};
let body = json!([
release("claude-code-v0.1.0", "2026-11-29T10:00:00Z"),
release("codex-v0.1.0", "2026-11-29T09:00:00Z"),
release("codex-v0.0.1", "2026-11-28T09:00:00Z"),
release("codex-vnext", "2026-11-28T08:00:00Z"),
release("0.0.9", "2026-11-27T09:00:00Z"),
]);
let normalize = |prefix: Value| {
let mut payload =
json!({"operation": "listReleases", "status": 200, "body": body.to_string()});
if !prefix.is_null() {
payload["tagPrefix"] = prefix;
}
let response = execute("github.normalizeResponse", payload);
assert_eq!(response["ok"], true, "{response:?}");
response["data"]
.as_array()
.unwrap()
.iter()
.map(|release| (release["tagName"].clone(), release["version"].clone()))
.collect::<Vec<_>>()
};
assert_eq!(
normalize(json!("codex-v")),
vec![
(json!("codex-v0.1.0"), json!("0.1.0")),
(json!("codex-v0.0.1"), json!("0.0.1"))
]
);
assert_eq!(normalize(json!("")), vec![(json!("0.0.9"), json!("0.0.9"))]);
// Without a prefix every release stays; a tag without a version has none.
let all = normalize(Value::Null);
assert_eq!(all.len(), 5);
assert_eq!(all[3], (json!("codex-vnext"), Value::Null));

let response = execute(
"github.normalizeResponse",
json!({"operation": "listReleases", "status": 200, "body": body.to_string(), "tagPrefix": "codex-1"}),
);
assert_eq!(response["ok"], false, "{response:?}");
assert_eq!(response["error"]["code"], "invalid_request");
}

#[test]
fn a_prefixed_release_list_keeps_the_newest_twenty() {
// The prefixed request reads 100 releases; the changelog still shows
// the same bounded number as an unprefixed one.
let body: Vec<Value> = (0..30)
.map(|patch| {
json!({
"tag_name": format!("codex-v0.0.{patch}"), "draft": false,
"published_at": format!("2026-11-01T00:00:{patch:02}Z"),
"html_url": format!("https://github.com/example/p/releases/tag/codex-v0.0.{patch}")
})
})
.collect();
let response = execute(
"github.normalizeResponse",
json!({
"operation": "listReleases", "status": 200,
"body": Value::Array(body).to_string(), "tagPrefix": "codex-v"
}),
);
assert_eq!(response["ok"], true, "{response:?}");
let releases = response["data"].as_array().unwrap();
assert_eq!(releases.len(), 20);
assert_eq!(releases[0]["tagName"], "codex-v0.0.29");
assert_eq!(releases[19]["tagName"], "codex-v0.0.10");
}
34 changes: 34 additions & 0 deletions rust/crates/core/src/tests/marketplace_plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,40 @@ fn accepted_entries_are_normalized_newest_first() {
assert_eq!(zig["repository"], "https://github.com/example/lithe-zig");
}

#[test]
fn a_release_tag_prefix_is_derived_only_from_one_consistent_convention() {
let elixir = |edit: Option<&str>| {
let mut entry = json_file(INDEX)["plugins"][3].clone();
assert_eq!(entry["id"], "io.example.elixir-tools");
if let Some(url) = edit {
*entry
.pointer_mut("/versions/1/downloads/0/downloadURL")
.unwrap() = json!(url);
}
let outcome = validate(
json!({ "schemaVersion": 0, "plugins": [entry] }),
"thirdParty",
"darwin-arm64",
);
assert_eq!(outcome["index"]["rejected"], json!([]), "{outcome}");
outcome["index"]["plugins"][0]["releaseTagPrefix"].clone()
};
assert_eq!(elixir(None), json!("v"));
let base = "https://github.com/example/lithe-elixir/releases/download";
for tag in [
// Another plugin's prefix in the same entry: two conventions.
"elixir-v2.0.0",
// A tag for a version other than the one listing it.
"v2.0.1",
// No version at the end, and an escaped segment.
"latest",
"v%32.0.0",
] {
let url = format!("{base}/{tag}/elixir-tools-2.0.0.zip");
assert_eq!(elixir(Some(&url)), Value::Null, "{tag}");
}
}

#[test]
fn invalid_index_entries_report_their_stable_codes() {
let cases = json_file(INVALID_ENTRIES);
Expand Down
Loading
Loading