feat(market): PHASE C — expose every unlisted trade-pile item as tradeState "inactive"
Q2 is LIVE-CONFIRMED (operator saw the inactive row under TRANSFER LIST with Start Price 0 and no Buy Now / Current Bid / timer, active rows still separate under LISTED ITEMS, and the state survived a full FUT exit/re-entry). Promoting from the bounded one-item probe to the real behaviour: the env gate is gone and /tradePile now enumerates the whole trade pile. Mechanism: read the pile (async), resolve each member to a shaped card (sync, because the identity/Core resolvers are not `Send`), then build the response (async). The core->wire lookup is `wire_for_owned_id`, which uses the identity store's NON-allocating `external_for` -- enumerating a pile is a READ and must never mint a wire id for an item the client has not seen. Items with no mapping, no Core record or no resolvable FIFA identity are skipped, never faked. Includes a bug the DIFFERENTIAL caught and unit tests did not: a pile row OUTLIVES its auction, so after a sale the seller's `trade` row is stale, and filtering only on ACTIVE listings re-advertised a SOLD card as an owned unlisted item. Suppression is now by listing state via `blocking_core_items()` -- active (real auction shown instead), reserved (sale in flight) and sold (card gone) -- while `cancelled` is deliberately NOT suppressed, because a cancelled listing means the card came back to the pile. New test covers all three plus the store-level rule. counts semantics deliberately unchanged: `count`/`selling` still track auctions only. 341 tests pass, 0 failed, clippy clean. Deployed: the 6 previously stranded pile items now render, alongside the 1 active listing, with Ronaldo correctly in /club and out of the pile. Body preserved as phase-c-full-pile-exposed.json.
This commit is contained in:
+142
-60
@@ -279,27 +279,48 @@ pub struct UnlistedCandidate {
|
||||
pub item_json: Option<String>,
|
||||
}
|
||||
|
||||
/// Resolve ONE wire item id to an [`UnlistedCandidate`]. Pure identity plus a single
|
||||
/// Core inventory read, so it runs OFF the async runtime exactly like
|
||||
/// [`resolve_market_list`] (the trait-object resolvers are not `Send`).
|
||||
pub fn resolve_unlisted_candidate<E: ReverseEntityResolver>(
|
||||
item_id: i64,
|
||||
reverse: &dyn SquadWireResolver,
|
||||
/// Resolve every Core owned instance sitting in the trade pile to an
|
||||
/// [`UnlistedCandidate`]. Pure identity plus one Core inventory read each, so it runs
|
||||
/// OFF the async runtime exactly like [`resolve_market_list`] (the trait-object
|
||||
/// resolvers are not `Send`).
|
||||
///
|
||||
/// `wire_for_core` MUST be a non-allocating lookup: enumerating a pile is a READ, and
|
||||
/// minting a wire id for an item the client has never seen would silently consume
|
||||
/// identities. An item with no existing mapping, no Core record, or no resolvable
|
||||
/// FIFA identity is skipped rather than faked.
|
||||
pub fn resolve_unlisted_pile<E, F>(
|
||||
core_ids: &[String],
|
||||
wire_for_core: F,
|
||||
resolver: &dyn ItemIdentityResolver,
|
||||
items: &dyn OwnedItemLookup,
|
||||
ent: &E,
|
||||
) -> Option<UnlistedCandidate> {
|
||||
let core_id = reverse.owned_id_for_wire(item_id)?;
|
||||
let owned = items.owned_item(&core_id)?;
|
||||
let item_json = resolver
|
||||
.resolve(&owned)
|
||||
.map(|id| shape_item(&owned, id, ent))
|
||||
.and_then(|card| serde_json::to_string(&card).ok());
|
||||
Some(UnlistedCandidate {
|
||||
item_id,
|
||||
core_id,
|
||||
item_json,
|
||||
})
|
||||
) -> Vec<UnlistedCandidate>
|
||||
where
|
||||
E: ReverseEntityResolver,
|
||||
F: Fn(&str) -> Option<i64>,
|
||||
{
|
||||
let mut out = Vec::with_capacity(core_ids.len());
|
||||
for core_id in core_ids {
|
||||
let Some(item_id) = wire_for_core(core_id) else {
|
||||
continue;
|
||||
};
|
||||
let Some(owned) = items.owned_item(core_id) else {
|
||||
continue;
|
||||
};
|
||||
let Some(item_json) = resolver
|
||||
.resolve(&owned)
|
||||
.map(|id| shape_item(&owned, id, ent))
|
||||
.and_then(|card| serde_json::to_string(&card).ok())
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
out.push(UnlistedCandidate {
|
||||
item_id,
|
||||
core_id: core_id.clone(),
|
||||
item_json: Some(item_json),
|
||||
});
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// The auction record for an item sitting in the trade pile with NO auction.
|
||||
@@ -463,8 +484,7 @@ pub async fn handle_market_query(
|
||||
state: &str,
|
||||
econ: &dyn CoreEconomy,
|
||||
store: &MarketStore,
|
||||
piles: &PileStore,
|
||||
unlisted: Option<&UnlistedCandidate>,
|
||||
unlisted: &[UnlistedCandidate],
|
||||
) -> WireResponse {
|
||||
let listings = match store.query_listings(state).await {
|
||||
Ok(l) => l,
|
||||
@@ -475,27 +495,27 @@ pub async fn handle_market_query(
|
||||
.map(|l| auction_record_as(l, "listFS"))
|
||||
.collect();
|
||||
|
||||
// BOUNDED Q2 EXPERIMENT: expose ONE unlisted trade-pile item as a non-active
|
||||
// record. Every precondition is re-checked here so the row can never contradict
|
||||
// the auction state: the item must actually be in the `trade` pile, and it must
|
||||
// NOT already own a listing (otherwise it would duplicate a real auction).
|
||||
if let Some(c) = unlisted {
|
||||
let in_trade_pile = matches!(piles.get(&c.core_id).await, Ok(Some(p)) if p == "trade");
|
||||
let already_listed = listings
|
||||
.iter()
|
||||
.any(|l| l.core_item_id.as_deref() == Some(c.core_id.as_str()));
|
||||
if in_trade_pile && !already_listed {
|
||||
auctions.push(unlisted_record(c));
|
||||
eprintln!(
|
||||
"utas-host owner=RUST route=market-query unlisted_candidate item_id={} state=inactive",
|
||||
c.item_id
|
||||
);
|
||||
} else {
|
||||
eprintln!(
|
||||
"utas-host owner=RUST route=market-query unlisted_candidate item_id={} skipped in_pile={in_trade_pile} listed={already_listed}",
|
||||
c.item_id
|
||||
);
|
||||
// Unlisted trade-pile members, as LIVE-CONFIRMED `tradeState: "inactive"` rows.
|
||||
// The caller enumerates them FROM the pile, so membership is established; what
|
||||
// must still be excluded is any item whose listing state forbids advertising it as
|
||||
// an owned unlisted card. A pile row OUTLIVES its auction, so after a sale the
|
||||
// seller's `trade` row is stale — filtering on the active set alone would
|
||||
// re-advertise a SOLD card as an unlisted item (caught by the differential).
|
||||
let blocked = store.blocking_core_items().await.unwrap_or_default();
|
||||
let mut inactive = 0usize;
|
||||
for c in unlisted {
|
||||
if blocked.contains(&c.core_id) {
|
||||
continue;
|
||||
}
|
||||
auctions.push(unlisted_record(c));
|
||||
inactive += 1;
|
||||
}
|
||||
if !unlisted.is_empty() {
|
||||
eprintln!(
|
||||
"utas-host owner=RUST route=market-query active={} inactive={inactive} pile_candidates={}",
|
||||
listings.len(),
|
||||
unlisted.len()
|
||||
);
|
||||
}
|
||||
|
||||
// GetTradePile shares one deserializer (0x18013e7f0) with ISSearch and
|
||||
@@ -974,14 +994,6 @@ mod tests {
|
||||
(store, db)
|
||||
}
|
||||
|
||||
/// An empty pile store on its own temp file, for tradePile tests that do not
|
||||
/// exercise the unlisted candidate.
|
||||
async fn empty_piles() -> (PileStore, TempDb) {
|
||||
let db = TempDb::new("piles");
|
||||
let piles = PileStore::open(db.path()).await.unwrap();
|
||||
(piles, db)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn unlisted_candidate_is_a_non_active_pile_row() {
|
||||
// Q2: an item in the trade pile with NO auction. The route table has exactly
|
||||
@@ -990,7 +1002,6 @@ mod tests {
|
||||
// lifecycle — whose PE string table is `active/inactive/expired/closed`. So
|
||||
// the row must be `inactive`, with no timer and no prices.
|
||||
let (store, _d) = store_at("unlisted").await;
|
||||
let (piles, _pd) = empty_piles().await;
|
||||
let econ = CountingEconomy::with_balance(10_000);
|
||||
let c = UnlistedCandidate {
|
||||
item_id: 100_000_059,
|
||||
@@ -998,16 +1009,15 @@ mod tests {
|
||||
item_json: Some(r#"{"rating":93,"preferredPosition":"RW"}"#.into()),
|
||||
};
|
||||
|
||||
// Not in the trade pile yet -> deliberately NOT exposed.
|
||||
let body = parse(&handle_market_query("active", &econ, &store, &piles, Some(&c)).await);
|
||||
// No candidates supplied -> nothing extra is advertised.
|
||||
let body = parse(&handle_market_query("active", &econ, &store, &[]).await);
|
||||
assert_eq!(
|
||||
body["auctionInfo"].as_array().unwrap().len(),
|
||||
0,
|
||||
"an item that is not in the trade pile must never be advertised as one"
|
||||
"an empty candidate set adds nothing"
|
||||
);
|
||||
|
||||
piles.set("core-unlisted", "trade").await.unwrap();
|
||||
let body = parse(&handle_market_query("active", &econ, &store, &piles, Some(&c)).await);
|
||||
let body = parse(&handle_market_query("active", &econ, &store, std::slice::from_ref(&c)).await);
|
||||
let recs = body["auctionInfo"].as_array().unwrap();
|
||||
assert_eq!(recs.len(), 1, "now in the pile, so it is exposed");
|
||||
let r = &recs[0];
|
||||
@@ -1034,7 +1044,6 @@ mod tests {
|
||||
// If the item already owns a listing, advertising it as `inactive` too would
|
||||
// put two records with the same tradeId in one body.
|
||||
let (store, _d) = store_at("unlistedduped").await;
|
||||
let (piles, _pd) = empty_piles().await;
|
||||
let econ = CountingEconomy::with_balance(10_000);
|
||||
store
|
||||
.create_listing(
|
||||
@@ -1051,18 +1060,91 @@ mod tests {
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
piles.set("core-unlisted", "trade").await.unwrap();
|
||||
let c = UnlistedCandidate {
|
||||
item_id: 100_000_059,
|
||||
core_id: "core-unlisted".into(),
|
||||
item_json: None,
|
||||
};
|
||||
let body = parse(&handle_market_query("active", &econ, &store, &piles, Some(&c)).await);
|
||||
let body = parse(&handle_market_query("active", &econ, &store, std::slice::from_ref(&c)).await);
|
||||
let recs = body["auctionInfo"].as_array().unwrap();
|
||||
assert_eq!(recs.len(), 1, "the real auction only");
|
||||
assert_eq!(recs[0]["tradeState"], "active");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_sold_or_in_flight_card_is_never_advertised_as_an_unlisted_member() {
|
||||
// A pile row OUTLIVES its auction: after a sale the seller's `trade` row is
|
||||
// stale. Filtering only on ACTIVE listings therefore re-advertised a SOLD card
|
||||
// as an owned unlisted item — caught by the differential, not by unit tests,
|
||||
// because it needs the full list -> sell -> poll sequence.
|
||||
let (store, _d) = store_at("soldpile").await;
|
||||
let econ = CountingEconomy::with_balance(10_000);
|
||||
let mk = |id: &str, core: &str| {
|
||||
let store = store.clone();
|
||||
let (id, core) = (id.to_string(), core.to_string());
|
||||
async move {
|
||||
store
|
||||
.create_listing(
|
||||
&id,
|
||||
"169193",
|
||||
Some(&core),
|
||||
None,
|
||||
None,
|
||||
150,
|
||||
2500,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
};
|
||||
mk("900000070", "core-sold").await;
|
||||
mk("900000071", "core-inflight").await;
|
||||
mk("900000072", "core-cancelled").await;
|
||||
store.reserve_listing("900000070").await.unwrap();
|
||||
store.complete_sale("900000070").await.unwrap();
|
||||
store.reserve_listing("900000071").await.unwrap();
|
||||
store.cancel_listing("900000072", None).await.unwrap();
|
||||
|
||||
let cands: Vec<UnlistedCandidate> = ["core-sold", "core-inflight", "core-cancelled"]
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, core)| UnlistedCandidate {
|
||||
item_id: 100_000_200 + i as i64,
|
||||
core_id: (*core).to_string(),
|
||||
item_json: None,
|
||||
})
|
||||
.collect();
|
||||
|
||||
let body = parse(&handle_market_query("active", &econ, &store, &cands).await);
|
||||
let recs = body["auctionInfo"].as_array().unwrap();
|
||||
let states: Vec<&str> = recs
|
||||
.iter()
|
||||
.map(|r| r["tradeState"].as_str().unwrap())
|
||||
.collect();
|
||||
assert_eq!(
|
||||
states,
|
||||
vec!["inactive"],
|
||||
"only the CANCELLED card returns to the pile as unlisted; sold and \
|
||||
in-flight cards must not be advertised as owned"
|
||||
);
|
||||
assert_eq!(
|
||||
recs[0]["itemData"]["id"], 100_000_202i64,
|
||||
"and it is specifically the cancelled one"
|
||||
);
|
||||
|
||||
// The store-level rule, asserted directly.
|
||||
let blocked = store.blocking_core_items().await.unwrap();
|
||||
assert!(blocked.contains("core-sold"));
|
||||
assert!(blocked.contains("core-inflight"));
|
||||
assert!(
|
||||
!blocked.contains("core-cancelled"),
|
||||
"a cancelled listing means the card is back in the pile"
|
||||
);
|
||||
}
|
||||
|
||||
async fn seed_listing(store: &MarketStore, id: &str, buy_now: i64) {
|
||||
store
|
||||
.create_listing(id, "169193", None, None, Some(169193), 400, buy_now, None, None, None)
|
||||
@@ -1114,7 +1196,7 @@ mod tests {
|
||||
assert_eq!(snap["preferredPosition"], "ST");
|
||||
assert_eq!(snap["attributeList"].as_array().unwrap().len(), 6);
|
||||
// tradePile embeds that full card and stamps the seller-pile state.
|
||||
let pile = handle_market_query("active", &econ, &store, &empty_piles().await.0, None).await;
|
||||
let pile = handle_market_query("active", &econ, &store, &[]).await;
|
||||
let rec = parse(&pile)["auctionInfo"][0].clone();
|
||||
assert_eq!(rec["itemData"]["itemState"], "listFS");
|
||||
assert_eq!(rec["itemData"]["rating"], 84);
|
||||
@@ -1211,7 +1293,7 @@ mod tests {
|
||||
let (store, _d) = store_at("query").await;
|
||||
seed_listing(&store, "900000005", 2500).await;
|
||||
let econ = CountingEconomy::with_balance(50);
|
||||
let resp = handle_market_query("active", &econ, &store, &empty_piles().await.0, None).await;
|
||||
let resp = handle_market_query("active", &econ, &store, &[]).await;
|
||||
let b = parse(&resp);
|
||||
assert_eq!(b["auctionInfo"].as_array().unwrap().len(), 1);
|
||||
assert_eq!(b["auctionInfo"][0]["tradeId"], 900000005i64);
|
||||
@@ -1261,7 +1343,7 @@ mod tests {
|
||||
let econ = CountingEconomy::with_balance(10_000);
|
||||
seed_listing(&store, "900000030", 2500).await;
|
||||
|
||||
let body = parse(&handle_market_query("active", &econ, &store, &empty_piles().await.0, None).await);
|
||||
let body = parse(&handle_market_query("active", &econ, &store, &[]).await);
|
||||
let rec = body["auctionInfo"][0].clone();
|
||||
let mut got: Vec<&str> = rec.as_object().unwrap().keys().map(String::as_str).collect();
|
||||
got.sort_unstable();
|
||||
|
||||
Reference in New Issue
Block a user