feat #14740: track uploads per backend server

Schema v4 adds calls.crm_base_url; existing uploads are tagged with the
test backend. A call counts as uploaded (list/detail fields, the
"Hochgeladen am" line, the upload-once guard) only if it was uploaded to
this build's backend. Uploading to the other server replaces the single
upload record; nothing is deleted.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
hauke
2026-11-09 10:52:16 +01:00
co-authored by Claude Opus 5.5
parent d0ece263a2
commit 3a16c76257
5 changed files with 265 additions and 42 deletions
+48 -10
View File
@@ -350,12 +350,15 @@ impl AppState {
/// Reserves call `id` for one upload; released when the claim is
/// dropped. A second upload of the same call is refused meanwhile, and
/// so is a call that already carries a CRM transcript id — or one the
/// CRM confirmed but whose id could not be saved locally, see
/// [`AppState::note_upload_confirmed_but_unsaved`]: the CRM must never
/// get a duplicate. All three checks happen while `uploading` is
/// locked, so a second upload can never slip in between this check and
/// the one upload it allows.
/// so is a call already uploaded to *this build's* backend
/// ([`call_view::uploaded_here`]) — or one the CRM confirmed but whose
/// id could not be saved locally, see
/// [`AppState::note_upload_confirmed_but_unsaved`]: the CRM this build
/// talks to must never get a duplicate. An upload recorded for another
/// backend (e.g. the test backend, read by a release build) is not
/// "uploaded" here and is claimed like any other call. All three checks
/// happen while `uploading` is locked, so a second upload can never
/// slip in between this check and the one upload it allows.
pub fn claim_upload(&self, id: CallId) -> Result<UploadClaim<'_>, String> {
let mut uploading = lock(&self.uploading);
if uploading.contains(&id) {
@@ -364,7 +367,10 @@ impl AppState {
if lock(&self.upload_confirmed_unsaved).contains(&id) {
return Err("Bereits hochgeladen".to_string());
}
if self.find_call(id)?.crm_transcript_id.is_some() {
// An upload recorded for another backend (e.g. the test backend,
// read by a release build) does not count: the CRM this build
// talks to has never seen this transcript.
if call_view::uploaded_here(&self.find_call(id)?, &self.backend_url) {
return Err("Bereits hochgeladen".to_string());
}
uploading.insert(id);
@@ -627,7 +633,10 @@ impl AppState {
/// All calls for the main window's list, newest first.
pub fn call_list(&self) -> Result<Vec<CallListItem>, String> {
let calls = self.store.list_calls().map_err(|e| e.to_string())?;
Ok(calls.iter().map(CallListItem::of).collect())
Ok(calls
.iter()
.map(|call| CallListItem::of(call, &self.backend_url))
.collect())
}
/// The selected call with its transcript (speaker merges applied),
@@ -637,7 +646,7 @@ impl AppState {
let segments = self.store.segments(id).map_err(|e| e.to_string())?;
let names = self.store.speaker_names(id).map_err(|e| e.to_string())?;
let merges = self.store.speaker_merges(id).map_err(|e| e.to_string())?;
let mut detail = CallDetail::of(&call, &segments, names, &merges);
let mut detail = CallDetail::of(&call, &segments, names, &merges, &self.backend_url);
detail.uploading = self.is_uploading(id);
Ok(detail)
}
@@ -692,7 +701,7 @@ impl AppState {
pub fn mark_uploaded(&self, id: CallId, crm_transcript_id: &str) -> Result<(), String> {
self.find_call(id)?;
self.store
.set_uploaded(id, crm_transcript_id, Local::now())
.set_uploaded(id, crm_transcript_id, &self.backend_url, Local::now())
.map_err(|e| format!("Upload konnte nicht vermerkt werden: {e}"))
}
@@ -1706,6 +1715,34 @@ mod tests {
assert!(!f.state.is_uploading(id));
}
/// The real case the review asked to lock in: a call uploaded to the
/// test backend is refused for upload by a build whose own backend is
/// the test backend (the normal case, above), but uploadable again by a
/// build whose backend is the production one — the CRM at that backend
/// has never seen this transcript.
#[test]
fn an_upload_to_another_backend_is_not_counted_as_uploaded_here() {
let mut f = fixture();
let (id, _, _) = finished_call(&f, "a");
// A build on the test backend (what `cargo tauri dev` is), whatever
// profile this test itself runs in: mark_uploaded records it.
f.state.backend_url = crate::backend::DEV_BACKEND_URL.to_string();
f.state.mark_uploaded(id, "4711").unwrap();
assert_eq!(
f.state.find_call(id).unwrap().crm_base_url.as_deref(),
Some(crate::backend::DEV_BACKEND_URL)
);
assert_eq!(
f.state.claim_upload(id).err(),
Some("Bereits hochgeladen".to_string())
);
// The same row, now read as a release build would be: a different
// backend, nothing else changed.
f.state.backend_url = crate::backend::RELEASE_BACKEND_URL.to_string();
assert!(f.state.claim_upload(id).is_ok());
}
#[test]
fn an_upload_confirmed_but_unsaved_is_never_retried() {
// The CRM has the transcript, but mark_uploaded failed: the row
@@ -1738,6 +1775,7 @@ mod tests {
let call = f.state.store.get_call(id).unwrap().unwrap();
assert_eq!(call.crm_transcript_id.as_deref(), Some("4711"));
assert_eq!(call.crm_base_url.as_deref(), Some(BASE));
assert!(call.uploaded_at.is_some());
assert_eq!(
f.state.mark_uploaded(id + 1, "1"),