');await badge.evaluate(()=>{window.tick=null;window.setInterval=f=>(tick=f,1);window.live=[];window.fetch=async()=>({ok:true,json:async()=>live});});
await badge.addScriptTag({content:fs.readFileSync(path.join(__dirname,'../../PlotLine/wwwroot/js/native-companion-status.js'),'utf8')});assert.equal(await badge.locator('#native-companion-status').isHidden(),true);
diff --git a/PlotLine.Tests/NativeCompanionHttpTests.cs b/PlotLine.Tests/NativeCompanionHttpTests.cs
index aa2b62ac..ee87b883 100644
--- a/PlotLine.Tests/NativeCompanionHttpTests.cs
+++ b/PlotLine.Tests/NativeCompanionHttpTests.cs
@@ -57,6 +57,14 @@ internal static class NativeCompanionHttpTests
await using var app=builder.Build();app.UseRouting();app.UseRateLimiter();app.UseAuthentication();app.UseAuthorization();
app.MapGet("/fixture-login",async (Microsoft.AspNetCore.Http.HttpContext context)=>{await context.SignInAsync(new ClaimsPrincipal(new ClaimsIdentity([new(ClaimTypes.NameIdentifier,"7"),new("PlotLine.SecurityStamp",user.SecurityStamp.ToString())],CookieAuthenticationDefaults.AuthenticationScheme)));return "Fixture login";});
app.MapGet("/fixture-antiforgery",(IAntiforgery xsrf,Microsoft.AspNetCore.Http.HttpContext context)=>xsrf.GetAndStoreTokens(context).RequestToken);
+ app.MapGet("/fixture-render-review/{id:guid}",async (Guid id,Microsoft.AspNetCore.Http.HttpContext context)=>{
+ var row=await context.RequestServices.GetRequiredService().Get(7,id);if(row==null)return Microsoft.AspNetCore.Http.Results.NotFound();
+ var action=new Microsoft.AspNetCore.Mvc.ActionContext(context,new Microsoft.AspNetCore.Routing.RouteData(),new Microsoft.AspNetCore.Mvc.Abstractions.ActionDescriptor());
+ var views=context.RequestServices.GetRequiredService();var view=views.GetView(null,"/Views/NativeWorkspace/Review.cshtml",false);if(!view.Success)throw new Exception("Native review Razor view unavailable");
+ using var writer=new StringWriter();var data=new Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary(new Microsoft.AspNetCore.Mvc.ModelBinding.EmptyModelMetadataProvider(),new Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary()){Model=new NativeReviewModel(row,JsonSerializer.Deserialize(row.ResultJson)!,string.IsNullOrEmpty(row.DecisionsJson)?[]:JsonSerializer.Deserialize(row.DecisionsJson)!,[],1)};
+ var temp=new Microsoft.AspNetCore.Mvc.ViewFeatures.TempDataDictionary(context,context.RequestServices.GetRequiredService());
+ await view.View.RenderAsync(new Microsoft.AspNetCore.Mvc.Rendering.ViewContext(action,view.View,data,temp,writer,new Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelperOptions()));return Microsoft.AspNetCore.Http.Results.Content(writer.ToString(),"text/html");
+ }).RequireAuthorization();
app.MapHub("/hubs/native-companion");app.MapControllers();await app.StartAsync();
try
{
@@ -86,6 +94,10 @@ internal static class NativeCompanionHttpTests
var result=await response.Content.ReadFromJsonAsync();Check(result?.State=="complete"&&result.Scenes.Single().Start==20&&provider.Prompts.Count==1,"Actual HTTP response maps scene to Word position");
Check((await agent.PostAsJsonAsync("/api/native-companion/analyse-chapter",request)).IsSuccessStatusCode&&provider.Prompts.Count==1,"HTTP retry reuses successful provider result");
Check(result!.ReviewPath.StartsWith("/native-companion/reviews/")&&!string.IsNullOrWhiteSpace(result.Scenes.Single().Summary),"AI summary is preserved and saved PWA review handoff returned");
+ var reviewId=Guid.Parse(result.ReviewPath.Split('/').Last());var reviewHtml=await browser.GetStringAsync("/fixture-render-review/"+reviewId);Check(reviewHtml.Contains("Save review decisions")&&reviewHtml.Contains("Summary")&&reviewHtml.Contains("scene"),"Actual compiled Razor review renders AI title/summary form");
+ var decisionFields=new Dictionary{{"version","1"},{"scenes[0].Index","0"},{"scenes[0].State","approved"},{"scenes[0].Title",""},{"scenes[0].Summary","Edited summary"},{"__RequestVerificationToken",antiforgery}};
+ Check((await browser.PostAsync(result.ReviewPath,new FormUrlEncodedContent(decisionFields))).StatusCode==HttpStatusCode.Redirect,"Actual antiforgery-protected form binds and saves review decisions");
+ Check((await browser.PostAsync(result.ReviewPath,new FormUrlEncodedContent(decisionFields))).StatusCode==HttpStatusCode.Conflict,"Actual stale review form receives conflict without overwriting");reviewHtml=await browser.GetStringAsync("/fixture-render-review/"+reviewId);Check(!reviewHtml.Contains("")&&reviewHtml.Contains("Edited summary"),"Saved title is encoded while edited summary remains reviewable");
request.RequestId=Guid.NewGuid();var reused=await agent.PostAsJsonAsync("/api/native-companion/analyse-chapter",request);Check(reused.IsSuccessStatusCode&&provider.Prompts.Count==1,"Unchanged chapter content reuses durable suggestion across new request identifiers");
var negotiation=await browser.PostAsync("/hubs/native-companion/negotiate?negotiateVersion=1",null);Check(negotiation.IsSuccessStatusCode,"Native presence hub requires normal browser authentication and negotiates after sign-in");
var connectionToken=(await negotiation.Content.ReadFromJsonAsync()).GetProperty("connectionToken").GetString();
diff --git a/PlotLine.Tests/NativeTrayIntegrationTests.cs b/PlotLine.Tests/NativeTrayIntegrationTests.cs
index 3a741a4b..0509e480 100644
--- a/PlotLine.Tests/NativeTrayIntegrationTests.cs
+++ b/PlotLine.Tests/NativeTrayIntegrationTests.cs
@@ -30,7 +30,7 @@ internal static class NativeTrayIntegrationTests
var repo=new MemoryNativeReviews();var result=new AiChapterResult{State="complete",ChapterTitle="Opening",Scenes=[new(){Kind="Scene",Origin="AI",Title="Arrival",Summary="A saved AI summary.",Start=0,End=100}]};
var row=await repo.Save(new(){ReviewID=Guid.NewGuid(),UserID=7,BookID=3,ManuscriptID=manuscript,ContentHash="hash",ResultJson=JsonSerializer.Serialize(result)});
var books=NativeWorkflowTests.Proxy((n,a)=>Task.FromResult(new(){BookID=3,ProjectID=1}));var workspace=new NativeWorkspaceController(access,books,repo,store){ControllerContext=new(){HttpContext=http},TempData=new TempDataDictionary(http,new TempData())};
- Check(await workspace.Review(row.ReviewID) is ViewResult,"Saved AI title and summary can be reviewed in PWA without Word");
+ Check(await workspace.Review(row.ReviewID) is ViewResult{Model:NativeReviewModel{BookID:3,ProjectID:1}},"Saved AI title and summary can be reviewed in PWA without Word");
Check(await workspace.Decide(row.ReviewID,1,[new(){Index=0,State="approved",Title="Edited title",Summary="Edited summary"}]) is RedirectToActionResult,"Explicit approval/edit saves suggestions only");
Check(await workspace.Decide(row.ReviewID,1,[new(){Index=0,State="rejected",Title="Late edit",Summary=""}]) is ConflictObjectResult,"Stale review window cannot overwrite decisions");
Check(await workspace.Decide(row.ReviewID,2,[new(){Index=0,State="invented",Title="No",Summary=""}]) is BadRequestObjectResult,"Invalid decisions are refused");
diff --git a/PlotLine/Controllers/NativeWorkspaceController.cs b/PlotLine/Controllers/NativeWorkspaceController.cs
index 0ea74d90..2248915e 100644
--- a/PlotLine/Controllers/NativeWorkspaceController.cs
+++ b/PlotLine/Controllers/NativeWorkspaceController.cs
@@ -33,7 +33,8 @@ public sealed class NativeWorkspaceController(IWordCompanionRepository access,IB
public async Task Review(Guid id)
{
var row=await reviews.Get(Author,id);if(row==null)return NotFound();if(await access.GetBookStructureAsync(row.BookID,Author)==null)return Forbid();
- return View(new NativeReviewModel(row,JsonSerializer.Deserialize(row.ResultJson)!,string.IsNullOrEmpty(row.DecisionsJson)?[]:JsonSerializer.Deserialize(row.DecisionsJson)!,presence.Read(Author,row.BookID).Where(l=>l.Position.WordAvailable&&l.Position.ManuscriptId==row.ManuscriptID&&l.Position.Revision==JsonSerializer.Deserialize(row.ResultJson)!.DocumentRevision).ToArray()));
+ var book=await books.GetAsync(row.BookID);if(book==null)return NotFound();
+ return View(new NativeReviewModel(row,JsonSerializer.Deserialize(row.ResultJson)!,string.IsNullOrEmpty(row.DecisionsJson)?[]:JsonSerializer.Deserialize(row.DecisionsJson)!,presence.Read(Author,row.BookID).Where(l=>l.Position.WordAvailable&&l.Position.ManuscriptId==row.ManuscriptID&&l.Position.Revision==JsonSerializer.Deserialize(row.ResultJson)!.DocumentRevision).ToArray(),book.ProjectID));
}
[HttpPost("reviews/{id:guid}/navigate"),ValidateAntiForgeryToken]
public async Task Navigate(Guid id,int index,Guid instanceId,Guid sessionId)
@@ -53,6 +54,6 @@ public sealed class NativeWorkspaceController(IWordCompanionRepository access,IB
TempData["NativeReviewSaved"]="Review decisions saved. No manuscript or canonical story records were changed.";return RedirectToAction(nameof(Review),new{id});
}
}
-public sealed record NativeWorkspaceModel(int Book,int Project,string Title,Guid? Instance,Guid? Session,string Mode,IReadOnlyList Reviews);
-public sealed record NativeReviewModel(NativeReview Row,AiChapterResult Result,NativeSceneDecision[] Decisions,NativeLease[] Sessions);
+public sealed record NativeWorkspaceModel(int Book,int Project,string Title,Guid? Instance,Guid? Session,string Mode,IReadOnlyList Reviews){public int BookID=>Book;public int ProjectID=>Project;}
+public sealed record NativeReviewModel(NativeReview Row,AiChapterResult Result,NativeSceneDecision[] Decisions,NativeLease[] Sessions,int ProjectID=0){public int BookID=>Row.BookID;}
public sealed class NativeSceneDecision {public int Index {get;set;}public string State {get;set;}="pending";public string Title {get;set;}="";public string Summary {get;set;}="";}