Skip to content

Commit dd502ce

Browse files
authored
Bridge / REPL / SDK cleanups (#3034)
* remove completions spinner because of glitches * cargo colors * type naming cleanups * preserve boolean case position * do not use global counters for enum cases. * union ordering fixes * fix optional boolean * lint / fmt * update test target * extract owners * format * format * update tests * increase defaults * test updates * test updates * also increase for download * fix accidentally removed command env * test updates * update CLI goldenfiles
1 parent 4f0d09a commit dd502ce

File tree

41 files changed

+2143
-1386
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2143
-1386
lines changed

Makefile.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
# - `cargo make worker-executor-tests`: runs worker executor tests only
1212
# - `cargo make integration-tests`: runs integration tests only
1313
# - `cargo make sharding-tests-debug`: runs sharding integration tests with file logging enabled, also accepts test name filter arguments
14-
# - `cargo make api-tests-http`: runs api integration tests using HTTP API only
15-
# - `cargo make api-tests-grpc`: runs api integration tests using GRPC API only
1614
# - `cargo make test`: runs all unit tests, worker executor tests and integration tests
1715
# - `cargo make check-openapi`: generates openapi spec from the code and checks if it is the same as the one in the openapi directory (for CI)
1816
# - `cargo make generate-openapi`: generates openapi spec from the code and saves it to the openapi directory
@@ -349,7 +347,6 @@ description = "Runs all unit tests, worker executor tests and integration tests"
349347
dependencies = [
350348
"unit-tests",
351349
"worker-executor-tests",
352-
"api-tests",
353350
"integration-tests",
354351
]
355352

cli/golem-cli/src/app/build/command.rs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,12 +372,16 @@ pub async fn execute_external_command(
372372
)
373373
.await?;
374374

375-
let mut cmd = Command::new(command_tokens[0].clone());
376-
cmd.args(command_tokens.iter().skip(1))
375+
let mut process = Command::new(command_tokens[0].clone());
376+
377+
process
378+
.args(command_tokens.iter().skip(1))
377379
.current_dir(&build_dir)
378-
.envs(&command.env)
379-
.stream_and_run(&command_tokens[0])
380-
.await
380+
.envs(&command.env);
381+
382+
configure_external_command_env(&mut process, command_tokens[0].as_str(), ctx);
383+
384+
process.stream_and_run(&command_tokens[0]).await
381385
},
382386
|| {
383387
log_skipping_up_to_date(format!(
@@ -420,3 +424,22 @@ pub async fn ensure_common_deps_for_tool(
420424
_ => Ok(()),
421425
}
422426
}
427+
428+
fn configure_external_command_env(command: &mut Command, executable: &str, ctx: &BuildContext<'_>) {
429+
let executable_name = Path::new(executable)
430+
.file_name()
431+
.and_then(|name| name.to_str());
432+
433+
if let Some("cargo") = executable_name {
434+
apply_cargo_term_color_env(command, ctx.should_colorize())
435+
}
436+
}
437+
438+
fn apply_cargo_term_color_env(command: &mut Command, should_colorize: bool) {
439+
if std::env::var_os("CARGO_TERM_COLOR").is_some() {
440+
return;
441+
}
442+
443+
let color = if should_colorize { "always" } else { "never" };
444+
command.env("CARGO_TERM_COLOR", color);
445+
}

cli/golem-cli/src/app/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ impl<'a> BuildContext<'a> {
8787
self.build_config.skip_up_to_date_checks
8888
}
8989

90+
pub fn should_colorize(&self) -> bool {
91+
self.application_config().should_colorize
92+
}
93+
9094
pub fn tools_with_ensured_common_deps(&self) -> &ToolsWithEnsuredCommonDeps {
9195
&self.application_context.tools_with_ensured_common_deps
9296
}

cli/golem-cli/src/bridge_gen/type_naming/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,21 @@ pub struct TypeNaming<TN: TypeName> {
7676

7777
impl<TN: TypeName> TypeNaming<TN> {
7878
pub fn new(agent_type: &AgentType, same_language: bool) -> anyhow::Result<Self> {
79+
Self::new_with_reserved_names(agent_type, same_language, std::iter::empty::<TN>())
80+
}
81+
82+
pub fn new_with_reserved_names(
83+
agent_type: &AgentType,
84+
same_language: bool,
85+
reserved_names: impl IntoIterator<Item = TN>,
86+
) -> anyhow::Result<Self> {
87+
let mut type_names = HashSet::new();
88+
type_names.extend(reserved_names);
89+
7990
let mut type_naming = Self {
8091
named_type_locations: Default::default(),
8192
anonymous_type_locations: Default::default(),
82-
type_names: HashSet::new(),
93+
type_names,
8394
types: HashMap::new(),
8495
same_language,
8596
};

cli/golem-cli/src/bridge_gen/type_naming/type_location.rs

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl TypeLocation {
2424
pub fn to_type_naming_segments(&self) -> Vec<Vec<&str>> {
2525
match &self.root {
2626
TypeLocationRoot::AgentConstructorInput { input_name } => {
27-
let mut segments = vec![vec!["ConstructorInput", input_name.as_str()]];
27+
let mut segments = vec![vec!["AgentParam", input_name.as_str()]];
2828
if let Some(path) = &self.path {
2929
segments.extend(path.to_type_naming_segments());
3030
}
@@ -34,7 +34,7 @@ impl TypeLocation {
3434
method_name,
3535
input_name,
3636
} => {
37-
let mut segments = vec![vec![method_name.as_str(), "Input", input_name.as_str()]];
37+
let mut segments = vec![vec![method_name.as_str(), "In", input_name.as_str()]];
3838
if let Some(path) = &self.path {
3939
segments.extend(path.to_type_naming_segments());
4040
}
@@ -44,7 +44,7 @@ impl TypeLocation {
4444
method_name,
4545
output_name,
4646
} => {
47-
let mut segments = vec![vec![method_name.as_str(), "Output", output_name.as_str()]];
47+
let mut segments = vec![vec![method_name.as_str(), "Out", output_name.as_str()]];
4848
if let Some(path) = &self.path {
4949
segments.extend(path.to_type_naming_segments());
5050
}
@@ -183,6 +183,7 @@ impl TypeLocationPath {
183183
if let Some(name) = name {
184184
subsegments.push(name.as_str());
185185
}
186+
subsegments.push("Ok");
186187
segments.push(subsegments);
187188
if let Some(inner) = inner {
188189
collect(segments, inner.as_ref());
@@ -196,6 +197,7 @@ impl TypeLocationPath {
196197
if let Some(name) = name {
197198
subsegments.push(name.as_str());
198199
}
200+
subsegments.push("Err");
199201
segments.push(subsegments);
200202
if let Some(inner) = inner {
201203
collect(segments, inner.as_ref());
@@ -370,3 +372,90 @@ impl Display for TypeLocationPath {
370372
Ok(())
371373
}
372374
}
375+
376+
#[cfg(test)]
377+
mod tests {
378+
use super::{TypeLocation, TypeLocationPath, TypeLocationRoot};
379+
use test_r::test;
380+
381+
#[test]
382+
fn root_segments_use_short_in_out_suffixes() {
383+
let constructor_in = TypeLocation {
384+
root: TypeLocationRoot::AgentConstructorInput {
385+
input_name: "payload".to_string(),
386+
},
387+
path: None,
388+
};
389+
assert_eq!(
390+
constructor_in.to_type_naming_segments(),
391+
vec![vec!["AgentParam", "payload"]]
392+
);
393+
394+
let method_in = TypeLocation {
395+
root: TypeLocationRoot::AgentMethodInput {
396+
method_name: "run".to_string(),
397+
input_name: "request".to_string(),
398+
},
399+
path: None,
400+
};
401+
assert_eq!(
402+
method_in.to_type_naming_segments(),
403+
vec![vec!["run", "In", "request"]]
404+
);
405+
406+
let method_out = TypeLocation {
407+
root: TypeLocationRoot::AgentMethodOutput {
408+
method_name: "run".to_string(),
409+
output_name: "response".to_string(),
410+
},
411+
path: None,
412+
};
413+
assert_eq!(
414+
method_out.to_type_naming_segments(),
415+
vec![vec!["run", "Out", "response"]]
416+
);
417+
}
418+
419+
#[test]
420+
fn result_path_segments_include_ok_and_err_markers() {
421+
let ok_location = TypeLocation {
422+
root: TypeLocationRoot::AgentMethodOutput {
423+
method_name: "run".to_string(),
424+
output_name: "response".to_string(),
425+
},
426+
path: Some(TypeLocationPath::ResultOk {
427+
name: Some("result".to_string()),
428+
owner: Some("my-owner".to_string()),
429+
inner: None,
430+
}),
431+
};
432+
433+
assert_eq!(
434+
ok_location.to_type_naming_segments(),
435+
vec![
436+
vec!["run", "Out", "response"],
437+
vec!["my-owner", "result", "Ok"]
438+
]
439+
);
440+
441+
let err_location = TypeLocation {
442+
root: TypeLocationRoot::AgentMethodOutput {
443+
method_name: "run".to_string(),
444+
output_name: "response".to_string(),
445+
},
446+
path: Some(TypeLocationPath::ResultErr {
447+
name: Some("result".to_string()),
448+
owner: Some("my-owner".to_string()),
449+
inner: None,
450+
}),
451+
};
452+
453+
assert_eq!(
454+
err_location.to_type_naming_segments(),
455+
vec![
456+
vec!["run", "Out", "response"],
457+
vec!["my-owner", "result", "Err"]
458+
]
459+
);
460+
}
461+
}

cli/golem-cli/src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,9 @@ impl HttpClientConfig {
386386
pub fn new_for_service_calls(allow_insecure: bool) -> Self {
387387
Self {
388388
allow_insecure,
389-
timeout: Some(Duration::from_secs(10)),
389+
timeout: Some(Duration::from_secs(120)),
390390
connect_timeout: Some(Duration::from_secs(10)),
391-
read_timeout: Some(Duration::from_secs(10)),
391+
read_timeout: Some(Duration::from_secs(60)),
392392
}
393393
.with_env_overrides("GOLEM_HTTP")
394394
}
@@ -416,7 +416,7 @@ impl HttpClientConfig {
416416
pub fn new_for_file_download(allow_insecure: bool) -> Self {
417417
Self {
418418
allow_insecure,
419-
timeout: Some(Duration::from_secs(60)),
419+
timeout: Some(Duration::from_secs(120)),
420420
connect_timeout: Some(Duration::from_secs(10)),
421421
read_timeout: Some(Duration::from_secs(60)),
422422
}

cli/golem-cli/src/context.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ impl Context {
325325
selected_context_logging: std::sync::OnceLock::new(),
326326
app_context_state: tokio::sync::RwLock::new(ApplicationContextState::new(
327327
yes,
328+
SHOULD_COLORIZE.should_colorize(),
328329
app_source_mode,
329330
)),
330331
caches: Caches::new(),
@@ -698,16 +699,18 @@ impl ApplicationContextConfig {
698699
#[derive()]
699700
pub struct ApplicationContextState {
700701
yes: bool,
702+
should_colorize: bool,
701703
app_source_mode: Option<ApplicationSourceMode>,
702704
pub silent_init: bool,
703705

704706
app_context: Option<Result<Option<ApplicationContext>, Arc<anyhow::Error>>>,
705707
}
706708

707709
impl ApplicationContextState {
708-
pub fn new(yes: bool, source_mode: ApplicationSourceMode) -> Self {
710+
pub fn new(yes: bool, should_colorize: bool, source_mode: ApplicationSourceMode) -> Self {
709711
Self {
710712
yes,
713+
should_colorize,
711714
app_source_mode: Some(source_mode),
712715
silent_init: false,
713716
app_context: None,
@@ -735,6 +738,7 @@ impl ApplicationContextState {
735738
let app_config = ApplicationConfig {
736739
offline: config.wasm_rpc_client_build_offline,
737740
dev_mode: config.dev_mode,
741+
should_colorize: self.should_colorize,
738742
enable_wasmtime_fs_cache: config.enable_wasmtime_fs_cache,
739743
};
740744

cli/golem-cli/src/evcxr_repl/repl.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,6 @@ impl Repl {
235235
}
236236

237237
fn run_interactive(&self, outputs: EvalContextOutputs) -> anyhow::Result<()> {
238-
let mut editor = Self::build_editor(self.command_context.clone(), self.cli_repl.clone())?;
239-
240-
let history_path = PathBuf::from(&self.config.base_config.history_file);
241-
editor.load_history(&history_path)?;
242-
243-
let buffered_output = BufferedEvalOutput::start(outputs.stdout, outputs.stderr);
244-
let mut printer = editor.create_external_printer()?;
245-
246238
let prompt = {
247239
if self.config.script_mode() {
248240
"".to_string()
@@ -258,6 +250,14 @@ impl Repl {
258250
}
259251
};
260252

253+
let mut editor = Self::build_editor(self.command_context.clone(), self.cli_repl.clone())?;
254+
255+
let history_path = PathBuf::from(&self.config.base_config.history_file);
256+
editor.load_history(&history_path)?;
257+
258+
let buffered_output = BufferedEvalOutput::start(outputs.stdout, outputs.stderr);
259+
let mut printer = editor.create_external_printer()?;
260+
261261
let mut interrupted = false;
262262
loop {
263263
let line = editor.readline(&prompt);
@@ -644,12 +644,9 @@ impl Completer for ReplRustyLineEditorHelper {
644644
return Ok((result.start, pairs));
645645
}
646646

647-
let completions = {
648-
let _spinner = SpinnerGuard::start_stdout("Completing...", true);
649-
match self.context.borrow_mut().completions(line, pos) {
650-
Ok(completions) => completions,
651-
Err(_) => return Ok((pos, Vec::new())),
652-
}
647+
let completions = match self.context.borrow_mut().completions(line, pos) {
648+
Ok(completions) => completions,
649+
Err(_) => return Ok((pos, Vec::new())),
653650
};
654651

655652
let mut candidates = Vec::with_capacity(completions.completions.len());

cli/golem-cli/src/model/app.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ impl BuildConfig {
106106
pub struct ApplicationConfig {
107107
pub offline: bool,
108108
pub dev_mode: bool,
109+
pub should_colorize: bool,
109110
pub enable_wasmtime_fs_cache: bool,
110111
}
111112

0 commit comments

Comments
 (0)