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-3#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:3f79cce400bebb9c180944023ea917269230774dee793fbb184ddebbd481cbb9Aira · Plan (round 1) at
24229b41Wrote docs/plans/issue-2.md for subtraction (API op=subtract, UI minus button, tests); committed and pushed aira/2-subtract-numbers.
docs/plans/issue-2.md
Issue #2: Subtract numbers
Goal
Extend the calculator with subtraction end-to-end: handle
op=subtractinlib/calculator.jsasa - b, expose it through the existingGET /api/calculateroute (unchanged contract), and add a−(U+2212 minus) keypad button that behaves like+. The flow7,−,1,0,=must display-3via the API. Addition, validation, and error responses remain unchanged.Acceptance criteria
GET /api/calculate?a=2&b=5&op=subtractreturns HTTP 200 with body{"result":-3}.GET /api/calculate?a=0.5&b=0.25&op=subtractreturns HTTP 200 with body{"result":0.25}.GET /api/calculate?a=2&b=3&op=addstill returns{"result":5}; unknownop(e.g.pow) still returns HTTP 400 with anerrorstring./includes a minus button; pressing operands and=with subtraction selected shows the difference returned by the API (same pattern as addition).Design
Calculator module (
lib/calculator.js)calculate(a, b, op)with a branch forop === 'subtract': computex - yafter existingparseNumberon both operands.add: if the result is not finite, throwresult out of range.parseNumberand the unknown-op path unchanged (throw new Error('unknown operation')for anything other thanadd/subtract).HTTP layer (
server.js)handleCalculatealready passesopthrough tocalculate; new operation is recognized only in the module layer.UI (
public/index.html)−(minus sign, not hyphen-minus) withdata-key="-"or a dedicated key value consistent with how operator selection is stored (e.g.data-key="−"with internal mapping toop=subtractin the fetch).leftandafterOp: when the user presses+or−, commit the current operand asleftand remember the chosen op (addvssubtract).=, callfetchwithopset from the remembered operator (defaultaddonly if an operator was set; keep current guardif (left === null) return).7→−→1,0→=→GET /api/calculate?a=7&b=10&op=subtract→ display-3.C, decimal input, and addition flow from issue #1.Test layout
test/calculator.test.jssubtractand regressions onadd/ unknown optest/server.test.jsaddstill works, unknown op 400 (AC3)test/ui.test.js+/=checksFiles to change
lib/calculator.jssubtractbranch incalculateserver.jspublic/index.htmlopon=test/calculator.test.jstest/server.test.jstest/ui.test.jsDo not edit
.forgejo/workflows/ci.ymlfor this task.Test plan
Unit (
test/calculator.test.js)calculate('2', '5', 'subtract')→-3calculate('0.5', '0.25', 'subtract')→0.25calculate('2', '3', 'add')→5calculate('1', '2', 'pow')throwsout of rangeaddHTTP API (
test/server.test.js)?a=2&b=5&op=subtract→ 200,result: -3?a=0.5&b=0.25&op=subtract→ 200,result: 0.25?a=2&b=3&op=add→ 200,result: 5?a=1&b=2&op=pow→ 400,errorstringa/b, non-numeric, empty) withop=subtractwhere applicableAll existing server tests (health, index, 404, add errors) must still pass.
UI / page (
test/ui.test.js)GET /HTML includes a minus control (e.g.data-keyor button text−)./api/calculateremains valid.7−10=→-3in browser (automation out of scope fornode --test).Local gate
npm testbefore every push; all tests green.Risks
op=addon=−(U+2212) vs-(ASCII) in testsdata-keyor escaped minus in HTML; API uses stringsubtract-0or float noiseresultas JSON number; assert exact values in tests from taskaddand error tests unchanged except new subtract cases−adjacent to+following same grid pattern as issue #1Implementation order
lib/calculator.jssubtract branch + unit tests intest/calculator.test.jstest/server.test.js(module already wired)public/index.htmlminus button and operator state +test/ui.test.jsnpm test, then pushaira/2-subtract-numbersAttachment: plan-2-r1.md
Aira · plan review
Plan pushed at
24229b41; independent Dodik plan review started.Aira · dodik-plan PASS on
24229b41The issue #2 plan maps subtraction to four numbered criteria and specifies the right changes: a subtract branch in lib/calculator.js after the existing parseNumber and finite-result checks, no server.js route change because handleCalculate already forwards op and maps thrown errors to 400, and a U+2212 keypad button plus remembered operator in public/index.html so 7, minus, 1, 0, equals fetches a=7&b=10&op=subtract and displays -3. Unit and HTTP tests cover both success cases, the add regression, unknown op, and invalid operands; the page test adds the minus control beside the existing button checks. Scope stays on the calculator, the page, and the three test files. The current suite is 17 passing tests and matches that baseline.
Checks performed
Attachment: dodik-plan-24229b41.json
Aira · implementing
Plan approved by Dodik at
24229b41. Implementation started.Aira · ci
Ready for review at
3aeb445f(PR #10). Waiting for CI.Implemented subtract in lib/calculator.js, minus keypad and dynamic op in public/index.html, and tests in calculator/server/ui suites (22 passing); committed and pushed to aira/2-subtract-numbers.
Aira · CI passed on
3aeb445fAira · review
CI is green on
3aeb445f. Independent Dodik and code review started.Aira · dodik PASS on
3aeb445fCommit
3aeb445adds op=subtract as a-b, a U+2212 minus button that sends that operation, and module, API, and page tests that fail if the new behavior is removed. npm test passed 22/22 with no skips; add and unknown-op errors are unchanged; the diff is limited to the planned files. Live API checks returned {"result":-3} and {"result":0.25}, and replaying 7, minus, 1, 0, = on the page script against the server displayed -3.Checks performed
Attachment: dodik-3aeb445f.json
Aira · reviewer PASS on
3aeb445fSubtraction is implemented consistently with the existing add path:
lib/calculator.jsparses operands and rejects non-finite results,server.jsis unchanged and still maps errors to 400, and the UI storespendingOpand sends the correctopon equals. All 22 tests pass, acceptance API cases match the plan, and manual checks for negatives, large magnitudes, and subtract overflow behave correctly without new security or regression issues.Checks performed
Attachment: reviewer-3aeb445f.json
Aira · qa
Dodik and the reviewer passed on
3aeb445f. Preview deployed at http://127.0.0.1:43553; QA started.Aira · qa PASS on
3aeb445fThe preview at http://127.0.0.1:43553 serves commit
3aeb445ff9. GET /api/calculate?op=subtract returns a-b for the required cases and for negatives and zeros, op=add still returns a sum, and missing, empty, non-numeric, and unknown inputs return 400 with an error field. The page includes a U+2212 minus button that sends op=subtract and displays the API result, so 7, minus, 1, 0, equals follows the same path as 7-10=-3.Checks performed
Attachment: qa-3aeb445f.json
Aira · merging
QA passed on
3aeb445f. Merging.Aira · Merged PR #10
Merge commit
420a70ea9662416dc4224073b60656d67b6be444from reviewed head3aeb445ff9d48e0ad3911b3d9e5068ac62b2d933.3aeb445adds op=subtract as a-b, a U+2212 minus button that sends that operation, and module, API, and page tests that fail if the new behavior is removelib/calculator.jsparses operands and rejects non-finite results,server.jsis unchanged3aeb445ff9. GET /api/calculate?op=subtract returns a-b for the required cases