Deploy AIOS web (React glide grid + FastAPI slice)
Browse files- RELEASES.json +1 -1
- VERSION +1 -1
- platform/harness/amazon_store.py +155 -15
- web/public/AIOS_DEPLOY_RECEIPT +1 -1
RELEASES.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
{
|
| 2 |
-
"current": "
|
| 3 |
"releases": []
|
| 4 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"current": "cf8ee97b45",
|
| 3 |
"releases": []
|
| 4 |
}
|
VERSION
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
cf8ee97b45
|
platform/harness/amazon_store.py
CHANGED
|
@@ -7577,12 +7577,15 @@ def _history_cut_tasks(tasks, table, period, end):
|
|
| 7577 |
and task[2] <= end and _history_task_period(task) == period)
|
| 7578 |
|
| 7579 |
|
| 7580 |
-
def _record_reconciliation(con, table, marker):
|
| 7581 |
-
"""Keep the most recent landed period, even while backfill travels backwards.
|
|
|
|
|
|
|
|
|
|
| 7582 |
key = entity_key("reconcile_" + table)
|
| 7583 |
previous = _read_state(con, key)
|
| 7584 |
old = json.loads(previous["detail"]) if previous and previous.get("detail") else {}
|
| 7585 |
-
if marker["end"] >= old.get("end", ""):
|
| 7586 |
_record_state(con, key, "done", detail=json.dumps(marker, separators=(",", ":")))
|
| 7587 |
|
| 7588 |
|
|
@@ -7874,6 +7877,36 @@ def document_row_count(text, roots=()):
|
|
| 7874 |
return sum(bool(raw) and not (len(raw) == 1 and not str(raw[0]).strip()) for raw in reader)
|
| 7875 |
|
| 7876 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7877 |
def _ledger_date(value):
|
| 7878 |
"""The DAILY ledger uses US dates; normalize dates without inventing a report date."""
|
| 7879 |
value = str(value or "").strip()
|
|
@@ -7949,7 +7982,7 @@ def _snapshot_identity(table, row):
|
|
| 7949 |
return identity
|
| 7950 |
|
| 7951 |
|
| 7952 |
-
def _replace_legacy_snapshot(con, table, columns, rows, meta, source_count):
|
| 7953 |
"""Replace the whole FBA snapshot with one parsed document, preserving the separate AWD leg.
|
| 7954 |
|
| 7955 |
Listings is a catalogue as of the vendor's data/creation date. The ledger is a DAILY
|
|
@@ -7957,6 +7990,9 @@ def _replace_legacy_snapshot(con, table, columns, rows, meta, source_count):
|
|
| 7957 |
Duplicate source identities refuse the whole document rather than silently dropping rows.
|
| 7958 |
S67-T32 (D-3031): one copy. The document's dates replace every earlier date, so the table
|
| 7959 |
holds exactly one pull, the row count a fresh first load would store.
|
|
|
|
|
|
|
|
|
|
| 7960 |
"""
|
| 7961 |
stamp = meta.get("dataEndTime") or meta.get("dataStartTime") or meta.get("createdTime")
|
| 7962 |
if not stamp and (table == "listings" or not rows):
|
|
@@ -7982,17 +8018,31 @@ def _replace_legacy_snapshot(con, table, columns, rows, meta, source_count):
|
|
| 7982 |
total += 1
|
| 7983 |
if total != source_count:
|
| 7984 |
raise ValueError(f"Amazon {table} snapshot row count differs from its document")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7985 |
if not counts:
|
| 7986 |
counts[_utc(stamp).date().isoformat()] = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7987 |
columns = sorted(set(columns) | {"_snapshot_date"}
|
| 7988 |
| (rows.keys() if lazy else {k for row in rows for k in row}))
|
| 7989 |
if table == "inventory":
|
| 7990 |
columns = sorted(set(columns) | {"inventory_source"})
|
| 7991 |
mirror = table_name(table)
|
| 7992 |
types = _ensure(con, mirror, columns, rows, preserve_rows=True)
|
| 7993 |
-
dates = sorted(counts)
|
| 7994 |
marker = {"start": dates[0], "end": dates[-1], "column": "_snapshot_date",
|
| 7995 |
-
"count":
|
|
|
|
|
|
|
|
|
|
| 7996 |
marker.update({key: meta[key] for key in ("reportId", "processingStatus") if meta.get(key)})
|
| 7997 |
if table == "inventory" and meta.get("cancelled") is True and meta.get("processingStatus") == "CANCELLED":
|
| 7998 |
marker["cancelled"] = True
|
|
@@ -8008,7 +8058,8 @@ def _replace_legacy_snapshot(con, table, columns, rows, meta, source_count):
|
|
| 8008 |
# The ledger keeps every daily snapshot as changes, oldest date first.
|
| 8009 |
for day in dates if history else ():
|
| 8010 |
_history_merge(con, table, day, f"({predicate}) AND CAST(_snapshot_date AS VARCHAR) = ?", [day])
|
| 8011 |
-
|
|
|
|
| 8012 |
con.execute("COMMIT")
|
| 8013 |
return count
|
| 8014 |
except Exception:
|
|
@@ -9097,9 +9148,10 @@ def _sync_margin_window(con, table, fields, w0, w1, *, max_wait, log, operations
|
|
| 9097 |
return count
|
| 9098 |
kwargs = {} if spec.get("snapshot") else {
|
| 9099 |
"start": _iso(w0), "end": _iso(w1 - timedelta(seconds=1))}
|
|
|
|
| 9100 |
if spec.get("dated_snapshot"):
|
| 9101 |
-
|
| 9102 |
-
|
| 9103 |
options = dict(spec.get("options") or {})
|
| 9104 |
if spec.get("period"):
|
| 9105 |
options["reportPeriod"] = spec["period"]
|
|
@@ -9132,7 +9184,8 @@ def _sync_margin_window(con, table, fields, w0, w1, *, max_wait, log, operations
|
|
| 9132 |
columns, rows = parse_flat_file(text, **parser_args)
|
| 9133 |
rows = normalise_app_dates(table, rows)
|
| 9134 |
if table in LEGACY_SNAPSHOT_TABLES:
|
| 9135 |
-
return _replace_legacy_snapshot(con, table, columns, rows, meta, document_row_count(text)
|
|
|
|
| 9136 |
if spec.get("snapshot"):
|
| 9137 |
stamp = meta.get("dataEndTime") or meta.get("dataStartTime") or meta.get("createdTime")
|
| 9138 |
if not stamp:
|
|
@@ -11876,6 +11929,90 @@ def inventory_status_selftest(log=print, check=None):
|
|
| 11876 |
return len(failures)
|
| 11877 |
|
| 11878 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11879 |
def snapshot_selftest(log=print, check=None):
|
| 11880 |
"""S66-T47: real sync with in-memory storage and fixture-only vendor transports."""
|
| 11881 |
from unittest.mock import patch
|
|
@@ -11957,8 +12094,9 @@ def snapshot_selftest(log=print, check=None):
|
|
| 11957 |
len(calls) == 1 and (("start" in calls[0] and "end" in calls[0]) if table == "inventory"
|
| 11958 |
else ("start" not in calls[0] and "end" not in calls[0]))
|
| 11959 |
and result["state"] == "done" and result["remaining"] == 0)
|
|
|
|
| 11960 |
ck(table + " all document rows reconcile", lambda:
|
| 11961 |
-
count() == (2 if table == "listings" else
|
| 11962 |
ck(table + " real sync publishes attributed rows and a durable snapshot", lambda:
|
| 11963 |
bool(datastore._publication(con, "amazon").get("snapshot_id"))
|
| 11964 |
and bool(rt.blobs.get(MIRROR_PREFIX + _MANIFEST_KEY))
|
|
@@ -11996,9 +12134,10 @@ def snapshot_selftest(log=print, check=None):
|
|
| 11996 |
"ORDER BY 1, 2").fetchall() == [("2026-09-26", "A", 9)]
|
| 11997 |
and valid()["state"] == "ok")
|
| 11998 |
else:
|
| 11999 |
-
ck("ledger keeps
|
| 12000 |
con.execute("SELECT COUNT(*), COUNT(DISTINCT (date, msku, disposition, location)), "
|
| 12001 |
-
"COUNT(DISTINCT _snapshot_date)
|
|
|
|
| 12002 |
and calls[0].get("options", {}).get("aggregateByTimePeriod") == "DAILY")
|
| 12003 |
payload[0] = ledger_header + "09/24/2026\tA\tFA\tAA\tSELLABLE\tUS\t9\n"
|
| 12004 |
sync(rt.key, tables=[table], since=start, rt=rt, log=lambda *_a: None)
|
|
@@ -12056,6 +12195,8 @@ def snapshot_selftest(log=print, check=None):
|
|
| 12056 |
"WHERE inventory_source='FBA'").fetchall() == [(9,)])
|
| 12057 |
con.close()
|
| 12058 |
ck("inventory request retention and empty-source controls", lambda: inventory_status_selftest(log, check) == 0)
|
|
|
|
|
|
|
| 12059 |
ck("S67-T32 saved mirror: one copy, content keys, kill-safe checkpoint, full purge",
|
| 12060 |
lambda: mirror_selftest(log, check) == 0)
|
| 12061 |
return len(failures)
|
|
@@ -12323,8 +12464,7 @@ def snapshot_sync_selftest(log=print, check=None):
|
|
| 12323 |
and Counter(table for table, _kwargs in resync_calls if table in ("orders", "transactions"))
|
| 12324 |
== {"orders": 3, "transactions": 3})
|
| 12325 |
ck("snapshot transports use no backfill window except the declared ledger day", lambda:
|
| 12326 |
-
all(
|
| 12327 |
-
and kwargs.get("end") == _iso(Clock.instant.replace(hour=0) - timedelta(seconds=1)))
|
| 12328 |
if cx.REPORT_TYPES[table].get("dated_snapshot") else
|
| 12329 |
kwargs.get("start") is None and kwargs.get("end") is None
|
| 12330 |
for table, kwargs in resync_calls if table in snapshots))
|
|
|
|
| 7577 |
and task[2] <= end and _history_task_period(task) == period)
|
| 7578 |
|
| 7579 |
|
| 7580 |
+
def _record_reconciliation(con, table, marker, replace=False):
|
| 7581 |
+
"""Keep the most recent landed period, even while backfill travels backwards.
|
| 7582 |
+
|
| 7583 |
+
`replace`: the table now holds only this marker's rows, so its proof always wins.
|
| 7584 |
+
"""
|
| 7585 |
key = entity_key("reconcile_" + table)
|
| 7586 |
previous = _read_state(con, key)
|
| 7587 |
old = json.loads(previous["detail"]) if previous and previous.get("detail") else {}
|
| 7588 |
+
if replace or marker["end"] >= old.get("end", ""):
|
| 7589 |
_record_state(con, key, "done", detail=json.dumps(marker, separators=(",", ":")))
|
| 7590 |
|
| 7591 |
|
|
|
|
| 7877 |
return sum(bool(raw) and not (len(raw) == 1 and not str(raw[0]).strip()) for raw in reader)
|
| 7878 |
|
| 7879 |
|
| 7880 |
+
#: D-18058: a ledger date is a US Pacific day, and Amazon returns no summary rows for an open day.
|
| 7881 |
+
LEDGER_TIMEZONE = "America/Los_Angeles"
|
| 7882 |
+
#: Closed Pacific days one summary request covers, so a day Amazon has not finished falls back a day.
|
| 7883 |
+
LEDGER_LOOKBACK_DAYS = 3
|
| 7884 |
+
|
| 7885 |
+
|
| 7886 |
+
def _ledger_days(now):
|
| 7887 |
+
"""`(first, newest)` closed Pacific ledger dates as of `now`."""
|
| 7888 |
+
from zoneinfo import ZoneInfo # noqa: PLC0415
|
| 7889 |
+
|
| 7890 |
+
newest = now.astimezone(ZoneInfo(LEDGER_TIMEZONE)).date() - timedelta(days=1)
|
| 7891 |
+
return newest - timedelta(days=LEDGER_LOOKBACK_DAYS - 1), newest
|
| 7892 |
+
|
| 7893 |
+
|
| 7894 |
+
def _ledger_window(now):
|
| 7895 |
+
"""The summary request for the newest closed Pacific ledger days, never the open day."""
|
| 7896 |
+
first, newest = _ledger_days(now)
|
| 7897 |
+
return {"start": f"{first.isoformat()}T00:00:00Z", "end": f"{newest.isoformat()}T23:59:59Z"}
|
| 7898 |
+
|
| 7899 |
+
|
| 7900 |
+
def _ledger_detail_rows(con, first, last):
|
| 7901 |
+
"""Ledger detail rows dated `first` to `last`, or None when no detail mirror exists."""
|
| 7902 |
+
mirror = table_name("inventory_ledger_detail")
|
| 7903 |
+
if "date" not in _columns_of(con, mirror):
|
| 7904 |
+
return None
|
| 7905 |
+
return int(con.execute(
|
| 7906 |
+
f"SELECT COUNT(*) FROM {mirror} WHERE CAST(\"date\" AS VARCHAR) BETWEEN ? AND ?",
|
| 7907 |
+
[first, last]).fetchone()[0])
|
| 7908 |
+
|
| 7909 |
+
|
| 7910 |
def _ledger_date(value):
|
| 7911 |
"""The DAILY ledger uses US dates; normalize dates without inventing a report date."""
|
| 7912 |
value = str(value or "").strip()
|
|
|
|
| 7982 |
return identity
|
| 7983 |
|
| 7984 |
|
| 7985 |
+
def _replace_legacy_snapshot(con, table, columns, rows, meta, source_count, window=None):
|
| 7986 |
"""Replace the whole FBA snapshot with one parsed document, preserving the separate AWD leg.
|
| 7987 |
|
| 7988 |
Listings is a catalogue as of the vendor's data/creation date. The ledger is a DAILY
|
|
|
|
| 7990 |
Duplicate source identities refuse the whole document rather than silently dropping rows.
|
| 7991 |
S67-T32 (D-3031): one copy. The document's dates replace every earlier date, so the table
|
| 7992 |
holds exactly one pull, the row count a fresh first load would store.
|
| 7993 |
+
D-18058: a multi-day ledger document keeps only its newest date. `window` is the requested
|
| 7994 |
+
`(first, last)` ledger dates: an empty summary while the ledger detail holds rows for them
|
| 7995 |
+
refuses, so the last published rows stay.
|
| 7996 |
"""
|
| 7997 |
stamp = meta.get("dataEndTime") or meta.get("dataStartTime") or meta.get("createdTime")
|
| 7998 |
if not stamp and (table == "listings" or not rows):
|
|
|
|
| 8018 |
total += 1
|
| 8019 |
if total != source_count:
|
| 8020 |
raise ValueError(f"Amazon {table} snapshot row count differs from its document")
|
| 8021 |
+
if table == "inventory" and not total and window:
|
| 8022 |
+
detail = _ledger_detail_rows(con, *window)
|
| 8023 |
+
if detail:
|
| 8024 |
+
raise ValueError(
|
| 8025 |
+
f"Amazon returned no FBA ledger summary rows for {window[0]} to {window[1]} while the "
|
| 8026 |
+
f"ledger detail holds {detail} rows for those days, so the last inventory rows are kept. "
|
| 8027 |
+
"Retry Amazon sync after Amazon finishes those days")
|
| 8028 |
if not counts:
|
| 8029 |
counts[_utc(stamp).date().isoformat()] = 0
|
| 8030 |
+
kept = max(counts) if table == "inventory" and len(counts) > 1 else None
|
| 8031 |
+
if kept:
|
| 8032 |
+
rows = (rows.pipe(lambda found: (row for row in found if row["_snapshot_date"] == kept)) if lazy
|
| 8033 |
+
else [row for row in rows if row["_snapshot_date"] == kept])
|
| 8034 |
columns = sorted(set(columns) | {"_snapshot_date"}
|
| 8035 |
| (rows.keys() if lazy else {k for row in rows for k in row}))
|
| 8036 |
if table == "inventory":
|
| 8037 |
columns = sorted(set(columns) | {"inventory_source"})
|
| 8038 |
mirror = table_name(table)
|
| 8039 |
types = _ensure(con, mirror, columns, rows, preserve_rows=True)
|
| 8040 |
+
dates = [kept] if kept else sorted(counts)
|
| 8041 |
marker = {"start": dates[0], "end": dates[-1], "column": "_snapshot_date",
|
| 8042 |
+
"count": counts[kept] if kept else source_count,
|
| 8043 |
+
"dates": {kept: counts[kept]} if kept else counts, "document": meta.get("reportDocumentId")}
|
| 8044 |
+
if kept:
|
| 8045 |
+
marker.update(documentCount=source_count, documentDates=counts)
|
| 8046 |
marker.update({key: meta[key] for key in ("reportId", "processingStatus") if meta.get(key)})
|
| 8047 |
if table == "inventory" and meta.get("cancelled") is True and meta.get("processingStatus") == "CANCELLED":
|
| 8048 |
marker["cancelled"] = True
|
|
|
|
| 8058 |
# The ledger keeps every daily snapshot as changes, oldest date first.
|
| 8059 |
for day in dates if history else ():
|
| 8060 |
_history_merge(con, table, day, f"({predicate}) AND CAST(_snapshot_date AS VARCHAR) = ?", [day])
|
| 8061 |
+
# D-18058: a closed Pacific day can be older than the last open-day empty proof.
|
| 8062 |
+
_record_reconciliation(con, table, marker, replace=True)
|
| 8063 |
con.execute("COMMIT")
|
| 8064 |
return count
|
| 8065 |
except Exception:
|
|
|
|
| 9148 |
return count
|
| 9149 |
kwargs = {} if spec.get("snapshot") else {
|
| 9150 |
"start": _iso(w0), "end": _iso(w1 - timedelta(seconds=1))}
|
| 9151 |
+
ledger_window = None
|
| 9152 |
if spec.get("dated_snapshot"):
|
| 9153 |
+
kwargs = _ledger_window(datetime.now(timezone.utc))
|
| 9154 |
+
ledger_window = (kwargs["start"][:10], kwargs["end"][:10])
|
| 9155 |
options = dict(spec.get("options") or {})
|
| 9156 |
if spec.get("period"):
|
| 9157 |
options["reportPeriod"] = spec["period"]
|
|
|
|
| 9184 |
columns, rows = parse_flat_file(text, **parser_args)
|
| 9185 |
rows = normalise_app_dates(table, rows)
|
| 9186 |
if table in LEGACY_SNAPSHOT_TABLES:
|
| 9187 |
+
return _replace_legacy_snapshot(con, table, columns, rows, meta, document_row_count(text),
|
| 9188 |
+
window=ledger_window)
|
| 9189 |
if spec.get("snapshot"):
|
| 9190 |
stamp = meta.get("dataEndTime") or meta.get("dataStartTime") or meta.get("createdTime")
|
| 9191 |
if not stamp:
|
|
|
|
| 11929 |
return len(failures)
|
| 11930 |
|
| 11931 |
|
| 11932 |
+
def ledger_window_selftest(log=print, check=None):
|
| 11933 |
+
"""D-18058: the ledger summary window, newest-date keep, and the empty-summary guard."""
|
| 11934 |
+
import duckdb
|
| 11935 |
+
failures = []
|
| 11936 |
+
|
| 11937 |
+
def ck(name, ok):
|
| 11938 |
+
if check:
|
| 11939 |
+
check("[ledger window] " + name, bool(ok))
|
| 11940 |
+
else:
|
| 11941 |
+
log(f" {'ok' if ok else 'FAIL'} {name}")
|
| 11942 |
+
if not ok:
|
| 11943 |
+
failures.append(name)
|
| 11944 |
+
|
| 11945 |
+
def at(stamp):
|
| 11946 |
+
return datetime.fromisoformat(stamp.replace("Z", "+00:00"))
|
| 11947 |
+
|
| 11948 |
+
days = {stamp: tuple(day.isoformat() for day in _ledger_days(at(stamp))) for stamp in (
|
| 11949 |
+
"2026-11-27T00:54:23Z", "2026-11-27T08:30:00Z", "2026-03-08T09:30:00Z",
|
| 11950 |
+
"2026-03-08T10:30:00Z", "2026-07-01T06:30:00Z", "2026-07-01T07:30:00Z")}
|
| 11951 |
+
ck("00:54Z asks closed Pacific days, never the open 11-26",
|
| 11952 |
+
days["2026-11-27T00:54:23Z"] == ("2026-11-23", "2026-11-25"))
|
| 11953 |
+
ck("after Pacific midnight the closed day joins", days["2026-11-27T08:30:00Z"] == ("2026-11-24", "2026-11-26"))
|
| 11954 |
+
ck("the spring DST change reads Pacific standard and daylight time",
|
| 11955 |
+
days["2026-03-08T09:30:00Z"][1] == "2026-03-07" and days["2026-03-08T10:30:00Z"][1] == "2026-03-07")
|
| 11956 |
+
ck("summer reads Pacific daylight time",
|
| 11957 |
+
days["2026-07-01T06:30:00Z"][1] == "2026-06-29" and days["2026-07-01T07:30:00Z"][1] == "2026-06-30")
|
| 11958 |
+
window = _ledger_window(at("2026-11-27T00:54:23Z"))
|
| 11959 |
+
ck("the request spans whole closed days",
|
| 11960 |
+
window == {"start": "2026-11-23T00:00:00Z", "end": "2026-11-25T23:59:59Z"})
|
| 11961 |
+
|
| 11962 |
+
header = "date\tmsku\tfnsku\tdisposition\tlocation\tending-warehouse-balance\n"
|
| 11963 |
+
|
| 11964 |
+
def landed(con, body, document, ledger=("2026-11-23", "2026-11-25")):
|
| 11965 |
+
columns, records = parse_flat_file(header + body, document_id=document,
|
| 11966 |
+
report_type="GET_LEDGER_SUMMARY_VIEW_DATA")
|
| 11967 |
+
meta = {"reportId": document, "processingStatus": "DONE", "reportDocumentId": document,
|
| 11968 |
+
"dataEndTime": "2026-11-25T23:59:59Z"}
|
| 11969 |
+
return _replace_legacy_snapshot(con, "inventory", columns, records, meta,
|
| 11970 |
+
document_row_count(header + body), window=ledger)
|
| 11971 |
+
|
| 11972 |
+
con = duckdb.connect(":memory:")
|
| 11973 |
+
try:
|
| 11974 |
+
con.execute("CREATE TABLE _sync_state (entity VARCHAR PRIMARY KEY, phase VARCHAR, "
|
| 11975 |
+
"last_id BIGINT, cursor_wd VARCHAR, rows BIGINT, updated_at VARCHAR)")
|
| 11976 |
+
# The old code's last proof: an empty open day dated after the closed day kept below.
|
| 11977 |
+
_record_state(con, "amzn_reconcile_inventory", "done", detail=json.dumps({
|
| 11978 |
+
"start": "2026-11-26", "end": "2026-11-26", "column": "_snapshot_date", "count": 0,
|
| 11979 |
+
"dates": {"2026-11-26": 0}, "document": "ledger-open-day"}))
|
| 11980 |
+
body = "".join(f"{day}\tS{i}\tF{i}\tSELLABLE\tUS\t{i + 1}\n"
|
| 11981 |
+
for day in ("11/23/2026", "11/24/2026", "11/25/2026") for i in range(3))
|
| 11982 |
+
landed(con, body, "ledger-three-days")
|
| 11983 |
+
rows = con.execute("SELECT CAST(_snapshot_date AS VARCHAR), COUNT(*) FROM amzn_inventory "
|
| 11984 |
+
"GROUP BY 1 ORDER BY 1").fetchall()
|
| 11985 |
+
marker = json.loads(_read_state(con, "amzn_reconcile_inventory")["detail"])
|
| 11986 |
+
ck("a three-day document keeps only its newest date", rows == [("2026-11-25", 3)])
|
| 11987 |
+
ck("the proof names the kept date and the whole document",
|
| 11988 |
+
marker["start"] == marker["end"] == "2026-11-25" and marker["count"] == 3
|
| 11989 |
+
and marker["documentCount"] == 9 and len(marker["documentDates"]) == 3)
|
| 11990 |
+
ck("the kept snapshot reconciles to its document",
|
| 11991 |
+
_validate_report_snapshot(con, "inventory", marker)["state"] == "ok")
|
| 11992 |
+
|
| 11993 |
+
con.execute("CREATE TABLE amzn_inventory_ledger_detail (date VARCHAR, msku VARCHAR)")
|
| 11994 |
+
con.execute("INSERT INTO amzn_inventory_ledger_detail VALUES ('2026-11-24', 'S1'), ('2026-11-01', 'S2')")
|
| 11995 |
+
try:
|
| 11996 |
+
landed(con, "", "ledger-empty-with-detail")
|
| 11997 |
+
refused = ""
|
| 11998 |
+
except ValueError as exc:
|
| 11999 |
+
refused = str(exc)
|
| 12000 |
+
ck("an empty summary refuses while the ledger detail shows those days",
|
| 12001 |
+
"ledger detail holds 1 rows" in refused and "last inventory rows are kept" in refused)
|
| 12002 |
+
ck("the refused empty summary keeps the last rows",
|
| 12003 |
+
con.execute("SELECT COUNT(*) FROM amzn_inventory").fetchone()[0] == 3)
|
| 12004 |
+
|
| 12005 |
+
con.execute("DELETE FROM amzn_inventory_ledger_detail WHERE date >= '2026-11-23'")
|
| 12006 |
+
landed(con, "", "ledger-truly-empty")
|
| 12007 |
+
marker = json.loads(_read_state(con, "amzn_reconcile_inventory")["detail"])
|
| 12008 |
+
ck("a truly empty seller still lands its empty proof",
|
| 12009 |
+
con.execute("SELECT COUNT(*) FROM amzn_inventory").fetchone()[0] == 0
|
| 12010 |
+
and marker["count"] == 0 and marker["dates"] == {"2026-11-25": 0})
|
| 12011 |
+
finally:
|
| 12012 |
+
con.close()
|
| 12013 |
+
return len(failures)
|
| 12014 |
+
|
| 12015 |
+
|
| 12016 |
def snapshot_selftest(log=print, check=None):
|
| 12017 |
"""S66-T47: real sync with in-memory storage and fixture-only vendor transports."""
|
| 12018 |
from unittest.mock import patch
|
|
|
|
| 12094 |
len(calls) == 1 and (("start" in calls[0] and "end" in calls[0]) if table == "inventory"
|
| 12095 |
else ("start" not in calls[0] and "end" not in calls[0]))
|
| 12096 |
and result["state"] == "done" and result["remaining"] == 0)
|
| 12097 |
+
# D-18058: a multi-date ledger document stores its newest date (3 of 4 fixture rows).
|
| 12098 |
ck(table + " all document rows reconcile", lambda:
|
| 12099 |
+
count() == (2 if table == "listings" else 3) and valid()["state"] == "ok")
|
| 12100 |
ck(table + " real sync publishes attributed rows and a durable snapshot", lambda:
|
| 12101 |
bool(datastore._publication(con, "amazon").get("snapshot_id"))
|
| 12102 |
and bool(rt.blobs.get(MIRROR_PREFIX + _MANIFEST_KEY))
|
|
|
|
| 12134 |
"ORDER BY 1, 2").fetchall() == [("2026-09-26", "A", 9)]
|
| 12135 |
and valid()["state"] == "ok")
|
| 12136 |
else:
|
| 12137 |
+
ck("ledger keeps its newest data date, one row per SKU, disposition and location", lambda:
|
| 12138 |
con.execute("SELECT COUNT(*), COUNT(DISTINCT (date, msku, disposition, location)), "
|
| 12139 |
+
"COUNT(DISTINCT _snapshot_date), MIN(CAST(_snapshot_date AS VARCHAR)) "
|
| 12140 |
+
"FROM amzn_inventory").fetchone() == (3, 3, 1, "2026-09-24")
|
| 12141 |
and calls[0].get("options", {}).get("aggregateByTimePeriod") == "DAILY")
|
| 12142 |
payload[0] = ledger_header + "09/24/2026\tA\tFA\tAA\tSELLABLE\tUS\t9\n"
|
| 12143 |
sync(rt.key, tables=[table], since=start, rt=rt, log=lambda *_a: None)
|
|
|
|
| 12195 |
"WHERE inventory_source='FBA'").fetchall() == [(9,)])
|
| 12196 |
con.close()
|
| 12197 |
ck("inventory request retention and empty-source controls", lambda: inventory_status_selftest(log, check) == 0)
|
| 12198 |
+
ck("D-18058 ledger summary asks closed Pacific days and an empty answer keeps rows",
|
| 12199 |
+
lambda: ledger_window_selftest(log, check) == 0)
|
| 12200 |
ck("S67-T32 saved mirror: one copy, content keys, kill-safe checkpoint, full purge",
|
| 12201 |
lambda: mirror_selftest(log, check) == 0)
|
| 12202 |
return len(failures)
|
|
|
|
| 12464 |
and Counter(table for table, _kwargs in resync_calls if table in ("orders", "transactions"))
|
| 12465 |
== {"orders": 3, "transactions": 3})
|
| 12466 |
ck("snapshot transports use no backfill window except the declared ledger day", lambda:
|
| 12467 |
+
all({"start": kwargs.get("start"), "end": kwargs.get("end")} == _ledger_window(Clock.instant)
|
|
|
|
| 12468 |
if cx.REPORT_TYPES[table].get("dated_snapshot") else
|
| 12469 |
kwargs.get("start") is None and kwargs.get("end") is None
|
| 12470 |
for table, kwargs in resync_calls if table in snapshots))
|
web/public/AIOS_DEPLOY_RECEIPT
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
44b1144b27ff7dfd033840544e7099a4f226be7252ab1792391ca2d4a6ef76b4
|