@tracecode/harness 0.6.6 → 0.7.0-beta8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/README.md +134 -15
- package/THIRD_PARTY_NOTICES.md +170 -0
- package/dist/browser.cjs +2361 -1033
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +33 -3
- package/dist/browser.d.ts +33 -3
- package/dist/browser.js +2357 -1033
- package/dist/browser.js.map +1 -1
- package/dist/cli.cjs +160 -23
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +161 -24
- package/dist/cli.js.map +1 -1
- package/dist/core.cjs +748 -867
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +21 -85
- package/dist/core.d.ts +21 -85
- package/dist/core.js +734 -855
- package/dist/core.js.map +1 -1
- package/dist/cpp-worker-client-Bn7kC0_L.d.ts +84 -0
- package/dist/cpp-worker-client-BzdJLuZa.d.cts +84 -0
- package/dist/cpp.cjs +1063 -0
- package/dist/cpp.cjs.map +1 -0
- package/dist/cpp.d.cts +7 -0
- package/dist/cpp.d.ts +7 -0
- package/dist/cpp.js +1035 -0
- package/dist/cpp.js.map +1 -0
- package/dist/csharp-worker-client-DMHIa2YG.d.cts +69 -0
- package/dist/csharp-worker-client-JwqS6LiX.d.ts +69 -0
- package/dist/csharp.cjs +1012 -0
- package/dist/csharp.cjs.map +1 -0
- package/dist/csharp.d.cts +7 -0
- package/dist/csharp.d.ts +7 -0
- package/dist/csharp.js +984 -0
- package/dist/csharp.js.map +1 -0
- package/dist/index.cjs +3142 -1160
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -5
- package/dist/index.d.ts +13 -5
- package/dist/index.js +3117 -1148
- package/dist/index.js.map +1 -1
- package/dist/internal/browser.cjs +1639 -30
- package/dist/internal/browser.cjs.map +1 -1
- package/dist/internal/browser.d.cts +6 -199
- package/dist/internal/browser.d.ts +6 -199
- package/dist/internal/browser.js +1636 -30
- package/dist/internal/browser.js.map +1 -1
- package/dist/java-worker-client-BOwKW-11.d.cts +72 -0
- package/dist/java-worker-client-C97DDnCp.d.ts +72 -0
- package/dist/java.cjs +1225 -0
- package/dist/java.cjs.map +1 -0
- package/dist/java.d.cts +7 -0
- package/dist/java.d.ts +7 -0
- package/dist/java.js +1197 -0
- package/dist/java.js.map +1 -0
- package/dist/javascript-worker-client-CYBGEEvc.d.cts +51 -0
- package/dist/javascript-worker-client-DIX1Mp21.d.ts +51 -0
- package/dist/javascript.cjs +1063 -19
- package/dist/javascript.cjs.map +1 -1
- package/dist/javascript.d.cts +7 -4
- package/dist/javascript.d.ts +7 -4
- package/dist/javascript.js +1061 -19
- package/dist/javascript.js.map +1 -1
- package/dist/pyodide-worker-client-C-2rfHj9.d.ts +111 -0
- package/dist/pyodide-worker-client-Cn0a8Uv3.d.cts +111 -0
- package/dist/python.cjs +1282 -74
- package/dist/python.cjs.map +1 -1
- package/dist/python.d.cts +20 -14
- package/dist/python.d.ts +20 -14
- package/dist/python.js +1279 -74
- package/dist/python.js.map +1 -1
- package/dist/runtime-language-info-BFUSti3-.d.ts +43 -0
- package/dist/runtime-language-info-Bxza1cI2.d.cts +43 -0
- package/dist/runtime-types-2qM0MukN.d.cts +244 -0
- package/dist/runtime-types-2qM0MukN.d.ts +244 -0
- package/package.json +73 -8
- package/workers/cpp/cpp-compiler-frame.html +82 -0
- package/workers/cpp/cpp-compiler-worker.js +131 -0
- package/workers/cpp/cpp-worker.js +5790 -0
- package/workers/cpp/tracecode_runtime.hpp +6169 -0
- package/workers/csharp/csharp-worker.js +301 -0
- package/workers/java/.build/classes/harness/browser/JavaRewriteLibrary.class +0 -0
- package/workers/java/java-source-augmentations.js +907 -0
- package/workers/java/java-worker.js +2161 -177
- package/workers/java/src/harness/browser/JavaRewriteLibrary.java +1659 -32
- package/workers/java/src/javafx/util/Pair.java +42 -0
- package/workers/java/src/tracecode/browser/BrowserCompileAndTraceLibrary.java +714 -0
- package/workers/java/src/tracecode/browser/BrowserCompileAndTraceMain.java +76 -0
- package/workers/java/src/tracecode/browser/RuntimeProbeMain.java +14 -0
- package/workers/java/src/tracecode/user/TraceHooks.java +1414 -0
- package/workers/javascript/javascript-libraries-entry.js +71 -0
- package/workers/javascript/javascript-worker.js +2055 -424
- package/workers/python/generated-python-harness-snippets.js +4 -4
- package/workers/python/pyodide-worker.js +222 -61
- package/workers/python/runtime-core.js +1387 -301
- package/workers/vendor/csharp/.stamp +0 -0
- package/workers/vendor/csharp/TraceCode.CSharpHost.runtimeconfig.json +32 -0
- package/workers/vendor/csharp/_framework/Microsoft.CSharp.wasm +0 -0
- package/workers/vendor/csharp/_framework/Microsoft.CodeAnalysis.CSharp.wasm +0 -0
- package/workers/vendor/csharp/_framework/Microsoft.CodeAnalysis.wasm +0 -0
- package/workers/vendor/csharp/_framework/Microsoft.VisualBasic.Core.wasm +0 -0
- package/workers/vendor/csharp/_framework/Microsoft.VisualBasic.wasm +0 -0
- package/workers/vendor/csharp/_framework/Microsoft.Win32.Primitives.wasm +0 -0
- package/workers/vendor/csharp/_framework/Microsoft.Win32.Registry.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.AppContext.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Buffers.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Collections.Concurrent.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Collections.Immutable.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Collections.NonGeneric.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Collections.Specialized.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Collections.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.ComponentModel.Annotations.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.ComponentModel.DataAnnotations.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.ComponentModel.EventBasedAsync.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.ComponentModel.Primitives.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.ComponentModel.TypeConverter.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.ComponentModel.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Configuration.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Console.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Core.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Data.Common.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Data.DataSetExtensions.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Data.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Diagnostics.Contracts.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Diagnostics.Debug.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Diagnostics.DiagnosticSource.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Diagnostics.FileVersionInfo.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Diagnostics.Process.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Diagnostics.StackTrace.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Diagnostics.TextWriterTraceListener.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Diagnostics.Tools.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Diagnostics.TraceSource.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Diagnostics.Tracing.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Drawing.Primitives.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Drawing.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Dynamic.Runtime.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Formats.Asn1.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Formats.Tar.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Globalization.Calendars.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Globalization.Extensions.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Globalization.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.Compression.Brotli.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.Compression.FileSystem.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.Compression.ZipFile.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.Compression.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.FileSystem.AccessControl.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.FileSystem.DriveInfo.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.FileSystem.Primitives.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.FileSystem.Watcher.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.FileSystem.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.IsolatedStorage.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.MemoryMappedFiles.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.Pipelines.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.Pipes.AccessControl.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.Pipes.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.UnmanagedMemoryStream.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Linq.AsyncEnumerable.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Linq.Expressions.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Linq.Parallel.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Linq.Queryable.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Linq.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Memory.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.Http.Json.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.Http.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.HttpListener.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.Mail.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.NameResolution.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.NetworkInformation.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.Ping.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.Primitives.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.Quic.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.Requests.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.Security.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.ServerSentEvents.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.ServicePoint.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.Sockets.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.WebClient.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.WebHeaderCollection.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.WebProxy.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.WebSockets.Client.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.WebSockets.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Numerics.Vectors.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Numerics.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.ObjectModel.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Private.CoreLib.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Private.DataContractSerialization.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Private.Uri.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Private.Xml.Linq.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Private.Xml.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Reflection.DispatchProxy.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Reflection.Emit.ILGeneration.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Reflection.Emit.Lightweight.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Reflection.Emit.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Reflection.Extensions.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Reflection.Metadata.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Reflection.Primitives.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Reflection.TypeExtensions.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Reflection.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Resources.Reader.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Resources.ResourceManager.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Resources.Writer.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.CompilerServices.Unsafe.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.CompilerServices.VisualC.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.Extensions.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.Handles.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.InteropServices.JavaScript.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.InteropServices.RuntimeInformation.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.InteropServices.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.Intrinsics.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.Loader.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.Numerics.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.Serialization.Formatters.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.Serialization.Json.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.Serialization.Primitives.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.Serialization.Xml.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.Serialization.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.AccessControl.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.Claims.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.Cryptography.Algorithms.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.Cryptography.Cng.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.Cryptography.Csp.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.Cryptography.Encoding.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.Cryptography.OpenSsl.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.Cryptography.Primitives.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.Cryptography.X509Certificates.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.Cryptography.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.Principal.Windows.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.Principal.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.SecureString.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.ServiceModel.Web.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.ServiceProcess.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Text.Encoding.CodePages.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Text.Encoding.Extensions.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Text.Encoding.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Text.Encodings.Web.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Text.Json.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Text.RegularExpressions.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Threading.AccessControl.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Threading.Channels.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Threading.Overlapped.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Threading.Tasks.Dataflow.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Threading.Tasks.Extensions.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Threading.Tasks.Parallel.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Threading.Tasks.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Threading.Thread.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Threading.ThreadPool.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Threading.Timer.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Threading.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Transactions.Local.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Transactions.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.ValueTuple.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Web.HttpUtility.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Web.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Windows.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Xml.Linq.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Xml.ReaderWriter.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Xml.Serialization.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Xml.XDocument.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Xml.XPath.XDocument.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Xml.XPath.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Xml.XmlDocument.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Xml.XmlSerializer.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Xml.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.wasm +0 -0
- package/workers/vendor/csharp/_framework/TraceCode.CSharpHost.wasm +0 -0
- package/workers/vendor/csharp/_framework/WindowsBase.wasm +0 -0
- package/workers/vendor/csharp/_framework/cs/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/cs/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/de/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/de/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/dotnet.boot.js +1958 -0
- package/workers/vendor/csharp/_framework/dotnet.js +4 -0
- package/workers/vendor/csharp/_framework/dotnet.js.map +1 -0
- package/workers/vendor/csharp/_framework/dotnet.native.js +6687 -0
- package/workers/vendor/csharp/_framework/dotnet.native.wasm +0 -0
- package/workers/vendor/csharp/_framework/dotnet.runtime.js +4 -0
- package/workers/vendor/csharp/_framework/dotnet.runtime.js.map +1 -0
- package/workers/vendor/csharp/_framework/es/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/es/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/fr/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/fr/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/it/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/it/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/ja/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/ja/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/ko/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/ko/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/mscorlib.wasm +0 -0
- package/workers/vendor/csharp/_framework/netstandard.wasm +0 -0
- package/workers/vendor/csharp/_framework/pl/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/pl/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/pt-BR/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/pt-BR/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/ru/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/ru/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/0_Microsoft.CodeAnalysis.CSharp.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/100_System.Reflection.Emit.ILGeneration.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/101_System.Reflection.Emit.Lightweight.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/102_System.Reflection.Extensions.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/103_System.Reflection.Metadata.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/104_System.Reflection.Primitives.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/105_System.Reflection.TypeExtensions.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/106_System.Resources.Reader.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/107_System.Resources.ResourceManager.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/108_System.Resources.Writer.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/109_System.Runtime.CompilerServices.Unsafe.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/10_System.Buffers.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/110_System.Runtime.CompilerServices.VisualC.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/111_System.Runtime.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/112_System.Runtime.Extensions.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/113_System.Runtime.Handles.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/114_System.Runtime.InteropServices.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/115_System.Runtime.InteropServices.JavaScript.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/116_System.Runtime.InteropServices.RuntimeInformation.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/117_System.Runtime.Intrinsics.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/118_System.Runtime.Loader.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/119_System.Runtime.Numerics.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/11_System.Collections.Concurrent.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/120_System.Runtime.Serialization.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/121_System.Runtime.Serialization.Formatters.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/122_System.Runtime.Serialization.Json.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/123_System.Runtime.Serialization.Primitives.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/124_System.Runtime.Serialization.Xml.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/125_System.Security.AccessControl.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/126_System.Security.Claims.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/127_System.Security.Cryptography.Algorithms.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/128_System.Security.Cryptography.Cng.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/129_System.Security.Cryptography.Csp.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/12_System.Collections.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/130_System.Security.Cryptography.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/131_System.Security.Cryptography.Encoding.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/132_System.Security.Cryptography.OpenSsl.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/133_System.Security.Cryptography.Primitives.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/134_System.Security.Cryptography.X509Certificates.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/135_System.Security.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/136_System.Security.Principal.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/137_System.Security.Principal.Windows.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/138_System.Security.SecureString.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/139_System.ServiceModel.Web.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/13_System.Collections.Immutable.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/140_System.ServiceProcess.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/141_System.Text.Encoding.CodePages.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/142_System.Text.Encoding.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/143_System.Text.Encoding.Extensions.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/144_System.Text.Encodings.Web.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/145_System.Text.Json.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/146_System.Text.RegularExpressions.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/147_System.Threading.AccessControl.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/148_System.Threading.Channels.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/149_System.Threading.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/14_System.Collections.NonGeneric.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/150_System.Threading.Overlapped.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/151_System.Threading.Tasks.Dataflow.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/152_System.Threading.Tasks.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/153_System.Threading.Tasks.Extensions.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/154_System.Threading.Tasks.Parallel.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/155_System.Threading.Thread.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/156_System.Threading.ThreadPool.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/157_System.Threading.Timer.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/158_System.Transactions.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/159_System.Transactions.Local.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/15_System.Collections.Specialized.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/160_System.ValueTuple.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/161_System.Web.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/162_System.Web.HttpUtility.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/163_System.Windows.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/164_System.Xml.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/165_System.Xml.Linq.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/166_System.Xml.ReaderWriter.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/167_System.Xml.Serialization.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/168_System.Xml.XDocument.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/169_System.Xml.XmlDocument.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/16_System.ComponentModel.Annotations.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/170_System.Xml.XmlSerializer.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/171_System.Xml.XPath.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/172_System.Xml.XPath.XDocument.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/173_TraceCode.CSharpHost.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/174_WindowsBase.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/17_System.ComponentModel.DataAnnotations.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/18_System.ComponentModel.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/19_System.ComponentModel.EventBasedAsync.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/1_Microsoft.CodeAnalysis.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/20_System.ComponentModel.Primitives.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/21_System.ComponentModel.TypeConverter.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/22_System.Configuration.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/23_System.Console.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/24_System.Core.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/25_System.Data.Common.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/26_System.Data.DataSetExtensions.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/27_System.Data.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/28_System.Diagnostics.Contracts.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/29_System.Diagnostics.Debug.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/2_Microsoft.CSharp.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/30_System.Diagnostics.DiagnosticSource.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/31_System.Diagnostics.FileVersionInfo.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/32_System.Diagnostics.Process.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/33_System.Diagnostics.StackTrace.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/34_System.Diagnostics.TextWriterTraceListener.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/35_System.Diagnostics.Tools.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/36_System.Diagnostics.TraceSource.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/37_System.Diagnostics.Tracing.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/38_System.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/39_System.Drawing.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/3_Microsoft.VisualBasic.Core.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/40_System.Drawing.Primitives.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/41_System.Dynamic.Runtime.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/42_System.Formats.Asn1.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/43_System.Formats.Tar.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/44_System.Globalization.Calendars.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/45_System.Globalization.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/46_System.Globalization.Extensions.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/47_System.IO.Compression.Brotli.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/48_System.IO.Compression.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/49_System.IO.Compression.FileSystem.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/4_Microsoft.VisualBasic.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/50_System.IO.Compression.ZipFile.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/51_System.IO.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/52_System.IO.FileSystem.AccessControl.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/53_System.IO.FileSystem.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/54_System.IO.FileSystem.DriveInfo.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/55_System.IO.FileSystem.Primitives.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/56_System.IO.FileSystem.Watcher.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/57_System.IO.IsolatedStorage.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/58_System.IO.MemoryMappedFiles.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/59_System.IO.Pipelines.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/5_Microsoft.Win32.Primitives.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/60_System.IO.Pipes.AccessControl.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/61_System.IO.Pipes.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/62_System.IO.UnmanagedMemoryStream.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/63_System.Linq.AsyncEnumerable.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/64_System.Linq.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/65_System.Linq.Expressions.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/66_System.Linq.Parallel.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/67_System.Linq.Queryable.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/68_System.Memory.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/69_System.Net.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/6_Microsoft.Win32.Registry.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/70_System.Net.Http.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/71_System.Net.Http.Json.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/72_System.Net.HttpListener.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/73_System.Net.Mail.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/74_System.Net.NameResolution.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/75_System.Net.NetworkInformation.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/76_System.Net.Ping.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/77_System.Net.Primitives.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/78_System.Net.Quic.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/79_System.Net.Requests.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/7_mscorlib.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/80_System.Net.Security.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/81_System.Net.ServerSentEvents.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/82_System.Net.ServicePoint.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/83_System.Net.Sockets.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/84_System.Net.WebClient.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/85_System.Net.WebHeaderCollection.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/86_System.Net.WebProxy.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/87_System.Net.WebSockets.Client.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/88_System.Net.WebSockets.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/89_System.Numerics.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/8_netstandard.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/90_System.Numerics.Vectors.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/91_System.ObjectModel.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/92_System.Private.CoreLib.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/93_System.Private.DataContractSerialization.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/94_System.Private.Uri.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/95_System.Private.Xml.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/96_System.Private.Xml.Linq.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/97_System.Reflection.DispatchProxy.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/98_System.Reflection.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/99_System.Reflection.Emit.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/9_System.AppContext.dll +0 -0
- package/workers/vendor/csharp/_framework/tr/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/tr/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/zh-Hans/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/zh-Hans/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/zh-Hant/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/zh-Hant/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/main.mjs +5 -0
- package/workers/vendor/csharp/package.json +1 -0
- package/workers/vendor/java-browser-helper.jar +0 -0
- package/workers/vendor/java-rewriter.jar +0 -0
- package/workers/vendor/javascript-libraries.js +10106 -0
- package/dist/runtime-types-89nchXlY.d.cts +0 -89
- package/dist/runtime-types-CCQ-ZLc9.d.ts +0 -89
- package/dist/types-zyvpJKCi.d.cts +0 -100
- package/dist/types-zyvpJKCi.d.ts +0 -100
- package/workers/java/java-source-augmentations.cjs +0 -242
- package/workers/java/src/spike/user/TraceHooks.java +0 -619
- package/workers/vendor/java-browser-spike-helper.jar +0 -0
- package/workers/vendor/java-practice-rewriter.jar +0 -0
- package/workers/vendor/java-rewrite-bridge.jar +0 -0
package/dist/internal/browser.js
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
+
// packages/harness-core/src/runtime-trace.ts
|
|
2
|
+
var RUNTIME_TRACE_SCHEMA_VERSION = "runtime-trace-2026-04-28";
|
|
3
|
+
function createEmptyRuntimeTrace(language, options = {}) {
|
|
4
|
+
return {
|
|
5
|
+
schemaVersion: RUNTIME_TRACE_SCHEMA_VERSION,
|
|
6
|
+
language,
|
|
7
|
+
runId: options.runId ?? `${language}:run`,
|
|
8
|
+
events: [],
|
|
9
|
+
lineEventCount: 0,
|
|
10
|
+
traceStepCount: 0
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// packages/harness-browser/src/runtime-diagnostics.ts
|
|
15
|
+
var CONSOLE_METHOD_BY_LEVEL = {
|
|
16
|
+
debug: "debug",
|
|
17
|
+
info: "info",
|
|
18
|
+
warn: "warn",
|
|
19
|
+
error: "error"
|
|
20
|
+
};
|
|
21
|
+
function runtimeDiagnosticEvent(params) {
|
|
22
|
+
return {
|
|
23
|
+
schema: "tracecode.runtime-diagnostic.v1",
|
|
24
|
+
source: "harness",
|
|
25
|
+
...params
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function logRuntimeDiagnostic(level, params, options = {}) {
|
|
29
|
+
if (options.enabled === false && level !== "error") {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const method = CONSOLE_METHOD_BY_LEVEL[level] ?? "info";
|
|
33
|
+
console[method]("[TraceRuntime]", runtimeDiagnosticEvent(params));
|
|
34
|
+
}
|
|
35
|
+
|
|
1
36
|
// packages/harness-browser/src/pyodide-worker-client.ts
|
|
2
37
|
var EXECUTION_TIMEOUT_MS = 1e4;
|
|
3
38
|
var INTERVIEW_MODE_TIMEOUT_MS = 5e3;
|
|
@@ -5,7 +40,7 @@ var TRACING_TIMEOUT_MS = 3e4;
|
|
|
5
40
|
var INIT_TIMEOUT_MS = 12e4;
|
|
6
41
|
var MESSAGE_TIMEOUT_MS = 2e4;
|
|
7
42
|
var WORKER_READY_TIMEOUT_MS = 1e4;
|
|
8
|
-
var
|
|
43
|
+
var PythonWorkerClient = class {
|
|
9
44
|
constructor(options) {
|
|
10
45
|
this.options = options;
|
|
11
46
|
this.debug = options.debug ?? process.env.NODE_ENV === "development";
|
|
@@ -15,6 +50,7 @@ var PyodideWorkerClient = class {
|
|
|
15
50
|
messageId = 0;
|
|
16
51
|
isInitializing = false;
|
|
17
52
|
initPromise = null;
|
|
53
|
+
warmupPromise = null;
|
|
18
54
|
workerReadyPromise = null;
|
|
19
55
|
workerReadyResolve = null;
|
|
20
56
|
workerReadyReject = null;
|
|
@@ -45,11 +81,22 @@ var PyodideWorkerClient = class {
|
|
|
45
81
|
this.workerReadyResolve?.();
|
|
46
82
|
this.workerReadyResolve = null;
|
|
47
83
|
this.workerReadyReject = null;
|
|
48
|
-
|
|
84
|
+
logRuntimeDiagnostic("info", {
|
|
85
|
+
component: "PythonWorkerClient",
|
|
86
|
+
runtime: "python",
|
|
87
|
+
phase: "worker-ready",
|
|
88
|
+
message: "Python worker is ready."
|
|
89
|
+
}, { enabled: this.debug });
|
|
49
90
|
return;
|
|
50
91
|
}
|
|
51
92
|
if (this.debug && !id) {
|
|
52
|
-
|
|
93
|
+
logRuntimeDiagnostic("debug", {
|
|
94
|
+
component: "PythonWorkerClient",
|
|
95
|
+
runtime: "python",
|
|
96
|
+
phase: "worker-event",
|
|
97
|
+
message: "Python worker emitted an unsolicited event.",
|
|
98
|
+
detail: { type, payload }
|
|
99
|
+
}, { enabled: this.debug });
|
|
53
100
|
}
|
|
54
101
|
if (id) {
|
|
55
102
|
const pending = this.pendingMessages.get(id);
|
|
@@ -59,14 +106,31 @@ var PyodideWorkerClient = class {
|
|
|
59
106
|
if (type === "error") {
|
|
60
107
|
pending.reject(new Error(payload.error));
|
|
61
108
|
} else {
|
|
62
|
-
|
|
109
|
+
logRuntimeDiagnostic("debug", {
|
|
110
|
+
component: "PythonWorkerClient",
|
|
111
|
+
runtime: "python",
|
|
112
|
+
phase: "worker-response",
|
|
113
|
+
message: "Python worker response received.",
|
|
114
|
+
detail: { id, type }
|
|
115
|
+
}, { enabled: this.debug });
|
|
63
116
|
pending.resolve(payload);
|
|
64
117
|
}
|
|
65
118
|
}
|
|
66
119
|
}
|
|
67
120
|
};
|
|
68
121
|
this.worker.onerror = (error) => {
|
|
69
|
-
|
|
122
|
+
logRuntimeDiagnostic("error", {
|
|
123
|
+
component: "PythonWorkerClient",
|
|
124
|
+
runtime: "python",
|
|
125
|
+
phase: "worker-error",
|
|
126
|
+
message: "Python worker emitted an error event.",
|
|
127
|
+
detail: {
|
|
128
|
+
message: error.message,
|
|
129
|
+
filename: error.filename,
|
|
130
|
+
lineno: error.lineno,
|
|
131
|
+
colno: error.colno
|
|
132
|
+
}
|
|
133
|
+
});
|
|
70
134
|
const workerError = new Error("Worker error");
|
|
71
135
|
this.workerReadyReject?.(workerError);
|
|
72
136
|
this.workerReadyResolve = null;
|
|
@@ -96,9 +160,13 @@ var PyodideWorkerClient = class {
|
|
|
96
160
|
const timeoutError = new Error(
|
|
97
161
|
`Python worker failed to initialize in time (${Math.round(WORKER_READY_TIMEOUT_MS / 1e3)}s)`
|
|
98
162
|
);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
163
|
+
logRuntimeDiagnostic("warn", {
|
|
164
|
+
component: "PythonWorkerClient",
|
|
165
|
+
runtime: "python",
|
|
166
|
+
phase: "worker-ready-timeout",
|
|
167
|
+
message: "Python worker did not send worker-ready before the timeout.",
|
|
168
|
+
detail: { timeoutMs: WORKER_READY_TIMEOUT_MS }
|
|
169
|
+
}, { enabled: this.debug });
|
|
102
170
|
this.terminateAndReset(timeoutError);
|
|
103
171
|
reject(timeoutError);
|
|
104
172
|
}, WORKER_READY_TIMEOUT_MS);
|
|
@@ -127,12 +195,24 @@ var PyodideWorkerClient = class {
|
|
|
127
195
|
resolve,
|
|
128
196
|
reject
|
|
129
197
|
});
|
|
130
|
-
|
|
198
|
+
logRuntimeDiagnostic("debug", {
|
|
199
|
+
component: "PythonWorkerClient",
|
|
200
|
+
runtime: "python",
|
|
201
|
+
phase: "worker-request",
|
|
202
|
+
message: "Sending request to Python worker.",
|
|
203
|
+
detail: { id, type }
|
|
204
|
+
}, { enabled: this.debug });
|
|
131
205
|
const timeoutId = globalThis.setTimeout(() => {
|
|
132
206
|
const pending2 = this.pendingMessages.get(id);
|
|
133
207
|
if (!pending2) return;
|
|
134
208
|
this.pendingMessages.delete(id);
|
|
135
|
-
|
|
209
|
+
logRuntimeDiagnostic("warn", {
|
|
210
|
+
component: "PythonWorkerClient",
|
|
211
|
+
runtime: "python",
|
|
212
|
+
phase: "worker-request-timeout",
|
|
213
|
+
message: "Python worker request timed out.",
|
|
214
|
+
detail: { id, type, timeoutMs }
|
|
215
|
+
}, { enabled: this.debug });
|
|
136
216
|
pending2.reject(new Error(`Worker request timed out: ${type}`));
|
|
137
217
|
}, timeoutMs);
|
|
138
218
|
const pending = this.pendingMessages.get(id);
|
|
@@ -149,9 +229,13 @@ var PyodideWorkerClient = class {
|
|
|
149
229
|
const timeoutId = globalThis.setTimeout(() => {
|
|
150
230
|
if (settled) return;
|
|
151
231
|
settled = true;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
232
|
+
logRuntimeDiagnostic("warn", {
|
|
233
|
+
component: "PythonWorkerClient",
|
|
234
|
+
runtime: "python",
|
|
235
|
+
phase: "execution-timeout",
|
|
236
|
+
message: "Python execution timed out; terminating worker.",
|
|
237
|
+
detail: { timeoutMs }
|
|
238
|
+
}, { enabled: this.debug });
|
|
155
239
|
this.terminateAndReset();
|
|
156
240
|
const seconds = Math.round(timeoutMs / 1e3);
|
|
157
241
|
reject(new Error(`Execution timed out (possible infinite loop). Code execution was stopped after ${seconds} seconds.`));
|
|
@@ -179,6 +263,7 @@ var PyodideWorkerClient = class {
|
|
|
179
263
|
this.worker = null;
|
|
180
264
|
}
|
|
181
265
|
this.initPromise = null;
|
|
266
|
+
this.warmupPromise = null;
|
|
182
267
|
this.isInitializing = false;
|
|
183
268
|
this.workerReadyPromise = null;
|
|
184
269
|
this.workerReadyResolve = null;
|
|
@@ -189,7 +274,7 @@ var PyodideWorkerClient = class {
|
|
|
189
274
|
this.pendingMessages.clear();
|
|
190
275
|
}
|
|
191
276
|
/**
|
|
192
|
-
* Initialize
|
|
277
|
+
* Initialize the Python worker. Runtime loading is lazy unless warmup() is called.
|
|
193
278
|
*/
|
|
194
279
|
async init() {
|
|
195
280
|
if (this.initPromise) {
|
|
@@ -209,9 +294,13 @@ var PyodideWorkerClient = class {
|
|
|
209
294
|
if (!shouldRetry) {
|
|
210
295
|
throw error;
|
|
211
296
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
297
|
+
logRuntimeDiagnostic("warn", {
|
|
298
|
+
component: "PythonWorkerClient",
|
|
299
|
+
runtime: "python",
|
|
300
|
+
phase: "init-retry",
|
|
301
|
+
message: "Python worker init failed; resetting worker and retrying once.",
|
|
302
|
+
detail: { message }
|
|
303
|
+
}, { enabled: this.debug });
|
|
215
304
|
this.terminateAndReset();
|
|
216
305
|
return this.sendMessage("init", void 0, INIT_TIMEOUT_MS);
|
|
217
306
|
}
|
|
@@ -226,6 +315,19 @@ var PyodideWorkerClient = class {
|
|
|
226
315
|
this.isInitializing = false;
|
|
227
316
|
}
|
|
228
317
|
}
|
|
318
|
+
async warmup() {
|
|
319
|
+
if (this.warmupPromise) return this.warmupPromise;
|
|
320
|
+
this.warmupPromise = (async () => {
|
|
321
|
+
try {
|
|
322
|
+
await this.init();
|
|
323
|
+
return await this.sendMessage("warmup", void 0, INIT_TIMEOUT_MS);
|
|
324
|
+
} catch (error) {
|
|
325
|
+
this.warmupPromise = null;
|
|
326
|
+
throw error;
|
|
327
|
+
}
|
|
328
|
+
})();
|
|
329
|
+
return this.warmupPromise;
|
|
330
|
+
}
|
|
229
331
|
/**
|
|
230
332
|
* Execute Python code with tracing for step-by-step visualization
|
|
231
333
|
* @param options.maxLineEvents - Max line events before abort (for complexity analysis, use higher values)
|
|
@@ -251,7 +353,7 @@ var PyodideWorkerClient = class {
|
|
|
251
353
|
return {
|
|
252
354
|
success: false,
|
|
253
355
|
error: errorMessage,
|
|
254
|
-
trace:
|
|
356
|
+
trace: createEmptyRuntimeTrace("python", { runId: "python:run", file: "solution.py" }),
|
|
255
357
|
executionTimeMs: TRACING_TIMEOUT_MS,
|
|
256
358
|
consoleOutput: [],
|
|
257
359
|
traceLimitExceeded: true,
|
|
@@ -351,10 +453,11 @@ function isWorkerSupported() {
|
|
|
351
453
|
}
|
|
352
454
|
|
|
353
455
|
// packages/harness-browser/src/javascript-worker-client.ts
|
|
354
|
-
var EXECUTION_TIMEOUT_MS2 =
|
|
456
|
+
var EXECUTION_TIMEOUT_MS2 = 2e4;
|
|
355
457
|
var INTERVIEW_MODE_TIMEOUT_MS2 = 5e3;
|
|
356
|
-
var TRACING_TIMEOUT_MS2 =
|
|
458
|
+
var TRACING_TIMEOUT_MS2 = 2e4;
|
|
357
459
|
var INIT_TIMEOUT_MS2 = 1e4;
|
|
460
|
+
var TYPESCRIPT_WARMUP_TIMEOUT_MS = 3e4;
|
|
358
461
|
var MESSAGE_TIMEOUT_MS2 = 12e3;
|
|
359
462
|
var WORKER_READY_TIMEOUT_MS2 = 1e4;
|
|
360
463
|
var JavaScriptWorkerClient = class {
|
|
@@ -367,6 +470,7 @@ var JavaScriptWorkerClient = class {
|
|
|
367
470
|
messageId = 0;
|
|
368
471
|
isInitializing = false;
|
|
369
472
|
initPromise = null;
|
|
473
|
+
warmupPromises = /* @__PURE__ */ new Map();
|
|
370
474
|
workerReadyPromise = null;
|
|
371
475
|
workerReadyResolve = null;
|
|
372
476
|
workerReadyReject = null;
|
|
@@ -391,7 +495,12 @@ var JavaScriptWorkerClient = class {
|
|
|
391
495
|
this.workerReadyResolve?.();
|
|
392
496
|
this.workerReadyResolve = null;
|
|
393
497
|
this.workerReadyReject = null;
|
|
394
|
-
|
|
498
|
+
logRuntimeDiagnostic("info", {
|
|
499
|
+
component: "JavaScriptWorkerClient",
|
|
500
|
+
runtime: "javascript",
|
|
501
|
+
phase: "worker-ready",
|
|
502
|
+
message: "JavaScript worker is ready."
|
|
503
|
+
}, { enabled: this.debug });
|
|
395
504
|
return;
|
|
396
505
|
}
|
|
397
506
|
if (id) {
|
|
@@ -407,7 +516,18 @@ var JavaScriptWorkerClient = class {
|
|
|
407
516
|
}
|
|
408
517
|
};
|
|
409
518
|
this.worker.onerror = (error) => {
|
|
410
|
-
|
|
519
|
+
logRuntimeDiagnostic("error", {
|
|
520
|
+
component: "JavaScriptWorkerClient",
|
|
521
|
+
runtime: "javascript",
|
|
522
|
+
phase: "worker-error",
|
|
523
|
+
message: "JavaScript worker emitted an error event.",
|
|
524
|
+
detail: {
|
|
525
|
+
message: error.message,
|
|
526
|
+
filename: error.filename,
|
|
527
|
+
lineno: error.lineno,
|
|
528
|
+
colno: error.colno
|
|
529
|
+
}
|
|
530
|
+
});
|
|
411
531
|
const workerError = new Error("Worker error");
|
|
412
532
|
this.workerReadyReject?.(workerError);
|
|
413
533
|
this.workerReadyResolve = null;
|
|
@@ -500,6 +620,7 @@ var JavaScriptWorkerClient = class {
|
|
|
500
620
|
this.worker = null;
|
|
501
621
|
}
|
|
502
622
|
this.initPromise = null;
|
|
623
|
+
this.warmupPromises.clear();
|
|
503
624
|
this.isInitializing = false;
|
|
504
625
|
this.workerReadyPromise = null;
|
|
505
626
|
this.workerReadyResolve = null;
|
|
@@ -527,6 +648,25 @@ var JavaScriptWorkerClient = class {
|
|
|
527
648
|
this.isInitializing = false;
|
|
528
649
|
}
|
|
529
650
|
}
|
|
651
|
+
async warmup(language = "javascript") {
|
|
652
|
+
const existing = this.warmupPromises.get(language);
|
|
653
|
+
if (existing) return existing;
|
|
654
|
+
const warmupPromise = (async () => {
|
|
655
|
+
await this.init();
|
|
656
|
+
return this.sendMessage(
|
|
657
|
+
"warmup",
|
|
658
|
+
{ language },
|
|
659
|
+
language === "typescript" ? TYPESCRIPT_WARMUP_TIMEOUT_MS : INIT_TIMEOUT_MS2
|
|
660
|
+
);
|
|
661
|
+
})();
|
|
662
|
+
this.warmupPromises.set(language, warmupPromise);
|
|
663
|
+
try {
|
|
664
|
+
return await warmupPromise;
|
|
665
|
+
} catch (error) {
|
|
666
|
+
this.warmupPromises.delete(language);
|
|
667
|
+
throw error;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
530
670
|
async executeWithTracing(code, functionName, inputs, options, executionStyle = "function", language = "javascript") {
|
|
531
671
|
await this.init();
|
|
532
672
|
return this.executeWithTimeout(
|
|
@@ -609,11 +749,351 @@ function isJavaScriptWorkerSupported() {
|
|
|
609
749
|
return typeof Worker !== "undefined";
|
|
610
750
|
}
|
|
611
751
|
|
|
752
|
+
// packages/harness-core/src/runtime-raw-emission-contract.ts
|
|
753
|
+
function sortedUnique(values) {
|
|
754
|
+
return [...new Set(values)].sort((left, right) => left.localeCompare(right));
|
|
755
|
+
}
|
|
756
|
+
var FORBIDDEN_RUNTIME_TRACE_TOKENS = [
|
|
757
|
+
"visualization",
|
|
758
|
+
"objectKinds",
|
|
759
|
+
"hashMaps",
|
|
760
|
+
"graph-adjacency",
|
|
761
|
+
"linked-list",
|
|
762
|
+
"tree"
|
|
763
|
+
];
|
|
764
|
+
var FORBIDDEN_RUNTIME_TRACE_KEYS = /* @__PURE__ */ new Set([
|
|
765
|
+
"visualization",
|
|
766
|
+
"objectKinds",
|
|
767
|
+
"hashMaps",
|
|
768
|
+
"graph-adjacency",
|
|
769
|
+
"linked-list"
|
|
770
|
+
]);
|
|
771
|
+
function normalizeJavaNativeTraceJsonPayload(payload) {
|
|
772
|
+
return payload.replace(/(?<![A-Za-z0-9_"])-Infinity(?![A-Za-z0-9_"])/g, '"-Infinity"').replace(/(?<![A-Za-z0-9_"])Infinity(?![A-Za-z0-9_"])/g, '"Infinity"').replace(/(?<![A-Za-z0-9_"])NaN(?![A-Za-z0-9_"])/g, '"NaN"');
|
|
773
|
+
}
|
|
774
|
+
function forbiddenRuntimeTraceTokens(value) {
|
|
775
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
776
|
+
collectForbiddenRuntimeTraceTokens(value, tokens, null, false);
|
|
777
|
+
return FORBIDDEN_RUNTIME_TRACE_TOKENS.filter((token) => tokens.has(token));
|
|
778
|
+
}
|
|
779
|
+
function collectForbiddenRuntimeTraceTokens(value, tokens, parentKey, semanticPayload) {
|
|
780
|
+
if (typeof value === "string") {
|
|
781
|
+
if ((semanticPayload || parentKey === "kind" || parentKey === "type" || parentKey === "category") && FORBIDDEN_RUNTIME_TRACE_TOKENS.includes(value)) {
|
|
782
|
+
tokens.add(value);
|
|
783
|
+
}
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
786
|
+
if (value === null || typeof value !== "object") return;
|
|
787
|
+
if (Array.isArray(value)) {
|
|
788
|
+
for (const item of value) collectForbiddenRuntimeTraceTokens(item, tokens, parentKey, semanticPayload);
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
const entries = Object.entries(value);
|
|
792
|
+
const objectSemanticPayload = entries.some(([key, child]) => {
|
|
793
|
+
if (parentKey !== "args" && FORBIDDEN_RUNTIME_TRACE_KEYS.has(key)) return true;
|
|
794
|
+
return (key === "kind" || key === "type" || key === "category") && typeof child === "string" && FORBIDDEN_RUNTIME_TRACE_TOKENS.includes(child);
|
|
795
|
+
});
|
|
796
|
+
for (const [key, child] of entries) {
|
|
797
|
+
if (parentKey !== "args" && FORBIDDEN_RUNTIME_TRACE_KEYS.has(key)) {
|
|
798
|
+
tokens.add(key);
|
|
799
|
+
}
|
|
800
|
+
if (key === "target" || key === "variable" || key === "function") continue;
|
|
801
|
+
collectForbiddenRuntimeTraceTokens(child, tokens, key, semanticPayload || objectSemanticPayload);
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
function unsupportedForbiddenPayload(label, value) {
|
|
805
|
+
const tokens = forbiddenRuntimeTraceTokens(value);
|
|
806
|
+
if (tokens.length === 0) return null;
|
|
807
|
+
return `${label} contains forbidden runtime trace token(s): ${tokens.join(", ")}`;
|
|
808
|
+
}
|
|
809
|
+
function javaNativeTracePayloadKind(event) {
|
|
810
|
+
if (!event.startsWith("trace:")) return null;
|
|
811
|
+
try {
|
|
812
|
+
const parsed = JSON.parse(normalizeJavaNativeTraceJsonPayload(event.slice("trace:".length)));
|
|
813
|
+
if (parsed.kind === "line") return "line";
|
|
814
|
+
if (parsed.kind === "call") return "call";
|
|
815
|
+
if (parsed.kind === "return") return "return";
|
|
816
|
+
if (parsed.kind === "exception") return "exception";
|
|
817
|
+
if (parsed.kind === "timeout") return "timeout";
|
|
818
|
+
if (parsed.kind === "stdout") return "stdout";
|
|
819
|
+
if (parsed.kind === "snapshot") return "snapshot";
|
|
820
|
+
if (parsed.kind === "read") return "read";
|
|
821
|
+
if (parsed.kind === "write") return "write";
|
|
822
|
+
if (parsed.kind === "mutate") return "mutate";
|
|
823
|
+
} catch {
|
|
824
|
+
return null;
|
|
825
|
+
}
|
|
826
|
+
return null;
|
|
827
|
+
}
|
|
828
|
+
function summarizeJavaRawEmissions(events) {
|
|
829
|
+
const kinds = [];
|
|
830
|
+
const unsupported = [];
|
|
831
|
+
for (const [index, event] of events.entries()) {
|
|
832
|
+
if (event.startsWith("trace:")) {
|
|
833
|
+
try {
|
|
834
|
+
const parsed = JSON.parse(normalizeJavaNativeTraceJsonPayload(event.slice("trace:".length)));
|
|
835
|
+
const forbiddenPayload = unsupportedForbiddenPayload(`java trace event ${index}`, parsed);
|
|
836
|
+
if (forbiddenPayload) {
|
|
837
|
+
unsupported.push(forbiddenPayload);
|
|
838
|
+
continue;
|
|
839
|
+
}
|
|
840
|
+
} catch {
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
const nativeKind = javaNativeTracePayloadKind(event);
|
|
844
|
+
if (nativeKind) {
|
|
845
|
+
kinds.push(nativeKind);
|
|
846
|
+
continue;
|
|
847
|
+
}
|
|
848
|
+
unsupported.push(event);
|
|
849
|
+
}
|
|
850
|
+
return {
|
|
851
|
+
language: "java",
|
|
852
|
+
kinds: sortedUnique(kinds),
|
|
853
|
+
unsupported
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
function assertSupportedRawEmissions(summary, label) {
|
|
857
|
+
if (summary.unsupported.length > 0) {
|
|
858
|
+
throw new Error(
|
|
859
|
+
`${label} emitted unsupported raw runtime payloads:
|
|
860
|
+
${summary.unsupported.slice(0, 20).join("\n")}`
|
|
861
|
+
);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
// packages/harness-core/src/trace-adapters/java.ts
|
|
866
|
+
function isNativeJavaTraceEvent(event) {
|
|
867
|
+
return event.startsWith("trace:");
|
|
868
|
+
}
|
|
869
|
+
function stripInlineComments(line, inBlockComment) {
|
|
870
|
+
let result = "";
|
|
871
|
+
let index = 0;
|
|
872
|
+
let inBlock = inBlockComment;
|
|
873
|
+
while (index < line.length) {
|
|
874
|
+
const current = line[index];
|
|
875
|
+
const next = index + 1 < line.length ? line[index + 1] : "";
|
|
876
|
+
if (inBlock) {
|
|
877
|
+
if (current === "*" && next === "/") {
|
|
878
|
+
inBlock = false;
|
|
879
|
+
index += 2;
|
|
880
|
+
continue;
|
|
881
|
+
}
|
|
882
|
+
index += 1;
|
|
883
|
+
continue;
|
|
884
|
+
}
|
|
885
|
+
if (current === "/" && next === "*") {
|
|
886
|
+
inBlock = true;
|
|
887
|
+
index += 2;
|
|
888
|
+
continue;
|
|
889
|
+
}
|
|
890
|
+
if (current === "/" && next === "/") break;
|
|
891
|
+
result += current;
|
|
892
|
+
index += 1;
|
|
893
|
+
}
|
|
894
|
+
return { text: result, inBlockComment: inBlock };
|
|
895
|
+
}
|
|
896
|
+
function isMethodDeclarationLine(line) {
|
|
897
|
+
const trimmed = line.trim();
|
|
898
|
+
if (!trimmed) return false;
|
|
899
|
+
if (trimmed.startsWith("@")) return false;
|
|
900
|
+
if (!trimmed.includes("(") || !trimmed.includes(")")) return false;
|
|
901
|
+
if (trimmed.endsWith(";")) return false;
|
|
902
|
+
if (trimmed.includes("->")) return false;
|
|
903
|
+
if (/^(?:if|for|while|switch|catch|do|try|else|return|throw|new)\b/.test(trimmed)) return false;
|
|
904
|
+
if (!/[A-Za-z_][A-Za-z0-9_]*\s*\([^{};]*\)/.test(trimmed)) return false;
|
|
905
|
+
return /(?:\{\s*)?$/.test(trimmed);
|
|
906
|
+
}
|
|
907
|
+
function buildLocalDeclarationNamesByLine(sourceText) {
|
|
908
|
+
const namesByLine = /* @__PURE__ */ new Map();
|
|
909
|
+
if (typeof sourceText !== "string" || sourceText.length === 0) return namesByLine;
|
|
910
|
+
const lines = sourceText.split(/\r?\n/);
|
|
911
|
+
let inBlockComment = false;
|
|
912
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
913
|
+
const { text, inBlockComment: nextInBlockComment } = stripInlineComments(lines[index] ?? "", inBlockComment);
|
|
914
|
+
inBlockComment = nextInBlockComment;
|
|
915
|
+
if (isMethodDeclarationLine(text)) continue;
|
|
916
|
+
const names = [];
|
|
917
|
+
const declarationPattern = /\b(?:final\s+)?(?:[A-Za-z_][A-Za-z0-9_.$]*(?:\s*<[^;=(){}]+>)?(?:\s*\[\])?)\s+([A-Za-z_][A-Za-z0-9_]*)\s*=/g;
|
|
918
|
+
for (const match of text.matchAll(declarationPattern)) {
|
|
919
|
+
if (match[1]) names.push(match[1]);
|
|
920
|
+
}
|
|
921
|
+
if (names.length > 0) namesByLine.set(index + 1, names);
|
|
922
|
+
}
|
|
923
|
+
return namesByLine;
|
|
924
|
+
}
|
|
925
|
+
function removeSameLineMutationDeclarationSnapshotEvents(events, sourceText) {
|
|
926
|
+
const declarationNamesByLine = buildLocalDeclarationNamesByLine(sourceText);
|
|
927
|
+
if (declarationNamesByLine.size === 0) return events;
|
|
928
|
+
const mutationVariablesByLine = /* @__PURE__ */ new Map();
|
|
929
|
+
for (const event of events) {
|
|
930
|
+
if (event.kind !== "mutate" || typeof event.line !== "number" || !("variable" in event.target)) continue;
|
|
931
|
+
const variables = mutationVariablesByLine.get(event.line) ?? /* @__PURE__ */ new Set();
|
|
932
|
+
variables.add(event.target.variable);
|
|
933
|
+
mutationVariablesByLine.set(event.line, variables);
|
|
934
|
+
}
|
|
935
|
+
if (mutationVariablesByLine.size === 0) return events;
|
|
936
|
+
return events.filter((event) => {
|
|
937
|
+
if (event.kind !== "snapshot" || typeof event.line !== "number" || !("variable" in event.target)) return true;
|
|
938
|
+
const declaredNames = declarationNamesByLine.get(event.line);
|
|
939
|
+
if (!declaredNames?.includes(event.target.variable)) return true;
|
|
940
|
+
const mutationVariables = mutationVariablesByLine.get(event.line);
|
|
941
|
+
return mutationVariables?.has(event.target.variable) === true;
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
function collectJavaLineDeclarationsForHeaderExpansion(line) {
|
|
945
|
+
const names = [];
|
|
946
|
+
const declarationPattern = /\b(?:final\s+)?((?:boolean|byte|char|short|int|long|float|double|String|Object|[A-Za-z_][A-Za-z0-9_<>.?]*(?:\s*<[^,;=(){}:]+>)?)\s*(?:\[\s*\])*)\s+([A-Za-z_][A-Za-z0-9_]*)\s*(?==)/g;
|
|
947
|
+
const skippedNames = /* @__PURE__ */ new Set(["class", "interface", "enum", "record", "return", "new"]);
|
|
948
|
+
for (const match of line.matchAll(declarationPattern)) {
|
|
949
|
+
const typeSource = match[1] ?? "";
|
|
950
|
+
const name = match[2];
|
|
951
|
+
if (!name || skippedNames.has(name) || name.startsWith("__tracecode")) continue;
|
|
952
|
+
if (typeSource.includes("[")) continue;
|
|
953
|
+
names.push(name);
|
|
954
|
+
}
|
|
955
|
+
return names;
|
|
956
|
+
}
|
|
957
|
+
function collectJavaControlHeaderDeclarations(line) {
|
|
958
|
+
const forMatch = /\bfor\s*\(\s*(?:final\s+)?(?:[A-Za-z_][A-Za-z0-9_<>.?]*(?:\s*<[^;=(){}:]+>)?|\w+(?:\s*\[\s*\])*)\s+([A-Za-z_][A-Za-z0-9_]*)\s*(?:=|:)/.exec(line);
|
|
959
|
+
return forMatch?.[1] ? [forMatch[1]] : [];
|
|
960
|
+
}
|
|
961
|
+
function buildJavaControlHeaderInfo(sourceText) {
|
|
962
|
+
if (typeof sourceText !== "string" || sourceText.length === 0) return null;
|
|
963
|
+
const lines = sourceText.split(/\r?\n/);
|
|
964
|
+
const loopBodyLineToHeader = /* @__PURE__ */ new Map();
|
|
965
|
+
const headerLineToExcludedVariables = /* @__PURE__ */ new Map();
|
|
966
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
967
|
+
const line = lines[index] ?? "";
|
|
968
|
+
const isLoopHeader = /\b(?:for|while)\s*\(/.test(line);
|
|
969
|
+
const isControlHeader = /\b(?:for|while|if|else\s+if)\s*\(/.test(line);
|
|
970
|
+
if (!isControlHeader || !line.includes("{")) continue;
|
|
971
|
+
for (let bodyIndex = index + 1; bodyIndex < lines.length; bodyIndex += 1) {
|
|
972
|
+
const trimmed = (lines[bodyIndex] ?? "").trim();
|
|
973
|
+
if (trimmed.length === 0) continue;
|
|
974
|
+
if (trimmed.startsWith("}")) break;
|
|
975
|
+
const headerInfo = {
|
|
976
|
+
line: index + 1,
|
|
977
|
+
excludedVariables: new Set(collectJavaLineDeclarationsForHeaderExpansion(lines[bodyIndex] ?? "")),
|
|
978
|
+
headerVariables: new Set(collectJavaControlHeaderDeclarations(line))
|
|
979
|
+
};
|
|
980
|
+
if (isLoopHeader) loopBodyLineToHeader.set(bodyIndex + 1, headerInfo);
|
|
981
|
+
headerLineToExcludedVariables.set(index + 1, headerInfo.excludedVariables);
|
|
982
|
+
break;
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
if (loopBodyLineToHeader.size === 0 && headerLineToExcludedVariables.size === 0) return null;
|
|
986
|
+
return { loopBodyLineToHeader, headerLineToExcludedVariables };
|
|
987
|
+
}
|
|
988
|
+
function eventLine(event) {
|
|
989
|
+
return typeof event.line === "number" && Number.isFinite(event.line) && event.line > 0 ? event.line : null;
|
|
990
|
+
}
|
|
991
|
+
function eventSnapshotVariable(event) {
|
|
992
|
+
if (event.kind !== "snapshot") return null;
|
|
993
|
+
const target = event.target;
|
|
994
|
+
if (!target || typeof target !== "object" || !("variable" in target)) return null;
|
|
995
|
+
const variable = target.variable;
|
|
996
|
+
return typeof variable === "string" && variable.length > 0 ? variable : null;
|
|
997
|
+
}
|
|
998
|
+
function cloneRuntimeEventAtLine(event, line) {
|
|
999
|
+
return { ...event, line };
|
|
1000
|
+
}
|
|
1001
|
+
function expandJavaLoopHeaderTraceEvents(events, sourceText) {
|
|
1002
|
+
if (events.length === 0) return events;
|
|
1003
|
+
const controlHeaderInfo = buildJavaControlHeaderInfo(sourceText);
|
|
1004
|
+
if (!controlHeaderInfo) return events;
|
|
1005
|
+
const { loopBodyLineToHeader, headerLineToExcludedVariables } = controlHeaderInfo;
|
|
1006
|
+
const expanded = [];
|
|
1007
|
+
const latestSnapshotByVariable = /* @__PURE__ */ new Map();
|
|
1008
|
+
let lastLineEventLine = null;
|
|
1009
|
+
for (let index = 0; index < events.length; index += 1) {
|
|
1010
|
+
const event = events[index];
|
|
1011
|
+
const line = eventLine(event);
|
|
1012
|
+
const snapshotVariable = eventSnapshotVariable(event);
|
|
1013
|
+
if (line !== null && snapshotVariable && headerLineToExcludedVariables.get(line)?.has(snapshotVariable)) {
|
|
1014
|
+
continue;
|
|
1015
|
+
}
|
|
1016
|
+
const headerInfo = line === null ? void 0 : loopBodyLineToHeader.get(line);
|
|
1017
|
+
const headerLine = headerInfo?.line;
|
|
1018
|
+
if (headerInfo && typeof headerLine === "number" && event.kind === "line" && lastLineEventLine !== headerLine) {
|
|
1019
|
+
expanded.push(cloneRuntimeEventAtLine(event, headerLine));
|
|
1020
|
+
for (const [variable, snapshotEvent] of latestSnapshotByVariable) {
|
|
1021
|
+
if (headerInfo.excludedVariables.has(variable)) continue;
|
|
1022
|
+
expanded.push(cloneRuntimeEventAtLine(snapshotEvent, headerLine));
|
|
1023
|
+
}
|
|
1024
|
+
lastLineEventLine = headerLine;
|
|
1025
|
+
}
|
|
1026
|
+
if (headerInfo && typeof headerLine === "number" && event.kind === "line") {
|
|
1027
|
+
for (let lookahead = index + 1; lookahead < events.length; lookahead += 1) {
|
|
1028
|
+
if (eventLine(events[lookahead]) !== line) break;
|
|
1029
|
+
const variable = eventSnapshotVariable(events[lookahead]);
|
|
1030
|
+
if (!variable || !headerInfo.headerVariables.has(variable)) continue;
|
|
1031
|
+
expanded.push(cloneRuntimeEventAtLine(events[lookahead], headerLine));
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
expanded.push(event);
|
|
1035
|
+
if (event.kind === "line") {
|
|
1036
|
+
lastLineEventLine = line;
|
|
1037
|
+
}
|
|
1038
|
+
if (snapshotVariable) {
|
|
1039
|
+
latestSnapshotByVariable.set(snapshotVariable, event);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
return expanded;
|
|
1043
|
+
}
|
|
1044
|
+
function nativeJavaTraceEventsToTrace(events, sourceText, options = {}) {
|
|
1045
|
+
const runId = options.runId ?? "java:run";
|
|
1046
|
+
let parsedEvents = events.map((event) => {
|
|
1047
|
+
let parsed;
|
|
1048
|
+
try {
|
|
1049
|
+
parsed = JSON.parse(normalizeJavaNativeTraceJsonPayload(event.slice("trace:".length)));
|
|
1050
|
+
} catch (error) {
|
|
1051
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1052
|
+
throw new Error(`Invalid Java native runtime trace event: ${message}
|
|
1053
|
+
${event.slice(0, 500)}`);
|
|
1054
|
+
}
|
|
1055
|
+
return {
|
|
1056
|
+
...parsed,
|
|
1057
|
+
runId,
|
|
1058
|
+
...options.file ? { file: options.file } : {}
|
|
1059
|
+
};
|
|
1060
|
+
});
|
|
1061
|
+
parsedEvents = removeSameLineMutationDeclarationSnapshotEvents(parsedEvents, sourceText);
|
|
1062
|
+
parsedEvents = expandJavaLoopHeaderTraceEvents(parsedEvents, sourceText);
|
|
1063
|
+
return {
|
|
1064
|
+
schemaVersion: RUNTIME_TRACE_SCHEMA_VERSION,
|
|
1065
|
+
language: "java",
|
|
1066
|
+
runId,
|
|
1067
|
+
events: parsedEvents,
|
|
1068
|
+
lineEventCount: parsedEvents.filter((event) => event.kind === "line").length,
|
|
1069
|
+
traceStepCount: parsedEvents.length
|
|
1070
|
+
};
|
|
1071
|
+
}
|
|
1072
|
+
function javaTraceHooksEventsToRuntimeTrace(events, sourceText, options = {}) {
|
|
1073
|
+
assertSupportedRawEmissions(summarizeJavaRawEmissions(events), "java");
|
|
1074
|
+
if (events.length === 0) {
|
|
1075
|
+
return {
|
|
1076
|
+
schemaVersion: RUNTIME_TRACE_SCHEMA_VERSION,
|
|
1077
|
+
language: "java",
|
|
1078
|
+
runId: options.runId ?? "java:run",
|
|
1079
|
+
events: [],
|
|
1080
|
+
lineEventCount: 0,
|
|
1081
|
+
traceStepCount: 0
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
if (!events.every(isNativeJavaTraceEvent)) {
|
|
1085
|
+
throw new Error("Java TraceHooks must emit native runtime trace events. Unsupported line=... events are no longer supported.");
|
|
1086
|
+
}
|
|
1087
|
+
return nativeJavaTraceEventsToTrace(events, sourceText, options);
|
|
1088
|
+
}
|
|
1089
|
+
|
|
612
1090
|
// packages/harness-browser/src/java-worker-client.ts
|
|
1091
|
+
var EXECUTION_TIMEOUT_MS3 = 2e4;
|
|
613
1092
|
var TRACING_TIMEOUT_MS3 = 25e3;
|
|
614
|
-
var INIT_TIMEOUT_MS3 =
|
|
1093
|
+
var INIT_TIMEOUT_MS3 = 12e4;
|
|
615
1094
|
var MESSAGE_TIMEOUT_MS3 = 3e4;
|
|
616
1095
|
var WORKER_READY_TIMEOUT_MS3 = 1e4;
|
|
1096
|
+
var JAVA_DEFAULT_FILE = "solution.java";
|
|
617
1097
|
var JavaWorkerClient = class {
|
|
618
1098
|
constructor(options) {
|
|
619
1099
|
this.options = options;
|
|
@@ -624,6 +1104,7 @@ var JavaWorkerClient = class {
|
|
|
624
1104
|
messageId = 0;
|
|
625
1105
|
isInitializing = false;
|
|
626
1106
|
initPromise = null;
|
|
1107
|
+
warmupPromise = null;
|
|
627
1108
|
workerReadyPromise = null;
|
|
628
1109
|
workerReadyResolve = null;
|
|
629
1110
|
workerReadyReject = null;
|
|
@@ -648,6 +1129,22 @@ var JavaWorkerClient = class {
|
|
|
648
1129
|
this.workerReadyResolve?.();
|
|
649
1130
|
this.workerReadyResolve = null;
|
|
650
1131
|
this.workerReadyReject = null;
|
|
1132
|
+
logRuntimeDiagnostic("info", {
|
|
1133
|
+
component: "JavaWorkerClient",
|
|
1134
|
+
runtime: "java",
|
|
1135
|
+
phase: "worker-ready",
|
|
1136
|
+
message: "Java worker is ready."
|
|
1137
|
+
}, { enabled: this.debug });
|
|
1138
|
+
return;
|
|
1139
|
+
}
|
|
1140
|
+
if (type === "idle-timeout") {
|
|
1141
|
+
logRuntimeDiagnostic("info", {
|
|
1142
|
+
component: "JavaWorkerClient",
|
|
1143
|
+
runtime: "java",
|
|
1144
|
+
phase: "idle-timeout",
|
|
1145
|
+
message: "Java worker closed after idle timeout."
|
|
1146
|
+
}, { enabled: this.debug });
|
|
1147
|
+
this.terminateAndReset(new Error("Java worker closed after idle timeout"));
|
|
651
1148
|
return;
|
|
652
1149
|
}
|
|
653
1150
|
if (!id) return;
|
|
@@ -662,6 +1159,18 @@ var JavaWorkerClient = class {
|
|
|
662
1159
|
pending.resolve(payload);
|
|
663
1160
|
};
|
|
664
1161
|
this.worker.onerror = (error) => {
|
|
1162
|
+
logRuntimeDiagnostic("error", {
|
|
1163
|
+
component: "JavaWorkerClient",
|
|
1164
|
+
runtime: "java",
|
|
1165
|
+
phase: "worker-error",
|
|
1166
|
+
message: "Java worker emitted an error event.",
|
|
1167
|
+
detail: {
|
|
1168
|
+
message: error.message,
|
|
1169
|
+
filename: error.filename,
|
|
1170
|
+
lineno: error.lineno,
|
|
1171
|
+
colno: error.colno
|
|
1172
|
+
}
|
|
1173
|
+
});
|
|
665
1174
|
const workerError = new Error(error.message || "Java worker error");
|
|
666
1175
|
this.workerReadyReject?.(workerError);
|
|
667
1176
|
this.workerReadyResolve = null;
|
|
@@ -686,6 +1195,13 @@ var JavaWorkerClient = class {
|
|
|
686
1195
|
const timeoutError = new Error(
|
|
687
1196
|
`Java worker failed to initialize in time (${Math.round(WORKER_READY_TIMEOUT_MS3 / 1e3)}s)`
|
|
688
1197
|
);
|
|
1198
|
+
logRuntimeDiagnostic("warn", {
|
|
1199
|
+
component: "JavaWorkerClient",
|
|
1200
|
+
runtime: "java",
|
|
1201
|
+
phase: "worker-ready-timeout",
|
|
1202
|
+
message: "Java worker did not send worker-ready before the timeout.",
|
|
1203
|
+
detail: { timeoutMs: WORKER_READY_TIMEOUT_MS3 }
|
|
1204
|
+
}, { enabled: this.debug });
|
|
689
1205
|
this.terminateAndReset(timeoutError);
|
|
690
1206
|
reject(timeoutError);
|
|
691
1207
|
}, WORKER_READY_TIMEOUT_MS3);
|
|
@@ -715,6 +1231,13 @@ var JavaWorkerClient = class {
|
|
|
715
1231
|
const pending2 = this.pendingMessages.get(id);
|
|
716
1232
|
if (!pending2) return;
|
|
717
1233
|
this.pendingMessages.delete(id);
|
|
1234
|
+
logRuntimeDiagnostic("warn", {
|
|
1235
|
+
component: "JavaWorkerClient",
|
|
1236
|
+
runtime: "java",
|
|
1237
|
+
phase: "worker-request-timeout",
|
|
1238
|
+
message: "Java worker request timed out.",
|
|
1239
|
+
detail: { id, type, timeoutMs }
|
|
1240
|
+
}, { enabled: this.debug });
|
|
718
1241
|
pending2.reject(new Error(`Worker request timed out: ${type}`));
|
|
719
1242
|
}, timeoutMs);
|
|
720
1243
|
const pending = this.pendingMessages.get(id);
|
|
@@ -728,6 +1251,13 @@ var JavaWorkerClient = class {
|
|
|
728
1251
|
const timeoutId = globalThis.setTimeout(() => {
|
|
729
1252
|
if (settled) return;
|
|
730
1253
|
settled = true;
|
|
1254
|
+
logRuntimeDiagnostic("warn", {
|
|
1255
|
+
component: "JavaWorkerClient",
|
|
1256
|
+
runtime: "java",
|
|
1257
|
+
phase: "execution-timeout",
|
|
1258
|
+
message: "Java execution timed out; terminating worker.",
|
|
1259
|
+
detail: { timeoutMs }
|
|
1260
|
+
}, { enabled: this.debug });
|
|
731
1261
|
this.terminateAndReset();
|
|
732
1262
|
reject(
|
|
733
1263
|
new Error(
|
|
@@ -755,6 +1285,7 @@ var JavaWorkerClient = class {
|
|
|
755
1285
|
this.worker = null;
|
|
756
1286
|
}
|
|
757
1287
|
this.initPromise = null;
|
|
1288
|
+
this.warmupPromise = null;
|
|
758
1289
|
this.isInitializing = false;
|
|
759
1290
|
this.workerReadyPromise = null;
|
|
760
1291
|
this.workerReadyResolve = null;
|
|
@@ -772,7 +1303,26 @@ var JavaWorkerClient = class {
|
|
|
772
1303
|
return this.init();
|
|
773
1304
|
}
|
|
774
1305
|
this.isInitializing = true;
|
|
775
|
-
this.initPromise =
|
|
1306
|
+
this.initPromise = (async () => {
|
|
1307
|
+
try {
|
|
1308
|
+
return await this.sendMessage("init", this.workerOptionsPayload(), INIT_TIMEOUT_MS3);
|
|
1309
|
+
} catch (error) {
|
|
1310
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1311
|
+
const shouldRetry = message.includes("Worker request timed out: init") || message.includes("Worker was terminated") || message.includes("Java worker error") || message.includes("failed to initialize in time");
|
|
1312
|
+
if (!shouldRetry) {
|
|
1313
|
+
throw error;
|
|
1314
|
+
}
|
|
1315
|
+
logRuntimeDiagnostic("warn", {
|
|
1316
|
+
component: "JavaWorkerClient",
|
|
1317
|
+
runtime: "java",
|
|
1318
|
+
phase: "init-retry",
|
|
1319
|
+
message: "Java worker init failed; resetting worker and retrying once.",
|
|
1320
|
+
detail: { message }
|
|
1321
|
+
}, { enabled: this.debug });
|
|
1322
|
+
this.terminateAndReset(error instanceof Error ? error : new Error(message));
|
|
1323
|
+
return this.sendMessage("init", this.workerOptionsPayload(), INIT_TIMEOUT_MS3);
|
|
1324
|
+
}
|
|
1325
|
+
})();
|
|
776
1326
|
try {
|
|
777
1327
|
return await this.initPromise;
|
|
778
1328
|
} catch (error) {
|
|
@@ -782,9 +1332,29 @@ var JavaWorkerClient = class {
|
|
|
782
1332
|
this.isInitializing = false;
|
|
783
1333
|
}
|
|
784
1334
|
}
|
|
1335
|
+
workerOptionsPayload() {
|
|
1336
|
+
return this.options.workerIdleTimeoutMs === void 0 ? {} : { idleTimeoutMs: this.options.workerIdleTimeoutMs };
|
|
1337
|
+
}
|
|
1338
|
+
async warmup() {
|
|
1339
|
+
if (this.warmupPromise) return this.warmupPromise;
|
|
1340
|
+
this.warmupPromise = (async () => {
|
|
1341
|
+
try {
|
|
1342
|
+
await this.init();
|
|
1343
|
+
return await this.sendMessage(
|
|
1344
|
+
"warmup",
|
|
1345
|
+
this.workerOptionsPayload(),
|
|
1346
|
+
INIT_TIMEOUT_MS3
|
|
1347
|
+
);
|
|
1348
|
+
} catch (error) {
|
|
1349
|
+
this.warmupPromise = null;
|
|
1350
|
+
throw error;
|
|
1351
|
+
}
|
|
1352
|
+
})();
|
|
1353
|
+
return this.warmupPromise;
|
|
1354
|
+
}
|
|
785
1355
|
async executeWithTracing(code, functionName, inputs, options, executionStyle) {
|
|
786
1356
|
await this.init();
|
|
787
|
-
|
|
1357
|
+
const result = await this.executeWithTimeout(
|
|
788
1358
|
() => this.sendMessage(
|
|
789
1359
|
"execute-with-tracing",
|
|
790
1360
|
{ code, functionName, inputs, options, executionStyle },
|
|
@@ -792,35 +1362,1071 @@ var JavaWorkerClient = class {
|
|
|
792
1362
|
),
|
|
793
1363
|
TRACING_TIMEOUT_MS3
|
|
794
1364
|
);
|
|
1365
|
+
return {
|
|
1366
|
+
...result,
|
|
1367
|
+
trace: result.success ? javaTraceHooksEventsToRuntimeTrace(result.events, result.sourceText, {
|
|
1368
|
+
runId: "java:run",
|
|
1369
|
+
file: JAVA_DEFAULT_FILE
|
|
1370
|
+
}) : createEmptyRuntimeTrace("java", { runId: "java:run", file: JAVA_DEFAULT_FILE })
|
|
1371
|
+
};
|
|
795
1372
|
}
|
|
796
1373
|
async executeCode(code, functionName, inputs, options, executionStyle) {
|
|
797
|
-
|
|
1374
|
+
return this.executeCodeMessage("execute-code", code, functionName, inputs, options, executionStyle);
|
|
1375
|
+
}
|
|
1376
|
+
async executeCodeMessage(type, code, functionName, inputs, options, executionStyle) {
|
|
1377
|
+
await this.init();
|
|
1378
|
+
const result = await this.executeWithTimeout(
|
|
1379
|
+
() => this.sendMessage(
|
|
1380
|
+
type,
|
|
1381
|
+
{ code, functionName, inputs, options, executionStyle },
|
|
1382
|
+
EXECUTION_TIMEOUT_MS3 + 5e3
|
|
1383
|
+
),
|
|
1384
|
+
EXECUTION_TIMEOUT_MS3
|
|
1385
|
+
);
|
|
798
1386
|
if (!result.success) {
|
|
799
1387
|
return {
|
|
800
1388
|
success: false,
|
|
801
1389
|
output: null,
|
|
802
1390
|
error: result.error ?? "Java execution failed",
|
|
803
1391
|
...result.errorLine !== void 0 ? { errorLine: result.errorLine } : {},
|
|
804
|
-
consoleOutput: result.consoleOutput
|
|
1392
|
+
consoleOutput: result.consoleOutput ?? [],
|
|
1393
|
+
timings: result.timings
|
|
805
1394
|
};
|
|
806
1395
|
}
|
|
807
1396
|
return {
|
|
808
1397
|
success: true,
|
|
809
1398
|
output: result.output,
|
|
810
|
-
consoleOutput: result.consoleOutput
|
|
1399
|
+
consoleOutput: result.consoleOutput ?? [],
|
|
1400
|
+
timings: result.timings
|
|
811
1401
|
};
|
|
812
1402
|
}
|
|
813
1403
|
async executeCodeInterviewMode(code, functionName, inputs, options, executionStyle) {
|
|
814
|
-
return this.
|
|
1404
|
+
return this.executeCodeMessage("execute-code-interview", code, functionName, inputs, options, executionStyle);
|
|
1405
|
+
}
|
|
1406
|
+
terminate() {
|
|
1407
|
+
this.terminateAndReset();
|
|
1408
|
+
}
|
|
1409
|
+
};
|
|
1410
|
+
|
|
1411
|
+
// packages/harness-browser/src/csharp-worker-client.ts
|
|
1412
|
+
var EXECUTION_TIMEOUT_MS4 = 2e4;
|
|
1413
|
+
var TRACING_TIMEOUT_MS4 = 2e4;
|
|
1414
|
+
var INTERVIEW_MODE_TIMEOUT_MS3 = 5e3;
|
|
1415
|
+
var INIT_TIMEOUT_MS4 = 45e3;
|
|
1416
|
+
var MESSAGE_TIMEOUT_MS4 = 3e4;
|
|
1417
|
+
var WORKER_READY_TIMEOUT_MS4 = 1e4;
|
|
1418
|
+
var CSHARP_DEFAULT_FILE = "solution.cs";
|
|
1419
|
+
var CSHARP_LEGACY_USER_FILE = "UserCode.cs";
|
|
1420
|
+
function isCSharpUserFile(file) {
|
|
1421
|
+
return Boolean(file?.endsWith(CSHARP_DEFAULT_FILE) || file?.endsWith(CSHARP_LEGACY_USER_FILE));
|
|
1422
|
+
}
|
|
1423
|
+
function isCSharpUserDiagnostic(diagnostic) {
|
|
1424
|
+
return isCSharpUserFile(diagnostic.file);
|
|
1425
|
+
}
|
|
1426
|
+
function normalizeCSharpTraceEventFile(event) {
|
|
1427
|
+
return isCSharpUserFile(event.file) ? { ...event, file: CSHARP_DEFAULT_FILE } : event;
|
|
1428
|
+
}
|
|
1429
|
+
var CSharpWorkerClient = class {
|
|
1430
|
+
constructor(options) {
|
|
1431
|
+
this.options = options;
|
|
1432
|
+
this.debug = options.debug ?? process.env.NODE_ENV === "development";
|
|
1433
|
+
this.initTimeoutMs = options.initTimeoutMs ?? INIT_TIMEOUT_MS4;
|
|
1434
|
+
this.executionTimeoutMs = options.executionTimeoutMs ?? EXECUTION_TIMEOUT_MS4;
|
|
1435
|
+
this.tracingTimeoutMs = options.tracingTimeoutMs ?? TRACING_TIMEOUT_MS4;
|
|
1436
|
+
this.interviewTimeoutMs = options.interviewTimeoutMs ?? INTERVIEW_MODE_TIMEOUT_MS3;
|
|
1437
|
+
}
|
|
1438
|
+
worker = null;
|
|
1439
|
+
pendingMessages = /* @__PURE__ */ new Map();
|
|
1440
|
+
messageId = 0;
|
|
1441
|
+
isInitializing = false;
|
|
1442
|
+
initPromise = null;
|
|
1443
|
+
warmupPromise = null;
|
|
1444
|
+
workerReadyPromise = null;
|
|
1445
|
+
workerReadyResolve = null;
|
|
1446
|
+
workerReadyReject = null;
|
|
1447
|
+
debug;
|
|
1448
|
+
initTimeoutMs;
|
|
1449
|
+
executionTimeoutMs;
|
|
1450
|
+
tracingTimeoutMs;
|
|
1451
|
+
interviewTimeoutMs;
|
|
1452
|
+
isSupported() {
|
|
1453
|
+
return typeof Worker !== "undefined";
|
|
1454
|
+
}
|
|
1455
|
+
getWorker() {
|
|
1456
|
+
if (this.worker) return this.worker;
|
|
1457
|
+
if (!this.isSupported()) {
|
|
1458
|
+
throw new Error("Web Workers are not supported in this environment");
|
|
1459
|
+
}
|
|
1460
|
+
this.workerReadyPromise = new Promise((resolve, reject) => {
|
|
1461
|
+
this.workerReadyResolve = resolve;
|
|
1462
|
+
this.workerReadyReject = (error) => reject(error);
|
|
1463
|
+
});
|
|
1464
|
+
const workerUrl = this.debug && !this.options.workerUrl.includes("?") ? `${this.options.workerUrl}?dev=${Date.now()}` : this.options.workerUrl;
|
|
1465
|
+
this.worker = new Worker(workerUrl, { type: "module" });
|
|
1466
|
+
this.worker.onmessage = (event) => {
|
|
1467
|
+
const { id, type, payload } = event.data;
|
|
1468
|
+
if (type === "worker-ready") {
|
|
1469
|
+
this.workerReadyResolve?.();
|
|
1470
|
+
this.workerReadyResolve = null;
|
|
1471
|
+
this.workerReadyReject = null;
|
|
1472
|
+
logRuntimeDiagnostic("info", {
|
|
1473
|
+
component: "CSharpWorkerClient",
|
|
1474
|
+
runtime: "csharp",
|
|
1475
|
+
phase: "worker-ready",
|
|
1476
|
+
message: "C# worker is ready."
|
|
1477
|
+
}, { enabled: this.debug });
|
|
1478
|
+
return;
|
|
1479
|
+
}
|
|
1480
|
+
if (type === "idle-timeout") {
|
|
1481
|
+
logRuntimeDiagnostic("info", {
|
|
1482
|
+
component: "CSharpWorkerClient",
|
|
1483
|
+
runtime: "csharp",
|
|
1484
|
+
phase: "idle-timeout",
|
|
1485
|
+
message: "C# worker closed after idle timeout."
|
|
1486
|
+
}, { enabled: this.debug });
|
|
1487
|
+
this.terminateAndReset(new Error("C# worker closed after idle timeout"));
|
|
1488
|
+
return;
|
|
1489
|
+
}
|
|
1490
|
+
if (!id) return;
|
|
1491
|
+
const pending = this.pendingMessages.get(id);
|
|
1492
|
+
if (!pending) return;
|
|
1493
|
+
this.pendingMessages.delete(id);
|
|
1494
|
+
if (pending.timeoutId) globalThis.clearTimeout(pending.timeoutId);
|
|
1495
|
+
if (type === "error") {
|
|
1496
|
+
pending.reject(new Error(payload.error));
|
|
1497
|
+
return;
|
|
1498
|
+
}
|
|
1499
|
+
pending.resolve(payload);
|
|
1500
|
+
};
|
|
1501
|
+
this.worker.onerror = (error) => {
|
|
1502
|
+
logRuntimeDiagnostic("error", {
|
|
1503
|
+
component: "CSharpWorkerClient",
|
|
1504
|
+
runtime: "csharp",
|
|
1505
|
+
phase: "worker-error",
|
|
1506
|
+
message: "C# worker emitted an error event.",
|
|
1507
|
+
detail: {
|
|
1508
|
+
message: error.message,
|
|
1509
|
+
filename: error.filename,
|
|
1510
|
+
lineno: error.lineno,
|
|
1511
|
+
colno: error.colno
|
|
1512
|
+
}
|
|
1513
|
+
});
|
|
1514
|
+
const workerError = new Error(error.message || "C# worker error");
|
|
1515
|
+
this.workerReadyReject?.(workerError);
|
|
1516
|
+
this.workerReadyResolve = null;
|
|
1517
|
+
this.workerReadyReject = null;
|
|
1518
|
+
for (const [, pending] of this.pendingMessages) {
|
|
1519
|
+
if (pending.timeoutId) globalThis.clearTimeout(pending.timeoutId);
|
|
1520
|
+
pending.reject(workerError);
|
|
1521
|
+
}
|
|
1522
|
+
this.pendingMessages.clear();
|
|
1523
|
+
this.terminateAndReset(workerError);
|
|
1524
|
+
};
|
|
1525
|
+
return this.worker;
|
|
1526
|
+
}
|
|
1527
|
+
async waitForWorkerReady() {
|
|
1528
|
+
const readyPromise = this.workerReadyPromise;
|
|
1529
|
+
if (!readyPromise) return;
|
|
1530
|
+
await new Promise((resolve, reject) => {
|
|
1531
|
+
let settled = false;
|
|
1532
|
+
const timeoutId = globalThis.setTimeout(() => {
|
|
1533
|
+
if (settled) return;
|
|
1534
|
+
settled = true;
|
|
1535
|
+
const timeoutError = new Error(
|
|
1536
|
+
`C# worker failed to initialize in time (${Math.round(WORKER_READY_TIMEOUT_MS4 / 1e3)}s)`
|
|
1537
|
+
);
|
|
1538
|
+
logRuntimeDiagnostic("warn", {
|
|
1539
|
+
component: "CSharpWorkerClient",
|
|
1540
|
+
runtime: "csharp",
|
|
1541
|
+
phase: "worker-ready-timeout",
|
|
1542
|
+
message: "C# worker did not send worker-ready before the timeout.",
|
|
1543
|
+
detail: { timeoutMs: WORKER_READY_TIMEOUT_MS4 }
|
|
1544
|
+
}, { enabled: this.debug });
|
|
1545
|
+
this.terminateAndReset(timeoutError);
|
|
1546
|
+
reject(timeoutError);
|
|
1547
|
+
}, WORKER_READY_TIMEOUT_MS4);
|
|
1548
|
+
readyPromise.then(() => {
|
|
1549
|
+
if (settled) return;
|
|
1550
|
+
settled = true;
|
|
1551
|
+
globalThis.clearTimeout(timeoutId);
|
|
1552
|
+
resolve();
|
|
1553
|
+
}).catch((error) => {
|
|
1554
|
+
if (settled) return;
|
|
1555
|
+
settled = true;
|
|
1556
|
+
globalThis.clearTimeout(timeoutId);
|
|
1557
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
1558
|
+
});
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1561
|
+
async sendMessage(type, payload, timeoutMs = MESSAGE_TIMEOUT_MS4) {
|
|
1562
|
+
const worker = this.getWorker();
|
|
1563
|
+
await this.waitForWorkerReady();
|
|
1564
|
+
const id = String(++this.messageId);
|
|
1565
|
+
return new Promise((resolve, reject) => {
|
|
1566
|
+
this.pendingMessages.set(id, {
|
|
1567
|
+
resolve,
|
|
1568
|
+
reject
|
|
1569
|
+
});
|
|
1570
|
+
const timeoutId = globalThis.setTimeout(() => {
|
|
1571
|
+
const pending2 = this.pendingMessages.get(id);
|
|
1572
|
+
if (!pending2) return;
|
|
1573
|
+
this.pendingMessages.delete(id);
|
|
1574
|
+
logRuntimeDiagnostic("warn", {
|
|
1575
|
+
component: "CSharpWorkerClient",
|
|
1576
|
+
runtime: "csharp",
|
|
1577
|
+
phase: "worker-request-timeout",
|
|
1578
|
+
message: "C# worker request timed out.",
|
|
1579
|
+
detail: { id, type, timeoutMs }
|
|
1580
|
+
}, { enabled: this.debug });
|
|
1581
|
+
pending2.reject(new Error(`Worker request timed out: ${type}`));
|
|
1582
|
+
}, timeoutMs);
|
|
1583
|
+
const pending = this.pendingMessages.get(id);
|
|
1584
|
+
if (pending) pending.timeoutId = timeoutId;
|
|
1585
|
+
worker.postMessage({ id, type, payload });
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
async executeWithTimeout(executor, timeoutMs) {
|
|
1589
|
+
return new Promise((resolve, reject) => {
|
|
1590
|
+
let settled = false;
|
|
1591
|
+
const timeoutId = globalThis.setTimeout(() => {
|
|
1592
|
+
if (settled) return;
|
|
1593
|
+
settled = true;
|
|
1594
|
+
logRuntimeDiagnostic("warn", {
|
|
1595
|
+
component: "CSharpWorkerClient",
|
|
1596
|
+
runtime: "csharp",
|
|
1597
|
+
phase: "execution-timeout",
|
|
1598
|
+
message: "C# execution timed out; terminating worker.",
|
|
1599
|
+
detail: { timeoutMs }
|
|
1600
|
+
}, { enabled: this.debug });
|
|
1601
|
+
this.terminateAndReset();
|
|
1602
|
+
reject(new Error(`C# execution timed out after ${Math.round(timeoutMs / 1e3)} seconds.`));
|
|
1603
|
+
}, timeoutMs);
|
|
1604
|
+
executor().then((result) => {
|
|
1605
|
+
if (settled) return;
|
|
1606
|
+
settled = true;
|
|
1607
|
+
globalThis.clearTimeout(timeoutId);
|
|
1608
|
+
resolve(result);
|
|
1609
|
+
}).catch((error) => {
|
|
1610
|
+
if (settled) return;
|
|
1611
|
+
settled = true;
|
|
1612
|
+
globalThis.clearTimeout(timeoutId);
|
|
1613
|
+
reject(error);
|
|
1614
|
+
});
|
|
1615
|
+
});
|
|
1616
|
+
}
|
|
1617
|
+
terminateAndReset(reason = new Error("Worker was terminated")) {
|
|
1618
|
+
this.workerReadyReject?.(reason);
|
|
1619
|
+
if (this.worker) {
|
|
1620
|
+
this.worker.terminate();
|
|
1621
|
+
this.worker = null;
|
|
1622
|
+
}
|
|
1623
|
+
this.initPromise = null;
|
|
1624
|
+
this.warmupPromise = null;
|
|
1625
|
+
this.isInitializing = false;
|
|
1626
|
+
this.workerReadyPromise = null;
|
|
1627
|
+
this.workerReadyResolve = null;
|
|
1628
|
+
this.workerReadyReject = null;
|
|
1629
|
+
for (const [, pending] of this.pendingMessages) {
|
|
1630
|
+
if (pending.timeoutId) globalThis.clearTimeout(pending.timeoutId);
|
|
1631
|
+
pending.reject(reason);
|
|
1632
|
+
}
|
|
1633
|
+
this.pendingMessages.clear();
|
|
1634
|
+
}
|
|
1635
|
+
shouldRetryInit(error) {
|
|
1636
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1637
|
+
return message.includes("timed out") || message.includes("Worker request timed out") || message.includes("worker error") || message.includes("Failed to fetch") || message.includes("was terminated") || message.includes("closed after idle timeout");
|
|
1638
|
+
}
|
|
1639
|
+
sendInitMessage() {
|
|
1640
|
+
return this.sendMessage(
|
|
1641
|
+
"init",
|
|
1642
|
+
{ assetBaseUrl: this.options.assetBaseUrl, ...this.workerOptionsPayload() },
|
|
1643
|
+
this.initTimeoutMs
|
|
1644
|
+
);
|
|
1645
|
+
}
|
|
1646
|
+
workerOptionsPayload() {
|
|
1647
|
+
return this.options.workerIdleTimeoutMs === void 0 ? {} : { idleTimeoutMs: this.options.workerIdleTimeoutMs };
|
|
1648
|
+
}
|
|
1649
|
+
async init() {
|
|
1650
|
+
if (this.initPromise) return this.initPromise;
|
|
1651
|
+
if (this.isInitializing) {
|
|
1652
|
+
await new Promise((resolve) => globalThis.setTimeout(resolve, 100));
|
|
1653
|
+
return this.init();
|
|
1654
|
+
}
|
|
1655
|
+
this.isInitializing = true;
|
|
1656
|
+
this.initPromise = (async () => {
|
|
1657
|
+
try {
|
|
1658
|
+
return await this.sendInitMessage();
|
|
1659
|
+
} catch (error) {
|
|
1660
|
+
if (!this.shouldRetryInit(error)) throw error;
|
|
1661
|
+
this.terminateAndReset(error instanceof Error ? error : new Error(String(error)));
|
|
1662
|
+
return this.sendInitMessage();
|
|
1663
|
+
}
|
|
1664
|
+
})();
|
|
1665
|
+
try {
|
|
1666
|
+
return await this.initPromise;
|
|
1667
|
+
} catch (error) {
|
|
1668
|
+
this.initPromise = null;
|
|
1669
|
+
throw error;
|
|
1670
|
+
} finally {
|
|
1671
|
+
this.isInitializing = false;
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
async warmup() {
|
|
1675
|
+
if (this.warmupPromise) return this.warmupPromise;
|
|
1676
|
+
this.warmupPromise = (async () => {
|
|
1677
|
+
try {
|
|
1678
|
+
await this.init();
|
|
1679
|
+
return await this.sendMessage(
|
|
1680
|
+
"warmup",
|
|
1681
|
+
{ assetBaseUrl: this.options.assetBaseUrl, ...this.workerOptionsPayload() },
|
|
1682
|
+
this.initTimeoutMs
|
|
1683
|
+
);
|
|
1684
|
+
} catch (error) {
|
|
1685
|
+
this.warmupPromise = null;
|
|
1686
|
+
throw error;
|
|
1687
|
+
}
|
|
1688
|
+
})();
|
|
1689
|
+
return this.warmupPromise;
|
|
1690
|
+
}
|
|
1691
|
+
async executeCode(code, functionName, inputs, executionStyle) {
|
|
1692
|
+
await this.init();
|
|
1693
|
+
const result = await this.executeWithTimeout(
|
|
1694
|
+
() => this.sendMessage(
|
|
1695
|
+
"execute-code",
|
|
1696
|
+
{
|
|
1697
|
+
code,
|
|
1698
|
+
functionName,
|
|
1699
|
+
inputs,
|
|
1700
|
+
executionStyle,
|
|
1701
|
+
assetBaseUrl: this.options.assetBaseUrl,
|
|
1702
|
+
timeoutMs: Math.max(100, this.executionTimeoutMs - 1e3),
|
|
1703
|
+
...this.workerOptionsPayload()
|
|
1704
|
+
},
|
|
1705
|
+
this.executionTimeoutMs + 5e3
|
|
1706
|
+
),
|
|
1707
|
+
this.executionTimeoutMs
|
|
1708
|
+
);
|
|
1709
|
+
if (!result.success) {
|
|
1710
|
+
const firstUserDiagnostic = result.diagnostics?.find(isCSharpUserDiagnostic);
|
|
1711
|
+
return {
|
|
1712
|
+
success: false,
|
|
1713
|
+
output: null,
|
|
1714
|
+
error: result.error ?? "C# execution failed",
|
|
1715
|
+
...firstUserDiagnostic ? { errorLine: firstUserDiagnostic.line } : {},
|
|
1716
|
+
consoleOutput: result.consoleOutput ?? [],
|
|
1717
|
+
timings: result.timings
|
|
1718
|
+
};
|
|
1719
|
+
}
|
|
1720
|
+
return {
|
|
1721
|
+
success: true,
|
|
1722
|
+
output: result.output,
|
|
1723
|
+
consoleOutput: result.consoleOutput ?? [],
|
|
1724
|
+
timings: result.timings
|
|
1725
|
+
};
|
|
1726
|
+
}
|
|
1727
|
+
async executeCodeInterviewMode(code, functionName, inputs, executionStyle) {
|
|
1728
|
+
await this.init();
|
|
1729
|
+
let result;
|
|
1730
|
+
try {
|
|
1731
|
+
result = await this.executeWithTimeout(
|
|
1732
|
+
() => this.sendMessage(
|
|
1733
|
+
"execute-code-interview",
|
|
1734
|
+
{
|
|
1735
|
+
code,
|
|
1736
|
+
functionName,
|
|
1737
|
+
inputs,
|
|
1738
|
+
executionStyle,
|
|
1739
|
+
assetBaseUrl: this.options.assetBaseUrl,
|
|
1740
|
+
timeoutMs: Math.max(100, this.interviewTimeoutMs - 1e3),
|
|
1741
|
+
...this.workerOptionsPayload()
|
|
1742
|
+
},
|
|
1743
|
+
this.interviewTimeoutMs + 5e3
|
|
1744
|
+
),
|
|
1745
|
+
this.interviewTimeoutMs
|
|
1746
|
+
);
|
|
1747
|
+
} catch {
|
|
1748
|
+
return {
|
|
1749
|
+
success: false,
|
|
1750
|
+
output: null,
|
|
1751
|
+
error: "Time Limit Exceeded",
|
|
1752
|
+
timeoutReason: "client-timeout",
|
|
1753
|
+
diagnosticStage: "interview",
|
|
1754
|
+
consoleOutput: [],
|
|
1755
|
+
timings: { totalMs: this.interviewTimeoutMs }
|
|
1756
|
+
};
|
|
1757
|
+
}
|
|
1758
|
+
if (!result.success) {
|
|
1759
|
+
const firstUserDiagnostic = result.diagnostics?.find(isCSharpUserDiagnostic);
|
|
1760
|
+
if (this.isInterviewTimeoutLike(result)) {
|
|
1761
|
+
return {
|
|
1762
|
+
success: false,
|
|
1763
|
+
output: null,
|
|
1764
|
+
error: "Time Limit Exceeded",
|
|
1765
|
+
timeoutReason: result.timeoutReason ?? "client-timeout",
|
|
1766
|
+
diagnosticStage: "interview",
|
|
1767
|
+
consoleOutput: result.consoleOutput ?? [],
|
|
1768
|
+
timings: result.timings
|
|
1769
|
+
};
|
|
1770
|
+
}
|
|
1771
|
+
return {
|
|
1772
|
+
success: false,
|
|
1773
|
+
output: null,
|
|
1774
|
+
error: result.error ?? "C# execution failed",
|
|
1775
|
+
...firstUserDiagnostic ? { errorLine: firstUserDiagnostic.line } : {},
|
|
1776
|
+
consoleOutput: result.consoleOutput ?? [],
|
|
1777
|
+
timings: result.timings
|
|
1778
|
+
};
|
|
1779
|
+
}
|
|
1780
|
+
return {
|
|
1781
|
+
success: true,
|
|
1782
|
+
output: result.output,
|
|
1783
|
+
consoleOutput: result.consoleOutput ?? [],
|
|
1784
|
+
timings: result.timings
|
|
1785
|
+
};
|
|
1786
|
+
}
|
|
1787
|
+
async executeWithTracing(code, functionName, inputs, options, executionStyle) {
|
|
1788
|
+
await this.init();
|
|
1789
|
+
let result;
|
|
1790
|
+
try {
|
|
1791
|
+
result = await this.executeWithTimeout(
|
|
1792
|
+
() => this.sendMessage(
|
|
1793
|
+
"execute-with-tracing",
|
|
1794
|
+
{
|
|
1795
|
+
code,
|
|
1796
|
+
functionName,
|
|
1797
|
+
inputs,
|
|
1798
|
+
executionStyle,
|
|
1799
|
+
assetBaseUrl: this.options.assetBaseUrl,
|
|
1800
|
+
timeoutMs: Math.max(100, this.tracingTimeoutMs - 1e3),
|
|
1801
|
+
maxTraceSteps: options?.maxTraceSteps,
|
|
1802
|
+
maxLineEvents: options?.maxLineEvents,
|
|
1803
|
+
maxSingleLineHits: options?.maxSingleLineHits,
|
|
1804
|
+
maxStoredEvents: options?.maxStoredEvents,
|
|
1805
|
+
minimalTrace: options?.minimalTrace,
|
|
1806
|
+
...this.workerOptionsPayload()
|
|
1807
|
+
},
|
|
1808
|
+
this.tracingTimeoutMs + 5e3
|
|
1809
|
+
),
|
|
1810
|
+
this.tracingTimeoutMs
|
|
1811
|
+
);
|
|
1812
|
+
} catch (error) {
|
|
1813
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1814
|
+
const trace2 = this.createTrace([
|
|
1815
|
+
{
|
|
1816
|
+
kind: "timeout",
|
|
1817
|
+
runId: "csharp:run",
|
|
1818
|
+
file: CSHARP_DEFAULT_FILE,
|
|
1819
|
+
message
|
|
1820
|
+
}
|
|
1821
|
+
]);
|
|
1822
|
+
return {
|
|
1823
|
+
success: false,
|
|
1824
|
+
output: null,
|
|
1825
|
+
error: message,
|
|
1826
|
+
trace: trace2,
|
|
1827
|
+
executionTimeMs: this.tracingTimeoutMs,
|
|
1828
|
+
consoleOutput: [],
|
|
1829
|
+
traceLimitExceeded: true,
|
|
1830
|
+
timeoutReason: "client-timeout",
|
|
1831
|
+
lineEventCount: trace2.lineEventCount,
|
|
1832
|
+
traceStepCount: trace2.traceStepCount,
|
|
1833
|
+
timings: { totalMs: this.tracingTimeoutMs }
|
|
1834
|
+
};
|
|
1835
|
+
}
|
|
1836
|
+
const consoleOutput = result.consoleOutput ?? [];
|
|
1837
|
+
const events = [
|
|
1838
|
+
...result.events ?? [],
|
|
1839
|
+
...consoleOutput.map((text) => ({
|
|
1840
|
+
kind: "stdout",
|
|
1841
|
+
runId: "csharp:run",
|
|
1842
|
+
file: CSHARP_DEFAULT_FILE,
|
|
1843
|
+
text
|
|
1844
|
+
}))
|
|
1845
|
+
];
|
|
1846
|
+
const trace = this.createTrace(events);
|
|
1847
|
+
if (!result.success) {
|
|
1848
|
+
const firstUserDiagnostic = result.diagnostics?.find(isCSharpUserDiagnostic);
|
|
1849
|
+
return {
|
|
1850
|
+
success: false,
|
|
1851
|
+
output: null,
|
|
1852
|
+
error: result.error ?? "C# execution failed",
|
|
1853
|
+
...firstUserDiagnostic ? { errorLine: firstUserDiagnostic.line } : {},
|
|
1854
|
+
trace,
|
|
1855
|
+
executionTimeMs: result.executionTimeMs ?? 0,
|
|
1856
|
+
consoleOutput,
|
|
1857
|
+
...result.traceLimitExceeded !== void 0 ? { traceLimitExceeded: result.traceLimitExceeded } : {},
|
|
1858
|
+
...result.timeoutReason ? { timeoutReason: result.timeoutReason } : {},
|
|
1859
|
+
lineEventCount: trace.lineEventCount,
|
|
1860
|
+
traceStepCount: trace.traceStepCount,
|
|
1861
|
+
timings: result.timings
|
|
1862
|
+
};
|
|
1863
|
+
}
|
|
1864
|
+
return {
|
|
1865
|
+
success: true,
|
|
1866
|
+
output: result.output,
|
|
1867
|
+
trace,
|
|
1868
|
+
executionTimeMs: result.executionTimeMs ?? 0,
|
|
1869
|
+
consoleOutput,
|
|
1870
|
+
...result.traceLimitExceeded !== void 0 ? { traceLimitExceeded: result.traceLimitExceeded } : {},
|
|
1871
|
+
...result.timeoutReason ? { timeoutReason: result.timeoutReason } : {},
|
|
1872
|
+
lineEventCount: trace.lineEventCount,
|
|
1873
|
+
traceStepCount: trace.traceStepCount,
|
|
1874
|
+
timings: result.timings
|
|
1875
|
+
};
|
|
1876
|
+
}
|
|
1877
|
+
createTrace(events) {
|
|
1878
|
+
return {
|
|
1879
|
+
schemaVersion: RUNTIME_TRACE_SCHEMA_VERSION,
|
|
1880
|
+
language: "csharp",
|
|
1881
|
+
runId: "csharp:run",
|
|
1882
|
+
events: events.map(normalizeCSharpTraceEventFile),
|
|
1883
|
+
lineEventCount: events.filter((event) => event.kind === "line").length,
|
|
1884
|
+
traceStepCount: events.length
|
|
1885
|
+
};
|
|
1886
|
+
}
|
|
1887
|
+
isInterviewTimeoutLike(result) {
|
|
1888
|
+
if (result.timeoutReason) return true;
|
|
1889
|
+
const normalized = String(result.error ?? "").toLowerCase();
|
|
1890
|
+
return normalized.includes("timed out") || normalized.includes("trace-limit") || normalized.includes("line-limit") || normalized.includes("single-line-limit") || normalized.includes("recursion-limit") || normalized.includes("memory-limit");
|
|
1891
|
+
}
|
|
1892
|
+
terminate() {
|
|
1893
|
+
this.terminateAndReset();
|
|
1894
|
+
}
|
|
1895
|
+
};
|
|
1896
|
+
|
|
1897
|
+
// packages/harness-browser/src/cpp-worker-client.ts
|
|
1898
|
+
var CppClientTimeoutError = class extends Error {
|
|
1899
|
+
constructor(message, stage, timeoutMs) {
|
|
1900
|
+
super(message);
|
|
1901
|
+
this.stage = stage;
|
|
1902
|
+
this.timeoutMs = timeoutMs;
|
|
1903
|
+
this.name = "CppClientTimeoutError";
|
|
1904
|
+
}
|
|
1905
|
+
};
|
|
1906
|
+
var INIT_TIMEOUT_MS5 = 12e4;
|
|
1907
|
+
var EXECUTION_TIMEOUT_MS5 = 6e4;
|
|
1908
|
+
var TRACING_TIMEOUT_MS5 = 6e4;
|
|
1909
|
+
var INTERVIEW_MODE_TIMEOUT_MS4 = 3e4;
|
|
1910
|
+
var MESSAGE_TIMEOUT_MS5 = 3e4;
|
|
1911
|
+
var WORKER_READY_TIMEOUT_MS5 = 1e4;
|
|
1912
|
+
var CPP_DEFAULT_FILE = "solution.cpp";
|
|
1913
|
+
var CppWorkerClient = class {
|
|
1914
|
+
constructor(options) {
|
|
1915
|
+
this.options = options;
|
|
1916
|
+
this.debug = options.debug ?? process.env.NODE_ENV === "development";
|
|
1917
|
+
this.initTimeoutMs = options.initTimeoutMs ?? INIT_TIMEOUT_MS5;
|
|
1918
|
+
this.executionTimeoutMs = options.executionTimeoutMs ?? EXECUTION_TIMEOUT_MS5;
|
|
1919
|
+
this.tracingTimeoutMs = options.tracingTimeoutMs ?? TRACING_TIMEOUT_MS5;
|
|
1920
|
+
this.interviewTimeoutMs = options.interviewTimeoutMs ?? INTERVIEW_MODE_TIMEOUT_MS4;
|
|
1921
|
+
this.compilerFrameUrl = options.compilerFrameUrl;
|
|
1922
|
+
}
|
|
1923
|
+
worker = null;
|
|
1924
|
+
pendingMessages = /* @__PURE__ */ new Map();
|
|
1925
|
+
messageId = 0;
|
|
1926
|
+
initPromise = null;
|
|
1927
|
+
warmupPromise = null;
|
|
1928
|
+
workerReadyPromise = null;
|
|
1929
|
+
workerReadyResolve = null;
|
|
1930
|
+
workerReadyReject = null;
|
|
1931
|
+
debug;
|
|
1932
|
+
initTimeoutMs;
|
|
1933
|
+
executionTimeoutMs;
|
|
1934
|
+
tracingTimeoutMs;
|
|
1935
|
+
interviewTimeoutMs;
|
|
1936
|
+
compilerFrameUrl;
|
|
1937
|
+
activeCompilerFrames = /* @__PURE__ */ new Set();
|
|
1938
|
+
compilerFrame = null;
|
|
1939
|
+
compilerFrameReadyPromise = null;
|
|
1940
|
+
compilerFrameReadyResolve = null;
|
|
1941
|
+
compilerFrameReadyReject = null;
|
|
1942
|
+
compilerFrameTargetOrigin = "";
|
|
1943
|
+
compilerFrameRequestId = 0;
|
|
1944
|
+
compilerFrameMessageHandler = null;
|
|
1945
|
+
pendingCompilerFrameRequests = /* @__PURE__ */ new Map();
|
|
1946
|
+
isSupported() {
|
|
1947
|
+
return typeof Worker !== "undefined";
|
|
1948
|
+
}
|
|
1949
|
+
getWorker() {
|
|
1950
|
+
if (this.worker) return this.worker;
|
|
1951
|
+
if (!this.isSupported()) {
|
|
1952
|
+
throw new Error("Web Workers are not supported in this environment");
|
|
1953
|
+
}
|
|
1954
|
+
this.workerReadyPromise = new Promise((resolve, reject) => {
|
|
1955
|
+
this.workerReadyResolve = resolve;
|
|
1956
|
+
this.workerReadyReject = (error) => reject(error);
|
|
1957
|
+
});
|
|
1958
|
+
const workerUrl = this.debug && !this.options.workerUrl.includes("?") ? `${this.options.workerUrl}?dev=${Date.now()}` : this.options.workerUrl;
|
|
1959
|
+
this.worker = new Worker(workerUrl, { type: "module" });
|
|
1960
|
+
this.worker.onmessage = (event) => {
|
|
1961
|
+
const { id, type, payload } = event.data;
|
|
1962
|
+
if (type === "worker-ready") {
|
|
1963
|
+
this.workerReadyResolve?.();
|
|
1964
|
+
this.workerReadyResolve = null;
|
|
1965
|
+
this.workerReadyReject = null;
|
|
1966
|
+
logRuntimeDiagnostic("info", {
|
|
1967
|
+
component: "CppWorkerClient",
|
|
1968
|
+
runtime: "cpp",
|
|
1969
|
+
phase: "worker-ready",
|
|
1970
|
+
message: "C++ worker is ready."
|
|
1971
|
+
}, { enabled: this.debug });
|
|
1972
|
+
return;
|
|
1973
|
+
}
|
|
1974
|
+
if (type === "idle-timeout") {
|
|
1975
|
+
logRuntimeDiagnostic("info", {
|
|
1976
|
+
component: "CppWorkerClient",
|
|
1977
|
+
runtime: "cpp",
|
|
1978
|
+
phase: "idle-timeout",
|
|
1979
|
+
message: "C++ worker closed after idle timeout."
|
|
1980
|
+
}, { enabled: this.debug });
|
|
1981
|
+
this.terminateAndReset(new Error("C++ worker closed after idle timeout"));
|
|
1982
|
+
return;
|
|
1983
|
+
}
|
|
1984
|
+
if (type === "compile-request") {
|
|
1985
|
+
this.handleCompileRequest(event.data).catch((error) => {
|
|
1986
|
+
if (!event.data.requestId) return;
|
|
1987
|
+
this.worker?.postMessage({
|
|
1988
|
+
type: "compile-response",
|
|
1989
|
+
requestId: event.data.requestId,
|
|
1990
|
+
payload: { success: false, error: error instanceof Error ? error.message : String(error) }
|
|
1991
|
+
});
|
|
1992
|
+
});
|
|
1993
|
+
return;
|
|
1994
|
+
}
|
|
1995
|
+
if (!id) return;
|
|
1996
|
+
const pending = this.pendingMessages.get(id);
|
|
1997
|
+
if (!pending) return;
|
|
1998
|
+
this.pendingMessages.delete(id);
|
|
1999
|
+
if (pending.timeoutId) globalThis.clearTimeout(pending.timeoutId);
|
|
2000
|
+
if (type === "error") {
|
|
2001
|
+
pending.reject(new Error(payload.error));
|
|
2002
|
+
return;
|
|
2003
|
+
}
|
|
2004
|
+
pending.resolve(payload);
|
|
2005
|
+
};
|
|
2006
|
+
this.worker.onerror = (error) => {
|
|
2007
|
+
logRuntimeDiagnostic("error", {
|
|
2008
|
+
component: "CppWorkerClient",
|
|
2009
|
+
runtime: "cpp",
|
|
2010
|
+
phase: "worker-error",
|
|
2011
|
+
message: "C++ worker emitted an error event.",
|
|
2012
|
+
detail: {
|
|
2013
|
+
message: error.message,
|
|
2014
|
+
filename: error.filename,
|
|
2015
|
+
lineno: error.lineno,
|
|
2016
|
+
colno: error.colno
|
|
2017
|
+
}
|
|
2018
|
+
});
|
|
2019
|
+
const workerError = new Error(error.message || "C++ worker error");
|
|
2020
|
+
this.workerReadyReject?.(workerError);
|
|
2021
|
+
this.workerReadyResolve = null;
|
|
2022
|
+
this.workerReadyReject = null;
|
|
2023
|
+
this.terminateAndReset(workerError);
|
|
2024
|
+
};
|
|
2025
|
+
return this.worker;
|
|
2026
|
+
}
|
|
2027
|
+
async waitForWorkerReady() {
|
|
2028
|
+
const readyPromise = this.workerReadyPromise;
|
|
2029
|
+
if (!readyPromise) return;
|
|
2030
|
+
await new Promise((resolve, reject) => {
|
|
2031
|
+
let settled = false;
|
|
2032
|
+
const timeoutId = globalThis.setTimeout(() => {
|
|
2033
|
+
if (settled) return;
|
|
2034
|
+
settled = true;
|
|
2035
|
+
const timeoutError = new Error(
|
|
2036
|
+
`C++ worker failed to initialize in time (${Math.round(WORKER_READY_TIMEOUT_MS5 / 1e3)}s)`
|
|
2037
|
+
);
|
|
2038
|
+
logRuntimeDiagnostic("warn", {
|
|
2039
|
+
component: "CppWorkerClient",
|
|
2040
|
+
runtime: "cpp",
|
|
2041
|
+
phase: "worker-ready-timeout",
|
|
2042
|
+
message: "C++ worker did not send worker-ready before the timeout.",
|
|
2043
|
+
detail: { timeoutMs: WORKER_READY_TIMEOUT_MS5 }
|
|
2044
|
+
}, { enabled: this.debug });
|
|
2045
|
+
this.terminateAndReset(timeoutError);
|
|
2046
|
+
reject(timeoutError);
|
|
2047
|
+
}, WORKER_READY_TIMEOUT_MS5);
|
|
2048
|
+
readyPromise.then(() => {
|
|
2049
|
+
if (settled) return;
|
|
2050
|
+
settled = true;
|
|
2051
|
+
globalThis.clearTimeout(timeoutId);
|
|
2052
|
+
resolve();
|
|
2053
|
+
}).catch((error) => {
|
|
2054
|
+
if (settled) return;
|
|
2055
|
+
settled = true;
|
|
2056
|
+
globalThis.clearTimeout(timeoutId);
|
|
2057
|
+
reject(error instanceof Error ? error : new Error(String(error)));
|
|
2058
|
+
});
|
|
2059
|
+
});
|
|
2060
|
+
}
|
|
2061
|
+
async sendMessage(type, payload, timeoutMs = MESSAGE_TIMEOUT_MS5) {
|
|
2062
|
+
const worker = this.getWorker();
|
|
2063
|
+
await this.waitForWorkerReady();
|
|
2064
|
+
const id = String(++this.messageId);
|
|
2065
|
+
return new Promise((resolve, reject) => {
|
|
2066
|
+
this.pendingMessages.set(id, {
|
|
2067
|
+
resolve,
|
|
2068
|
+
reject
|
|
2069
|
+
});
|
|
2070
|
+
const timeoutId = globalThis.setTimeout(() => {
|
|
2071
|
+
const pending2 = this.pendingMessages.get(id);
|
|
2072
|
+
if (!pending2) return;
|
|
2073
|
+
this.pendingMessages.delete(id);
|
|
2074
|
+
logRuntimeDiagnostic("warn", {
|
|
2075
|
+
component: "CppWorkerClient",
|
|
2076
|
+
runtime: "cpp",
|
|
2077
|
+
phase: "worker-request-timeout",
|
|
2078
|
+
message: "C++ worker request timed out.",
|
|
2079
|
+
detail: { id, type, timeoutMs }
|
|
2080
|
+
}, { enabled: this.debug });
|
|
2081
|
+
pending2.reject(new Error(`Worker request timed out: ${type}`));
|
|
2082
|
+
}, timeoutMs);
|
|
2083
|
+
const pending = this.pendingMessages.get(id);
|
|
2084
|
+
if (pending) pending.timeoutId = timeoutId;
|
|
2085
|
+
worker.postMessage({ id, type, payload });
|
|
2086
|
+
});
|
|
2087
|
+
}
|
|
2088
|
+
async executeWithTimeout(executor, timeoutMs, stage) {
|
|
2089
|
+
return new Promise((resolve, reject) => {
|
|
2090
|
+
let settled = false;
|
|
2091
|
+
const timeoutId = globalThis.setTimeout(() => {
|
|
2092
|
+
if (settled) return;
|
|
2093
|
+
settled = true;
|
|
2094
|
+
const timeoutLabel = stage === "trace" ? "tracing" : stage === "interview" ? "interview execution" : "compile/run";
|
|
2095
|
+
const timeoutError = new CppClientTimeoutError(
|
|
2096
|
+
`C++ ${timeoutLabel} timed out after ${Math.round(timeoutMs / 1e3)} seconds.`,
|
|
2097
|
+
stage,
|
|
2098
|
+
timeoutMs
|
|
2099
|
+
);
|
|
2100
|
+
logRuntimeDiagnostic("warn", {
|
|
2101
|
+
component: "CppWorkerClient",
|
|
2102
|
+
runtime: "cpp",
|
|
2103
|
+
phase: "execution-timeout",
|
|
2104
|
+
message: "C++ execution timed out; terminating worker.",
|
|
2105
|
+
detail: { timeoutMs, stage }
|
|
2106
|
+
}, { enabled: this.debug });
|
|
2107
|
+
this.terminateAndReset(timeoutError);
|
|
2108
|
+
reject(timeoutError);
|
|
2109
|
+
}, timeoutMs);
|
|
2110
|
+
executor().then((result) => {
|
|
2111
|
+
if (settled) return;
|
|
2112
|
+
settled = true;
|
|
2113
|
+
globalThis.clearTimeout(timeoutId);
|
|
2114
|
+
resolve(result);
|
|
2115
|
+
}).catch((error) => {
|
|
2116
|
+
if (settled) return;
|
|
2117
|
+
settled = true;
|
|
2118
|
+
globalThis.clearTimeout(timeoutId);
|
|
2119
|
+
reject(error);
|
|
2120
|
+
});
|
|
2121
|
+
});
|
|
2122
|
+
}
|
|
2123
|
+
isClientTimeout(error) {
|
|
2124
|
+
return error instanceof CppClientTimeoutError || error instanceof Error && error.message.includes("C++") && error.message.includes("timed out");
|
|
2125
|
+
}
|
|
2126
|
+
timeoutCodeResult(error) {
|
|
2127
|
+
const timeoutError = error instanceof CppClientTimeoutError ? error : null;
|
|
2128
|
+
return {
|
|
2129
|
+
success: false,
|
|
2130
|
+
output: null,
|
|
2131
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2132
|
+
consoleOutput: [],
|
|
2133
|
+
timeoutReason: "client-timeout",
|
|
2134
|
+
diagnosticStage: timeoutError?.stage === "interview" ? "interview" : "runtime",
|
|
2135
|
+
timings: { totalMs: timeoutError?.timeoutMs ?? this.executionTimeoutMs }
|
|
2136
|
+
};
|
|
2137
|
+
}
|
|
2138
|
+
timeoutTraceResult(error) {
|
|
2139
|
+
const timeoutError = error instanceof CppClientTimeoutError ? error : null;
|
|
2140
|
+
const trace = createEmptyRuntimeTrace("cpp", { runId: "cpp:run", file: CPP_DEFAULT_FILE });
|
|
2141
|
+
trace.events = [
|
|
2142
|
+
{
|
|
2143
|
+
kind: "timeout",
|
|
2144
|
+
runId: "cpp:run",
|
|
2145
|
+
file: CPP_DEFAULT_FILE,
|
|
2146
|
+
message: error instanceof Error ? error.message : String(error)
|
|
2147
|
+
}
|
|
2148
|
+
];
|
|
2149
|
+
trace.traceStepCount = 1;
|
|
2150
|
+
return {
|
|
2151
|
+
success: false,
|
|
2152
|
+
output: null,
|
|
2153
|
+
error: error instanceof Error ? error.message : String(error),
|
|
2154
|
+
trace,
|
|
2155
|
+
executionTimeMs: timeoutError?.timeoutMs ?? this.tracingTimeoutMs,
|
|
2156
|
+
consoleOutput: [],
|
|
2157
|
+
traceLimitExceeded: true,
|
|
2158
|
+
timeoutReason: "client-timeout",
|
|
2159
|
+
lineEventCount: 0,
|
|
2160
|
+
traceStepCount: 1,
|
|
2161
|
+
timings: { totalMs: timeoutError?.timeoutMs ?? this.tracingTimeoutMs }
|
|
2162
|
+
};
|
|
2163
|
+
}
|
|
2164
|
+
terminateAndReset(reason = new Error("Worker was terminated")) {
|
|
2165
|
+
this.workerReadyReject?.(reason);
|
|
2166
|
+
if (this.worker) {
|
|
2167
|
+
this.worker.terminate();
|
|
2168
|
+
this.worker = null;
|
|
2169
|
+
}
|
|
2170
|
+
this.initPromise = null;
|
|
2171
|
+
this.warmupPromise = null;
|
|
2172
|
+
this.workerReadyPromise = null;
|
|
2173
|
+
this.workerReadyResolve = null;
|
|
2174
|
+
this.workerReadyReject = null;
|
|
2175
|
+
for (const [, pending] of this.pendingMessages) {
|
|
2176
|
+
if (pending.timeoutId) globalThis.clearTimeout(pending.timeoutId);
|
|
2177
|
+
pending.reject(reason);
|
|
2178
|
+
}
|
|
2179
|
+
this.pendingMessages.clear();
|
|
2180
|
+
this.clearCompilerFrames();
|
|
2181
|
+
}
|
|
2182
|
+
shouldRetryInit(error) {
|
|
2183
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
2184
|
+
return message.includes("timed out") || message.includes("Worker request timed out") || message.includes("worker error") || message.includes("Failed to fetch") || message.includes("was terminated") || message.includes("closed after idle timeout");
|
|
2185
|
+
}
|
|
2186
|
+
sendInitMessage() {
|
|
2187
|
+
return this.sendMessage(
|
|
2188
|
+
"init",
|
|
2189
|
+
{
|
|
2190
|
+
assets: {
|
|
2191
|
+
clangWasmUrl: this.options.clangWasmUrl,
|
|
2192
|
+
lldWasmUrl: this.options.lldWasmUrl,
|
|
2193
|
+
sysrootUrl: this.options.sysrootUrl,
|
|
2194
|
+
runtimeHeaderUrl: this.options.runtimeHeaderUrl,
|
|
2195
|
+
compilerBundleUrl: this.options.compilerBundleUrl,
|
|
2196
|
+
compilerFrameEnabled: Boolean(this.compilerFrameUrl && typeof document !== "undefined"),
|
|
2197
|
+
compilerFrameUrl: this.compilerFrameUrl,
|
|
2198
|
+
compilerWorkerUrl: this.options.compilerWorkerUrl
|
|
2199
|
+
},
|
|
2200
|
+
...this.workerOptionsPayload()
|
|
2201
|
+
},
|
|
2202
|
+
this.initTimeoutMs
|
|
2203
|
+
);
|
|
2204
|
+
}
|
|
2205
|
+
async init() {
|
|
2206
|
+
if (this.initPromise) return this.initPromise;
|
|
2207
|
+
this.initPromise = (async () => {
|
|
2208
|
+
try {
|
|
2209
|
+
return await this.sendInitMessage();
|
|
2210
|
+
} catch (error) {
|
|
2211
|
+
if (!this.shouldRetryInit(error)) throw error;
|
|
2212
|
+
this.terminateAndReset(error instanceof Error ? error : new Error(String(error)));
|
|
2213
|
+
return this.sendInitMessage();
|
|
2214
|
+
}
|
|
2215
|
+
})();
|
|
2216
|
+
try {
|
|
2217
|
+
return await this.initPromise;
|
|
2218
|
+
} catch (error) {
|
|
2219
|
+
this.initPromise = null;
|
|
2220
|
+
throw error;
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
workerOptionsPayload() {
|
|
2224
|
+
return this.options.workerIdleTimeoutMs === void 0 ? {} : { idleTimeoutMs: this.options.workerIdleTimeoutMs };
|
|
2225
|
+
}
|
|
2226
|
+
async warmup() {
|
|
2227
|
+
if (this.warmupPromise) return this.warmupPromise;
|
|
2228
|
+
this.warmupPromise = (async () => {
|
|
2229
|
+
try {
|
|
2230
|
+
await this.init();
|
|
2231
|
+
return await this.sendMessage("warmup", this.workerOptionsPayload(), this.initTimeoutMs);
|
|
2232
|
+
} catch (error) {
|
|
2233
|
+
this.warmupPromise = null;
|
|
2234
|
+
throw error;
|
|
2235
|
+
}
|
|
2236
|
+
})();
|
|
2237
|
+
return this.warmupPromise;
|
|
2238
|
+
}
|
|
2239
|
+
clearCompilerFrames(reason = new Error("C++ compiler frame was closed")) {
|
|
2240
|
+
this.compilerFrameReadyReject?.(reason);
|
|
2241
|
+
this.compilerFrameReadyPromise = null;
|
|
2242
|
+
this.compilerFrameReadyResolve = null;
|
|
2243
|
+
this.compilerFrameReadyReject = null;
|
|
2244
|
+
if (this.compilerFrameMessageHandler) {
|
|
2245
|
+
globalThis.removeEventListener("message", this.compilerFrameMessageHandler);
|
|
2246
|
+
this.compilerFrameMessageHandler = null;
|
|
2247
|
+
}
|
|
2248
|
+
for (const [, pending] of this.pendingCompilerFrameRequests) {
|
|
2249
|
+
globalThis.clearTimeout(pending.timeoutId);
|
|
2250
|
+
pending.resolve({ success: false, error: reason.message });
|
|
2251
|
+
}
|
|
2252
|
+
this.pendingCompilerFrameRequests.clear();
|
|
2253
|
+
this.compilerFrame = null;
|
|
2254
|
+
this.compilerFrameTargetOrigin = "";
|
|
2255
|
+
for (const frame of this.activeCompilerFrames) {
|
|
2256
|
+
frame.remove();
|
|
2257
|
+
}
|
|
2258
|
+
this.activeCompilerFrames.clear();
|
|
2259
|
+
}
|
|
2260
|
+
async handleCompileRequest(message) {
|
|
2261
|
+
if (!message.requestId) return;
|
|
2262
|
+
const worker = this.worker;
|
|
2263
|
+
if (!worker) return;
|
|
2264
|
+
const result = await this.compileInFrame(message.payload);
|
|
2265
|
+
const transfer = result?.programBuffer instanceof ArrayBuffer ? [result.programBuffer] : [];
|
|
2266
|
+
worker.postMessage(
|
|
2267
|
+
{
|
|
2268
|
+
type: "compile-response",
|
|
2269
|
+
requestId: message.requestId,
|
|
2270
|
+
payload: result
|
|
2271
|
+
},
|
|
2272
|
+
transfer
|
|
2273
|
+
);
|
|
2274
|
+
}
|
|
2275
|
+
ensureCompilerFrame() {
|
|
2276
|
+
if (!this.compilerFrameUrl || typeof document === "undefined") {
|
|
2277
|
+
return Promise.reject(new Error("C++ compiler frame is not available."));
|
|
2278
|
+
}
|
|
2279
|
+
if (this.compilerFrame && this.compilerFrameReadyPromise) return this.compilerFrameReadyPromise;
|
|
2280
|
+
const frameUrl = new URL(this.compilerFrameUrl, globalThis.location?.href);
|
|
2281
|
+
this.compilerFrameTargetOrigin = frameUrl.origin;
|
|
2282
|
+
const iframe = document.createElement("iframe");
|
|
2283
|
+
iframe.src = frameUrl.href;
|
|
2284
|
+
iframe.style.display = "none";
|
|
2285
|
+
iframe.setAttribute("aria-hidden", "true");
|
|
2286
|
+
this.compilerFrame = iframe;
|
|
2287
|
+
this.activeCompilerFrames.add(iframe);
|
|
2288
|
+
this.compilerFrameReadyPromise = new Promise((resolve, reject) => {
|
|
2289
|
+
let settled = false;
|
|
2290
|
+
let timeoutId;
|
|
2291
|
+
const finishReady = () => {
|
|
2292
|
+
if (settled) return;
|
|
2293
|
+
settled = true;
|
|
2294
|
+
globalThis.clearTimeout(timeoutId);
|
|
2295
|
+
this.compilerFrameReadyResolve = null;
|
|
2296
|
+
this.compilerFrameReadyReject = null;
|
|
2297
|
+
resolve();
|
|
2298
|
+
};
|
|
2299
|
+
const onMessage = (event) => {
|
|
2300
|
+
if (event.source !== iframe.contentWindow) return;
|
|
2301
|
+
if (event.origin !== this.compilerFrameTargetOrigin) return;
|
|
2302
|
+
if (event.data?.type === "frame-ready") {
|
|
2303
|
+
finishReady();
|
|
2304
|
+
return;
|
|
2305
|
+
}
|
|
2306
|
+
const requestId = event.data?.id;
|
|
2307
|
+
if (!requestId) return;
|
|
2308
|
+
const pending = this.pendingCompilerFrameRequests.get(requestId);
|
|
2309
|
+
if (!pending) return;
|
|
2310
|
+
this.pendingCompilerFrameRequests.delete(requestId);
|
|
2311
|
+
globalThis.clearTimeout(pending.timeoutId);
|
|
2312
|
+
const response = event.data;
|
|
2313
|
+
pending.resolve(response.payload ?? { success: false, error: "C++ compiler frame returned an empty response." });
|
|
2314
|
+
};
|
|
2315
|
+
this.compilerFrameMessageHandler = onMessage;
|
|
2316
|
+
timeoutId = globalThis.setTimeout(() => {
|
|
2317
|
+
const error = new Error("C++ compiler frame request timed out.");
|
|
2318
|
+
this.clearCompilerFrames(error);
|
|
2319
|
+
reject(error);
|
|
2320
|
+
}, this.initTimeoutMs);
|
|
2321
|
+
this.compilerFrameReadyResolve = finishReady;
|
|
2322
|
+
this.compilerFrameReadyReject = (error) => {
|
|
2323
|
+
if (settled) return;
|
|
2324
|
+
settled = true;
|
|
2325
|
+
globalThis.clearTimeout(timeoutId);
|
|
2326
|
+
reject(error);
|
|
2327
|
+
};
|
|
2328
|
+
globalThis.addEventListener("message", onMessage);
|
|
2329
|
+
document.body.appendChild(iframe);
|
|
2330
|
+
});
|
|
2331
|
+
return this.compilerFrameReadyPromise;
|
|
2332
|
+
}
|
|
2333
|
+
async compileInFrame(payload) {
|
|
2334
|
+
try {
|
|
2335
|
+
await this.ensureCompilerFrame();
|
|
2336
|
+
} catch (error) {
|
|
2337
|
+
return { success: false, error: error instanceof Error ? error.message : String(error) };
|
|
2338
|
+
}
|
|
2339
|
+
const iframe = this.compilerFrame;
|
|
2340
|
+
const frameWindow = iframe?.contentWindow;
|
|
2341
|
+
if (!frameWindow) {
|
|
2342
|
+
return { success: false, error: "C++ compiler frame is not available." };
|
|
2343
|
+
}
|
|
2344
|
+
return new Promise((resolve) => {
|
|
2345
|
+
const requestId = `compile-${++this.compilerFrameRequestId}`;
|
|
2346
|
+
const timeoutId = globalThis.setTimeout(() => {
|
|
2347
|
+
this.pendingCompilerFrameRequests.delete(requestId);
|
|
2348
|
+
resolve({ success: false, error: "C++ compiler frame request timed out." });
|
|
2349
|
+
}, this.initTimeoutMs);
|
|
2350
|
+
this.pendingCompilerFrameRequests.set(requestId, { resolve, timeoutId });
|
|
2351
|
+
frameWindow.postMessage(
|
|
2352
|
+
{
|
|
2353
|
+
id: requestId,
|
|
2354
|
+
type: "compile",
|
|
2355
|
+
payload
|
|
2356
|
+
},
|
|
2357
|
+
this.compilerFrameTargetOrigin
|
|
2358
|
+
);
|
|
2359
|
+
});
|
|
2360
|
+
}
|
|
2361
|
+
async executeCode(code, functionName, inputs, executionStyle) {
|
|
2362
|
+
await this.init();
|
|
2363
|
+
try {
|
|
2364
|
+
return await this.executeWithTimeout(
|
|
2365
|
+
() => this.sendMessage(
|
|
2366
|
+
"compile-run",
|
|
2367
|
+
{ code, functionName, inputs, executionStyle },
|
|
2368
|
+
this.executionTimeoutMs + 5e3
|
|
2369
|
+
),
|
|
2370
|
+
this.executionTimeoutMs,
|
|
2371
|
+
"compile-run"
|
|
2372
|
+
);
|
|
2373
|
+
} catch (error) {
|
|
2374
|
+
if (this.isClientTimeout(error)) return this.timeoutCodeResult(error);
|
|
2375
|
+
throw error;
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
async executeWithTracing(code, functionName, inputs, options, executionStyle) {
|
|
2379
|
+
await this.init();
|
|
2380
|
+
try {
|
|
2381
|
+
return await this.executeWithTimeout(
|
|
2382
|
+
() => this.sendMessage(
|
|
2383
|
+
"execute-with-tracing",
|
|
2384
|
+
{ code, functionName, inputs, options, executionStyle },
|
|
2385
|
+
this.tracingTimeoutMs + 5e3
|
|
2386
|
+
),
|
|
2387
|
+
this.tracingTimeoutMs,
|
|
2388
|
+
"trace"
|
|
2389
|
+
);
|
|
2390
|
+
} catch (error) {
|
|
2391
|
+
if (this.isClientTimeout(error)) return this.timeoutTraceResult(error);
|
|
2392
|
+
throw error;
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
async executeCodeInterviewMode(code, functionName, inputs, executionStyle) {
|
|
2396
|
+
await this.init();
|
|
2397
|
+
try {
|
|
2398
|
+
return await this.executeWithTimeout(
|
|
2399
|
+
() => this.sendMessage(
|
|
2400
|
+
"execute-code-interview",
|
|
2401
|
+
{ code, functionName, inputs, executionStyle },
|
|
2402
|
+
this.interviewTimeoutMs + 5e3
|
|
2403
|
+
),
|
|
2404
|
+
this.interviewTimeoutMs,
|
|
2405
|
+
"interview"
|
|
2406
|
+
);
|
|
2407
|
+
} catch {
|
|
2408
|
+
return {
|
|
2409
|
+
success: false,
|
|
2410
|
+
output: null,
|
|
2411
|
+
error: "Time Limit Exceeded",
|
|
2412
|
+
timeoutReason: "client-timeout",
|
|
2413
|
+
diagnosticStage: "interview",
|
|
2414
|
+
consoleOutput: [],
|
|
2415
|
+
timings: { totalMs: this.interviewTimeoutMs }
|
|
2416
|
+
};
|
|
2417
|
+
}
|
|
815
2418
|
}
|
|
816
2419
|
terminate() {
|
|
817
2420
|
this.terminateAndReset();
|
|
818
2421
|
}
|
|
819
2422
|
};
|
|
820
2423
|
export {
|
|
2424
|
+
CSharpWorkerClient,
|
|
2425
|
+
CppWorkerClient,
|
|
821
2426
|
JavaScriptWorkerClient,
|
|
822
2427
|
JavaWorkerClient,
|
|
823
|
-
PyodideWorkerClient,
|
|
2428
|
+
PythonWorkerClient as PyodideWorkerClient,
|
|
2429
|
+
PythonWorkerClient,
|
|
824
2430
|
isJavaScriptWorkerSupported,
|
|
825
2431
|
isWorkerSupported
|
|
826
2432
|
};
|