mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-04 10:48:23 +00:00
Web search restrictions after internal content (#1074)
Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
1 parent
f38c4aa563
commit
1f8d72aa45
42 files changed
+1654
-228
No files matched your search
@@ -7,18 +7,20 @@ using AIStudio.Tools;
|
||||
namespace AIStudio.Tests.Chat;
|
||||
|
||||
/// <summary>
|
||||
/// Checks how the mailboxes a chat read from restrict where it may still send data.
|
||||
/// Checks how the internal content a chat holds restricts where it may still send data.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Once mail content is in a chat, every tool which runs afterwards could carry it out. The chat
|
||||
/// therefore keeps the strictest restriction of every mailbox it read from, and it keeps it beyond
|
||||
/// a restart, because the content stays in the chat as well.
|
||||
/// Once internal content is in a chat, mails or pages of the wiki or the intranet, every tool which
|
||||
/// runs afterwards could carry it out. The chat therefore keeps the strictest restriction of every
|
||||
/// source it read from, and it keeps it beyond a restart, because the content stays in the chat as
|
||||
/// well.
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
public sealed class ChatThreadOutboundDataRestrictionTests
|
||||
{
|
||||
private const string PRIVATE_MAILBOX_ID = "5c9e2a7b-3f1d-4e8a-b6c4-2d7f9a1e3b5c";
|
||||
private const string WORK_MAILBOX_ID = "8d1f4b6a-2e9c-4a7d-9b3e-6c5a8f2d1e4b";
|
||||
private const string INTRANET_HOST = "intranet.example.org";
|
||||
|
||||
[Test]
|
||||
public void AChatWhichReadNoMailboxDemandsNothing() =>
|
||||
@@ -30,10 +32,10 @@ public sealed class ChatThreadOutboundDataRestrictionTests
|
||||
public void AStricterMailboxTightensTheChat(OutboundDataRestriction held, OutboundDataRestriction arriving)
|
||||
{
|
||||
var thread = new ChatThread();
|
||||
thread.RequireOutboundDataRestriction(new(held, PRIVATE_MAILBOX_ID));
|
||||
thread.RequireOutboundDataRestriction(new(arriving, WORK_MAILBOX_ID));
|
||||
thread.RequireOutboundDataRestriction(new(held, OutboundDataOrigin.MAILBOX, PRIVATE_MAILBOX_ID));
|
||||
thread.RequireOutboundDataRestriction(new(arriving, OutboundDataOrigin.MAILBOX, WORK_MAILBOX_ID));
|
||||
|
||||
Assert.That(thread.RequiredOutboundDataRestriction, Is.EqualTo(new OutboundDataRequirement(arriving, WORK_MAILBOX_ID)), "The stricter mailbox is the one which keeps a tool from running, so it is the one to name.");
|
||||
Assert.That(thread.RequiredOutboundDataRestriction, Is.EqualTo(new OutboundDataRequirement(arriving, OutboundDataOrigin.MAILBOX, WORK_MAILBOX_ID)), "The stricter mailbox is the one which keeps a tool from running, so it is the one to name.");
|
||||
}
|
||||
|
||||
[TestCase(OutboundDataRestriction.ONLY_CONFIGURED_SERVICES, OutboundDataRestriction.ONLY_LINKS_FROM_CHAT)]
|
||||
@@ -42,41 +44,74 @@ public sealed class ChatThreadOutboundDataRestrictionTests
|
||||
public void ARestrictionStays(OutboundDataRestriction held, OutboundDataRestriction arriving)
|
||||
{
|
||||
var thread = new ChatThread();
|
||||
thread.RequireOutboundDataRestriction(new(held, PRIVATE_MAILBOX_ID));
|
||||
thread.RequireOutboundDataRestriction(new(arriving, WORK_MAILBOX_ID));
|
||||
thread.RequireOutboundDataRestriction(new(held, OutboundDataOrigin.MAILBOX, PRIVATE_MAILBOX_ID));
|
||||
thread.RequireOutboundDataRestriction(new(arriving, OutboundDataOrigin.MAILBOX, WORK_MAILBOX_ID));
|
||||
|
||||
Assert.That(thread.RequiredOutboundDataRestriction, Is.EqualTo(new OutboundDataRequirement(held, PRIVATE_MAILBOX_ID)), "The mail content was read by this chat. A more permissive mailbox read later cannot undo that.");
|
||||
Assert.That(thread.RequiredOutboundDataRestriction, Is.EqualTo(new OutboundDataRequirement(held, OutboundDataOrigin.MAILBOX, PRIVATE_MAILBOX_ID)), "The mail content was read by this chat. A more permissive mailbox read later cannot undo that.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OnATieTheMailboxReadFirstStaysNamed()
|
||||
{
|
||||
var thread = new ChatThread();
|
||||
thread.RequireOutboundDataRestriction(new(OutboundDataRestriction.ONLY_LINKS_FROM_CHAT, PRIVATE_MAILBOX_ID));
|
||||
thread.RequireOutboundDataRestriction(new(OutboundDataRestriction.ONLY_LINKS_FROM_CHAT, WORK_MAILBOX_ID));
|
||||
thread.RequireOutboundDataRestriction(new(OutboundDataRestriction.ONLY_LINKS_FROM_CHAT, OutboundDataOrigin.MAILBOX, PRIVATE_MAILBOX_ID));
|
||||
thread.RequireOutboundDataRestriction(new(OutboundDataRestriction.ONLY_LINKS_FROM_CHAT, OutboundDataOrigin.MAILBOX, WORK_MAILBOX_ID));
|
||||
|
||||
Assert.That(thread.RequiredOutboundDataRestriction.DataSourceId, Is.EqualTo(PRIVATE_MAILBOX_ID), "Otherwise the chat would name another mailbox with every search.");
|
||||
Assert.That(thread.RequiredOutboundDataRestriction.Reference, Is.EqualTo(PRIVATE_MAILBOX_ID), "Otherwise the chat would name another mailbox with every search.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AStricterSourceOfAnotherKindTightensTheChat()
|
||||
{
|
||||
var thread = new ChatThread();
|
||||
thread.RequireOutboundDataRestriction(new(OutboundDataRestriction.ONLY_LINKS_FROM_CHAT, OutboundDataOrigin.MAILBOX, WORK_MAILBOX_ID));
|
||||
thread.RequireOutboundDataRestriction(new(OutboundDataRestriction.ONLY_CONFIGURED_SERVICES, OutboundDataOrigin.INTERNAL_WEB_PAGE, INTRANET_HOST));
|
||||
|
||||
Assert.That(thread.RequiredOutboundDataRestriction, Is.EqualTo(new OutboundDataRequirement(OutboundDataRestriction.ONLY_CONFIGURED_SERVICES, OutboundDataOrigin.INTERNAL_WEB_PAGE, INTRANET_HOST)), "The level decides, not the kind of source, and the stricter source is the one to name.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OnATieTheSourceReadFirstStaysNamedWhateverItsKind()
|
||||
{
|
||||
var thread = new ChatThread();
|
||||
thread.RequireOutboundDataRestriction(new(OutboundDataRestriction.ONLY_LINKS_FROM_CHAT, OutboundDataOrigin.CONFLUENCE_WIKI, string.Empty));
|
||||
thread.RequireOutboundDataRestriction(new(OutboundDataRestriction.ONLY_LINKS_FROM_CHAT, OutboundDataOrigin.MAILBOX, WORK_MAILBOX_ID));
|
||||
thread.RequireOutboundDataRestriction(new(OutboundDataRestriction.ONLY_LINKS_FROM_CHAT, OutboundDataOrigin.INTERNAL_WEB_PAGE, INTRANET_HOST));
|
||||
|
||||
Assert.That(thread.RequiredOutboundDataRestriction, Is.EqualTo(new OutboundDataRequirement(OutboundDataRestriction.ONLY_LINKS_FROM_CHAT, OutboundDataOrigin.CONFLUENCE_WIKI, string.Empty)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ResultsWhichDemandNothingChangeNothing()
|
||||
{
|
||||
var thread = new ChatThread();
|
||||
thread.RequireOutboundDataRestriction(new(OutboundDataRestriction.ONLY_CONFIGURED_SERVICES, PRIVATE_MAILBOX_ID));
|
||||
thread.RequireOutboundDataRestriction(new(OutboundDataRestriction.ONLY_CONFIGURED_SERVICES, OutboundDataOrigin.MAILBOX, PRIVATE_MAILBOX_ID));
|
||||
thread.RequireOutboundDataRestriction(OutboundDataRequirement.NONE);
|
||||
|
||||
Assert.That(thread.RequiredOutboundDataRestriction, Is.EqualTo(new OutboundDataRequirement(OutboundDataRestriction.ONLY_CONFIGURED_SERVICES, PRIVATE_MAILBOX_ID)), "A search of the local files, say, says nothing about mailboxes and must leave the chat as it was.");
|
||||
Assert.That(thread.RequiredOutboundDataRestriction, Is.EqualTo(new OutboundDataRequirement(OutboundDataRestriction.ONLY_CONFIGURED_SERVICES, OutboundDataOrigin.MAILBOX, PRIVATE_MAILBOX_ID)), "A search of the local files, say, says nothing about mailboxes and must leave the chat as it was.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheRestrictionSurvivesSavingTheChat()
|
||||
{
|
||||
var thread = new ChatThread { ChatId = Guid.NewGuid() };
|
||||
thread.RequireOutboundDataRestriction(new(OutboundDataRestriction.ONLY_LINKS_FROM_CHAT, WORK_MAILBOX_ID));
|
||||
thread.RequireOutboundDataRestriction(new(OutboundDataRestriction.ONLY_LINKS_FROM_CHAT, OutboundDataOrigin.MAILBOX, WORK_MAILBOX_ID));
|
||||
|
||||
var loaded = JsonSerializer.Deserialize<ChatThread>(JsonSerializer.Serialize(thread, WorkspaceBehaviour.JSON_OPTIONS), WorkspaceBehaviour.JSON_OPTIONS);
|
||||
|
||||
Assert.That(loaded?.RequiredOutboundDataRestriction, Is.EqualTo(new OutboundDataRequirement(OutboundDataRestriction.ONLY_LINKS_FROM_CHAT, WORK_MAILBOX_ID)), "After a restart, the mail content is still in the chat, so the restriction has to be as well.");
|
||||
Assert.That(loaded?.RequiredOutboundDataRestriction, Is.EqualTo(new OutboundDataRequirement(OutboundDataRestriction.ONLY_LINKS_FROM_CHAT, OutboundDataOrigin.MAILBOX, WORK_MAILBOX_ID)), "After a restart, the mail content is still in the chat, so the restriction has to be as well.");
|
||||
}
|
||||
|
||||
[TestCase(OutboundDataOrigin.CONFLUENCE_WIKI, "")]
|
||||
[TestCase(OutboundDataOrigin.INTERNAL_WEB_PAGE, INTRANET_HOST)]
|
||||
public void TheOriginSurvivesSavingTheChat(OutboundDataOrigin origin, string reference)
|
||||
{
|
||||
var thread = new ChatThread { ChatId = Guid.NewGuid() };
|
||||
thread.RequireOutboundDataRestriction(new(OutboundDataRestriction.ONLY_LINKS_FROM_CHAT, origin, reference));
|
||||
|
||||
var loaded = JsonSerializer.Deserialize<ChatThread>(JsonSerializer.Serialize(thread, WorkspaceBehaviour.JSON_OPTIONS), WorkspaceBehaviour.JSON_OPTIONS);
|
||||
|
||||
Assert.That(loaded?.RequiredOutboundDataRestriction, Is.EqualTo(new OutboundDataRequirement(OutboundDataRestriction.ONLY_LINKS_FROM_CHAT, origin, reference)), "Otherwise a restored chat would name a mailbox for content it read from elsewhere.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
Reference in new issue
Block a user