Skip to content
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
749df2d
Harden JSON-RPC server mode protocol
Evangelink Aug 26, 2026
e15ead5
Merge origin/main into protocol hardening
Evangelink Aug 27, 2026
8fdd33b
Address JSON-RPC hardening review
Evangelink Aug 27, 2026
c31b67c
Clarify legacy protocol fallback
Evangelink Aug 27, 2026
351c4dd
Preserve JSON-RPC string request IDs
Evangelink Aug 27, 2026
d6258ae
Restore serializer source BOMs
Evangelink Aug 27, 2026
40fa635
Close remaining JSON-RPC parity gaps
Evangelink Aug 27, 2026
d4697d6
Align initialize process ID documentation
Evangelink Aug 27, 2026
c4d5e07
Harden queued request validation
Evangelink Aug 27, 2026
2816344
Reject null test-node identity fields
Evangelink Aug 27, 2026
dae2cb2
Align test-node identity validation
Evangelink Aug 27, 2026
e4ecd46
Separate JSON-RPC ID correlation types
Evangelink Aug 27, 2026
1a08b8d
Restore strict scalar null validation
Evangelink Aug 27, 2026
cb9c843
Define complete test-node locations
Evangelink Aug 27, 2026
14f50f5
Align protocol location line bounds
Evangelink Aug 27, 2026
dc74cfa
Close remaining protocol contract gaps
Evangelink Aug 27, 2026
94c2ff5
Prevent canceled queued request setup
Evangelink Aug 27, 2026
c6871a4
Separate response IDs and initialization release
Evangelink Aug 27, 2026
8dc90f9
Accept integral JSON-RPC number IDs
Evangelink Aug 27, 2026
c543bed
Align attachment and log contracts
Evangelink Aug 27, 2026
be01ba9
Process cancellation notifications in order
Evangelink Aug 27, 2026
2790b14
Reject invalid passive handshake frames
Evangelink Aug 27, 2026
26edfa5
Preserve exact JSON-RPC numeric IDs
Evangelink Aug 27, 2026
4fb6c0a
Harden cancellation and exact RPC IDs
Evangelink Aug 27, 2026
1aeba4f
Handle immediate initialize ID reuse
Evangelink Aug 27, 2026
906495b
Reject explicit null JSON-RPC IDs
Evangelink Aug 27, 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
5 changes: 5 additions & 0 deletions docs/RFCs/019-Code-Coverage-Messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,11 @@ public sealed class CoverageReportReference
}
```

`ITestCoverageCapabilities.SupportsTestCoverageMessages` describes the platform's in-process message
and consumer contract. It is distinct from the JSON-RPC server-mode capability with the same suffix:
`capabilities.testing.supportsTestCoverageMessages` remains `false` until those first-class messages
are forwarded over the server-mode wire.

None of these public properties use `init`, per platform guidelines.

## How consumers use it — two tiers
Expand Down
134 changes: 84 additions & 50 deletions docs/mstest-runner-protocol/001-protocol-intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ This document describes the JSON-RPC server-mode protocol. The separate, binary
[`dotnet test` named-pipe protocol](./004-protocol-dotnet-test-pipe.md) (`--server dotnettestcli`)
is specified in its own document.

The machine-readable JSON Schema for the base protocol is
[`server-mode-1.0.schema.json`](./server-mode-1.0.schema.json).

## API overview

Here's the current list of APIs that supported by the client.
Expand All @@ -24,8 +27,6 @@ Here's the current list of APIs that supported by the client.
- [testing/testUpdates/tests](#discovery-of-tests) - Notifies client about test updates (test cases and test results)
- [testing/testUpdates/attachments](#execution-of-tests) - Notifies client about additional attachments (trx/coverage)
- Client notifications updates
- [client/launchDebugger](#launch-debugger) - Requests a client to launch a process with debugger attached to it
- [client/attachDebugger](#attach-debugger) - Requests a client to attach a debugger to a process by pid
- [client/log](#logging-of-messages) - Notifies a client to logs a message to the output window
- Miscellaneous requests
- [telemetry/update](#telemetry) - Sends telemetry data to the client
Expand Down Expand Up @@ -148,6 +149,9 @@ namespace ErrorCodes {

export const testingPlatformErrorRangeStart = -31700;

// The initialize request did not contain a protocol version supported by the server.
export const ProtocolVersionNotSupported: integer = -31699;

// If a top level assertion has failed when running tests.
// TODO: Decide if we can forward all assertion failures and attach them to test nodes.
export const AssertionFailed: integer = -31001;
Expand Down Expand Up @@ -181,6 +185,15 @@ what the client supports and limit functionality based on unsupported features.
> Since the capabilities are fetched by sending an RPC request to a started executable, these can only be queried by the client after
> the project was successfully built.

The `initialize` request MUST be the first request sent on a connection:

- Before `initialize` is received, requests are rejected with `ServerNotInitialized` (`-32002`) and
notifications other than `exit` and `$/cancelRequest` are ignored.
- While initialization is in progress, non-initialize requests wait for it to complete. A second
`initialize` request is rejected with `InvalidRequest` (`-32600`).
- After initialization succeeds, normal requests are processed and another `initialize` request is rejected.
If initialization fails, the client may correct the request and try again.

### Determine capabilities during test runner initialization

> [!NOTE]
Expand All @@ -194,33 +207,33 @@ Request:

```typescript
interface InitializeParams {
// The process Id of the parent process that started the server. Is null if
// the process has not been started by another process. If the parent
// process is not alive then the server should exit (see exit notification)
// its process.
// The process ID of the client process that started the server.
// Protocol 1.0 requires this value to be an integer.
processId: PID,

clientInfo: {
// The name of the client.
name: string,

// This is the version of the client's protocol and should follow
// semver.
// The client and the server should be able to communicate
// only if the major version stays the same.
// The client can attempt to fallback on the older protocol
// version if it has such a fallback and send another INITIALIZE
// request.
// Client compatibility version. Existing server integrations use this
// to gate client-specific behavior, so it remains separate from the
// independently negotiated wire-protocol version below.
version: string,
},

// OPTIONAL for compatibility with clients predating protocol negotiation.
// The server selects its most preferred mutually supported version.
// If omitted, null, or empty, the server uses the legacy base protocol (1.0.0).
protocolVersions?: string[] | null,

capabilities: {
// Note: Since the initialize message is compatible with the LSP protocol,
// we should make sure that the capability paths for the testing features are unique.
// As such, we put all of them under a single testing namespace.
// This reduces collisions with other LSP capabilities.
testing: {
// If true, the client supports the client/attachDebugger and client/launchDebugger requests.
// Reserved for future debugger callbacks. Protocol 1.0 accepts this field
// for compatibility but does not send debugger requests.
debuggerProvider: boolean,

// If true, the client is stateful: it persists an addressable set of test nodes for the
Expand All @@ -247,9 +260,13 @@ interface InitializeResponse {
// The name of the server.
name: string,

// The server's protocol version.
// Product/build version of the server. This is not the wire-protocol version.
version: string
},

// Independently negotiated wire-protocol version.
protocolVersion?: string,

capabilities: {
testing: {
// If true, the server supports test discovery.
Expand All @@ -276,8 +293,10 @@ interface InitializeResponse {

// If true, the server understands the first-class test-coverage message contract.
// This advertises protocol support only; it does not imply that an enabled extension
// will produce coverage during the run. The current server always advertises true.
supportsTestCoverageMessages: true;
// will produce coverage during the run.
// This MUST only be true when first-class coverage messages are actually
// forwarded over this JSON-RPC connection.
supportsTestCoverageMessages: boolean;
},
}
}
Expand All @@ -288,6 +307,11 @@ interface InitializeResponse {
Any behavior changes should be announced via capabilities, where the client/server
should announce what kinds of additional RPC requests and responses they can handle.

The independently negotiated `protocolVersion` versions the base wire contract. It is intentionally
separate from `clientInfo.version` and `serverInfo.version`, which identify the client compatibility
surface and server product build. Protocol `1.0.0` is the legacy base. An unsupported set is rejected
with `ProtocolVersionNotSupported` (`-31699`).

For instance, let's say the server would like to be make the file/line location lazy.
The client should announce that is supports lazy locations.
If the capability is present the server can then send lazy location data.
Expand All @@ -298,6 +322,14 @@ lazy locations and send the full location.
> The TestNode format specified in the initial release of the protocol should be supported by all
> clients and servers. As such, it is not expressed via capabilities.

## Additional passive connections

A server advertising `multipleConnectionProvider` can use additional passive connections to push
artifacts from child or watcher processes. The endpoint is configured by the client out of band when
the process is launched; protocol 1.0 does not define a `testing.callbackProvider` initialize capability.
This is used, for example, to preserve hang-dump or crash-dump attachments if the primary test-host
process terminates.

## Discovery and run requests

The two most basic features that the a test runner should provide is the capability to discover and run tests.
Expand Down Expand Up @@ -467,7 +499,7 @@ type ExecutionState =
| 'failed'
| 'timed-out'
| 'error'
| "cancelled"
| "canceled"

interface Trait {
key: string;
Expand Down Expand Up @@ -511,7 +543,7 @@ Notifications:
// These should be processed in order and also should be complete,
// i.e. a server will send an update for the test, if it already sent updates
// for all of the parent nodes.
changes: TestUpdateChange[]
changes: TestUpdateChange[] | null

// Run id for which the notification is sent. It should match the id sent during the discovery request.
runId: GUID
Expand All @@ -535,7 +567,11 @@ Notifications:
processing all node update notifications.
- Implementation detail: if a server sends callback notifications and returns a JSON-RPC response, vs-streamjsonrpc may resolve them in any order. As such, awaiting of the response is insufficient to guarantee that all updates were processed by the callback handler.
- method: `testing/testUpdates/tests`
- params: `TestUpdateNotificationParams` where `params.children == null`.
- params: `TestUpdateNotificationParams` where `params.changes == null`.
- The server sends this terminal notification before the final success or error response for requests
whose discovery/run params were successfully deserialized, including requests canceled while queued
during initialization. Requests rejected by lifecycle checks and requests whose params could not be
deserialized receive only the error response.

Response:

Expand Down Expand Up @@ -583,22 +619,17 @@ Notifications:
As soon as the client processes this notification it is guaranteed to be done
processing all node update notifications.
- method: `testing/testUpdates/tests`
- params: `TestUpdateNotificationParams` where `params.testCases == null`.
- params: `TestUpdateNotificationParams` where `params.changes == null`.
- Attachment updates
- method: `testing/testUpdates/attachments`
- params: `AttachmentUpdatesParams` defined as follows:

```typescript
interface AttachmentUpdatesParams {
attachments?: Attachment[],
runId: GUID
attachments: Attachment[],
}
```

- Attachment updates completes
method: `testing/testUpdates/attachments`
params: `AttachmentUpdatesParams` where `params.attachments == null`

Response:

- result: `RunTestsResponse` defined as follows:
Expand All @@ -609,33 +640,33 @@ interface RunTestsResponse {
// rather than to a single test result.
// Note: If multiple data collectors are generating attachments, they should send separate
// attachment events.
attachments?: Attachment[]
attachments: Attachment[]
}

interface Attachment {
// OPTIONAL: If the attachment is based on a file (and the client can show a hyperlink to it)
// the file's location should be specified by this property.
// If the attachment is based on a file (and the client can show a hyperlink to it),
// the file's location should be specified; otherwise this value is null.
// Example: "uri": "file://some/coverage.trx"
uri: string,
uri: string | null,

// The name of the extension that generated the attachment.
// Note: For the time being the client does not special case attachments
// based on their producer.
// Example: "producer": "TrxReportGeneratorProcessLifetimeHandler"
producer: string,
producer: string | null,

// OPTIONAL: The file extension can be used to resolve the attachment type
// if that isn't ambiguous.
// The file extension can be used to resolve the attachment type if that isn't ambiguous;
// otherwise this value is null.
// Note: For the time being the client does not special case attachments
// based on their type.
// Example: "type": "file"
type: string,
type: string | null,

// How the attachment can be displayed as by the client.
// Example: "display-name": "Code Coverage"
displayName: string;
'display-name': string | null;

description: string;
description: string | null;
}
```

Expand Down Expand Up @@ -696,8 +727,11 @@ Notification:
- params: `CancelParams` defined as follows:

```typescript
type NumericStringId = `${bigint}`;

interface CancelParams {
id: number;
// String IDs use the canonical decimal integer representation and signed 32-bit range.
id: number | NumericStringId;
}
```

Expand All @@ -706,6 +740,8 @@ interface CancelParams {
### Launch debugger

> Message direction: Server -> Client
> [!NOTE]
> Reserved protocol shape. Microsoft.Testing.Platform 1.0 does not currently send this request.

Requests a client to attach a debugger to the spawned child process.

Expand Down Expand Up @@ -737,6 +773,8 @@ interface LaunchDebuggerParams {
### Attach debugger

> Message direction: Server -> Client
> [!NOTE]
> Reserved protocol shape. Microsoft.Testing.Platform 1.0 does not currently send this request.

Requests a client to attach a debugger to the spawned child process.

Expand Down Expand Up @@ -781,17 +819,13 @@ interface LogMessageParams {
level: TestingPlatformLogLevel;
message: string;
}
```

```typescript
enum TestingPlatformLogLevel
{
Trace = 0,
Debug = 1,
Information = 2,
Warning = 3,
Error = 4,
Critical = 5,
None = 6,
}
type TestingPlatformLogLevel =
'Trace'
| 'Debug'
| 'Information'
| 'Warning'
| 'Error'
| 'Critical'
| 'None';
```
Loading
Loading