# Workbook check of the truck cost study

Checked on 2026-11-23 with LibreOffice 24.2.7.2. This is a check, not a validation of the cell prices.

## What it checks
The cost study records, for each of six runs (main, reserve, underFrameReserve, each on the market and the catalog price basis), seven cost figures. The Pack Designer exports a SpreadsheetML workbook for each run whose Economics sheet computes the same seven figures from named input cells. The script checks that:

1. the named inputs in each workbook equal the inputs the model ran on (`runnerInputs` in `cost.json`), to a relative 1e-12;
2. the seven Economics outputs, **recalculated by LibreOffice**, equal the figures in `cost.json` within a tolerance set by the six-decimal rounding of `cost.json`.

## How the values come from the formulas, not the cache
For each workbook the script makes a copy in a temporary folder and deletes the stored `<Data>` value of every cell that has an `ss:Formula` (20 per workbook; formulas and input cells stay). LibreOffice loads the copy headless and saves it as .xlsx, and the script reads the numbers from that file. It stops if any stored value remains in the copy, if any formula cell lacks a number after loading, or if a control copy (cell price doubled) does not double the upfront cost. The original cached values are read only for the side observation in the console output.

The model field `replacements` is compared with the sheet cell "Packs needed over target"; the model's `tcoUSD` equals upfront cost times that number.

## Run it
From the page folder (the one holding `cost.json`, `runs/` and `verification/`), with `python3` and `soffice` on the path:

    python3 -I verification/check_workbooks.py

It rewrites `runs/workbook-check.json` byte for byte (no timestamps; run it twice and compare the hashes) and prints a per-run summary. Scratch files go to a temporary folder that is removed at the end.

## What it shares with the model
Same inputs, and formulas written by the same project: the workbook is exported by the Pack Designer itself. A wrong formula, a wrong input or a shared misunderstanding would be present on both sides and not be caught.

## What it cannot establish
No supplier price and no measurement. Whether the cell prices are what a buyer would pay at truck volumes needs a supplier quote or invoice. Nor does it test anything outside the seven Economics cells.
