7.13. Statements of Files and requests
The exact statements behind the claims on the page Files and requests.
theorem a_block_has_the_key_entities (es : List (String × Yaml)) :
blockOf (.map [("entities", .map es)]) =
(es.mapM fun (e, y) => (sectionOf e y).mapError (LoadError.inEntity e)).map ({ entities := · })proof: spec/Spec/YamlFacts.lean:22
theorem an_entity_has_the_keys_key_events_and_rules (e k : String) (ev : Yaml) (rs : List Yaml) :
sectionOf e (.map [("key", .str k), ("events", ev), ("rules", .list rs)]) =
(do pure { entity := e, key := some k, events := ← eventsOf ev, rules := ← rs.mapM ruleOf })proof: spec/Spec/YamlFacts.lean:29
theorem the_entities_of_a_block_load_as_separate_blocks (a b : List (String × Yaml)) :
blockOf (.map [("entities", .map (a ++ b))]) =
(do pure ((← blockOf (.map [("entities", .map a)])) ++ (← blockOf (.map [("entities", .map b)]))))proof: spec/Spec/YamlFacts.lean:36
theorem an_entity_without_events_needs_no_key {fs : List DefFile} {e : String}
(hk : (filesOf fs e).filterMap (·.key) = []) (he : (filesOf fs e).flatMap (·.events) = []) :
keyOf fs e = .ok noneproof: spec/Spec/YamlFacts.lean:466
theorem a_rule_with_on_and_requires_is_a_precondition {s c : String} {S : Selector} {C : CondExpr} (hs : parseSelector s = some S)
(hc : parseCondExpr c = some C) :
ruleOf (.map [("on", .str s), ("requires", .str c)]) = .ok (.pre { on := S, requires := C })proof: spec/Spec/YamlFacts.lean:45
theorem a_rule_with_always_is_an_invariant {c : String} {C : CondExpr} (hc : parseCondExpr c = some C) :
ruleOf (.map [("always", .str c)]) = .ok (.inv (.always C))proof: spec/Spec/YamlFacts.lean:51
theorem a_rule_with_always_per_values_and_active_is_a_grouped_invariant {q p a : String} {vs : List (String × String)} {Q : Quantity} {P : List Per}
{V : List (String × ValueExpr)} {A : CondExpr} (hq : parseQuantity q = some Q) (hp : parsePers p = some P)
(hv : vs.mapM (fun nv => (parseValueExpr nv.2).map (nv.1, ·)) = some V) (ha : parseCondExpr a = some A) :
ruleOf (.map [("always", .str q), ("per", .str p), ("values", .map (vs.map fun nv => (nv.1, .str nv.2))),
("active", .str a)]) = .ok (.inv (.grouped Q P V (some A)))proof: spec/Spec/YamlFacts.lean:74
theorem field_types_are_text_number_boolean_date_timestamp_and_duration :
typeOfName "text" = some (.str, false) ∧ typeOfName "number" = some (.num, false) ∧
typeOfName "boolean" = some (.bool, false) ∧ typeOfName "date" = some (.date, false) ∧
typeOfName "timestamp" = some (.timestamp, false) ∧ typeOfName "duration" = some (.dur, false) ∧
typeOfName "text?" = some (.str, true) ∧ typeOfName "number?" = some (.num, true) ∧
typeOfName "boolean?" = some (.bool, true) ∧ typeOfName "date?" = some (.date, true) ∧
typeOfName "timestamp?" = some (.timestamp, true) ∧ typeOfName "duration?" = some (.dur, true)proof: spec/Spec/YamlFacts.lean:127
theorem an_event_type_is_its_name_and_its_fields (n : String) (typed : List (String × Ty × Bool))
(ht : ∀ x ∈ typed, x.2.1.allowedAsFieldType = true) :
eventOf n (.map (typed.map fun x => (x.1, .str (typeName x.2.1 x.2.2)))) =
.ok ⟨n, typed.map fun x => (x.1, x.2.1), (typed.filter (·.2.2)).map (·.1)⟩proof: spec/Spec/YamlFacts.lean:152
theorem block_with_unknown_key_is_rejected {kvs : List (String × Yaml)} {k : String} {y : Yaml}
(hm : (k, y) ∈ kvs) (hk : k ∉ ["entities", "views"]) :
∃ k', blockOf (.map kvs) = .error (.unknownKey k')proof: spec/Spec/YamlFacts.lean:93
theorem entity_with_unknown_key_is_rejected {e : String} {kvs : List (String × Yaml)} {k : String} {y : Yaml}
(hm : (k, y) ∈ kvs) (hk : k ∉ ["key", "events", "rules"]) :
∃ k', sectionOf e (.map kvs) = .error (.unknownKey k')proof: spec/Spec/YamlFacts.lean:100
theorem rule_with_unknown_key_is_rejected {kvs : List (String × Yaml)} {k : String} {y : Yaml}
(hm : (k, y) ∈ kvs) (hk : k ∉ ["on", "requires", "always", "per", "values", "active"]) :
∃ k', ruleOf (.map kvs) = .error (.unknownKey k')proof: spec/Spec/YamlFacts.lean:107
theorem unknown_field_type_is_rejected (n : String) (fs : List (String × String)) {f tn : String}
(hm : (f, tn) ∈ fs) (hb : typeOfName tn = none) :
∃ t, eventOf n (.map (fs.map fun x => (x.1, .str x.2))) = .error (.badType t)proof: spec/Spec/YamlFacts.lean:175
theorem event_type_declared_twice_is_rejected {fs : List DefFile} {e n : String}
(he : e ∈ fs.map (·.entity))
(hd : dupName? (((filesOf fs e).flatMap (·.events)).map (·.name)) = some n) :
∃ e' n', combine fs = .error (.duplicateType e' n')proof: spec/Spec/YamlFacts.lean:452
theorem definitions_may_be_split_across_files (pre post : List DefFile) (e : String) (k : Option String)
(ev1 ev2 : List EventSchema) (r1 r2 : List Rule) :
combine (pre ++ { entity := e, key := k, events := ev1 ++ ev2, rules := r1 ++ r2 } :: post) =
combine (pre ++ { entity := e, key := k, events := ev1, rules := r1 } ::
{ entity := e, key := k, events := ev2, rules := r2 } :: post)proof: spec/Spec/YamlFacts.lean:212
theorem a_file_of_blocks_loads_as_the_blocks_as_separate_files (pre post bs : List String) (lead : Bool)
(hne : bs ≠ []) (hb : ∀ b ∈ bs, NoSeparator b) :
(loadFiles (pre ++ ((if lead then "---\n" else "") ++ joinBlocks bs) :: post)).toOption =
(loadFiles (pre ++ bs ++ post)).toOptionproof: spec/Spec/YamlFacts.lean:435
theorem a_separator_before_the_first_block_is_dropped :
(loadText "---\nentities:\n a: {}\n---\nentities:\n b: {}").toOption.map (·.entities.map (·.entity)) = some ["a", "b"]proof: spec/Spec/Readable.lean:74
theorem an_error_in_a_block_carries_the_block_and_the_line :
loadErrorOf? (loadText "entities:\n a: {}\n---\nentities:\n b:\n key: |\n c") =
some (.inBlock 1 (.syntax 6))proof: spec/Spec/Readable.lean:68
theorem hotel_file_loads_without_errors : (loadText hotelText).isOkproof: spec/Spec/Readable.lean:54
theorem hotel_file_defines_guest_and_room :
(loadText hotelText).toOption.map (·.entities.map (·.entity)) = some ["guest", "room"]proof: spec/Spec/Readable.lean:58
theorem numbers_are_exact :
numOf "12.50".toList = some (25 / 2) ∧ numOf "1e3".toList = some 1000 ∧
numOf "0.1".toList = some (1 / 10) ∧ String.ofList (numText (1 / 3)) = "1/3" ∧
String.ofList (numText (25 / 2)) = "12.5"
theorem every_number_reads_back_from_its_text (q : Rat) : numOf (numText q) = some q
theorem dates_and_timestamps_have_fixed_text_forms :
dateOfText "2024-02-29".toList = some (daysFromCivil 2024 2 29) ∧ dateOfText "2026-02-29".toList = none ∧
timestampOfText "2026-12-01T10:00:00.5Z".toList = some (timestampOf 2026 12 1 10 0 0 500000) ∧
timestampOfText "2026-12-01T10:00:00+01:00".toList = none
theorem every_date_reads_back_from_its_text (z : Int) (hy : yearOk z = true) : dateOfText (dateText z) = some zproof: spec/Spec/WireProofs.lean:49
theorem every_timestamp_reads_back_from_its_text (t : Rat) (h1 : t.den = 1) (hy : yearOk (t.num / usPerDay) = true) :
timestampOfText (timestampText t) = some tproof: spec/Spec/WireProofs.lean:73
theorem every_duration_reads_back_from_its_text (d : Rat) : (numOf (durText d)).map (· * 1000000) = some d
theorem every_value_reads_back_from_its_json (v : Value) (h : v.encodable = true) :
decodeValue v.ty? (encodeValue v) = some v
theorem Json.every_json_tree_reads_back_from_its_text (j : Json) (h : j.ok = true) : Json.parse j.render = some j
theorem charge_request_decodes_without_errors :
(decodeBatch folioSchema [("folio", "folio_id")] (timestampOf 2026 12 1 10 0 0) chargeRequestText).isOkproof: spec/Spec/Readable.lean:81
theorem charge_request_is_a_charge_of_12_50 :
(decodeBatch folioSchema [("folio", "folio_id")] (timestampOf 2026 12 1 10 0 0) chargeRequestText).toOption.map
(·.map fun e => (e.type, e.key, e.get "gross_minor", e.expected_revision)) =
some [("ChargePosted", "F-1042", .num (25 / 2), some 1)]proof: spec/Spec/Readable.lean:88
def Event.sendable (sc : Schema) (keys : List (String × String)) (now : Rat) (e : Event) : Prop
theorem a_batch_of_sendable_events_survives_the_wire {sc : Schema} {keys : List (String × String)} {now : Rat}
{es : List Event} (h : ∀ e ∈ es, e.sendable sc keys now) :
decodeBatch sc keys now (encodeBatch keys es).render = .ok es
theorem an_accepted_batch_is_answered_with_status_200_and_the_response_text :
(encodeResponse (.appended [exampleStamp])).1 = 200 ∧
(encodeResponse (.appended [exampleStamp])).2.render = appendedResponseTextproof: spec/Spec/Api.lean:350
theorem stamps_describe_the_stored_events {st st' : State} {es : List Event} (h : st.appendBatch es = some st') :
(stamps (st.store.length + 1) (st'.store.drop st.store.length)).length = es.length ∧
∀ (i : Nat) (hi : i < (st'.store.drop st.store.length).length),
(stamps (st.store.length + 1) (st'.store.drop st.store.length))[i]'(st:Statest':Statees:List Eventh:st.appendBatch es = some st'i:Nathi:i < (List.drop st.store.length st'.store).length⊢ i < (stamps (st.store.length + 1) (List.drop st.store.length st'.store)).length st:Statest':Statees:List Eventh:st.appendBatch es = some st'i:Nathi:i < (List.drop st.store.length st'.store).length⊢ i < st'.store.length - st.store.length; All goals completed! 🐙) =
{ position := st.store.length + 1 + i, revision := (st'.store.drop st.store.length)[i].revision,
at_ := (st'.store.drop st.store.length)[i].at }proof: spec/Spec/Api.lean:296
theorem stamp_survives_the_wire (s : Stamp) (h1 : s.at_.den = 1)
(hy : yearOk (s.at_.num / usPerDay) = true) :
(Json.parse (encodeStamp s).render).bind decodeStamp = some s
theorem a_rejected_batch_is_answered_with_status_409_and_the_response_text :
(encodeResponse (.rejected exampleRejection)).1 = 409 ∧
(encodeResponse (.rejected exampleRejection)).2.render = rejectedResponseTextproof: spec/Spec/Api.lean:356
theorem rejection_survives_the_wire (rj : Rejection) (h : rj.reason.printable = true) :
(Json.parse (encodeRejection rj).render).bind decodeRejection = some rj
theorem the_api_answers_as_the_spec_says (now : Rat) (sv : Server) (req : Request) :
ApiSpec now sv req (handle now sv req).1 (handle now sv req).2proof: spec/Spec/Api.lean:89
theorem the_spec_allows_one_answer_only {now : Rat} {sv : Server} {req : Request} {sv' : Server} {r : Response}
(h : ApiSpec now sv req sv' r) : (sv', r) = handle now sv reqproof: spec/Spec/Api.lean:169
theorem a_rejection_reaches_the_client {now : Rat} {sv : Server} {body : String} {es : List Event}
{rj : Rejection} (hd : decodeBatch sv.core.schema sv.keys now body = .ok es)
(ha : sv.core.append es = .error rj) (hp : rj.reason.printable = true) :
(serve now sv ⟨"POST", "/append", body⟩).2.status = 409 ∧
((Json.parse (serve now sv ⟨"POST", "/append", body⟩).2.body).bind (·.get? "rejected")).bind
decodeRejection = some rjproof: spec/Spec/Api.lean:265
theorem an_accepted_batch_reaches_the_client_as_its_stamps {now : Rat} {sv : Server} {body : String} {es : List Event}
{st' : State} (hd : decodeBatch sv.core.schema sv.keys now body = .ok es)
(ha : sv.core.appendBatch es = some st') :
serve now sv ⟨"POST", "/append", body⟩ = ({ sv with core := st' }, ⟨200,
(Json.obj [("events", .arr ((stamps (sv.core.store.length + 1)
(st'.store.drop sv.core.store.length)).map encodeStamp))]).render⟩)proof: spec/Spec/Api.lean:279
theorem a_tab_in_the_indentation_is_rejected :
syntaxLine? (Yaml.parse "entity: a\nrules:\n\t- b") = some 3proof: spec/Spec/Readable.lean:461
theorem anchors_aliases_tags_and_block_scalars_are_rejected :
syntaxLine? (Yaml.parse "entity: a\nkey: &x b") = some 2 ∧
syntaxLine? (Yaml.parse "entity: a\nkey: *x") = some 2 ∧
syntaxLine? (Yaml.parse "entity: a\nkey: !t b") = some 2 ∧
syntaxLine? (Yaml.parse "entity: a\nkey: |\n b") = some 2 ∧
syntaxLine? (Yaml.parse "entity: a\nkey: >\n b") = some 2proof: spec/Spec/Readable.lean:466
theorem nested_flow_collections_are_rejected :
syntaxLine? (Yaml.parse "entity: a\nevents: [[A]]") = some 2 ∧
syntaxLine? (Yaml.parse "entity: a\nevents: { A: [x] }") = some 2 ∧
syntaxLine? (Yaml.parse "entity: a\nevents: { A: { x: y } }") = some 2proof: spec/Spec/Readable.lean:475
theorem a_file_outside_the_subset_does_not_load_and_the_error_carries_the_line :
syntaxLine? (loadFile "entities:\n a:\n key: |\n b") = some 3proof: spec/Spec/Readable.lean:482
theorem a_hash_starts_a_comment_after_a_space_or_at_the_start_of_a_line :
(Yaml.parse "# note\nentity: a # note\nkey: b#c").toOption = some (.map [("entity", .str "a"), ("key", .str "b#c")])proof: spec/Spec/Readable.lean:487
theorem quotes_know_only_the_escapes_quote_and_backslash :
(Yaml.parse "a: \"x\\\"y\\\\z\"").toOption = some (.map [("a", .str "x\"y\\z")]) ∧
syntaxLine? (Yaml.parse "a: \"x\\ny\"") = some 1 ∧
(Yaml.parse "a: 'it''s'").toOption = some (.map [("a", .str "it's")])proof: spec/Spec/Readable.lean:492
theorem flow_collections_are_one_line_of_plain_scalars :
(Yaml.parse "a: { x: text, y: number? }\nb: [A, B]\nc: {}").toOption = some (.map [("a", .map [("x", .str "text"), ("y", .str "number?")]),
("b", .list [.str "A", .str "B"]), ("c", .map [])]) ∧
syntaxLine? (Yaml.parse "b: [A,\n B]") = some 1proof: spec/Spec/Readable.lean:499
theorem a_plain_scalar_may_continue_on_more_indented_lines :
(Yaml.parse "a: b\n c\nd: e").toOption = some (.map [("a", .str "b c"), ("d", .str "e")])proof: spec/Spec/Readable.lean:506
theorem numbers_are_written_as_texts_and_read_from_texts_or_numbers :
(encodeValue (.num (25 / 2))).str? = some "12.5" ∧
decodeValue (some .num) (.str "12.5") = some (.num (25 / 2)) ∧
decodeValue (some .num) (.num (25 / 2)) = some (.num (25 / 2))proof: spec/Spec/Readable.lean:513
theorem durations_are_seconds_not_iso_8601 :
decodeValue (some .dur) (.str "5400") = some (.dur (5400 * 1000000)) ∧
decodeValue (some .dur) (.str "PT1H30M") = some (.str "PT1H30M")proof: spec/Spec/Readable.lean:521