From 451e766777b134f5be4b0780c01ac8d56b3ec39d Mon Sep 17 00:00:00 2001 From: Nick Beckley Date: Fri, 27 Nov 2026 13:31:56 +0000 Subject: [PATCH] Bind reviewed location merge versions without timestamp rounding --- PlotLine.Tests/Browser/locations-workspace-dev.cjs | 4 ++-- PlotLine.Tests/LocationsWorkspaceDatabaseTests.cs | 9 +++++++++ PlotLine/Controllers/LocationWorkspaceController.cs | 7 +++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/PlotLine.Tests/Browser/locations-workspace-dev.cjs b/PlotLine.Tests/Browser/locations-workspace-dev.cjs index 28ffc77c..c5f2835f 100644 --- a/PlotLine.Tests/Browser/locations-workspace-dev.cjs +++ b/PlotLine.Tests/Browser/locations-workspace-dev.cjs @@ -3,7 +3,7 @@ const {chromium}=require('playwright'),assert=require('node:assert/strict'),fs=r const base='https://dev.plotdirector.com',file=process.argv[2],setup=process.argv.includes('--setup'); if(!file?.startsWith('/tmp/pd-dev-browser-'))throw Error('Private dedicated identity file required.'); const identity=JSON.parse(fs.readFileSync(file,'utf8'));assert.equal(identity.Database,'PlotDirector_Development');assert(identity.Email.startsWith('pwa-browser-')&&identity.Email.endsWith('@example.invalid')); -(async()=>{const browser=await chromium.launch(),context=await browser.newContext({viewport:{width:1440,height:1000}}),page=await context.newPage();try{ +(async()=>{const browser=await chromium.launch(),context=await browser.newContext({viewport:{width:1440,height:1000}}),page=await context.newPage();await context.addInitScript(user=>localStorage.setItem(`plotdirector.desktop.v1.${user}`,JSON.stringify({dismissedAt:Date.now()})),identity.UserID);try{ await page.goto(base+'/Account/Login');await page.locator('[name=Email]').fill(identity.Email);await page.locator('[name=Password]').fill(identity.Password);await page.locator('form button[type=submit]').click();await page.waitForURL(base+'/Projects'); if(setup){assert(!identity.ProjectID);await page.goto(base+'/Projects/Create');await page.locator('[name=ProjectName]').fill('Locations acceptance · disposable world');await page.getByRole('button',{name:'Save project',exact:true}).click();await page.waitForURL(/\/Projects\/Details\/\d+/);identity.ProjectID=Number(page.url().split('/').pop());await page.goto(base+`/Books/Create?projectId=${identity.ProjectID}`);await page.locator('[name=BookTitle]').fill('Locations acceptance fixture');await page.getByRole('button',{name:'Save book',exact:true}).click();await page.waitForURL(/\/Books\/Details\/\d+/);identity.BookID=Number(page.url().split('/').pop());fs.writeFileSync(file,JSON.stringify(identity,null,2),{mode:0o600});console.log('PASS dedicated fixture project/book created through normal Development forms.');return;} assert(identity.ProjectID&&identity.BookID);const q=`projectId=${identity.ProjectID}`; @@ -25,6 +25,6 @@ const identity=JSON.parse(fs.readFileSync(file,'utf8'));assert.equal(identity.Da await page.goto(base+`/Locations/Edit/${id}`);await page.locator('[name=ParentLocationID]').selectOption(String(child.id));await page.getByRole('button',{name:'Save location',exact:true}).click();await page.waitForLoadState();assert.match(await page.locator('.validation-summary-errors').textContent(),/descendant/);data=await directory();assert.equal(data.locations.find(r=>r.id===id).parent,null);assert.equal(data.locations.find(r=>r.id===id).description,'Author-controlled synthetic description.'); const checks=[];for(const route of [`/Characters?${q}`,`/Names?${q}`,`/RelationshipMap?${q}`,`/Maps?${q}`,`/FloorPlans?${q}`,`/StoryAssets?${q}`,`/Locations/Details/${id}`,`/Locations/Edit/${id}`,`/Writer?${q}&bookId=${identity.BookID}`]){const response=await page.goto(base+route);assert.equal(response.status(),200,route);assert(!page.url().includes('/Account/'));checks.push(route.split('?')[0]);} await page.goto(base+`/Locations/Details/${id}`);await page.locator('[name=ToLocationID]').selectOption(String(child.id));await page.locator('[name=Notes]').fill('Disposable non-hierarchical relationship');await page.getByRole('button',{name:'Add relationship',exact:true}).click();await page.waitForLoadState();assert(await page.getByText('Disposable non-hierarchical relationship',{exact:true}).count()); - await page.goto(base+`/Locations?${q}`);await page.locator('[data-location-records][aria-busy=false]').waitFor();await page.getByRole('button',{name:'Expand all',exact:true}).click();await page.locator(`[data-location-id="${child.id}"]`).getByRole('button',{name:'Actions for Observatory acceptance'}).click();await page.getByRole('menuitem',{name:'Merge with another location…',exact:true}).click();await page.getByRole('combobox',{name:'Surviving location'}).selectOption(String(id));await page.locator('[data-location-dialog] input[type=checkbox]').check();await page.locator('[data-dialog-save]').click();await page.locator('[data-location-dialog]').waitFor({state:'hidden'});data=await directory();assert.equal(data.locations.length,1);assert.equal(data.locations[0].id,id);assert.equal(data.locations[0].description,'Author-controlled synthetic description.'); + await page.goto(base+`/Locations?${q}`);await page.locator('[data-location-records][aria-busy=false]').waitFor();await page.getByRole('button',{name:'Expand all',exact:true}).click();await page.locator(`[data-location-id="${child.id}"]`).getByRole('button',{name:'Actions for Observatory acceptance'}).click();await page.getByRole('menuitem',{name:'Merge with another location…',exact:true}).click();await page.getByRole('combobox',{name:'Surviving location'}).selectOption(String(id));await page.locator('[data-location-dialog] input[type=checkbox]').check();const mergeResponse=page.waitForResponse(r=>r.url().endsWith('/LocationWorkspace/Merge'));await page.locator('[data-dialog-save]').click();const mergeResult=await mergeResponse;assert.equal(mergeResult.status(),200,await mergeResult.text());await page.locator('[data-location-dialog]').waitFor({state:'hidden'});data=await directory();assert.equal(data.locations.length,1);assert.equal(data.locations[0].id,id);assert.equal(data.locations[0].description,'Author-controlled synthetic description.'); fs.writeFileSync(out+'/development-smoke.json',JSON.stringify({status:'passed',target:'Development',checks:['real Directory/Create/Assign/Undo/Merge endpoints','bulk assignment and protected Undo','one-step workspace Undo clears after restoration','normal non-hierarchical relationship form','reviewed merge archives source and retains survivor','inline child Enter-save','context menu for a selection hidden in a collapsed branch','classification','inline rename preserves child identifiers','description save','server cycle rejection','traditional full Edit rejects cycles without losing posted data','cross-project mutation rejection','actual second-window live invalidation',...checks]},null,2));console.log('PASS authenticated Development workspace mutations, hierarchy safeguards, cross-window live updates and related route smoke; disposable data only.'); }finally{await browser.close();}})().catch(e=>{console.error(e);process.exitCode=1;}); diff --git a/PlotLine.Tests/LocationsWorkspaceDatabaseTests.cs b/PlotLine.Tests/LocationsWorkspaceDatabaseTests.cs index fe0bebca..72a7f8e3 100644 --- a/PlotLine.Tests/LocationsWorkspaceDatabaseTests.cs +++ b/PlotLine.Tests/LocationsWorkspaceDatabaseTests.cs @@ -45,6 +45,15 @@ internal static class LocationsWorkspaceDatabaseTests if(rows.Count(r=>r.LocationName.StartsWith("Dapper performance fixture "))!=count)throw new Exception("Directory lost fixture rows."); Console.WriteLine($"PASS Dapper read: {count} synthetic + {rows.Length-count} existing clone records, old list {baselineMs:F1} ms ({previousRows.Length} rows), new six-result directory {watch.Elapsed.TotalMilliseconds:F1} ms"); } + var mergeSource=await db.QuerySingleAsync("dbo.Location_WorkspaceCreate",new{identity.ProjectID,identity.UserID,Name="Dapper exact merge source",ParentID=(int?)null},transaction,commandType:CommandType.StoredProcedure); + // A fractional timestamp that SQL datetime cannot represent exposes accidental default binding. + await db.ExecuteAsync("UPDATE dbo.Locations SET UpdatedDate=CONVERT(datetime2(7),'2026-11-27T10:11:12.1234567') WHERE LocationID IN(@created,@mergeSource)",new{created,mergeSource},transaction); + var mergeVersion=new DateTime(2026,11,27,10,11,12).AddTicks(1234567); + var mergeParameters=new DynamicParameters(new{identity.ProjectID,identity.UserID,SourceID=mergeSource,TargetID=created}); + mergeParameters.Add("SourceVersion",mergeVersion,DbType.DateTime2);mergeParameters.Add("TargetVersion",mergeVersion,DbType.DateTime2); + var merged=await db.QuerySingleAsync("dbo.Location_WorkspaceMerge",mergeParameters,transaction,commandType:CommandType.StoredProcedure); + if(!await db.ExecuteScalarAsync("SELECT IsArchived FROM dbo.Locations WHERE LocationID=@mergeSource",new{mergeSource},transaction))throw new Exception("Dapper merge did not archive its reviewed source."); + Console.WriteLine("PASS Dapper reviewed merge preserves exact datetime2(7) versions."); transaction.Rollback(); Console.WriteLine("PASS Dapper create result, exact-version assignment/Undo, directory projections including entry/exit-only usage, and rollback; no live data changed."); } diff --git a/PlotLine/Controllers/LocationWorkspaceController.cs b/PlotLine/Controllers/LocationWorkspaceController.cs index b2e8ac4e..200ca2a7 100644 --- a/PlotLine/Controllers/LocationWorkspaceController.cs +++ b/PlotLine/Controllers/LocationWorkspaceController.cs @@ -106,8 +106,11 @@ public sealed class LocationWorkspaceController(ISqlConnectionFactory connection try { using var db = connections.CreateConnection(); - await db.QuerySingleAsync("dbo.Location_WorkspaceMerge", new { ProjectID = input.ProjectId, UserID = author, - SourceID = input.SourceId, TargetID = input.TargetId, SourceVersion = sourceVersion, TargetVersion = targetVersion }, commandType: CommandType.StoredProcedure); + var parameters = new DynamicParameters(new { ProjectID = input.ProjectId, UserID = author, SourceID = input.SourceId, TargetID = input.TargetId }); + // Dapper's default DateTime binding rounds to SQL datetime precision; review versions are datetime2. + parameters.Add("SourceVersion", sourceVersion, DbType.DateTime2); + parameters.Add("TargetVersion", targetVersion, DbType.DateTime2); + await db.QuerySingleAsync("dbo.Location_WorkspaceMerge", parameters, commandType: CommandType.StoredProcedure); await notifications.Invalidate(author, projectId: input.ProjectId, kind: "locations"); return Json(new { id = input.TargetId }); }