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#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:9957c1149a1f9eb5ec9c7ccb8cd1c2919a8db07a66402a00590211ba86917eb3Aira · Plan (round 1) at
9d74802cRead AGENTS.md and the existing add implementation; wrote docs/plans/issue-2.md following issue-1 format; committed and pushed to aira/2-subtract-numbers. No code changes yet.
docs/plans/issue-2.md
Issue #2: Subtract numbers
Goal
Add subtraction alongside addition end to end: a pure
subtractfunction inlib/calculator.js,GET /api/calculatesupport forop=subtract, and a−(minus) button in the UI that behaves like+but invokes subtraction on=. The example flow7,−,1,0,=must show-3. Addition and existing error handling 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}.op=addstill works (e.g. existing success cases) and an unknownopstill returns HTTP 400 with{"error":"<message>"}./has a minus button and displays differences returned by the API (including7−10=→-3via the client calling the API withop=subtract).Design
Calculator module (
lib/calculator.js)subtract(a, b)— returnsa - bfor finite numbers (caller supplies parsed numbers).calculate(op, a, b):op === 'subtract'tosubtract(same operand validation path asadd).addandsubtract; any otheropreturns{ error: 'unknown operation' }.subtractfrommodule.exportsalongside existing exports.parseNumberand non-finite result checks (overflow /Infinityon subtract should mirror add behaviour).HTTP layer (
server.js)/api/calculatealready delegates tocalculate(op, a, b).UI (
public/index.html)−key to the button grid (Unicode minus U+2212 or consistent−label in thelabelsarray anddataset.key).pendingOp(default'add'or set on operator press):+and−commit the current operand as the first number and setpendingOpto'add'or'subtract'respectively (samewaitingForSecondflow as today’s+).=buildsURLSearchParamswithop: pendingOp(not hardcoded'add').=, resetpendingOpto a sensible default (e.g.'add') so chained use stays predictable..,C, and display behaviour aligned with issue #1.Files to change
lib/calculator.jssubtract; extendcalculateforop=subtract; exportsubtract.server.jspublic/index.htmlpendingOp; passopto API on=.test/calculator.test.jssubtractandcalculate('subtract', ...).test/server.test.jstest/ui.test.jssubtractor dynamicop.Test plan
Unit tests (
test/calculator.test.js)subtract(2, 5) === -3subtract(0.5, 0.25) === 0.25calculate('subtract', '2', '5')→{ result: -3 }calculate('add', ...)still succeedscalculate('pow', ...)still unknown errorHTTP tests (
test/server.test.js)Use existing
withServer+fetchpattern:?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 }(regression)?a=1&b=2&op=powerrorstring?a=7&b=10&op=subtract{ result: -3 }(UI example operands)UI / page tests (
test/ui.test.js)labels(or equivalent) includes minus ('−'or documented label)+,=,C, andfetchto/api/calculatesubtractor non–hardcoded-onlyadd)Run
npm testlocally before every push; all tests must pass.Risks
-vs Unicode−in UI label vs APIop=subtract)op=subtract; UI label is display-only; tests assert HTML contains the minus key label used in code.op: 'add'on=pendingOpset by+/−; test that fetch params include subtract.0.5 - 0.25calculatestructure; add subtract branch only; run full existing test suite.labelsorder to fit 4-column grid without removing existing keys.Implementation order (for later steps)
lib/calculator.js+test/calculator.test.jstest/server.test.js(server unchanged)public/index.htmlUI +test/ui.test.jsnpm test, then push branchaira/2-subtract-numbersAttachment: plan-2-r1.md
Aira · plan review
Plan pushed at
9d74802c; independent Dodik plan review started.Aira · dodik-plan PASS on
9d74802cThe issue #2 plan at
9d74802maps each subtraction requirement to a numbered, testable acceptance criterion, and the design matches the current code: subtract belongs in lib/calculator.js on the same validation path as add, server.js already delegates op to calculate, and the page should add a − key plus pendingOp instead of hardcoding op=add. The test plan covers the module, the HTTP cases (including 2−5, 0.5−0.25, add regression, unknown op, and the 7−10 example), and the page button and wiring, with no out-of-scope work.Checks performed
9d74802with a clean tree and read docs/plans/issue-2.mdAttachment: dodik-plan-9d74802c.json
Aira · implementing
Plan approved by Dodik at
9d74802c. Implementation started.Aira · ci
Ready for review at
3482997d(PR #10). Waiting for CI.Implemented subtract in lib/calculator.js, minus button and pendingOp in public/index.html (server unchanged), and unit/HTTP/UI tests for all acceptance criteria. npm test: 34 passed. Pushed feat commit on aira/2-subtract-numbers.
Aira · CI passed on
3482997dAira · review
CI is green on
3482997d. Independent Dodik and code review started.Aira · dodik PASS on
3482997dCommit
3482997implements subtraction as specified in docs/plans/issue-2.md. GET /api/calculate?a=2&b=5&op=subtract returns 200 {"result":-3} and a=0.5&b=0.25 returns 200 {"result":0.25}; op=add still returns sums and an unknown op still returns 400 {"error":"unknown operation"}. The page has a Unicode minus button that sets pendingOp to subtract, and the sequence 7, −, 1, 0, = calls a=7&b=10&op=subtract and shows -3, while 1, 2, +, 3, = still shows 15. npm test passed 34 tests with none skipped or weakened, and the diff is limited to the plan, calculator, page, and tests.Checks performed
3482997: only docs/plans/issue-2.md, lib/calculator.js, public/index.html, test/calculator.test.js, test/server.test.js, and test/ui.test.js changed; server.js was left unchanged as planned.Attachment: dodik-3482997d.json
Aira · reviewer PASS on
3482997dThe subtraction feature is implemented consistently across lib/calculator.js, the existing server delegate, and the UI via pendingOp and a minus key; acceptance API cases and regressions for add and unknown op are covered by tests, and npm test passes with no correctness, security, or behavioural regressions identified in the diff.
Checks performed
Attachment: reviewer-3482997d.json
Aira · qa
Dodik and the reviewer passed on
3482997d. Preview deployed at http://127.0.0.1:46141; QA started.Aira · qa PASS on
3482997dHealth reports sha
3482997d53. GET /api/calculate?a=2&b=5&op=subtract returns 200 {"result":-3}, a=0.5&b=0.25&op=subtract returns 200 {"result":0.25}, and the UI sequence 7 − 10 (= a=7&b=10&op=subtract) returns 200 {"result":-3}. op=add still returns 200 {"result":7} for a=2&b=5, unknown and missing or non-numeric inputs return 400 {"error":...}, and GET / is 200 HTML containing a U+2212 minus button wired to op=subtract that displays the API result. npm test passed 34/34.Checks performed
Attachment: qa-3482997d.json
Aira · merging
QA passed on
3482997d. Merging.Aira · Merged PR #10
Merge commit
8956e23d9afb718b23b33f59ddf1946fa431e373from reviewed head3482997d53916d01af53e954b64ce2935a4c484e.3482997implements subtraction as specified in docs/plans/issue-2.md. GET /api/calculate?a=2&b=5&op=subtract returns 200 {"result":-3} and a=0.5&b=0.25 r3482997d53. GET /api/calculate?a=2&b=5&op=subtract returns 200 {"result":-3}, a=0.5&b=0.25&op=subtract returns