From e1b192ff86f3abc2477d28890d618a5360a2d7ab Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Fri, 21 Aug 2026 12:13:16 +0200 Subject: [PATCH] #14570 Orion Events: Fix schedule user metadata --- .../RicScheduleDataGenerator.cpp | 7 +++- .../Python/rips/tests/test_well_events.py | 32 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/ApplicationLibCode/Commands/CompletionExportCommands/RicScheduleDataGenerator.cpp b/ApplicationLibCode/Commands/CompletionExportCommands/RicScheduleDataGenerator.cpp index 8381d6f61d..4957ced810 100644 --- a/ApplicationLibCode/Commands/CompletionExportCommands/RicScheduleDataGenerator.cpp +++ b/ApplicationLibCode/Commands/CompletionExportCommands/RicScheduleDataGenerator.cpp @@ -60,8 +60,13 @@ std::expected RicScheduleDataGenerator::generateSchedule( cons // Header QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); - QString userName = environment.value( "USERNAME" ); +#ifdef Q_OS_WIN + QString userName = environment.value( "USERNAME" ); if ( userName.isEmpty() ) userName = environment.value( "USER", "unknown" ); +#else + QString userName = environment.value( "USER" ); + if ( userName.isEmpty() ) userName = environment.value( "USERNAME", "unknown" ); +#endif result += "-- Generated by ResInsight\n"; result += QString( "-- Timestamp: %1\n" ).arg( QDateTime::currentDateTimeUtc().toString( Qt::ISODateWithMs ) ); diff --git a/GrpcInterface/Python/rips/tests/test_well_events.py b/GrpcInterface/Python/rips/tests/test_well_events.py index 60dff1aa8a..3a6e37307b 100644 --- a/GrpcInterface/Python/rips/tests/test_well_events.py +++ b/GrpcInterface/Python/rips/tests/test_well_events.py @@ -1469,6 +1469,38 @@ class TestScheduleGeneration: assert lines[2].startswith("-- User: ") assert lines[2] != "-- User: " + def test_schedule_header_uses_platform_user_variable(self, monkeypatch): + """Prefer USER on Unix and USERNAME on Windows when both are set.""" + if sys.platform == "win32": + monkeypatch.setenv("USERNAME", "preferred-schedule-user") + monkeypatch.setenv("USER", "wrong-schedule-user") + else: + monkeypatch.setenv("USER", "preferred-schedule-user") + monkeypatch.setenv("USERNAME", "wrong-schedule-user") + + instance = rips.Instance.launch(console=True) + try: + case_root = dataroot.PATH + "/TEST10K_FLT_LGR_NNC" + project = instance.project + case = project.load_case(path=case_root + "/TEST10K_FLT_LGR_NNC.EGRID") + project.import_well_paths(well_path_files=[case_root + "/wellpath_a.dev"]) + well_path = project.well_paths()[0] + timeline = project.descendants(rips.WellPathCollection)[0].event_timeline() + 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 = timeline.generate_schedule_text(eclipse_case=case) + assert "-- User: preferred-schedule-user\n" in schedule + assert "wrong-schedule-user" not in schedule + finally: + instance.exit() + def test_event_comment_lines_are_safely_emitted(self, project_with_case_and_well): project, case, timeline = project_with_case_and_well well_path = project.well_paths()[0]