Subtract numbers #2
Labels
No labels
aira:blocked
aira:cancelled
aira:ci
aira:done
aira:implementing
aira:merging
aira:plan-review
aira:planning
aira:qa
aira:queued
aira:ready
aira:review
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
lab/web-calculator#2
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Add subtraction next to addition.
Requirements
op=subtractreturnsa - b.−(minus) button that works like+. Pressing7,−,1,0,=shows-3.400 {"error"}for bad input).Acceptance criteria
/api/calculate?a=2&b=5&op=subtractreturns{"result":-3}./api/calculate?a=0.5&b=0.25&op=subtractreturns{"result":0.25}.op=addstill works and an unknown op still returns 400.Aira · queued
Aira picked up this task. Branch
aira/2-subtract-numbers.Aira · planning
Orchestrator thread started (composer-2.5). Planning on
aira/2-subtract-numbers.T3 thread:
mcp:launch:8dfd463a24e85bb482777cedca23b43b29968115c174816b7672945382b2809dAira · Plan (round 1) at
1cc4b924Added docs/plans/issue-2.md (goal, ACs, design, files, test plan, risks); committed and pushed to aira/2-subtract-numbers.
docs/plans/issue-2.md
Issue #2: Subtract numbers
Goal
Add subtraction alongside addition: a pure
subtractfunction in the library,op=subtractonGET /api/calculate, and a−(minus) button on the calculator UI that follows the same operand / equals flow as+. Preserve existing addition behaviour, error handling,/health, and/static serving.Acceptance criteria
/api/calculate?a=2&b=5&op=subtractreturns{"result":-3}./api/calculate?a=0.5&b=0.25&op=subtractreturns{"result":0.25}.op=addstill works and an unknownopstill returns HTTP 400 with{"error": "<message>"}.−) button and shows differences returned by the API (example flow:7,−,1,0,=displays-3).Design
Calculation module (
lib/calculator.js)subtract(a, b)— pure numeric subtraction (a - b); same IEEE double semantics asadd.calculate(rawA, rawB, op):op === 'add'(existing) andop === 'subtract'.opwithCalculatorError('Unknown operation')(unchanged message contract).subtractalongside existing exports.parseOperandand finite-result check for subtract results (including overflow edge cases analogous to add).HTTP layer (
server.js)/api/calculatealready delegates tocalculate(). Subtraction is picked up automatically once the module supportsop=subtract.400 {"error": ...}viaCalculatorError.UI (
public/index.html)−button on the keypad (Unicode minus U+2212), placed like the+button (same row pattern / grid).+: setpendingOp = 'add'and commit first operand (current behaviour, but not hard-coded only inevaluate).−: setpendingOp = 'subtract'and commit first operand the same way.=: requireoperandA,pendingOp, and current entry;fetch('/api/calculate?...')withopequal topendingOp(addorsubtract).resulton success (including negative values such as-3); show error text on 400 as today.7→−→1→0→=→ display-3.Test layout
test/calculator.test.jssubtract,calculatewithop=subtract, regressions foraddand unknownop.test/server.test.jstest/ui.test.jsdata-keyfor−) and that client script can passsubtractvia/api/calculate.Files to change
lib/calculator.jssubtract, extendcalculatedispatch.server.jspublic/index.html−button, generalisependingOp/evaluate.test/calculator.test.jstest/server.test.jstest/ui.test.jsdocs/plans/issue-2.mdNo changes to
package.json, CI workflows, or dependencies (Node built-ins only).Test plan
Unit (
test/calculator.test.js)subtract(2, 5) === -3;calculate('2', '5', 'subtract') === -3.subtract(0.5, 0.25) === 0.25;calculate('0.5', '0.25', 'subtract') === 0.25.calculate(..., 'add')tests unchanged; unknownopstill throwsCalculatorError.subtractmirroradd; overflow if applicable (e.g. extreme magnitudes producing non-finite result).HTTP (
test/server.test.js)a=2&b=5&op=subtract{ result: -3 }a=0.5&b=0.25&op=subtract{ result: 0.25 }a=2&b=3&op=add{ result: 5 }(existing)a=1&b=2&op=pow{ error: string }(existing)Re-run all existing health, index, 404, and add error tests unchanged.
UI / page (
test/ui.test.js)data-keyfor−(minus button)./api/calculateand usessubtract(orpendingOpthat includes subtract) so differences are fetched from the API.Optional manual check: keypad
7,−,1,0,=shows-3when the server is running.Pre-push
npm testlocally; all tests green beforegit push origin aira/2-subtract-numbers.Risks
−(U+2212) with ASCII-indata-key/ click handlingdata-keyand JSswitch; document in code only if needed; UI test matches the chosen key.addincommitOperand/evaluatependingOpstring used in API query; add tests for subtract in UI file.resultas returned (String(body.result)).−fits without breaking digit/+/=layout./healthor/Attachment: plan-2-r1.md
Aira · plan review
Plan pushed at
1cc4b924; independent Dodik plan review started.Aira · dodik-plan PASS on
1cc4b924The plan at
1cc4b924maps each subtraction requirement to a numbered, testable acceptance criterion and matches the current code: calculate() only accepts op=add and rejects anything else with CalculatorError, server.js already delegates /api/calculate to calculate() and maps CalculatorError to 400, and the page hard-codes pendingOp and op to add in commitOperand and evaluate. The test plan proves AC1–AC2 at unit and HTTP level, AC3 by keeping the add and unknown-op tests, subtract invalid-operand and overflow edges in the module, and AC4 with a minus data-key check plus a script check that the page calls /api/calculate with subtract. Scope stays inside the calculator module, the page, and those tests.Checks performed
1cc4b92409with the task requirements and acceptance criteriaAttachment: dodik-plan-1cc4b924.json
Aira · implementing
Plan approved by Dodik at
1cc4b924. Implementation started.Aira · ci
Ready for review at
a2d47366(PR #6). Waiting for CI.Implemented op=subtract in lib/calculator.js, minus button and pendingOp UI in public/index.html, and tests in calculator/server/ui suites; npm test 27/27 pass; pushed feat commit.
Aira · CI passed on
a2d47366Aira · review
CI is green on
a2d47366. Independent Dodik and code review started.Aira · dodik PASS on
a2d47366Subtraction is implemented as specified: op=subtract returns a-b (including 2-5=-3 and 0.5-0.25=0.25), addition and unknown-op 400 handling are unchanged, and the page minus button displays API differences. All 27 tests passed, the new tests fail on origin/main, and the diff matches the approved plan with no unrelated or weakened tests.
Checks performed
a2d4736) with docs/plans/issue-2.md; only the planned calculator, page, tests, and plan file changed, and server.js was untouched.Attachment: dodik-a2d47366.json
Aira · reviewer PASS on
a2d47366The change cleanly adds subtract to the calculator module via shared dispatch in calculate(), relies on the unchanged server handler for op=subtract, and generalizes the UI with a Unicode minus key and pendingOp-driven API calls. All 27 tests pass, acceptance cases for subtract (including negatives and decimals) are covered at unit and HTTP layers, and existing add, health, index, and error paths regress correctly with no security or contract issues identified.
Checks performed
a2d473669dAttachment: reviewer-a2d47366.json
Aira · qa
Dodik and the reviewer passed on
a2d47366. Preview deployed at http://127.0.0.1:44177; QA started.Aira · qa PASS on
a2d47366Preview commit
a2d473669dserves subtraction correctly. GET /health reports that sha. op=subtract returns a-b for 2-5 (-3) and 0.5-0.25 (0.25); op=add still returns a sum; missing, empty, non-numeric, and unknown operations return 400 with an error object. The page includes a − button wired to op=subtract and displays the API result. npm test passed 27/27, including subtract cases for the module, API, and page.Checks performed
Attachment: qa-a2d47366.json
Aira · merging
QA passed on
a2d47366. Merging.Aira · Merged PR #6
Merge commit
f215b5f209ae6c6b2bc2071a4c7fee8ba49f3f3cfrom reviewed heada2d473669dd9f8be888db47242dfd51794bb77e2.a2d473669dserves subtraction correctly. GET /health reports that sha. op=subtract returns a-b for 2-5 (-3) and 0.5