From deb75c8dd12275509948ef328aa04163afbeb34e Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Wed, 25 Nov 2026 16:38:31 +0100 Subject: [PATCH] Added a notice naming the page when a source opens without it (#1233) --- .../Assistants/I18N/allTexts.lua | 15 ++ .../Components/FileActions.razor | 2 +- .../Components/FileActions.razor.cs | 24 ++- .../Components/SourcesList.razor | 4 +- .../Components/SourcesList.razor.cs | 9 + .../plugin.lua | 15 ++ .../plugin.lua | 15 ++ .../Tools/Rust/DocumentPageOutcome.cs | 32 ++++ .../Tools/Rust/OpenDocumentResponse.cs | 10 +- .../Rust/RuntimeInfoResponseExtensions.cs | 20 +++ .../Tools/Services/RustService.FileSystem.cs | 22 +-- .../Tools/SourceDocumentLocationExtensions.cs | 37 +++- .../wwwroot/changelog/v26.11.2.md | 1 + app/Tests/Components/FileActionsTests.cs | 17 ++ app/Tests/Tools/OpenDocumentResponseTests.cs | 44 +++++ app/Tests/Tools/RuntimeInfoResponseTests.cs | 14 ++ .../SourceDocumentLocationExtensionsTests.cs | 58 ++++++ runtime/src/file_actions.rs | 165 ++++++++++++++---- 18 files changed, 447 insertions(+), 57 deletions(-) create mode 100644 app/MindWork AI Studio/Tools/Rust/DocumentPageOutcome.cs create mode 100644 app/MindWork AI Studio/Tools/Rust/RuntimeInfoResponseExtensions.cs create mode 100644 app/Tests/Tools/OpenDocumentResponseTests.cs create mode 100644 app/Tests/Tools/SourceDocumentLocationExtensionsTests.cs diff --git a/app/MindWork AI Studio/Assistants/I18N/allTexts.lua b/app/MindWork AI Studio/Assistants/I18N/allTexts.lua index 8e5718f61..4219a65a5 100644 --- a/app/MindWork AI Studio/Assistants/I18N/allTexts.lua +++ b/app/MindWork AI Studio/Assistants/I18N/allTexts.lua @@ -9799,6 +9799,9 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::FILEACTIONS::T4218155268"] = "Open the fi -- Open the file in the program your system uses for it UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::FILEACTIONS::T4218155268::INFORMAL"] = "Open the file in the program your system uses for it" +-- Open the file. As a Flatpak, AI Studio cannot open it at page {0}, where the passage is. +UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::FILEACTIONS::T755778778"] = "Open the file. As a Flatpak, AI Studio cannot open it at page {0}, where the passage is." + -- Exclusion help and examples UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::FILEEXCLUSIONEDITOR::T1309128010"] = "Exclusion help and examples" @@ -24439,15 +24442,27 @@ UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCECODELANGUAGES::T1041509726"] = "Text" -- Could not open the file location. UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T1118835751"] = "Could not open the file location." +-- As a Flatpak, AI Studio cannot open the document at its page: the sandbox of the Flatpak lets no page through to the program which shows the document. The passage is on page {0}. +UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T1426315148"] = "As a Flatpak, AI Studio cannot open the document at its page: the sandbox of the Flatpak lets no page through to the program which shows the document. The passage is on page {0}." + -- Could not open the file location: {0} UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T1455637941"] = "Could not open the file location: {0}" +-- AI Studio could not open the document at its page: the program which shows the document could not be started with the page, so it opened without it. The passage is on page {0}. +UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T3168067729"] = "AI Studio could not open the document at its page: the program which shows the document could not be started with the page, so it opened without it. The passage is on page {0}." + -- Unknown error UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T3461425987"] = "Unknown error" -- Could not open the document. UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T3570758363"] = "Could not open the document." +-- AI Studio cannot open the document at its page: the program your system shows it with does not allow choosing a page. The passage is on page {0}. +UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T932584602"] = "AI Studio cannot open the document at its page: the program your system shows it with does not allow choosing a page. The passage is on page {0}." + +-- AI Studio cannot open the document at its page: the program your system shows it with does not allow choosing a page. The passage is on page {0}. +UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T932584602::INFORMAL"] = "AI Studio cannot open the document at its page: the program your system shows it with does not allow choosing a page. The passage is on page {0}." + -- Could not open the document: {0} UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T945417289"] = "Could not open the document: {0}" diff --git a/app/MindWork AI Studio/Components/FileActions.razor b/app/MindWork AI Studio/Components/FileActions.razor index 1cb5ee7da..ce974db3c 100644 --- a/app/MindWork AI Studio/Components/FileActions.razor +++ b/app/MindWork AI Studio/Components/FileActions.razor @@ -53,7 +53,7 @@ @if (this.ShowOpen) { - + } diff --git a/app/MindWork AI Studio/Components/FileActions.razor.cs b/app/MindWork AI Studio/Components/FileActions.razor.cs index 641becba9..d60383c85 100644 --- a/app/MindWork AI Studio/Components/FileActions.razor.cs +++ b/app/MindWork AI Studio/Components/FileActions.razor.cs @@ -1,4 +1,5 @@ using AIStudio.Tools.PluginSystem; +using AIStudio.Tools.Rust; using AIStudio.Tools.Services; using Microsoft.AspNetCore.Components; @@ -82,6 +83,9 @@ public partial class FileActions : MSGComponentBase [Inject] private RustService RustService { get; init; } = null!; + [Inject] + private RuntimeInfoResponse RuntimeInfo { get; init; } + private FileActionsKind kind; /// @@ -94,14 +98,28 @@ public partial class FileActions : MSGComponentBase /// private bool isMissing; + /// + /// Whether a page can reach the program which opens a file, see RuntimeInfoResponseExtensions. + /// + private bool CanOpenAtPage => this.RuntimeInfo.CanOpenDocumentsAtPage; + /// /// The tooltip of opening a file, at its page where there is one. /// + /// + /// Inside a Flatpak, no page reaches the program, so the tooltip promises none and says why. Elsewhere, + /// whether the page arrives depends on the program, and the user hears afterwards when it did not, see + /// SourceDocumentLocationExtensions.GetPageNotice. + /// /// The page the file opens at, or null when it opens at its beginning. + /// Whether a page can reach the program at all; false inside a Flatpak. /// The tooltip. - internal static string GetOpenTooltip(int? pageNumber) => pageNumber is { } page - ? string.Format(TB("Open the file at page {0}"), page) - : TA("Open the file in the program your system uses for it"); + internal static string GetOpenTooltip(int? pageNumber, bool canOpenAtPage) => pageNumber switch + { + { } page when canOpenAtPage => string.Format(TB("Open the file at page {0}"), page), + { } page => string.Format(TB("Open the file. As a Flatpak, AI Studio cannot open it at page {0}, where the passage is."), page), + _ => TA("Open the file in the program your system uses for it"), + }; #region Overrides of ComponentBase diff --git a/app/MindWork AI Studio/Components/SourcesList.razor b/app/MindWork AI Studio/Components/SourcesList.razor index 809a016bf..90f0e66de 100644 --- a/app/MindWork AI Studio/Components/SourcesList.razor +++ b/app/MindWork AI Studio/Components/SourcesList.razor @@ -41,7 +41,7 @@ } - + @pageRange @@ -55,7 +55,7 @@ { @* Inline rather than the usual inline block: a long title, e.g., one naming many parts, then wraps like text right after its number instead of moving below it. *@ - + @entry.Title diff --git a/app/MindWork AI Studio/Components/SourcesList.razor.cs b/app/MindWork AI Studio/Components/SourcesList.razor.cs index 29e7112f1..c566fa648 100644 --- a/app/MindWork AI Studio/Components/SourcesList.razor.cs +++ b/app/MindWork AI Studio/Components/SourcesList.razor.cs @@ -1,5 +1,6 @@ using AIStudio.Dialogs; using AIStudio.Tools.RAG; +using AIStudio.Tools.Rust; using AIStudio.Tools.Services; using Microsoft.AspNetCore.Components; @@ -39,6 +40,9 @@ public partial class SourcesList : MSGComponentBase [Inject] private RustService RustService { get; init; } = null!; + [Inject] + private RuntimeInfoResponse RuntimeInfo { get; init; } + [Inject] private IDialogService DialogService { get; init; } = null!; @@ -112,6 +116,11 @@ public partial class SourcesList : MSGComponentBase private async Task OpenDocument(SourceDocumentLocation document) => await document.OpenAsync(this.RustService); + /// + /// Whether a page can reach the program which opens a document, see RuntimeInfoResponseExtensions. + /// + private bool CanOpenAtPage => this.RuntimeInfo.CanOpenDocumentsAtPage; + /// /// The files of sources which are no longer at their place, by their paths, as FileActions found out. /// diff --git a/app/MindWork AI Studio/Plugins/languages/de-de-43065dbc-78d0-45b7-92be-f14c2926e2dc/plugin.lua b/app/MindWork AI Studio/Plugins/languages/de-de-43065dbc-78d0-45b7-92be-f14c2926e2dc/plugin.lua index 4880e0adf..f71593cbc 100644 --- a/app/MindWork AI Studio/Plugins/languages/de-de-43065dbc-78d0-45b7-92be-f14c2926e2dc/plugin.lua +++ b/app/MindWork AI Studio/Plugins/languages/de-de-43065dbc-78d0-45b7-92be-f14c2926e2dc/plugin.lua @@ -9801,6 +9801,9 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::FILEACTIONS::T4218155268"] = "Datei in de -- Open the file in the program your system uses for it UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::FILEACTIONS::T4218155268::INFORMAL"] = "Datei in dem Programm öffnen, das dein System dafür verwendet" +-- Open the file. As a Flatpak, AI Studio cannot open it at page {0}, where the passage is. +UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::FILEACTIONS::T755778778"] = "Datei öffnen. Als Flatpak kann AI Studio sie nicht auf Seite {0} öffnen, wo die Textstelle steht." + -- Exclusion help and examples UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::FILEEXCLUSIONEDITOR::T1309128010"] = "Hilfe und Beispiele zu Ausschlussregeln" @@ -24441,15 +24444,27 @@ UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCECODELANGUAGES::T1041509726"] = "Text" -- Could not open the file location. UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T1118835751"] = "Der Speicherort der Datei konnte nicht geöffnet werden." +-- As a Flatpak, AI Studio cannot open the document at its page: the sandbox of the Flatpak lets no page through to the program which shows the document. The passage is on page {0}. +UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T1426315148"] = "Als Flatpak kann AI Studio das Dokument nicht auf der richtigen Seite öffnen: Die Sandbox des Flatpaks lässt keine Seitenzahl zu dem Programm durch, das das Dokument anzeigt. Die Textstelle steht auf Seite {0}." + -- Could not open the file location: {0} UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T1455637941"] = "Der Speicherort der Datei konnte nicht geöffnet werden: {0}" +-- AI Studio could not open the document at its page: the program which shows the document could not be started with the page, so it opened without it. The passage is on page {0}. +UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T3168067729"] = "AI Studio konnte das Dokument nicht auf der richtigen Seite öffnen: Das Programm, das das Dokument anzeigt, ließ sich nicht mit der Seitenzahl starten und hat es deshalb ohne sie geöffnet. Die Textstelle steht auf Seite {0}." + -- Unknown error UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T3461425987"] = "Unbekannter Fehler" -- Could not open the document. UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T3570758363"] = "Das Dokument konnte nicht geöffnet werden." +-- AI Studio cannot open the document at its page: the program your system shows it with does not allow choosing a page. The passage is on page {0}. +UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T932584602"] = "AI Studio kann das Dokument nicht auf der richtigen Seite öffnen: Das Programm, mit dem Ihr System es anzeigt, erlaubt keine Wahl der Seite. Die Textstelle steht auf Seite {0}." + +-- AI Studio cannot open the document at its page: the program your system shows it with does not allow choosing a page. The passage is on page {0}. +UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T932584602::INFORMAL"] = "AI Studio kann das Dokument nicht auf der richtigen Seite öffnen: Das Programm, mit dem dein System es anzeigt, erlaubt keine Wahl der Seite. Die Textstelle steht auf Seite {0}." + -- Could not open the document: {0} UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T945417289"] = "Das Dokument konnte nicht geöffnet werden: {0}" diff --git a/app/MindWork AI Studio/Plugins/languages/en-us-97dfb1ba-50c4-4440-8dfa-6575daf543c8/plugin.lua b/app/MindWork AI Studio/Plugins/languages/en-us-97dfb1ba-50c4-4440-8dfa-6575daf543c8/plugin.lua index 2b03601f7..a3e5c8712 100644 --- a/app/MindWork AI Studio/Plugins/languages/en-us-97dfb1ba-50c4-4440-8dfa-6575daf543c8/plugin.lua +++ b/app/MindWork AI Studio/Plugins/languages/en-us-97dfb1ba-50c4-4440-8dfa-6575daf543c8/plugin.lua @@ -9801,6 +9801,9 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::FILEACTIONS::T4218155268"] = "Open the fi -- Open the file in the program your system uses for it UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::FILEACTIONS::T4218155268::INFORMAL"] = "Open the file in the program your system uses for it" +-- Open the file. As a Flatpak, AI Studio cannot open it at page {0}, where the passage is. +UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::FILEACTIONS::T755778778"] = "Open the file. As a Flatpak, AI Studio cannot open it at page {0}, where the passage is." + -- Exclusion help and examples UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::FILEEXCLUSIONEDITOR::T1309128010"] = "Exclusion help and examples" @@ -24441,15 +24444,27 @@ UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCECODELANGUAGES::T1041509726"] = "Text" -- Could not open the file location. UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T1118835751"] = "Could not open the file location." +-- As a Flatpak, AI Studio cannot open the document at its page: the sandbox of the Flatpak lets no page through to the program which shows the document. The passage is on page {0}. +UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T1426315148"] = "As a Flatpak, AI Studio cannot open the document at its page: the sandbox of the Flatpak lets no page through to the program which shows the document. The passage is on page {0}." + -- Could not open the file location: {0} UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T1455637941"] = "Could not open the file location: {0}" +-- AI Studio could not open the document at its page: the program which shows the document could not be started with the page, so it opened without it. The passage is on page {0}. +UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T3168067729"] = "AI Studio could not open the document at its page: the program which shows the document could not be started with the page, so it opened without it. The passage is on page {0}." + -- Unknown error UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T3461425987"] = "Unknown error" -- Could not open the document. UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T3570758363"] = "Could not open the document." +-- AI Studio cannot open the document at its page: the program your system shows it with does not allow choosing a page. The passage is on page {0}. +UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T932584602"] = "AI Studio cannot open the document at its page: the program your system shows it with does not allow choosing a page. The passage is on page {0}." + +-- AI Studio cannot open the document at its page: the program your system shows it with does not allow choosing a page. The passage is on page {0}. +UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T932584602::INFORMAL"] = "AI Studio cannot open the document at its page: the program your system shows it with does not allow choosing a page. The passage is on page {0}." + -- Could not open the document: {0} UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEDOCUMENTLOCATIONEXTENSIONS::T945417289"] = "Could not open the document: {0}" diff --git a/app/MindWork AI Studio/Tools/Rust/DocumentPageOutcome.cs b/app/MindWork AI Studio/Tools/Rust/DocumentPageOutcome.cs new file mode 100644 index 000000000..994c04b24 --- /dev/null +++ b/app/MindWork AI Studio/Tools/Rust/DocumentPageOutcome.cs @@ -0,0 +1,32 @@ +namespace AIStudio.Tools.Rust; + +/// +/// What became of the page a document was to be shown at, as the runtime reports it. +/// +/// +/// The runtime names these values in PageOutcome in runtime/src/file_actions.rs. The app tells the user +/// from them why a document opened without its page, so that they know AI Studio could not do otherwise. +/// +public enum DocumentPageOutcome +{ + /// A value of a newer runtime which the app does not know. + UNKNOWN, + + /// The document was handed to its program together with the page. + APPLIED, + + /// No page was asked for. + NOT_REQUESTED, + + /// AI Studio runs as a Flatpak, whose sandbox lets no page through to the program. + SANDBOXED, + + /// The program which shows the document cannot be told a page, or the document is no PDF. + PROGRAM_TAKES_NO_PAGE, + + /// The program takes a page, but it could not be started with one. + PROGRAM_FAILED, + + /// The document did not open at all. + DOCUMENT_NOT_OPENED +} \ No newline at end of file diff --git a/app/MindWork AI Studio/Tools/Rust/OpenDocumentResponse.cs b/app/MindWork AI Studio/Tools/Rust/OpenDocumentResponse.cs index 495dda92d..dc7417163 100644 --- a/app/MindWork AI Studio/Tools/Rust/OpenDocumentResponse.cs +++ b/app/MindWork AI Studio/Tools/Rust/OpenDocumentResponse.cs @@ -4,11 +4,9 @@ namespace AIStudio.Tools.Rust; /// Says how opening a document went. /// /// Whether the document was opened at all. -/// -/// Whether the document was handed to its program together with the page. False means it opens on -/// its first page: no page was asked for, the system uses a program which cannot be told one, or -/// starting that program failed. None of these is an error, so this belongs in the log rather than -/// in front of the user, who is told the page by the source itself. +/// +/// What became of the page the document was to be shown at. A page which did not arrive is no error, +/// since the document opens either way, but the user hears why, see SourceDocumentLocationExtensions. /// /// Why the document could not be opened, or an empty text when it was. -public readonly record struct OpenDocumentResponse(bool Success, bool PageApplied, string Issue); \ No newline at end of file +public readonly record struct OpenDocumentResponse(bool Success, DocumentPageOutcome PageOutcome, string Issue); \ No newline at end of file diff --git a/app/MindWork AI Studio/Tools/Rust/RuntimeInfoResponseExtensions.cs b/app/MindWork AI Studio/Tools/Rust/RuntimeInfoResponseExtensions.cs new file mode 100644 index 000000000..ec4ce096f --- /dev/null +++ b/app/MindWork AI Studio/Tools/Rust/RuntimeInfoResponseExtensions.cs @@ -0,0 +1,20 @@ +namespace AIStudio.Tools.Rust; + +public static class RuntimeInfoResponseExtensions +{ + /// What the runtime tells about itself. + extension(RuntimeInfoResponse runtimeInfo) + { + /// + /// Whether a document can be opened at a page at all. + /// + /// + /// Never inside a Flatpak: its sandbox lets AI Studio start no program itself, and the desktop + /// portal, which opens the document instead, knows no pages, see PageOutcome in + /// runtime/src/file_actions.rs. Everywhere else, whether the page arrives depends on the + /// program, which the runtime learns only while it opens the document. + /// + /// False inside a Flatpak. + public bool CanOpenDocumentsAtPage => runtimeInfo.LinuxPackageType is not LinuxPackageType.FLATPAK; + } +} \ No newline at end of file diff --git a/app/MindWork AI Studio/Tools/Services/RustService.FileSystem.cs b/app/MindWork AI Studio/Tools/Services/RustService.FileSystem.cs index 9fe4ed89d..236ccbafb 100644 --- a/app/MindWork AI Studio/Tools/Services/RustService.FileSystem.cs +++ b/app/MindWork AI Studio/Tools/Services/RustService.FileSystem.cs @@ -177,11 +177,11 @@ public sealed partial class RustService /// /// /// The page is best effort and never decides whether this succeeded. Which programs can be - /// told a page is the runtime's business, and it says afterwards whether it managed to. + /// told a page is the runtime's business, and it says afterwards what became of the page. /// /// The document to open. /// The page to show, counted from one, or null when there is none. - /// Whether the document was opened, whether the page was applied, and what went wrong. + /// Whether the document was opened, what became of the page, and what went wrong. public async Task TryOpenDocumentInSystemViewer(string path, int? pageNumber) { HttpResponseMessage result; @@ -192,12 +192,12 @@ public sealed partial class RustService catch (HttpRequestException e) { this.logger!.LogWarning(e, "Failed to reach the Rust runtime document endpoint."); - return new OpenDocumentResponse(false, false, TB("The runtime document endpoint is not available.")); + return new OpenDocumentResponse(false, DocumentPageOutcome.DOCUMENT_NOT_OPENED, TB("The runtime document endpoint is not available.")); } catch (TaskCanceledException e) { this.logger!.LogWarning(e, "Timed out while reaching the Rust runtime document endpoint."); - return new OpenDocumentResponse(false, false, TB("The runtime document endpoint is not available.")); + return new OpenDocumentResponse(false, DocumentPageOutcome.DOCUMENT_NOT_OPENED, TB("The runtime document endpoint is not available.")); } try @@ -205,28 +205,24 @@ public sealed partial class RustService if (!result.IsSuccessStatusCode) { this.logger!.LogWarning("Failed to open a document through the Rust runtime: '{StatusCode}'", result.StatusCode); - return new OpenDocumentResponse(false, false, string.Format(TB("The runtime document endpoint returned '{0}'."), result.StatusCode)); + return new OpenDocumentResponse(false, DocumentPageOutcome.DOCUMENT_NOT_OPENED, string.Format(TB("The runtime document endpoint returned '{0}'."), result.StatusCode)); } var response = await result.Content.ReadFromJsonAsync(JSON_OPTIONS); if (response.Success) { - // - // A page which was asked for but not applied is noted here and nowhere else: the - // document is open, and the source the user clicked names the page anyway. - // - if (pageNumber is > 0 && !response.PageApplied) - this.logger!.LogInformation("Opened a document without the requested page {PageNumber}, because the system uses a program which cannot be told one.", pageNumber); + if (pageNumber is > 0 && response.PageOutcome is not DocumentPageOutcome.APPLIED) + this.logger!.LogInformation("Opened a document without the requested page {PageNumber}: {PageOutcome}.", pageNumber, response.PageOutcome); return response; } - return new OpenDocumentResponse(false, false, string.IsNullOrWhiteSpace(response.Issue) ? TB("The runtime document endpoint failed without details.") : response.Issue); + return new OpenDocumentResponse(false, DocumentPageOutcome.DOCUMENT_NOT_OPENED, string.IsNullOrWhiteSpace(response.Issue) ? TB("The runtime document endpoint failed without details.") : response.Issue); } catch (Exception e) { this.logger!.LogWarning(e, "Failed to process the Rust runtime document endpoint response."); - return new OpenDocumentResponse(false, false, TB("The runtime document endpoint failed without details.")); + return new OpenDocumentResponse(false, DocumentPageOutcome.DOCUMENT_NOT_OPENED, TB("The runtime document endpoint failed without details.")); } finally { diff --git a/app/MindWork AI Studio/Tools/SourceDocumentLocationExtensions.cs b/app/MindWork AI Studio/Tools/SourceDocumentLocationExtensions.cs index 169eacb2e..69608f9d3 100644 --- a/app/MindWork AI Studio/Tools/SourceDocumentLocationExtensions.cs +++ b/app/MindWork AI Studio/Tools/SourceDocumentLocationExtensions.cs @@ -17,6 +17,8 @@ public static class SourceDocumentLocationExtensions private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(SourceDocumentLocationExtensions).Namespace, nameof(SourceDocumentLocationExtensions)); + private static string TA(string fallbackEN) => I18N.I.TA(fallbackEN, typeof(SourceDocumentLocationExtensions).Namespace, nameof(SourceDocumentLocationExtensions)); + /// The document to show, and the page to show it at. extension(SourceDocumentLocation document) { @@ -25,8 +27,9 @@ public static class SourceDocumentLocationExtensions /// /// /// Whether the program can be sent to a page is the runtime's business, and it says afterwards - /// whether it managed to. Nothing is shown about that: the document is open, and the page is - /// named where the user asked to open it. + /// what became of the page. When the page did not arrive, the user hears where the passage is + /// and why AI Studio could not do otherwise, see GetPageNotice. Otherwise, they would take the + /// beginning of the document, or the place their program remembered, for the passage. /// /// The runtime, which opens the document. public async Task OpenAsync(RustService rustService) @@ -44,12 +47,42 @@ public static class SourceDocumentLocationExtensions } if (response.Success) + { + if (document.GetPageNotice(response) is { } notice) + await MessageBus.INSTANCE.SendInfo(new(AppIcons.DOCUMENT, notice)); + return; + } var issue = string.IsNullOrWhiteSpace(response.Issue) ? TB("Unknown error") : response.Issue; await MessageBus.INSTANCE.SendError(new(AppIcons.DOCUMENT, string.Format(TB("Could not open the document: {0}"), issue))); } + /// + /// Tells the user on which page the passage is, when the document opened without that page, and + /// why AI Studio could not open it there. + /// + /// + /// Each reason lies outside of AI Studio, and the notice says so: the sandbox of the Flatpak, a + /// program which does not let anybody choose its page, or a program which did not start with + /// one. A reason of a newer runtime is told like a program which takes no page. + /// + /// How opening the document went. + /// The notice, or null when the page arrived, none was asked for, or the document did not open at all, which the user hears about as an error. + internal string? GetPageNotice(OpenDocumentResponse response) + { + if (!response.Success || document.PageNumber is not { } page || page <= 0) + return null; + + return response.PageOutcome switch + { + DocumentPageOutcome.APPLIED or DocumentPageOutcome.NOT_REQUESTED or DocumentPageOutcome.DOCUMENT_NOT_OPENED => null, + DocumentPageOutcome.SANDBOXED => string.Format(TB("As a Flatpak, AI Studio cannot open the document at its page: the sandbox of the Flatpak lets no page through to the program which shows the document. The passage is on page {0}."), page), + DocumentPageOutcome.PROGRAM_FAILED => string.Format(TB("AI Studio could not open the document at its page: the program which shows the document could not be started with the page, so it opened without it. The passage is on page {0}."), page), + _ => string.Format(TA("AI Studio cannot open the document at its page: the program your system shows it with does not allow choosing a page. The passage is on page {0}."), page), + }; + } + /// /// Opens the file browser of the system and selects the document in it. /// diff --git a/app/MindWork AI Studio/wwwroot/changelog/v26.11.2.md b/app/MindWork AI Studio/wwwroot/changelog/v26.11.2.md index 76a6a71af..bfad5d1f2 100644 --- a/app/MindWork AI Studio/wwwroot/changelog/v26.11.2.md +++ b/app/MindWork AI Studio/wwwroot/changelog/v26.11.2.md @@ -26,6 +26,7 @@ - Improved the assistants when a request nearly fills the context window of the selected model: before sending it, AI Studio tells you, so that you can attach fewer or smaller files, or send the request anyway. - Improved the settings of the AI tasks, which AI Studio hands to a model on its own, such as the data source selection or the text content cleaner, formerly called agents: for each of them, you can now set the minimum confidence its provider needs, and the provider selection tells you which model AI Studio uses when you choose none. - Improved classic RAG: when the model you chose for selecting data sources or validating retrieval contexts may not see the data sources of your chat, AI Studio now uses the model of the chat for this step instead of skipping it. +- Improved the page numbers in the sources of your own documents: when a document opens without the page you clicked, AI Studio now tells you on which page the passage is and why it could not open the document there. This happens, for example, when AI Studio runs as a Flatpak, whose sandbox lets no page through, or when the program which shows the document does not allow choosing a page. In the Flatpak, the tooltip of a page number says so already. - Improved entering API keys: AI Studio removes spaces and line breaks around a pasted key and tells you right away when a key contains a character which an API key cannot contain, such as an invisible character copied from a web page or a typographic quotation mark. - Improved the message when a stored API key contains a character which an API key cannot contain, such as a line break: AI Studio now asks you to enter the key again instead of showing a technical error. - Improved the API keys which organizations provide through configuration plugins: AI Studio removes spaces and line breaks around them and leaves out a key with characters which an API key cannot contain, noting this in the log. diff --git a/app/Tests/Components/FileActionsTests.cs b/app/Tests/Components/FileActionsTests.cs index c630e20d6..9aad82bce 100644 --- a/app/Tests/Components/FileActionsTests.cs +++ b/app/Tests/Components/FileActionsTests.cs @@ -29,4 +29,21 @@ public sealed class FileActionsTests [Test] public void WhatOnlyADataSourceKnowsGetsNoActions() => Assert.That(FileActions.DetermineKind(SourceExtensions.CreateRetrievalSourceUrl("handbook.pdf", "docs/handbook.pdf")), Is.EqualTo(FileActions.FileActionsKind.NONE)); + + /// + /// Inside a Flatpak, no page reaches the program, so the tooltip must not promise one. It still names + /// the page, since that is where the passage is. Nothing asserts on the wording, which I18N decides. + /// + [Test] + public void WhereNoPageCanArriveTheTooltipPromisesNone() + { + var promise = FileActions.GetOpenTooltip(33, canOpenAtPage: true); + var withoutPromise = FileActions.GetOpenTooltip(33, canOpenAtPage: false); + + using (Assert.EnterMultipleScope()) + { + Assert.That(withoutPromise, Is.Not.EqualTo(promise)); + Assert.That(withoutPromise, Does.Contain("33")); + } + } } \ No newline at end of file diff --git a/app/Tests/Tools/OpenDocumentResponseTests.cs b/app/Tests/Tools/OpenDocumentResponseTests.cs new file mode 100644 index 000000000..c8b7c3808 --- /dev/null +++ b/app/Tests/Tools/OpenDocumentResponseTests.cs @@ -0,0 +1,44 @@ +using System.Text.Json; + +using AIStudio.Tools.Rust; +using AIStudio.Tools.Services; + +namespace AIStudio.Tests.Tools; + +/// +/// Checks that the app reads what the runtime tells about the page of a document it opened. +/// +/// +/// PageOutcome in runtime/src/file_actions.rs names its values in Pascal case, and the app tells the user from +/// them why a document opened without its page. A name which the app spelled differently would leave the user +/// without the reason, and failing nowhere. The test the_app_reads_the_page_outcome_by_these_names checks the +/// same names on the side of the runtime. The answers are read with the options of RustService itself. +/// +[TestFixture] +public sealed class OpenDocumentResponseTests +{ + [TestCase("Applied", DocumentPageOutcome.APPLIED)] + [TestCase("NotRequested", DocumentPageOutcome.NOT_REQUESTED)] + [TestCase("Sandboxed", DocumentPageOutcome.SANDBOXED)] + [TestCase("ProgramTakesNoPage", DocumentPageOutcome.PROGRAM_TAKES_NO_PAGE)] + [TestCase("ProgramFailed", DocumentPageOutcome.PROGRAM_FAILED)] + [TestCase("DocumentNotOpened", DocumentPageOutcome.DOCUMENT_NOT_OPENED)] + public void TheAppReadsWhatBecameOfThePage(string runtimeName, DocumentPageOutcome expected) + { + var response = JsonSerializer.Deserialize($$"""{"success":true,"page_outcome":"{{runtimeName}}","issue":""}""", RustService.JSON_OPTIONS); + + Assert.That(response, Is.EqualTo(new OpenDocumentResponse(true, expected, string.Empty))); + } + + [Test] + public void AnOutcomeOfANewerRuntimeIsUnknown() + { + var response = JsonSerializer.Deserialize("""{"success":true,"page_outcome":"ViewerOnTheMoon","issue":""}""", RustService.JSON_OPTIONS); + + using (Assert.EnterMultipleScope()) + { + Assert.That(response.Success, Is.True); + Assert.That(response.PageOutcome, Is.EqualTo(DocumentPageOutcome.UNKNOWN)); + } + } +} \ No newline at end of file diff --git a/app/Tests/Tools/RuntimeInfoResponseTests.cs b/app/Tests/Tools/RuntimeInfoResponseTests.cs index c6e1e6b74..4f92c3d90 100644 --- a/app/Tests/Tools/RuntimeInfoResponseTests.cs +++ b/app/Tests/Tools/RuntimeInfoResponseTests.cs @@ -37,4 +37,18 @@ public sealed class RuntimeInfoResponseTests Assert.That(response.RustVersion, Is.Null); } } + + /// + /// The sandbox of a Flatpak lets no page through to the program which opens a document. Everywhere else, + /// the program decides, which the runtime learns only while opening the document. + /// + [TestCase(LinuxPackageType.FLATPAK, false)] + [TestCase(LinuxPackageType.APP_IMAGE, true)] + [TestCase(LinuxPackageType.NOT_APPLICABLE, true)] + [TestCase(LinuxPackageType.UNKNOWN, true)] + public void OnlyAFlatpakCannotOpenDocumentsAtAPage(LinuxPackageType packageType, bool canOpenAtPage) + { + var runtimeInfo = new RuntimeInfoResponse("/samples/work", "/samples/app/mindwork-ai-studio", packageType, InstallationKind.USER, null); + Assert.That(runtimeInfo.CanOpenDocumentsAtPage, Is.EqualTo(canOpenAtPage)); + } } \ No newline at end of file diff --git a/app/Tests/Tools/SourceDocumentLocationExtensionsTests.cs b/app/Tests/Tools/SourceDocumentLocationExtensionsTests.cs new file mode 100644 index 000000000..ef3629b61 --- /dev/null +++ b/app/Tests/Tools/SourceDocumentLocationExtensionsTests.cs @@ -0,0 +1,58 @@ +using AIStudio.Tools; +using AIStudio.Tools.Rust; + +namespace AIStudio.Tests.Tools; + +/// +/// Checks when the user hears that a document opened without the page of its passage. +/// +/// +/// Without the notice, the user takes the beginning of the document, or the place their program remembered, +/// for the passage. Each reason gets a notice of its own, since each tells why AI Studio could not do +/// otherwise. Nothing here asserts on the wording: I18N is process-wide state without a reset, so an Init +/// somewhere else would decide whether these pass. The page itself is inserted whatever the language. +/// +[TestFixture] +public sealed class SourceDocumentLocationExtensionsTests +{ + private static readonly SourceDocumentLocation DOCUMENT_AT_PAGE_33 = new(Path.Combine(Path.GetTempPath(), "handbook.pdf"), 33); + + [TestCase(DocumentPageOutcome.SANDBOXED)] + [TestCase(DocumentPageOutcome.PROGRAM_TAKES_NO_PAGE)] + [TestCase(DocumentPageOutcome.PROGRAM_FAILED)] + [TestCase(DocumentPageOutcome.UNKNOWN)] + public void APageWhichDidNotArriveIsNamed(DocumentPageOutcome outcome) + { + var notice = DOCUMENT_AT_PAGE_33.GetPageNotice(new(true, outcome, string.Empty)); + Assert.That(notice, Does.Contain("33")); + } + + [Test] + public void EachReasonIsToldItsOwnWay() + { + var notices = new[] { DocumentPageOutcome.SANDBOXED, DocumentPageOutcome.PROGRAM_TAKES_NO_PAGE, DocumentPageOutcome.PROGRAM_FAILED } + .Select(outcome => DOCUMENT_AT_PAGE_33.GetPageNotice(new(true, outcome, string.Empty))) + .ToList(); + + Assert.That(notices, Is.Unique); + } + + [TestCase(DocumentPageOutcome.APPLIED)] + [TestCase(DocumentPageOutcome.NOT_REQUESTED)] + public void APageWhichArrivedOrWasNotAskedForNeedsNoNotice(DocumentPageOutcome outcome) => Assert.That(DOCUMENT_AT_PAGE_33.GetPageNotice(new(true, outcome, string.Empty)), Is.Null); + + [TestCase(null)] + [TestCase(0)] + public void ADocumentWithoutAPageNeedsNoNotice(int? pageNumber) + { + var document = DOCUMENT_AT_PAGE_33 with { PageNumber = pageNumber }; + Assert.That(document.GetPageNotice(new(true, DocumentPageOutcome.PROGRAM_TAKES_NO_PAGE, string.Empty)), Is.Null); + } + + /// + /// The user hears about a document which did not open as an error, and a notice about its page would only add to it. + /// + [TestCase(DocumentPageOutcome.DOCUMENT_NOT_OPENED)] + [TestCase(DocumentPageOutcome.SANDBOXED)] + public void ADocumentWhichDidNotOpenNeedsNoNotice(DocumentPageOutcome outcome) => Assert.That(DOCUMENT_AT_PAGE_33.GetPageNotice(new(false, outcome, "The path is not a file.")), Is.Null); +} \ No newline at end of file diff --git a/runtime/src/file_actions.rs b/runtime/src/file_actions.rs index 5ac046527..80c604bd4 100644 --- a/runtime/src/file_actions.rs +++ b/runtime/src/file_actions.rs @@ -101,16 +101,44 @@ pub struct OpenPathResponse { pub struct OpenDocumentResponse { success: bool, - /// Whether the document was handed to a program together with the page it should show. + /// What became of the page the document was to be shown at. /// - /// False means the document opens on its first page: no page was asked for, the system uses a - /// program we cannot tell a page, or the attempt to start that program failed. None of these - /// is an error — the document opens either way — so the app only notes it in its log. - page_applied: bool, + /// A page which did not arrive is no error — the document opens either way — but the app tells + /// the user why, so that they know where to look and that AI Studio could not do otherwise. + page_outcome: PageOutcome, issue: String, } +/// What became of the page a document was to be shown at. +/// +/// The app reads these names as `DocumentPageOutcome`, and tells the user from them why a document +/// opened without its page. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)] +pub enum PageOutcome { + /// The document was handed to its program together with the page. + Applied, + + /// No page was asked for: a slide and a spreadsheet row are no pages, and neither is a passage + /// whose page the index never learned. + NotRequested, + + /// AI Studio runs as a Flatpak. Its sandbox lets it start no program itself, and the desktop + /// portal, which opens the document instead, knows no pages. + Sandboxed, + + /// The program which shows the document cannot be told a page, or the document is no PDF, + /// the only kind of document a page is ever sent to. + ProgramTakesNoPage, + + /// The program takes a page, but it could not be started with one, so the document opened + /// without it. + ProgramFailed, + + /// The document did not open at all; the issue of the response says why. + DocumentNotOpened, +} + #[derive(Clone, Deserialize)] pub struct PreviousFile { file_path: String, @@ -410,7 +438,8 @@ async fn open_file_manager_target(requested_path: &Path) -> Result<(), String> { /// Opens a document in the program the system uses for it, on the given page where that is possible. /// /// The page is best effort and never decides whether this succeeded: a viewer which cannot be told -/// a page still shows the document, which is what the user asked for by clicking a source. +/// a page still shows the document, which is what the user asked for by clicking a source. The +/// response says what became of the page, so the app can tell the user why it did not arrive. pub async fn open_document( payload: Json, ) -> Json { @@ -419,7 +448,7 @@ pub async fn open_document( error!(Source = "Tauri"; "Refused to open a document: {issue}"); return Json(OpenDocumentResponse { success: false, - page_applied: false, + page_outcome: PageOutcome::DocumentNotOpened, issue, }); } @@ -429,21 +458,26 @@ pub async fn open_document( // pages, and neither is a passage whose page the index never learned. // let page = payload.page.filter(|page| *page > 0); - if let Some(page) = page && try_open_at_page(&requested_path, page).await { + let page_outcome = match page { + Some(page) => try_open_at_page(&requested_path, page).await, + None => PageOutcome::NotRequested, + }; + + if let Some(page) = page && page_outcome == PageOutcome::Applied { info!("Opened document at page {page}: {requested_path:?}"); return Json(OpenDocumentResponse { success: true, - page_applied: true, + page_outcome, issue: String::new(), }); } match tauri_plugin_opener::open_path(&requested_path, None::<&str>) { Ok(()) => { - info!("Opened document: {requested_path:?}"); + info!("Opened document without a page ({page_outcome:?}): {requested_path:?}"); Json(OpenDocumentResponse { success: true, - page_applied: false, + page_outcome, issue: String::new(), }) }, @@ -453,7 +487,7 @@ pub async fn open_document( error!(Source = "Tauri"; "{issue}"); Json(OpenDocumentResponse { success: false, - page_applied: false, + page_outcome: PageOutcome::DocumentNotOpened, issue, }) }, @@ -514,28 +548,42 @@ fn refuse_document(requested_path: &Path) -> Option { } } -/// Tries to show the document on the given page, and says whether it did. +/// Tries to show the document on the given page, and says what became of the page. /// /// On macOS, `open` drops the fragment of a URL before the program it starts ever sees it, with and /// without `-a`, so neither a browser nor Preview can be told a page from the command line. Only a -/// program which takes the page as an argument of its own gets there; with any other, the document -/// opens on its first page, and the source names the page for the reader. -async fn try_open_at_page(path: &Path, page: u32) -> bool { - let DocumentOpenPlan::WithPage { program, arguments } = resolve_document_open_plan(path, page).await else { - return false; +/// program which takes the page as an argument of its own gets there; with any other, the caller +/// opens the document plainly, and the app tells the user the page and why it did not arrive. +async fn try_open_at_page(path: &Path, page: u32) -> PageOutcome { + let plan = resolve_document_open_plan(path, page).await; + let DocumentOpenPlan::WithPage { program, arguments } = &plan else { + return page_outcome_of(&plan, false); }; - match start_page_aware_viewer(&program, &arguments).await { + let started = match start_page_aware_viewer(program, arguments).await { Ok(()) => true, // - // Failing to start the viewer ourselves is not something the user has to hear about: the - // caller opens the document plainly afterwards, only without the page. + // The caller opens the document plainly afterwards, only without the page, and the app + // tells the user that the program could not be started with it. // Err(issue) => { warn!(Source = "Tauri"; "Could not open '{}' at page {page}, opening it without a page instead: {issue}", path.to_string_lossy()); false }, + }; + + page_outcome_of(&plan, started) +} + +/// What became of the page, from how the document was to be opened and whether a program which +/// takes the page was started with it. +fn page_outcome_of(plan: &DocumentOpenPlan, started: bool) -> PageOutcome { + match plan { + DocumentOpenPlan::Plain => PageOutcome::ProgramTakesNoPage, + DocumentOpenPlan::Sandboxed => PageOutcome::Sandboxed, + DocumentOpenPlan::WithPage { .. } if started => PageOutcome::Applied, + DocumentOpenPlan::WithPage { .. } => PageOutcome::ProgramFailed, } } @@ -582,9 +630,16 @@ enum PageArgument { /// What it takes to show a document on a page. #[derive(Debug, PartialEq, Eq)] enum DocumentOpenPlan { - /// Hand the file to the system and let it decide. The document opens on its first page. + /// Hand the file to the system and let it decide. Its program cannot be told a page, or the + /// document is no PDF, so it opens without one. Plain, + /// Hand the file to the system, because AI Studio runs as a Flatpak. Its sandbox has its own list + /// of registered programs rather than the desktop's, and even the right answer would name a + /// program which is not in the sandbox to be started. The desktop portal opens the document + /// instead, and it knows no pages. + Sandboxed, + /// Start this program ourselves, because it takes the page as an argument. WithPage { program: String, arguments: Vec }, } @@ -678,6 +733,10 @@ async fn resolve_document_open_plan(path: &Path, page: u32) -> DocumentOpenPlan return DocumentOpenPlan::Plain; } + if crate::environment::is_flatpak() { + return DocumentOpenPlan::Sandboxed; + } + #[cfg(windows)] { let Some(prog_id) = windows_default_pdf_prog_id() else { @@ -860,16 +919,9 @@ fn windows_page_argument(prog_id: &str) -> Option { /// Reads which program the desktop opens PDFs with. /// -/// Inside a Flatpak there is nothing to read: the sandbox has its own list of registered programs -/// rather than the desktop's, and even the right answer would name a program which is not in the -/// sandbox to be started. The document is handed to the desktop portal instead, which opens it on -/// its first page. +/// Never asked inside a Flatpak, which has nothing to read, see DocumentOpenPlan::Sandboxed. #[cfg(target_os = "linux")] async fn linux_default_pdf_handler() -> Option { - if crate::environment::is_flatpak() { - return None; - } - let output = tokio::process::Command::new("xdg-mime") .args(["query", "default", "application/pdf"]) .output() @@ -1456,6 +1508,59 @@ mod tests { ); } + /// The app tells the user why a page did not arrive, so every way of opening has to name its reason. + #[test] + fn every_way_of_opening_names_what_became_of_the_page() { + let with_page = DocumentOpenPlan::WithPage { + program: String::from("pdfcraft"), + arguments: vec![String::from("--page"), String::from("12"), String::from("/docs/handbook.pdf")], + }; + + assert_eq!(page_outcome_of(&with_page, true), PageOutcome::Applied); + assert_eq!(page_outcome_of(&with_page, false), PageOutcome::ProgramFailed, "A program which takes the page but did not start leaves the document without it."); + assert_eq!(page_outcome_of(&DocumentOpenPlan::Plain, false), PageOutcome::ProgramTakesNoPage); + assert_eq!(page_outcome_of(&DocumentOpenPlan::Sandboxed, false), PageOutcome::Sandboxed, "Inside a Flatpak, the sandbox is the reason, not the program."); + } + + #[tokio::test] + async fn a_document_which_is_no_pdf_gets_no_page() { + let plan = resolve_document_open_plan(Path::new("/docs/handbook.docx"), 12).await; + assert_eq!(plan, DocumentOpenPlan::Plain, "Only PDFs are ever sent to a page, also inside a Flatpak."); + } + + /// The app reads these names as DocumentPageOutcome; renaming one breaks it without any compiler noticing. + #[test] + fn the_app_reads_the_page_outcome_by_these_names() { + let response = OpenDocumentResponse { + success: true, + page_outcome: PageOutcome::ProgramTakesNoPage, + issue: String::new(), + }; + + assert_eq!( + serde_json::to_string(&response).unwrap(), + r#"{"success":true,"page_outcome":"ProgramTakesNoPage","issue":""}"#, + ); + + let names = [ + PageOutcome::Applied, + PageOutcome::NotRequested, + PageOutcome::Sandboxed, + PageOutcome::ProgramTakesNoPage, + PageOutcome::ProgramFailed, + PageOutcome::DocumentNotOpened, + ].map(|outcome| serde_json::to_string(&outcome).unwrap()); + + assert_eq!(names, [ + r#""Applied""#, + r#""NotRequested""#, + r#""Sandboxed""#, + r#""ProgramTakesNoPage""#, + r#""ProgramFailed""#, + r#""DocumentNotOpened""#, + ]); + } + #[test] fn windows_recognizes_the_programs_it_can_send_to_a_page() { assert_eq!(windows_page_argument("AcroExch.Document.DC"), Some(PageArgument::AcrobatOpenAction));