code: def _test_initremote_rewrite(host, ds_path, store):
      # rudimentary repetition of test_initremote_basic, but
      # with url.<base>.insteadOf config, which should not only
      # be respected, but lead to the rewritten URL stored in
      # git-annex:remote.log
  
      ds_path = Path(ds_path)
      store = Path(store)
      ds = Dataset(ds_path).create()
      populate_dataset(ds)
      assert_repo_status(ds.path)
  
      url = "mystore:"
      init_opts = common_init_opts + ["url={}".format(url)]
  
      if host:
          replacement = "ria+ssh://{host}{path}".format(
              host=host, path=store
          )
      else:
          replacement = "ria+{}".format(store.as_uri())
  
      ds.config.set(
          "url.{}.insteadOf".format(replacement), url, scope="local"
      )
  
      # set up store:
      io = SSHRemoteIO(host) if host else LocalIO()
      create_store(io, store, "1")
      create_ds_in_store(io, store, ds.id, "2", "1")
  
      # run initremote and check what's stored:
      ds.repo.init_remote("ria-remote", options=init_opts)
      assert_in(
          "ria-remote",
          [
              cfg["name"]
              for uuid, cfg in ds.repo.get_special_remotes().items()
          ],
      )
      # git-annex:remote.log should have:
      #   - rewritten url
      #   - common_init_opts
      #   - archive_id (which equals ds id)
      remote_log = ds.repo.call_git(
          ["cat-file", "blob", "git-annex:remote.log"], read_only=True
      )
      assert_in("url={}".format(replacement), remote_log)
      [assert_in(c, remote_log) for c in common_init_opts]
      assert_in("archive-id={}".format(ds.id), remote_log)
  
imports: import logging
  import stat
  from datalad.api import Dataset, clone, create_sibling_ria
  from datalad.cmd import NoCapture
  from datalad.customremotes.ria_utils import create_ds_in_store, create_store, get_layout_locations
  from datalad.distributed.ora_remote import LocalIO, SSHRemoteIO, _sanitize_key
  from datalad.distributed.tests.ria_utils import common_init_opts, get_all_files, populate_dataset
  from datalad.support.exceptions import CommandError, IncompleteResultsError
  from datalad.tests.utils_pytest import SkipTest, assert_equal, assert_false, assert_in, assert_not_in, assert_raises, assert_repo_status, assert_status, assert_true, has_symlink_capability, known_failure_windows, serve_path_via_http, skip_if_adjusted_branch, skip_if_no_network, skip_if_root, skip_ssh, skip_wo_symlink_capability, slow, swallow_logs, turtle, with_tempfile
  from datalad.utils import Path
label_desc: Use image node_id 8 for calling a global function with example usage: _test_initremote_rewrite(host, ds_path, store) without return types