mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-18 09:30:45 +00:00
Added simulated participants to the BeyondFacts Lab (#1208)
This commit is contained in:
1 parent
92d0ff68f4
commit
ef059ffd15
46 files changed
+1871
-71
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);
|
||||
|
||||
@@ -102,6 +102,13 @@ public sealed class BflPromptLibraryTests
|
||||
foreach (var step in BflStep.All)
|
||||
longestStep = Math.Max(longestStep, (await BflPromptLibrary.ReadAsync(BflPromptLibrary.StepPath(step))).Length);
|
||||
|
||||
// The step "Test situation" carries the simulation of people from the research as well:
|
||||
var longestSimulation = 0;
|
||||
foreach (var mode in BflSimulationMode.All)
|
||||
longestSimulation = Math.Max(longestSimulation, (await BflPromptLibrary.LoadPartsAsync(BflStep.TEST_SITUATION, AddressForm.FORMAL, simulation: mode)).Simulation.Length);
|
||||
|
||||
longestStep = Math.Max(longestStep, (await BflPromptLibrary.ReadAsync(BflPromptLibrary.StepPath(BflStep.TEST_SITUATION))).Length + longestSimulation + 2);
|
||||
|
||||
var longestAddress = 0;
|
||||
foreach (var addressForm in Enum.GetValues<AddressForm>())
|
||||
longestAddress = Math.Max(longestAddress, (await BflPromptLibrary.ReadAsync(BflPromptLibrary.AddressPath(addressForm))).Length);
|
||||
|
||||
@@ -179,6 +179,24 @@ public sealed class BflShareModelBuilderTests
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheSimulationAppearsWithItsModeAndTheNumberOfPeopleButNoNames()
|
||||
{
|
||||
var research = new BflPersonResearch { Name = "Eva Klein" };
|
||||
research.Set(BflPersonResearchStage.POSITIONS, new BflResearch { Text = "Positionen", CreatedAtUtc = NOW });
|
||||
var simulation = new BflEffectiveSimulation(BflSimulationMode.PANEL_DISCUSSION, [new BflSimulatedPerson(new() { Name = "Eva Klein" }, research)]);
|
||||
|
||||
var withPeople = Build(simulation: simulation);
|
||||
var generic = Build();
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(withPeople, Does.Contain($"- **Simulation in the test situation:** {BflSimulationMode.PANEL_DISCUSSION.Title} (1 simulated)\n"));
|
||||
Assert.That(withPeople, Does.Not.Contain("Eva Klein"));
|
||||
Assert.That(generic, Does.Contain($"- **Simulation in the test situation:** {BflSimulationMode.GENERIC.Title}\n"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EveryStepAppearsInItsOrder()
|
||||
{
|
||||
@@ -237,7 +255,7 @@ public sealed class BflShareModelBuilderTests
|
||||
Assert.That(Build(forms: forms, valueDeck: deck), Does.Not.Contain("Card sort"));
|
||||
}
|
||||
|
||||
private static string Build(Dictionary<BflStep, BflStepFormData>? forms = null, IReadOnlyDictionary<BflStep, BflWorkState>? workStates = null, IReadOnlyDictionary<BflResultKind, BflResult>? results = null, IReadOnlyDictionary<BflStep, IReadOnlyList<BflConversationMessage>>? conversations = null, IReadOnlyList<BflMaterial>? materials = null, IReadOnlyCollection<BflResearchTopic>? researchTopics = null, int researchedPeople = 0, bool includePersonalDisclosures = false, BflValueDeck? valueDeck = null) => BflShareModelBuilder.Build(new BflShareInput(
|
||||
private static string Build(Dictionary<BflStep, BflStepFormData>? forms = null, IReadOnlyDictionary<BflStep, BflWorkState>? workStates = null, IReadOnlyDictionary<BflResultKind, BflResult>? results = null, IReadOnlyDictionary<BflStep, IReadOnlyList<BflConversationMessage>>? conversations = null, IReadOnlyList<BflMaterial>? materials = null, IReadOnlyCollection<BflResearchTopic>? researchTopics = null, int researchedPeople = 0, bool includePersonalDisclosures = false, BflValueDeck? valueDeck = null, BflEffectiveSimulation? simulation = null) => BflShareModelBuilder.Build(new BflShareInput(
|
||||
forms ?? Forms(),
|
||||
workStates ?? new Dictionary<BflStep, BflWorkState>(),
|
||||
results ?? new Dictionary<BflResultKind, BflResult>(),
|
||||
@@ -249,7 +267,8 @@ public sealed class BflShareModelBuilderTests
|
||||
"26.11.2",
|
||||
NOW,
|
||||
CultureInfo.InvariantCulture,
|
||||
valueDeck));
|
||||
valueDeck,
|
||||
simulation));
|
||||
|
||||
private static Dictionary<BflStep, BflStepFormData> Forms() => BflStep.All.ToDictionary(step => step, _ => new BflStepFormData());
|
||||
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
using AIStudio.Assistants.BeyondFactsLab;
|
||||
using AIStudio.Settings;
|
||||
using AIStudio.Settings.DataModel;
|
||||
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
||||
namespace AIStudio.Tests.BeyondFactsLab;
|
||||
|
||||
/// <summary>
|
||||
/// Checks how the simulation the person chose reaches the prompt of the step "Test situation" of the BeyondFacts Lab.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public sealed class BflSimulationPromptTests
|
||||
{
|
||||
private const string SIMULATION_TEXT = "Regeln der Simulation";
|
||||
|
||||
private static readonly BflPromptParts PARTS = new("{{STEP}}\n---\n{{RESEARCH}}\n---\n{{DETAILS}}", "Leitfaden", "Schritt", "Anrede", string.Empty, SIMULATION_TEXT);
|
||||
|
||||
private static readonly DateTimeOffset CREATED_AT_UTC = new(2026, 11, 15, 10, 0, 0, TimeSpan.Zero);
|
||||
|
||||
private string dataDirectory = string.Empty;
|
||||
|
||||
[SetUp]
|
||||
public void CreateDataDirectory()
|
||||
{
|
||||
this.dataDirectory = Path.Combine(Path.GetTempPath(), $"ai-studio-beyondfacts-lab-simulation-{Guid.NewGuid():N}");
|
||||
Directory.CreateDirectory(this.dataDirectory);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void DeleteDataDirectory()
|
||||
{
|
||||
if (Directory.Exists(this.dataDirectory))
|
||||
Directory.Delete(this.dataDirectory, true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheLibraryReadsTheSimulationOnlyForTheTestSituationWithPeople()
|
||||
{
|
||||
var rules = await BflPromptLibrary.ReadAsync(BflPromptLibrary.PERSONA_PATH);
|
||||
var panel = await BflPromptLibrary.ReadAsync(BflPromptLibrary.SimulationPath(BflSimulationMode.PANEL_DISCUSSION));
|
||||
|
||||
var withPanel = await BflPromptLibrary.LoadPartsAsync(BflStep.TEST_SITUATION, AddressForm.FORMAL, simulation: BflSimulationMode.PANEL_DISCUSSION);
|
||||
var generic = await BflPromptLibrary.LoadPartsAsync(BflStep.TEST_SITUATION, AddressForm.FORMAL);
|
||||
var otherStep = await BflPromptLibrary.LoadPartsAsync(BflStep.STRATEGY, AddressForm.FORMAL, simulation: BflSimulationMode.PANEL_DISCUSSION);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(withPanel.Simulation, Is.EqualTo($"{rules.Trim()}\n\n{panel.Trim()}"));
|
||||
Assert.That(generic.Simulation, Is.Empty);
|
||||
Assert.That(otherStep.Simulation, Is.Empty);
|
||||
Assert.That(BflPromptLibrary.AllPaths, Does.Contain(BflPromptLibrary.PERSONA_PATH));
|
||||
Assert.That(BflPromptLibrary.AllPaths, Is.SupersetOf(BflSimulationMode.All.Where(mode => mode.HasPeople).Select(BflPromptLibrary.SimulationPath)));
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => BflPromptLibrary.SimulationPath(BflSimulationMode.GENERIC));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheTestSituationCarriesTheSimulationAndOnlyTheDossiersOfTheChosenPeople()
|
||||
{
|
||||
var forms = Forms();
|
||||
var candidates = Candidates(forms, ("Eva Klein", "Moderation; Universität Beispielstadt"), ("Frank Ott", "Podiumsgast"));
|
||||
var simulation = BflEffectiveSimulation.Of(new() { Mode = BflSimulationMode.SINGLE_PERSON, People = ["Eva Klein"] }, candidates);
|
||||
|
||||
var prompt = BflPromptComposer.Compose(PARTS, BflStep.TEST_SITUATION, forms, [], "Deutsch", simulation: simulation);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(prompt, Does.StartWith($"Schritt\n\n{SIMULATION_TEXT}\n---\n"));
|
||||
Assert.That(prompt, Does.Contain("<person name=\"Eva Klein\">\n<eintrag>\nModeration; Universität Beispielstadt\n</eintrag>\n"));
|
||||
Assert.That(prompt, Does.Contain($"<stufe titel=\"{BflPersonResearchStage.POSITIONS.Title}\" stand=\"2026-11-15\">\nText {BflPersonResearchStage.POSITIONS}\n</stufe>"));
|
||||
Assert.That(prompt, Does.Not.Contain("Frank Ott"), "A candidate whom the person did not choose stays out.");
|
||||
Assert.That(prompt, Does.Contain($"- Simulation: {BflSimulationMode.SINGLE_PERSON.Title}; gewählt: Eva Klein"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnEmptyEntryInTheListSaysSo()
|
||||
{
|
||||
var forms = Forms();
|
||||
var simulation = BflEffectiveSimulation.Of(new() { Mode = BflSimulationMode.SINGLE_PERSON, People = ["Eva Klein"] }, Candidates(forms, ("Eva Klein", " ")));
|
||||
|
||||
var prompt = BflPromptComposer.Compose(PARTS, BflStep.TEST_SITUATION, forms, [], "Deutsch", simulation: simulation);
|
||||
|
||||
Assert.That(prompt, Does.Contain("<eintrag>\nDie Liste nennt nur den Namen.\n</eintrag>"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenericCounterpartsCarryNoSimulationAndNoDossier()
|
||||
{
|
||||
var forms = Forms();
|
||||
Candidates(forms, ("Eva Klein", "Podiumsgast"));
|
||||
|
||||
var prompt = BflPromptComposer.Compose(PARTS, BflStep.TEST_SITUATION, forms, [], "Deutsch", simulation: BflEffectiveSimulation.GENERIC);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(prompt, Does.StartWith("Schritt\n---\n"));
|
||||
Assert.That(prompt, Does.Not.Contain(SIMULATION_TEXT));
|
||||
Assert.That(prompt, Does.Contain("Die Recherche nutzt der Schritt „Strategie“."));
|
||||
Assert.That(prompt, Does.Not.Contain("- Simulation:"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EveryOtherStepIgnoresTheSimulation()
|
||||
{
|
||||
var forms = Forms();
|
||||
var simulation = BflEffectiveSimulation.Of(new() { Mode = BflSimulationMode.SINGLE_PERSON, People = ["Eva Klein"] }, Candidates(forms, ("Eva Klein", "Podiumsgast")));
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
foreach (var step in BflStep.All.Where(step => step is not BflStep.TEST_SITUATION))
|
||||
{
|
||||
var prompt = BflPromptComposer.Compose(PARTS, step, forms, [], "Deutsch", simulation: simulation);
|
||||
Assert.That(prompt, Does.Not.Contain(SIMULATION_TEXT), step.ToString());
|
||||
Assert.That(prompt, Does.Not.Contain("Eva Klein"), step.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ThePromptOfASimulationMarksItAndForbidsMadeUpQuotes()
|
||||
{
|
||||
var forms = Forms();
|
||||
var simulation = BflEffectiveSimulation.Of(new() { Mode = BflSimulationMode.PRESS_CONFERENCE, People = ["Eva Klein"] }, Candidates(forms, ("Eva Klein", "Podiumsgast")));
|
||||
var parts = await BflPromptLibrary.LoadPartsAsync(BflStep.TEST_SITUATION, AddressForm.FORMAL, simulation: simulation.Mode);
|
||||
|
||||
var prompt = BflPromptComposer.Compose(parts, BflStep.TEST_SITUATION, forms, [], "Deutsch", simulation: simulation);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(prompt, Does.Contain("### Simulation recherchierter Personen"));
|
||||
Assert.That(prompt, Does.Contain("### Pressekonferenz"));
|
||||
Assert.That(prompt, Does.Contain("(Simulation):**"));
|
||||
Assert.That(prompt, Does.Contain("(Simulation, keine reale Person):**"));
|
||||
Assert.That(prompt, Does.Contain("Erfinde keine Zitate."));
|
||||
Assert.That(prompt, Does.Contain("„Pause“"));
|
||||
Assert.That(prompt, Does.Contain("<person name=\"Eva Klein\">"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ThePromptOfTheTestSituationTellsHowTheButtonEndsAnExercise()
|
||||
{
|
||||
var step = (await BflPromptLibrary.ReadAsync(BflPromptLibrary.StepPath(BflStep.TEST_SITUATION))).ReplaceLineEndings("\n");
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(step, Does.Contain("\n### Übung beenden\n"));
|
||||
Assert.That(step, Does.Contain("folge dann „Nach einer Übung“"));
|
||||
Assert.That(step, Does.Contain("\n### Nach einer Übung\n"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheServiceLoadsWhomOnlyTheTestSituationPlays()
|
||||
{
|
||||
var store = new BeyondFactsLabStore(NullLogger<BeyondFactsLabStore>.Instance, new BflStorageOptions { DataDirectory = this.dataDirectory });
|
||||
var service = new BflConversationService(store, null!, new SettingsManager(NullLogger<SettingsManager>.Instance, null!), null!, null!, NullLogger<BflConversationService>.Instance);
|
||||
var created = await store.CreateAsync("Panel");
|
||||
var forms = Forms();
|
||||
await store.SaveFormAsync(created.ProjectId, BflStep.FRAMEWORK, forms[BflStep.FRAMEWORK]);
|
||||
await store.SaveFormAsync(created.ProjectId, BflStep.TEST_SITUATION, new BflStepFormData { Simulation = new() { Mode = BflSimulationMode.PANEL_DISCUSSION, People = ["Frank Ott", "Eva Klein"] } });
|
||||
await store.SaveResearchAsync(created.ProjectId, BflResearchTopic.PARTICIPANTS, Participants(forms, ("Eva Klein", "Moderation"), ("Frank Ott", "Podiumsgast")));
|
||||
await store.SavePersonResearchAsync(created.ProjectId, Person(forms, "Eva Klein"));
|
||||
await store.SavePersonResearchAsync(created.ProjectId, Person(forms, "Frank Ott"));
|
||||
|
||||
var storedForms = await store.LoadFormsAsync(created.ProjectId);
|
||||
var testSituation = await service.LoadSimulationAsync(new(created.ProjectId, BflStep.TEST_SITUATION), storedForms);
|
||||
var strategy = await service.LoadSimulationAsync(new(created.ProjectId, BflStep.STRATEGY), storedForms);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(testSituation.Mode, Is.EqualTo(BflSimulationMode.PANEL_DISCUSSION));
|
||||
Assert.That(testSituation.People.Select(person => person.Name), Is.EqualTo(new[] { "Eva Klein", "Frank Ott" }));
|
||||
Assert.That(testSituation.People[0].Participant.Entry, Is.EqualTo("Moderation"));
|
||||
Assert.That(strategy, Is.SameAs(BflEffectiveSimulation.GENERIC));
|
||||
}
|
||||
}
|
||||
|
||||
private static List<BflSimulatedPerson> Candidates(IReadOnlyDictionary<BflStep, BflStepFormData> forms, params (string Name, string Entry)[] people)
|
||||
{
|
||||
var topics = new Dictionary<BflResearchTopic, BflResearch> { [BflResearchTopic.PARTICIPANTS] = Participants(forms, people) };
|
||||
return [.. BflSimulationCandidates.Of(forms, topics, [.. people.Select(person => Person(forms, person.Name))])];
|
||||
}
|
||||
|
||||
private static BflResearch Participants(IReadOnlyDictionary<BflStep, BflStepFormData> forms, params (string Name, string Entry)[] people)
|
||||
{
|
||||
var list = BflResearch.Of(string.Join("\n\n", people.Select(person => $"### {person.Name}\n{person.Entry}")), [], [], BflPromptComposer.PublicDetailsOf(forms), CREATED_AT_UTC);
|
||||
list.Participants = [.. BflParticipant.ListIn(list.Text)];
|
||||
return list;
|
||||
}
|
||||
|
||||
private static BflPersonResearch Person(IReadOnlyDictionary<BflStep, BflStepFormData> forms, string name)
|
||||
{
|
||||
var person = new BflPersonResearch { Name = name };
|
||||
foreach (var stage in BflPersonResearchStage.All)
|
||||
person.Set(stage, BflResearch.Of($"Text {stage}", [], [], BflPromptComposer.PublicDetailsOf(forms), CREATED_AT_UTC));
|
||||
|
||||
return person;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
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 research = new BflPersonResearch { Name = "Eva Klein" };
|
||||
research.Set(BflPersonResearchStage.PROFILE, new BflResearch { Text = new string('a', 3_000), CreatedAtUtc = CREATED_AT_UTC });
|
||||
research.Set(BflPersonResearchStage.POSITIONS, new BflResearch { Text = $" {new string('b', 3_999)}\n", CreatedAtUtc = CREATED_AT_UTC });
|
||||
var person = new BflSimulatedPerson(new() { Name = "Eva Klein", Entry = $" {new string('c', 1_000)} " }, research);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(BflSimulationBudget.DossierTokens([person]), Is.EqualTo(2_000), "The entry in the list goes into the prompt as well.");
|
||||
Assert.That(BflSimulationBudget.RequiredTokens([person]), Is.EqualTo(BflModelRequirements.MINIMUM_CONTEXT_TOKENS + 2_000));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AKnownWindowWhichIsTooSmallRefusesAndAnUnknownOneWarns()
|
||||
{
|
||||
var research = new BflPersonResearch { Name = "Eva Klein" };
|
||||
research.Set(BflPersonResearchStage.POSITIONS, new BflResearch { Text = new string('a', 40_000), CreatedAtUtc = CREATED_AT_UTC });
|
||||
var person = new BflSimulatedPerson(new() { Name = "Eva Klein" }, research);
|
||||
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<BflSimulatedPerson> 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