PlotDirector/PlotLine.Tests/ContextRelationshipLensTests.cs

23 lines
5.2 KiB
C#

using PlotLine.Data;using PlotLine.Models;using PlotLine.Services;using PlotLine.Services.Context;using PlotLine.ViewModels;
internal static class ContextRelationshipLensTests
{
public static async Task Run(){void Check(bool p,string m){if(!p)throw new Exception(m);Console.WriteLine("PASS Context visual lenses: "+m);}
var scene=new SceneEditViewModel{SceneID=22,ChapterID=10,SceneTitle="Current point",POVCharacterID=5,SceneCharacters=[new(){CharacterID=5,PresenceTypeName="Present"},new(){CharacterID=7,PresenceTypeName="Present",RoleInSceneTypeName="Mentioned Only"}]};
var data=new RelationshipMapData{Books=[new(){BookID=12,SortOrder=1}],Chapters=[new(){ChapterID=10,BookID=12,SortOrder=1}],Scenes=[new(){SceneID=90,ChapterID=10,SceneNumber=1},new(){SceneID=22,ChapterID=10,SceneNumber=2},new(){SceneID=2,ChapterID=10,SceneNumber=3}],Characters=[new(){CharacterID=5,ProjectID=7,CharacterName="Focus",IsDeceased=true,BirthDate=new(1950,1,1)},new(){CharacterID=6,ProjectID=7,CharacterName="Archived relative",IsArchived=true},new(){CharacterID=7,ProjectID=7,CharacterName="Mentioned identity"}],Relationships=[new(){CharacterRelationshipID=9,ProjectID=7,CharacterAID=5,CharacterBID=6,RelationshipTypeName="Parent",RelationshipCategoryName="Family",IsInitialRelationship=true,InitialRelationshipStateName="Before"},new(){CharacterRelationshipID=10,ProjectID=7,CharacterAID=5,CharacterBID=7,RelationshipTypeName="Acquaintance",RelationshipCategoryName="Professional / Social",IsInitialRelationship=true,InitialRelationshipStateName="Known of"},new(){CharacterRelationshipID=11,ProjectID=7,CharacterAID=6,CharacterBID=7,RelationshipTypeName="Child",RelationshipCategoryName="Family",StartSceneID=2}],RelationshipEvents=[new(){RelationshipEventID=1,CharacterRelationshipID=9,SceneID=22,RelationshipStateName="Now",Description="Recorded present change"},new(){RelationshipEventID=2,CharacterRelationshipID=9,SceneID=2,RelationshipStateName="Later",Description="Future evidence"}]};
var read=new ContextLensRead(data,5,false);var story=ContextRelationshipLenses.Compose(read,"story",scene,true);
Check(story.Links.Single(r=>r.ID==9).State=="Now"&&!story.Links.Any(r=>r.ID==11),"Story uses canonical scene order and excludes future-start relationships");
Check(story.Links.Single(r=>r.ID==9).Recent.All(e=>e.SceneID!=2)&&story.Links.Single(r=>r.ID==9).Notes=="Recorded present change","future events cannot leak into current details or recent changes");
Check(!story.Nodes.Single(n=>n.ID==7).Physical&&story.Nodes.Single(n=>n.ID==5).Physical,"mentioned-only role overrides a contradictory physical presence label");
var family=ContextRelationshipLenses.Compose(read,"family",scene,false);Check(family.Links.Any(r=>r.ID==11)&&family.Nodes.Any(n=>n.ID==6&&n.Archived)&&!family.CanEdit,"Family author truth retains recorded future structure and archived identities, explicitly outside POV knowledge");
Check(family.Links.All(r=>r.Category=="Family")&&ContextRelationshipLenses.Family("Romantic / Sexual","Spouse")&&!ContextRelationshipLenses.Family("Professional / Social","Partner"),"family spouse semantics do not turn professional partners into kinship");
Check(story.Links.Single(r=>r.ID==10).State=="Known of"&&!story.Links.Single(r=>r.ID==9).Reciprocal,"explicit states and directional connections are preserved without inferred meeting or symmetry");
Check(family.Nodes.Single(n=>n.ID==5).IsDeceased==true&&family.Nodes.Single(n=>n.ID==6).IsDeceased==null&&story.Nodes.All(n=>n.IsDeceased==null),"canonical death status is Family author reference only; archival does not imply death and Story cannot leak a global future death");
int[]? observedPhysical=null;bool? narrative=null;var role="Viewer";
var reader=NativeWorkflowTests.Proxy<IContextRelationshipReader>((n,a)=>{observedPhysical=((IReadOnlyList<int>)a![6]!).ToArray();return Task.FromResult(read);});
var lens=new ContextRelationshipLenses(reader,NativeWorkflowTests.Proxy<ICharacterRepository>((n,a)=>Task.FromResult<Character?>(new(){CharacterID=(int)a![0]!,ProjectID=(int)a[0]! ==99?8:7})),NativeWorkflowTests.Proxy<IWordCompanionRepository>((n,a)=>Task.FromResult<WordCompanionBookStructureResponse?>((int)a![0]! ==12?new(){BookId=12,Chapters=[new(){ChapterId=10,Scenes=[new(){SceneId=22}]}]}:null)),NativeWorkflowTests.Proxy<IBookRepository>((_,_)=>Task.FromResult<Book?>(new(){BookID=12,ProjectID=7})),NativeWorkflowTests.Proxy<IProjectRepository>((_,_)=>Task.FromResult<Project?>(new(){ProjectID=7,AccessRole=role})),NativeWorkflowTests.Proxy<ICurrentUserService>((_,_)=>4),NativeWorkflowTests.Proxy<IStoryContextService>((n,a)=>{narrative=(bool)a![4]!;return Task.FromResult<StoryContextViewModel?>(new(){Position=new(7,12,10,22),Scene=scene});}));
var actual=await lens.Graph(12,22,"story",null,3);Check(observedPhysical!.SequenceEqual([5])&&narrative==false&&!actual.CanEdit,"visual reads use bounded reader and thin scene context without loading narrative histories; viewers remain read-only");
try{await lens.Graph(12,22,"family",99,3);throw new Exception("foreign focus accepted");}catch(UnauthorizedAccessException){Check(true,"cross-project focus rejected before graph read");}
try{await lens.Graph(12,999,"family",5,3);throw new Exception("foreign scene accepted");}catch(UnauthorizedAccessException){Check(true,"cross-book scene rejected");}
}
}