Repository: AcademySoftwareFoundation/rez (python)

Issue:
Bake resolves with rez<3.2.0 can't be loaded due to missing `testing` key
Baked resolves generated with older versions are not compatible with rez-3.2.0.
Note a regression per say but a breaking change 

**Environment**
* windows 10
* 3.2.0
* Python 3.11.4

**To Reproduce**
1. using rez-3.0.0, bake a simple resolve into a rxt file
```
> rez --version
Rez 3.0.0 from c:\rez\3.0.0\Lib\site-packages\rez (python 3.11)
> rez env python --output py.rxt
```

2. using rez-3.2.0, resolve a context from the above rxt file
```
> rez env --input py.rxt
12:10:10 ERROR    ResolvedContextError: Failed to load context from py.rxt: KeyError: 'testing'
```

**Expected behavior**
We should be left in a resolved context

**Actual behavior**
Resolution failure.

**Related Issues/PRs**
* #1740

Pull request description:
Fix key error on getting the "testing" key on older contexts
Fixes #1862.

Now with a test to make sure we never regress.

Patch:
diff --git a/src/rez/resolved_context.py b/src/rez/resolved_context.py
index 0661978c..98082242 100644
--- a/src/rez/resolved_context.py
+++ b/src/rez/resolved_context.py
@@ -134,7 +134,7 @@ class ResolvedContext(object):
     command within a configured python namespace, without spawning a child
     shell.
     """
-    serialize_version = (4, 8)
+    serialize_version = (4, 9)
     tmpdir_manager = TempDirs(config.context_tmpdir, prefix="rez_context_")
     context_tracking_payload = None
     context_tracking_lock = threading.Lock()
@@ -1630,7 +1630,6 @@ class ResolvedContext(object):
 
         r.timestamp = d["timestamp"]
         r.building = d["building"]
-        r.testing = d["testing"]
         r.caching = d["caching"]
         r.implicit_packages = [PackageRequest(x) for x in d["implicit_packages"]]
         r._package_requests = [PackageRequest(x) for x in d["package_requests"]]
@@ -1725,6 +1724,9 @@ class ResolvedContext(object):
 
         r.package_cache_async = d.get("package_cache_async", True)
 
+        # -- SINCE SERIALIZE 4.9
+        r.testing = d.get("testing", False)
+
         # <END SERIALIZATION>
 
         # track context usage


Test patch:
diff --git a/src/rez/data/tests/contexts/resolved_context-4.8.json b/src/rez/data/tests/contexts/resolved_context-4.8.json
new file mode 100644
index 00000000..a92be60f
--- /dev/null
+++ b/src/rez/data/tests/contexts/resolved_context-4.8.json
@@ -0,0 +1,51 @@
+{
+    "append_sys_path": true,
+    "arch": "x86_64",
+    "building": false,
+    "caching": false,
+    "created": 1729961872,
+    "default_patch_lock": "no_lock",
+    "failure_description": null,
+    "from_cache": false,
+    "graph": "{'nodes': [((('fillcolor', '#FFFFAA'), ('fontsize', 10), ('style', 'filled,dashed')), [('_1', 'hello_world')]), ((('fillcolor', '#AAFFAA'), ('fontsize', 10), ('style', 'filled')), [('_2', 'hello_world-1.0[]')])], 'edges': [((('arrowsize', '0.5'),), [('_1', '_2')])]}",
+    "host": "arch01",
+    "implicit_packages": [],
+    "load_time": 0.0,
+    "num_loaded_packages": 1,
+    "os": "arch",
+    "package_cache_async": true,
+    "package_caching": true,
+    "package_filter": [],
+    "package_orderers": null,
+    "package_paths": [
+        "/tmp/rez_selftest_ec71iu0a/packages"
+    ],
+    "package_requests": [
+        "hello_world"
+    ],
+    "parent_suite_path": null,
+    "patch_locks": {},
+    "platform": "linux",
+    "requested_timestamp": null,
+    "resolved_ephemerals": [],
+    "resolved_packages": [
+        {
+            "key": "filesystem.variant",
+            "variables": {
+                "index": null,
+                "location": "/tmp/rez_selftest_ec71iu0a/packages",
+                "name": "hello_world",
+                "repository_type": "filesystem",
+                "version": "1.0"
+            }
+        }
+    ],
+    "rez_path": "/home/jcmorin/jcmenv/aswf/rez/src/rez",
+    "rez_version": "3.1.1",
+    "serialize_version": "4.8",
+    "solve_time": 0.00042057037353515625,
+    "status": "solved",
+    "suite_context_name": null,
+    "timestamp": 1729961872,
+    "user": "jcmorin"
+}
\ No newline at end of file
diff --git a/src/rez/tests/test_context.py b/src/rez/tests/test_context.py
index a0f984f7..9c2467c6 100644
--- a/src/rez/tests/test_context.py
+++ b/src/rez/tests/test_context.py
@@ -129,6 +129,14 @@ class TestContext(TestBase, TempdirMixin):
         env = r2.get_environ()
         self.assertEqual(env.get("OH_HAI_WORLD"), "hello")
 
+    def test_deserialize_older_versions(self):
+        """Test deserialization of older contexts."""
+        baked_contexts_path = self.data_path("contexts")
+
+        for context_file in os.listdir(baked_contexts_path):
+            # load
+            _ = ResolvedContext.load(os.path.join(baked_contexts_path, context_file))
+
     def test_retarget(self):
         """Test that a retargeted context behaves identically."""
         self.inject_python_repo()