2024-05-13 13:37:53 +00:00
|
|
|
use crate::repl::tests::{fail_test, run_test, run_test_std, TestResult};
|
2022-12-12 18:46:25 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn mutate_nu_config() -> TestResult {
|
2023-11-04 20:18:57 +00:00
|
|
|
run_test_std(
|
2022-12-12 18:46:25 +00:00
|
|
|
r#"$env.config.footer_mode = 30; $env.config.footer_mode"#,
|
|
|
|
"30",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn mutate_nu_config_nested_ls() -> TestResult {
|
2023-11-04 20:18:57 +00:00
|
|
|
run_test_std(
|
|
|
|
r#"$env.config.ls.clickable_links = false; $env.config.ls.clickable_links"#,
|
2022-12-12 18:46:25 +00:00
|
|
|
"false",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn mutate_nu_config_nested_table() -> TestResult {
|
2023-11-04 20:18:57 +00:00
|
|
|
run_test_std(
|
|
|
|
r#"
|
2024-07-30 23:55:22 +00:00
|
|
|
$env.config.table.trim.methodology = 'wrapping'
|
2023-11-04 20:18:57 +00:00
|
|
|
$env.config.table.trim.wrapping_try_keep_words = false
|
|
|
|
$env.config.table.trim.wrapping_try_keep_words
|
|
|
|
"#,
|
2022-12-12 18:46:25 +00:00
|
|
|
"false",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn mutate_nu_config_nested_menu() -> TestResult {
|
2023-11-04 20:18:57 +00:00
|
|
|
run_test_std(
|
|
|
|
r#"
|
|
|
|
$env.config.menus = [
|
|
|
|
{
|
|
|
|
name: menu
|
|
|
|
only_buffer_difference: true
|
|
|
|
marker: "M "
|
|
|
|
type: {}
|
|
|
|
style: {}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
$env.config.menus.0.type.columns = 3;
|
|
|
|
$env.config.menus.0.type.columns
|
|
|
|
"#,
|
2022-12-12 18:46:25 +00:00
|
|
|
"3",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn mutate_nu_config_nested_keybindings() -> TestResult {
|
2023-11-04 20:18:57 +00:00
|
|
|
run_test_std(
|
|
|
|
r#"
|
|
|
|
$env.config.keybindings = [
|
|
|
|
{
|
|
|
|
name: completion_previous
|
|
|
|
modifier: shift
|
|
|
|
keycode: backtab
|
|
|
|
mode: [ vi_normal, vi_insert ]
|
|
|
|
event: { send: menuprevious }
|
|
|
|
}
|
|
|
|
];
|
|
|
|
$env.config.keybindings.0.keycode = 'char_x';
|
|
|
|
$env.config.keybindings.0.keycode
|
|
|
|
"#,
|
2022-12-12 18:46:25 +00:00
|
|
|
"char_x",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn mutate_nu_config_nested_color_nested() -> TestResult {
|
2023-11-04 20:18:57 +00:00
|
|
|
run_test_std(
|
2022-12-12 18:46:25 +00:00
|
|
|
r#"$env.config.color_config.shape_flag = 'cyan'; $env.config.color_config.shape_flag"#,
|
|
|
|
"cyan",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn mutate_nu_config_nested_completion() -> TestResult {
|
2023-11-04 20:18:57 +00:00
|
|
|
run_test_std(
|
2022-12-12 18:46:25 +00:00
|
|
|
r#"$env.config.completions.external.enable = false; $env.config.completions.external.enable"#,
|
|
|
|
"false",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn mutate_nu_config_nested_history() -> TestResult {
|
2023-11-04 20:18:57 +00:00
|
|
|
run_test_std(
|
2022-12-12 18:46:25 +00:00
|
|
|
r#"$env.config.history.max_size = 100; $env.config.history.max_size"#,
|
|
|
|
"100",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn mutate_nu_config_nested_filesize() -> TestResult {
|
2023-11-04 20:18:57 +00:00
|
|
|
run_test_std(
|
2022-12-12 18:46:25 +00:00
|
|
|
r#"$env.config.filesize.format = 'kb'; $env.config.filesize.format"#,
|
|
|
|
"kb",
|
|
|
|
)
|
|
|
|
}
|
2024-01-15 08:59:47 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn mutate_nu_config_plugin() -> TestResult {
|
|
|
|
run_test_std(
|
|
|
|
r#"
|
|
|
|
$env.config.plugins = {
|
|
|
|
config: {
|
|
|
|
key1: value
|
|
|
|
key2: other
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$env.config.plugins.config.key1 = 'updated'
|
|
|
|
$env.config.plugins.config.key1
|
|
|
|
"#,
|
|
|
|
"updated",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn reject_nu_config_plugin_non_record() -> TestResult {
|
2024-10-11 16:40:32 +00:00
|
|
|
fail_test(r#"$env.config.plugins = 5"#, "Type mismatch")
|
2024-01-15 08:59:47 +00:00
|
|
|
}
|
Keep plugins persistently running in the background (#12064)
# Description
This PR uses the new plugin protocol to intelligently keep plugin
processes running in the background for further plugin calls.
Running plugins can be seen by running the new `plugin list` command,
and stopped by running the new `plugin stop` command.
This is an enhancement for the performance of plugins, as starting new
plugin processes has overhead, especially for plugins in languages that
take a significant amount of time on startup. It also enables plugins
that have persistent state between commands, making the migration of
features like dataframes and `stor` to plugins possible.
Plugins are automatically stopped by the new plugin garbage collector,
configurable with `$env.config.plugin_gc`:
```nushell
$env.config.plugin_gc = {
# Configuration for plugin garbage collection
default: {
enabled: true # true to enable stopping of inactive plugins
stop_after: 10sec # how long to wait after a plugin is inactive to stop it
}
plugins: {
# alternate configuration for specific plugins, by name, for example:
#
# gstat: {
# enabled: false
# }
}
}
```
If garbage collection is enabled, plugins will be stopped after
`stop_after` passes after they were last active. Plugins are counted as
inactive if they have no running plugin calls. Reading the stream from
the response of a plugin call is still considered to be activity, but if
a plugin holds on to a stream but the call ends without an active
streaming response, it is not counted as active even if it is reading
it. Plugins can explicitly disable the GC as appropriate with
`engine.set_gc_disabled(true)`.
The `version` command now lists plugin names rather than plugin
commands. The list of plugin commands is accessible via `plugin list`.
Recommend doing this together with #12029, because it will likely force
plugin developers to do the right thing with mutability and lead to less
unexpected behavior when running plugins nested / in parallel.
# User-Facing Changes
- new command: `plugin list`
- new command: `plugin stop`
- changed command: `version` (now lists plugin names, rather than
commands)
- new config: `$env.config.plugin_gc`
- Plugins will keep running and be reused, at least for the configured
GC period
- Plugins that used mutable state in weird ways like `inc` did might
misbehave until fixed
- Plugins can disable GC if they need to
- Had to change plugin signature to accept `&EngineInterface` so that
the GC disable feature works. #12029 does this anyway, and I'm expecting
(resolvable) conflicts with that
# Tests + Formatting
- :green_circle: `toolkit fmt`
- :green_circle: `toolkit clippy`
- :green_circle: `toolkit test`
- :green_circle: `toolkit test stdlib`
Because there is some specific OS behavior required for plugins to not
respond to Ctrl-C directly, I've developed against and tested on both
Linux and Windows to ensure that works properly.
# After Submitting
I think this probably needs to be in the book somewhere
2024-03-09 23:10:22 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn mutate_nu_config_plugin_gc_default_enabled() -> TestResult {
|
|
|
|
run_test(
|
|
|
|
r#"
|
|
|
|
$env.config.plugin_gc.default.enabled = false
|
|
|
|
$env.config.plugin_gc.default.enabled
|
|
|
|
"#,
|
|
|
|
"false",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn mutate_nu_config_plugin_gc_default_stop_after() -> TestResult {
|
|
|
|
run_test(
|
|
|
|
r#"
|
|
|
|
$env.config.plugin_gc.default.stop_after = 20sec
|
|
|
|
$env.config.plugin_gc.default.stop_after
|
|
|
|
"#,
|
|
|
|
"20sec",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn mutate_nu_config_plugin_gc_default_stop_after_negative() -> TestResult {
|
|
|
|
fail_test(
|
|
|
|
r#"
|
|
|
|
$env.config.plugin_gc.default.stop_after = -1sec
|
|
|
|
$env.config.plugin_gc.default.stop_after
|
|
|
|
"#,
|
2024-10-11 16:40:32 +00:00
|
|
|
"expected a non-negative duration",
|
Keep plugins persistently running in the background (#12064)
# Description
This PR uses the new plugin protocol to intelligently keep plugin
processes running in the background for further plugin calls.
Running plugins can be seen by running the new `plugin list` command,
and stopped by running the new `plugin stop` command.
This is an enhancement for the performance of plugins, as starting new
plugin processes has overhead, especially for plugins in languages that
take a significant amount of time on startup. It also enables plugins
that have persistent state between commands, making the migration of
features like dataframes and `stor` to plugins possible.
Plugins are automatically stopped by the new plugin garbage collector,
configurable with `$env.config.plugin_gc`:
```nushell
$env.config.plugin_gc = {
# Configuration for plugin garbage collection
default: {
enabled: true # true to enable stopping of inactive plugins
stop_after: 10sec # how long to wait after a plugin is inactive to stop it
}
plugins: {
# alternate configuration for specific plugins, by name, for example:
#
# gstat: {
# enabled: false
# }
}
}
```
If garbage collection is enabled, plugins will be stopped after
`stop_after` passes after they were last active. Plugins are counted as
inactive if they have no running plugin calls. Reading the stream from
the response of a plugin call is still considered to be activity, but if
a plugin holds on to a stream but the call ends without an active
streaming response, it is not counted as active even if it is reading
it. Plugins can explicitly disable the GC as appropriate with
`engine.set_gc_disabled(true)`.
The `version` command now lists plugin names rather than plugin
commands. The list of plugin commands is accessible via `plugin list`.
Recommend doing this together with #12029, because it will likely force
plugin developers to do the right thing with mutability and lead to less
unexpected behavior when running plugins nested / in parallel.
# User-Facing Changes
- new command: `plugin list`
- new command: `plugin stop`
- changed command: `version` (now lists plugin names, rather than
commands)
- new config: `$env.config.plugin_gc`
- Plugins will keep running and be reused, at least for the configured
GC period
- Plugins that used mutable state in weird ways like `inc` did might
misbehave until fixed
- Plugins can disable GC if they need to
- Had to change plugin signature to accept `&EngineInterface` so that
the GC disable feature works. #12029 does this anyway, and I'm expecting
(resolvable) conflicts with that
# Tests + Formatting
- :green_circle: `toolkit fmt`
- :green_circle: `toolkit clippy`
- :green_circle: `toolkit test`
- :green_circle: `toolkit test stdlib`
Because there is some specific OS behavior required for plugins to not
respond to Ctrl-C directly, I've developed against and tested on both
Linux and Windows to ensure that works properly.
# After Submitting
I think this probably needs to be in the book somewhere
2024-03-09 23:10:22 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn mutate_nu_config_plugin_gc_plugins() -> TestResult {
|
|
|
|
run_test(
|
|
|
|
r#"
|
|
|
|
$env.config.plugin_gc.plugins.inc = {
|
|
|
|
enabled: true
|
|
|
|
stop_after: 0sec
|
|
|
|
}
|
|
|
|
$env.config.plugin_gc.plugins.inc.stop_after
|
|
|
|
"#,
|
|
|
|
"0sec",
|
|
|
|
)
|
|
|
|
}
|