|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Runtime.CompilerServices; |
| 4 | +using GitHub.DistributedTask.Pipelines; |
| 5 | +using GitHub.DistributedTask.Pipelines.ContextData; |
4 | 6 | using GitHub.DistributedTask.WebApi; |
5 | 7 | using GitHub.Runner.Common.Util; |
6 | 8 | using GitHub.Runner.Sdk; |
7 | 9 | using GitHub.Runner.Worker; |
8 | 10 | using GitHub.Runner.Worker.Handlers; |
9 | 11 | using Moq; |
| 12 | +using Newtonsoft.Json.Linq; |
10 | 13 | using Xunit; |
11 | 14 | using DTWebApi = GitHub.DistributedTask.WebApi; |
| 15 | +using Pipelines = GitHub.DistributedTask.Pipelines; |
12 | 16 |
|
13 | 17 | namespace GitHub.Runner.Common.Tests.Worker.Handlers |
14 | 18 | { |
@@ -250,6 +254,66 @@ public void MarkerFormat_ContinueOnError() |
250 | 254 | Assert.Equal("##[end-action id=failing-step;outcome=failure;conclusion=success;duration_ms=500]", marker); |
251 | 255 | } |
252 | 256 |
|
| 257 | + [Fact] |
| 258 | + [Trait("Level", "L0")] |
| 259 | + [Trait("Category", "Worker")] |
| 260 | + public void PostStepMarker_UsesEvaluatedDisplayName() |
| 261 | + { |
| 262 | + // Arrange: create an ActionRunner with a RepositoryPathReference (simulating actions/cache@v4) |
| 263 | + // and Stage = Post. Verify that EvaluateDisplayName produces the correct display name |
| 264 | + // so the composite marker emits "Run actions/cache@v4" instead of the fallback "run". |
| 265 | + var hc = new TestHostContext(this, nameof(PostStepMarker_UsesEvaluatedDisplayName)); |
| 266 | + var actionManifestLegacy = new ActionManifestManagerLegacy(); |
| 267 | + actionManifestLegacy.Initialize(hc); |
| 268 | + hc.SetSingleton<IActionManifestManagerLegacy>(actionManifestLegacy); |
| 269 | + var actionManifestNew = new ActionManifestManager(); |
| 270 | + actionManifestNew.Initialize(hc); |
| 271 | + hc.SetSingleton<IActionManifestManager>(actionManifestNew); |
| 272 | + var actionManifestManager = new ActionManifestManagerWrapper(); |
| 273 | + actionManifestManager.Initialize(hc); |
| 274 | + hc.SetSingleton<IActionManifestManagerWrapper>(actionManifestManager); |
| 275 | + |
| 276 | + var ec = new Mock<IExecutionContext>(); |
| 277 | + var contextData = new DictionaryContextData(); |
| 278 | + var githubContext = new GitHubContext(); |
| 279 | + githubContext.Add("event", JToken.Parse("{\"foo\":\"bar\"}").ToPipelineContextData()); |
| 280 | + contextData.Add("github", githubContext); |
| 281 | +#if OS_WINDOWS |
| 282 | + contextData["env"] = new DictionaryContextData(); |
| 283 | +#else |
| 284 | + contextData["env"] = new CaseSensitiveDictionaryContextData(); |
| 285 | +#endif |
| 286 | + ec.Setup(x => x.Global).Returns(new GlobalContext()); |
| 287 | + ec.Setup(x => x.ExpressionValues).Returns(contextData); |
| 288 | + ec.Setup(x => x.ExpressionFunctions).Returns(new List<GitHub.DistributedTask.Expressions2.IFunctionInfo>()); |
| 289 | + ec.Setup(x => x.Write(It.IsAny<string>(), It.IsAny<string>())); |
| 290 | + ec.Object.Global.Variables = new Variables(hc, new Dictionary<string, VariableValue>()); |
| 291 | + |
| 292 | + var actionRunner = new ActionRunner(); |
| 293 | + actionRunner.Initialize(hc); |
| 294 | + actionRunner.ExecutionContext = ec.Object; |
| 295 | + actionRunner.Stage = ActionRunStage.Post; |
| 296 | + actionRunner.Action = new Pipelines.ActionStep() |
| 297 | + { |
| 298 | + Name = "cache", |
| 299 | + Id = Guid.NewGuid(), |
| 300 | + Reference = new Pipelines.RepositoryPathReference() |
| 301 | + { |
| 302 | + Name = "actions/cache", |
| 303 | + Ref = "v4" |
| 304 | + } |
| 305 | + }; |
| 306 | + |
| 307 | + // Act: call EvaluateDisplayName directly, which is what CompositeActionHandler now does |
| 308 | + // for embedded steps (including Post stage) instead of TryUpdateDisplayName. |
| 309 | + var result = actionRunner.EvaluateDisplayName(contextData, ec.Object, out bool updated); |
| 310 | + |
| 311 | + // Assert: display name should be "Run actions/cache@v4", not the fallback "run" |
| 312 | + Assert.True(result); |
| 313 | + Assert.True(updated); |
| 314 | + Assert.Equal("Run actions/cache@v4", actionRunner.DisplayName); |
| 315 | + } |
| 316 | + |
253 | 317 | // Helper methods that call the real production code |
254 | 318 | private static string EscapeProperty(string value) => |
255 | 319 | CompositeActionHandler.EscapeProperty(value); |
|
0 commit comments