Skip to content

Commit 7381e79

Browse files
committed
fix(run-config): 未生成构建模型的项目也能列出和新建内置运行
- runConfig.resolve 在还没有生成层时返回已保存的运行;一个都没有时返回空列表,不再报 workspace_not_found, 没有任何插件的项目也能新建第一个脚本运行 - 没有生成层时不报 orphanedOverride - 保存表单时,来源为“脚本文本”且文本为空只报 text 必填,不再同时报 script 必填
1 parent e7c7739 commit 7381e79

4 files changed

Lines changed: 33 additions & 12 deletions

File tree

‎rust/contracts/rust-core-api.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3684,7 +3684,10 @@ An implicit selector-root cwd remains omitted from launch options. Current model
36843684
native build workflow before every preparation. No generated document is needed:
36853685
`runConfig.inspect` recognizes explicit saved team/local references and `runConfig.resolve`
36863686
merges them against an empty generated layer. A workspace without generated data
3687-
or an explicit saved Provider reference retains the existing missing state.
3687+
or a saved runnable entry is still `missing` for `runConfig.inspect`, while
3688+
`runConfig.resolve` returns an empty list, so the first built-in process run can be
3689+
created before any build model loads. Without generated data, overrides of generated
3690+
runs are not reported as `orphanedOverride`.
36883691
Complete saved `build.provider` entries (name, provider, selector and matching execution)
36893692
can retain any existing Run ID, including IDs imported from older formats; a prefix
36903693
does not grant launch authority. Sparse unknown-ID patches remain orphaned. Such an

‎rust/crates/core/src/tests/run_configuration.rs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,6 +1725,13 @@ fn built_in_process_runs_are_created_edited_moved_and_deleted_through_the_editor
17251725
let local = ".lithe/run/local.yaml";
17261726
let project = ".lithe/run/configurations.yaml";
17271727

1728+
// A project with no build model and no saved run has an empty list, so the
1729+
// first configuration can be created there.
1730+
let empty = call("runConfig.resolve", serde_json::json!({"root": root}));
1731+
assert_eq!(empty["ok"], true, "{empty}");
1732+
assert_eq!(empty["data"]["configurations"], serde_json::json!([]));
1733+
assert_eq!(empty["data"]["diagnostics"], serde_json::json!([]));
1734+
17281735
let types = call("runConfig.configurationTypes", serde_json::json!({}));
17291736
let providers: Vec<_> = types["data"]["types"]
17301737
.as_array()
@@ -1780,6 +1787,18 @@ fn built_in_process_runs_are_created_edited_moved_and_deleted_through_the_editor
17801787
{"field":"environment","code":"duplicate"}
17811788
])
17821789
);
1790+
// An empty text is reported once, on the field the chosen source shows.
1791+
let empty_text = call(
1792+
"runConfig.saveConfiguration",
1793+
serde_json::json!({"root":root,"provider":"process.shell","values":{
1794+
"name":"inline","source":"text","text":" "
1795+
}}),
1796+
);
1797+
assert_eq!(
1798+
empty_text["data"]["errors"],
1799+
serde_json::json!([{"field":"text","code":"required"}]),
1800+
"{empty_text}"
1801+
);
17831802

17841803
let saved = call(
17851804
"runConfig.saveConfiguration",

‎rust/crates/execution/src/configuration/form.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,8 @@ impl Draft {
721721
};
722722
// The saved entry must pass the same checks a launch makes; report
723723
// the ones the steps above do not, such as lengths and characters.
724+
// A missing value is left to the steps above, which name the field
725+
// of the chosen source: an empty text is not also a missing script.
724726
let configuration = RunConfiguration {
725727
id: "user:draft".into(),
726728
name: stored.name.clone(),
@@ -746,7 +748,9 @@ impl Draft {
746748
};
747749
if let Ok(found) = process::field_errors(&configuration, Platform::HOST) {
748750
for error in found {
749-
if !errors.iter().any(|known| known.field == error.field) {
751+
if error.code != "required"
752+
&& !errors.iter().any(|known| known.field == error.field)
753+
{
750754
errors.push(error);
751755
}
752756
}

‎rust/crates/execution/src/configuration/resolve.rs‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,13 @@ pub(crate) fn resolve_layers(
2323
) -> Result<Value, CoreError> {
2424
let team = &layers.project.document;
2525
let local = &layers.local.document;
26+
// Before any build model is loaded nothing is generated: the saved runs
27+
// still resolve, and a project with none has an empty list. Overrides of
28+
// generated runs are only orphaned once a generation can be compared.
2629
let layer = generated_layer::get(root);
2730
let generated = match layer.as_deref() {
2831
Some(document) => serde_json::to_value(document).expect("run configurations encode"),
29-
None if has_saved_runnable(local) || has_saved_runnable(team) => {
30-
json!({"version": VERSION, "configurations": []})
31-
}
32-
None => {
33-
return Err(CoreError::new(
34-
ErrorCode::WorkspaceNotFound,
35-
"Run configuration has not been generated",
36-
))
37-
}
32+
None => json!({"version": VERSION, "configurations": []}),
3833
};
3934
let generated_ids = configuration_ids(&generated)?;
4035
let local_toolchains = read_local_toolchains(root)?;
@@ -49,7 +44,7 @@ pub(crate) fn resolve_layers(
4944
.iter()
5045
.map(|item| item.id.as_str())
5146
.collect::<BTreeSet<_>>();
52-
for source in [team, local] {
47+
for source in [team, local].into_iter().filter(|_| layer.is_some()) {
5348
for id in configuration_ids(source)?.keys() {
5449
if !resolved_ids.contains(id.as_str()) && !id.starts_with("user:") {
5550
diagnostics.push(json!({

0 commit comments

Comments
 (0)