record MonthlyTotal {
month: Text
total_pence: Int where it >= 0
}path monthly_report ok
entry reporting.monthly_totals · 4 reachable · effects { alloc, sql.read } within { alloc, sql.read } · forbid { io.file, io.net, sql.write }
coverage: 3 proved · 0 checked, 0 exercised by tests · 0 assumptions, 0 verifiable, 0 verified · no contract mutations run
Assumptions
No assumptions on this path.
Ledger (4 proved)
| status | kind | obligation | in | at | by |
|---|---|---|---|---|---|
| proved | representation | year within ±2^53 - 1 | reporting.monthly_totals | examples/reporting/reporting.onus:18:3 | z3 |
| proved (pinned) | requires | parse_select(text: text) is Ok | reporting.monthly_totals | examples/reporting/reporting.onus:23:40 | const evaluator |
| proved (pinned) | requires | columns_match(text: text, record: row) is Ok | reporting.monthly_totals | examples/reporting/reporting.onus:23:40 | const evaluator |
| proved | ensures | forall t: MonthlyTotal in result: t.total_pence >= 0 | reporting.monthly_totals | examples/reporting/reporting.onus:26:3 | z3 |
module reporting
coverage: 4 proved · 0 checked, 0 exercised by tests · 0 assumptions, 0 verifiable, 0 verified · no contract mutations run
union AppError = | Config of detail: config.Error | Storage of detail: sql.Error | Io of detail: io.Error
pub fn monthly_totals( db: sql.Db[ReadOnly, schema: "orders"], year: Int where 2000 <= it and it <= 2100 ) -> Result[List[MonthlyTotal], sql.Error] may sql.read, alloc
ensures forall t: MonthlyTotal in result: t.total_pence >= 0{ ... } expand body (counted)
pub fn monthly_totals(
db: sql.Db[ReadOnly, schema: "orders"],
year: Int where 2000 <= it and it <= 2100
) -> Result[List[MonthlyTotal], sql.Error] may sql.read, alloc
ensures forall t: MonthlyTotal in result: t.total_pence >= 0
{
-- text is a const parameter (§3.8.1): std.sql's own parse_select runs at check time and rejects anything but a single SELECT.
let stmt: sql.Select[MonthlyTotal] = sql.select[
text: "select to_char(created, 'YYYY-MM') as month, sum(amount_pence) as total_pence from orders where extract(year from created) = $1 group by 1 order by 1"
](params: [sql.int(x: year)], row: MonthlyTotal)
return sql.query(db: db, statement: stmt)
}pub fn main( args: List[Text], env: io.Env, files: io.Files, net: io.Net ) -> Result[Unit, AppError] may io.env, io.file, io.net, sql.read, alloc
{ ... } expand body (counted)
pub fn main(
args: List[Text],
env: io.Env,
files: io.Files,
net: io.Net
) -> Result[Unit, AppError] may io.env, io.file, io.net, sql.read, alloc {
let cfg: config.Config = try config.load(env: env) else e: Config(detail: e)
let reporting: sql.Db[ReadOnly] = try sql.connect(
net: net,
dsn: cfg.reporting_dsn,
mode: ReadOnly
) else e: Storage(detail: e)
let orders: sql.Db[ReadOnly, schema: "orders"] = sql.restrict(db: reporting, schema: "orders")
let rows: List[MonthlyTotal] = try monthly_totals(db: orders, year: 2026)
else e: Storage(detail: e)
let out: io.File = try io.create(files: files, path: "report.csv") else e: Io(detail: e)
for row: MonthlyTotal in rows {
try io.write(file: out, text: row.month ++ "," ++ Int.to_text(x: row.total_pence) ++ "\n")
else e: Io(detail: e)
}
return Ok(value: Unit)
}path monthly_report
entry monthly_totals
effects <= { sql.read, alloc }
forbid { sql.write, io.net, io.file }module app.config
coverage: 0 proved · 0 checked, 0 exercised by tests · 0 assumptions, 0 verifiable, 0 verified · no contract mutations run
pub record Config {
reporting_dsn: Text
}pub union Error = | Missing of key: Text
pub fn load(env: io.Env) -> Result[Config, Error] may io.env, alloc
{ ... } expand body (counted)
pub fn load(env: io.Env) -> Result[Config, Error] may io.env, alloc {
match io.get_env(env: env, name: "REPORTING_DSN") with
| Some(value) -> return Ok(value: Config { reporting_dsn: value })
| None -> return Err(error: Missing(key: "REPORTING_DSN"))
}Ledger
| status | kind | obligation | in | at | by |
|---|---|---|---|---|---|
| proved | representation | year within ±2^53 - 1 | reporting.monthly_totals | examples/reporting/reporting.onus:18:3 | z3 |
| proved (pinned) | requires | parse_select(text: text) is Ok | reporting.monthly_totals | examples/reporting/reporting.onus:23:40 | const evaluator |
| proved (pinned) | requires | columns_match(text: text, record: row) is Ok | reporting.monthly_totals | examples/reporting/reporting.onus:23:40 | const evaluator |
| proved | ensures | forall t: MonthlyTotal in result: t.total_pence >= 0 | reporting.monthly_totals | examples/reporting/reporting.onus:26:3 | z3 |
| proved | refinement | 2000 <= it and it <= 2100 | reporting.main | examples/reporting/reporting.onus:43:71 | z3 |
Assumptions (0)
None.
Recover sites (0)
None.
Capability construction sites (0)
None on any path.
Diff
No previous interface was given (onus review --against <interface.json>).
Changes
The regeneration loop has written no change under .onus/changes/.
Diagnostics
None.