Price is a rate function, not a scalar (#22), and #15 bars any model from evaluating one — so the shapes have to be closed AND computable. This replaces the src/pricing seam with a composition rather than an enumeration: one base schedule deciding unit price, plus closed modifiers, plus an optional floor. Three vendors on one small RFP already produced five cells of the alternative cross-product, and two of the three are the same object wearing different decoration. The scenario vocabulary is closed too, and published with the RFP, so every bid in a field is priced against identical assumptions. A structure reading a variable the RFP never declared is rejected at submission, while the vendor can still fix it. Abstention is typed. `input_missing` is separated from `shape_unsupported` because Chesapeake's shape is fully supported and its unit price simply is not in the document — that is recoverable by asking, and collapsing the two throws away the only actionable fact. Null is never zero, never the vendor's stated figure, and never a partial sum. The derivation is the record. A bare scalar can only assert; a protest asks why a bid ranked where it did. Lines accumulate as exact rationals in bigint and round once, half-up. A scenario amendment voids derived costs rather than recomputing them. Exceptions carry a closed consequence union. Anacostia's EX-3 says the vendor cannot bid produce at all if declined — a nullable price delta reads that as "no cost impact", the inverse of the truth, on the most consequential of the three. Two defects the corpus check caught that review would not have: - The band ladder priced two ways depending on a flag. `to` is inclusive, and subtracting those bounds in the marginal path lost the unit between bands — one in 21,400, invisible in the total and wrong in the record. - The published scenario was quantizing the price before the evaluator saw it. Twelve basis-point shares moved the seasonal factor by 3e-5, about $19 on a $624,000 line. Weights, not shares: a school calendar publishes instructional days, an exact integer, and the ratio is taken last. npm run check:pricing Potomac computes $589,570.00 and not the stated $589,970.00; Chesapeake abstains naming base.unitPrice; Anacostia is $649,792.00 with the calendar and unpriceable without it; a 3-of-4-line bid withholds its total. Migrations generated in two passes so drizzle-kit never needed the interactive rename prompt. No SQL hand-edited. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
58 lines
2.3 KiB
TypeScript
58 lines
2.3 KiB
TypeScript
import {
|
|
MONTHLY_WEIGHTS,
|
|
type RateStructure,
|
|
type ScalarVariable,
|
|
type ScenarioVariable,
|
|
requiredVariables,
|
|
} from './rate.js'
|
|
|
|
/**
|
|
* The published scenario. #10 put it in the RFP so price is bindable up front,
|
|
* and #29 made its variable set closed (see rate.ts).
|
|
*
|
|
* Note what a scenario variable IS: an assumption declared for comparison, not
|
|
* a contract term. Chesapeake's delivery frequency is changeable mid-term on
|
|
* two weeks' notice, so the awarded price will not match the derived cost and
|
|
* nobody should be surprised by that. Naming it an assumption here is cheaper
|
|
* than explaining it during a protest.
|
|
*/
|
|
export interface Scenario {
|
|
/** Per price line. Fractional quantities are fine; the evaluator scales to integers. */
|
|
readonly quantities: Readonly<Record<string, number>>
|
|
readonly scalars: Readonly<Partial<Record<ScalarVariable, number>>>
|
|
/**
|
|
* Relative volume per month, index 0 = January. Non-negative integers in any
|
|
* consistent unit — instructional days is the natural one for a school food
|
|
* contract. Only the ratios are read, so nothing here needs normalising and
|
|
* therefore nothing here gets rounded.
|
|
*/
|
|
readonly monthlyWeights?: readonly number[]
|
|
}
|
|
|
|
/**
|
|
* Submission-time validation: a structure that reads a variable this RFP did
|
|
* not publish is rejected NOW, while the vendor can still fix it — not
|
|
* resolved to a null in the evaluator months later when nobody can act on it.
|
|
*/
|
|
export function missingVariables(rate: RateStructure, scenario: Scenario): ScenarioVariable[] {
|
|
return requiredVariables(rate).filter((v) =>
|
|
v === MONTHLY_WEIGHTS
|
|
? scenario.monthlyWeights === undefined
|
|
: scenario.scalars[v] === undefined,
|
|
)
|
|
}
|
|
|
|
/**
|
|
* A malformed published scenario is a bug, not a bid outcome — so this throws
|
|
* rather than abstaining. Abstention is reserved for facts about the response.
|
|
*/
|
|
export function assertWellFormed(scenario: Scenario): void {
|
|
const w = scenario.monthlyWeights
|
|
if (w === undefined) return
|
|
if (w.length !== 12) throw new Error(`monthlyWeights has ${w.length} entries, expected 12`)
|
|
if (w.some((n) => !Number.isInteger(n) || n < 0)) {
|
|
throw new Error('monthlyWeights must be non-negative integers')
|
|
}
|
|
if (w.reduce((a, b) => a + b, 0) <= 0) throw new Error('monthlyWeights sum to zero')
|
|
}
|