Open lesson

Mission: the blank operator box

Command palette

This mission workspace keeps code and notes in this browser tab. Export them before closing it. Running code is practice, not an automatic grade for the mission.

Brief

Write and apply a shape contract for supplier events, then explain what a version change may break.

Mara puts a supplier page in front of you. Voss insists, “the operator was the recruit.” Yet practice v2 row TRANSFER-7 lacks operator_id, while E8 has it. Imani must report what the delivery actually says without filling gaps for either side. In the story she waits for your check before a meeting; the lesson has no timer.

Your mission

  1. List the required fields and types in this v2 contract.
  2. Classify E8 and TRANSFER-7 using the validator and name the exact error.
  3. Explain why assigning your ID to the missing operator_id would be false.
  4. Say what to do if the supplier still sends a version 1 message.

How to check your work

  • schema_version is int; six other fields are nonempty text.
  • E8 passes; TRANSFER-7 lacks operator_id.
  • A guess about identity must not replace absent data.
  • Version 1 follows an explicit older rule or migration, not invented compliance.

Course example

REQUIRED = {
    "schema_version": int,
    "event_id": str,
    "event_type": str,
    "event_at": str,
    "vehicle_label": str,
    "operator_id": str,
    "source_file": str,
}

def check_event(event):
    if not isinstance(event, dict):
        return ["event must be an object"]
    errors = []
    for field, kind in REQUIRED.items():
        if field not in event:
            errors.append(f"missing {field}")
        elif type(event[field]) is not kind:
            errors.append(f"wrong type for {field}")
        elif kind is str and not event[field].strip():
            errors.append(f"empty {field}")
    if "schema_version" in event and event["schema_version"] != 2:
        errors.append("expected schema_version 2")
    return errors

complete = {
    "schema_version": 2, "event_id": "E8", "event_type": "TRANSFER",
    "event_at": "2026-04-12T21:25:00Z", "vehicle_label": "NOCTIS-01",
    "operator_id": "OP-17", "source_file": "supplier-page3.json"
}
critical = {**complete, "event_id": "TRANSFER-7"}
del critical["operator_id"]

print(check_event(complete))
print(check_event(critical))

Code

Use Tab to leave the editor. Ctrl+Enter runs the source. The lines beginning with # are task reminders. Python ignores them. Write your code beneath them.

Python console

Loading laboratory…

Explore Python or SQL here; this is not an operating-system shell.

This is a disposable browser experiment. The code run here is not recorded as a completed mission.

Each command starts a fresh disposable worker: it runs a captured copy of your current source, then your command with the lesson fixtures. Changes are discarded afterward. Commands never save source or award XP. Ctrl+Enter executes the command.

Virtual workspace files

Source and declarative assets are readable here without JavaScript. Python input files are created at runtime; SQL setup initializes the disposable database.

source.py

Current editor source. Inspection shows your current edits.

# List the required fields and types in this v2 contract.
# Classify E8 and TRANSFER-7 using the validator and name the exact error.
# Explain why assigning your ID to the missing operator_id would be false.
# Say what to do if the supplier still sends a version 1 message.

exemple.py

Declarative lesson asset; this is not a file created in the Python filesystem.

REQUIRED = {
    "schema_version": int,
    "event_id": str,
    "event_type": str,
    "event_at": str,
    "vehicle_label": str,
    "operator_id": str,
    "source_file": str,
}

def check_event(event):
    if not isinstance(event, dict):
        return ["event must be an object"]
    errors = []
    for field, kind in REQUIRED.items():
        if field not in event:
            errors.append(f"missing {field}")
        elif type(event[field]) is not kind:
            errors.append(f"wrong type for {field}")
        elif kind is str and not event[field].strip():
            errors.append(f"empty {field}")
    if "schema_version" in event and event["schema_version"] != 2:
        errors.append("expected schema_version 2")
    return errors

complete = {
    "schema_version": 2, "event_id": "E8", "event_type": "TRANSFER",
    "event_at": "2026-04-12T21:25:00Z", "vehicle_label": "NOCTIS-01",
    "operator_id": "OP-17", "source_file": "supplier-page3.json"
}
critical = {**complete, "event_id": "TRANSFER-7"}
del critical["operator_id"]

print(check_event(complete))
print(check_event(critical))