fix(overlay): overlay use and overlay hide now update config state (#16154)

- fixes #5986
- fixes #7760
- fixes #8856
- fixes #10592
- fixes #11082

# Description
Unconditionally update the config state after each `overlay use` and
`overlay hide`.

The fix looks simple, but only because of the constant improvements and
refactors to the codebase that have taken place over time made it
possible.

Fixing these issue when they were initially filed would have been much
harder.

# User-Facing Changes
Overlays can add hooks, change color_config, update the config in
general.

# Tests + Formatting
No tests added as I still haven't figured out how to simulate the repl
in tests.

# After Submitting
N/A

---------

Co-authored-by: Bahex <17417311+Bahex@users.noreply.github.com>
This commit is contained in:
Bahex
2025-07-13 02:31:16 +03:00
committed by GitHub
parent f48656e18b
commit 60ca889443
3 changed files with 70 additions and 0 deletions

View File

@ -96,6 +96,7 @@ impl Command for OverlayHide {
for (name, val) in env_vars_to_keep { for (name, val) in env_vars_to_keep {
stack.add_env_var(name, val); stack.add_env_var(name, val);
} }
stack.update_config(engine_state)?;
Ok(PipelineData::empty()) Ok(PipelineData::empty())
} }

View File

@ -178,6 +178,7 @@ impl Command for OverlayUse {
} }
} else { } else {
caller_stack.add_overlay(overlay_name); caller_stack.add_overlay(overlay_name);
caller_stack.update_config(engine_state)?;
} }
Ok(PipelineData::empty()) Ok(PipelineData::empty())

View File

@ -918,6 +918,74 @@ fn overlay_use_export_env() {
assert_eq!(actual_repl.out, "foo"); assert_eq!(actual_repl.out, "foo");
} }
#[test]
fn overlay_use_export_env_config_affected() {
let inp = &[
"mut out = []",
"$env.config.filesize.unit = 'metric'",
"$out ++= [(20MB | into string)]",
"module spam { export-env { $env.config.filesize.unit = 'binary' } }",
"overlay use spam",
"$out ++= [(20MiB | into string)]",
r#"$out | to json --raw"#,
];
let actual = nu!(&inp.join("; "));
let actual_repl = nu!(nu_repl_code(inp));
assert_eq!(actual.out, r#"["20.0 MB","20.0 MiB"]"#);
assert_eq!(actual_repl.out, r#"["20.0 MB","20.0 MiB"]"#);
}
#[test]
fn overlay_hide_config_affected() {
let inp = &[
"mut out = []",
"$env.config.filesize.unit = 'metric'",
"$out ++= [(20MB | into string)]",
"module spam { export-env { $env.config.filesize.unit = 'binary' } }",
"overlay use spam",
"$out ++= [(20MiB | into string)]",
"overlay hide",
"$out ++= [(20MB | into string)]",
r#"$out | to json --raw"#,
];
// Can't hide overlay within the same source file
// let actual = nu!(&inp.join("; "));
let actual_repl = nu!(nu_repl_code(inp));
// assert_eq!(actual.out, r#"["20.0 MB","20.0 MiB","20.0 MB"]"#);
assert_eq!(actual_repl.out, r#"["20.0 MB","20.0 MiB","20.0 MB"]"#);
}
#[test]
fn overlay_use_after_hide_config_affected() {
let inp = &[
"mut out = []",
"$env.config.filesize.unit = 'metric'",
"$out ++= [(20MB | into string)]",
"module spam { export-env { $env.config.filesize.unit = 'binary' } }",
"overlay use spam",
"$out ++= [(20MiB | into string)]",
"overlay hide",
"$out ++= [(20MB | into string)]",
"overlay use spam",
"$out ++= [(20MiB | into string)]",
r#"$out | to json --raw"#,
];
// Can't hide overlay within the same source file
// let actual = nu!(&inp.join("; "));
let actual_repl = nu!(nu_repl_code(inp));
// assert_eq!(actual.out, r#"["20.0 MB","20.0 MiB","20.0 MB"]"#);
assert_eq!(
actual_repl.out,
r#"["20.0 MB","20.0 MiB","20.0 MB","20.0 MiB"]"#
);
}
#[test] #[test]
fn overlay_use_export_env_hide() { fn overlay_use_export_env_hide() {
let inp = &[ let inp = &[