code: def test_commit_preserve_fields(tmp_dir, dvc):
      text = textwrap.dedent(
          """\
          # top comment
          desc: top desc
          outs:
          - path: foo # out comment
            desc: out desc
            type: mytype
            labels:
            - label1
            - label2
            meta:
              key1: value1
              key2: value2
            remote: testremote
            hash: md5
          meta: some metadata
      """
      )
      tmp_dir.gen("foo.dvc", text)
      tmp_dir.dvc_gen("foo", "foo", commit=False)
      dvc.commit("foo")
      assert (tmp_dir / "foo.dvc").read_text() == textwrap.dedent(
          """\
          # top comment
          desc: top desc
          outs:
          - path: foo # out comment
            desc: out desc
            type: mytype
            labels:
            - label1
            - label2
            meta:
              key1: value1
              key2: value2
            remote: testremote
            hash: md5
            md5: acbd18db4cc2f85cedef654fccc4a4d8
            size: 3
          meta: some metadata
      """
      )
  
imports: import os
  import textwrap
  import pytest
  from dvc.dependency.base import DependencyDoesNotExistError
  from dvc.dvcfile import PROJECT_FILE
  from dvc.fs import localfs
  from dvc.output import OutputDoesNotExistError
  from dvc.stage.exceptions import StageCommitError
label_desc: Use image node_id 3 for calling a global function with example usage: test_commit_preserve_fields(tmp_dir, dvc) without return types