Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src-tauri/src/library_sync_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ pub(crate) struct LibrarySyncDomainRevisionsResponse {
#[derive(Deserialize)]
pub(crate) struct LibrarySyncCreateSpoolInput {
pub(crate) base_url: String,
pub(crate) expected_library_id: Option<String>,
pub(crate) expected_library_id: String,
pub(crate) expected_target_generation: u64,
pub(crate) master_id: Option<String>,
pub(crate) material: Option<String>,
pub(crate) filament_name: Option<String>,
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/src/library_sync_resilience_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,8 @@ async fn real_tcp_client_completes_the_five_fixed_workflows_on_the_host() {
&state,
LibrarySyncCreateSpoolInput {
base_url,
expected_library_id: Some(HOST_LIBRARY_ID.to_string()),
expected_library_id: HOST_LIBRARY_ID.to_string(),
expected_target_generation: target_generation,
master_id: None,
material: Some("PLA".to_string()),
filament_name: Some("Fixed Workflow".to_string()),
Expand Down
18 changes: 15 additions & 3 deletions src-tauri/src/library_sync_spool_write_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,17 @@ pub(crate) fn create_library_sync_host_spool_blocking(
state: &AppState,
input: LibrarySyncCreateSpoolInput,
) -> Result<String, String> {
let host_input = library_sync_host_input(&input.base_url, input.expected_library_id.as_deref());
let (_, _, target) = prepare_library_sync_host_write(state, &host_input)?;
if input.expected_library_id.trim().is_empty() {
return Err(crate::app_error::coded_command_error(
"common.invalid_request",
));
}
let host_input = library_sync_host_input(&input.base_url, Some(&input.expected_library_id));
let (_, _, target) = prepare_library_sync_host_write_for_generation(
state,
&host_input,
Some(input.expected_target_generation),
)?;

let path = library_sync_create_spool_path(
input.ownership_type.as_deref(),
Expand Down Expand Up @@ -460,8 +469,11 @@ pub(crate) fn create_library_sync_host_spool_blocking(
return Err(response.message);
}

if response.spool_id.trim().is_empty() {
return Err(crate::app_error::coded_command_error("common.internal"));
}
refresh_library_sync_spool_cache(state, &target);
save_library_sync_success(state, &target, &response.message, None)?;
let _ = save_library_sync_success(state, &target, &response.message, None);

Ok(response.spool_id)
}
Expand Down
4 changes: 2 additions & 2 deletions ui/src/lib/spool_writes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ test("createInventorySpoolFromMaster routes client writes to the host and return

const createdId = await createInventorySpoolFromMaster(
masterSpoolInput(),
{ clientReadOnly: true, clientHostBaseUrl: "http://host", clientLibraryId: "library-1" },
{ clientReadOnly: true, clientHostBaseUrl: "http://host", clientLibraryId: "library-1", clientTargetGeneration: 3 },
{
createHostSpool: async (baseUrl, libraryId, input) => {
calls.push({ baseUrl, libraryId, input });
Expand Down Expand Up @@ -100,7 +100,7 @@ test("createManualInventorySpool routes manual client writes to the host", async

const createdId = await createManualInventorySpool(
manualSpoolInput(),
{ clientReadOnly: true, clientHostBaseUrl: "http://host", clientLibraryId: "library-1" },
{ clientReadOnly: true, clientHostBaseUrl: "http://host", clientLibraryId: "library-1", clientTargetGeneration: 3 },
{
createHostSpool: async (baseUrl, _libraryId, input) => {
calls.push({ baseUrl, input });
Expand Down
12 changes: 7 additions & 5 deletions ui/src/lib/spool_writes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
type UpdateSpoolRfidTagInput,
} from "./tauri_client";
import { updateActiveLibrarySpoolDetails, type ReviewedLibraryAuthority } from "./tauri_active_library_gateway_client";
import { requireClientHostWriteTarget } from "./host_write_target";
import { requireClientHostWriteTarget, resolveClientHostCacheTarget } from "./host_write_target";

export type SpoolWriteTarget = {
reviewedAuthority?: ReviewedLibraryAuthority;
Expand Down Expand Up @@ -68,8 +68,9 @@ export async function createInventorySpoolFromMaster(
const createLocalSpool = dependencies.createLocalSpool ?? createSpool;

if (target.clientReadOnly) {
const hostTarget = requireClientHostWriteTarget(target, missingSpoolHostTargetMessage);
return createHostSpool(hostTarget.baseUrl, hostTarget.libraryId, input);
const hostTarget = resolveClientHostCacheTarget(target);
if (!hostTarget) throw new Error(missingSpoolHostTargetMessage);
return createHostSpool(hostTarget.baseUrl, hostTarget.libraryId, input, hostTarget.targetGeneration);
}

await createLocalSpool(input);
Expand All @@ -86,8 +87,9 @@ export async function createManualInventorySpool(
dependencies.createLocalManualSpool ?? createManualSpool;

if (target.clientReadOnly) {
const hostTarget = requireClientHostWriteTarget(target, missingSpoolHostTargetMessage);
return createHostSpool(hostTarget.baseUrl, hostTarget.libraryId, input);
const hostTarget = resolveClientHostCacheTarget(target);
if (!hostTarget) throw new Error(missingSpoolHostTargetMessage);
return createHostSpool(hostTarget.baseUrl, hostTarget.libraryId, input, hostTarget.targetGeneration);
}

await createLocalManualSpool(input);
Expand Down
7 changes: 4 additions & 3 deletions ui/src/lib/tauri_inventory_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,12 @@ test("buildLibrarySyncHostSpoolCreatePayload forwards catalog ownership to host
};

assert.deepEqual(
buildLibrarySyncHostSpoolCreatePayload("http://host", "library-1", input),
buildLibrarySyncHostSpoolCreatePayload("http://host", "library-1", input, 3),
{
input: {
base_url: "http://host",
expected_library_id: "library-1",
expected_target_generation: 3,
master_id: "master-1",
material: null,
filament_name: null,
Expand Down Expand Up @@ -135,12 +136,12 @@ test("buildLibrarySyncHostSpoolCreatePayload forwards manual ownership to host c
};

assert.equal(
buildLibrarySyncHostSpoolCreatePayload("http://host", null, input).input
buildLibrarySyncHostSpoolCreatePayload("http://host", "library-1", input, 3).input
.ownership_type,
"OWNED",
);
assert.equal(
buildLibrarySyncHostSpoolCreatePayload("http://host", null, input).input.location,
buildLibrarySyncHostSpoolCreatePayload("http://host", "library-1", input, 3).input.location,
"Shelf A",
);
});
11 changes: 7 additions & 4 deletions ui/src/lib/tauri_inventory_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,9 @@ export async function createSpool(input: CreateSpoolInput) {

export function buildLibrarySyncHostSpoolCreatePayload(
baseUrl: string,
expectedLibraryId: string | null | undefined,
expectedLibraryId: string,
input: CreateSpoolInput | CreateManualSpoolInput,
expectedGeneration: number,
) {
const normalizedLocation =
("location" in input ? input.location : undefined) ??
Expand All @@ -277,7 +278,8 @@ export function buildLibrarySyncHostSpoolCreatePayload(
return {
input: {
base_url: baseUrl,
expected_library_id: expectedLibraryId ?? null,
expected_library_id: expectedLibraryId,
expected_target_generation: expectedGeneration,
master_id: "master_id" in input ? input.master_id ?? null : null,
material: "material" in input ? input.material : null,
filament_name: "filament_name" in input ? input.filament_name : null,
Expand All @@ -296,12 +298,13 @@ export function buildLibrarySyncHostSpoolCreatePayload(

export async function createLibrarySyncHostSpool(
baseUrl: string,
expectedLibraryId: string | null | undefined,
expectedLibraryId: string,
input: CreateSpoolInput | CreateManualSpoolInput,
expectedGeneration: number,
) {
return invoke<string>(
"create_library_sync_host_spool",
buildLibrarySyncHostSpoolCreatePayload(baseUrl, expectedLibraryId, input),
buildLibrarySyncHostSpoolCreatePayload(baseUrl, expectedLibraryId, input, expectedGeneration),
);
}

Expand Down
10 changes: 5 additions & 5 deletions ui/src/lib/use_inventory_create_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export function useInventoryCreateActions({
tauriAvailable,
t,
}: InventoryCreateActionsInput) {
const hostWriteTarget = { clientReadOnly, clientHostBaseUrl, clientLibraryId };
const hostWriteTarget = { clientReadOnly, clientHostBaseUrl, clientLibraryId, clientTargetGeneration };
const batchController = useMemo(() => batchControllerFor({
clientReadOnly, clientHostBaseUrl, clientLibraryId, clientTargetGeneration,
}), [clientReadOnly, clientHostBaseUrl, clientLibraryId, clientTargetGeneration]);
Expand Down Expand Up @@ -521,7 +521,7 @@ export function useInventoryCreateActions({
quantity: 1,
note: null,
},
{ ...hostWriteTarget, clientTargetGeneration, libraryMode },
{ ...hostWriteTarget, libraryMode },
);
if (!isCurrent()) return;
await reloadWishlist();
Expand Down Expand Up @@ -561,7 +561,7 @@ export function useInventoryCreateActions({
item_id: itemId,
status,
},
{ ...hostWriteTarget, clientTargetGeneration, libraryMode },
{ ...hostWriteTarget, libraryMode },
);
if (!isCurrent()) return;
await reloadWishlist();
Expand Down Expand Up @@ -590,7 +590,7 @@ export function useInventoryCreateActions({
setConfirmWishlistRemoveId(null);
setInfoMessage(null);
try {
await deleteWishlistEntry(itemId, { ...hostWriteTarget, clientTargetGeneration, libraryMode });
await deleteWishlistEntry(itemId, { ...hostWriteTarget, libraryMode });
if (!isCurrent()) return;
await reloadWishlist();
} catch (deleteError) {
Expand Down Expand Up @@ -684,7 +684,7 @@ export function useInventoryCreateActions({
attempt = pending;
const receipt = await receiveWishlistEntry(
{ ...input, request_id: attempt.requestId },
{ ...hostWriteTarget, clientTargetGeneration, libraryMode, retry: attempt.retry },
{ ...hostWriteTarget, libraryMode, retry: attempt.retry },
);
if (!isConfirmedWishlistReceipt(receipt, quantity)) {
throw createAppError(clientReadOnly
Expand Down
2 changes: 2 additions & 0 deletions ui/src/pages/use_printer_slot_interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,7 @@ export function usePrinterSlotInteractions({
clientReadOnly,
clientHostBaseUrl,
clientLibraryId,
clientTargetGeneration,
});
const postCreateWrites = buildSlotCatalogOnboardingPostCreateWrites({
printerId,
Expand Down Expand Up @@ -1076,6 +1077,7 @@ export function usePrinterSlotInteractions({
clientHostBaseUrl,
clientLibraryId,
clientReadOnly,
clientTargetGeneration,
ensureLocalWriteAllowed,
findLiveTrayForSlot,
printers,
Expand Down
Loading