Skip to content

Commit 408acca

Browse files
committed
contract baseline updates
1 parent f4fbabd commit 408acca

File tree

8 files changed

+71
-84
lines changed

8 files changed

+71
-84
lines changed

src/Microsoft.DotNet.Interactive.ApiCompatibility.Tests/ApiCompatibilityTests.Document_api_is_not_changed.approved.txt

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,27 @@ Microsoft.DotNet.Interactive.Documents
66
public static System.Threading.Tasks.Task<InteractiveDocument> ReadAsync(System.IO.Stream stream, System.String defaultLanguage, System.Collections.Generic.IReadOnlyCollection<KernelName> kernelNames)
77
public static System.String ToCodeSubmissionContent(System.String newline =
88
)
9-
public static System.Void Write(InteractiveDocument interactiveDocument, System.String newline, System.IO.Stream stream)
10-
public static System.Void Write(InteractiveDocument interactiveDocument, System.String newline, System.IO.TextWriter writer)
11-
public class DataDictionaryConverter : JsonConverter<System.Collections.Generic.IDictionary<System.String,System.Object>>
12-
.ctor()
13-
public System.Collections.Generic.IDictionary<System.String,System.Object> Read(ref System.Text.Json.Utf8JsonReader& reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
9+
public static System.Void Write(InteractiveDocument document, System.IO.Stream stream, System.String newline =
10+
)
11+
public static System.Void Write(InteractiveDocument document, System.IO.TextWriter writer, System.String newline =
12+
)
1413
public class DisplayElement : InteractiveDocumentOutputElement
1514
.ctor(System.Collections.Generic.IDictionary<System.String,System.Object> data)
1615
public System.Collections.Generic.IDictionary<System.String,System.Object> Data { get;}
1716
public class ErrorElement : InteractiveDocumentOutputElement
18-
.ctor(System.String errorName, System.String errorValue, System.String[] stackTrace)
17+
.ctor(System.String errorName, System.String errorValue, System.String[] stackTrace = null)
1918
public System.String ErrorName { get;}
2019
public System.String ErrorValue { get;}
2120
public System.String[] StackTrace { get;}
2221
public class InteractiveDocument
2322
.ctor(System.Collections.Generic.IList<InteractiveDocumentElement> elements)
2423
public System.Collections.Generic.IList<InteractiveDocumentElement> Elements { get;}
2524
public class InteractiveDocumentElement
26-
.ctor(System.String language, System.String contents, InteractiveDocumentOutputElement[] outputs = null)
25+
.ctor(System.String language, System.String contents, System.Collections.Generic.IList<InteractiveDocumentOutputElement> outputs = null)
2726
public System.String Contents { get;}
2827
public System.String Language { get;}
29-
public InteractiveDocumentOutputElement[] Outputs { get;}
28+
public System.Collections.Generic.IList<InteractiveDocumentOutputElement> Outputs { get;}
3029
public abstract class InteractiveDocumentOutputElement
31-
public abstract class JsonConverter<T> : JsonConverter<T>
32-
protected System.Void EnsureStartObject(System.Text.Json.Utf8JsonReader reader, System.Type typeToConvert)
33-
protected System.Void OnWrite(System.Text.Json.Utf8JsonWriter writer, T value, System.Text.Json.JsonSerializerOptions options)
34-
public System.Void Write(System.Text.Json.Utf8JsonWriter writer, T value, System.Text.Json.JsonSerializerOptions options)
3530
public static class JsonElementExtensions
3631
public static System.Nullable<System.Text.Json.JsonElement> GetPropertyFromPath(System.String[] path)
3732
public class KernelName
@@ -41,7 +36,8 @@ Microsoft.DotNet.Interactive.Documents
4136
public System.String Name { get;}
4237
public System.String ToString()
4338
public class TextElement : InteractiveDocumentOutputElement
44-
.ctor(System.String text)
39+
.ctor(System.String text, System.String name = stdout)
40+
public System.String Name { get;}
4541
public System.String Text { get;}
4642
Microsoft.DotNet.Interactive.Documents.Jupyter
4743
public class InputCellMetadata
@@ -54,17 +50,11 @@ Microsoft.DotNet.Interactive.Documents.Jupyter
5450
public static System.Threading.Tasks.Task<Microsoft.DotNet.Interactive.Documents.InteractiveDocument> ReadAsync(System.IO.Stream stream, System.Collections.Generic.IReadOnlyCollection<Microsoft.DotNet.Interactive.Documents.KernelName> kernelNames)
5551
public static System.String ToJupyterNotebookContent(System.String newline =
5652
)
57-
public static System.Void Write(Microsoft.DotNet.Interactive.Documents.InteractiveDocument interactive, System.String newline, System.IO.Stream stream)
58-
public static System.Void Write(Microsoft.DotNet.Interactive.Documents.InteractiveDocument interactive, System.String newline, System.IO.TextWriter writer)
59-
public class NotebookCellOutputConverter : Microsoft.DotNet.Interactive.Documents.JsonConverter<Microsoft.DotNet.Interactive.Documents.InteractiveDocumentOutputElement>
60-
public static System.Text.Json.JsonSerializerOptions InternalOptions { get; set;}
61-
.ctor()
62-
public Microsoft.DotNet.Interactive.Documents.InteractiveDocumentOutputElement Read(ref System.Text.Json.Utf8JsonReader& reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
53+
public static System.Void Write(Microsoft.DotNet.Interactive.Documents.InteractiveDocument document, System.IO.Stream stream, System.String newline =
54+
)
55+
public static System.Void Write(Microsoft.DotNet.Interactive.Documents.InteractiveDocument document, System.IO.TextWriter writer, System.String newline =
56+
)
6357
Microsoft.DotNet.Interactive.Documents.ParserServer
64-
public class ByteArrayConverter : Microsoft.DotNet.Interactive.Documents.JsonConverter<System.Byte[]>
65-
.ctor()
66-
public System.Byte[] Read(ref System.Text.Json.Utf8JsonReader& reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
67-
public System.Void Write(System.Text.Json.Utf8JsonWriter writer, System.Byte[] value, System.Text.Json.JsonSerializerOptions options)
6858
public enum DocumentSerializationType : System.Enum, System.IComparable, System.IConvertible, System.IFormattable
6959
Dib=0
7060
Ipynb=1
@@ -81,15 +71,9 @@ Microsoft.DotNet.Interactive.Documents.ParserServer
8171
.ctor(System.String id, DocumentSerializationType serializationType, System.String defaultLanguage, System.Byte[] rawData)
8272
public System.Byte[] RawData { get;}
8373
public RequestType Type { get;}
84-
public class NotebookParseRequestConverter : Microsoft.DotNet.Interactive.Documents.JsonConverter<NotebookParseOrSerializeRequest>
85-
.ctor()
86-
public NotebookParseOrSerializeRequest Read(ref System.Text.Json.Utf8JsonReader& reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
8774
public class NotebookParseResponse : NotebookParserServerResponse
8875
.ctor(System.String id, Microsoft.DotNet.Interactive.Documents.InteractiveDocument document)
8976
public Microsoft.DotNet.Interactive.Documents.InteractiveDocument Document { get;}
90-
public class NotebookParseResponseConverter : Microsoft.DotNet.Interactive.Documents.JsonConverter<NotebookParserServerResponse>
91-
.ctor()
92-
public NotebookParserServerResponse Read(ref System.Text.Json.Utf8JsonReader& reader, System.Type typeToConvert, System.Text.Json.JsonSerializerOptions options)
9377
public class NotebookParserServer
9478
public static NotebookParserServerResponse HandleRequest(NotebookParseOrSerializeRequest request)
9579
.ctor(System.IO.TextReader input, System.IO.TextWriter output)
@@ -101,7 +85,6 @@ Microsoft.DotNet.Interactive.Documents.ParserServer
10185
public static System.String ToJson()
10286
public abstract class NotebookParserServerResponse
10387
public static NotebookParserServerResponse FromJson(System.String json)
104-
.ctor(System.String id)
10588
public System.String Id { get;}
10689
public class NotebookSerializeRequest : NotebookParseOrSerializeRequest
10790
.ctor(System.String id, DocumentSerializationType serializationType, System.String defaultLanguage, System.String newLine, Microsoft.DotNet.Interactive.Documents.InteractiveDocument document)

src/Microsoft.DotNet.Interactive.Documents.Tests/JupyterFormatTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ public void text_cell_outputs_are_serialized()
11321132
{
11331133
var cells = new List<InteractiveDocumentElement>
11341134
{
1135-
new InteractiveDocumentElement("csharp", "//", new[]
1135+
new("csharp", "//", new[]
11361136
{
11371137
new TextElement("this is text")
11381138
})
@@ -1153,7 +1153,7 @@ public void text_cell_outputs_are_serialized()
11531153
{
11541154
output_type = "stream",
11551155
name = "stdout",
1156-
text = "this is text"
1156+
text = new[] { "this is text" }
11571157
}
11581158
)));
11591159
}

src/Microsoft.DotNet.Interactive.Documents/CodeSubmission.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,16 @@ public static string ToCodeSubmissionContent(this InteractiveDocument interactiv
150150
return content;
151151
}
152152

153-
public static void Write(InteractiveDocument interactiveDocument, Stream stream, string newline = "\n")
153+
public static void Write(InteractiveDocument document, Stream stream, string newline = "\n")
154154
{
155155
using var writer = new StreamWriter(stream, Encoding, 1024, true);
156-
Write(interactiveDocument, writer, newline);
156+
Write(document, writer, newline);
157157
writer.Flush();
158158
}
159159

160-
public static void Write(InteractiveDocument interactiveDocument, TextWriter writer, string newline = "\n")
160+
public static void Write(InteractiveDocument document, TextWriter writer, string newline = "\n")
161161
{
162-
var content = interactiveDocument.ToCodeSubmissionContent(newline);
162+
var content = document.ToCodeSubmissionContent(newline);
163163
writer.Write(content);
164164
}
165165
}

src/Microsoft.DotNet.Interactive.Documents/ErrorElement.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ namespace Microsoft.DotNet.Interactive.Documents
55
{
66
public class ErrorElement : InteractiveDocumentOutputElement
77
{
8-
public ErrorElement(string? errorName, string? errorValue, string[]? stackTrace)
8+
public ErrorElement(string errorName, string errorValue, string[]? stackTrace = null)
99
{
10-
ErrorName = errorName;
11-
ErrorValue = errorValue;
10+
ErrorName = errorName ?? "Error";
11+
ErrorValue = errorValue ?? "";
1212
StackTrace = stackTrace ?? new string[] { };
1313
}
1414

15-
public string? ErrorName { get; }
15+
public string ErrorName { get; }
1616

17-
public string? ErrorValue { get; }
17+
public string ErrorValue { get; }
1818

1919
public string[] StackTrace { get; }
2020
}

src/Microsoft.DotNet.Interactive.Documents/Jupyter/Notebook.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ possibleTargetKernelName is not null &&
9494
cellOutput.GetPropertyFromPath("data").GetRawText(), _serializerOptions)),
9595

9696
"stream" =>
97+
// FIX: (Parse) it looks like this is supposed to be a string[]
9798
new TextElement(
9899
GetTextAsSingleString(cellOutput.GetPropertyFromPath("text"))),
99100

@@ -162,17 +163,17 @@ private static string GetTextAsSingleString(JsonElement? jsonElement)
162163
return string.Join("\n", textLines);
163164
}
164165

165-
public static void Write(InteractiveDocument interactive, Stream stream, string newline = "\n")
166+
public static void Write(InteractiveDocument document, Stream stream, string newline = "\n")
166167
{
167168
using var writer = new StreamWriter(stream, Encoding, 1024, true);
168-
Write(interactive, writer, newline);
169+
Write(document, writer, newline);
169170
writer.Flush();
170171
}
171172

172-
public static string ToJupyterNotebookContent(this InteractiveDocument interactive, string newline = "\n")
173+
public static string ToJupyterNotebookContent(this InteractiveDocument document, string newline = "\n")
173174
{
174175
var cells = new List<object>();
175-
foreach (var element in interactive.Elements)
176+
foreach (var element in document.Elements)
176177
{
177178
switch (element.Language)
178179
{
@@ -205,7 +206,7 @@ public static string ToJupyterNotebookContent(this InteractiveDocument interacti
205206
{
206207
output_type = "stream",
207208
name = "stdout", // n.b., could also be `stderr`, but our representation (and VS Code) don't differentiate the two
208-
text = textOutput.Text,
209+
text = textOutput.Text.SplitIntoLines(),
209210
},
210211
_ => null
211212
}).Where(x => x is not null);
@@ -264,9 +265,9 @@ public static string ToJupyterNotebookContent(this InteractiveDocument interacti
264265
return content;
265266
}
266267

267-
public static void Write(InteractiveDocument interactive, TextWriter writer, string newline = "\n")
268+
public static void Write(InteractiveDocument document, TextWriter writer, string newline = "\n")
268269
{
269-
var content = interactive.ToJupyterNotebookContent(newline);
270+
var content = document.ToJupyterNotebookContent(newline);
270271
writer.Write(content);
271272
}
272273

src/Microsoft.DotNet.Interactive.Documents/TextElement.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ namespace Microsoft.DotNet.Interactive.Documents
55
{
66
public class TextElement : InteractiveDocumentOutputElement
77
{
8-
public string Text { get; }
9-
10-
public TextElement(string text)
8+
public TextElement(string text, string name = "stdout")
119
{
1210
Text = text;
11+
Name = name;
1312
}
13+
14+
public string Name { get; }
15+
16+
public string Text { get; }
1417
}
1518
}

src/dotnet-interactive.Tests/TypeScriptInterfacesContractTests.cs

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,34 @@
88
using Microsoft.DotNet.Interactive.InterfaceGen.App;
99
using Xunit;
1010

11-
namespace Microsoft.DotNet.Interactive.App.Tests
11+
namespace Microsoft.DotNet.Interactive.App.Tests;
12+
13+
public class TypeScriptInterfacesContractTests
1214
{
13-
public class TypeScriptInterfacesContractTests
15+
private string GetTypeScriptContractFullPath(string subPath, [CallerFilePath] string thisDir = null)
1416
{
15-
private string GetTypeScriptContractFullPath(string subPath, [CallerFilePath] string thisDir = null)
16-
{
17-
var sourceRoot = Path.Combine(Path.GetDirectoryName(thisDir), "..", "..");
18-
var fullPath = Path.Combine(sourceRoot, subPath);
19-
return fullPath;
20-
}
21-
22-
private void CheckTypeScriptInterfaceFile(string interfaceFileSubPath)
23-
{
24-
var contractFile = new FileInfo(GetTypeScriptContractFullPath(interfaceFileSubPath));
25-
contractFile.Exists.Should().BeTrue(
26-
$"The Typescript contract file {interfaceFileSubPath} does not exist. Please run the `src/interface-generator` tool with option --out-file {contractFile.FullName}.");
27-
28-
var actual = File.ReadAllText(contractFile.FullName);
29-
var expected = InterfaceGenerator.Generate();
30-
31-
var compareResult = new DefaultStringComparer(true).Compare(actual, expected);
32-
33-
compareResult
34-
.Error
35-
.Should()
36-
.BeNullOrEmpty(
37-
because:
38-
$@"{contractFile.Name} should match the checked-in version.
17+
var sourceRoot = Path.Combine(Path.GetDirectoryName(thisDir), "..", "..");
18+
var fullPath = Path.Combine(sourceRoot, subPath);
19+
return fullPath;
20+
}
21+
22+
private void CheckTypeScriptInterfaceFile(string interfaceFileSubPath)
23+
{
24+
var contractFile = new FileInfo(GetTypeScriptContractFullPath(interfaceFileSubPath));
25+
contractFile.Exists.Should().BeTrue(
26+
$"The Typescript contract file {interfaceFileSubPath} does not exist. Please run the `src/interface-generator` tool with option --out-file {contractFile.FullName}.");
27+
28+
var actual = File.ReadAllText(contractFile.FullName);
29+
var expected = InterfaceGenerator.Generate();
30+
31+
var compareResult = new DefaultStringComparer(true).Compare(actual, expected);
32+
33+
compareResult
34+
.Error
35+
.Should()
36+
.BeNullOrEmpty(
37+
because:
38+
$@"{contractFile.Name} should match the checked-in version.
3939
4040
If the contract change is deliberate, then the TypeScript contracts file '{interfaceFileSubPath}' needs to be regenerated.
4141
@@ -44,12 +44,11 @@ private void CheckTypeScriptInterfaceFile(string interfaceFileSubPath)
4444
dotnet run --project src/interface-generator -- --out-file {contractFile.FullName}
4545
4646
");
47-
}
47+
}
4848

49-
[Fact]
50-
public void vscode_generated_TypeScript_interfaces_file_has_known_shape()
51-
{
52-
CheckTypeScriptInterfaceFile("src/microsoft-dotnet-interactive/src/contracts.ts");
53-
}
49+
[Fact]
50+
public void vscode_generated_TypeScript_interfaces_file_has_known_shape()
51+
{
52+
CheckTypeScriptInterfaceFile("src/microsoft-dotnet-interactive/src/contracts.ts");
5453
}
55-
}
54+
}

src/microsoft-dotnet-interactive/src/contracts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export interface InteractiveDocumentOutputElement {
149149
}
150150

151151
export interface TextElement extends InteractiveDocumentOutputElement {
152+
name: string;
152153
text: string;
153154
}
154155

0 commit comments

Comments
 (0)