Repository: spack/spack

Issue:
Attempting to execute test callbacks fails with padded installs
### Steps to reproduce

```console
$ spack config add --scope=site 'config:install_tree:padded_length:255`
$ spack --backtrace install --test=root --no-cache perl-any-perl-pkg
```

[ Specifying a Perl package avoids dependence on whether #33928 has been fixed ]

### Error message

```console
<snip>
==> Installing perl-task-perl-critic-1.008-ikrfsky3auhgf56w7f4llijbs7beewgo
==> Using cached archive: /scratch/greenc/art-ci-spack-2022-11-09/spack_env/var/spack/cache/_source-cache/archive/62/626e4d746023b1f573f05a90fdcd0a0eb8f1b292882ac6535cadbdcd281f16ce.tar.gz
==> No patches needed for perl-task-perl-critic
==> perl-task-perl-critic: Executing phase: 'configure'
==> perl-task-perl-critic: Executing phase: 'build'
==> Error: TypeError: expected string or bytes-like object

/scratch/greenc/art-ci-spack-2022-11-09/spack_env/lib/spack/spack/build_environment.py:1086, in _setup_pkg_and_run:
       1083        tb_string = traceback.format_exc()
       1084
       1085        # build up some context from the offending package so we can
  >>   1086        # show that, too.
       1087        package_context = get_package_context(tb)
       1088
       1089        logfile = None

See build log for details:
  /tmp/greenc/spack-stage/spack-stage-perl-task-perl-critic-1.008-ikrfsky3auhgf56w7f4llijbs7beewgo/spack-build-out.txt

Traceback (most recent call last):
  File "/scratch/greenc/art-ci-spack-2022-11-09/spack_env/lib/spack/spack/build_environment.py", line 1070, in _setup_pkg_and_run
    return_value = function(pkg, kwargs)
  File "/scratch/greenc/art-ci-spack-2022-11-09/spack_env/lib/spack/spack/installer.py", line 2088, in build_process
    return installer.run()
  File "/scratch/greenc/art-ci-spack-2022-11-09/spack_env/lib/spack/spack/installer.py", line 1950, in run
    self._real_install()
  File "/scratch/greenc/art-ci-spack-2022-11-09/spack_env/lib/spack/spack/installer.py", line 2049, in _real_install
    phase_fn.execute()
  File "/scratch/greenc/art-ci-spack-2022-11-09/spack_env/lib/spack/spack/builder.py", line 426, in execute
    callback(self.builder)
  File "/scratch/greenc/art-ci-spack-2022-11-09/spack_env/lib/spack/spack/build_systems/_checks.py", line 107, in execute_build_time_tests
    builder.pkg.run_test_callbacks(builder, builder.build_time_test_callbacks, "build")
  File "/scratch/greenc/art-ci-spack-2022-11-09/spack_env/lib/spack/spack/package_base.py", line 2457, in run_test_callbacks
    print_test_message(logger, msg, True)
  File "/scratch/greenc/art-ci-spack-2022-11-09/spack_env/lib/spack/spack/package_base.py", line 2494, in print_test_message
    tty.msg(msg)
  File "/scratch/greenc/art-ci-spack-2022-11-09/spack_env/lib/spack/llnl/util/tty/__init__.py", line 182, in msg
    cprint("@*b{%s==>} %s%s" % (st_text, get_timestamp(), cescape(_output_filter(message))))
  File "/scratch/greenc/art-ci-spack-2022-11-09/spack_env/lib/spack/spack/util/path.py", line 454, in padding_filter
    return _filter_re.sub(replacer, string)
TypeError: expected string or bytes-like object
==> Error: perl-task-perl-critic-1.008-ikrfsky3auhgf56w7f4llijbs7beewgo: Package was not installed
==> Error: Installation request failed.  Refer to reported errors for failing package(s).
Traceback (most recent call last):
  File "/scratch/greenc/art-ci-spack-2022-11-09/spack_env/lib/spack/spack/main.py", line 1012, in main
    return _main(argv)
  File "/scratch/greenc/art-ci-spack-2022-11-09/spack_env/lib/spack/spack/main.py", line 967, in _main
    return finish_parse_and_run(parser, cmd_name, env_format_error)
  File "/scratch/greenc/art-ci-spack-2022-11-09/spack_env/lib/spack/spack/main.py", line 995, in finish_parse_and_run
    return _invoke_command(command, parser, args, unknown)
  File "/scratch/greenc/art-ci-spack-2022-11-09/spack_env/lib/spack/spack/main.py", line 639, in _invoke_command
    return_val = command(parser, args)
  File "/scratch/greenc/art-ci-spack-2022-11-09/spack_env/lib/spack/spack/cmd/install.py", line 549, in install
    install_specs(zip(abstract_specs, concrete_specs), install_kwargs, args)
  File "/scratch/greenc/art-ci-spack-2022-11-09/spack_env/lib/spack/spack/cmd/install.py", line 268, in install_specs
    install_specs_inside_environment(specs, install_kwargs, cli_args)
  File "/scratch/greenc/art-ci-spack-2022-11-09/spack_env/lib/spack/spack/cmd/install.py", line 340, in install_specs_inside_environment
    env.install_specs(specs_to_install, **install_kwargs)
  File "/scratch/greenc/art-ci-spack-2022-11-09/spack_env/lib/spack/spack/environment/environment.py", line 1736, in install_specs
    builder.install()
  File "/scratch/greenc/art-ci-spack-2022-11-09/spack_env/lib/spack/spack/installer.py", line 1867, in install
    pkg=pkg,
spack.installer.InstallError: Installation request failed.  Refer to reported errors for failing package(s).
```


### Information on your system

* **Spack:** 0.19.0 (9c020da21df641256b2f799073abc7f714c0f3c3)
* **Python:** 3.6.8
* **Platform:** linux-scientific7-skylake_avx512
* **Concretizer:** clingo


### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have searched the issues of this repo and believe this is not a duplicate
- [X] I have run the failing commands in debug mode and reported the output


Discussion:

Resolving patch:
diff --git a/lib/spack/spack/package_base.py b/lib/spack/spack/package_base.py
--- a/lib/spack/spack/package_base.py
+++ b/lib/spack/spack/package_base.py
@@ -2455,12 +2455,12 @@ def run_test_callbacks(builder, method_names, callback_type="install"):
                 try:
                     fn = getattr(builder, name)
 
-                    msg = ("RUN-TESTS: {0}-time tests [{1}]".format(callback_type, name),)
+                    msg = "RUN-TESTS: {0}-time tests [{1}]".format(callback_type, name)
                     print_test_message(logger, msg, True)
 
                     fn()
                 except AttributeError as e:
-                    msg = ("RUN-TESTS: method not implemented [{0}]".format(name),)
+                    msg = "RUN-TESTS: method not implemented [{0}]".format(name)
                     print_test_message(logger, msg, True)
 
                     builder.pkg.test_failures.append((e, msg))


Test patch:
diff --git a/lib/spack/spack/test/cmd/install.py b/lib/spack/spack/test/cmd/install.py
--- a/lib/spack/spack/test/cmd/install.py
+++ b/lib/spack/spack/test/cmd/install.py
@@ -1178,3 +1178,11 @@ def install_use_buildcache(opt):
         # Alternative to --cache-only (always) or --no-cache (never)
         for opt in ["auto", "only", "never"]:
             install_use_buildcache(opt)
+
+
+@pytest.mark.regression("34006")
+@pytest.mark.disable_clean_stage_check
+def test_padded_install_runtests_root(install_mockery_mutable_config, mock_fetch):
+    spack.config.set("config:install_tree:padded_length", 255)
+    output = install("--test=root", "--no-cache", "test-build-callbacks", fail_on_error=False)
+    assert output.count("method not implemented") == 1