def test_record_metadata_plain(self):
        """Test inclusion of metadata in records."""

        # Need unique app_id per test as they may be run in parallel and have
        # same ids.
        session = core_session.TruSession()
        chain, recorder = self._create_basic_chain(app_name="metaplain")

        message, _ = self._get_question_and_answers(0)
        meta = "this is plain metadata"

        with recorder as recording:
            recording.record_metadata = meta
            chain.invoke(input=dict(question=message))

        record = recording.get()

        with self.subTest("Check the record has the metadata"):
            self.assertEqual(record.meta, meta)

        with self.subTest(
            "Check the record has the metadata when retrieved back from db"
        ):
            recs, _ = session.get_records_and_feedback([recorder.app_id])
            self.assertGreater(len(recs), 0)
            rec = self._load_first_record(recs.iloc[-1:])
            self.assertEqual(rec.meta, meta)

        with self.subTest("Check updating the record metadata in the db."):
            new_meta = "this is new meta"
            rec.meta = new_meta
            session.update_record(rec)
            recs, _ = session.get_records_and_feedback([recorder.app_id])
            self.assertGreater(len(recs), 0)
            rec = self._load_first_record(recs[recs.record_id == rec.record_id])
            self.assertNotEqual(rec.meta, meta)
            self.assertEqual(rec.meta, new_meta)

        with self.subTest(
            "Check adding meta to a record that initially didn't have it."
        ):
            with recorder as recording:
                chain.invoke(input=dict(question=message))

            with self.subTest("with no metadata"):
                rec = recording.get()
                self.assertEqual(rec.meta, None)
                recs, _ = session.get_records_and_feedback([recorder.app_id])
                self.assertGreater(len(recs), 1)
                rec = self._load_first_record(
                    recs[recs.record_id == rec.record_id]
                )
                self.assertEqual(rec.meta, None)

            with self.subTest("Updated with metadata"):
                rec.meta = new_meta
                session.update_record(rec)
                recs, _ = session.get_records_and_feedback([recorder.app_id])
                self.assertGreater(len(recs), 1)
                rec = self._load_first_record(
                    recs[recs.record_id == rec.record_id]
                )
                self.assertEqual(rec.meta, new_meta)
Test inclusion of metadata in records.
tests/e2e/test_tru_chain.py