Add Google mailbox lifecycle controls and guarded sync recovery
This commit is contained in:
@@ -15,6 +15,7 @@ IStore store = uri == null ? new PreviewStore() : new MongoStore(new Configurati
|
||||
await store.Initialize();
|
||||
try
|
||||
{
|
||||
await MailboxTests.Run(Check, store);
|
||||
await TeamTests.Run(Check, store);
|
||||
await ReplyTests.Run(Check, store);
|
||||
await PmsTests.Run(Check, store);
|
||||
@@ -54,6 +55,10 @@ try
|
||||
oldMailbox!.SyncError = "stale worker failure"; await store.SaveSync(oldMailbox);
|
||||
var newMailbox = await store.Get<Mailbox>(a.Id, mailbox.Id);
|
||||
Check("Stale worker cannot overwrite reconnected credentials", newMailbox?.ProtectedRefreshToken == "new-protected-token" && newMailbox.SyncError == "");
|
||||
await new MongoClient(uri).GetDatabase(dbName).GetCollection<Mailbox>("mailbox").UpdateOneAsync(x=>x.Id==mailbox.Id,Builders<Mailbox>.Update.Unset(x=>x.Version));
|
||||
var legacy=(await store.Get<Mailbox>(a.Id,mailbox.Id))!;legacy.SyncError="Legacy sync health";await store.SaveSync(legacy);
|
||||
Check("Pre-migration mailboxes accept guarded health updates",(await store.Get<Mailbox>(a.Id,mailbox.Id))?.SyncError=="Legacy sync health");
|
||||
Check("Pre-migration mailbox can be disconnected with version zero",await MailboxManagement.Change(store,legacy,0,"disconnect"));
|
||||
}
|
||||
var parsed = AiExtractionPrompt.BuildRowsFromJson("{\"action\":\"CreateBooking\",\"first_name\":\"Guest {test}\"}", new ParsedBooking());
|
||||
Check("Migrated parser preserves braces in JSON strings", parsed.Count > 0 && parsed[0].GuestFirstName == "Guest {test}");
|
||||
@@ -79,6 +84,10 @@ try
|
||||
Check("Draft save succeeds", (await one.PutAsJsonAsync($"/api/conversations/{id}/draft",new {draft="Hello guest",version=0})).IsSuccessStatusCode);
|
||||
Check("Stale API draft save returns conflict", (await one.PutAsJsonAsync($"/api/conversations/{id}/draft",new {draft="old",version=0})).StatusCode==HttpStatusCode.Conflict);
|
||||
Check("Preview cannot connect real Gmail", !(await one.PostAsJsonAsync("/api/integrations/google/connect",new {})).IsSuccessStatusCode);
|
||||
var boxes=await Read(one,"/api/mailboxes");var boxId=boxes.GetProperty("items")[0].GetProperty("id").GetString();
|
||||
Check("Mailbox health includes recovery state without secrets",boxes.GetProperty("items")[0].GetProperty("syncErrorCode").GetString()=="ReconnectRequired"&&!boxes.GetRawText().Contains("protectedRefreshToken")&&!boxes.GetRawText().Contains("pageToken"));
|
||||
foreach(var action in new[]{"disconnect","reconnect","retry"})Check("Other hotel cannot "+action+" a mailbox",(await two.PostAsJsonAsync($"/api/mailboxes/{boxId}/{action}",new{version=0})).StatusCode==HttpStatusCode.NotFound);
|
||||
Check("Preview recovery cannot change real Google state",(await one.PostAsJsonAsync($"/api/mailboxes/{boxId}/reconnect",new{version=0})).StatusCode==HttpStatusCode.BadRequest);
|
||||
Check("Preview cannot enable paid AI", (await one.PutAsJsonAsync("/api/reply-controls",new {version=0,aiDraftsEnabled=true,staffSendingEnabled=false})).StatusCode==HttpStatusCode.BadRequest);
|
||||
Check("Cross-hotel reply approval is blocked", (await two.PostAsJsonAsync($"/api/conversations/{id}/send",new {version=1,recipient="guest@example.invalid"})).StatusCode==HttpStatusCode.NotFound);
|
||||
Check("Cross-hotel AI generation is blocked", (await two.PostAsJsonAsync($"/api/conversations/{id}/generate",new {version=1})).StatusCode==HttpStatusCode.NotFound);
|
||||
@@ -124,3 +133,4 @@ finally
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user