mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-17 08:18:00 +00:00
Fixed local source links being refused by Word and LibreOffice
This commit is contained in:
6 files changed
+125
-7
No files matched your search
@@ -0,0 +1,39 @@
|
||||
using AIStudio.Tools;
|
||||
|
||||
namespace AIStudio.Tests.Tools;
|
||||
|
||||
/// <summary>
|
||||
/// Checks what AI Studio assumes about the readers of the formats it writes.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public sealed class FileExportFormatTests
|
||||
{
|
||||
[Test]
|
||||
public void OnlyTheTwoOfficeFormatsRefuseAPageInALocalLink()
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(FileExportFormat.MICROSOFT_WORD.FollowsPageAnchors(), Is.False, "Word looks for a file whose name ends in the fragment, finds none, and refuses the link.");
|
||||
Assert.That(FileExportFormat.OPEN_DOCUMENT_TEXT.FollowsPageAnchors(), Is.False, "LibreOffice does the same, verified on 2026-09-15 with an exported .odt.");
|
||||
Assert.That(FileExportFormat.HTML.FollowsPageAnchors(), Is.True, "A browser opens the document on the page the fragment names.");
|
||||
Assert.That(FileExportFormat.MARKDOWN.FollowsPageAnchors(), Is.True);
|
||||
Assert.That(FileExportFormat.LATEX.FollowsPageAnchors(), Is.True);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EveryFormatAnAnswerIsWrittenAsHasAnAnswerHere()
|
||||
{
|
||||
// Whoever adds a format decides what its reader can follow, rather than inheriting an
|
||||
// assumption. This fails for a format which nobody thought about, because the list below
|
||||
// has to name it:
|
||||
Assert.That(FileExportFormatExtensions.ANSWER_FORMATS, Is.EquivalentTo(new[]
|
||||
{
|
||||
FileExportFormat.MICROSOFT_WORD,
|
||||
FileExportFormat.OPEN_DOCUMENT_TEXT,
|
||||
FileExportFormat.LATEX,
|
||||
FileExportFormat.MARKDOWN,
|
||||
FileExportFormat.HTML,
|
||||
}), "A format was added to or removed from the export menu: say in FollowsPageAnchors whether its reader follows a page in a local link, then name it here.");
|
||||
}
|
||||
}
|
||||
@@ -137,6 +137,36 @@ public sealed class SourceExtensionsTests
|
||||
Assert.That(entries[index], Does.StartWith($"- [{listed[index].Number}] ").And.Contains(listed[index].Source.Title), "The Markdown and the chat read the same grouping, so a source cannot be numbered one way here and another way there.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AReaderWhichCannotFollowAPageGetsTheDocumentWithoutOne()
|
||||
{
|
||||
IList<Source> sources =
|
||||
[
|
||||
new("Handbook (Page 266)", "file:///Users/someone/My Documents/handbook.pdf#page=266", SourceOrigin.RAG),
|
||||
new("An older answer", "file:///Users/someone/handbook.pdf#chunk=3", SourceOrigin.RAG),
|
||||
new("A section of an article", "https://example.org/article#results", SourceOrigin.LLM),
|
||||
];
|
||||
|
||||
Assert.That(EntriesOf(sources.ToMarkdown(keepPageAnchors: false)), Is.EqualTo(new[]
|
||||
{
|
||||
"- [1] [A section of an article](<https://example.org/article#results>)",
|
||||
"- [2] [Handbook (Page 266)](<file:///Users/someone/My%20Documents/handbook.pdf>)",
|
||||
"- [3] [An older answer](<file:///Users/someone/handbook.pdf>)",
|
||||
}), "Word and LibreOffice take the fragment of a local link for part of the file name and refuse the link, so the local links lose it -- and the web link keeps its own, where a fragment names a section of the page and belongs to the address.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AReaderWhichFollowsAPageIsToldIt()
|
||||
{
|
||||
IList<Source> sources = [new("Handbook (Page 266)", "file:///Users/someone/handbook.pdf#page=266", SourceOrigin.RAG)];
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(EntriesOf(sources.ToMarkdown()).Single(), Does.EndWith("handbook.pdf#page=266>)"), "A browser and a PDF reader open the document where the passage is, so they are told the page.");
|
||||
Assert.That(EntriesOf(sources.ToExportMarkdown()).Single(), Does.EndWith("handbook.pdf#page=266>)"), "The clipboard and every text format keep it as well; only the two office formats ask for it to be dropped.");
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AKnownPageRidesInTheLinkOfASource()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user