Merge branch 'phase/46-speech-home'

Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	docs/phases/09-social/README.md
#	src/HSchool.Server/Game/SchoolWorker.cs
#	tests/HSchool.Ai.Tests/TalkCirclesTests.cs
#	tests/HSchool.Simulation.Tests/MorningOpinionsTests.cs
#	tests/HSchool.Simulation.Tests/TalkCircleTests.cs
This commit is contained in:
Leonid Pershin
2026-08-20 14:06:29 +03:00
35 changed files with 910 additions and 36 deletions
@@ -79,6 +79,47 @@ public class MorningOpinionsTests
Assert.False(child.Opinions.ContainsKey(classmate.Id));
}
[Fact]
public void SkipFridayToMonday_AppliesHomeEventAndDrift()
{
var fridayEvening = new DateTime(2012, 4, 6, 22, 0, 0, DateTimeKind.Utc);
using var school = OpenEmpty(fridayEvening);
var child = school.Roster!.People.First(person => person.IsStudent && !person.IsParent);
var classmate = school.Roster.People.First(person =>
person.IsStudent
&& !person.Id.Equals(child.Id, StringComparison.Ordinal)
&& !OpinionStore.FamilyMemberIds(school.Roster, child).Contains(person.Id));
var family = school.Roster.Families.Single(row => row.Id.Equals(child.FamilyId, StringComparison.Ordinal));
var parentId = family.ParentIds
.OrderBy(id => id, StringComparer.Ordinal)
.First(id => school.Roster.People.Any(person => person.Id.Equals(id, StringComparison.Ordinal)));
var rules = school.Catalog!.BehaviorRules!;
var parentStart = rules.OpinionChildToParentStart;
OpinionStore.Set(child, parentId, parentStart);
OpinionStore.Set(child, classmate.Id, 30);
Assert.True(school.TrySkipEmpty().Succeeded);
Assert.Equal(new DateTime(2012, 4, 9, 6, 0, 0, DateTimeKind.Utc), school.Clock.Time);
Assert.True(child.Opinions.TryGetValue(parentId, out var parentView));
Assert.NotEqual(parentStart, parentView);
Assert.True(child.Opinions.TryGetValue(classmate.Id, out var classmateView));
Assert.True(classmateView < 30);
Assert.True(classmateView <= 30 - rules.OpinionDriftPerMorning);
var schoolShift = school.Catalog.Topics.Values
.Where(topic => !topic.Abstract && topic.Tags.Contains(TopicTags.Family, StringComparer.Ordinal))
.Select(topic => Math.Abs(topic.OpinionShift))
.DefaultIfEmpty(2)
.Max();
Assert.True(Math.Abs(parentView - parentStart) < schoolShift);
Assert.Contains(
school.DayLog,
row => row.PersonId == child.Id && row.Type.Equals(PersonLogTypes.HomeTalk, StringComparison.Ordinal));
}
private static void AdvanceTo(School school, DateTime until)
{
while (school.Clock.Time < until)
@@ -173,6 +173,75 @@ public class TalkCircleTests
}
}
[Fact]
public void PendingStudyOnlyToday_DoesNotChangeCurrentGamesCircle()
{
var (school, first, second) = TwoPupilsOnBreak();
using (school)
{
OpinionStore.Set(first, second.Id, 55);
OpinionStore.Set(second, first.Id, 55);
PlaceAt(school, first.Id, "corridor-1");
PlaceAt(school, second.Id, "corridor-1");
Assert.True(school.TryStartAction(first.Id, TalkActions.Chat));
var live = school.TalkCirclesById.Values.Single();
live.TopicId = "TopicGames";
school.SpeechRules = school.SpeechRules.WithPending(SpeechPolicies.StudyOnly, null);
Assert.Equal(SpeechPolicies.Free, school.SpeechRules.Students);
TalkCircleSystem.Apply(school, 0.5d);
Assert.Equal("TopicGames", school.TalkCircleOf(first.Id)?.TopicId);
Assert.Equal(SpeechPolicies.StudyOnly, school.SpeechRules.PendingStudents);
}
}
[Fact]
public void AfterWorkMorning_NoRudePolicy_StudentsDoNotStartRudeTopic()
{
var (school, first, second) = TwoPupilsOnBreak();
using (school)
{
school.SpeechRules = school.SpeechRules.WithPending(SpeechPolicies.NoRude, null);
MorningDress.Apply(school);
Assert.Equal(SpeechPolicies.NoRude, school.SpeechRules.Students);
Assert.Null(school.SpeechRules.PendingStudents);
TalkCircleSystem.Interrupt(school, first.Id);
TalkCircleSystem.Interrupt(school, second.Id);
PlaceAt(school, first.Id, "corridor-1");
PlaceAt(school, second.Id, "corridor-1");
OpinionStore.Set(first, second.Id, 55);
OpinionStore.Set(second, first.Id, 55);
var started = 0;
var classmates = school.Roster!.Classes.First(row => row.RoomId == "classroom-101").PupilIds
.Select(id => school.Roster.People.First(person => person.Id == id))
.ToArray();
foreach (var initiator in classmates)
{
TalkCircleSystem.Interrupt(school, initiator.Id);
PlaceAt(school, initiator.Id, "corridor-1");
PlaceAt(school, first.Id, "corridor-1");
PlaceAt(school, second.Id, "corridor-1");
if (!school.TryStartAction(initiator.Id, TalkActions.Chat))
{
continue;
}
started++;
var circle = school.TalkCircleOf(initiator.Id);
Assert.NotNull(circle);
Assert.False(
school.Catalog!.Topics[circle.TopicId].Tags.Contains(TopicTags.Rude, StringComparer.Ordinal),
circle.TopicId);
TalkCircleSystem.Interrupt(school, initiator.Id);
}
Assert.True(started > 0);
}
}
private static (School School, Person First, Person Second) TwoPupilsWithPhonesOnBreak()
{
var (catalog, map) = Vanilla();