diff --git a/PlotDirector.NativeCompanion/Tests/TrayTests.cs b/PlotDirector.NativeCompanion/Tests/TrayTests.cs index debdffb7..1b027662 100644 --- a/PlotDirector.NativeCompanion/Tests/TrayTests.cs +++ b/PlotDirector.NativeCompanion/Tests/TrayTests.cs @@ -62,6 +62,8 @@ internal static class TrayTests Apply(new(){Kind="adapter-result",SessionId=first.SessionId,Revision=1,SnapshotId=maintenance!.Id,OperationMessage="Stopped: read-only"}); check(maintained.Book==3,"failed cleanup preserves document association"); control.Maintain(first.SessionId,"reset");maintenance=null;for(var i=0;i<16;i++){var queued=Apply(new(){Kind="ping"}).Command;if(queued?.Kind=="maintenance-reset"){maintenance=queued;break;}} + var resetRegistration=Apply(new(){Kind="document",Documents=[new(){SessionId=first.SessionId,ManuscriptId=first.ManuscriptId,Title=first.Title,Revision=1,IdentityPersisted=false}]}); + check(resetRegistration.Status=="ok","association reset retains live-session manuscript identity while removing persisted metadata"); Apply(new(){Kind="adapter-result",SessionId=first.SessionId,Revision=1,SnapshotId=maintenance!.Id,OperationMessage="Complete: reset"}); check(maintained.Book==0&&control.Documents.Single(d=>d.Session==second.SessionId).MaintenanceReport!="Complete: reset","acknowledged reset unlinks only the selected session"); control.Disconnected(instance,replacementLease);check(control.Documents.Length==0,"pipe disconnect removes exact Word instance sessions and pending control work"); diff --git a/PlotDirector.NativeCompanion/Vsto/WordAdapter.cs b/PlotDirector.NativeCompanion/Vsto/WordAdapter.cs index 106a68dc..9865af50 100644 --- a/PlotDirector.NativeCompanion/Vsto/WordAdapter.cs +++ b/PlotDirector.NativeCompanion/Vsto/WordAdapter.cs @@ -292,7 +292,8 @@ namespace PlotDirector.WordAddIn if(value!=""){if(report.Length<3500)report.AppendLine(name+": "+value.Substring(0,Math.Min(512,value.Length))); if(kind is "reset" or "clean"){object properties=null,property=null;try{properties=Com(()=>doc.Document.CustomDocumentProperties);dynamic collection=properties;property=Com(()=>collection[name]);dynamic item=property;Com(()=>{item.Delete();return true;});}finally{Release(property);Release(properties);}}} }else{ - if(kind is "reset" or "clean"){doc.Identity=Guid.NewGuid();doc.IdentityPersisted=false;doc.BookId=null;doc.ProjectId=null;doc.AssociationSite="";link.Register(Descriptor(doc));} + if(kind is "reset" or "clean"){// The live session keeps its identity until close; a new open allocates an identity when metadata is absent. + doc.IdentityPersisted=false;doc.BookId=null;doc.ProjectId=null;doc.AssociationSite="";link.Register(Descriptor(doc));} Reply(command,"Complete: "+(kind=="inspect"?"PlotDirector identifiers (only owned metadata shown)":$"{removed} owned markers removed. Prose retained. Save Word normally if you wish to keep changes.")+"\r\n"+report);return; } if(!scheduler.Post("maintenance:"+doc.Session,next))Reply(command,"Stopped: Word queue busy; inspect before retrying.");