chr
2026-04-05 fe750b791d5b517cc4e9bc8e99a9a75139a0cfba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.ComponentModel;
 
namespace OpenTap.Package
{
    // This is not actually used as a component setting. This is a hack because there currently is no other 
    // hook to know when a TestPlanRun is started, besides creating a result listener. 
    // Since this component setting is internal, it will not show up in the GUI, but it is detected by the engine
    // since the 'PluginAssembly' attribute is used in this assembly. 
    [Browsable(false)]
    internal class TestPlanRunPackageParameterMonitor : ComponentSettings, ITestPlanRunMonitor
    {
        private static TraceSource log = Log.CreateSource(nameof(TestPlanRunPackageParameterMonitor));
        public void EnterTestPlanRun(TestPlanRun plan)
        {
            try
            {
                var pathParam = plan.Parameters["TestPlanPath"];
 
                if (!(pathParam is string path)) return;
                if (path == "NULL" || string.IsNullOrEmpty(path)) return;
 
                var package = Installation.Current.FindPackageContainingFile(path);
                if (package == null) return;
 
                plan.Parameters["Test Plan Package"] =
                    $"{package.Name}|{package.Version}|{package.Hash ?? package.ComputeHash()}";
            }
            catch (Exception ex)
            {
                // It is crucial that this method does not prevent test plans from executing since it cannot be disabled.
                // Just log the error and return
                log.Debug(ex);
            }
        }
 
        public void ExitTestPlanRun(TestPlanRun plan)
        {
            
        }
    }
}