code: def test_discover_ds_trace(path=None, otherdir=None):
      ds = make_demo_hierarchy_datasets(
          path,
          {k: v for k, v in demo_hierarchy.items() if k in ["a", "d"]},
      )
      a = opj(ds.path, "a")
      aa = opj(a, "aa")
      d = opj(ds.path, "d")
      db = opj(d, "db")
      # we have to check whether we get the correct hierarchy, as the test
      # subject is also involved in this
      assert_true(exists(opj(db, "file_db")))
      ds.save(recursive=True)
      assert_repo_status(ds.path)
      # now two datasets which are not available locally, but we
      # know about them (e.g. from metadata)
      dba = opj(db, "sub", "dba")
      dbaa = opj(dba, "subsub", "dbaa")
      for input, eds, goal in (
          ([], None, {}),
          ([ds.path], None, {}),
          ([otherdir], None, {}),
          ([opj(ds.path, "nothere")], None, {}),
          ([opj(d, "nothere")], None, {}),
          ([opj(db, "nothere")], None, {}),
          ([a], None, {ds.path: set([a])}),
          ([aa, a], None, {ds.path: set([a]), a: set([aa])}),
          ([db], None, {ds.path: set([d]), d: set([db])}),
          (
              [opj(db, "file_db")],
              None,
              {ds.path: set([d]), d: set([db])},
          ),
          # just a regular non-existing path
          ([dba], None, {}),
          # but if we inject this knowledge it must come back out
          # as the child of the closest existing dataset
          (
              [dba],
              [dba],
              {ds.path: set([d]), d: set([db]), db: set([dba])},
          ),
          # regardless of the depth
          (
              [dbaa],
              [dbaa],
              {ds.path: set([d]), d: set([db]), db: set([dbaa])},
          ),
          (
              [dba, dbaa],
              [dba, dbaa],
              {ds.path: set([d]), d: set([db]), db: set([dba, dbaa])},
          ),
          # we can simply add existing and non-existing datasets to the
          # include list get the desired result
          (
              [d, dba, dbaa],
              [d, dba, dbaa],
              {ds.path: set([d]), d: set([db]), db: set([dba, dbaa])},
          ),
      ):
          spec = {}
          discover_dataset_trace_to_targets(
              ds.path, input, [], spec, includeds=eds
          )
          assert_dict_equal(spec, goal)
  
imports: import logging
  import re
  from contextlib import contextmanager
  from os.path import exists
  from os.path import join
  from time import sleep
  from datalad.distribution.dataset import Dataset, EnsureDataset, datasetmethod
  from datalad.interface.base import build_doc, eval_results
  from datalad.support.constraints import EnsureKeyChoice, EnsureNone, EnsureStr
  from datalad.support.param import Parameter
  from datalad.tests.utils_pytest import assert_dict_equal, assert_equal, assert_in, assert_not_equal, assert_not_in, assert_raises, assert_re_in, assert_repo_status, assert_result_count, assert_true, ok_, slow, with_tempfile, with_tree
  from datalad.utils import swallow_logs, swallow_outputs
  from ..base import Interface
  from ..results import get_status_dict
  from ..utils import discover_dataset_trace_to_targets, handle_dirty_dataset
label_desc: Use image node_id 8 for calling a global function with example usage: test_discover_ds_trace(path, otherdir) without return types