Skip to content

Commit

Permalink
.Net Processes - Update shared code pattern (#9438)
Browse files Browse the repository at this point in the history
### Motivation and Context
<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->

Shared code causing type collisions when used outside of _Runtime_
projects.

### Description
<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

- Separate shared code for _Runtime_ projects from that which is
targeted for _Core_ and _Abstractions_
- Isolate testing of shared code into its own project:
`Process.Utilities.UnitTests`
- Must never grant internal visiblity to `Process.Utilities.UnitTests`
- Must never add reference from `Process.Utilities.UnitTests` to
_Runtime_ projects
- Must never allow common utilities to be `public`

### Contribution Checklist
<!-- Before submitting this PR, please make sure: -->

- [X] The code builds clean without any errors or warnings
- [X] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [X] All unit tests pass, and I have added new tests where possible
- [X] I didn't break anyone 😄
  • Loading branch information
crickman authored Oct 25, 2024
1 parent 55596a9 commit ea5ceb1
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 21 deletions.
34 changes: 22 additions & 12 deletions dotnet/SK-dotnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MongoDB", "MongoDB", "{AF7F
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Connectors.Pinecone.UnitTests", "src\Connectors\Connectors.Pinecone.UnitTests\Connectors.Pinecone.UnitTests.csproj", "{E82B640C-1704-430D-8D71-FD8ED3695468}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AotCompatibility", "samples\Demos\AotCompatibility\AotCompatibility.csproj", "{6ECFDF04-2237-4A85-B114-DAA34923E9E6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SemanticKernel.AotTests", "src\SemanticKernel.AotTests\SemanticKernel.AotTests.csproj", "{39EAB599-742F-417D-AF80-95F90376BB18}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Process.Utilities.UnitTests", "src\Experimental\Process.Utilities.UnitTests\Process.Utilities.UnitTests.csproj", "{DAC54048-A39A-4739-8307-EA5A291F2EA0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1012,18 +1015,6 @@ Global
{95163AA2-1ED5-412A-990B-C40B81934BFD}.Publish|Any CPU.Build.0 = Debug|Any CPU
{95163AA2-1ED5-412A-990B-C40B81934BFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95163AA2-1ED5-412A-990B-C40B81934BFD}.Release|Any CPU.Build.0 = Release|Any CPU
{6ECFDF04-2237-4A85-B114-DAA34923E9E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6ECFDF04-2237-4A85-B114-DAA34923E9E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6ECFDF04-2237-4A85-B114-DAA34923E9E6}.Publish|Any CPU.ActiveCfg = Publish|Any CPU
{6ECFDF04-2237-4A85-B114-DAA34923E9E6}.Publish|Any CPU.Build.0 = Publish|Any CPU
{6ECFDF04-2237-4A85-B114-DAA34923E9E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6ECFDF04-2237-4A85-B114-DAA34923E9E6}.Release|Any CPU.Build.0 = Release|Any CPU
{39EAB599-742F-417D-AF80-95F90376BB18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{39EAB599-742F-417D-AF80-95F90376BB18}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39EAB599-742F-417D-AF80-95F90376BB18}.Publish|Any CPU.ActiveCfg = Publish|Any CPU
{39EAB599-742F-417D-AF80-95F90376BB18}.Publish|Any CPU.Build.0 = Publish|Any CPU
{39EAB599-742F-417D-AF80-95F90376BB18}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39EAB599-742F-417D-AF80-95F90376BB18}.Release|Any CPU.Build.0 = Release|Any CPU
{6F591D05-5F7F-4211-9042-42D8BCE60415}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6F591D05-5F7F-4211-9042-42D8BCE60415}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F591D05-5F7F-4211-9042-42D8BCE60415}.Publish|Any CPU.ActiveCfg = Debug|Any CPU
Expand All @@ -1036,6 +1027,24 @@ Global
{E82B640C-1704-430D-8D71-FD8ED3695468}.Publish|Any CPU.Build.0 = Debug|Any CPU
{E82B640C-1704-430D-8D71-FD8ED3695468}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E82B640C-1704-430D-8D71-FD8ED3695468}.Release|Any CPU.Build.0 = Release|Any CPU
{6ECFDF04-2237-4A85-B114-DAA34923E9E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6ECFDF04-2237-4A85-B114-DAA34923E9E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6ECFDF04-2237-4A85-B114-DAA34923E9E6}.Publish|Any CPU.ActiveCfg = Publish|Any CPU
{6ECFDF04-2237-4A85-B114-DAA34923E9E6}.Publish|Any CPU.Build.0 = Publish|Any CPU
{6ECFDF04-2237-4A85-B114-DAA34923E9E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6ECFDF04-2237-4A85-B114-DAA34923E9E6}.Release|Any CPU.Build.0 = Release|Any CPU
{39EAB599-742F-417D-AF80-95F90376BB18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{39EAB599-742F-417D-AF80-95F90376BB18}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39EAB599-742F-417D-AF80-95F90376BB18}.Publish|Any CPU.ActiveCfg = Publish|Any CPU
{39EAB599-742F-417D-AF80-95F90376BB18}.Publish|Any CPU.Build.0 = Publish|Any CPU
{39EAB599-742F-417D-AF80-95F90376BB18}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39EAB599-742F-417D-AF80-95F90376BB18}.Release|Any CPU.Build.0 = Release|Any CPU
{DAC54048-A39A-4739-8307-EA5A291F2EA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DAC54048-A39A-4739-8307-EA5A291F2EA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DAC54048-A39A-4739-8307-EA5A291F2EA0}.Publish|Any CPU.ActiveCfg = Debug|Any CPU
{DAC54048-A39A-4739-8307-EA5A291F2EA0}.Publish|Any CPU.Build.0 = Debug|Any CPU
{DAC54048-A39A-4739-8307-EA5A291F2EA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DAC54048-A39A-4739-8307-EA5A291F2EA0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1179,6 +1188,7 @@ Global
{E82B640C-1704-430D-8D71-FD8ED3695468} = {5A7028A7-4DDF-4E4F-84A9-37CE8F8D7E89}
{6ECFDF04-2237-4A85-B114-DAA34923E9E6} = {5D4C0700-BBB5-418F-A7B2-F392B9A18263}
{39EAB599-742F-417D-AF80-95F90376BB18} = {831DDCA2-7D2C-4C31-80DB-6BDB3E1F7AE0}
{DAC54048-A39A-4739-8307-EA5A291F2EA0} = {0D8C6358-5DAA-4EA6-A924-C268A9A21BC9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FBDC56A3-86AD-4323-AA0F-201E59123B83}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<Import Project="$(RepoRoot)/dotnet/nuget/nuget-package.props" />
<Import Project="$(RepoRoot)/dotnet/src/InternalUtilities/src/InternalUtilities.props" />
<Import Project="$(RepoRoot)/dotnet/src/InternalUtilities/process/InternalUtilities.props" />

<PropertyGroup>
<!-- NuGet Package Settings -->
Expand Down
1 change: 1 addition & 0 deletions dotnet/src/Experimental/Process.Core/Process.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<Import Project="$(RepoRoot)/dotnet/nuget/nuget-package.props" />
<Import Project="$(RepoRoot)/dotnet/src/InternalUtilities/src/InternalUtilities.props" />
<Import Project="$(RepoRoot)/dotnet/src/InternalUtilities/process/InternalUtilities.props" />

<PropertyGroup>
<!-- NuGet Package Settings -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<Import Project="$(RepoRoot)/dotnet/nuget/nuget-package.props" />
<Import Project="$(RepoRoot)/dotnet/src/InternalUtilities/src/InternalUtilities.props" />
<Import Project="$(RepoRoot)/dotnet/src/InternalUtilities/process/InternalUtilities.props" />
<Import Project="$(RepoRoot)/dotnet/src/InternalUtilities/process/RuntimeUtilities.props" />

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<Import Project="$(RepoRoot)/dotnet/nuget/nuget-package.props" />
<Import Project="$(RepoRoot)/dotnet/src/InternalUtilities/src/InternalUtilities.props" />
<Import Project="$(RepoRoot)/dotnet/src/InternalUtilities/process/InternalUtilities.props" />
<Import Project="$(RepoRoot)/dotnet/src/InternalUtilities/process/RuntimeUtilities.props" />

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Process.Runtime;
using Xunit;

namespace Microsoft.SemanticKernel.Process.Runtime.UnitTests;
namespace SemanticKernel.Process.Utilities.UnitTests;

/// <summary>
/// Unit tests for the ability to clone:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>SemanticKernel.Process.Utilities.UnitTests</RootNamespace>
<AssemblyName>SemanticKernel.Process.Utilities.UnitTests</AssemblyName>
<TargetFrameworks>net8.0</TargetFrameworks>
<RollForward>LatestMajor</RollForward>
<IsTestProject>true</IsTestProject>
<IsPackable>false</IsPackable>
<LangVersion>12</LangVersion>
<NoWarn>
$(NoWarn);CA2007,CA1812,CA1861,CA1063,VSTHRD111,SKEXP0001,SKEXP0050,SKEXP0080,SKEXP0110;OPENAI001</NoWarn>
</PropertyGroup>

<Import Project="$(RepoRoot)/dotnet/src/InternalUtilities/process/InternalUtilities.props" />
<Import Project="$(RepoRoot)/dotnet/src/InternalUtilities/process/RuntimeUtilities.props" />

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Moq" />
<PackageReference Include="Verify.Xunit" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\SemanticKernel.Abstractions\SemanticKernel.Abstractions.csproj" />
<ProjectReference Include="..\..\SemanticKernel.Core\SemanticKernel.Core.csproj" />
<ProjectReference Include="..\Process.Abstractions\Process.Abstractions.csproj" />
<ProjectReference Include="..\Process.Core\Process.Core.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Runtime\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright (c) Microsoft. All rights reserved.
using System.IO;
using SemanticKernel.Process.UnitTests.Runtime;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Process.Runtime;
using Xunit;

namespace Microsoft.SemanticKernel.Process.Runtime.UnitTests;
namespace SemanticKernel.Process.Utilities.UnitTests;

/// <summary>
/// Unit tests for the <see cref="LocalProcess"/> class.
/// Unit tests for the <see cref="ProcessEvent"/> class.
/// </summary>
public class ProcessEventTests
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) Microsoft. All rights reserved.
using System.IO;
using SemanticKernel.Process.UnitTests.Runtime;
using Microsoft.SemanticKernel.Process.Runtime;
using Xunit;

namespace Microsoft.SemanticKernel.Process.Runtime.UnitTests;
namespace SemanticKernel.Process.Utilities.UnitTests;

/// <summary>
/// Unit tests for the <see cref="LocalProcess"/> class.
/// Unit tests for the <see cref="ProcessMessage"/> class.
/// </summary>
public class ProcessMessageTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Text;
using System.Xml;

namespace SemanticKernel.Process.UnitTests.Runtime;
namespace SemanticKernel.Process.Utilities.UnitTests;

internal static class TestSerializer
{
Expand Down
5 changes: 5 additions & 0 deletions dotnet/src/InternalUtilities/process/InternalUtilities.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<ItemGroup>
<Compile Include="$(RepoRoot)/dotnet/src/InternalUtilities/process/Internal/**/*.cs" Link="%(RecursiveDir)Internal/%(Filename)%(Extension)" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<ItemGroup>
<Compile Include="$(RepoRoot)/dotnet/src/InternalUtilities/process/**/*.cs" Link="%(RecursiveDir)Runtime/%(Filename)%(Extension)" />
<Compile Include="$(RepoRoot)/dotnet/src/InternalUtilities/process/Runtime/**/*.cs" Link="%(RecursiveDir)Runtime/%(Filename)%(Extension)" />
</ItemGroup>
</Project>

0 comments on commit ea5ceb1

Please sign in to comment.