From 153b81dfbd878fe7dd9c3d2d0778a689fd5b5974 Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Sat, 28 Nov 2026 09:28:23 +0100 Subject: [PATCH 1/5] Restore module records when an evaluation is rolled back Extra tags, enabled modulepaths and sourced shell scripts of loaded modules are recorded in memory structures that were not part of the settings pushed before an evaluation. When a module load fails, its evaluation is rolled back but these records are kept. If the same module is then successfully loaded, the properties saved for it in the loaded environment mix those of the failed attempt with those of the successful one. Save these structures along with the other settings, so a rollback restores them to their state prior the failed evaluation. Assisted-by: Claude:claude-fable-5-2 Signed-off-by: Xavier Delaruelle --- NEWS.rst | 3 ++ tcl/modeval.tcl | 3 +- testsuite/modulefiles.5/rbsh/1.0 | 7 ++++ testsuite/modulefiles.5/rbtag/1.0 | 3 ++ testsuite/modulefiles.5/rbuse/1.0 | 7 ++++ testsuite/modules.50-cmds/377-rollback.exp | 37 ++++++++++++++++++++++ 6 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 testsuite/modulefiles.5/rbsh/1.0 create mode 100644 testsuite/modulefiles.5/rbtag/1.0 create mode 100644 testsuite/modulefiles.5/rbuse/1.0 diff --git a/NEWS.rst b/NEWS.rst index 0422a08e7..30e3abf29 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -109,6 +109,9 @@ Modules 5.8.0 (not yet released) list. Requirements loaded then withdrawn by the failed attempt were considered still loaded. (fix issue #749 with contribution from Alexis Couture) +* Fix extra tags, enabled modulepaths and sourced shell scripts recorded for + a loaded module to exclude those set during a previous load attempt that + failed. .. _5.7 release notes: diff --git a/tcl/modeval.tcl b/tcl/modeval.tcl index 8f74533aa..d7dc72009 100644 --- a/tcl/modeval.tcl +++ b/tcl/modeval.tcl @@ -594,7 +594,8 @@ proc pushSettings {} { g_savedLoReqOfReloadMod g_savedLoReqOfUnloadMod g_savedPropsOfReloadMod\ g_loadedModulePrereqPath g_tagHash g_loadedByModroot g_modrootByLoaded\ g_loadedModulePosition g_modrootByLoadedConflict\ - g_loadedConflictByModroot g_loadRequirementModuleListMemCache} { + g_loadedConflictByModroot g_loadRequirementModuleListMemCache\ + g_extraTagHash g_loadedModuleSourceSh g_loadedModuleUse} { ##nagelfar ignore Suspicious variable name lappend save_array $var [array get ::$var] } diff --git a/testsuite/modulefiles.5/rbsh/1.0 b/testsuite/modulefiles.5/rbsh/1.0 new file mode 100644 index 000000000..bf9bea69c --- /dev/null +++ b/testsuite/modulefiles.5/rbsh/1.0 @@ -0,0 +1,7 @@ +#%Module +if {[is-loaded rbdep]} { + source-sh sh testsuite/example/mini-sh-to-mod.sh +} else { + source-sh sh testsuite/example/mini-sh-to-mod.sh arg + break +} diff --git a/testsuite/modulefiles.5/rbtag/1.0 b/testsuite/modulefiles.5/rbtag/1.0 new file mode 100644 index 000000000..01230557c --- /dev/null +++ b/testsuite/modulefiles.5/rbtag/1.0 @@ -0,0 +1,3 @@ +#%Module +prereq --tag=foo rbdep/1.0 +break diff --git a/testsuite/modulefiles.5/rbuse/1.0 b/testsuite/modulefiles.5/rbuse/1.0 new file mode 100644 index 000000000..32be33735 --- /dev/null +++ b/testsuite/modulefiles.5/rbuse/1.0 @@ -0,0 +1,7 @@ +#%Module +if {[is-loaded rbdep]} { + module use $env(TESTSUITEDIR)/modulefiles.path2 +} else { + module use $env(TESTSUITEDIR)/modulefiles.path1 + break +} diff --git a/testsuite/modules.50-cmds/377-rollback.exp b/testsuite/modules.50-cmds/377-rollback.exp index 13e785b70..b4916c3de 100644 --- a/testsuite/modules.50-cmds/377-rollback.exp +++ b/testsuite/modules.50-cmds/377-rollback.exp @@ -54,6 +54,43 @@ set tserr [msg_top_load rbapp/1.0 {} rblib/2.0 {}] testouterr_cmd bash {load rbapp/1.0} $ans $tserr +# extra tag set on a requirement loaded by a failed load attempt is not +# applied when this requirement is loaded afterward +setenv_loaded_module {} {} +set ans [list] +lappend ans [list set _LMFILES_ $mp/rbdep/1.0] +lappend ans [list set LOADEDMODULES rbdep/1.0] +lappend ans [list ERR] +set tserr [msg_load rbtag/1.0 $err_evalabort] +testouterr_cmd bash {load rbtag/1.0 rbdep/1.0} $ans $tserr + +# modulepath enabled by a failed load attempt is not recorded when module is +# loaded afterward +set ans [list] +lappend ans [list set __MODULES_LMUSE rbuse/1.0&$modpath.path2] +lappend ans [list set _LMFILES_ $mp/rbdep/1.0:$mp/rbuse/1.0] +lappend ans [list set LOADEDMODULES rbdep/1.0:rbuse/1.0] +lappend ans [list set MODULEPATH $modpath.path2:$mp] +lappend ans [list ERR] +set tserr [msg_load rbuse/1.0 $err_evalabort] +testouterr_cmd bash {load rbuse/1.0 rbdep/1.0 rbuse/1.0} $ans $tserr + +# script sourced by a failed load attempt is not recorded when module is +# loaded afterward +set ans [list] +lappend ans [list set FOOMINI value] +lappend ans [list set __MODULES_SHARE_FOOPATH :1] +lappend ans [list set FOOPATH /path/to/mini:] +lappend ans [list set __MODULES_LMREFRESH rbsh/1.0] +lappend ans [list set _LMFILES_ $mp/rbdep/1.0:$mp/rbsh/1.0] +lappend ans [list set LOADEDMODULES rbdep/1.0:rbsh/1.0] +lappend ans [list set __MODULES_LMSOURCESH rbsh/1.0\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\ \{\}\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value] +lappend ans [list alias almini {echo mini}] +lappend ans [list ERR] +set tserr [msg_load rbsh/1.0 $err_evalabort] +testouterr_cmd bash {load rbsh/1.0 rbdep/1.0 rbsh/1.0} $ans $tserr + + # # Cleanup # From 74e02551ff506d24ac08db77dcc8c569157158a5 Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Sat, 28 Nov 2026 09:28:44 +0100 Subject: [PATCH 2/5] Restore modulepath match caches when an evaluation is rolled back Result of the test checking that a loaded or loading module comes from a given modulepath is cached and this cache is only dropped when a module is unloaded. When the load of a module fails, the requirements it has loaded are withdrawn by a rollback and their cache entry is kept. If such requirement is then loaded from another modulepath, the outdated entry makes it satisfy a requirement targeting the first modulepath. Save these caches along with the other settings pushed before an evaluation, so a rollback restores them to their state prior the failed evaluation. Assisted-by: Claude:claude-fable-5-2 Signed-off-by: Xavier Delaruelle --- NEWS.rst | 2 ++ tcl/modeval.tcl | 4 +++- testsuite/modulefiles.5/rbpath/1.0 | 3 +++ testsuite/modulefiles.5/rbpathok/1.0 | 3 +++ testsuite/modules.50-cmds/377-rollback.exp | 10 ++++++++++ 5 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 testsuite/modulefiles.5/rbpath/1.0 create mode 100644 testsuite/modulefiles.5/rbpathok/1.0 diff --git a/NEWS.rst b/NEWS.rst index 30e3abf29..a2527b98f 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -112,6 +112,8 @@ Modules 5.8.0 (not yet released) * Fix extra tags, enabled modulepaths and sourced shell scripts recorded for a loaded module to exclude those set during a previous load attempt that failed. +* Fix check of the modulepath a loaded module comes from, when this module + was first loaded from another modulepath by a load attempt that failed. .. _5.7 release notes: diff --git a/tcl/modeval.tcl b/tcl/modeval.tcl index d7dc72009..2d24edec6 100644 --- a/tcl/modeval.tcl +++ b/tcl/modeval.tcl @@ -595,7 +595,9 @@ proc pushSettings {} { g_loadedModulePrereqPath g_tagHash g_loadedByModroot g_modrootByLoaded\ g_loadedModulePosition g_modrootByLoadedConflict\ g_loadedConflictByModroot g_loadRequirementModuleListMemCache\ - g_extraTagHash g_loadedModuleSourceSh g_loadedModuleUse} { + g_extraTagHash g_loadedModuleSourceSh g_loadedModuleUse\ + g_isLoadedMatchSpecificPathMemCache\ + g_isLoadingMatchSpecificPathMemCache} { ##nagelfar ignore Suspicious variable name lappend save_array $var [array get ::$var] } diff --git a/testsuite/modulefiles.5/rbpath/1.0 b/testsuite/modulefiles.5/rbpath/1.0 new file mode 100644 index 000000000..461deefd5 --- /dev/null +++ b/testsuite/modulefiles.5/rbpath/1.0 @@ -0,0 +1,3 @@ +#%Module +prereq --modulepath $env(TESTSUITEDIR)/modulefiles.path1 novercross +break diff --git a/testsuite/modulefiles.5/rbpathok/1.0 b/testsuite/modulefiles.5/rbpathok/1.0 new file mode 100644 index 000000000..d064f8152 --- /dev/null +++ b/testsuite/modulefiles.5/rbpathok/1.0 @@ -0,0 +1,3 @@ +#%Module +module load --not-req --modulepath $env(TESTSUITEDIR)/modulefiles.path2 novercross +prereq --modulepath $env(TESTSUITEDIR)/modulefiles.path1 novercross diff --git a/testsuite/modules.50-cmds/377-rollback.exp b/testsuite/modules.50-cmds/377-rollback.exp index b4916c3de..429f87c47 100644 --- a/testsuite/modules.50-cmds/377-rollback.exp +++ b/testsuite/modules.50-cmds/377-rollback.exp @@ -91,6 +91,16 @@ set tserr [msg_load rbsh/1.0 $err_evalabort] testouterr_cmd bash {load rbsh/1.0 rbdep/1.0 rbsh/1.0} $ans $tserr +# requirement loaded from a given modulepath by a failed load attempt, then +# loaded from another modulepath +setenv_path_var MODULEPATH $mp $modpath.path1 $modpath.path2 +set tserr [msg_load rbpath/1.0 $err_evalabort]\n\n +append tserr [msg_load novercross $err_modfromdiffpathloaded]\n\n +append tserr [msg_load rbpathok/1.0 [err_reqlo_path novercross]] +testouterr_cmd bash {load rbpath/1.0 rbpathok/1.0} ERR $tserr +setenv_path_var MODULEPATH $mp + + # # Cleanup # From f18a052355455600fb43a3ac6f39366cecf5baba Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Sat, 28 Nov 2026 09:31:02 +0100 Subject: [PATCH 3/5] Withdraw states of module command when it fails in modulefile The module modulefile command sets states describing the sub-command it runs: its name, the way modulefiles should be read and, when the --not-req option is set, the inhibition of requirement recording. These states were only withdrawn when the sub-command ended without error. When it raised an error, like for a module to load that cannot be found, the modulefile evaluation is aborted but these states stayed set for the modulefiles evaluated afterward. Among other effects, a module loaded with "module load --not-req" was kept loaded when the module that has loaded it got unloaded. Run the sub-command from a dedicated procedure, so the calling module procedure withdraws the states whatever the result obtained. Assisted-by: Claude:claude-fable-5-2 Signed-off-by: Xavier Delaruelle --- NEWS.rst | 4 ++++ tcl/mfcmd.tcl | 21 ++++++++++++++++++--- testsuite/modulefiles.5/rbgood/1.0 | 2 ++ testsuite/modulefiles.5/rbnr/1.0 | 2 ++ testsuite/modulefiles.5/rbun/1.0 | 2 ++ testsuite/modules.50-cmds/377-rollback.exp | 15 +++++++++++++++ 6 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 testsuite/modulefiles.5/rbgood/1.0 create mode 100644 testsuite/modulefiles.5/rbnr/1.0 create mode 100644 testsuite/modulefiles.5/rbun/1.0 diff --git a/NEWS.rst b/NEWS.rst index a2527b98f..1ea60de3d 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -114,6 +114,10 @@ Modules 5.8.0 (not yet released) failed. * Fix check of the modulepath a loaded module comes from, when this module was first loaded from another modulepath by a load attempt that failed. +* Fix :mfcmd:`module` modulefile command to clear its evaluation context + when the sub-command it runs fails. This context was affecting the + modulefiles evaluated afterward, for instance by keeping loaded the + modules a ``module load --not-req`` command should unload. .. _5.7 release notes: diff --git a/tcl/mfcmd.tcl b/tcl/mfcmd.tcl index df7961246..e73e754d6 100644 --- a/tcl/mfcmd.tcl +++ b/tcl/mfcmd.tcl @@ -2803,6 +2803,24 @@ proc module {command args} { list avail aliases edit spider]}] lappendState commandname $command + # withdraw states even if command fails, as after a failed modulefile + # evaluation other modulefiles may still be evaluated + set inhibit_req_depth [depthState inhibit_req_record] + set ret_code [catch {runModuleCommandFromModulefile $command {*}$args}\ + ret_val ret_opts] + + lpopState commandname + lpopState always_read_full_file + if {[depthState inhibit_req_record] > $inhibit_req_depth} { + lpopState inhibit_req_record + } + + return -options $ret_opts $ret_val +} + +# States relative to command should be set prior calling this procedure and +# withdrawn afterward by caller, as an error may be raised here. +proc runModuleCommandFromModulefile {command args} { # parse options, do that globally to ignore options not related to a given # module sub-command (exclude them from arg list) lassign [parseModuleCommandArgs 0 $command 0 0 {*}$args] show_oneperline\ @@ -2838,9 +2856,6 @@ proc module {command args} { $addpath_pos $show_oneperline $show_mtime $show_filter $search_filter\ $search_match $dump_state $parsed_args] - lpopState commandname - lpopState always_read_full_file - if {$inhibit_req} { lpopState inhibit_req_record } diff --git a/testsuite/modulefiles.5/rbgood/1.0 b/testsuite/modulefiles.5/rbgood/1.0 new file mode 100644 index 000000000..7171bc7e2 --- /dev/null +++ b/testsuite/modulefiles.5/rbgood/1.0 @@ -0,0 +1,2 @@ +#%Module +module load --not-req rbdep/1.0 diff --git a/testsuite/modulefiles.5/rbnr/1.0 b/testsuite/modulefiles.5/rbnr/1.0 new file mode 100644 index 000000000..02aadd1f3 --- /dev/null +++ b/testsuite/modulefiles.5/rbnr/1.0 @@ -0,0 +1,2 @@ +#%Module +module load --not-req rbunk diff --git a/testsuite/modulefiles.5/rbun/1.0 b/testsuite/modulefiles.5/rbun/1.0 new file mode 100644 index 000000000..297ce8841 --- /dev/null +++ b/testsuite/modulefiles.5/rbun/1.0 @@ -0,0 +1,2 @@ +#%Module +module unload rbgood diff --git a/testsuite/modules.50-cmds/377-rollback.exp b/testsuite/modules.50-cmds/377-rollback.exp index 429f87c47..9b3803473 100644 --- a/testsuite/modules.50-cmds/377-rollback.exp +++ b/testsuite/modules.50-cmds/377-rollback.exp @@ -101,6 +101,21 @@ testouterr_cmd bash {load rbpath/1.0 rbpathok/1.0} ERR $tserr setenv_path_var MODULEPATH $mp +# module command failing in a modulefile does not change the behavior of the +# module commands evaluated afterward: requirement loaded with --not-req +# option is unloaded with the module that has loaded it +setenv_loaded_module [list rbdep/1.0 rbgood/1.0] [list $mp/rbdep/1.0 $mp/rbgood/1.0] [list rbdep/1.0] +set ans [list] +lappend ans [list set __MODULES_LMCONFLICT rbun/1.0&rbgood] +lappend ans [list set _LMFILES_ $mp/rbun/1.0] +lappend ans [list set LOADEDMODULES rbun/1.0] +lappend ans [list unset __MODULES_LMTAG] +lappend ans [list ERR] +set tserr [msg_load rbnr/1.0 $err_path'rbunk' [err_reqlo rbunk]]\n\n +append tserr [msg_top_load_conun rbun/1.0 {} rbgood/1.0 rbdep/1.0 {} {}] +testouterr_cmd bash {load rbnr/1.0 rbun/1.0} $ans $tserr + + # # Cleanup # From 1d6b1cc81fc59692edc8f6e1e6f63de6925eb6e1 Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Sat, 28 Nov 2026 09:37:03 +0100 Subject: [PATCH 4/5] Fix record of modulepath restrictions set on several prereqs Modulepath restrictions set with the --modulepath option of prereq are recorded per module as a list of requirement and modulepath list pairs. New pairs were added to this list element by element, skipping those already found in it. A second requirement restricted to the same modulepath, or the same requirement defined again with another restriction, thus led to an unbalanced list and to an internal error when the dependencies of the loading module were computed. Record these restrictions pair by pair. When a requirement is defined several times, the modulepaths common to its definitions are retained, as a loaded module has to comply with all of them. Definitions without any modulepath in common can never be fulfilled and make the load fail. Latest definition is recorded in this case, so the requirement is reported unmet if load is forced. Assisted-by: Claude:claude-fable-5-2 Signed-off-by: Xavier Delaruelle --- NEWS.rst | 4 + tcl/modfind.tcl.in | 17 ++- testsuite/modulefiles.5/pathdup/1.0 | 3 + testsuite/modulefiles.5/pathdup/2.0 | 3 + testsuite/modulefiles.5/pathdup/3.0 | 3 + testsuite/modulefiles.5/pathdup/4.0 | 3 + .../modules.50-cmds/642-modulepath-multi.exp | 103 ++++++++++++++++++ 7 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 testsuite/modulefiles.5/pathdup/1.0 create mode 100644 testsuite/modulefiles.5/pathdup/2.0 create mode 100644 testsuite/modulefiles.5/pathdup/3.0 create mode 100644 testsuite/modulefiles.5/pathdup/4.0 create mode 100644 testsuite/modules.50-cmds/642-modulepath-multi.exp diff --git a/NEWS.rst b/NEWS.rst index 1ea60de3d..c382f7c6a 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -118,6 +118,10 @@ Modules 5.8.0 (not yet released) when the sub-command it runs fails. This context was affecting the modulefiles evaluated afterward, for instance by keeping loaded the modules a ``module load --not-req`` command should unload. +* Fix internal error raised when loading a modulefile that defines with + :mfcmd:`prereq` several requirements restricted to the same modulepath with + the ``--modulepath`` option, or that defines the same requirement several + times with different modulepath restrictions. .. _5.7 release notes: diff --git a/tcl/modfind.tcl.in b/tcl/modfind.tcl.in index 1c5ad07a2..13c9ce2ce 100644 --- a/tcl/modfind.tcl.in +++ b/tcl/modfind.tcl.in @@ -1864,8 +1864,23 @@ proc getLoadedPrereq {mod} { } } +# Record the modulepaths each prereq of mod is restricted to. args is a list +# of prereq and modulepath list pairs. proc setLoadedPrereqPath {mod args} { - lappendNoDup ::g_loadedModulePrereqPath($mod) {*}$args + foreach {prereq modulepath_list} $args { + # prereq defined several times has to comply with all its definitions. + # Without any modulepath in common it can never be fulfilled: latest + # definition is recorded to get it reported as unmet if load is forced. + if {[info exists ::g_loadedModulePrereqPath($mod)] && [dict exists\ + $::g_loadedModulePrereqPath($mod) $prereq]} { + set common_list [getIntersectBetweenList [dict get\ + $::g_loadedModulePrereqPath($mod) $prereq] $modulepath_list] + if {[llength $common_list]} { + set modulepath_list $common_list + } + } + dict set ::g_loadedModulePrereqPath($mod) $prereq $modulepath_list + } } proc unsetLoadedPrereqPath {mod} { diff --git a/testsuite/modulefiles.5/pathdup/1.0 b/testsuite/modulefiles.5/pathdup/1.0 new file mode 100644 index 000000000..f6e90b05a --- /dev/null +++ b/testsuite/modulefiles.5/pathdup/1.0 @@ -0,0 +1,3 @@ +#%Module +prereq --modulepath $env(TESTSUITEDIR)/modulefiles.5 rbdep/1.0 +prereq --modulepath $env(TESTSUITEDIR)/modulefiles.5 rblib/2.0 diff --git a/testsuite/modulefiles.5/pathdup/2.0 b/testsuite/modulefiles.5/pathdup/2.0 new file mode 100644 index 000000000..05163e2d9 --- /dev/null +++ b/testsuite/modulefiles.5/pathdup/2.0 @@ -0,0 +1,3 @@ +#%Module +prereq --modulepath $env(TESTSUITEDIR)/modulefiles.5 rbdep/1.0 +prereq --modulepath $env(TESTSUITEDIR)/modulefiles.5:$env(TESTSUITEDIR)/modulefiles.path1 rbdep/1.0 diff --git a/testsuite/modulefiles.5/pathdup/3.0 b/testsuite/modulefiles.5/pathdup/3.0 new file mode 100644 index 000000000..e47c1d1db --- /dev/null +++ b/testsuite/modulefiles.5/pathdup/3.0 @@ -0,0 +1,3 @@ +#%Module +prereq --modulepath $env(TESTSUITEDIR)/modulefiles.path1:$env(TESTSUITEDIR)/modulefiles.5 rbdep/1.0 +prereq --modulepath $env(TESTSUITEDIR)/modulefiles.5 rbdep/1.0 diff --git a/testsuite/modulefiles.5/pathdup/4.0 b/testsuite/modulefiles.5/pathdup/4.0 new file mode 100644 index 000000000..fad076ebd --- /dev/null +++ b/testsuite/modulefiles.5/pathdup/4.0 @@ -0,0 +1,3 @@ +#%Module +prereq --modulepath $env(TESTSUITEDIR)/modulefiles.5 rbdep/1.0 +prereq --modulepath $env(TESTSUITEDIR)/modulefiles.path1 rbdep/1.0 diff --git a/testsuite/modules.50-cmds/642-modulepath-multi.exp b/testsuite/modules.50-cmds/642-modulepath-multi.exp new file mode 100644 index 000000000..22315c763 --- /dev/null +++ b/testsuite/modules.50-cmds/642-modulepath-multi.exp @@ -0,0 +1,103 @@ +############################################################################## +# Modules Revision 3.0 +# Providing a flexible user environment +# +# File: modules.50-cmds/%M% +# Revision: %I% +# First Edition: 2026/11/28 +# Last Mod.: %U%, %G% +# +# Authors: Xavier Delaruelle, xavier.delaruelle@cea.fr +# +# Description: Testuite testsequence +# Command: load, unload +# Modulefiles: pathdup, rbdep, rblib +# Sub-Command: +# +# Comment: %C{ +# Test --modulepath option of prereq modulefile command when +# set on several requirements of the same modulefile +# }C% +# +############################################################################## + +# enable auto_handling with environment variable +setenv_var MODULES_AUTO_HANDLING 1 + +# ensure auto symbolic versions are not set for these tests +setenv_var MODULES_ADVANCED_VERSION_SPEC 0 + +set mp $modpath.5 +setenv_path_var MODULEPATH $mp $modpath.path1 + +setenv_loaded_module {} {} + + +# different requirements restricted to the same modulepath +set ans [list] +lappend ans [list set __MODULES_LMPREREQ rblib/2.0&rbdep/1.0:pathdup/1.0&rbdep/1.0&rblib/2.0] +lappend ans [list set _LMFILES_ $mp/rbdep/1.0:$mp/rblib/2.0:$mp/pathdup/1.0] +lappend ans [list set LOADEDMODULES rbdep/1.0:rblib/2.0:pathdup/1.0] +lappend ans [list set __MODULES_LMPREREQPATH pathdup/1.0&rbdep/1.0&$mp&rblib/2.0&$mp] +lappend ans [list set __MODULES_LMTAG rbdep/1.0&auto-loaded:rblib/2.0&auto-loaded] +set tserr [msg_top_load pathdup/1.0 {} {rbdep/1.0 rblib/2.0} {}] +testouterr_cmd bash {load pathdup/1.0} $ans $tserr + +setenv_loaded_module [list rbdep/1.0 rblib/2.0 pathdup/1.0] [list $mp/rbdep/1.0 $mp/rblib/2.0 $mp/pathdup/1.0] [list rbdep/1.0 rblib/2.0] +setenv_var __MODULES_LMPREREQ rblib/2.0&rbdep/1.0:pathdup/1.0&rbdep/1.0&rblib/2.0 +setenv_var __MODULES_LMPREREQPATH pathdup/1.0&rbdep/1.0&$mp&rblib/2.0&$mp +set ans [list] +lappend ans [list unset __MODULES_LMPREREQ] +lappend ans [list unset _LMFILES_] +lappend ans [list unset LOADEDMODULES] +lappend ans [list unset __MODULES_LMTAG] +lappend ans [list unset __MODULES_LMPREREQPATH] +set tserr [msg_top_unload pathdup/1.0 {} {rblib/2.0 rbdep/1.0} {}] +testouterr_cmd bash {unload pathdup/1.0} $ans $tserr + +setenv_loaded_module {} {} +unsetenv_var __MODULES_LMPREREQ +unsetenv_var __MODULES_LMPREREQPATH + +# same requirement defined twice with different modulepath restrictions: +# modulepaths common to both definitions are retained +set ans [list] +lappend ans [list set __MODULES_LMPREREQ pathdup/2.0&rbdep/1.0] +lappend ans [list set _LMFILES_ $mp/rbdep/1.0:$mp/pathdup/2.0] +lappend ans [list set LOADEDMODULES rbdep/1.0:pathdup/2.0] +lappend ans [list set __MODULES_LMPREREQPATH pathdup/2.0&rbdep/1.0&$mp] +lappend ans [list set __MODULES_LMTAG rbdep/1.0&auto-loaded] +set tserr [msg_top_load pathdup/2.0 {} rbdep/1.0 {}] +testouterr_cmd bash {load pathdup/2.0} $ans $tserr + +set ans [list] +lappend ans [list set __MODULES_LMPREREQ pathdup/3.0&rbdep/1.0] +lappend ans [list set _LMFILES_ $mp/rbdep/1.0:$mp/pathdup/3.0] +lappend ans [list set LOADEDMODULES rbdep/1.0:pathdup/3.0] +lappend ans [list set __MODULES_LMPREREQPATH pathdup/3.0&rbdep/1.0&$mp] +lappend ans [list set __MODULES_LMTAG rbdep/1.0&auto-loaded] +set tserr [msg_top_load pathdup/3.0 {} rbdep/1.0 {}] +testouterr_cmd bash {load pathdup/3.0} $ans $tserr + +# no modulepath in common between both definitions: requirement cannot be +# fulfilled +set tserr [msg_load pathdup/4.0 $err_path'rbdep/1.0' [err_prereq_path rbdep/1.0]] +testouterr_cmd bash {load pathdup/4.0} ERR $tserr + +# latest definition is recorded when load is forced +set ans [list] +lappend ans [list set __MODULES_LMPREREQ pathdup/4.0&rbdep/1.0] +lappend ans [list set _LMFILES_ $mp/rbdep/1.0:$mp/pathdup/4.0] +lappend ans [list set LOADEDMODULES rbdep/1.0:pathdup/4.0] +lappend ans [list set __MODULES_LMPREREQPATH pathdup/4.0&rbdep/1.0&$modpath.path1] +lappend ans [list set __MODULES_LMTAG rbdep/1.0&auto-loaded] +lappend ans [list ERR] +set tserr [msg_top_load pathdup/4.0 {} rbdep/1.0 {} $err_path'rbdep/1.0' [err_reqmisf_path rbdep/1.0]] +testouterr_cmd bash {load --force pathdup/4.0} $ans $tserr + + +# +# Cleanup +# + +reset_test_env From 8696247b2379c1c236621aebbee2ae6e1a3c7e36 Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Sat, 28 Nov 2026 14:20:36 +0100 Subject: [PATCH 5/5] ts: adapt modulepath rollback test to conflict_unload option When conflict_unload option is enabled, a requirement loaded from another modulepath than the one expected is unloaded and replaced instead of making the load fail. Assisted-by: Claude:claude-fable-5-2 Signed-off-by: Xavier Delaruelle --- testsuite/modules.50-cmds/377-rollback.exp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/testsuite/modules.50-cmds/377-rollback.exp b/testsuite/modules.50-cmds/377-rollback.exp index 9b3803473..4e49bd03f 100644 --- a/testsuite/modules.50-cmds/377-rollback.exp +++ b/testsuite/modules.50-cmds/377-rollback.exp @@ -95,9 +95,23 @@ testouterr_cmd bash {load rbsh/1.0 rbdep/1.0 rbsh/1.0} $ans $tserr # loaded from another modulepath setenv_path_var MODULEPATH $mp $modpath.path1 $modpath.path2 set tserr [msg_load rbpath/1.0 $err_evalabort]\n\n -append tserr [msg_load novercross $err_modfromdiffpathloaded]\n\n -append tserr [msg_load rbpathok/1.0 [err_reqlo_path novercross]] -testouterr_cmd bash {load rbpath/1.0 rbpathok/1.0} ERR $tserr +if {[is_conf_enabled conflictunload]} { + # requirement loaded from the other modulepath is replaced + set ans [list] + lappend ans [list set __MODULES_LMPREREQ rbpathok/1.0&novercross] + lappend ans [list set _LMFILES_ $modpath.path1/novercross:$mp/rbpathok/1.0] + lappend ans [list set LOADEDMODULES novercross:rbpathok/1.0] + lappend ans [list set testsuite yes] + lappend ans [list set __MODULES_LMPREREQPATH rbpathok/1.0&novercross&$modpath.path1] + lappend ans [list set __MODULES_LMTAG novercross&auto-loaded] + lappend ans [list ERR] + append tserr [msg_load rbpathok/1.0 {Loading requirement: novercross novercross} {Unloading conflict: novercross}] +} else { + set ans ERR + append tserr [msg_load novercross $err_modfromdiffpathloaded]\n\n + append tserr [msg_load rbpathok/1.0 [err_reqlo_path novercross]] +} +testouterr_cmd bash {load rbpath/1.0 rbpathok/1.0} $ans $tserr setenv_path_var MODULEPATH $mp