code: def get_job_environment() -> "JobEnvironment":
      # Don't cache this function. It makes testing harder.
      # The slow part is the plugin discovery anyway.
      envs = get_job_environments()
      # bypassing can be helful for testing
      if "_TEST_CLUSTER_" in os.environ:
          c = os.environ["_TEST_CLUSTER_"]
          assert (
              c in envs
          ), f"Unknown $_TEST_CLUSTER_='{c}', available: {envs.keys()}."
          return envs[c]
      for env in envs.values():
          # TODO? handle the case where several envs are valid
          if env.activated():
              return env
      raise RuntimeError(
          f"Could not figure out which environment the job is runnning in. Known environments: {', '.join(envs.keys())}."
      )
  
imports: import functools
  import os
  from typing import TYPE_CHECKING, List, Mapping, Tuple, Type
  from ..core import logger
label_desc: Use image node_id 3 for calling a global function with example usage: get_job_environment() and returns: envs, env