Modern UI contract: bank credits
The credit read previews the loan dialog (bank or another human lender) with per-field bounds, fees and refund; bank.commit action credit books the same edits. The bank read now points to it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
06445c24ef
commit
74c1504e3a
3 files changed
+97
-5
No files matched your search
@@ -432,6 +432,36 @@ int main(int argc, char** argv) {
|
||||
check(s(at(booked, "messageType")) == "command_result" && rev == before + 1, "friendly booked");
|
||||
}
|
||||
}
|
||||
// a bank credit: draft with an edit within its bounds, preview, booking
|
||||
{
|
||||
const J credit = session.ui_read(O{{"kind", "credit"}}, rev);
|
||||
const auto* fields = at(at(credit, "data"), "fields").array();
|
||||
if (s(at(credit, "messageType")) != "snapshot") std::fprintf(stderr, "credit: %s\n", cli::dump_json(credit).c_str());
|
||||
check(fields && fields->size() == 8, "credit read with eight fields");
|
||||
int field = -1;
|
||||
int64_t value = 0;
|
||||
if (fields)
|
||||
for (const auto& f : *fields)
|
||||
if (field < 0 && truth(at(f, "editable")) && *at(f, "max").integer() > *at(f, "min").integer()) {
|
||||
field = int(*at(f, "field").integer());
|
||||
value = (*at(f, "min").integer() + *at(f, "max").integer()) / 2;
|
||||
}
|
||||
if (field >= 0) {
|
||||
const J::Array edits{J(O{{"field", field}, {"value", value}})};
|
||||
const J preview = session.ui_read(O{{"kind", "credit"}, {"edits", edits}}, rev);
|
||||
check(s(at(preview, "messageType")) == "snapshot", "credit preview");
|
||||
int64_t too_high = 0;
|
||||
for (const auto& f : *fields)
|
||||
if (*at(f, "field").integer() == field) too_high = *at(f, "max").integer() + 1;
|
||||
const J::Array bad{J(O{{"field", field}, {"value", too_high}})};
|
||||
const J refused = session.ui_read(O{{"kind", "credit"}, {"edits", bad}}, rev);
|
||||
check(s(at(refused, "code")) == "invalid_credit_edit", "credit edit beyond its bound refused");
|
||||
const uint64_t before = rev;
|
||||
const J booked = session.ui_command(cmd("request:k9", "bank.commit", O{{"action", "credit"}, {"edits", edits}, {"acceptFees", true}}), rev);
|
||||
std::printf("(credit field %d to %lld: %s)\n", field, (long long)value, cli::dump_json(booked).substr(0, 160).c_str());
|
||||
check(s(at(booked, "messageType")) == "command_result" && rev == before + 1, "credit booked");
|
||||
}
|
||||
}
|
||||
// the surroundings: six budgets 0-6
|
||||
{
|
||||
const J env = session.ui_read(O{{"kind", "environment"}}, rev);
|
||||
|
||||
Reference in new issue
Block a user