diff --git a/ApplicationLibCode/Commands/CompletionExportCommands/RicScheduleDataGenerator.cpp b/ApplicationLibCode/Commands/CompletionExportCommands/RicScheduleDataGenerator.cpp index d79ce3c571..92db91a747 100644 --- a/ApplicationLibCode/Commands/CompletionExportCommands/RicScheduleDataGenerator.cpp +++ b/ApplicationLibCode/Commands/CompletionExportCommands/RicScheduleDataGenerator.cpp @@ -36,6 +36,7 @@ #include "opm/input/eclipse/Deck/DeckRecord.hpp" #include +#include #include #include @@ -55,7 +56,13 @@ QString RicScheduleDataGenerator::generateSchedule( const RimWellEventTimeline& QString result; // Header + QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); + QString userName = environment.value( "USERNAME" ); + if ( userName.isEmpty() ) userName = environment.value( "USER", "unknown" ); + result += "-- Generated by ResInsight\n"; + result += QString( "-- Timestamp: %1\n" ).arg( QDateTime::currentDateTimeUtc().toString( Qt::ISODateWithMs ) ); + result += QString( "-- User: %1\n" ).arg( userName ); result += "-- Schedule data based on well events\n"; result += "--\n"; diff --git a/GrpcInterface/Python/rips/tests/test_well_events.py b/GrpcInterface/Python/rips/tests/test_well_events.py index a010271534..ec94579b89 100644 --- a/GrpcInterface/Python/rips/tests/test_well_events.py +++ b/GrpcInterface/Python/rips/tests/test_well_events.py @@ -5,6 +5,7 @@ These tests verify the well event timeline and event management functionality. """ import os +import re import sys import pytest @@ -1441,6 +1442,33 @@ class TestScheduleGeneration: assert "COMPDAT" in schedule_text + def test_schedule_header_contains_generation_metadata( + self, project_with_case_and_well + ): + """Generated schedules identify when and by whom they were created.""" + project, case, timeline = project_with_case_and_well + well_path = project.well_paths()[0] + + timeline.add_perf_event( + event_date="2024-01-01", + well_path=well_path, + start_md=2000.0, + end_md=2200.0, + diameter=0.1, + state="OPEN", + ) + + schedule_text = timeline.generate_schedule_text(eclipse_case=case) + lines = schedule_text.splitlines() + + assert lines[0] == "-- Generated by ResInsight" + assert re.fullmatch( + r"-- Timestamp: \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z", + lines[1], + ) + assert lines[2].startswith("-- User: ") + assert lines[2] != "-- User: " + def test_align_columns_adds_headers_and_alignment(self, project_with_case_and_well): """align_columns=True must add a '--'-prefixed column-header comment per keyword and indent right-aligned data rows, while the default (align_columns=False) keeps the