############################################################################## # Modules Revision 3.0 # Providing a flexible user environment # # File: completion.00-init/%M% # Revision: %I% # First Edition: 2026/08/12 # Last Mod.: %U%, %G% # # Authors: Xavier Delaruelle, xavier.delaruelle@cea.fr # # Description: Testuite testsequence # Command: avail, load, unload, ml, use, unuse, restore # Sub-Command: # # Comment: %C{ # Check tcsh Tab completion: mirrors 021-bash.exp (see # that file for the full rationale of each check) as # closely as tcsh's own completion script allows -- every # completion_bash_* call replaced by its completion_tcsh_* # counterpart -- since init/tcsh_completion.in gates its # option flags per sub-command via the same shared # @comp_*_opts@ token lists bash's own script is built # from (see init/Makefile), every per-sub-command # ground-truth section bash has is kept here too, unlike # 031-zsh.exp/041-fish.exp. The few genuine deviations # from bash, all driven by init/tcsh_completion.in itself # or by tcsh's own line editor (see 050-tcsh-procs.exp's # header for the latter), are noted where they occur: # - "bar" uniquely matching the "bar/" module category # still rings a bell on completion: tcsh has no # equivalent of bash's 'compopt -o nospace' exception # that stays silent right at a directory-style '/' # boundary even though the match remains ambiguous # beyond it (see 050-tcsh-procs.exp's header) # - unlike bash/zsh's own completion scripts, the # aliases in init/tcsh_completion.in (_module_avail, # ...) never collapse every module sharing a name into # one directory-style "name/" candidate of their own: # Ctrl-D's listing always shows the flat 'name/version' # strings modulecmd.tcl produced, so every listing # check in this file looks for those instead of the # "name/" category entries 021-bash.exp checks for. A # single Tab's own common-prefix computation can still # land exactly on a "/" boundary and insert it (eg the # "bar" case above) -- that is a computed common # prefix, not a distinct listed candidate, so it is # unaffected by this # - 'ml' has a far sparser 'complete' registration of its # own than 'module' does: no global switches at all for # a bare 'ml' (no '-h'/'--help'/'-D', unlike bash), and # 'ml -' offers only the loaded-module unload # shortcuts ('-name', via a dedicated 'c/-/.../' rule) # -- not also 'load's own option flags the way bash # mixes in there. This file's 'ml' section is pared # down to just the checks that still apply # - 'unuse' is only usable from a bare, empty word: every # modulepath in this fixture is an absolute path, and # the moment the word being completed starts with '/' # it matches init/tcsh_completion.in's own unconditional # 'C,/*,f,' rule (plain filename completion for any # word starting with '/'), which is declared ahead of # the 'unuse'-specific 'n/unuse/`_module_modulepath`/' # rule and wins over it -- so, unlike bash, this file # cannot narrow the listing by prefix or check the # single-remaining-modulepath inline-completion case # - 'use' and 'source' each document an option flag or # two in their usage synopsis ('-a'/'-p'; # '--auto'/'--no-auto'/'-f'), but init/tcsh_completion.in # never wires any @comp_*_opts@ macro into their own # rule the way every other option-bearing sub-command's # rule does -- so, like 'ml'/'unuse' above, the # per-sub-command option ground-truth section below # treats these two as if they took no option at all # ('help' had the same gap -- no '@comp_mfile_opts@' in # its own rule despite documenting '-i' -- fixed # directly in init/tcsh_completion.in rather than # worked around here, since 'help' otherwise dispatches # exactly like 'show'/'display'/'test'/... which all # already carry that macro) # # Also checks, like 021-bash.exp/031-zsh.exp, that a # candidate word built from untrusted text (a module # name, LOADEDMODULES, MODULEPATH) cannot reach a shell # expansion step: init/tcsh_completion.in only ever hands # such text to a plain 'n/.../`...`/' backtick rule, where # each output line becomes a literal candidate string, so # this is expected to already be safe -- these cases guard # against a regression, not a known vulnerability. The # MODULEPATH case uses a bare 'module unuse ' (no typed # prefix), same restriction as this file's own 'unuse' # section above # }C% # ############################################################################## # # module names and option flags both get listed on Tab completion # setenv_path_var MODULEPATH $modpath completion_tcsh_start ## unlike bash/zsh's own completion scripts, init/tcsh_completion.in's ## aliases (_module_avail, ...) do not collapse every module sharing a name ## into one directory-style "name/" candidate -- Ctrl-D's listing shows ## exactly the flat 'name/version' strings modulecmd.tcl produced, so this ## file checks for those instead of the "name/" category entries ## 021-bash.exp looks for (a single Tab's own common-prefix computation can ## still land exactly on a "/" boundary, see the "bar" case further below -- ## that is a computed common prefix, not a distinct listed candidate) set got [completion_tcsh_list {module avail }] completion_assert_contains $got {advvers/1.0 bar/1.0 baz/1.0 foo/1.0} completion_assert_contains $got {--all --icase --terse} set got [completion_tcsh_list {module load }] completion_assert_contains $got {advvers/1.0 bar/1.0 baz/1.0 foo/1.0} completion_assert_contains $got {--force -f --icase} ## "ba" is the common prefix of bar/ and baz/: a single Tab from "b" must ## auto-insert the "a" inline, with a bell right before it since bar/baz ## still leave the completion ambiguous beyond it set got [completion_tcsh_inline {module load b}] completion_assert_eq $got "\aa" ## from "ba", nothing more can be auto-inserted (bar/baz diverge right ## there): Ctrl-D must list every flat module matching that prefix (see ## this section's opening comment on why these are not "bar/"/"baz/" ## category entries) set got [completion_tcsh_list {module load ba}] completion_assert_contains $got {bar/1.0 bar/2.0 baz/1.0 baz/2.0} completion_assert_not_contains $got {foo/1.0 advvers/1.0} ## "bar" uniquely matches the "bar/" module category: a single Tab must ## complete it inline with a trailing '/' and no trailing space (so typing ## can continue straight into a version) -- but, unlike bash, still with a ## leading bell, since tcsh has no exception for a directory-style boundary ## that remains ambiguous beyond it (see this file's header) set got [completion_tcsh_inline {module load bar}] completion_assert_eq $got "\a/" ## from "bar/", Ctrl-D must list the versions available under it set got [completion_tcsh_list {module load bar/}] completion_assert_contains $got {bar/1.0 bar/2.0} ## "flatlcompat" is a single, versionless module (no further completion ## possible beneath it, so unlike "bar" above it does not end in '/'): a ## single Tab must complete it inline, with a trailing space since it is ## not a directory-style entry, and no bell since it is genuinely unique set got [completion_tcsh_inline {module load fl}] completion_assert_eq $got {atlcompat } completion_tcsh_close # # 'unload' lists the currently loaded modules alongside the option flags, # and lists/completes them on the typed prefix like any other candidate list # setenv_loaded_module [list bar/1.0 baz/1.0 foo/1.0]\ [list $modpath/bar/1.0 $modpath/baz/1.0 $modpath/foo/1.0] completion_tcsh_start set got [completion_tcsh_list {module unload }] completion_assert_contains $got {bar/1.0 baz/1.0 foo/1.0 --force -f --icase} ## "ba" is the common prefix of bar/1.0 and baz/1.0: a single Tab from "b" ## must auto-insert the "a" inline, with a bell right before it since ## bar/1.0 and baz/1.0 still leave the completion ambiguous beyond it set got [completion_tcsh_inline {module unload b}] completion_assert_eq $got "\aa" ## from "ba", nothing more can be auto-inserted (bar/1.0 and baz/1.0 ## diverge right there), so Ctrl-D must list just the two matching loaded ## modules, not foo/1.0 set got [completion_tcsh_list {module unload ba}] completion_assert_contains $got {bar/1.0 baz/1.0} completion_assert_not_contains $got {foo/1.0} ## "foo/1.0" is the only loaded module starting with "f", and no option ## flag does either: a single Tab must complete the rest of it inline, ## with a trailing space since a loaded-module candidate is not a ## directory-style entry, and no bell since it is genuinely unique set got [completion_tcsh_inline {module unload f}] completion_assert_eq $got {oo/1.0 } completion_tcsh_close unsetenv_loaded_module # # 'ml' mirrors 'module load' completion for the bare sub-command case, but # (unlike bash) proposes no global switches at all alongside the module # names, and (once an option flag is being typed) offers only the "-" # unload shortcut for each currently loaded module -- not also 'load's own # option flags (see this file's header) # setenv_path_var MODULEPATH $modpath completion_tcsh_start set got [completion_tcsh_list {ml }] completion_assert_contains $got {advvers/1.0 bar/1.0 baz/1.0 foo/1.0} completion_assert_not_contains $got {-h --help -D} completion_tcsh_raw {module load bar} ## with bar/2.0 loaded (the default version, no .version file pins it), a ## "bar/2.0" candidate must appear -- and, unlike bash, nothing else. The ## listing itself drops the leading "-" the 'c/-/.../' rule matched on (it ## is only the single-Tab *insertion* below that appends the suffix right ## after the "-" already typed on the line, making the result look like ## "-bar/2.0" there) set got [completion_tcsh_list {ml -}] completion_assert_contains $got {bar/2.0} completion_assert_not_contains $got {--force -f --icase} ## "-bar/2.0" is the only candidate starting with "-ba": a single Tab must ## complete the rest of it inline, with a trailing space since it is not a ## directory-style entry, and no bell since it is genuinely unique set got [completion_tcsh_inline {ml -ba}] completion_assert_eq $got {r/2.0 } completion_tcsh_close # # 'use' completes a filesystem directory path: init/tcsh_completion.in # registers it as directory-only completion ('n/use/d/'), and the # unconditional 'C,/*,f,' rule (see this file's header) reaches the same # filesystem entry regardless for this fixture's absolute path, so either # way this behaves like plain directory completion # set usedir "$env(TESTSUITEDIR)/completion-use-fixture" file delete -force $usedir file mkdir $usedir completion_tcsh_start ## drop the last 3 characters of the fixture dir name ("ure"): a single Tab ## must complete them back plus a trailing '/', with no trailing space and ## no bell, exactly like the "flatlcompat" case above -- the match is ## genuinely unique, so unlike the "bar" -> "bar/" case earlier there is no ## further ambiguity beyond the boundary for tcsh to bell about set got [completion_tcsh_inline "module use [string range $usedir 0 end-3]"] completion_assert_eq $got {ure/} completion_tcsh_close file delete -force $usedir # # 'unuse' lists the currently enabled modulepaths, but (unlike bash) only # from a bare, empty word -- typing any prefix at all trips the '/' # filename-completion catch-all before it ever reaches the modulepath list # (see this file's header), so this section, unlike 031-zsh.exp's own # 'unuse' checks, cannot narrow by prefix or exercise the single-remaining- # modulepath inline-completion case # setenv_path_var MODULEPATH $modpath "$env(TESTSUITEDIR)/modulefiles.4" /tmp completion_tcsh_start set got [completion_tcsh_list {module unuse }] completion_assert_contains $got [list $modpath "$env(TESTSUITEDIR)/modulefiles.4" /tmp] completion_tcsh_close # # 'restore' lists the saved collections, and filters them on the typed # prefix like any other candidate list # setenv_path_var MODULEPATH $modpath completion_tcsh_start completion_tcsh_raw {module save foo} completion_tcsh_raw {module save fox} completion_tcsh_raw {module save bar1} set got [completion_tcsh_list {module restore }] completion_assert_contains $got {foo fox bar1} ## "fo" is the common prefix of foo/fox: a single Tab from "f" must ## auto-insert the "o" inline, with a bell right before it since foo/fox ## still leave the completion ambiguous beyond it set got [completion_tcsh_inline {module restore f}] completion_assert_eq $got "\ao" ## from "fo", nothing more can be auto-inserted (foo/fox diverge right ## there), so Ctrl-D must list just the two matching collections set got [completion_tcsh_list {module restore fo}] completion_assert_contains $got {foo fox} completion_assert_not_contains $got {bar1} ## "bar1" is the only collection starting with "ba": a single Tab must ## complete the rest of it inline, with a trailing space since a ## collection candidate is not a directory-style entry, and no bell since ## it is genuinely unique set got [completion_tcsh_inline {module restore ba}] completion_assert_eq $got {r1 } completion_tcsh_close # # ground-truth check against 'module help' (see completion.00-init/ # 007-module_help.exp): a bare 'module ' must propose exactly the # documented sub-commands plus the global switches, and 'module -' # (isolating the switches from the sub-command names) must propose exactly # the documented switches # setenv_path_var MODULEPATH $modpath completion_tcsh_start set got [completion_tcsh_list {module }] set got_subcmds [lsearch -all -inline -not -regexp $got {^-}] completion_assert_contains $got_subcmds $help_subcmds completion_assert_only_known $got_subcmds {*} $help_subcmds set got [completion_tcsh_list {module -}] completion_assert_contains $got $help_switches completion_assert_only_known $got {-*} $help_switches completion_tcsh_close # # ground-truth check, per sub-command: 'module -' must # propose exactly the option flags 'module help' documents for that # sub-command -- including none at all, for a sub-command that takes no # option # ## typing '-' first, rather than a bare trailing space, matters for the ## same reason it does in 021-bash.exp: every option-bearing sub-command's ## own completion helper skips looking up real module/collection/modulepath ## candidates once the word being completed starts with '-', isolating the ## option flags on their own -- unlike bash/zsh, though, this needs no ## special-casing for 'config's own further '-' -> '--' auto-extension, ## since completion_tcsh_list's Ctrl-D never extends the typed word at all ## (see 050-tcsh-procs.exp's header) ## ## two further sub-commands, beyond 'ml'/'unuse' already noted in this ## file's header, turn out to have a gap of their own here: 'use' ## ('n/use/d/'/'N/use/d/') and 'source' ('n/source/f/') each document an ## option flag or two in their usage synopsis ('-a'/'-p'; ## '--auto'/'--no-auto'/'-f'), but their init/tcsh_completion.in rule never ## concatenates any @comp_*_opts@ macro the way every other option-bearing ## sub-command's rule does -- so these two are treated the same as a ## genuinely option-less sub-command below, overriding whatever ## 'module help' itself documents for them ('help' had the same gap, fixed ## directly in init/tcsh_completion.in instead, see this file's header) set tcsh_no_opt_subcmds {use source} setenv_path_var MODULEPATH $modpath completion_tcsh_start foreach subcmd $help_subcmds { set expected {} if {[info exists help_subcmd_opts($subcmd)] && $subcmd ni $tcsh_no_opt_subcmds} { set expected $help_subcmd_opts($subcmd) } if {[llength $expected] == 0} { ## nothing is expected to complete at all: a single Tab must insert ## nothing but a bell (not even a directory-style default-completion ## fallback match, since no file in the test run's working directory ## starts with '-') -- tcsh rings the bell on any Tab that finds zero ## completions, not just an ambiguous one set got [completion_tcsh_inline "module $subcmd -"] completion_assert_eq $got "\a" } else { set got [completion_tcsh_list "module $subcmd -"] completion_assert_contains $got $expected completion_assert_only_known $got {-*} $expected } } completion_tcsh_close # # same ground truth, this time against 'ml': unlike 021-bash.exp, its # per-sub-command dispatch does not apply here at all -- 'ml's own # 'complete' registration in init/tcsh_completion.in only ever completes a # bare module name or an unload shortcut (see this file's header), it has # no sub-command dispatch of its own to check # # # ground-truth check, per sub-command: 'module ' must # propose a candidate of the kind 'module help' documents as that # sub-command's positional argument, for the two kinds with fixture data # predictable enough to check for by name -- an available/loaded module # ('modulefile'/'modfile'/'mod1'/'mod2'/'mod' in the usage synopsis) or a # saved collection ('collection'/'coll'). The remaining kinds # (a filesystem directory, an arbitrary file, or nothing completable at # all -- a search string, a shell name, a stash collection name generated # with an unpredictable timestamp, ...) are not asserted on here: 'use' and # 'unuse' already get a dedicated, fixture-appropriate check of their own # earlier in this file, and the rest fall back to plain filename completion # of the working directory, which is not fixture data this testsuite # controls # setenv_path_var MODULEPATH $modpath setenv_loaded_module [list bar/1.0] [list $modpath/bar/1.0] completion_tcsh_start completion_tcsh_raw {module save foo} completion_tcsh_raw {module save fox} completion_tcsh_raw {module save bar1} foreach subcmd $help_subcmds { ## 'list'/'savelist' take a search string filtering already-known state ## (loaded modules / saved collections), not a name completion target: ## their own completion only ever proposes their option flags, despite ## their usage synopsis documenting a module/collection-shaped argument if {$subcmd in {list savelist}} { continue } if {$subcmd eq {config}} { ## 'config' takes a configuration option name, not a module or ## collection: check it against the ground truth fetched from ## 'module config' (see 008-module_config.exp), plus the two real ## flags mixed into the same candidate list -- neither less nor more set got [completion_tcsh_list "module $subcmd "] completion_assert_contains $got $config_opts completion_assert_only_known $got {*} [concat $config_opts\ $help_subcmd_opts(config)] continue } if {![info exists help_subcmd_argtype($subcmd)]} { continue } set argtype $help_subcmd_argtype($subcmd) if {$argtype ni {module collection}} { continue } set got [completion_tcsh_list "module $subcmd "] if {$argtype eq {module}} { ## covers every module-completion mechanism this fixture set can ## produce: available modules not yet loaded (directory-style, ## trailing '/'), available modules regardless of load state ## (whatis/display/... style), and the one loaded module (flat ## 'name/version', switch/unload style) completion_assert_any $got {bar/ baz/ foo/ advvers/ flatlcompat bar/1.0} } else { completion_assert_any $got {foo fox bar1} } } completion_tcsh_close unsetenv_loaded_module # # candidate words built from untrusted text cannot reach a shell expansion # step (see this file's header, and the security fix for the bash-completion # command injection this guards against a regression of) # # each case below spawns a fresh tcsh session and, unlike every other # section in this file, its Ctrl-D listing goes through _module_loaded/ # _module_avail/_module_modulepath cold (no completion call already primed # the pty/subprocess pipeline): comfortably inside the default 10s # 'timeout' most of the time, but occasionally not under a loaded machine, # so it is raised for just this section rather than risking a false # UNRESOLVED set old_timeout $timeout set timeout 30 set marker "$env(TESTSUITEDIR)/completion-injection-marker" file delete -force $marker # module avail: malicious module name read off disk # the marker path is passed through as an env var rather than embedded # directly in the filename, since a filename cannot itself contain '/' setenv_var INJMARKER $marker set evilname {evil$(touch>$INJMARKER)} file mkdir $injectdir set fd [open "$injectdir/$evilname" w] puts $fd {#%Module1.0} close $fd setenv_path_var MODULEPATH $injectdir completion_tcsh_start set got [completion_tcsh_list {module load }] completion_assert_no_exec $marker completion_assert_contains $got [list $evilname] completion_tcsh_close unsetenv_path_var MODULEPATH unsetenv_var INJMARKER file delete -force $injectdir # LOADEDMODULES: malicious already-loaded module name set evilmod [string map [list MARKERPATH $marker] {python$(touch>MARKERPATH)}] setenv_loaded_module [list gcc $evilmod] [list /fake/gcc /fake/evilmod] completion_tcsh_start set got [completion_tcsh_list {module unload }] completion_assert_no_exec $marker completion_assert_contains $got [list $evilmod] completion_tcsh_close unsetenv_loaded_module # MODULEPATH: malicious path entry (module unuse); like this file's own # 'unuse' section above, only a bare, empty word reaches the modulepath # listing at all (see this file's header) set evilpath [string map [list MARKERPATH $marker] {/opt$(touch>MARKERPATH)}] setenv_path_var MODULEPATH /tmp $evilpath completion_tcsh_start set got [completion_tcsh_list {module unuse }] completion_assert_no_exec $marker completion_assert_contains $got [list $evilpath] completion_tcsh_close unsetenv_path_var MODULEPATH set timeout $old_timeout file delete -force $marker # # Cleanup # reset_test_env # vim:set tabstop=3 shiftwidth=3 expandtab autoindent: