Practise this: Stop a repeated mistake with a check
Clone the starter linked below. It is the pricing code of a camping-gear shop's quote service, in Node, with nothing to install. Money is meant to be integer cents and rates whole basis points, with applyRate in src/pricing/cents.js doing the rounding. Read INCIDENTS.md first: twice an agent has handled money as floating-point numbers, twice someone told it not to in the chat, and the second one is still in src/pricing/card-fee.js. The next change on the list is a weekend delivery surcharge. Your job is to make sure there is no third time, by moving the mistake up the ladder.
-
The rule file. Add a
## Moneysection toAGENTS.md(the file every agent here reads;CLAUDE.mdimports it). Say that money is integer cents and never floating-point, that rates are applied withapplyRate, and thatnode scripts/check-money.jsmust pass. -
The check. Write
scripts/check-money.js. It exportscheckSource(file, text), which returns a list of findings, each{ file, line, message }, for pricing code that usesparseFloat(,toFixed(or a number with a decimal point. Each message names the file and line and tells the agent the fix: useapplyRatefromsrc/pricing/cents.js. Run asnode scripts/check-money.js [folder], it checks every.jsfile under the folder (src/pricingwhen none is given), prints each finding, and exits 1 if there are any and 0 if there are none. Importing the file must not run the check. Watch it fail before you trust it: put a violation in by hand, run it, read the message, take it out. And make sure it raises no false alarm on pricing code that is already integer cents. -
Fix the card fee. 1.4% is 140 basis points. Put a test on an amount where half a cent decides the answer (a $17.50 quote has a fee of 25 cents).
-
The gates. Add
.githooks/pre-commitrunning the check andnode --test(make it executable withchmod +x .githooks/pre-commit, then turn it on withgit config core.hooksPath .githooks; git silently skips a hook that is not executable). In.github/workflows/checks.yml, thechecksjob must run both commands, and nothing may let it skip: the starter's job has anif:that skips agent branches, and a skipped job reports success. On a hosted repository you would then makechecksa required status check onmain, with bypassing turned off for administrators. The hidden tests cannot check that setting, but write it into the Money section so the agent knows. -
The re-run. Ask for the next change: a weekend delivery surcharge of 2.5% of the goods, added before GST, returned as
weekendCentson the quote (0 when not asked for) when the quote's options includeweekendDelivery: true. If an agent does it, give it the request as written and see whether it reaches for floating point. If you do it by hand, write the floating-point version first. Either way, let the hook or the check stop it, then finish it withapplyRate, with a test. Record it inRERUN.md: the request, the first attempt, the command you ran and the check's message exactly as printed, and the change that passed.
Get node scripts/check-money.js and node --test both passing on what you upload, with the output in front of you. Then upload the repository folder. The .git folder is left out for you, so the hidden tests mark what is in your files: fees and quotes on amounts where floating point is a cent out, your check run on code it has never seen (with faults and without), the workflow, the hook, the rule file, your tests and RERUN.md.
Open the lab · needs a free Tarmac account to have your work marked