From bcfdbea1c51f6c3928fa1057094ee25f17ffd5fc Mon Sep 17 00:00:00 2001 From: William Fu-Hinthorn <13333726+hinthornw@users.noreply.github.com> Date: Thu, 15 Feb 2024 07:49:48 -0800 Subject: [PATCH] some test deps --- dotnet/LangSmith/Client.cs | 10 +- dotnet/LangSmith/ClientTest.cs | 97 +++++++++ dotnet/LangSmith/LangSmith.csproj | 5 + .../Debug/net8.0/LangSmith.AssemblyInfo.cs | 2 +- .../net8.0/LangSmith.AssemblyInfoInputs.cache | 2 +- .../obj/Debug/net8.0/LangSmith.assets.cache | Bin 148 -> 3114 bytes .../LangSmith.csproj.AssemblyReference.cache | Bin 0 -> 2105 bytes .../obj/LangSmith.csproj.nuget.dgspec.json | 10 + .../obj/LangSmith.csproj.nuget.g.props | 3 + dotnet/LangSmith/obj/project.assets.json | 203 +++++++++++++++++- dotnet/LangSmith/obj/project.nuget.cache | 9 +- 11 files changed, 332 insertions(+), 9 deletions(-) create mode 100644 dotnet/LangSmith/ClientTest.cs create mode 100644 dotnet/LangSmith/obj/Debug/net8.0/LangSmith.csproj.AssemblyReference.cache diff --git a/dotnet/LangSmith/Client.cs b/dotnet/LangSmith/Client.cs index f5a775791..4f6d1b2d9 100644 --- a/dotnet/LangSmith/Client.cs +++ b/dotnet/LangSmith/Client.cs @@ -68,8 +68,9 @@ public class Client private readonly HttpClient _httpClient; private readonly ClientConfig _config; private readonly ConcurrentQueue _autoBatchQueue = new ConcurrentQueue(); + private IConfig @object; - public Client(ClientConfig config) + public Client(ClientConfig config, HttpClient httpClient) { _config = config ?? throw new ArgumentNullException(nameof(config)); _httpClient = new HttpClient @@ -83,6 +84,11 @@ public Client(ClientConfig config) } } + public Client(IConfig @object) + { + this.@object = @object; + } + public async Task CreateRunAsync(CreateRunParams runParams) { if (runParams != null) @@ -132,7 +138,7 @@ private void TriggerBatchProcessingIfNeeded() { if (_autoBatchQueue.Count >= _config.PendingAutoBatchedRunLimit) { - Task.Run(async () => await ProcessAutoBatchQueueAsync()); + Task.Run(ProcessAutoBatchQueueAsync); } } diff --git a/dotnet/LangSmith/ClientTest.cs b/dotnet/LangSmith/ClientTest.cs new file mode 100644 index 000000000..7bec3a865 --- /dev/null +++ b/dotnet/LangSmith/ClientTest.cs @@ -0,0 +1,97 @@ +using NUnit.Framework; +using LangSmith; +using System.Threading.Tasks; +using System.Collections.Generic; +using Moq.Protected; // Needed for mocking HttpMessageHandler +using System.Net.Http; +using System.Threading; +using System.Net; +using System.Text.Json; +using Moq; + +[TestFixture] +public class ClientTest +{ + private Client _client; + private ClientConfig _config; + private Mock _handlerMock; + + [SetUp] + public void Setup() + { + _config = new ClientConfig + { + ApiUrl = "https://api.smith.langchain.com", + ApiKey = "test-api-key", + AutoBatchTracing = true, + TimeoutMs = 12000, + PendingAutoBatchedRunLimit = 100 + }; + + _handlerMock = new Mock(); + var httpClient = new HttpClient(_handlerMock.Object) + { + BaseAddress = new System.Uri(_config.ApiUrl), + }; + + _client = new Client(_config, httpClient); // Adjust Client constructor to accept HttpClient for testing + } + + [Test] + public async Task CreateRunAsync_WithValidParamsAndAutoBatchTracingEnabled_ReturnsQueuedRunResult() + { + // Arrange + var runParams = new CreateRunParams { Name = "Test Run", Id = "test-id" }; + _config.AutoBatchTracing = true; + + // Simulate queued response without actual HTTP call + _handlerMock + .Protected() + .Setup>( + "SendAsync", + ItExpr.IsAny(), + ItExpr.IsAny() + ) + .ReturnsAsync(new HttpResponseMessage + { + StatusCode = HttpStatusCode.OK, + Content = new StringContent(JsonSerializer.Serialize(new RunResult { Success = true, Message = "Run creation queued" })) + }); + + // Act + var result = await _client.CreateRunAsync(runParams); + + // Assert + Assert.IsTrue(result.Success); + Assert.AreEqual("Run creation queued", result.Message); + } + + [Test] + public async Task CreateRunAsync_WithValidParamsAndAutoBatchTracingDisabled_ReturnsRunResultFromPostAsync() + { + // Arrange + var runParams = new CreateRunParams(); + _configMock.Setup(c => c.AutoBatchTracing).Returns(false); + var expectedPath = "/runs"; + var expectedRunResult = new RunResult { Success = true, Message = "Test Run Result" }; + _client.PostAsync(expectedPath, runParams).Returns(expectedRunResult); + + // Act + var result = await _client.CreateRunAsync(runParams); + + // Assert + Assert.AreEqual(expectedRunResult, result); + _configMock.Verify(c => c.AutoBatchTracing, Times.Once); + _client.Verify(c => c.PostAsync(expectedPath, runParams), Times.Once); + } + + [Test] + public void CreateRunAsync_WithNullParams_ThrowsArgumentNullException() + { + // Arrange + CreateRunParams runParams = null; + + // Act & Assert + Assert.ThrowsAsync(() => _client.CreateRunAsync(runParams)); + } +} \ No newline at end of file diff --git a/dotnet/LangSmith/LangSmith.csproj b/dotnet/LangSmith/LangSmith.csproj index bb23fb7d6..0eb752fe9 100644 --- a/dotnet/LangSmith/LangSmith.csproj +++ b/dotnet/LangSmith/LangSmith.csproj @@ -6,4 +6,9 @@ enable + + + + + diff --git a/dotnet/LangSmith/obj/Debug/net8.0/LangSmith.AssemblyInfo.cs b/dotnet/LangSmith/obj/Debug/net8.0/LangSmith.AssemblyInfo.cs index 8fed07439..c0f90b3a1 100644 --- a/dotnet/LangSmith/obj/Debug/net8.0/LangSmith.AssemblyInfo.cs +++ b/dotnet/LangSmith/obj/Debug/net8.0/LangSmith.AssemblyInfo.cs @@ -13,7 +13,7 @@ [assembly: System.Reflection.AssemblyCompanyAttribute("LangSmith")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+d8b863758624f78ace060f4ab866f80d254aa5d7")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c14c9fb4b272f5d5998e8a2fcf7e53bfacde1111")] [assembly: System.Reflection.AssemblyProductAttribute("LangSmith")] [assembly: System.Reflection.AssemblyTitleAttribute("LangSmith")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/dotnet/LangSmith/obj/Debug/net8.0/LangSmith.AssemblyInfoInputs.cache b/dotnet/LangSmith/obj/Debug/net8.0/LangSmith.AssemblyInfoInputs.cache index d5d798d05..bc2ada53a 100644 --- a/dotnet/LangSmith/obj/Debug/net8.0/LangSmith.AssemblyInfoInputs.cache +++ b/dotnet/LangSmith/obj/Debug/net8.0/LangSmith.AssemblyInfoInputs.cache @@ -1 +1 @@ -3b84794afe51ab4e4a7e81e9ba93bc891d9b74009cf7304dc48a131cdc3a82d0 +7fdc29b12e858a4f995d7fdf5a3519db6e6303b14ca260055580c106d48d5992 diff --git a/dotnet/LangSmith/obj/Debug/net8.0/LangSmith.assets.cache b/dotnet/LangSmith/obj/Debug/net8.0/LangSmith.assets.cache index 0441e6d098c98129533f12981ce896b55523954d..f20e6f7b35bcb4bd3c36664851b6642b193a1df4 100644 GIT binary patch literal 3114 zcmcguOHUI~6h>(+SRO)E5EK*z(Zx*hMcfz(1=0wF@GyqmFug4k=27O}f=zUzYZDjl zT>2wi;L^X~!nKJD6BB=c3%@fR!l9WC1{!YiG3DHQ&v)jYZ_YhS&*r8&T3T9uefsFV z{pNr9`|juL*Y9sWeE##}cgM)9Cwuo-Uc6sl-y3hoqHrYfoYU8&@TI<6+|)Iht}scfN{o-g!=+JrWt+t!Be3iU|K>eIE!X-sMb+inegp271hK>sHI;&>dx z;dtBn1MOZ`o6K_W3*I*OdJbO5YYHH*ZNN;7SGVF?3VySPV-Cz((Kj5i>-k%pfsTb3 z&I81d2If!BV2hGrR^x~$X{8tV2P$Rtw;?$lZ$IOWBN51!%FkSl*X?8Jd-3Y0F=}o zfRfq^WPppnCEzm92c!d*S|<1RQL1Pkr7CJ)KkOvK!I)FUbRf;9$p58d(>v1O@;|2R znKv%`Cdi$6=5lYI%o`A#io6*&mp3J)nRSj*LW3uoJ`>`&0t^6yz*XQHFa#V^2&k(2 zY+MM$M)fa>Z5Z|@2!%0op#&iH1gf)Hh*^ikj@VfKgx!xDBXNe}kC7 z#}QCe;AF249HwC0!QZaM%A8P3wKgYTNV6L*!>693F|s^28T3A#ONQFayWy?@cImS1 z!6l2UE)}*ky=+<7($wzFWYC)ovFV83WHe^_ps|R%ev?6maF_XsxvMGo#3Fj5RQTeV zyv#dg+cGU>S979hxuTGqHEb!`mWA}}9Z^WE`W2C&qZx})hI4TF$1P)BTl@`b59zuMo(anEw?%g-0k%2`EA_^l`blZ}=i5&u65HaM#Q delta 85 zcmZ1_F@;exz}wxChk=1%xiWX^?3fS0{}O88*cyr diff --git a/dotnet/LangSmith/obj/Debug/net8.0/LangSmith.csproj.AssemblyReference.cache b/dotnet/LangSmith/obj/Debug/net8.0/LangSmith.csproj.AssemblyReference.cache new file mode 100644 index 0000000000000000000000000000000000000000..7305f414b0a5713e0920946ca9dead589847bd5b GIT binary patch literal 2105 zcmZQ$WMyDrV070HElw>e)-O-X(AUc=O;0V+FGx(zPE1cN)=y3>F3CyNOU^G!)i>2M z)HBr2$xPDEOD!?eGthU2NIC;0^-^+j7#V@4F}QDB|H*q}=I*`X>Eb3s_e&z0eg3nO zrKSEoTq^%>om1KDJR|NN?{9H|UH zzU6i*mNZxd{JVKbN%hc~|DWV7Ppt3Sztk~WEam-$8xNL!{}gB~BbYk-hP(2eN`}K% z8h02kx6(c@chg7g$i9@T&Os+K!%oaJaPgaUFi_=krky?042c(x{9?s3ukD;_LcAd;PB7F!(@q~O{Xs$Ahn6X5e+I__ zKbjhFjDYNf=LDz&$cPcccZ&-)&hY+~E4Mu1;i-hwb5EqC)aNWRnQZ^Ee8Ds&9X^qt zPZ!pPbsEIv)(f$%hzdT^vp|4@ede`y?-NgU?Ug92P`|@^>s5CCUcI&!ft&lDzARe6 za`)P#dnbN5crS^RYpLq_9Q#N{*Iao|Z+TSO)+uXWPb)Pqn*V5t+g6XW;mg1=qGoZH zHId!rHDeH(PmyB>7;ePGjggtLMRJOPshOdHxrs??5p_$b-oN;>xxBB1XC^I4v|-rsEA^Vpxd*48eoi(xxj^2rIds1C zdzCYq;>T_ZKVIr+Y$eNjbKfOxi__q&ccxnS|5@F;fsAo@e2s`zaM%))4U?12lMId1 Q(vnk*Qc_Y(4Pn6s0I)Kv4gdfE literal 0 HcmV?d00001 diff --git a/dotnet/LangSmith/obj/LangSmith.csproj.nuget.dgspec.json b/dotnet/LangSmith/obj/LangSmith.csproj.nuget.dgspec.json index f538206e2..e16225197 100644 --- a/dotnet/LangSmith/obj/LangSmith.csproj.nuget.dgspec.json +++ b/dotnet/LangSmith/obj/LangSmith.csproj.nuget.dgspec.json @@ -37,6 +37,16 @@ "frameworks": { "net8.0": { "targetAlias": "net8.0", + "dependencies": { + "NUnit": { + "target": "Package", + "version": "[4.0.1, )" + }, + "moq": { + "target": "Package", + "version": "[4.20.70, )" + } + }, "imports": [ "net461", "net462", diff --git a/dotnet/LangSmith/obj/LangSmith.csproj.nuget.g.props b/dotnet/LangSmith/obj/LangSmith.csproj.nuget.g.props index ab10f8b13..701f8be2b 100644 --- a/dotnet/LangSmith/obj/LangSmith.csproj.nuget.g.props +++ b/dotnet/LangSmith/obj/LangSmith.csproj.nuget.g.props @@ -12,4 +12,7 @@ + + + \ No newline at end of file diff --git a/dotnet/LangSmith/obj/project.assets.json b/dotnet/LangSmith/obj/project.assets.json index 1779dff7c..3cbdf0796 100644 --- a/dotnet/LangSmith/obj/project.assets.json +++ b/dotnet/LangSmith/obj/project.assets.json @@ -1,11 +1,198 @@ { "version": 3, "targets": { - "net8.0": {} + "net8.0": { + "Castle.Core/5.1.1": { + "type": "package", + "dependencies": { + "System.Diagnostics.EventLog": "6.0.0" + }, + "compile": { + "lib/net6.0/Castle.Core.dll": { + "related": ".xml" + } + }, + "runtime": { + "lib/net6.0/Castle.Core.dll": { + "related": ".xml" + } + } + }, + "Moq/4.20.70": { + "type": "package", + "dependencies": { + "Castle.Core": "5.1.1" + }, + "compile": { + "lib/net6.0/Moq.dll": { + "related": ".xml" + } + }, + "runtime": { + "lib/net6.0/Moq.dll": { + "related": ".xml" + } + } + }, + "NUnit/4.0.1": { + "type": "package", + "compile": { + "lib/net6.0/nunit.framework.dll": { + "related": ".legacy.xml;.xml" + }, + "lib/net6.0/nunit.framework.legacy.dll": { + "related": ".xml" + } + }, + "runtime": { + "lib/net6.0/nunit.framework.dll": { + "related": ".legacy.xml;.xml" + }, + "lib/net6.0/nunit.framework.legacy.dll": { + "related": ".xml" + } + }, + "build": { + "build/NUnit.props": {} + } + }, + "System.Diagnostics.EventLog/6.0.0": { + "type": "package", + "compile": { + "lib/net6.0/System.Diagnostics.EventLog.dll": { + "related": ".xml" + } + }, + "runtime": { + "lib/net6.0/System.Diagnostics.EventLog.dll": { + "related": ".xml" + } + }, + "build": { + "buildTransitive/netcoreapp3.1/_._": {} + }, + "runtimeTargets": { + "runtimes/win/lib/net6.0/System.Diagnostics.EventLog.Messages.dll": { + "assetType": "runtime", + "rid": "win" + }, + "runtimes/win/lib/net6.0/System.Diagnostics.EventLog.dll": { + "assetType": "runtime", + "rid": "win" + } + } + } + } + }, + "libraries": { + "Castle.Core/5.1.1": { + "sha512": "rpYtIczkzGpf+EkZgDr9CClTdemhsrwA/W5hMoPjLkRFnXzH44zDLoovXeKtmxb1ykXK9aJVODSpiJml8CTw2g==", + "type": "package", + "path": "castle.core/5.1.1", + "files": [ + ".nupkg.metadata", + ".signature.p7s", + "ASL - Apache Software Foundation License.txt", + "CHANGELOG.md", + "LICENSE", + "castle-logo.png", + "castle.core.5.1.1.nupkg.sha512", + "castle.core.nuspec", + "lib/net462/Castle.Core.dll", + "lib/net462/Castle.Core.xml", + "lib/net6.0/Castle.Core.dll", + "lib/net6.0/Castle.Core.xml", + "lib/netstandard2.0/Castle.Core.dll", + "lib/netstandard2.0/Castle.Core.xml", + "lib/netstandard2.1/Castle.Core.dll", + "lib/netstandard2.1/Castle.Core.xml", + "readme.txt" + ] + }, + "Moq/4.20.70": { + "sha512": "4rNnAwdpXJBuxqrOCzCyICXHSImOTRktCgCWXWykuF1qwoIsVvEnR7PjbMk/eLOxWvhmj5Kwt+kDV3RGUYcNwg==", + "type": "package", + "path": "moq/4.20.70", + "files": [ + ".nupkg.metadata", + ".signature.p7s", + "icon.png", + "lib/net462/Moq.dll", + "lib/net462/Moq.xml", + "lib/net6.0/Moq.dll", + "lib/net6.0/Moq.xml", + "lib/netstandard2.0/Moq.dll", + "lib/netstandard2.0/Moq.xml", + "lib/netstandard2.1/Moq.dll", + "lib/netstandard2.1/Moq.xml", + "moq.4.20.70.nupkg.sha512", + "moq.nuspec", + "readme.md" + ] + }, + "NUnit/4.0.1": { + "sha512": "jNTHZ01hJsDNPDSBycoHpavFZUBf9vRVQLCyuo78LRrrFj6Ol/CeqK+NIeTk5d8Eycjk59KseWb7X5Ge6z7CgQ==", + "type": "package", + "path": "nunit/4.0.1", + "files": [ + ".nupkg.metadata", + ".signature.p7s", + "CHANGES.md", + "LICENSE.txt", + "NOTICES.md", + "README.md", + "THIRD_PARTY_NOTICES.md", + "build/NUnit.props", + "icon.png", + "lib/net462/nunit.framework.dll", + "lib/net462/nunit.framework.legacy.dll", + "lib/net462/nunit.framework.legacy.xml", + "lib/net462/nunit.framework.xml", + "lib/net6.0/nunit.framework.dll", + "lib/net6.0/nunit.framework.legacy.dll", + "lib/net6.0/nunit.framework.legacy.xml", + "lib/net6.0/nunit.framework.xml", + "nunit.4.0.1.nupkg.sha512", + "nunit.nuspec" + ] + }, + "System.Diagnostics.EventLog/6.0.0": { + "sha512": "lcyUiXTsETK2ALsZrX+nWuHSIQeazhqPphLfaRxzdGaG93+0kELqpgEHtwWOlQe7+jSFnKwaCAgL4kjeZCQJnw==", + "type": "package", + "path": "system.diagnostics.eventlog/6.0.0", + "files": [ + ".nupkg.metadata", + ".signature.p7s", + "Icon.png", + "LICENSE.TXT", + "THIRD-PARTY-NOTICES.TXT", + "buildTransitive/netcoreapp2.0/System.Diagnostics.EventLog.targets", + "buildTransitive/netcoreapp3.1/_._", + "lib/net461/System.Diagnostics.EventLog.dll", + "lib/net461/System.Diagnostics.EventLog.xml", + "lib/net6.0/System.Diagnostics.EventLog.dll", + "lib/net6.0/System.Diagnostics.EventLog.xml", + "lib/netcoreapp3.1/System.Diagnostics.EventLog.dll", + "lib/netcoreapp3.1/System.Diagnostics.EventLog.xml", + "lib/netstandard2.0/System.Diagnostics.EventLog.dll", + "lib/netstandard2.0/System.Diagnostics.EventLog.xml", + "runtimes/win/lib/net6.0/System.Diagnostics.EventLog.Messages.dll", + "runtimes/win/lib/net6.0/System.Diagnostics.EventLog.dll", + "runtimes/win/lib/net6.0/System.Diagnostics.EventLog.xml", + "runtimes/win/lib/netcoreapp3.1/System.Diagnostics.EventLog.Messages.dll", + "runtimes/win/lib/netcoreapp3.1/System.Diagnostics.EventLog.dll", + "runtimes/win/lib/netcoreapp3.1/System.Diagnostics.EventLog.xml", + "system.diagnostics.eventlog.6.0.0.nupkg.sha512", + "system.diagnostics.eventlog.nuspec", + "useSharedDesignerContext.txt" + ] + } }, - "libraries": {}, "projectFileDependencyGroups": { - "net8.0": [] + "net8.0": [ + "NUnit >= 4.0.1", + "moq >= 4.20.70" + ] }, "packageFolders": { "/Users/wfh/.nuget/packages/": {} @@ -43,6 +230,16 @@ "frameworks": { "net8.0": { "targetAlias": "net8.0", + "dependencies": { + "NUnit": { + "target": "Package", + "version": "[4.0.1, )" + }, + "moq": { + "target": "Package", + "version": "[4.20.70, )" + } + }, "imports": [ "net461", "net462", diff --git a/dotnet/LangSmith/obj/project.nuget.cache b/dotnet/LangSmith/obj/project.nuget.cache index 7ccca0ace..7041c7c1b 100644 --- a/dotnet/LangSmith/obj/project.nuget.cache +++ b/dotnet/LangSmith/obj/project.nuget.cache @@ -1,8 +1,13 @@ { "version": 2, - "dgSpecHash": "Zr3kAlURx4wPCS2psSXDQ5TzwUewoNav93uSW2hXRmmYyWbKxfgKUaXmbI8RZlskhO6QmjkWJWULybIc0TrNOQ==", + "dgSpecHash": "df93G06536s3ge2+qlmdEm7GWMbTNaOK53PMCgtepS50C5ry5DKKaNuLaii2oDhzlWdiCTPJK+vpmFSoSoO3+w==", "success": true, "projectFilePath": "/Users/wfh/code/lc/langchainplus-sdk/dotnet/LangSmith/LangSmith.csproj", - "expectedPackageFiles": [], + "expectedPackageFiles": [ + "/Users/wfh/.nuget/packages/castle.core/5.1.1/castle.core.5.1.1.nupkg.sha512", + "/Users/wfh/.nuget/packages/moq/4.20.70/moq.4.20.70.nupkg.sha512", + "/Users/wfh/.nuget/packages/nunit/4.0.1/nunit.4.0.1.nupkg.sha512", + "/Users/wfh/.nuget/packages/system.diagnostics.eventlog/6.0.0/system.diagnostics.eventlog.6.0.0.nupkg.sha512" + ], "logs": [] } \ No newline at end of file