mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-16 08:48:34 +00:00
Added the choice of simulated participants to the test situation of the BeyondFacts Lab
This commit is contained in:
13 files changed
+557
-5
No files matched your search
@@ -405,6 +405,54 @@ public sealed class BeyondFactsLabStoreTests
|
||||
await Assert.ThrowsAsync<InvalidDataException>(async () => await store.LoadFormAsync(created.ProjectId, BflStep.VALUES_AND_PERSPECTIVES));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ASimulationIsStoredWithTheFormOfItsStep()
|
||||
{
|
||||
var store = this.CreateStore();
|
||||
var created = await store.CreateAsync("Panel");
|
||||
var form = new BflStepFormData { Simulation = new() { Mode = BflSimulationMode.PANEL_DISCUSSION, People = ["Eva Klein", "Frank Ott"] } };
|
||||
|
||||
await store.SaveFormAsync(created.ProjectId, BflStep.TEST_SITUATION, form);
|
||||
var json = await File.ReadAllTextAsync(Path.Combine(this.RootDirectory, created.ProjectId.ToString("D"), "steps", "06-test", "form.json"));
|
||||
var loaded = (await this.CreateStore().LoadFormAsync(created.ProjectId, BflStep.TEST_SITUATION)).Simulation;
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(json, Does.Contain("\"PANEL_DISCUSSION\""), "The mode is stored by its name, which never changes.");
|
||||
Assert.That(loaded, Is.Not.Null);
|
||||
Assert.That(loaded!.Mode, Is.EqualTo(BflSimulationMode.PANEL_DISCUSSION));
|
||||
Assert.That(loaded.People, Is.EqualTo(new[] { "Eva Klein", "Frank Ott" }));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AFormOfTheSecondVersionIsStillOpenedWithoutASimulation()
|
||||
{
|
||||
var store = this.CreateStore();
|
||||
var created = await store.CreateAsync("Panel");
|
||||
await this.WriteFormFileAsync(created.ProjectId, "06-test", """{ "schemaVersion": 2, "values": { "test_notes": "Text" } }""");
|
||||
|
||||
var form = await store.LoadFormAsync(created.ProjectId, BflStep.TEST_SITUATION);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(form.Get(BflFieldCatalog.TEST_NOTES), Is.EqualTo("Text"));
|
||||
Assert.That(form.Simulation, Is.Null);
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase("""{ "schemaVersion": 3, "values": {}, "simulation": { "mode": "PANEL_DISCUSSION", "people": null } }""")]
|
||||
[TestCase("""{ "schemaVersion": 3, "values": {}, "simulation": { "mode": "PANEL_DISCUSSION", "people": [ null ] } }""")]
|
||||
[TestCase("""{ "schemaVersion": 3, "values": {}, "simulation": { "mode": 42, "people": [] } }""")]
|
||||
public async Task AFormWithABrokenSimulationIsNotOpened(string json)
|
||||
{
|
||||
var store = this.CreateStore();
|
||||
var created = await store.CreateAsync("Panel");
|
||||
await this.WriteFormFileAsync(created.ProjectId, "06-test", json);
|
||||
|
||||
await Assert.ThrowsAsync<InvalidDataException>(async () => await store.LoadFormAsync(created.ProjectId, BflStep.TEST_SITUATION));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AStepWithoutAFormGetsAnEmptyOne()
|
||||
{
|
||||
@@ -463,7 +511,7 @@ public sealed class BeyondFactsLabStoreTests
|
||||
[Test]
|
||||
public async Task AFormOfANewerVersionIsNotOverwritten()
|
||||
{
|
||||
const string NEWER = """{ "schemaVersion": 3, "values": {} }""";
|
||||
const string NEWER = """{ "schemaVersion": 4, "values": {} }""";
|
||||
var store = this.CreateStore();
|
||||
var created = await store.CreateAsync("Panel");
|
||||
var formPath = await this.WriteFormFileAsync(created.ProjectId, "05-strategy", NEWER);
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
using AIStudio.Assistants.BeyondFactsLab;
|
||||
using AIStudio.Models;
|
||||
|
||||
namespace AIStudio.Tests.BeyondFactsLab;
|
||||
|
||||
/// <summary>
|
||||
/// Checks whom the chat of the step "Test situation" of the BeyondFacts Lab may play, whom it plays of what the person
|
||||
/// chose, and whether a model reads enough for it.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public sealed class BflSimulationTests
|
||||
{
|
||||
private static readonly DateTimeOffset CREATED_AT_UTC = new(2026, 11, 15, 10, 0, 0, TimeSpan.Zero);
|
||||
|
||||
[Test]
|
||||
public void OnlyAListedPersonWithDocumentedPositionsQualifies()
|
||||
{
|
||||
var forms = Forms();
|
||||
BflPersonResearch[] people =
|
||||
[
|
||||
Person(forms, "Eva Klein", BflPersonResearchStage.All),
|
||||
Person(forms, "Frank Ott", [BflPersonResearchStage.PROFILE]),
|
||||
Person(forms, "Gina Roth", [BflPersonResearchStage.PROFILE, BflPersonResearchStage.POSITIONS], positionsText: " "),
|
||||
Person(forms, "Nicht Gelistet", BflPersonResearchStage.All)
|
||||
];
|
||||
|
||||
var candidates = BflSimulationCandidates.Of(forms, Topics(forms, "Eva Klein", "Frank Ott", "Gina Roth"), people);
|
||||
|
||||
Assert.That(candidates.Select(person => person.Name), Is.EqualTo(new[] { "Eva Klein" }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheCandidatesComeInTheOrderOfTheList()
|
||||
{
|
||||
var forms = Forms();
|
||||
BflPersonResearch[] people = [Person(forms, "Eva Klein", BflPersonResearchStage.All), Person(forms, "Frank Ott", BflPersonResearchStage.All)];
|
||||
|
||||
var candidates = BflSimulationCandidates.Of(forms, Topics(forms, "Frank Ott", "Eva Klein"), people);
|
||||
|
||||
Assert.That(candidates.Select(person => person.Name), Is.EqualTo(new[] { "Frank Ott", "Eva Klein" }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NobodyQualifiesForAnEventWhichIsNotPublic()
|
||||
{
|
||||
var forms = Forms();
|
||||
BflPersonResearch[] people = [Person(forms, "Eva Klein", BflPersonResearchStage.All)];
|
||||
var topics = Topics(forms, "Eva Klein");
|
||||
forms[BflStep.FRAMEWORK].Set(BflFieldCatalog.EVENT_VISIBILITY, BflFieldCatalog.EVENT_NOT_PUBLIC);
|
||||
|
||||
Assert.That(BflSimulationCandidates.Of(forms, topics, people), Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenericCounterpartsPlayNobody()
|
||||
{
|
||||
var candidates = Candidates("Eva Klein");
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(BflEffectiveSimulation.Of(null, candidates), Is.SameAs(BflEffectiveSimulation.GENERIC));
|
||||
Assert.That(BflEffectiveSimulation.Of(new() { Mode = BflSimulationMode.GENERIC, People = ["Eva Klein"] }, candidates), Is.SameAs(BflEffectiveSimulation.GENERIC));
|
||||
}
|
||||
}
|
||||
|
||||
[TestCase(BflSimulationMode.SINGLE_PERSON, 1)]
|
||||
[TestCase(BflSimulationMode.PANEL_DISCUSSION, 3)]
|
||||
[TestCase(BflSimulationMode.PRESS_CONFERENCE, 5)]
|
||||
public void AModePlaysAtMostItsNumberOfPeopleInTheOrderOfTheList(BflSimulationMode mode, int expected)
|
||||
{
|
||||
string[] names = ["Anna Arendt", "Bruno Berg", "Clara Cramer", "David Dorn", "Eva Klein", "Frank Ott"];
|
||||
var candidates = Candidates(names);
|
||||
var simulation = new BflSimulation { Mode = mode, People = [.. names.Reverse()] };
|
||||
|
||||
var effective = BflEffectiveSimulation.Of(simulation, candidates);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(mode.MaxPeople, Is.EqualTo(expected));
|
||||
Assert.That(effective.Mode, Is.EqualTo(mode));
|
||||
Assert.That(effective.People.Select(person => person.Name), Is.EqualTo(names.Take(expected)));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void APersonWhoIsNoLongerACandidateCountsNoLonger()
|
||||
{
|
||||
var candidates = Candidates("Eva Klein", "Frank Ott");
|
||||
var simulation = new BflSimulation { Mode = BflSimulationMode.PANEL_DISCUSSION, People = ["Nicht Mehr Gelistet", "frank ott"] };
|
||||
|
||||
var effective = BflEffectiveSimulation.Of(simulation, candidates);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(effective.People.Select(person => person.Name), Is.EqualTo(new[] { "Frank Ott" }));
|
||||
Assert.That(simulation.People, Has.Count.EqualTo(2), "What the person chose stays stored.");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AModeWithoutAnyChosenCandidateFallsBackToGenericCounterparts()
|
||||
{
|
||||
var candidates = Candidates("Eva Klein");
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(BflEffectiveSimulation.Of(new() { Mode = BflSimulationMode.SINGLE_PERSON }, candidates), Is.SameAs(BflEffectiveSimulation.GENERIC));
|
||||
Assert.That(BflEffectiveSimulation.Of(new() { Mode = BflSimulationMode.PRESS_CONFERENCE, People = ["Frank Ott"] }, candidates), Is.SameAs(BflEffectiveSimulation.GENERIC));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheDossiersAreCountedWithTheCharactersPerTokenOfTheMaterial()
|
||||
{
|
||||
var person = new BflPersonResearch { Name = "Eva Klein" };
|
||||
person.Set(BflPersonResearchStage.PROFILE, new BflResearch { Text = new string('a', 4_000), CreatedAtUtc = CREATED_AT_UTC });
|
||||
person.Set(BflPersonResearchStage.POSITIONS, new BflResearch { Text = $" {new string('b', 3_999)}\n", CreatedAtUtc = CREATED_AT_UTC });
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(BflSimulationBudget.DossierTokens([person]), Is.EqualTo(2_000));
|
||||
Assert.That(BflSimulationBudget.RequiredTokens([person]), Is.EqualTo(BflModelRequirements.MINIMUM_CONTEXT_TOKENS + 2_000));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AKnownWindowWhichIsTooSmallRefusesAndAnUnknownOneWarns()
|
||||
{
|
||||
var person = new BflPersonResearch { Name = "Eva Klein" };
|
||||
person.Set(BflPersonResearchStage.POSITIONS, new BflResearch { Text = new string('a', 40_000), CreatedAtUtc = CREATED_AT_UTC });
|
||||
var simulation = new BflEffectiveSimulation(BflSimulationMode.SINGLE_PERSON, [person]);
|
||||
var required = BflSimulationBudget.RequiredTokens([person]);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(BflSimulationBudget.Check(simulation, ContextWindow.Of(required - 1)), Is.EqualTo(BflSimulationFit.TOO_SMALL));
|
||||
Assert.That(BflSimulationBudget.Check(simulation, ContextWindow.Of(required)), Is.EqualTo(BflSimulationFit.FITS));
|
||||
Assert.That(BflSimulationBudget.Check(simulation, ContextWindow.UNKNOWN), Is.EqualTo(BflSimulationFit.UNKNOWN_CONTEXT));
|
||||
Assert.That(BflSimulationBudget.Check(BflEffectiveSimulation.GENERIC, ContextWindow.Of(8_192)), Is.EqualTo(BflSimulationFit.FITS), "Generic counterparts need no room for dossiers.");
|
||||
Assert.That(BflSimulationBudget.Check(BflEffectiveSimulation.GENERIC, ContextWindow.UNKNOWN), Is.EqualTo(BflSimulationFit.FITS));
|
||||
}
|
||||
}
|
||||
|
||||
private static List<BflPersonResearch> Candidates(params string[] names)
|
||||
{
|
||||
var forms = Forms();
|
||||
return [.. BflSimulationCandidates.Of(forms, Topics(forms, names), [.. names.Select(name => Person(forms, name, BflPersonResearchStage.All))])];
|
||||
}
|
||||
|
||||
private static BflPersonResearch Person(IReadOnlyDictionary<BflStep, BflStepFormData> forms, string name, IEnumerable<BflPersonResearchStage> stages, string? positionsText = null)
|
||||
{
|
||||
var person = new BflPersonResearch { Name = name };
|
||||
foreach (var stage in stages)
|
||||
person.Set(stage, BflResearch.Of(stage is BflPersonResearchStage.POSITIONS && positionsText is not null ? positionsText : $"Text {stage}", [], [], BflPromptComposer.PublicDetailsOf(forms), CREATED_AT_UTC));
|
||||
|
||||
return person;
|
||||
}
|
||||
|
||||
private static Dictionary<BflResearchTopic, BflResearch> Topics(IReadOnlyDictionary<BflStep, BflStepFormData> forms, params string[] names)
|
||||
{
|
||||
var list = BflResearch.Of(string.Join("\n\n", names.Select(name => $"### {name}")), [], [], BflPromptComposer.PublicDetailsOf(forms), CREATED_AT_UTC);
|
||||
list.Participants = [.. BflParticipant.ListIn(list.Text)];
|
||||
return new() { [BflResearchTopic.PARTICIPANTS] = list };
|
||||
}
|
||||
|
||||
private static Dictionary<BflStep, BflStepFormData> Forms()
|
||||
{
|
||||
var forms = BflStep.All.ToDictionary(step => step, _ => new BflStepFormData());
|
||||
forms[BflStep.FRAMEWORK].Set(BflFieldCatalog.FORMAT, "Podium");
|
||||
forms[BflStep.FRAMEWORK].Set(BflFieldCatalog.EVENT_TOPIC, "Klimapolitik");
|
||||
return forms;
|
||||
}
|
||||
}
|
||||
@@ -213,6 +213,46 @@ public sealed class BflStalenessTests
|
||||
Assert.That(BflStaleness.FingerprintOf(first), Is.EqualTo(BflStaleness.FingerprintOf(second)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WithGenericCounterpartsTheFingerprintStaysAsItWasBeforeTheSimulation()
|
||||
{
|
||||
var withoutSimulation = new BflStepFormData();
|
||||
withoutSimulation.Set(BflFieldCatalog.TEST_NOTES, "Text");
|
||||
var generic = new BflStepFormData { Simulation = new() { Mode = BflSimulationMode.GENERIC, People = ["Eva Klein"] } };
|
||||
generic.Set(BflFieldCatalog.TEST_NOTES, "Text");
|
||||
|
||||
// How the lab computed the fingerprint of this form before it simulated people:
|
||||
var before = Convert.ToHexStringLower(SHA256.HashData(Encoding.UTF8.GetBytes($"{BflFieldCatalog.TEST_NOTES}\0Text\0")));
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(BflStaleness.FingerprintOf(withoutSimulation), Is.EqualTo(before));
|
||||
Assert.That(BflStaleness.FingerprintOf(generic), Is.EqualTo(before));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheFingerprintCountsTheModeAndThePeopleOfTheSimulation()
|
||||
{
|
||||
var empty = new BflStepFormData();
|
||||
var single = new BflStepFormData { Simulation = new() { Mode = BflSimulationMode.SINGLE_PERSON, People = ["Eva Klein"] } };
|
||||
var panel = new BflStepFormData { Simulation = new() { Mode = BflSimulationMode.PANEL_DISCUSSION, People = ["Eva Klein"] } };
|
||||
var otherPerson = new BflStepFormData { Simulation = new() { Mode = BflSimulationMode.SINGLE_PERSON, People = ["Frank Ott"] } };
|
||||
|
||||
var fingerprints = new[] { empty, single, panel, otherPerson }.Select(BflStaleness.FingerprintOf).ToList();
|
||||
|
||||
Assert.That(fingerprints, Is.Unique);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheOrderAndTheSpellingOfTheSimulatedPeopleIsNoChange()
|
||||
{
|
||||
var first = new BflStepFormData { Simulation = new() { Mode = BflSimulationMode.PANEL_DISCUSSION, People = ["Eva Klein", "Frank Ott"] } };
|
||||
var second = new BflStepFormData { Simulation = new() { Mode = BflSimulationMode.PANEL_DISCUSSION, People = ["frank ott", "Eva Klein"] } };
|
||||
|
||||
Assert.That(BflStaleness.FingerprintOf(first), Is.EqualTo(BflStaleness.FingerprintOf(second)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AChangedCardSortWeighsLikeChangedDetails()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user