code: def test_walk_nested_subrepos(tmp_dir, dvc, scm, traverse_subrepos):
      # generate a dvc and fs structure, with suffix based on repo's basename
      def fs_structure(suffix):
          return {
              f"foo-{suffix}": f"foo-{suffix}",
              f"dir-{suffix}": {f"bar-{suffix}": f"bar-{suffix}"},
          }
  
      def dvc_structure(suffix):
          return {
              f"lorem-{suffix}": f"lorem-{suffix}",
              f"dvc-{suffix}": {f"ipsum-{suffix}": f"ipsum-{suffix}"},
          }
  
      paths = [
          "subrepo1",
          "subrepo2",
          os.path.join("subrepo1", "subrepo3"),
      ]
      subrepos = [tmp_dir / path for path in paths]
      for repo_dir in subrepos:
          make_subrepo(repo_dir, scm)
  
      extras = {".gitignore"}  # these files are always there
      expected = {}
      for repo_dir in [*subrepos, tmp_dir]:
          base = os.path.basename(repo_dir)
          scm_files = fs_structure(base)
          dvc_files = dvc_structure(base)
          with repo_dir.chdir():
              repo_dir.scm_gen(
                  scm_files, commit=f"git add in {repo_dir}"
              )
              repo_dir.dvc_gen(
                  dvc_files, commit=f"dvc add in {repo_dir}"
              )
  
          if traverse_subrepos or repo_dir == tmp_dir:
              repo_dir_path = (
                  "/" + repo_dir.relative_to(tmp_dir).as_posix()
                  if repo_dir != tmp_dir
                  else "/"
              )
              expected[repo_dir_path] = set(
                  scm_files.keys() | dvc_files.keys() | extras
              )
              # files inside a dvc directory
              expected[posixpath.join(repo_dir_path, f"dvc-{base}")] = {
                  f"ipsum-{base}"
              }
              # files inside a git directory
              expected[posixpath.join(repo_dir_path, f"dir-{base}")] = {
                  f"bar-{base}"
              }
  
      if traverse_subrepos:
          # update subrepos
          expected["/"].update(["subrepo1", "subrepo2"])
          expected["/subrepo1"].add("subrepo3")
  
      actual = {}
      fs = DVCFileSystem(repo=dvc)
      for root, dirs, files in fs.walk(
          "/", ignore_subrepos=not traverse_subrepos
      ):
          actual[root] = set(dirs + files)
      assert expected == actual
  
imports: import os
  import posixpath
  import shutil
  import pytest
  from fsspec.utils import tokenize
  from dvc.fs import localfs
  from dvc.fs.dvc import DVCFileSystem
  from dvc.testing.tmp_dir import make_subrepo
  from dvc_data.hashfile.build import build
  from dvc_data.hashfile.hash_info import HashInfo
label_desc: Use image node_id 28 for calling a global function with example usage: test_walk_nested_subrepos(tmp_dir, dvc, scm, traverse_subrepos) and returns: dict, dict