// test_worktrack.el — durability + inspectability of the work-tracking journal.

fn main() -> Int {
    let corr: String = "test-" + uuid_v4()

    // record a swarm lifecycle
    let p1: String = json_set("{}", "input_count", "3")
    worktrack_append("swarm.created", corr, "swarm-1", p1)
    worktrack_append("worker.started", corr, "worker-001", "{}")
    worktrack_append("worker.started", corr, "worker-002", "{}")
    worktrack_append("worker.completed", corr, "worker-001", "{}")
    worktrack_append("worker.failed", corr, "worker-002", "{}")
    worktrack_append("swarm.completed", corr, "swarm-1", "{}")

    // inspect: reconstruct the report from the durable journal
    let report: String = worktrack_swarm_report(corr)
    print("report=" + report)

    let recs_n: Int = el_list_len(worktrack_records(corr))
    print("records=" + int_to_str(recs_n))

    let state: String = json_get_string(report, "state")
    let completed: Int = str_to_int(json_get_string(report, "workers_completed"))
    let failed: Int = str_to_int(json_get_string(report, "workers_failed"))

    if str_eq(state, "completed") {
        if completed == 1 {
            if failed == 1 {
                if recs_n == 6 {
                    print("PASS worktrack")
                    return 0
                }
            }
        }
    }
    print("FAIL worktrack")
    return 1
}
