Cookwala / حزمة التطوير والسيناريوهات / 051

Report an anonymous incident to a catalog

Incident reports carry a date, a category, a severity, the operation and the safety limits that fired, and no names or ids, so every maker learns from each near miss. Send the example report and read the recall list it feeds.

الفئة: food safety officer · الهدف: صحة أفضل للناس, روبوتات في خدمة الناس · المستوى: beginner

اقرأ أولًا: /docs/CORE/ /docs/HUB/

الخطوات

  1. Submit the example report: oil reached 201 °C while a robot waited for a delivery; the oil.max_temp limit cut the heat. The catalog answers received. reportIncident

  2. Recalls are the catalog's other door: what it publishes after reviewing incidents. The reference hub publishes none. recalls

النتيجة

You have filed an incident that names no one. Next: scenario 052 reads a signed recall.

سطر الأوامر

cookwala hub --recipes examples --speed 200
curl -s -X POST http://localhost:7878/v1/incidents -H 'Content-Type: application/json' -H 'Idempotency-Key: inc-2026-0001' -d @examples/core/incident.json
curl -s http://localhost:7878/v1/recalls

المخرجات المسجلة

الحالة: ok

[1] reportIncident: {"received": true}
[2] recalls: []

الكود

التشغيل: python scenarios/out/051-report-an-incident/python.py

# Scenario 051: Report an anonymous incident to a catalog
# Incident reports carry a date, a category, a severity, the operation and the safety limits that fired, and no names or ids, so every maker learns from each near miss. Send the example report and read the recall list it feeds.
# Run a hub first: python hub/cookwala_hub.py --recipes examples
import json, os
from cookwala.client import CookwalaClient, CookwalaProblem

def load(path):
    with open(path, encoding="utf-8") as f:
        return json.load(f)

def pick(obj, path):
    for part in path.replace("]", "").replace("[", ".").split("."):
        obj = obj[int(part)] if part.isdigit() else (len(obj) if part == "length" else obj.get(part))
    return obj

c = CookwalaClient(os.environ.get("COOKWALA_HUB", "http://localhost:7878"))


# Step 1: Submit the example report: oil reached 201 °C while a robot waited for a delivery; the oil.max_temp limit cut the heat. The catalog answers received.
r = c.report_incident(load("examples/core/incident.json"))
assert pick(r, "received") == True, pick(r, "received")
print("ok", "received", "=", True)

# Step 2: Recalls are the catalog's other door: what it publishes after reviewing incidents. The reference hub publishes none.
recalls = c.recalls()
assert pick(recalls, "length") == 0, pick(recalls, "length")
print("ok", "length", "=", 0)

print("scenario complete")

scenarios/051-report-an-incident.json

السابق: 050 التالي: 052