code: def test_job_spec(engine: Engine):
      job_spec = {"a": 2, "b": [0, 1, 2], "c": {"x": 1, "y": "foo"}}
      container_spec = {
          "nogpu": True,
          "cloud_key": "/path/to/key.json",
          "image_tag": None,
          "dir": ["/extra/path0", "/extra/path2"],
          "base_dir": "/home/foo",
          "module": "train.py",
      }
  
      def validate_spec(session) -> JobSpec:
          s = session.query(JobSpec).all()
          assert len(s) == 1
          s = s[0]
          assert s.platform == Platform.LOCAL
          assert s.spec == job_spec
          return s
  
      # test basic creation
      with session_scope(engine) as session:
          xg = ExperimentGroup.get_or_create(session=session)
          c = ContainerSpec.get_or_create(
              session=session, spec=container_spec
          )
          e = Experiment.get_or_create(xgroup=xg, container_spec=c)
          j = JobSpec.get_or_create(
              experiment=e,
              spec=job_spec,
              platform=Platform.LOCAL,
          )
          session.add(xg)
  
      # test basic persistence, then add duplicate
      with session_scope(engine) as session:
          s = validate_spec(session)
  
          session.add(
              JobSpec.get_or_create(
                  experiment=s.experiment,
                  spec=job_spec,
                  platform=Platform.LOCAL,
              )
          )
  
      # test get_or_create, then create new spec
      with session_scope(engine) as session:
          s = validate_spec(session)
  
          session.add(
              JobSpec.get_or_create(
                  experiment=s.experiment,
                  spec=job_spec,
                  platform=Platform.CAIP,
              )
          )
  
      # verify that new spec was peristed
      with session_scope(engine) as session:
          s = session.query(JobSpec).all()
          assert len(s) == 2
          assert s[0].spec == s[1].spec
          assert s[0].platform != s[1].platform
  
file_path: caliban/tests/caliban/history/test_history.py
imports: from datetime import datetime
  from sqlalchemy.engine.base import Engine
  import pytest
  from caliban.history.types import ContainerSpec, Experiment, ExperimentGroup, Job, JobSpec, Platform
  from caliban.history.util import get_mem_engine, session_scope
  from caliban.util import current_user
label_desc: Use image node_id 4 for calling a global function with example usage: test_job_spec(engine) and returns: s