{
 "use_case": "signed-lab-notebook",
 "title": "Rehearsal: signed lab notebook for a fictional enzyme-kinetics run",
 "about": "A fictional lab records a protocol and a plate-reader run with its rates file attached by SHA-256, asks the model to analyse the data (receipted), amends the run to exclude the planted outlier well F7 with a reason, and collects witness, review and approval signatures and an RFC 3161 timestamp. The exported record must verify, and a copy with one entry changed must not. The timestamp comes from FreeTSA, a free third-party authority: if it is down that step is skipped and nothing checks it.",
 "licence": "Synthetic: the lab, people, instrument and data are invented for Decosa; the rates come from a Michaelis-Menten curve (Vmax 118, Km 0.42 mM) with small noise and one deliberate outlier. Part of decosa-api, AGPL-3.0-or-later.",
 "inputs": [
  {
   "file": "inputs/notebook.json",
   "what": "The notebook: title, lab, project, description, owner {name, role}."
  },
  {
   "file": "inputs/member-1.json",
   "what": "A member who writes entries: {name, role}."
  },
  {
   "file": "inputs/member-2.json",
   "what": "A member who witnesses and reviews: {name, role}."
  },
  {
   "file": "inputs/entry-1-protocol.json",
   "what": "An entry: {title, text, author, attachments}."
  },
  {
   "file": "inputs/entry-2-plate-run.json",
   "what": "An entry with an instrument file attached by name, SHA-256, size and instrument details (the file itself is not uploaded)."
  },
  {
   "file": "inputs/rates.csv",
   "what": "The instrument export attached to entry 2 and sent to the analysis as text. Well F7 is the planted outlier."
  },
  {
   "file": "inputs/analysis-question.txt",
   "what": "The question for the AI analysis of the attached data."
  },
  {
   "file": "inputs/amendment.txt",
   "what": "The amended entry text."
  },
  {
   "file": "inputs/amendment-reason.txt",
   "what": "Why the entry is amended (required: the original stays in the record)."
  },
  {
   "file": "inputs/amendment-attachments.json",
   "what": "The corrected file attached to the amendment by SHA-256."
  },
  {
   "file": "inputs/rates-corrected.csv",
   "what": "The corrected rates without well F7 (hashed in amendment-attachments.json)."
  }
 ],
 "steps": [
  {
   "id": "book",
   "method": "POST",
   "path": "/notebook/books",
   "body": {
    "$file": "inputs/notebook.json"
   }
  },
  {
   "id": "member1",
   "method": "POST",
   "path": "/notebook/books/${book.notebook_id}/members",
   "body": {
    "$file": "inputs/member-1.json"
   }
  },
  {
   "id": "member2",
   "method": "POST",
   "path": "/notebook/books/${book.notebook_id}/members",
   "body": {
    "$file": "inputs/member-2.json"
   }
  },
  {
   "id": "protocol",
   "method": "POST",
   "path": "/notebook/books/${book.notebook_id}/entries",
   "body": {
    "$file": "inputs/entry-1-protocol.json"
   }
  },
  {
   "id": "run",
   "method": "POST",
   "path": "/notebook/books/${book.notebook_id}/entries",
   "body": {
    "$file": "inputs/entry-2-plate-run.json"
   }
  },
  {
   "id": "analysis",
   "method": "POST",
   "path": "/notebook/books/${book.notebook_id}/analysis",
   "timeout": 150,
   "body": {
    "question": {
     "$file": "inputs/analysis-question.txt"
    },
    "requested_by": "Dr. Maya Okafor",
    "of": [
     {
      "$ref": "protocol.entry.n"
     },
     {
      "$ref": "run.entry.n"
     }
    ],
    "data": [
     {
      "name": "rates.csv",
      "text": {
       "$file": "inputs/rates.csv"
      }
     }
    ]
   }
  },
  {
   "id": "amend",
   "method": "POST",
   "path": "/notebook/books/${book.notebook_id}/amend",
   "body": {
    "amends": {
     "$ref": "run.entry.n"
    },
    "title": "Plate reader run: initial rates (well F7 excluded)",
    "text": {
     "$file": "inputs/amendment.txt"
    },
    "reason": {
     "$file": "inputs/amendment-reason.txt"
    },
    "author": "Dr. Maya Okafor",
    "attachments": {
     "$file": "inputs/amendment-attachments.json"
    }
   }
  },
  {
   "id": "witness",
   "method": "POST",
   "path": "/notebook/books/${book.notebook_id}/sign",
   "body": {
    "n": {
     "$ref": "amend.entry.n"
    },
    "meaning": "witnessed",
    "signer": "Dr. Tomas Reyes"
   }
  },
  {
   "id": "reviewed",
   "method": "POST",
   "path": "/notebook/books/${book.notebook_id}/sign",
   "body": {
    "n": {
     "$ref": "analysis.entry.n"
    },
    "meaning": "reviewed",
    "signer": "Dr. Tomas Reyes"
   }
  },
  {
   "id": "approved",
   "method": "POST",
   "path": "/notebook/books/${book.notebook_id}/sign",
   "body": {
    "n": {
     "$ref": "amend.entry.n"
    },
    "meaning": "approved",
    "signer": "Prof. Anika Hartwell"
   }
  },
  {
   "id": "timestamp",
   "method": "POST",
   "path": "/notebook/books/${book.notebook_id}/timestamp",
   "body": {},
   "required": false,
   "timeout": 60
  },
  {
   "id": "export",
   "method": "GET",
   "path": "/notebook/books/${book.notebook_id}/export"
  },
  {
   "id": "verify",
   "method": "POST",
   "path": "/notebook/verify",
   "auth": false,
   "body": {
    "record": {
     "$ref": "export"
    }
   }
  },
  {
   "id": "tampered",
   "method": "POST",
   "path": "/notebook/verify",
   "auth": false,
   "body": {
    "record": {
     "$ref": "export"
    }
   },
   "tamper": {
    "at": "record.entries[kind=amend].reason",
    "set": "No reason given"
   }
  }
 ],
 "checks": [
  {
   "says": "the AI analysis flags the planted outlier well F7",
   "path": "analysis.text",
   "contains": "F7"
  },
  {
   "says": "the analysis records the SHA-256 of the rates file it read",
   "path": "analysis.entry.inputs[0].sha256",
   "equals": "df0b60abcbe72548efe8c763babacb7ea528168fbdbaf8fe11bc18a7471f9c13"
  },
  {
   "says": "the amendment points at the original run entry, which stays in the record",
   "path": "amend.entry.amends.n",
   "equals": 2
  },
  {
   "says": "the exported record verifies",
   "path": "verify.ok",
   "equals": true
  },
  {
   "says": "the record holds 1 amendment and 3 e-signatures",
   "path": "verify.notebook",
   "has_keys": [
    "amendments",
    "signatures"
   ],
   "contains": [
    "\"amendments\": 1",
    "\"signatures\": 3"
   ]
  },
  {
   "says": "a copy with the amendment reason changed no longer verifies",
   "path": "tampered.ok",
   "equals": false
  },
  {
   "says": "every model call has a signed receipt",
   "receipts": "signed"
  }
 ]
}
