Repository: equinor/fmu-dataio

Issue:
`komodo` missing from `sysinfo`
The current `komodo` version is supposedly added to the metadata (in `sysinfo`), however we don't see it in produced metadata.

fmu-dataio version: `2.9.2` and `2.9.3`

Example of `sysinfo` from live case (with fmu-dataio version `2.9.2`):
```yaml
tracklog:
  - datetime: "2025-02-25T08:19:27.574601Z"
    event: "created"
    user:
      id: ... # <redacted>
    sysinfo:
      fmu-dataio:
        version: "2.9.3"
      operating_system:
        hostname: ... # <redacted>
        operating_system: ... # <redacted>
        release: ... # <redacted>
        system: "Linux"
        version: "#1 SMP Fri Jan 10 05:56:06 EST 2025"
```

Reproduce:
- Run data export while sourcing Komodo
- Observe `komodo` not in the list of keys under `sysinfo` in the relevant `tracklog` events.

Expected behavior:
When running under Komodo, the current Komodo version is included in produced metadata.

Discussion:
@mferrera: It seems to be lacking in things that are exported from RMS. This makes sense because Komodo is disabled completely when RMS is launched so we cannot read the `KOMODO_RELEASE` environment variable. I do see the `komodo` entry in things produced by sim2sumo (from a quick, not-thorough check).

I'm not sure what the best course of action is.@mferrera: A simpler solution is probably to read `KOMODO_RELEASE_BACKUP` which is set by the internal `equilibrium` package when Komodo is disabled.

Solution patch:
diff --git a/src/fmu/dataio/_models/fmu_results/fields.py b/src/fmu/dataio/_models/fmu_results/fields.py
index 23cac8dab..fbe8559a0 100644
--- a/src/fmu/dataio/_models/fmu_results/fields.py
+++ b/src/fmu/dataio/_models/fmu_results/fields.py
@@ -496,6 +496,14 @@ class Tracklog(RootModel):
         event: enums.TrackLogEventType,
     ) -> list[fields.TracklogEvent]:
         """Generate new tracklog events with the given event type"""
+        komodo_release = os.environ.get(
+            "KOMODO_RELEASE", os.environ.get("KOMODO_RELEASE_BACKUP", None)
+        )
+        komodo = (
+            fields.Version.model_construct(version=komodo_release)
+            if komodo_release
+            else None
+        )
         return [
             fields.TracklogEvent.model_construct(
                 datetime=datetime.datetime.now(timezone.utc),
@@ -504,11 +512,7 @@ class Tracklog(RootModel):
                 sysinfo=(
                     fields.SystemInformation.model_construct(
                         fmu_dataio=fields.Version.model_construct(version=__version__),
-                        komodo=(
-                            fields.Version.model_construct(version=kr)
-                            if (kr := os.environ.get("KOMODO_RELEASE"))
-                            else None
-                        ),
+                        komodo=komodo,
                         operating_system=(
                             fields.OperatingSystem.model_construct(
                                 hostname=platform.node(),


Test patch:
diff --git a/tests/test_units/test_metadata_class.py b/tests/test_units/test_metadata_class.py
index 126e2deef..61ba5415b 100644
--- a/tests/test_units/test_metadata_class.py
+++ b/tests/test_units/test_metadata_class.py
@@ -4,6 +4,8 @@ import logging
 from copy import deepcopy
 
 import pytest
+import xtgeo
+from pytest import MonkeyPatch
 
 import fmu.dataio as dio
 from fmu.dataio._metadata import generate_export_metadata
@@ -67,7 +69,9 @@ def test_generate_meta_tracklog_fmu_dataio_version(regsurf, edataobj1):
     assert parsed.sysinfo.fmu_dataio.version is not None
 
 
-def test_generate_meta_tracklog_komodo_version(edataobj1, regsurf, monkeypatch):
+def test_generate_meta_tracklog_komodo_version(
+    edataobj1: dio.ExportData, regsurf: xtgeo.RegularSurface, monkeypatch: MonkeyPatch
+) -> None:
     fake_komodo_release = "<FAKE_KOMODO_RELEASE_VERSION>"
     monkeypatch.setenv("KOMODO_RELEASE", fake_komodo_release)
 
@@ -90,6 +94,38 @@ def test_generate_meta_tracklog_komodo_version(edataobj1, regsurf, monkeypatch):
     assert parsed.sysinfo.komodo.version == fake_komodo_release
 
 
+def test_generate_meta_tracklog_backup_komodo_version(
+    edataobj1: dio.ExportData, regsurf: xtgeo.RegularSurface, monkeypatch: MonkeyPatch
+) -> None:
+    """Tests that we read the Komodo version from KOMODO_RELEASE_BACKUP if it's set."""
+    komodo_release = "2123.01.01"
+    monkeypatch.setenv("KOMODO_RELEASE_BACKUP", komodo_release)
+
+    metadata = generate_export_metadata(regsurf, edataobj1)
+    tracklog = TracklogEvent.model_validate(metadata.tracklog[0])
+    assert tracklog.sysinfo.komodo.version == komodo_release
+
+
+def test_generate_meta_tracklog_komodo_version_preferred_over_backup(
+    edataobj1: dio.ExportData, regsurf: xtgeo.RegularSurface, monkeypatch: MonkeyPatch
+) -> None:
+    """Tests that we read the Komodo version from KOMODO_RELEASE.
+
+    This should be true even if KOMODO_RELEASE_BACKUP is set."""
+    komodo_release = "2123.01.01"
+    backup_komodo_release = "2123.01.02"  # Suppose it's botched.
+
+    # Sanity check to make sure this test tests something if modified in the future
+    assert komodo_release != backup_komodo_release
+
+    monkeypatch.setenv("KOMODO_RELEASE", komodo_release)
+    monkeypatch.setenv("KOMODO_RELEASE_BACKUP", backup_komodo_release)
+
+    metadata = generate_export_metadata(regsurf, edataobj1)
+    tracklog = TracklogEvent.model_validate(metadata.tracklog[0])
+    assert tracklog.sysinfo.komodo.version == komodo_release
+
+
 def test_generate_meta_tracklog_operating_system(edataobj1, regsurf):
     mymeta = generate_export_metadata(regsurf, edataobj1)
     tracklog = mymeta.tracklog