Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5d0affe
Build the test tree in FSAC instead of in each client
shayanhabibi Sep 22, 2026
d0650c8
Keep parameterised test cases distinct in the server's test names
shayanhabibi Sep 22, 2026
1b2fa1a
Classify the test platform a project's tests run on
shayanhabibi Sep 22, 2026
d84e1fb
Gate Microsoft.Testing.Platform behind a feature flag
shayanhabibi Sep 22, 2026
12c8736
Map Microsoft.Testing.Platform nodes onto the server's test tree
shayanhabibi Sep 22, 2026
bd0a583
Discover tests through the Microsoft.Testing.Platform server protocol
shayanhabibi Sep 22, 2026
614301a
Discover Microsoft.Testing.Platform projects alongside VSTest projects
shayanhabibi Sep 22, 2026
261a11c
Map a Microsoft.Testing.Platform result onto a test outcome
shayanhabibi Sep 22, 2026
9881629
Run tests through the Microsoft.Testing.Platform server protocol
shayanhabibi Sep 22, 2026
4ef7fee
Answer the platform's request to attach a debugger
shayanhabibi Sep 22, 2026
73d1572
Run Microsoft.Testing.Platform tests alongside VSTest tests
shayanhabibi Sep 22, 2026
80233d8
Cover discovery over Microsoft.Testing.Platform at the LSP level
shayanhabibi Sep 22, 2026
c4993dd
Don't invoke VSTest when no VSTest projects are selected
shayanhabibi Sep 23, 2026
7affbc9
Keep the testing platform client inside FSAC
shayanhabibi Sep 23, 2026
06fef43
Keep MTP test selections explicit
shayanhabibi Sep 23, 2026
78abeb6
Attach to MTP test host before debug runs
shayanhabibi Sep 23, 2026
ac598ea
Skip VSTest discovery when only MTP projects are present
shayanhabibi Sep 23, 2026
73cdafa
Fix FSAC format and analyzer checks
shayanhabibi Sep 24, 2026
ce3620a
Improve caseFragment logic in TestServer.fs
shayanhabibi Sep 24, 2026
28c38ff
Defer VSTest lookup for MTP-only workspaces
shayanhabibi Sep 24, 2026
2008f41
Isolate LSP MTP fixture from Paket test dependencies
shayanhabibi Sep 24, 2026
d6c04cc
Propagate cancellation through MTP test requests
shayanhabibi Sep 24, 2026
5092dc6
Ensure MTP discovery and execution always shut down clients
shayanhabibi Sep 24, 2026
09ec63b
Own launched MTP clients until shutdown, and cover cleanup and mixed …
shayanhabibi Sep 24, 2026
9741d5d
Add parameterised VSTest fixtures for per-case test ids
shayanhabibi Sep 25, 2026
f90c351
Add a versioned, escaped TestId that routes a test to its platform
shayanhabibi Sep 25, 2026
83f6c1d
Issue TestIds for discovered tests and their results
shayanhabibi Sep 25, 2026
5d2ba22
Run a chosen list of discovered VSTest cases
shayanhabibi Sep 25, 2026
4d976ac
Accept TestIds on test run requests
shayanhabibi Sep 25, 2026
415a6bd
Run tests by the ids discovery issued them
shayanhabibi Sep 25, 2026
5ecb40e
Remove PlatformUid from test items
shayanhabibi Sep 25, 2026
9b519b4
Link a testing platform node to its parent by the parent's own id
shayanhabibi Sep 25, 2026
c1dc4f8
Cover debugging and the remaining rejections of id runs
shayanhabibi Sep 25, 2026
f39d038
Carry a testing platform test's console output to its result
shayanhabibi Sep 25, 2026
fdb1954
Keep one testing platform application from failing the others
shayanhabibi Sep 25, 2026
377a368
Qualify a testing platform test's full name by its type
shayanhabibi Sep 25, 2026
7f79e4a
Fix code analysis-based test updates for xunit.v3
farlee2121 Oct 14, 2026
0a54fd5
fix: code analysis-based test updates for xunit.v3
shayanhabibi Oct 16, 2026
2daac4a
Group a testing platform test by the type the platform names
shayanhabibi Nov 14, 2026
47fa28e
Merge remote-tracking branch 'upstream/main' into feature/mtp-server-…
shayanhabibi Nov 14, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions FsAutoComplete.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
</Folder>
<Folder Name="/src/">
<Project Path="src/FsAutoComplete.Logging/FsAutoComplete.Logging.fsproj" />
<Project Path="src/FsAutoComplete.TestingPlatform.Client.Protocol/FsAutoComplete.TestingPlatform.Client.Protocol.csproj" />
<Project Path="src/FsAutoComplete.TestingPlatform.Client/FsAutoComplete.TestingPlatform.Client.fsproj" />
<Project Path="src/FsAutoComplete.ToolStub/FsAutoComplete.ToolStub.csproj" />
</Folder>
<Folder Name="/test/">
Expand Down
1 change: 0 additions & 1 deletion nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<!-- <add key="local" value="./libs" /> -->
</packageSources>
</configuration>
3 changes: 3 additions & 0 deletions src/FsAutoComplete.Core/FsAutoComplete.Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\FsAutoComplete.Logging\FsAutoComplete.Logging.fsproj" />
<ProjectReference Include="../FsAutoComplete.TestingPlatform.Client/FsAutoComplete.TestingPlatform.Client.fsproj" />
<TrimmerRootAssembly Include="FsAutoComplete.Core" />
<InternalsVisibleTo Include="FsAutoComplete.Tests.TestExplorer" />
</ItemGroup>
<ItemGroup>
<Compile Include="SemaphoreSlimLocks.fsi" />
Expand All @@ -19,6 +21,7 @@
<Compile Include="Utils.fsi" />
<Compile Include="Utils.fs" />
<Compile Include="VSTestWrapper.fs" />
<Compile Include="MtpWrapper.fs" />
<Compile Include="TestServer.fs" />
<Compile Include="TestAdapter.fs" />
<Compile Include="DotnetNewTemplate.fs" />
Expand Down
294 changes: 294 additions & 0 deletions src/FsAutoComplete.Core/MtpWrapper.fs
Comment thread
shayanhabibi marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,294 @@
namespace FsAutoComplete.TestServer

open System
open System.Collections.Generic
open System.Runtime.ExceptionServices
open System.Threading
open System.Threading.Tasks
open FsAutoComplete.TestingPlatform.Client

/// Drives Microsoft.Testing.Platform applications over the server-mode protocol. Each application
/// is its own test runner, so there is no separate runner to locate.
module MtpWrapper =
/// Path to a dll or executable that speaks the server-mode protocol.
type TestApplication = string

/// A node of a test tree, paired with the application that reported it.
type DiscoveredNode = TestApplication * TestNodeUpdate

type TestDiscoveryUpdate =
| Progress of DiscoveredNode list
| LogMessage of ClientLogLevel * string

let private clientOptions =
{ MtpClientOptions.Default with
ClientName = "FsAutoComplete"
}

/// Starts a task under the async's cancellation token and reports its outcome only once it has
/// finished: its result, its exception unwrapped, or request cancellation as async cancellation.
/// Async.AwaitTask checks for cancellation after the task it is given is already running, so a
/// racing cancellation is reported while that task carries on, and anything it produces is lost.
/// Cancellation is therefore reported late on purpose: only once the task has noticed it and
/// released everything it holds, which for a test host includes tearing the host down.
/// Internal so the tests can reach it.
let internal startTaskAsync (start: CancellationToken -> Task<'T>) : Async<'T> =
async {
let! cancellationToken = Async.CancellationToken

return!
Async.FromContinuations(fun (ok, error, cancelled) ->
(start cancellationToken)
.ContinueWith(
(fun (completed: Task<'T>) ->
if completed.IsCompletedSuccessfully then
ok completed.Result
else
try
completed.GetAwaiter().GetResult() |> ignore
with
| :? OperationCanceledException as failure when cancellationToken.IsCancellationRequested ->
cancelled failure
| failure -> error failure),
TaskScheduler.Default
)
|> ignore)
}

let private rethrow (error: exn) : 'a =
ExceptionDispatchInfo.Capture(error).Throw()
Unchecked.defaultof<'a>

/// Acquires a resource and owns it from acquisition to disposal, all within one task, so no
/// cancellation can separate the two. The resource is released, then disposed, before the
/// outcome of <c>work</c> is reported. Release is best-effort, so that outcome stays the one
/// observed; it runs first so that disposal finds nothing left to wait for.
/// Internal so the tests can reach it.
let internal ownedAsync<'R, 'T when 'R :> IDisposable>
(acquire: CancellationToken -> Task<'R>)
(release: 'R -> Task)
(work: CancellationToken -> 'R -> Task<'T>)
: Async<'T> =
startTaskAsync (fun cancellationToken ->
task {
use! resource = acquire cancellationToken

let! outcome =
task {
try
let! result = work cancellationToken resource
return Choice1Of2 result
with error ->
return Choice2Of2 error
}

try
do! release resource
with _ ->
()

match outcome with
| Choice1Of2 result -> return result
| Choice2Of2 error -> return rethrow error
})

/// Launches <c>application</c> and owns its client until it is shut down. Shutdown goes through
/// <c>ShutdownAsync</c>, which does not block a thread while the host is torn down, as a
/// synchronous <c>Dispose</c> would.
let private withClientAsync (application: TestApplication) (work: CancellationToken -> MtpClient -> Task<'T>) =
ownedAsync
(fun cancellationToken -> MtpClient.LaunchAsync(application, clientOptions, cancellationToken))
(fun client -> client.ShutdownAsync())
work

/// Runs <c>work</c> for one application of several, so that one which is not built, cannot be
/// launched or fails partway is reported at error level instead of failing the others. Its
/// outcome is <c>Error</c> with the failure; cancellation is not contained.
let private isolatedAsync
(logError: string -> unit)
(application: TestApplication)
(work: Async<'T list>)
: Async<Result<'T list, exn>> =
async {
if not (IO.File.Exists application) then
let message =
$"Skipped test application '{application}': it does not exist. Build its project first."

logError message
return Result.Error(IO.FileNotFoundException(message, application) :> exn)
else
match! Async.Catch work with
| Choice1Of2 nodes -> return Ok nodes
| Choice2Of2 error ->
logError $"Test application '{application}' failed: {error.Message}"
return Result.Error error
}

/// Collects every node an application reports, notifying as the batches arrive.
let private discoverFromAsync (notify: TestDiscoveryUpdate -> unit) (application: TestApplication) =
withClientAsync application (fun cancellationToken client ->
task {
let discovered = ResizeArray<DiscoveredNode>()

use _ =
client.TestNodesUpdated.Subscribe(fun batch ->
let nodes = batch.Updates |> List.map (fun node -> application, node)
discovered.AddRange nodes
notify (Progress nodes))

use _ =
client.LogReceived.Subscribe(fun log -> notify (LogMessage(log.Level, log.Message)))

let! _capabilities = client.InitializeAsync(cancellationToken)
do! client.DiscoverTestsAsync(cancellationToken)
do! client.ExitAsync(cancellationToken)

return List.ofSeq discovered
})

/// A node reported while running, paired with the application that reported it. A test is
/// reported more than once: once as it starts, and again with its outcome.
type RunNode = TestApplication * TestNodeUpdate

type TestRunUpdate =
| Progress of RunNode list
| LogMessage of ClientLogLevel * string

[<RequireQualifiedAccess>]
type TestSelection =
| All
| Uids of string list

/// Each application runs either all tests or an explicit set of discovered test uids.
type RunRequest = TestApplication * TestSelection

type ProcessId = int
type DidDebuggerAttach = bool

/// Answers the server's request to have a debugger attached. Unlike VSTest, where the client
/// launches the test host itself to get ahead of it, the platform runs its own host and asks the
/// client to attach to it; the run continues once this answers.
let attachDebuggerHandler (onAttachDebugger: ProcessId -> DidDebuggerAttach) : ServerRequestHandler =
fun name parameters _cancellationToken ->
if name <> "client/attachDebugger" then
Task.FromResult None
else
let processId =
parameters
|> Option.bind (fun p ->
match p.TryGetValue "processId" with
| true, processId -> Some(Convert.ToInt32 processId)
| _ -> None)

let attached = processId |> Option.map onAttachDebugger |> Option.defaultValue false

Dictionary<string, obj>(dict [ "success", box attached ]) :> IReadOnlyDictionary<string, obj>
|> Some
|> Task.FromResult

/// Runs the requested tests of one application, notifying as the outcomes arrive.
let private runOnAsync
(notify: TestRunUpdate -> unit)
(onAttachDebugger: (ProcessId -> DidDebuggerAttach) option)
((application, selection): RunRequest)
=
withClientAsync application (fun cancellationToken client ->
task {
let reported = ResizeArray<RunNode>()

use _ =
client.TestNodesUpdated.Subscribe(fun batch ->
let nodes = batch.Updates |> List.map (fun node -> application, node)
reported.AddRange nodes
notify (Progress nodes))

use _ =
client.LogReceived.Subscribe(fun log -> notify (LogMessage(log.Level, log.Message)))

let attachOnce =
onAttachDebugger
|> Option.map (fun attach ->
let mutable attachedProcess = None

fun processId ->
if attachedProcess = Some processId then
true
else
let didAttach = attach processId

if didAttach then
attachedProcess <- Some processId

didAttach)

attachOnce
|> Option.iter (fun attach -> client.ServerRequestHandler <- Some(attachDebuggerHandler attach))

let! _capabilities = client.InitializeAsync(cancellationToken)

// Protocol 1.0 reserves attachDebugger but its server never sends that request.
// The launched application is the test host, so attach to its pid before execution.
attachOnce |> Option.iter (fun attach -> attach client.ProcessId |> ignore)

let! _result =
match selection with
| TestSelection.All -> client.RunTestsAsync(cancellationToken)
| TestSelection.Uids uids -> client.RunTestsAsync(uids, cancellationToken)

do! client.ExitAsync(cancellationToken)

return List.ofSeq reported
})

/// Runs the requested tests of every given application. A debugger is attached only where the
/// application asks for one, which it does when the run was started under a debugger. An
/// application that cannot run is reported and the others still run; only a run in which no
/// application could run fails, with the first application's failure.
let runTestsWithDebuggerAsync
(notify: TestRunUpdate -> unit)
(onAttachDebugger: (ProcessId -> DidDebuggerAttach) option)
(requests: RunRequest list)
: Async<RunNode list> =
async {
let logError message = notify (TestRunUpdate.LogMessage(ClientLogLevel.Error, message))

// The platform treats an empty uid collection as "run all". An explicit empty
// selection must therefore never be sent to an application.
let! perApplication =
requests
|> List.filter (fun (_, selection) -> selection <> TestSelection.Uids [])
|> List.map (fun request -> isolatedAsync logError (fst request) (runOnAsync notify onAttachDebugger request))
|> Async.Sequential

let failures =
perApplication
|> Array.choose (function
| Result.Error error -> Some error
| Ok _ -> None)

if failures.Length > 0 && failures.Length = perApplication.Length then
return rethrow failures[0]
else
return perApplication |> Seq.collect (Result.defaultValue []) |> List.ofSeq
}

/// Runs the requested tests of every given application, undebugged.
let runTestsAsync (notify: TestRunUpdate -> unit) (requests: RunRequest list) : Async<RunNode list> =
runTestsWithDebuggerAsync notify None requests

/// Discovers the tests of every given application. An application that cannot be discovered is
/// reported and contributes no tests.
let discoverTestsAsync
(notify: TestDiscoveryUpdate -> unit)
(applications: TestApplication list)
: Async<DiscoveredNode list> =
async {
let logError message = notify (TestDiscoveryUpdate.LogMessage(ClientLogLevel.Error, message))

let! perApplication =
applications
|> List.map (fun application -> isolatedAsync logError application (discoverFromAsync notify application))
|> Async.Sequential

return perApplication |> Seq.collect (Result.defaultValue []) |> List.ofSeq
}
Loading
Loading