Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
db49198
feat(plugins): authorize native Tests runs and scoped result pages
WhiteZeek Nov 30, 2026
2788f66
feat(tests): support standalone runner reports and lifecycle diagnostics
WhiteZeek Nov 30, 2026
ce7cf59
docs(plugins): register API-29 methods in the protocol history
WhiteZeek Nov 30, 2026
453594a
test(plugins): exercise typed Tests calls and document callback admis…
WhiteZeek Nov 30, 2026
d3be95a
Merge remote-tracking branch 'origin/main' into feat/2499-native-tests
WhiteZeek Nov 30, 2026
b1a0c80
Merge branch 'feat/2499-native-tests' into feat/2499-test-runners
WhiteZeek Nov 30, 2026
65d4249
Merge remote-tracking branch 'origin/main' into feat/2499-native-tests
WhiteZeek Nov 30, 2026
205709b
Merge branch 'feat/2499-native-tests' into feat/2499-test-runners
WhiteZeek Nov 30, 2026
6c48ddf
Merge remote-tracking branch 'origin/main' into feat/2499-native-tests
WhiteZeek Dec 1, 2026
02d25c1
Merge branch 'feat/2499-native-tests' into feat/2499-test-runners
WhiteZeek Dec 1, 2026
95f803f
Merge remote-tracking branch 'origin/main' into feat/2499-native-tests
WhiteZeek Dec 1, 2026
abe523c
Merge Core main and retain the native Tests and Agents protocol entries
WhiteZeek Dec 1, 2026
3e71335
fix(tests): reject standalone reports missing the tests array
WhiteZeek Dec 1, 2026
646b0f3
Merge remote-tracking branch 'origin/main' into feat/2499-native-tests
WhiteZeek Dec 1, 2026
0cb1673
Merge branch 'feat/2499-native-tests' into feat/2499-test-runners
WhiteZeek Dec 1, 2026
e48ba0e
fix(plugins): require the project of a native test target and documen…
WhiteZeek Dec 1, 2026
950e196
docs(plugins): clarify standalone reruns and protocol availability
WhiteZeek Dec 1, 2026
533cc53
Merge remote-tracking branch 'origin/main' into feat/2499-native-tests
WhiteZeek Dec 1, 2026
639e6cc
Merge branch 'feat/2499-native-tests' into feat/2499-test-runners
WhiteZeek Dec 1, 2026
ba9b4da
Merge remote-tracking branch 'origin/main' into feat/2499-native-tests
WhiteZeek Dec 1, 2026
45bd06c
Merge branch 'feat/2499-native-tests' into feat/2499-test-runners
WhiteZeek Dec 1, 2026
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/contracts/rust-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ or removing a command fails until the table changes in the same commit.
| `build.decodeRunEntrypoints` | Validate and deduplicate the run entrypoints a Provider named |
| `build.dependencyPlan` | Expand the command that prints a project's dependency tree, or the request a build provider answers |
| `build.decodeModel` | Decode model output or a provider result into projects, targets, tasks, content roots, option values, and run entries |
| `build.decodeInlineTestResults` | Decode an inline `litheTestResults` version 0 report from an independent test runner. Returns the same results envelope and workspace-relative locations as provider reports. |
| `build.decodeTestResults` | Decode a test run's reports and output into per-case results and a summary |
| `build.decodeDiagnostics` | Decode build output into workspace file diagnostics |
| `build.decodeDependencies` | Decode dependency output or a provider result into one project's bounded tree |
Expand Down
12 changes: 12 additions & 0 deletions rust/crates/build/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,18 @@ pub fn build_decode_test_results_command<M: BuildManifest>(
)
}

/// Decodes a standalone runner's inline canonical report under its workspace root.
pub fn build_decode_inline_test_results_command(payload: Value) -> Result<Value, CoreError> {
let results = if payload.get("tests").is_none() {
Err(super::decode::invalid_output(
"The standalone test report is missing its tests array.",
))
} else {
outputs::inline_test_results(&payload, ".")
};
Ok(outcome(results.map(|results| ("results", results))))
}

/// `build.decodeDiagnostics`: file diagnostics from process output.
pub fn build_decode_diagnostics_command<M: BuildManifest>(
payload: Value,
Expand Down
47 changes: 41 additions & 6 deletions rust/crates/build/src/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,17 +397,14 @@ pub(crate) fn decode_test_results(
None => root.clone(),
};
decode::bounded_text(&request.output)?;
let mut coverage = Vec::new();
let cases = match source {
TestResultsSource::Provider => {
let (cases, scopes) = provider_test_cases(
return inline_test_results(
request.result.as_ref().ok_or_else(|| {
decode::invalid_output("The provider returned no test report.")
})?,
&root,
)?;
coverage = scopes;
cases
);
}
TestResultsSource::JunitXml { reports } => report_cases(
&workspace,
Expand All @@ -424,6 +421,17 @@ pub(crate) fn decode_test_results(
|text, base| canonical_cases(text, &workspace, base),
),
};
Ok(summarize_results(cases, Vec::new()))
}

/// Decodes the same inline report for a build provider and for a standalone plugin runner.
/// Filenames are workspace-relative. Reading or searching the workspace is unnecessary.
pub(crate) fn inline_test_results(value: &Value, root: &str) -> Validation<Value> {
let (cases, coverage) = provider_test_cases(value, root)?;
Comment thread
WhiteZeek marked this conversation as resolved.
Resolved
Ok(summarize_results(cases, coverage))
}

fn summarize_results(cases: Vec<TestCaseResult>, coverage: Vec<TestCoverage>) -> Value {
let cases = aggregate(cases);
let summary = summary(&cases);
let mut result = json!({
Expand All @@ -434,7 +442,7 @@ pub(crate) fn decode_test_results(
if !coverage.is_empty() {
result["coverage"] = json!(coverage);
}
Ok(result)
result
}

/// Validates an inline report without opening report files or inferring tool semantics.
Expand Down Expand Up @@ -1117,3 +1125,30 @@ pub(crate) fn sync_fingerprint(
"watch": files,
}))
}

#[cfg(test)]
mod inline_runner_tests {
use super::*;

#[test]
fn standalone_report_requires_an_explicit_tests_array() {
let mut report = json!({"format": "litheTestResults", "version": 0});
let rejected = crate::build_decode_inline_test_results_command(report.clone()).unwrap();
assert_eq!(rejected["error"]["code"], "plugin.build.invalidOutput");

report["tests"] = json!([]);
let empty = crate::build_decode_inline_test_results_command(report).unwrap();
assert_eq!(empty["status"], "ok");
assert_eq!(empty["results"]["tests"], json!([]));
}

#[test]
fn standalone_report_uses_provider_validation_and_outcomes() {
let mut report = json!({"format":"litheTestResults","version":0,"tests":[{"suite":"cart","case":"add","status":"failed","path":"tests/cart.txt","line":2},{"suite":"cart","case":"add","status":"passed"}]});
let results = inline_test_results(&report, ".").unwrap();
assert_eq!(results["tests"][0]["invocations"], 2);
assert_eq!(results["summary"]["failed"], 1);
report["tests"][0]["path"] = json!("../outside");
assert!(inline_test_results(&report, ".").is_err());
}
}
5 changes: 5 additions & 0 deletions rust/crates/core/src/protocol/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,8 @@ pub enum BuildCommand {
DecodeModel,
/// Normalizes build test results (`build.decodeTestResults`).
DecodeTestResults,
/// Normalizes one inline native Tests report without a build-system declaration.
DecodeInlineTestResults,
/// Normalizes build diagnostics from process output (`build.decodeDiagnostics`).
DecodeDiagnostics,
/// Normalizes a project's dependency tree (`build.decodeDependencies`).
Expand Down Expand Up @@ -1500,6 +1502,9 @@ impl CoreCommand {
"build.decodeRunEntrypoints" => Some(Self::Build(BuildCommand::DecodeRunEntrypoints)),
"build.dependencyPlan" => Some(Self::Build(BuildCommand::DependencyPlan)),
"build.decodeModel" => Some(Self::Build(BuildCommand::DecodeModel)),
"build.decodeInlineTestResults" => {
Some(Self::Build(BuildCommand::DecodeInlineTestResults))
}
"build.decodeTestResults" => Some(Self::Build(BuildCommand::DecodeTestResults)),
"build.decodeDiagnostics" => Some(Self::Build(BuildCommand::DecodeDiagnostics)),
"build.decodeDependencies" => Some(Self::Build(BuildCommand::DecodeDependencies)),
Expand Down
5 changes: 5 additions & 0 deletions rust/crates/core/src/runtime/dispatcher/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ pub(super) fn dispatch(command: BuildCommand, id: Option<String>, payload: Value
payload,
crate::build::build_decode_model_command::<Manifest>,
),
BuildCommand::DecodeInlineTestResults => plugin_response(
id,
payload,
crate::build::build_decode_inline_test_results_command,
),
BuildCommand::DecodeTestResults => plugin_response(
id,
payload,
Expand Down
14 changes: 14 additions & 0 deletions rust/crates/diagnostics/src/catalog_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1881,6 +1881,20 @@ pub static EVENTS: &[EventMetadata] = &[
rate: 600,
owner: "Lithe",
},
EventMetadata {
id: "run.tests.state_changed",
channel: "run",
level: LogLevel::Info,
message: "Native Tests run {run} reached {stage}",
fields: &[
FieldMetadata { name: "outcome", field_type: FieldType::Token, required: false, description: "Core verdict or stable failure category when the test run ends", reason: None },
FieldMetadata { name: "run", field_type: FieldType::Token, required: true, description: "Host-generated run ID returned to the originating plugin session", reason: None },
FieldMetadata { name: "stage", field_type: FieldType::Token, required: true, description: "Stable lifecycle stage of this test run: accepted, stop_requested or finished", reason: None },
],
span: None,
rate: 600,
owner: "Lithe",
},
EventMetadata {
id: "terminal.input.failed",
channel: "terminal",
Expand Down
81 changes: 81 additions & 0 deletions rust/crates/plugin-rpc/src/host_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ pub(crate) fn check_host_params(
HostParams::HostPaths => &["context", "rootIDs"],
HostParams::BuildConfiguration { watch: false } => &["context", "buildSystemID", "root"],
HostParams::BuildConfiguration { watch: true } => &["context", "files"],
HostParams::Tests { results: false } => &[
"context",
"buildSystemID",
"root",
"project",
"target",
"suite",
"case",
"onFinish",
"runner",
"data",
"filters",
],
HostParams::Tests { results: true } => &["context", "runID", "offset"],
HostParams::FunctionProviders => &["functionID"],
HostParams::FunctionInvoke => &[
"pluginID",
Expand Down Expand Up @@ -165,6 +179,73 @@ pub(crate) fn check_host_params(
}
}
}
HostParams::Tests { results } => {
if !params.get("context").is_some_and(is_context_reference) {
return Err(invalid(CONTEXT_REFERENCE_MESSAGE));
}
if results {
if !params
.get("runID")
.and_then(Value::as_str)
.is_some_and(is_credential_key)
|| params
.get("offset")
.is_some_and(|v| v.as_u64().is_none_or(|n| n > 10000))
{
return Err(invalid("Expected a run ID and an optional result offset."));
}
} else {
let text = |key: &str| {
params.get(key).and_then(Value::as_str).is_some_and(|s| {
!s.is_empty() && s.len() <= 4096 && !s.chars().any(char::is_control)
})
};
if !params
.get("onFinish")
.and_then(Value::as_str)
.is_some_and(is_function_id)
|| ["project", "target", "suite", "case"]
.iter()
.any(|key| params.contains_key(*key) && !text(key))
|| (params.contains_key("target") && !params.contains_key("project"))
{
return Err(invalid(
"Expected a build instance, exact selectors and a completion function.",
));
}
if let Some(runner) = params.get("runner") {
let valid_filters = params.get("filters").is_none_or(|value| {
value.as_array().is_some_and(|filters| {
let mut seen = BTreeSet::new();
filters.len() <= 2
&& filters.iter().all(|filter| {
matches!(filter.as_str(), Some("suite" | "case"))
&& seen.insert(filter.as_str())
})
})
});
if !runner.as_str().is_some_and(is_function_id)
|| ["root", "buildSystemID", "target"]
.iter()
.any(|key| params.contains_key(*key))
|| !valid_filters
|| params
.get("data")
.is_some_and(|v| v.to_string().len() > 65536)
{
return Err(invalid("Invalid test runner, filters or rerun data."));
}
} else if !text("buildSystemID")
|| !text("root")
|| params.contains_key("data")
|| params.contains_key("filters")
{
return Err(invalid(
"Expected a declared build instance or a registered runner.",
));
}
}
}
HostParams::BuildConfiguration { watch } => {
if !params.get("context").is_some_and(is_context_reference) {
return Err(invalid(CONTEXT_REFERENCE_MESSAGE));
Expand Down
87 changes: 87 additions & 0 deletions rust/crates/plugin-rpc/src/host_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub(crate) enum HostParams {
/// `{ context, rootIDs? }`: a well-formed context reference and at most
/// 256 distinct root IDs (plan API-40).
HostPaths,
/// Starts tests on a declared build instance or reads a page of its completed results.
Tests { results: bool },
/// Build option lookup or build configuration subscription.
BuildConfiguration { watch: bool },
/// Snapshot source listing or one bounded chunk from a selected source.
Expand Down Expand Up @@ -370,6 +372,18 @@ pub(crate) const HOST_METHODS: &[HostMethod] = &[
permission: None,
params: HostParams::Context,
},
HostMethod {
method: "lithe/host/tests/start",
service: "tests",
permission: Some("tests.start"),
params: HostParams::Tests { results: false },
},
HostMethod {
method: "lithe/host/tests/results",
service: "tests",
permission: Some("tests.start"),
params: HostParams::Tests { results: true },
},
HostMethod {
method: "lithe/host/build/getOptions",
service: "build",
Expand Down Expand Up @@ -779,6 +793,79 @@ pub(crate) fn capabilities_answer(version: u64, granted: &BTreeSet<String>) -> V
})
}

#[cfg(test)]
mod native_tests {
use super::*;

#[test]
fn independent_runner_cannot_combine_build_fields_or_invent_filters() {
let method = "lithe/host/tests/start";
let grants = [method.to_owned()].into_iter().collect();
let mut params = json!({"context":{"contextID":"ctx","generation":1},"runner":"tests.run","onFinish":"tests.done","filters":["case"]});
assert_eq!(
host_request(method, Some(&params), Some(0), &grants).unwrap(),
HostRoute::Forward("tests")
);
for (field, value) in [("root", json!(".")), ("filters", json!(["file"]))] {
params[field] = value;
assert_eq!(
host_request(method, Some(&params), Some(0), &grants)
.unwrap_err()
.code,
codes::HOST_INVALID_PARAMS
);
params.as_object_mut().unwrap().remove(field);
}
}

#[test]
fn test_start_and_pages_require_the_declared_grant_and_context() {
let method = "lithe/host/tests/start";
let mut params: Value = serde_json::from_str(include_str!(
"../../../../shared/plugins/contract/v1/fixtures/build-providers/native-tests-start.json"
)).unwrap();
assert_eq!(
host_request(method, Some(&params), Some(0), &BTreeSet::new())
.unwrap_err()
.code,
codes::HOST_PERMISSION_DENIED
);
let granted = [method.to_owned(), "lithe/host/tests/results".to_owned()]
.into_iter()
.collect();
assert_eq!(
host_request(method, Some(&params), Some(0), &granted).unwrap(),
HostRoute::Forward("tests")
);
params["target"] = json!("unit");
assert_eq!(
host_request(method, Some(&params), Some(0), &granted)
.unwrap_err()
.code,
codes::HOST_INVALID_PARAMS
);
params["project"] = json!("module");
assert_eq!(
host_request(method, Some(&params), Some(0), &granted).unwrap(),
HostRoute::Forward("tests")
);
params["case"] = json!("");
assert_eq!(
host_request(method, Some(&params), Some(0), &granted)
.unwrap_err()
.code,
codes::HOST_INVALID_PARAMS
);
let page = json!({"context":params["context"],"runID":"test-1","offset":10001});
assert_eq!(
host_request("lithe/host/tests/results", Some(&page), Some(0), &granted)
.unwrap_err()
.code,
codes::HOST_INVALID_PARAMS
);
}
}

#[cfg(test)]
mod build_configuration_tests {
use super::*;
Expand Down
1 change: 1 addition & 0 deletions rust/crates/plugin-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ pub const HOST_PERMISSIONS: &[&str] = &[
"window.messages",
"terminal.create",
"keymaps.readSelectedSources",
"tests.start",
"run.start",
"debug.start",
PERMISSION_LANGUAGE_SERVER_REQUEST,
Expand Down
25 changes: 25 additions & 0 deletions rust/logging/events/run.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@
"version": 1,
"root": "run",
"events": [
{
"id": "run.tests.state_changed",
"channel": "run",
"level": "info",
"message": "Native Tests run {run} reached {stage}",
"fields": {
"run": {
"type": "token",
"required": true,
"description": "Host-generated run ID returned to the originating plugin session"
},
"stage": {
"type": "token",
"required": true,
"description": "Stable lifecycle stage of this test run: accepted, stop_requested or finished"
},
"outcome": {
"type": "token",
"required": false,
"description": "Core verdict or stable failure category when the test run ends"
}
},
"rate": 600,
"owner": "Lithe"
},
{
"id": "run.process.execution",
"channel": "run",
Expand Down
Loading
Loading