feat(catalog): make the live catalog self-correcting and honest about failure
Gitea Actions Runner Test / test-job (push) Successful in 0s
CI / check (push) Successful in 29s
CI / tests-unit (push) Successful in 1m34s
CI / tests-integration (push) Failing after 1m34s
CI / tests-ui (push) Successful in 2m19s
CI / preflight (push) Skipped
CI / deploy (push) Skipped
Gitea Actions Runner Test / test-job (push) Successful in 0s
CI / check (push) Successful in 29s
CI / tests-unit (push) Successful in 1m34s
CI / tests-integration (push) Failing after 1m34s
CI / tests-ui (push) Successful in 2m19s
CI / preflight (push) Skipped
CI / deploy (push) Skipped
The previous commit made imports update the Studio without a reload, but the guarantee only held inside the tab that started the import and only as long as every read succeeded. Four holes were left, and this closes them. A session that mounted the tree before an import kept the pre-import tree for the rest of its life, because ensureCatalogTreeLoaded() was a once-per-session no-op. It now asks the server whether what it holds is still current. The answer is a revision: sendCatalogUpdate() already runs after every catalog write, so it bumps one, and clients read it on mount, on focus, on a 20s poll and from other tabs over a BroadcastChannel. An import that finishes in another tab, another browser or the job worker now lands here too. A failed read used to be swallowed, which is the worst outcome available: the rail kept showing pre-import counts as if they were current and nothing said so. The snapshot now carries the error, the rail shows it with a retry, and the previous tree stays on screen because stale beats empty. Every settled import pulled the entire flat tree, which is the one payload that grows with the size of the catalog. The revision doubles as the ETag on mode=full, so an unchanged catalog answers 304 and the poll costs a file read. An import could also report success for an offer the hotel will never sell: a hidden or disabled page, an item_ids that misses the furni id, a zero amount. importSingleFurni reads its own row back and reports each of those as a warning, where the import report already is, instead of leaving it to surface as "the import did not work" in the client. Finally, the catalog items table no longer falls back to router.refresh() — onRefresh is now required, so every mutation ends in a refresh of the caller's own data instead of a route re-render that threw away editor state and scroll position. useServerAction keeps its default, because 47 callers across the app depend on it. The 750-line CatalogTree in catalog-tree.tsx was dead code that kept its own stale tree and three more router.refresh() calls; only CatalogIcon and LAYOUT_COLORS are still imported, so the rest is gone. Tests: the store now covers revisions, 304s, probe failures and error recovery; a jsdom test mounts a consumer and asserts the tree updates in place with no navigation; the old organize-imports e2e asserted nothing about the endpoints the code actually calls, and is replaced by one that asserts a cross-tab write lands in the mounted categories without a reload. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
1 parent
28ce0f911c
commit
9550b3d66f
18 files changed
+1016
-973
No files matched your search
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Why a catalog offer can be "imported successfully" and still be invisible in
|
||||
* the hotel.
|
||||
*
|
||||
* The import writes `catalog_items` plus a `furnidata` entry and reports `ok`.
|
||||
* Whether the emulator will actually sell the offer depends on a handful of
|
||||
* conditions the import never asserts: the page has to be enabled and visible,
|
||||
* `item_ids` has to name the furni id, `amount` has to be positive. Every one of
|
||||
* them looks fine in the CMS and produces a client that shows nothing, which is
|
||||
* reported as "the import did not work".
|
||||
*
|
||||
* This module is the pure part of that check so the rules can be tested without
|
||||
* a database; `importSingleFurni` supplies the row it read back.
|
||||
*/
|
||||
|
||||
export interface OfferPurchasabilityInput {
|
||||
/** Catalog page the offer sits on. */
|
||||
pageEnabled: string;
|
||||
pageVisible: string;
|
||||
/** Raw `catalog_items.item_ids`, `;`-separated. */
|
||||
itemIds: string;
|
||||
amount: number;
|
||||
costCredits: number;
|
||||
costPoints: number;
|
||||
/** `-1` means the offer is not wired up. */
|
||||
offerId: number;
|
||||
haveOffer: string;
|
||||
/** The `catalog_item_base.id` the import just wrote. */
|
||||
furniId: number;
|
||||
}
|
||||
|
||||
/** Offer id used by Habbo DBs for "this offer has no offer id". */
|
||||
const NO_OFFER_ID = -1;
|
||||
|
||||
function parsesItemIds(itemIds: string): number[] {
|
||||
return itemIds
|
||||
.split(/[;,]/)
|
||||
.map((part) => Number(part.trim()))
|
||||
.filter((value) => Number.isFinite(value) && value > 0);
|
||||
}
|
||||
|
||||
/** Problems that stop the hotel from selling the offer, in reporting order. */
|
||||
export function offerPurchasabilityProblems(
|
||||
offer: OfferPurchasabilityInput,
|
||||
): string[] {
|
||||
const problems: string[] = [];
|
||||
const ids = parsesItemIds(offer.itemIds);
|
||||
if (ids.length === 0) {
|
||||
problems.push("catalog item has no furni id in item_ids");
|
||||
} else if (!ids.includes(offer.furniId)) {
|
||||
problems.push(
|
||||
`item_ids does not contain furni id ${offer.furniId} (it holds ${ids.join(", ")})`,
|
||||
);
|
||||
}
|
||||
if (offer.pageEnabled !== "1") problems.push("catalog page is disabled");
|
||||
if (offer.pageVisible !== "1") problems.push("catalog page is hidden");
|
||||
if (!Number.isFinite(offer.amount) || offer.amount < 1)
|
||||
problems.push(`amount is ${offer.amount}, so the offer delivers nothing`);
|
||||
if (offer.costCredits < 0 || offer.costPoints < 0)
|
||||
problems.push("offer has a negative price");
|
||||
if (
|
||||
offer.offerId !== NO_OFFER_ID &&
|
||||
offer.haveOffer !== "1" &&
|
||||
ids.length > 0
|
||||
) {
|
||||
problems.push("offer_id is set but haveOffer is not 1");
|
||||
}
|
||||
return problems;
|
||||
}
|
||||
Reference in new issue
Block a user