Cotton code
466 lines · 13.2 KB · JSONRaw
{  "pair": "values and refusals",  "rust": "crates/cotton-tools/src/mcp/handlers/tables (create_record, update_record, get_record_by_table over a kit table); cotton-core records::check_value_as",  "worker": "apps/business/src/mcp/tools/records/write.ts, records/values.ts",  "cases": [    {      "name": "a value of the wrong kind, in the kit's words",      "steps": [        {          "tool": "create_record",          "args": {            "table": "book",            "data": {              "title": "Read more",              "added_on": "31/12/2026"            }          },          "expect": {            "refusal": "\"added_on\" takes a date written YYYY-MM-DD; \"31/12/2026\" is not one"          }        },        {          "tool": "create_record",          "args": {            "table": "book",            "data": {              "title": "Read more",              "added_on": "2026-02-30"            }          },          "expect": {            "refusal": "\"added_on\" takes a date written YYYY-MM-DD; \"2026-02-30\" is not one"          }        },        {          "tool": "create_record",          "args": {            "table": "book",            "data": {              "title": "Read more",              "rating": "three"            }          },          "expect": {            "refusal": "\"rating\" takes a number; \"three\" is not one"          }        },        {          "tool": "create_record",          "args": {            "table": "book",            "data": {              "title": "Read more",              "status": "someday"            }          },          "expect": {            "refusal": "\"status\" takes one of want_to_read, reading, finished, stopped; \"someday\" is not one"          }        },        {          "tool": "create_record",          "args": {            "table": "book",            "data": {              "title": 42            }          },          "expect": {            "refusal": "\"title\" takes text; 42 is not one"          }        },        {          "tool": "create_record",          "args": {            "table": "book",            "data": {              "title": "Read more",              "review": [                "a",                "list"              ]            }          },          "expect": {            "refusal": "\"review\" takes text; a list is not one"          }        }      ]    },    {      "name": "columns that are not there, read only, or not given",      "steps": [        {          "tool": "create_record",          "args": {            "table": "book",            "data": {              "title": "Read more",              "colour": "blue"            }          },          "expect": {            "refusal": "Books have no column \"colour\""          }        },        {          "tool": "create_record",          "args": {            "table": "book",            "data": {              "author": "No title"            }          },          "expect": {            "refusal": "\"title\" is required"          }        },        {          "tool": "create_record",          "args": {            "table": "book"          },          "expect": {            "refusal": "data is required: an object of column keys and values"          }        },        {          "tool": "create_record",          "args": {            "table": "book",            "data": {              "title": "Read more",              "format": "epub"            }          },          "expect": {            "refusal": "\"format\" is read only"          }        }      ]    },    {      "name": "a link to a record that is not there",      "steps": [        {          "tool": "create_record",          "args": {            "table": "film",            "data": {              "title": "A Quiet Film",              "recommended_by": "00000000-0000-4000-8000-000000000999"            }          },          "expect": {            "refusal": "\"recommended_by\" links to person, and there is no person \"00000000-0000-4000-8000-000000000999\""          }        }      ]    },    {      "name": "tables and records that are not there",      "steps": [        {          "tool": "create_record",          "args": {            "table": "invented_table",            "data": {              "title": "Dal"            }          },          "expect": {            "refusal": "No tool draws this table."          }        },        {          "tool": "create_record",          "args": {            "data": {              "title": "Dal"            }          },          "expect": {            "refusal": "table is required: the table's id, e.g. \"todo\""          }        },        {          "tool": "update_record",          "args": {            "table": "book",            "id": "00000000-0000-4000-8000-000000000999",            "patch": {              "rating": 3            }          },          "expect": {            "refusal": "That book is no longer here"          }        },        {          "tool": "update_record",          "args": {            "table": "book",            "id": "00000000-0000-4000-8000-000000000999"          },          "expect": {            "refusal": "patch is required: an object of column keys and values"          }        },        {          "tool": "get_record_by_table",          "args": {            "table": "book",            "id": "00000000-0000-4000-8000-000000000999"          },          "expect": {            "refusal": "That book is no longer here"          }        }      ]    }  ],  "differs": [    {      "name": "a book written whole, then patched",      "why": "The written values and the change agree; the shapes do not: the change id is a uuid on the phone and a number on the Worker, the phone adds automation_depth_limited, automation_changes and notifications, and the record's byline is the connection on the phone, null on the Worker; since f02078080c the phone's receipt carries `values` (the other columns a changed receipt read, before and after in words), which the Worker's receipt does not yet.",      "steps": [        {          "tool": "create_record",          "args": {            "table": "book",            "data": {              "title": "The Synthetic Garden",              "author": "A. Example",              "status": "want_to_read",              "rating": 4,              "added_on": "2026-01-05",              "pages": 320            }          },          "rust": {            "answer": {              "change": {                "id": "<id1>",                "table": "book",                "record_id": "<id2>",                "verb": "create",                "byline": "Claude",                "before": null,                "after": {                  "title": "The Synthetic Garden",                  "author": "A. Example",                  "status": "want_to_read",                  "rating": 4,                  "added_on": "2026-01-05",                  "pages": 320                },                "created_at": "<instant>",                "undone_by": null,                "undoable": true,                "reason": null,                "receipt": {                  "kind": "added",                  "said": "Added The Synthetic Garden",                  "words": [],                  "values": []                }              },              "record": {                "table": "book",                "id": "<id2>",                "data": {                  "title": "The Synthetic Garden",                  "author": "A. Example",                  "status": "want_to_read",                  "rating": 4,                  "added_on": "2026-01-05",                  "pages": 320                },                "created_at": "<instant>",                "updated_at": "<instant>",                "deleted_at": null,                "byline": "Claude"              },              "automation_depth_limited": false,              "automation_changes": [],              "notifications": []            }          },          "worker": {            "answer": {              "change": {                "id": 5,                "table": "book",                "record_id": "<id1>",                "verb": "create",                "byline": "Claude",                "before": null,                "after": {                  "title": "The Synthetic Garden",                  "author": "A. Example",                  "status": "want_to_read",                  "rating": 4,                  "added_on": "2026-01-05",                  "pages": 320                },                "created_at": "<instant>",                "undone_by": null,                "undoable": true,                "reason": null,                "receipt": {                  "kind": "added",                  "said": "Added The Synthetic Garden",                  "words": []                }              },              "record": {                "table": "book",                "id": "<id1>",                "data": {                  "title": "The Synthetic Garden",                  "author": "A. Example",                  "status": "want_to_read",                  "rating": 4,                  "added_on": "2026-01-05",                  "pages": 320                },                "created_at": "<instant>",                "updated_at": "<instant>",                "deleted_at": null,                "byline": null              }            }          }        },        {          "tool": "update_record",          "args": {            "table": "book",            "id": "{{0.record.id}}",            "patch": {              "rating": 5,              "pages": null            }          },          "rust": {            "answer": {              "change": {                "id": "<id3>",                "table": "book",                "record_id": "<id2>",                "verb": "update",                "byline": "Claude",                "before": {                  "pages": 320,                  "rating": 4,                  "updated_at": "<instant>"                },                "after": {                  "pages": null,                  "rating": 5                },                "created_at": "<instant>",                "undone_by": null,                "undoable": true,                "reason": null,                "receipt": {                  "kind": "changed",                  "said": "Changed The Synthetic Garden",                  "words": [],                  "values": [                    {                      "name": "Rating",                      "before": "4 of 5",                      "after": "5 of 5"                    },                    {                      "name": "Pages",                      "before": "320 pages",                      "after": null                    }                  ]                }              },              "record": {                "table": "book",                "id": "<id2>",                "data": {                  "title": "The Synthetic Garden",                  "author": "A. Example",                  "status": "want_to_read",                  "rating": 5,                  "added_on": "2026-01-05"                },                "created_at": "<instant>",                "updated_at": "<instant>",                "deleted_at": null,                "byline": "Claude"              },              "automation_depth_limited": false,              "automation_changes": [],              "notifications": []            }          },          "worker": {            "answer": {              "change": {                "id": 6,                "table": "book",                "record_id": "<id1>",                "verb": "update",                "byline": "Claude",                "before": {                  "rating": 4,                  "pages": 320,                  "updated_at": "<instant>"                },                "after": {                  "rating": 5,                  "pages": null                },                "created_at": "<instant>",                "undone_by": null,                "undoable": true,                "reason": null,                "receipt": {                  "kind": "changed",                  "said": "Changed The Synthetic Garden",                  "words": []                }              },              "record": {                "table": "book",                "id": "<id1>",                "data": {                  "title": "The Synthetic Garden",                  "author": "A. Example",                  "status": "want_to_read",                  "rating": 5,                  "added_on": "2026-01-05"                },                "created_at": "<instant>",                "updated_at": "<instant>",                "deleted_at": null,                "byline": null              }            }          }        },        {          "tool": "update_record",          "args": {            "table": "book",            "id": "{{0.record.id}}",            "patch": {              "rating": 5            }          },          "expect": {            "refusal": "the patch changes nothing"          }        }      ]    }  ]}