From 4eee8e1e70879ebc0288ed8e588b6de9135f2482 Mon Sep 17 00:00:00 2001 From: Nick Beckley Date: Wed, 4 Nov 2026 05:30:26 +0000 Subject: [PATCH] test: independently census every owned backup row --- .../2026-11-03-phase2-row-coverage.csv | 104 ++++++++++++++++++ Docs/Sprints/2026-11-03-phase2.md | 8 +- .../ProjectTransferDatabaseTests.cs | 11 ++ .../ProjectTransferOwnedRowCensus.cs | 94 ++++++++++++++++ 4 files changed, 216 insertions(+), 1 deletion(-) create mode 100644 Docs/Sprints/2026-11-03-phase2-row-coverage.csv create mode 100644 PlotLine.Tests/ProjectTransferOwnedRowCensus.cs diff --git a/Docs/Sprints/2026-11-03-phase2-row-coverage.csv b/Docs/Sprints/2026-11-03-phase2-row-coverage.csv new file mode 100644 index 00000000..aa237489 --- /dev/null +++ b/Docs/Sprints/2026-11-03-phase2-row-coverage.csv @@ -0,0 +1,104 @@ +Table,Collection,OwnedDatabaseRows,ExportedRows,ExtraSharedRows,MissingOwnedRows +WholeBookPlotSynthesisRuns,WholeBookPlotSynthesisRuns,2,2,0,0 +StoryIntelligenceNarrativeCandidates,StoryIntelligenceNarrativeCandidates,6,6,0,0 +StoryIntelligenceNarrativeCandidateEvidence,StoryIntelligenceNarrativeCandidateEvidence,6,6,0,0 +StoryIntelligenceNarrativeCandidateEvents,StoryIntelligenceNarrativeCandidateEvents,2,2,0,0 +CharacterEnrichmentRuns,CharacterEnrichmentRuns,2,2,0,0 +CharacterEnrichmentEvidence,CharacterEnrichmentEvidence,2,2,0,0 +StoryIntelligenceReviewCandidateGenerations,StoryIntelligenceReviewCandidateGenerations,5,5,0,0 +StoryIntelligenceReviewCandidates,StoryIntelligenceReviewCandidates,16,16,0,0 +StoryIntelligenceReviewCandidateEvidence,StoryIntelligenceReviewCandidateEvidence,16,16,0,0 +StoryIntelligenceBookPipelines,StoryIntelligenceBookPipelines,1,1,0,0 +StoryMemoryCharacters,StoryMemoryCharacters,1,1,0,0 +StoryMemoryCharacterAliases,StoryMemoryCharacterAliases,1,1,0,0 +StoryMemoryCharacterAttributes,StoryMemoryCharacterAttributes,1,1,0,0 +StoryMemoryLocations,StoryMemoryLocations,1,1,0,0 +StoryMemoryAssets,StoryMemoryAssets,1,1,0,0 +StoryMemoryRelationships,StoryMemoryRelationships,2,2,0,0 +StoryMemoryProcessedSceneResults,StoryMemoryProcessedSceneResults,1,1,0,0 +StoryMemoryImportPreferences,StoryMemoryImportPreferences,1,1,0,0 +CharacterIntelligenceProfiles,CharacterIntelligenceProfiles,1,1,0,0 +CharacterIntelligenceEvidenceEvents,CharacterIntelligenceEvidenceEvents,1,1,0,0 +StoryIntelligenceRuns,StoryIntelligenceRuns,1,1,0,0 +StoryIntelligenceChapterResults,StoryIntelligenceChapterResults,1,1,0,0 +StoryIntelligenceSceneResults,StoryIntelligenceSceneResults,1,1,0,0 +StoryIntelligenceImportCommits,StoryIntelligenceImportCommits,1,1,0,0 +CoreImportBasicLocationReviews,CoreImportBasicLocationReviews,1,1,0,0 +CoreImportBasicLocationCandidates,CoreImportBasicLocationCandidates,1,1,0,0 +CoreImportBasicLocationEvidence,CoreImportBasicLocationEvidence,1,1,0,0 +SceneAssetSuggestions,SceneAssetSuggestions,4,4,0,0 +SceneCharacterSuggestions,SceneCharacterSuggestions,4,4,0,0 +SceneLocationSuggestions,SceneLocationSuggestions,4,4,0,0 +SceneTextStatistics,SceneTextStatistics,1,1,0,0 +OnboardingManuscriptBuilds,OnboardingManuscriptBuilds,1,1,0,0 +OnboardingManuscriptBuildChapterMap,OnboardingManuscriptBuildChapterMap,1,1,0,0 +OnboardingManuscriptBuildSceneMap,OnboardingManuscriptBuildSceneMap,2,2,0,0 +OnboardingManuscriptBuildCharacterMap,OnboardingManuscriptBuildCharacterMap,1,1,0,0 +CharacterImages,CharacterImages,2,2,0,0 +WordCompanionSceneAssets,WordCompanionSceneAssets,1,1,0,0 +WordCompanionSceneLocations,WordCompanionSceneLocations,1,1,0,0 +ManuscriptDocuments,ManuscriptDocuments,1,1,0,0 +SceneManuscriptSources,SceneManuscriptSources,1,1,0,0 +ManuscriptStructuralChapterSources,ManuscriptStructuralChapterSources,1,1,0,0 +WritingPlans,WritingPlans,1,1,0,0 +WritingScheduleItems,WritingScheduleItems,1,1,0,0 +CharacterAliases,CharacterAliases,1,1,0,0 +AssetAliases,AssetAliases,1,1,0,0 +LocationAliases,LocationAliases,1,1,0,0 +AuthorPlotSeeds,AuthorPlotSeeds,1,1,0,0 +ContinuityWarningAcknowledgements,ContinuityWarningAcknowledgements,1,1,0,0 +PlotEventTargetPlotLines,PlotEventTargetPlotLines,1,1,0,0 +MapReferenceImages,MapReferenceImages,1,1,0,0 +MapJourneyNotes,MapJourneyNotes,1,1,0,0 +StoryMaps,StoryMaps,2,2,0,0 +MapFeatures,MapFeatures,2,2,0,0 +MapRelationships,MapRelationships,1,1,0,0 +Books,Books,1,1,0,0 +Chapters,Chapters,1,1,0,0 +Scenes,Scenes,2,2,0,0 +ScenePurposes,ScenePurposes,1,1,0,0 +SceneOutcomes,SceneOutcomes,1,1,0,0 +SceneMetricTypes,SceneMetricTypes,1,1,0,0 +SceneMetricValues,SceneMetricValues,1,1,0,0 +ProjectTimelineSettings,TimelineSettings,1,1,0,0 +ProjectTimelineMetricSettings,TimelineMetricSettings,1,1,0,0 +TimelineViewPresets,TimelineViewPresets,1,1,0,0 +PlotLines,PlotLines,2,2,0,0 +PlotThreads,PlotThreads,1,1,0,0 +ThreadEvents,ThreadEvents,3,3,0,0 +StoryAssets,StoryAssets,2,2,0,0 +AssetStates,AssetStates,1,2,1,0 +AssetEvents,AssetEvents,1,1,0,0 +AssetDependencies,AssetDependencies,1,1,0,0 +AssetCustodyEvents,AssetCustodyEvents,1,1,0,0 +AssetCustodyEventCharacters,AssetCustodyCharacters,1,1,0,0 +Characters,Characters,2,2,0,0 +SceneCharacters,SceneCharacters,1,1,0,0 +CharacterAttributeTypes,CharacterAttributeTypes,1,1,0,0 +CharacterAttributeEvents,CharacterAttributeEvents,1,1,0,0 +CharacterKnowledge,CharacterKnowledge,1,1,0,0 +CharacterRelationships,CharacterRelationships,1,1,0,0 +RelationshipEvents,RelationshipEvents,1,1,0,0 +Locations,Locations,2,2,0,0 +LocationRelationships,LocationRelationships,1,1,0,0 +FloorPlans,FloorPlans,1,1,0,0 +FloorPlanFloors,FloorPlanFloors,1,1,0,0 +FloorPlanBlocks,FloorPlanBlocks,1,1,0,0 +FloorPlanTransitions,FloorPlanTransitions,1,1,0,0 +SceneAssetLocations,SceneAssetLocations,1,1,0,0 +SceneFloorPlanOccupancy,SceneFloorPlanOccupancy,1,1,0,0 +SceneDependencies,SceneDependencies,1,1,0,0 +ValidationRuns,ValidationRuns,1,1,0,0 +ContinuityWarnings,ContinuityWarnings,1,1,0,0 +SceneNotes,SceneNotes,1,1,0,0 +SceneWorkflow,SceneWorkflow,1,1,0,0 +SceneChecklistItems,SceneChecklistItems,1,1,0,0 +SceneAttachments,SceneAttachments,2,2,0,0 +ChapterGoals,ChapterGoals,1,1,0,0 +Scenarios,Scenarios,1,1,0,0 +ScenarioSceneOrder,ScenarioSceneOrder,1,1,0,0 +ScenarioValidationRuns,ScenarioValidationRuns,1,1,0,0 +ScenarioWarnings,ScenarioWarnings,1,1,0,0 +ProjectUserAccess,ProjectAccess,1,1,0,0 +UserFile,UserFiles,1,1,0,0 +Projects,Project,1,1,0,0 diff --git a/Docs/Sprints/2026-11-03-phase2.md b/Docs/Sprints/2026-11-03-phase2.md index e19e1700..3d6f214a 100644 --- a/Docs/Sprints/2026-11-03-phase2.md +++ b/Docs/Sprints/2026-11-03-phase2.md @@ -17,7 +17,7 @@ 3. DEFERRED ACCEPTANCE: authenticated live Writer/PWA testing; no session is available. Real full-layout browser/Hub fixture results are recorded separately. 4. DEFERRED DEPLOYMENT: two illustration records were Generating at restart preflight. No interruption authorised; expanded gate b523a86 refuses restart. Recheck only at the next meaningful deployment checkpoint. 5. COMPLETE CHECKPOINT: serialized backup/restore coverage now has 104 collections (100 persistent plus 4 diagnostic/shared vocabulary), 105 SQL entities / 1,342 columns with no missing non-computed model properties. All 100 persistent collections have populated stored-value copy/in-place comparisons; 12 uploaded files and embedded map image bytes are verified. Commits f12ad43, dbb2e2d, 6ae3715, 571f670, 28397ff. -6. CURRENT: illustration catalogue/provenance/files and final ownership-scope row census. Narrative synthesis and enrichment evidence now pass. Operational account reference preservation now passes. HTTP JSON transport repair, 40 packet/format cases, legacy JSON, Word structure API and Core Import SQL/source/provenance workflows passed. Retained SI analysis audit now passes isolated stored-value copy/in-place tests. +6. CURRENT: illustration catalogue/provenance/files. Independent ownership-scope row census passed. Narrative synthesis and enrichment evidence now pass. Operational account reference preservation now passes. HTTP JSON transport repair, 40 packet/format cases, legacy JSON, Word structure API and Core Import SQL/source/provenance workflows passed. Retained SI analysis audit now passes isolated stored-value copy/in-place tests. 7. PENDING: remaining persistent table classification and historical fixture discovery. Unrepresented SI review/audit/provenance is persistent under its runtime contract, not an expendable cache; project-derived illustration catalogue/files also remain outside verified backup coverage. Do not claim a complete 167-table audit. 8. PENDING: finish independently safe data gaps and meaningful format round trips; record concrete limits/deferred work. No historical compatibility claim without actual fixtures. 9. PENDING: final serial build/harness and focused browser/integration checks; meaningful restart-gate recheck, safe Development deployment if idle, concise handover. @@ -312,3 +312,9 @@ Production narrative readers returned all six candidate states/records, six evid Final indexed real SQL matrix passed all 100 populated persistent collections (104 serialized collections): source 2,427 stored values across 103 populated entities; copy 2,301 generic comparisons plus explicit review/provenance assertions; in-place 2,391. Invalid preview count 47. Field census 105 entities / 1,342 columns / zero missing non-computed model properties (one computed synthesis key intentionally omitted from the DTO). Build zero warnings/errors. Evidence `/tmp/plotdirector-phase2-narrative-before.log`, `narrative-after.log` (comparison-harness semantic mapping gap), `narrative-guards.log`, `narrative-index.log` (final pass), `build-narrative-index.log`, `census-narrative.log` (all `/tmp/plotdirector-phase2-` prefix). Remaining feature scope: illustration catalogue/provenance/files; final independent owned-row census still pending. No Development writes/deployment. Narrative checkpoint: full 405-check regression harness passed, exit 0 (`/tmp/plotdirector-phase2-tests-narrative.log`). Migration 228 remains synthetic-only; no Production or Development schema/data writes. + +## Independent owned-row census — 4 November + +Added a census independent of the backup selectors and DTO graph descriptor. Actual database foreign keys, composite primary keys, non-null ProjectID anchors and the documented legacy BookID soft reference determine the owned rows. The check rejects omitted owned rows, duplicate primary keys and foreign rows; explicitly shared vocabulary is checked separately. Per-table counts are in `2026-11-03-phase2-row-coverage.csv`. + +Final real SQL run passed all 173 owned rows across 103 scoped entities, plus the existing 100 populated persistent collection copy/in-place matrix. Negative probes omitted a deleted gallery record and an ignored narrative event; both were detected despite every remaining exported value being valid. Build zero warnings/errors. Evidence `/tmp/plotdirector-phase2-row-census-final.log` and `/tmp/plotdirector-phase2-build-row-census-final.log`. Full 405 checks last passed at narrative checkpoint; this group changes only the specialist test harness. The census covers advertised entities, not the still-unclassified illustration tables. diff --git a/PlotLine.Tests/ProjectTransferDatabaseTests.cs b/PlotLine.Tests/ProjectTransferDatabaseTests.cs index 3dfee013..aef354a3 100644 --- a/PlotLine.Tests/ProjectTransferDatabaseTests.cs +++ b/PlotLine.Tests/ProjectTransferDatabaseTests.cs @@ -166,6 +166,7 @@ internal static class ProjectTransferDatabaseTests foreach(var required in new[]{"SceneAssetSuggestions","SceneCharacterSuggestions","SceneLocationSuggestions","SceneTextStatistics","CoreImportBasicLocationReviews","CoreImportBasicLocationCandidates","CoreImportBasicLocationEvidence","StoryIntelligenceRuns","StoryIntelligenceChapterResults","StoryIntelligenceSceneResults","StoryIntelligenceImportCommits","StoryIntelligenceBookPipelines","StoryMemoryCharacters","StoryMemoryCharacterAliases","StoryMemoryCharacterAttributes","StoryMemoryLocations","StoryMemoryAssets","StoryMemoryRelationships","StoryMemoryProcessedSceneResults","StoryMemoryImportPreferences","CharacterIntelligenceProfiles","CharacterIntelligenceEvidenceEvents","StoryIntelligenceReviewCandidateGenerations","StoryIntelligenceReviewCandidates","StoryIntelligenceReviewCandidateEvidence","CharacterEnrichmentRuns","CharacterEnrichmentEvidence","WholeBookPlotSynthesisRuns","StoryIntelligenceNarrativeCandidates","StoryIntelligenceNarrativeCandidateEvidence","StoryIntelligenceNarrativeCandidateEvents"}) Check(encoded.RootElement.GetProperty("Data").TryGetProperty(required,out var rows) && rows.GetArrayLength()>0,"Backup must retain populated review/statistics set: "+required); await VerifyStoredProjectionAsync(db,before); + await ProjectTransferOwnedRowCensus.VerifyAsync(db,before); Check(before.Data.Books.Single().BookTitle=="Book Ω" && before.Data.Scenes.Single(x=>x.SceneTitle=="Scene café").Summary=="“Hello”—雪 🖋","Core Unicode export content."); if(coreOnly) { @@ -197,6 +198,16 @@ internal static class ProjectTransferDatabaseTests var service=new ImportService(repository,importUserService,subscription,NullLogger.Instance,assetFiles); var baselineProjectCount=await db.ExecuteScalarAsync("SELECT COUNT(*) FROM dbo.Projects"); var sourceJson=JsonSerializer.Serialize(before); + foreach(var probe in new[]{(Collection:"CharacterImages",Flag:"IsDeleted"),(Collection:"StoryIntelligenceNarrativeCandidateEvents",Flag:"IsIgnored")}) + { + var incomplete=System.Text.Json.Nodes.JsonNode.Parse(sourceJson)!; + var rows=incomplete["Data"]![probe.Collection]!.AsArray(); + rows.Remove(rows.Single(row=>row![probe.Flag]!.GetValue())); + var omittedDetected=false; + try { await ProjectTransferOwnedRowCensus.VerifyAsync(db,JsonSerializer.Deserialize(incomplete.ToJsonString())!,emit:false); } + catch(InvalidOperationException error) when(error.Message.StartsWith("Backup omits owned rows from "+probe.Collection,StringComparison.Ordinal)) { omittedDetected=true; } + Check(omittedDetected,"Independent row census must detect omitted tombstone/ignored rows: "+probe.Collection); + } var invalidPayloads=new List{"null","[]","42"}; foreach(var mutation in new Action[] { root=>root["Data"]=null, diff --git a/PlotLine.Tests/ProjectTransferOwnedRowCensus.cs b/PlotLine.Tests/ProjectTransferOwnedRowCensus.cs new file mode 100644 index 00000000..f0d25e11 --- /dev/null +++ b/PlotLine.Tests/ProjectTransferOwnedRowCensus.cs @@ -0,0 +1,94 @@ +using System.Globalization; +using System.Reflection; +using System.Text.Json; +using Dapper; +using Microsoft.Data.SqlClient; +using PlotLine.Models; + +internal static class ProjectTransferOwnedRowCensus +{ + private sealed class Column + { + public string TableName { get; init; }=""; + public string ColumnName { get; init; }=""; + public bool IsNullable { get; init; } + } + private sealed class ForeignPart + { + public int ConstraintID { get; init; } + public string ChildTable { get; init; }=""; + public string ParentTable { get; init; }=""; + public string ChildColumn { get; init; }=""; + public string ParentColumn { get; init; }=""; + } + private sealed class PrimaryPart + { + public string TableName { get; init; }=""; + public string ColumnName { get; init; }=""; + public int KeyOrdinal { get; init; } + } + private sealed record Link(string Parent,(string Child,string Parent)[] Columns); + private static void Check(bool condition,string message){if(!condition)throw new InvalidOperationException(message);} + private static string Quote(string name)=>"["+name.Replace("]","]]")+ "]"; + private static object? Read(object row,string column)=>row.GetType().GetProperty(column,BindingFlags.Public|BindingFlags.Instance|BindingFlags.IgnoreCase)!.GetValue(row); + private static string Key(IEnumerable values)=>JsonSerializer.Serialize(values.ToArray()); + + internal static async Task VerifyAsync(SqlConnection db,ProjectBackupExport backup,bool emit=true) + { + Check(await db.ExecuteScalarAsync("SELECT DB_NAME()") == "PlotDirector_Phase2_20261103_2305" + && await db.ExecuteScalarAsync("SELECT COUNT(*) FROM sys.extended_properties WHERE class=0 AND name=N'PlotDirector.Phase2.SyntheticOnly' AND CONVERT(nvarchar(20),value)=N'true'")==1,"Owned-row census requires the verified synthetic database."); + var columns=(await db.QueryAsync("SELECT t.name AS TableName,c.name AS ColumnName,c.is_nullable AS IsNullable FROM sys.tables t JOIN sys.schemas s ON s.schema_id=t.schema_id JOIN sys.columns c ON c.object_id=t.object_id WHERE s.name=N'dbo'")).GroupBy(row=>row.TableName).ToDictionary(group=>group.Key,group=>group.ToArray()); + var foreign=(await db.QueryAsync("SELECT fk.object_id AS ConstraintID,t.name AS ChildTable,rt.name AS ParentTable,c.name AS ChildColumn,rc.name AS ParentColumn FROM sys.foreign_keys fk JOIN sys.foreign_key_columns f ON f.constraint_object_id=fk.object_id JOIN sys.tables t ON t.object_id=f.parent_object_id JOIN sys.tables rt ON rt.object_id=f.referenced_object_id JOIN sys.columns c ON c.object_id=t.object_id AND c.column_id=f.parent_column_id JOIN sys.columns rc ON rc.object_id=rt.object_id AND rc.column_id=f.referenced_column_id WHERE SCHEMA_NAME(t.schema_id)=N'dbo' AND SCHEMA_NAME(rt.schema_id)=N'dbo'")).GroupBy(row=>row.ChildTable).ToDictionary(group=>group.Key,group=>group.GroupBy(row=>row.ConstraintID).Select(parts=>new Link(parts.First().ParentTable,parts.Select(part=>(part.ChildColumn,part.ParentColumn)).ToArray())).ToList()); + var primary=(await db.QueryAsync("SELECT t.name AS TableName,c.name AS ColumnName,ic.key_ordinal AS KeyOrdinal FROM sys.tables t JOIN sys.indexes i ON i.object_id=t.object_id AND i.is_primary_key=1 JOIN sys.index_columns ic ON ic.object_id=i.object_id AND ic.index_id=i.index_id JOIN sys.columns c ON c.object_id=t.object_id AND c.column_id=ic.column_id WHERE SCHEMA_NAME(t.schema_id)=N'dbo'")).GroupBy(row=>row.TableName).ToDictionary(group=>group.Key,group=>group.OrderBy(row=>row.KeyOrdinal).Select(row=>row.ColumnName).ToArray()); + var aliasNumber=0; + string? Scope(string table,string alias,HashSet path) + { + if(!path.Add(table))return null; + var fields=columns[table];var project=fields.FirstOrDefault(field=>field.ColumnName=="ProjectID"); + if(project is {IsNullable:false})return alias+".[ProjectID]=@OwnedProject"; + var choices=new List(); + if(project is not null)choices.Add(alias+".[ProjectID]=@OwnedProject"); + var links=foreign.GetValueOrDefault(table)?.ToList() ?? []; + // Legacy analysis rows can identify their book without a declared database FK. + if(fields.Any(field=>field.ColumnName=="BookID") && !links.Any(link=>link.Columns.Any(part=>part.Child=="BookID")))links.Add(new("Books",[("BookID","BookID")])); + foreach(var link in links) + { + var parentAlias="owned"+(++aliasNumber).ToString(CultureInfo.InvariantCulture); + var parent=Scope(link.Parent,parentAlias,new HashSet(path)); + if(parent is null)continue; + var join=string.Join(" AND ",link.Columns.Select(part=>alias+"."+Quote(part.Child)+"="+parentAlias+"."+Quote(part.Parent))); + choices.Add("EXISTS(SELECT 1 FROM dbo."+Quote(link.Parent)+" "+parentAlias+" WHERE "+join+" AND ("+parent+"))"); + } + return choices.Count==0 ? null : "("+string.Join(" OR ",choices)+")"; + } + var aliases=new Dictionary{["TimelineSettings"]="ProjectTimelineSettings",["TimelineMetricSettings"]="ProjectTimelineMetricSettings",["AssetCustodyCharacters"]="AssetCustodyEventCharacters",["ProjectAccess"]="ProjectUserAccess",["UserFiles"]="UserFile"}; + var collections=typeof(ProjectBackupData).GetProperties().Where(property=>property.Name is not ("GenreMetricPresets" or "GenreMetricPresetMetrics")) + .Select(property=>(Name:property.Name,Table:aliases.GetValueOrDefault(property.Name,property.Name),Rows:((System.Collections.IEnumerable)property.GetValue(backup.Data)!).Cast().ToArray())).ToList(); + collections.Add(("Project","Projects",[backup.Project!])); + var ownedRows=0; + var coverage=new List{"Table,Collection,OwnedDatabaseRows,ExportedRows,ExtraSharedRows,MissingOwnedRows"}; + foreach(var collection in collections) + { + var scope=Scope(collection.Table,"ownedRoot",[]); + Check(scope is not null,"Unclassified ownership path for backup table "+collection.Table); + var keys=primary[collection.Table]; + var actual=(await db.QueryAsync("SELECT "+string.Join(',',keys.Select(key=>"ownedRoot."+Quote(key)))+" FROM dbo."+Quote(collection.Table)+" ownedRoot WHERE "+scope,new{OwnedProject=backup.Project!.ProjectID})) + .Cast>().Select(row=>Key(keys.Select(key=>row[key]))).ToHashSet(); + var exported=collection.Rows.Select(row=>Key(keys.Select(key=>Read(row,key)))).ToHashSet(); + Check(exported.Count==collection.Rows.Length,"Backup repeats primary-key rows in "+collection.Table); + Check(actual.IsSubsetOf(exported),"Backup omits owned rows from "+collection.Table+": "+actual.Except(exported).Count()); + foreach(var row in collection.Rows) + { + var shared=collection.Table is "AssetStates" or "CharacterAttributeTypes" or "SceneMetricTypes" && Read(row,"ProjectID") is null; + Check(shared || actual.Contains(Key(keys.Select(key=>Read(row,key)))),"Backup contains a foreign owned row from "+collection.Table); + } + ownedRows+=actual.Count; + coverage.Add($"{collection.Table},{collection.Name},{actual.Count},{collection.Rows.Length},{exported.Except(actual).Count()},0"); + } + if(emit) + { + await File.WriteAllLinesAsync("Docs/Sprints/2026-11-03-phase2-row-coverage.csv",coverage); + Console.WriteLine($"PASS independent ownership row census: {collections.Count} scoped entities / {ownedRows} owned rows present; shared vocabulary checked separately."); + } + } +}