code: def metrics_repo(tmp_dir, scm, dvc, run_copy_metrics):
      dvc.run(name="prepare", cmd="echo preparing data")
      scm.add(["dvc.yaml", "dvc.lock"])
      scm.commit("prepare data")
      sub_dir = tmp_dir / "eval"
      sub_dir.mkdir()
      tmp_dir.gen(
          "tmp_train_val_metrics.json",
          json.dumps(TRAIN_METRICS[0]),
      )
      train_metrics_file = os.path.join(
          sub_dir, "train_val_metrics.json"
      )
      run_copy_metrics(
          "tmp_train_val_metrics.json",
          train_metrics_file,
          name="train",
          metrics_no_cache=[train_metrics_file],
      )
      (tmp_dir / "tmp_train_val_metrics.json").unlink()
  
      scm.add(["dvc.yaml", "dvc.lock", train_metrics_file])
      scm.commit("train model")
  
      test_metrics_file = os.path.join(sub_dir, "test_metrics.json")
      tmp_dir.gen("tmp_test_metrics.json", json.dumps(TEST_METRICS[0]))
      run_copy_metrics(
          "tmp_test_metrics.json",
          test_metrics_file,
          name="test",
          metrics_no_cache=[test_metrics_file],
      )
      (tmp_dir / "tmp_test_metrics.json").unlink()
  
      scm.add(["dvc.yaml", "dvc.lock", test_metrics_file])
      scm.commit("test model")
  
      with tmp_dir.branch("better-model", new=True):
          tmp_dir.gen(
              "tmp_train_val_metrics.json",
              json.dumps(TRAIN_METRICS[1]),
          )
          run_copy_metrics(
              "tmp_train_val_metrics.json",
              train_metrics_file,
              name="train",
              metrics_no_cache=[train_metrics_file],
          )
          (tmp_dir / "tmp_train_val_metrics.json").unlink()
  
          scm.add(["dvc.yaml", "dvc.lock", train_metrics_file])
          scm.commit("train better model")
  
          tmp_dir.gen(
              "tmp_test_metrics.json", json.dumps(TEST_METRICS[1])
          )
          run_copy_metrics(
              "tmp_test_metrics.json",
              test_metrics_file,
              name="test",
              metrics_no_cache=[test_metrics_file],
          )
          (tmp_dir / "tmp_test_metrics.json").unlink()
  
          scm.add(["dvc.yaml", "dvc.lock", test_metrics_file])
          scm.commit("test better model")
  
      scm.checkout("master")
  
      return (
          os.path.relpath(train_metrics_file, tmp_dir),
          os.path.relpath(test_metrics_file, tmp_dir),
      )
  
imports: import json
  import os
  from textwrap import dedent
  from typing import Dict, List
  import pytest
  from dvc import api
label_desc: Use image node_id 2 for calling a global function with example usage: metrics_repo(tmp_dir, scm, dvc, run_copy_metrics) and returns: os,  os