using PlotLine.Models; using PlotLine.Services; internal static class PlotLineWorkspaceTests { public static void FocusWeaveGapsAndSharedScenes() { var data = Fixture(); var focus = PlotLineWorkspaceComposer.Compose(data, [1]); Check(focus.Count == 2, "Focus mode should contain the selected line's two scenes."); Check(focus[1].GapBefore == 4, "Dormancy should report the four intervening narrative scenes."); Check(focus[1].ChapterGapBefore == 2, "Chapter dormancy should report whole intervening chapters."); var weave = PlotLineWorkspaceComposer.Compose(data, [1, 2]); Check(weave.Count == 2, "Weave mode should render a shared scene once, not once per line."); Check(weave[0].IsShared && weave[0].Memberships.Count == 2, "A shared scene should retain both line memberships."); Check(weave[0].Memberships.SelectMany(x => x.Contributions).Any(x => x.CanonicalTitle == "Canonical event" && x.CandidateTitle == "Supporting imported detail"), "Imported supporting detail must enrich rather than replace the canonical event."); } public static void ThreadFilteringAndInspectorContracts() { var data = Fixture(); var filtered = PlotLineWorkspaceComposer.Compose(data, [1, 2], [12]); Check(filtered.Count == 1 && filtered[0].SceneID == 101, "Thread filtering should retain only contributions from selected threads."); Check(filtered[0].Memberships.Single().PlotLineID == 2, "Thread filtering must not leak another line's events."); var root = RepositoryRoot(); var timeline = File.ReadAllText(Path.Combine(root, "PlotLine/Views/Timeline/Index.cshtml")); var settings = File.ReadAllText(Path.Combine(root, "PlotLine/Views/Timeline/Settings.cshtml")); var characterEditor = File.ReadAllText(Path.Combine(root, "PlotLine/Views/Shared/SceneInspectorV2/_SceneCharactersEditor.cshtml")); var controller = File.ReadAllText(Path.Combine(root, "PlotLine/Controllers/ScenesController.cs")); var sql = File.ReadAllText(Path.Combine(root, "PlotLine/Sql/204_PlotLineWorkspaceV1.sql")); Check(!timeline.Contains("character-lane-board", StringComparison.Ordinal), "Timeline must not render Character lane presentation."); Check(!settings.Contains("ShowCharacterAppearances", StringComparison.Ordinal), "Timeline settings must not offer Character lanes."); Check(characterEditor.Contains("Knowledge notes", StringComparison.Ordinal) && controller.Contains("KnowledgeNotes = row.KnowledgeNotes", StringComparison.Ordinal), "Scene Inspector must expose and save character knowledge notes."); Check(sql.Contains("cm.NarrativeCandidateID = te.SourceReferenceID AND cm.SceneID = te.SceneID", StringComparison.Ordinal), "Imported event enrichment must require SourceReferenceID and SceneID."); Check(sql.Contains("nc.Status = N'Pending'", StringComparison.Ordinal), "Suggestions must be restricted to pending candidates."); } public static void GeneratedScale() { const int lineCount = 40; const int sceneCount = 1200; var lines = Enumerable.Range(1, lineCount).Select(id => new PlotLineWorkspaceLineRow { PlotLineID = id, PlotLineName = $"Generated line {id}", SortOrder = id }).ToList(); var contributions = new List(lineCount * 300); for (var lineId = 1; lineId <= lineCount; lineId++) { for (var index = 0; index < 300; index++) { var sceneId = 10_000 + ((index * 7 + lineId * 13) % sceneCount); contributions.Add(Contribution(lineId, lineId * 10, sceneId, sceneId - 9_999, 1 + (sceneId % 40), $"Event {lineId}-{index}", null)); } } var composed = PlotLineWorkspaceComposer.Compose(new PlotLineWorkspaceData { PlotLines = lines, Contributions = contributions }, lines.Select(x => x.PlotLineID).ToArray()); Check(composed.Count <= sceneCount, "Large weave must still render each scene at most once."); Check(composed.Select(x => x.SceneID).Distinct().Count() == composed.Count, "Large weave contains duplicate scene cards."); Check(composed.Zip(composed.Skip(1), (left, right) => left.NarrativeOrder <= right.NarrativeOrder).All(x => x), "Large weave lost narrative ordering."); } private static PlotLineWorkspaceData Fixture() => new() { PlotLines = [ new() { PlotLineID = 1, PlotLineName = "Line A", Colour = "#111111", SortOrder = 1 }, new() { PlotLineID = 2, PlotLineName = "Line B", Colour = "#222222", SortOrder = 2 } ], Contributions = [ Contribution(1, 11, 101, 2, 1, "Canonical event", "Supporting imported detail"), Contribution(2, 12, 101, 2, 1, "Other canonical event", null), Contribution(1, 11, 102, 7, 4, "Later event", null) ] }; private static PlotLineWorkspaceContributionRow Contribution( int lineId, int threadId, int sceneId, int order, decimal chapter, string canonicalTitle, string? candidateTitle) => new() { ThreadEventID = sceneId * 10 + lineId, PlotLineID = lineId, PlotThreadID = threadId, SceneID = sceneId, NarrativeOrder = order, ChapterNumber = chapter, ChapterTitle = $"Chapter {chapter}", SceneNumber = order, SceneTitle = $"Scene {sceneId}", CanonicalTitle = canonicalTitle, CandidateTitle = candidateTitle, ThreadTitle = $"Thread {threadId}", CanonicalRole = "Developed" }; private static string RepositoryRoot() { var directory = new DirectoryInfo(AppContext.BaseDirectory); while (directory is not null && !File.Exists(Path.Combine(directory.FullName, "PlotLine.slnx"))) directory = directory.Parent; return directory?.FullName ?? throw new InvalidOperationException("Repository root not found."); } private static void Check(bool condition, string message) { if (!condition) throw new InvalidOperationException(message); } }