Added a notice naming the page when a source opens without it (#1233)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-25 16:38:31 +01:00
1 parent e63e70a5cf
commit deb75c8dd1
18 files changed
+447 -57

No files matched your search

+17
View File
@@ -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));
/// <summary>
/// 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.
/// </summary>
[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"));
}
}
}
@@ -0,0 +1,44 @@
using System.Text.Json;
using AIStudio.Tools.Rust;
using AIStudio.Tools.Services;
namespace AIStudio.Tests.Tools;
/// <summary>
/// Checks that the app reads what the runtime tells about the page of a document it opened.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
[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<OpenDocumentResponse>($$"""{"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<OpenDocumentResponse>("""{"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));
}
}
}
@@ -37,4 +37,18 @@ public sealed class RuntimeInfoResponseTests
Assert.That(response.RustVersion, Is.Null);
}
}
/// <summary>
/// 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.
/// </summary>
[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));
}
}
@@ -0,0 +1,58 @@
using AIStudio.Tools;
using AIStudio.Tools.Rust;
namespace AIStudio.Tests.Tools;
/// <summary>
/// Checks when the user hears that a document opened without the page of its passage.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
[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);
}
/// <summary>
/// The user hears about a document which did not open as an error, and a notice about its page would only add to it.
/// </summary>
[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);
}