code: def test_rerun_subdir(path=None):
      # Note: Using with_tree rather than with_tempfile is matters. The latter
      # calls realpath on the path, which masks a failure in the
      # TMPDIR="/var/tmp/sym link" test case
      ds = Dataset(path).create(force=True)
      subdir = op.join(path, "subdir")
      with chpwd(subdir):
          run(touch_command + "test.dat")
      assert_repo_status(ds.path)
  
      # FIXME: A plain ok_file_under_git call doesn't properly resolve the file
      # in the TMPDIR="/var/tmp/sym link" test case. Temporarily call realpath.
      def ok_file_under_git_kludge(path, basename):
          ok_file_under_git(
              op.join(str(Path(path).resolve()), basename), annexed=True
          )
  
      ok_file_under_git_kludge(subdir, "test.dat")
  
      rec_msg, runinfo = get_run_info(ds, last_commit_msg(ds.repo))
      eq_(runinfo["pwd"], "subdir")
      # now, rerun within root of the dataset
      with chpwd(ds.path):
          ds.rerun()
      assert_repo_status(ds.path)
      ok_file_under_git_kludge(subdir, "test.dat")
      # and not on top
      assert_raises(
          AssertionError,
          ok_file_under_git,
          op.join(ds.path, "test.dat"),
          annexed=True,
      )
  
      # but if we run ds.run -- runs within top of the dataset
      with chpwd(subdir):
          ds.run(touch_command + "test2.dat")
      assert_repo_status(ds.path)
      ok_file_under_git_kludge(ds.path, "test2.dat")
      rec_msg, runinfo = get_run_info(ds, last_commit_msg(ds.repo))
      eq_(runinfo["pwd"], ".")
      # now, rerun within subdir -- smoke for now
      with chpwd(subdir):
          ds.rerun()
  
imports: import logging
  import os.path
  import sys
  from io import StringIO
  from os import remove
  import pytest
  from unittest.mock import patch
  from datalad.api import install, run
  from datalad.core.local.run import run_command
  from datalad.core.local.tests.test_run import last_commit_msg
  from datalad.distribution.dataset import Dataset
  from datalad.local.rerun import diff_revision, get_run_info, new_or_modified
  from datalad.support.exceptions import CommandError, IncompleteResultsError
  from datalad.support.gitrepo import GitRepo
  from datalad.tests.utils_pytest import DEFAULT_BRANCH, DEFAULT_REMOTE, SkipTest, assert_dict_equal, assert_false, assert_in, assert_in_results, assert_not_in, assert_not_in_results, assert_raises, assert_repo_status, assert_result_count, assert_status, create_tree, eq_, known_failure_windows, neq_, ok_, ok_exists, ok_file_has_content, ok_file_under_git, skip_if_adjusted_branch, slow, swallow_logs, swallow_outputs, with_tempfile, with_tree
  from datalad.utils import Path, chpwd, on_windows
label_desc: Use image node_id 12 for calling a global function with example usage: test_rerun_subdir(path) without return types