chore: import upstream snapshot with attribution
dotnet-build-and-test / dotnet-test-functions (push) Has been cancelled
dotnet-build-and-test / paths-filter (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Debug, windows-latest, net9.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net8.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-foundry-hosted-it (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test-check (push) Has been cancelled
dotnet-build-and-test / Integration Test Report (push) Has been cancelled
CodeQL / Analyze (csharp) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:39:25 +08:00
commit db620d33df
5151 changed files with 925932 additions and 0 deletions
@@ -0,0 +1,191 @@
// Copyright (c) Microsoft. All rights reserved.
using FluentAssertions;
using Microsoft.Agents.AI.Workflows.Declarative.Events;
using Microsoft.Agents.AI.Workflows.Declarative.Kit;
using Microsoft.Agents.AI.Workflows.Declarative.ObjectModel;
namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.Kit;
/// <summary>
/// Tests that edge predicates correctly handle PortableValue-wrapped messages,
/// which occur after checkpoint restore (JSON round-trip).
/// </summary>
public sealed class PortableValuePredicateTests
{
#region ActionExecutorResult.ThrowIfNot
[Fact]
public void ActionExecutorResult_ThrowIfNot_WithDirectActionExecutorResult_ReturnsResult()
{
// Arrange
ActionExecutorResult result = new("test-executor");
// Act
ActionExecutorResult actual = ActionExecutorResult.ThrowIfNot(result);
// Assert
actual.Should().BeSameAs(result);
}
[Fact]
public void ActionExecutorResult_ThrowIfNot_WithPortableValueWrappedActionExecutorResult_Unwraps()
{
// Arrange
ActionExecutorResult result = new("test-executor");
PortableValue wrapped = new(result);
// Act
ActionExecutorResult actual = ActionExecutorResult.ThrowIfNot(wrapped);
// Assert
actual.ExecutorId.Should().Be("test-executor");
}
[Fact]
public void ActionExecutorResult_ThrowIfNot_WithNonActionExecutorResult_Throws()
{
// Arrange
object message = "not an ActionExecutorResult";
// Act & Assert
Assert.Throws<DeclarativeActionException>(() => ActionExecutorResult.ThrowIfNot(message));
}
[Fact]
public void ActionExecutorResult_ThrowIfNot_WithNull_Throws()
{
// Act & Assert
Assert.Throws<DeclarativeActionException>(() => ActionExecutorResult.ThrowIfNot(null));
}
[Fact]
public void ActionExecutorResult_ThrowIfNot_WithPortableValueWrappedNonResult_Throws()
{
// Arrange
PortableValue wrapped = new("not an ActionExecutorResult");
// Act & Assert
Assert.Throws<DeclarativeActionException>(() => ActionExecutorResult.ThrowIfNot(wrapped));
}
#endregion
#region InvokeAzureAgentExecutor Predicates
[Fact]
public void InvokeAzureAgentExecutor_RequiresInput_WithDirectExternalInputRequest_ReturnsTrue()
{
// Arrange
ExternalInputRequest request = new("test prompt");
// Act & Assert
InvokeAzureAgentExecutor.RequiresInput(request).Should().BeTrue();
}
[Fact]
public void InvokeAzureAgentExecutor_RequiresInput_WithPortableValueWrappedRequest_ReturnsTrue()
{
// Arrange
ExternalInputRequest request = new("test prompt");
PortableValue wrapped = new(request);
// Act & Assert
InvokeAzureAgentExecutor.RequiresInput(wrapped).Should().BeTrue();
}
[Fact]
public void InvokeAzureAgentExecutor_RequiresInput_WithActionExecutorResult_ReturnsFalse()
{
// Arrange
ActionExecutorResult result = new("test");
// Act & Assert
InvokeAzureAgentExecutor.RequiresInput(result).Should().BeFalse();
}
[Fact]
public void InvokeAzureAgentExecutor_RequiresNothing_WithDirectActionExecutorResult_ReturnsTrue()
{
// Arrange
ActionExecutorResult result = new("test");
// Act & Assert
InvokeAzureAgentExecutor.RequiresNothing(result).Should().BeTrue();
}
[Fact]
public void InvokeAzureAgentExecutor_RequiresNothing_WithPortableValueWrappedResult_ReturnsTrue()
{
// Arrange
ActionExecutorResult result = new("test");
PortableValue wrapped = new(result);
// Act & Assert
InvokeAzureAgentExecutor.RequiresNothing(wrapped).Should().BeTrue();
}
[Fact]
public void InvokeAzureAgentExecutor_RequiresNothing_WithExternalInputRequest_ReturnsFalse()
{
// Arrange
ExternalInputRequest request = new("test prompt");
// Act & Assert
InvokeAzureAgentExecutor.RequiresNothing(request).Should().BeFalse();
}
#endregion
#region InvokeMcpToolExecutor Predicates
[Fact]
public void InvokeMcpToolExecutor_RequiresInput_WithPortableValueWrappedRequest_ReturnsTrue()
{
// Arrange
ExternalInputRequest request = new("test prompt");
PortableValue wrapped = new(request);
// Act & Assert
InvokeMcpToolExecutor.RequiresInput(wrapped).Should().BeTrue();
}
[Fact]
public void InvokeMcpToolExecutor_RequiresNothing_WithPortableValueWrappedResult_ReturnsTrue()
{
// Arrange
ActionExecutorResult result = new("test");
PortableValue wrapped = new(result);
// Act & Assert
InvokeMcpToolExecutor.RequiresNothing(wrapped).Should().BeTrue();
}
#endregion
#region QuestionExecutor.IsComplete
[Fact]
public void QuestionExecutor_IsComplete_WithPortableValueWrappedResult_NullResult_ReturnsTrue()
{
// Arrange - result with null Result property means "complete"
ActionExecutorResult result = new("test", result: null);
PortableValue wrapped = new(result);
// Act & Assert
QuestionExecutor.IsComplete(wrapped).Should().BeTrue();
}
[Fact]
public void QuestionExecutor_IsComplete_WithPortableValueWrappedResult_NonNullResult_ReturnsFalse()
{
// Arrange - result with non-null Result property means "not complete"
ActionExecutorResult result = new("test", result: true);
PortableValue wrapped = new(result);
// Act & Assert
QuestionExecutor.IsComplete(wrapped).Should().BeFalse();
}
#endregion
}
@@ -0,0 +1,166 @@
// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Collections.Generic;
using Microsoft.Agents.AI.Workflows.Declarative.Kit;
namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.Kit;
public sealed class VariableTypeTests
{
[Fact]
public void IsValidPrimitivesReturnTrue()
{
Assert.True(VariableType.IsValid<bool>());
Assert.True(VariableType.IsValid<int>());
Assert.True(VariableType.IsValid<long>());
Assert.True(VariableType.IsValid<float>());
Assert.True(VariableType.IsValid<decimal>());
Assert.True(VariableType.IsValid<double>());
Assert.True(VariableType.IsValid<string>());
Assert.True(VariableType.IsValid<DateTime>());
Assert.True(VariableType.IsValid<TimeSpan>());
}
[Fact]
public void IsValidUnsupportedTypeReturnFalse()
{
Assert.False(VariableType.IsValid<Guid>());
Assert.False(VariableType.IsValid<Uri>());
}
[Fact]
public void IsListForListTypeReturnTrue()
{
VariableType listType = new(typeof(List<int>));
Assert.True(listType.IsList);
Assert.False(listType.IsRecord);
Assert.True(listType.IsValid());
}
[Fact]
public void IsRecordForDictionaryInterfaceReturnTrue()
{
VariableType recordType = new(typeof(IDictionary<string, object?>));
Assert.True(recordType.IsRecord);
Assert.False(recordType.IsList);
Assert.True(recordType.IsValid());
}
[Fact]
public void RecordFactoryCreatesSchema()
{
// Assuming the intended signature supports tuple params; adjust if needed.
VariableType nameType = new(typeof(string));
VariableType ageType = new(typeof(int));
// If the actual signature differs (params IEnumerable<...>), adapt test accordingly.
VariableType recordType = VariableType.Record(
[("name", nameType), ("age", ageType)]
);
Assert.True(recordType.IsRecord);
Assert.True(recordType.HasSchema);
Assert.NotNull(recordType.Schema);
Assert.Equal(2, recordType.Schema.Count);
Assert.True(recordType.Schema.ContainsKey("name"));
Assert.True(recordType.Schema.ContainsKey("age"));
Assert.Equal(typeof(string), recordType.Schema["name"].Type);
Assert.Equal(typeof(int), recordType.Schema["age"].Type);
}
[Fact]
public void EqualsPrimitiveTypeEquality()
{
VariableType t1 = new(typeof(int));
VariableType t2 = new(typeof(int));
VariableType t3 = new(typeof(string));
Assert.True(t1.Equals(t2));
Assert.True(t1.Equals(typeof(int)));
Assert.False(t1.Equals(t3));
Assert.False(t1.Equals(typeof(string)));
}
[Fact]
public void EqualsRecordEqualityIgnoresOrder()
{
VariableType strType = new(typeof(string));
VariableType intType = new(typeof(int));
VariableType recordA = VariableType.Record(
[("first", strType), ("second", intType)]
);
VariableType recordB = VariableType.Record(
[("second", intType), ("first", strType)]
);
Assert.True(recordA.Equals(recordB));
Assert.True(recordB.Equals(recordA));
}
[Fact]
public void EqualsRecordInequalityDifferentSchema()
{
VariableType strType = new(typeof(string));
VariableType intType = new(typeof(int));
VariableType recordA = VariableType.Record(
[("first", strType), ("second", intType)]
);
VariableType recordB = VariableType.Record(
[("first", strType)]
);
Assert.False(recordA.Equals(recordB));
Assert.False(recordB.Equals(recordA));
}
[Fact]
public void GetHashCodePrimitiveConsistency()
{
VariableType a = new(typeof(double));
VariableType b = new(typeof(double));
Assert.Equal(a, b);
Assert.Equal(a, typeof(double));
Assert.Equal(a.GetHashCode(), b.GetHashCode());
}
[Fact]
public void GetHashCodeRecordConsistency()
{
VariableType a = VariableType.Record(("a", typeof(string)), ("b", typeof(int)));
VariableType b = VariableType.Record(("a", typeof(string)), ("b", typeof(int)));
Assert.Equal(a, b);
Assert.NotEqual(a.GetHashCode(), b.GetHashCode());
}
[Fact]
public void HasSchemaFalseForNonRecord()
{
VariableType primitive = new(typeof(int));
Assert.False(primitive.HasSchema);
}
[Fact]
public void ImplicitOperatorFromTypeWrapsCorrectly()
{
VariableType vt = typeof(string);
Assert.Equal(typeof(string), vt.Type);
Assert.True(vt.IsValid());
}
[Fact]
public void EqualsNullAndDifferentTypes()
{
VariableType vt = new(typeof(int));
VariableType? nullType = null;
object? nullObj = null;
object different = "test";
Assert.False(vt.Equals(nullObj));
Assert.False(vt.Equals(nullType));
Assert.False(vt.Equals(different));
Assert.True(vt.Equals((object)typeof(int)));
}
}