From 5294a3ee065fad93fad06fddd665b96b71dfa370 Mon Sep 17 00:00:00 2001 From: eric sciple Date: Wed, 12 Feb 2020 21:07:43 -0500 Subject: [PATCH] commands translate file path from container action (#331) --- src/Runner.Worker/ActionCommandManager.cs | 47 ++-- src/Runner.Worker/Handlers/OutputManager.cs | 2 +- src/Test/L0/Worker/ActionCommandManagerL0.cs | 258 +++++++++---------- src/Test/L0/Worker/OutputManagerL0.cs | 4 +- 4 files changed, 154 insertions(+), 157 deletions(-) diff --git a/src/Runner.Worker/ActionCommandManager.cs b/src/Runner.Worker/ActionCommandManager.cs index 023e2f304..29bd4a03b 100644 --- a/src/Runner.Worker/ActionCommandManager.cs +++ b/src/Runner.Worker/ActionCommandManager.cs @@ -1,6 +1,7 @@ using GitHub.DistributedTask.Pipelines; using GitHub.DistributedTask.WebApi; using GitHub.Runner.Common.Util; +using GitHub.Runner.Worker.Container; using System; using System.Collections.Generic; using System.IO; @@ -15,14 +16,14 @@ namespace GitHub.Runner.Worker { void EnablePluginInternalCommand(); void DisablePluginInternalCommand(); - bool TryProcessCommand(IExecutionContext context, string input); + bool TryProcessCommand(IExecutionContext context, string input, ContainerInfo container); } public sealed class ActionCommandManager : RunnerService, IActionCommandManager { private const string _stopCommand = "stop-commands"; private readonly Dictionary _commandExtensions = new Dictionary(StringComparer.OrdinalIgnoreCase); - private HashSet _registeredCommands = new HashSet(StringComparer.OrdinalIgnoreCase); + private readonly HashSet _registeredCommands = new HashSet(StringComparer.OrdinalIgnoreCase); private readonly object _commandSerializeLock = new object(); private bool _stopProcessCommand = false; private string _stopToken = null; @@ -58,7 +59,7 @@ namespace GitHub.Runner.Worker _registeredCommands.Remove("internal-set-repo-path"); } - public bool TryProcessCommand(IExecutionContext context, string input) + public bool TryProcessCommand(IExecutionContext context, string input, ContainerInfo container) { if (string.IsNullOrEmpty(input)) { @@ -114,7 +115,7 @@ namespace GitHub.Runner.Worker try { - extension.ProcessCommand(context, input, actionCommand); + extension.ProcessCommand(context, input, actionCommand, container); } catch (Exception ex) { @@ -140,7 +141,7 @@ namespace GitHub.Runner.Worker string Command { get; } bool OmitEcho { get; } - void ProcessCommand(IExecutionContext context, string line, ActionCommand command); + void ProcessCommand(IExecutionContext context, string line, ActionCommand command, ContainerInfo container); } public sealed class InternalPluginSetRepoPathCommandExtension : RunnerService, IActionCommandExtension @@ -150,7 +151,7 @@ namespace GitHub.Runner.Worker public Type ExtensionType => typeof(IActionCommandExtension); - public void ProcessCommand(IExecutionContext context, string line, ActionCommand command) + public void ProcessCommand(IExecutionContext context, string line, ActionCommand command, ContainerInfo container) { if (!command.Properties.TryGetValue(SetRepoPathCommandProperties.repoFullName, out string repoFullName) || string.IsNullOrEmpty(repoFullName)) { @@ -180,7 +181,7 @@ namespace GitHub.Runner.Worker public Type ExtensionType => typeof(IActionCommandExtension); - public void ProcessCommand(IExecutionContext context, string line, ActionCommand command) + public void ProcessCommand(IExecutionContext context, string line, ActionCommand command, ContainerInfo container) { if (!command.Properties.TryGetValue(SetEnvCommandProperties.Name, out string envName) || string.IsNullOrEmpty(envName)) { @@ -205,7 +206,7 @@ namespace GitHub.Runner.Worker public Type ExtensionType => typeof(IActionCommandExtension); - public void ProcessCommand(IExecutionContext context, string line, ActionCommand command) + public void ProcessCommand(IExecutionContext context, string line, ActionCommand command, ContainerInfo container) { if (!command.Properties.TryGetValue(SetOutputCommandProperties.Name, out string outputName) || string.IsNullOrEmpty(outputName)) { @@ -229,7 +230,7 @@ namespace GitHub.Runner.Worker public Type ExtensionType => typeof(IActionCommandExtension); - public void ProcessCommand(IExecutionContext context, string line, ActionCommand command) + public void ProcessCommand(IExecutionContext context, string line, ActionCommand command, ContainerInfo container) { if (!command.Properties.TryGetValue(SaveStateCommandProperties.Name, out string stateName) || string.IsNullOrEmpty(stateName)) { @@ -253,7 +254,7 @@ namespace GitHub.Runner.Worker public Type ExtensionType => typeof(IActionCommandExtension); - public void ProcessCommand(IExecutionContext context, string line, ActionCommand command) + public void ProcessCommand(IExecutionContext context, string line, ActionCommand command, ContainerInfo container) { if (string.IsNullOrWhiteSpace(command.Data)) { @@ -279,7 +280,7 @@ namespace GitHub.Runner.Worker public Type ExtensionType => typeof(IActionCommandExtension); - public void ProcessCommand(IExecutionContext context, string line, ActionCommand command) + public void ProcessCommand(IExecutionContext context, string line, ActionCommand command, ContainerInfo container) { ArgUtil.NotNullOrEmpty(command.Data, "path"); context.PrependPath.RemoveAll(x => string.Equals(x, command.Data, StringComparison.CurrentCulture)); @@ -294,7 +295,7 @@ namespace GitHub.Runner.Worker public Type ExtensionType => typeof(IActionCommandExtension); - public void ProcessCommand(IExecutionContext context, string line, ActionCommand command) + public void ProcessCommand(IExecutionContext context, string line, ActionCommand command, ContainerInfo container) { var file = command.Data; @@ -306,9 +307,9 @@ namespace GitHub.Runner.Worker } // Translate file path back from container path - if (context.Container != null) + if (container != null) { - file = context.Container.TranslateToHostPath(file); + file = container.TranslateToHostPath(file); } // Root the path @@ -341,7 +342,7 @@ namespace GitHub.Runner.Worker public Type ExtensionType => typeof(IActionCommandExtension); - public void ProcessCommand(IExecutionContext context, string line, ActionCommand command) + public void ProcessCommand(IExecutionContext context, string line, ActionCommand command, ContainerInfo container) { command.Properties.TryGetValue(RemoveMatcherCommandProperties.Owner, out string owner); var file = command.Data; @@ -369,9 +370,9 @@ namespace GitHub.Runner.Worker else { // Translate file path back from container path - if (context.Container != null) + if (container != null) { - file = context.Container.TranslateToHostPath(file); + file = container.TranslateToHostPath(file); } // Root the path @@ -409,7 +410,7 @@ namespace GitHub.Runner.Worker public Type ExtensionType => typeof(IActionCommandExtension); - public void ProcessCommand(IExecutionContext context, string inputLine, ActionCommand command) + public void ProcessCommand(IExecutionContext context, string inputLine, ActionCommand command, ContainerInfo container) { context.Debug(command.Data); } @@ -437,7 +438,7 @@ namespace GitHub.Runner.Worker public Type ExtensionType => typeof(IActionCommandExtension); - public void ProcessCommand(IExecutionContext context, string inputLine, ActionCommand command) + public void ProcessCommand(IExecutionContext context, string inputLine, ActionCommand command, ContainerInfo container) { command.Properties.TryGetValue(IssueCommandProperties.File, out string file); command.Properties.TryGetValue(IssueCommandProperties.Line, out string line); @@ -454,10 +455,10 @@ namespace GitHub.Runner.Worker { issue.Category = "Code"; - if (context.Container != null) + if (container != null) { // Translate file path back from container path - file = context.Container.TranslateToHostPath(file); + file = container.TranslateToHostPath(file); command.Properties[IssueCommandProperties.File] = file; } @@ -517,7 +518,7 @@ namespace GitHub.Runner.Worker public Type ExtensionType => typeof(IActionCommandExtension); - public void ProcessCommand(IExecutionContext context, string line, ActionCommand command) + public void ProcessCommand(IExecutionContext context, string line, ActionCommand command, ContainerInfo container) { var data = this is GroupCommandExtension ? command.Data : string.Empty; context.Output($"##[{Command}]{data}"); @@ -531,7 +532,7 @@ namespace GitHub.Runner.Worker public Type ExtensionType => typeof(IActionCommandExtension); - public void ProcessCommand(IExecutionContext context, string line, ActionCommand command) + public void ProcessCommand(IExecutionContext context, string line, ActionCommand command, ContainerInfo container) { ArgUtil.NotNullOrEmpty(command.Data, "value"); diff --git a/src/Runner.Worker/Handlers/OutputManager.cs b/src/Runner.Worker/Handlers/OutputManager.cs index 3e8215704..42478e44d 100644 --- a/src/Runner.Worker/Handlers/OutputManager.cs +++ b/src/Runner.Worker/Handlers/OutputManager.cs @@ -84,7 +84,7 @@ namespace GitHub.Runner.Worker.Handlers { // This does not need to be inside of a critical section. // The logging queues and command handlers are thread-safe. - if (_commandManager.TryProcessCommand(_executionContext, line)) + if (_commandManager.TryProcessCommand(_executionContext, line, _container)) { return; } diff --git a/src/Test/L0/Worker/ActionCommandManagerL0.cs b/src/Test/L0/Worker/ActionCommandManagerL0.cs index f2e8d6755..a1f69c92d 100644 --- a/src/Test/L0/Worker/ActionCommandManagerL0.cs +++ b/src/Test/L0/Worker/ActionCommandManagerL0.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.IO; using System.Runtime.CompilerServices; using GitHub.DistributedTask.WebApi; using GitHub.Runner.Worker; +using GitHub.Runner.Worker.Container; using Moq; using Xunit; using Pipelines = GitHub.DistributedTask.Pipelines; @@ -11,47 +13,35 @@ namespace GitHub.Runner.Common.Tests.Worker { public sealed class ActionCommandManagerL0 { + private ActionCommandManager _commandManager; + private Mock _ec; + private Mock _extensionManager; + private Mock _pipelineDirectoryManager; + [Fact] [Trait("Level", "L0")] [Trait("Category", "Worker")] public void EnablePluginInternalCommand() { - using (TestHostContext _hc = new TestHostContext(this)) + using (TestHostContext hc = CreateTestContext()) { - var extensionManger = new Mock(); - var directoryManager = new Mock(); - - var pluginCommand = new InternalPluginSetRepoPathCommandExtension(); - pluginCommand.Initialize(_hc); - - var envCommand = new SetEnvCommandExtension(); - envCommand.Initialize(_hc); - - extensionManger.Setup(x => x.GetExtensions()) - .Returns(new List() { pluginCommand, envCommand }); - _hc.SetSingleton(extensionManger.Object); - _hc.SetSingleton(directoryManager.Object); - - Mock _ec = new Mock(); _ec.Setup(x => x.Write(It.IsAny(), It.IsAny())) .Returns((string tag, string line) => { - _hc.GetTrace().Info($"{tag} {line}"); + hc.GetTrace().Info($"{tag} {line}"); return 1; }); _ec.Setup(x => x.AddIssue(It.IsAny(), It.IsAny())) .Callback((Issue issue, string message) => { - _hc.GetTrace().Info($"{issue.Type} {issue.Message} {message ?? string.Empty}"); + hc.GetTrace().Info($"{issue.Type} {issue.Message} {message ?? string.Empty}"); }); - ActionCommandManager commandManager = new ActionCommandManager(); - commandManager.Initialize(_hc); - commandManager.EnablePluginInternalCommand(); + _commandManager.EnablePluginInternalCommand(); - Assert.True(commandManager.TryProcessCommand(_ec.Object, "##[internal-set-repo-path repoFullName=actions/runner;workspaceRepo=true]somepath")); + Assert.True(_commandManager.TryProcessCommand(_ec.Object, "##[internal-set-repo-path repoFullName=actions/runner;workspaceRepo=true]somepath", null)); - directoryManager.Verify(x => x.UpdateRepositoryDirectory(_ec.Object, "actions/runner", "somepath", true), Times.Once); + _pipelineDirectoryManager.Verify(x => x.UpdateRepositoryDirectory(_ec.Object, "actions/runner", "somepath", true), Times.Once); } } @@ -60,47 +50,29 @@ namespace GitHub.Runner.Common.Tests.Worker [Trait("Category", "Worker")] public void DisablePluginInternalCommand() { - using (TestHostContext _hc = new TestHostContext(this)) + using (TestHostContext hc = CreateTestContext()) { - var extensionManger = new Mock(); - var directoryManager = new Mock(); - - var pluginCommand = new InternalPluginSetRepoPathCommandExtension(); - pluginCommand.Initialize(_hc); - - var envCommand = new SetEnvCommandExtension(); - envCommand.Initialize(_hc); - - extensionManger.Setup(x => x.GetExtensions()) - .Returns(new List() { pluginCommand, envCommand }); - - _hc.SetSingleton(extensionManger.Object); - _hc.SetSingleton(directoryManager.Object); - - Mock _ec = new Mock(); _ec.Setup(x => x.Write(It.IsAny(), It.IsAny())) .Returns((string tag, string line) => { - _hc.GetTrace().Info($"{tag} {line}"); + hc.GetTrace().Info($"{tag} {line}"); return 1; }); _ec.Setup(x => x.AddIssue(It.IsAny(), It.IsAny())) .Callback((Issue issue, string message) => { - _hc.GetTrace().Info($"{issue.Type} {issue.Message} {message ?? string.Empty}"); + hc.GetTrace().Info($"{issue.Type} {issue.Message} {message ?? string.Empty}"); }); - ActionCommandManager commandManager = new ActionCommandManager(); - commandManager.Initialize(_hc); - commandManager.EnablePluginInternalCommand(); + _commandManager.EnablePluginInternalCommand(); - Assert.True(commandManager.TryProcessCommand(_ec.Object, "##[internal-set-repo-path repoFullName=actions/runner;workspaceRepo=true]somepath")); + Assert.True(_commandManager.TryProcessCommand(_ec.Object, "##[internal-set-repo-path repoFullName=actions/runner;workspaceRepo=true]somepath", null)); - commandManager.DisablePluginInternalCommand(); + _commandManager.DisablePluginInternalCommand(); - Assert.False(commandManager.TryProcessCommand(_ec.Object, "##[internal-set-repo-path repoFullName=actions/runner;workspaceRepo=true]somepath")); + Assert.False(_commandManager.TryProcessCommand(_ec.Object, "##[internal-set-repo-path repoFullName=actions/runner;workspaceRepo=true]somepath", null)); - directoryManager.Verify(x => x.UpdateRepositoryDirectory(_ec.Object, "actions/runner", "somepath", true), Times.Once); + _pipelineDirectoryManager.Verify(x => x.UpdateRepositoryDirectory(_ec.Object, "actions/runner", "somepath", true), Times.Once); } } @@ -109,42 +81,27 @@ namespace GitHub.Runner.Common.Tests.Worker [Trait("Category", "Worker")] public void StopProcessCommand() { - using (TestHostContext _hc = new TestHostContext(this)) + using (TestHostContext hc = CreateTestContext()) { - var extensionManger = new Mock(); - var pluginCommand = new InternalPluginSetRepoPathCommandExtension(); - pluginCommand.Initialize(_hc); - - var envCommand = new SetEnvCommandExtension(); - envCommand.Initialize(_hc); - - extensionManger.Setup(x => x.GetExtensions()) - .Returns(new List() { pluginCommand, envCommand }); - _hc.SetSingleton(extensionManger.Object); - - Mock _ec = new Mock(); _ec.Setup(x => x.Write(It.IsAny(), It.IsAny())) .Returns((string tag, string line) => { - _hc.GetTrace().Info($"{tag} {line}"); + hc.GetTrace().Info($"{tag} {line}"); return 1; }); _ec.Setup(x => x.AddIssue(It.IsAny(), It.IsAny())) .Callback((Issue issue, string message) => { - _hc.GetTrace().Info($"{issue.Type} {issue.Message} {message ?? string.Empty}"); + hc.GetTrace().Info($"{issue.Type} {issue.Message} {message ?? string.Empty}"); }); _ec.Setup(x => x.EnvironmentVariables).Returns(new Dictionary()); - ActionCommandManager commandManager = new ActionCommandManager(); - commandManager.Initialize(_hc); - - Assert.True(commandManager.TryProcessCommand(_ec.Object, "##[stop-commands]stopToken")); - Assert.False(commandManager.TryProcessCommand(_ec.Object, "##[set-env name=foo]bar")); - Assert.True(commandManager.TryProcessCommand(_ec.Object, "##[stopToken]")); - Assert.True(commandManager.TryProcessCommand(_ec.Object, "##[set-env name=foo]bar")); + Assert.True(_commandManager.TryProcessCommand(_ec.Object, "##[stop-commands]stopToken", null)); + Assert.False(_commandManager.TryProcessCommand(_ec.Object, "##[set-env name=foo]bar", null)); + Assert.True(_commandManager.TryProcessCommand(_ec.Object, "##[stopToken]", null)); + Assert.True(_commandManager.TryProcessCommand(_ec.Object, "##[set-env name=foo]bar", null)); } } @@ -153,41 +110,29 @@ namespace GitHub.Runner.Common.Tests.Worker [Trait("Category", "Worker")] public void EchoProcessCommand() { - using (TestHostContext _hc = new TestHostContext(this)) + using (TestHostContext hc = CreateTestContext()) { - var extensionManager = new Mock(); - var echoCommand = new EchoCommandExtension(); - echoCommand.Initialize(_hc); - - extensionManager.Setup(x => x.GetExtensions()) - .Returns(new List() { echoCommand }); - _hc.SetSingleton(extensionManager.Object); - - Mock _ec = new Mock(); _ec.Setup(x => x.Write(It.IsAny(), It.IsAny())) .Returns((string tag, string line) => { - _hc.GetTrace().Info($"{tag} {line}"); + hc.GetTrace().Info($"{tag} {line}"); return 1; }); _ec.SetupAllProperties(); - ActionCommandManager commandManager = new ActionCommandManager(); - commandManager.Initialize(_hc); - Assert.False(_ec.Object.EchoOnActionCommand); - Assert.True(commandManager.TryProcessCommand(_ec.Object, "::echo::on")); + Assert.True(_commandManager.TryProcessCommand(_ec.Object, "::echo::on", null)); Assert.True(_ec.Object.EchoOnActionCommand); - Assert.True(commandManager.TryProcessCommand(_ec.Object, "::echo::off")); + Assert.True(_commandManager.TryProcessCommand(_ec.Object, "::echo::off", null)); Assert.False(_ec.Object.EchoOnActionCommand); - Assert.True(commandManager.TryProcessCommand(_ec.Object, "::echo::ON")); + Assert.True(_commandManager.TryProcessCommand(_ec.Object, "::echo::ON", null)); Assert.True(_ec.Object.EchoOnActionCommand); - Assert.True(commandManager.TryProcessCommand(_ec.Object, "::echo::Off ")); + Assert.True(_commandManager.TryProcessCommand(_ec.Object, "::echo::Off ", null)); Assert.False(_ec.Object.EchoOnActionCommand); } } @@ -197,7 +142,7 @@ namespace GitHub.Runner.Common.Tests.Worker [Trait("Category", "Worker")] public void EchoProcessCommandDebugOn() { - using (TestHostContext _hc = new TestHostContext(this)) + using (TestHostContext hc = CreateTestContext()) { // Set up a few things // 1. Job request message (with ACTIONS_STEP_DEBUG = true) @@ -219,84 +164,135 @@ namespace GitHub.Runner.Common.Tests.Worker var jobServerQueue = new Mock(); jobServerQueue.Setup(x => x.QueueTimelineRecordUpdate(It.IsAny(), It.IsAny())); - _hc.SetSingleton(jobServerQueue.Object); - - var extensionManager = new Mock(); - var echoCommand = new EchoCommandExtension(); - echoCommand.Initialize(_hc); - - extensionManager.Setup(x => x.GetExtensions()) - .Returns(new List() { echoCommand }); - _hc.SetSingleton(extensionManager.Object); + hc.SetSingleton(jobServerQueue.Object); var configurationStore = new Mock(); configurationStore.Setup(x => x.GetSettings()).Returns(new RunnerSettings()); - _hc.SetSingleton(configurationStore.Object); + hc.SetSingleton(configurationStore.Object); var pagingLogger = new Mock(); - _hc.EnqueueInstance(pagingLogger.Object); - - ActionCommandManager commandManager = new ActionCommandManager(); - commandManager.Initialize(_hc); - - var _ec = new Runner.Worker.ExecutionContext(); - _ec.Initialize(_hc); + hc.EnqueueInstance(pagingLogger.Object); // Initialize the job (to exercise logic that sets EchoOnActionCommand) - _ec.InitializeJob(jobRequest, System.Threading.CancellationToken.None); + var ec = new Runner.Worker.ExecutionContext(); + ec.Initialize(hc); + ec.InitializeJob(jobRequest, System.Threading.CancellationToken.None); - _ec.Complete(); + ec.Complete(); - Assert.True(_ec.EchoOnActionCommand); + Assert.True(ec.EchoOnActionCommand); - Assert.True(commandManager.TryProcessCommand(_ec, "::echo::off")); - Assert.False(_ec.EchoOnActionCommand); + Assert.True(_commandManager.TryProcessCommand(ec, "::echo::off", null)); + Assert.False(ec.EchoOnActionCommand); - Assert.True(commandManager.TryProcessCommand(_ec, "::echo::on")); - Assert.True(_ec.EchoOnActionCommand); + Assert.True(_commandManager.TryProcessCommand(ec, "::echo::on", null)); + Assert.True(ec.EchoOnActionCommand); } } - [Fact] [Trait("Level", "L0")] [Trait("Category", "Worker")] public void EchoProcessCommandInvalid() { - using (TestHostContext _hc = new TestHostContext(this)) + using (TestHostContext hc = CreateTestContext()) { - var extensionManager = new Mock(); - var echoCommand = new EchoCommandExtension(); - echoCommand.Initialize(_hc); - - extensionManager.Setup(x => x.GetExtensions()) - .Returns(new List() { echoCommand }); - _hc.SetSingleton(extensionManager.Object); - - Mock _ec = new Mock(); _ec.Setup(x => x.Write(It.IsAny(), It.IsAny())) .Returns((string tag, string line) => { - _hc.GetTrace().Info($"{tag} {line}"); + hc.GetTrace().Info($"{tag} {line}"); return 1; }); _ec.SetupAllProperties(); - ActionCommandManager commandManager = new ActionCommandManager(); - commandManager.Initialize(_hc); - // Echo commands below are considered "processed", but are invalid // 1. Invalid echo value - Assert.True(commandManager.TryProcessCommand(_ec.Object, "::echo::invalid")); + Assert.True(_commandManager.TryProcessCommand(_ec.Object, "::echo::invalid", null)); Assert.Equal(TaskResult.Failed, _ec.Object.CommandResult); Assert.False(_ec.Object.EchoOnActionCommand); // 2. No value - Assert.True(commandManager.TryProcessCommand(_ec.Object, "::echo::")); + Assert.True(_commandManager.TryProcessCommand(_ec.Object, "::echo::", null)); Assert.Equal(TaskResult.Failed, _ec.Object.CommandResult); Assert.False(_ec.Object.EchoOnActionCommand); } } + + [Fact] + [Trait("Level", "L0")] + [Trait("Category", "Worker")] + public void AddMatcherTranslatesFilePath() + { + using (TestHostContext hc = CreateTestContext()) + { + // Create a problem matcher config file + var hostDirectory = hc.GetDirectory(WellKnownDirectory.Temp); + var hostFile = Path.Combine(hostDirectory, "my-matcher.json"); + Directory.CreateDirectory(hostDirectory); + var content = @" +{ + ""problemMatcher"": [ + { + ""owner"": ""my-matcher"", + ""pattern"": [ + { + ""regexp"": ""^ERROR: (.+)$"", + ""message"": 1 + } + ] + } + ] +}"; + File.WriteAllText(hostFile, content); + + // Setup translation info + var container = new ContainerInfo(); + var containerDirectory = "/some-container-directory"; + var containerFile = Path.Combine(containerDirectory, "my-matcher.json"); + container.AddPathTranslateMapping(hostDirectory, containerDirectory); + + // Act + _commandManager.TryProcessCommand(_ec.Object, $"::add-matcher::{containerFile}", container); + + // Assert + _ec.Verify(x => x.AddMatchers(It.IsAny()), Times.Once); + } + } + + private TestHostContext CreateTestContext([CallerMemberName] string testName = "") + { + var hostContext = new TestHostContext(this, testName); + + // Mock extension manager + _extensionManager = new Mock(); + var commands = new IActionCommandExtension[] + { + new AddMatcherCommandExtension(), + new EchoCommandExtension(), + new InternalPluginSetRepoPathCommandExtension(), + new SetEnvCommandExtension(), + }; + foreach (var command in commands) + { + command.Initialize(hostContext); + } + _extensionManager.Setup(x => x.GetExtensions()) + .Returns(new List(commands)); + hostContext.SetSingleton(_extensionManager.Object); + + // Mock pipeline directory manager + _pipelineDirectoryManager = new Mock(); + hostContext.SetSingleton(_pipelineDirectoryManager.Object); + + // Execution context + _ec = new Mock(); + + // Command manager + _commandManager = new ActionCommandManager(); + _commandManager.Initialize(hostContext); + + return hostContext; + } } } diff --git a/src/Test/L0/Worker/OutputManagerL0.cs b/src/Test/L0/Worker/OutputManagerL0.cs index 78d342a31..8b50c08b5 100644 --- a/src/Test/L0/Worker/OutputManagerL0.cs +++ b/src/Test/L0/Worker/OutputManagerL0.cs @@ -973,8 +973,8 @@ namespace GitHub.Runner.Common.Tests.Worker }); _commandManager = new Mock(); - _commandManager.Setup(x => x.TryProcessCommand(It.IsAny(), It.IsAny())) - .Returns((IExecutionContext executionContext, string line) => + _commandManager.Setup(x => x.TryProcessCommand(It.IsAny(), It.IsAny(), It.IsAny())) + .Returns((IExecutionContext executionContext, string line, ContainerInfo container) => { if (line.IndexOf("##[some-command]") >= 0) {