Add numbers #1
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#1
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?
The calculator cannot calculate yet. Add addition.
Requirements
GET /api/calculate?a=<number>&b=<number>&op=addreturns200 {"result": a + b}.a=-1.5&b=2gives0.5).aorb, or an unknownop, returns400 {"error": "<message>"}./): a display, digit buttons 0-9, a decimal point, a+button, an=button and aC(clear) button. Pressing1,2,+,3,=shows15, using the API for the calculation.Acceptance criteria
/api/calculate?a=2&b=3&op=addreturns{"result":5}./api/calculate?a=-1.5&b=2&op=addreturns{"result":0.5}./api/calculate?a=x&b=2&op=add,?b=2&op=addand?a=1&b=2&op=powreturn 400 with anerrormessage..,+,=andC, and the UI shows sums returned by the API.Aira · queued
Aira picked up this task. Branch
aira/1-add-numbers.Aira · planning
Orchestrator thread started (composer-2.5). Planning on
aira/1-add-numbers.T3 thread:
mcp:launch:6da702d3ddd84359e9bf0a0583438cfa612083122e17f8c6babc52f660a964faAira · Plan (round 1) at
eae347eeAdded docs/plans/issue-1.md (goal, acceptance criteria, design, test plan, risks), committed, and pushed branch aira/1-add-numbers.
docs/plans/issue-1.md
Issue #1: Add numbers
Goal
Enable addition in the web calculator end to end: a pure
addfunction inlib/calculator.js, aGET /api/calculatehandler that validates query parameters and returns results or errors, and a button-based UI that builds two operands, invokes the API on=, and shows the sum on the display. The example flow1,2,+,3,=must show15.Acceptance criteria
GET /api/calculate?a=2&b=3&op=addreturns HTTP 200 with body{"result":5}.GET /api/calculate?a=-1.5&b=2&op=addreturns HTTP 200 with body{"result":0.5}.{"error":"<message>"}:a(e.g.?a=x&b=2&op=add)a(e.g.?b=2&op=add)op(e.g.?a=1&b=2&op=pow)b, missing/emptyop)/includes digit buttons0–9,.,+,=, andC, and the UI displays sums returned by the API (including the12+3=→15behaviour).Design
Calculator module (
lib/calculator.js)add(a, b)— returnsa + bfor finite numbers (caller supplies parsed numbers).parseNumber(raw)— returns a number ornullifrawis missing, empty, or not a valid numeric string (support negatives and decimals viaNumber()/ trimming rules consistent with tests).calculate(op, a, b)— dispatchesop === 'add'toadd; unknown ops throw or return a structured error object used by the server.HTTP layer (
server.js)GET /api/calculate:a,b,opfrom query string (url.searchParams).opis present and equalsaddfor this issue; otherwise 400 with a clearerrormessage.aandbwith the same rules as the module; 400 on failure.{"result": <number>}.lib/calculator.js; keep existing/health,/, and 404 behaviour unchanged.UI (
public/index.html)#display) showing the current value or result.0–9,.,+,=,C..append to the current entry (reasonable rules for one decimal point per number).+commits the first operand and waits for the second.=callsfetch('/api/calculate?a=...&b=...&op=add'), parses JSON, sets display toresult(or shows error).Cresets state and display.<button>elements with identifiable text ordata-*attributes).Files to change
lib/calculator.jsserver.js/api/calculate.public/index.htmltest/calculator.test.jsadd, parsing, and unknown op.test/server.test.jstest/ui.test.jspublic/index.htmland assert required buttons exist.(Exact test file split follows existing project style after skim of
test/; minimum is module tests + HTTP tests + HTML content checks per AGENTS.md.)Test plan
Unit tests (
test/calculator.test.js)add(2, 3) === 5add(-1.5, 2) === 0.5parseNumberrejectsundefined,'','x'calculate('add', ...)success;calculate('pow', ...)errorHTTP tests (
test/server.test.js)Use existing
withServer+fetchpattern:?a=2&b=3&op=add{ result: 5 }?a=-1.5&b=2&op=add{ result: 0.5 }?a=x&b=2&op=adderrorstring?b=2&op=add(noa)errorstring?a=1&b=2&op=powerrorstringb, emptya/b, non-numericberrorstringUI / page tests
public/index.html(or GET/and assert HTML contains) buttons for0–9,.,+,=, andC.12+3=→15; prefer a small unit test on any extracted display/format helpers if added.Run
npm testlocally before every push; all tests must pass.Risks
0.1 + 0.2)resultas returned JSON number; display viaString(result)or reasonable formatting; tests focus on given acceptance examples.=or+C; document behaviour in code only if non-obvious..in current entry.errorstring, not exact wording, unless project already fixes messages.addin calculator dispatch; reject all otheropvalues with 400.Implementation order (for later steps)
lib/calculator.js+test/calculator.test.js/api/calculateinserver.js+ HTTP testspublic/index.htmlUI + button presence testsnpm test, then push branchaira/1-add-numbersAttachment: plan-1-r1.md
Aira · plan review
Plan pushed at
eae347ee; independent Dodik plan review started.Aira · dodik-plan PASS on
eae347eeThe plan at
eae347ecovers addition end to end. Each requirement maps to a numbered, testable acceptance criterion; the design names lib/calculator.js, server.js, public/index.html, and the test files and matches the current server (URL parsing, sendJson, /health, /, 404), the existing #display placeholder, and the withServer/fetch tests. The test plan proves the success cases, negative and decimal input, and every required 400 case at HTTP level, with unit coverage for add, parsing, and unknown op, plus HTML checks for buttons 0-9, ., +, =, and C. Scope stays on op=add and leaves health, index serving, and 404 unchanged.Checks performed
Attachment: dodik-plan-eae347ee.json
Aira · implementing
Plan approved by Dodik at
eae347ee. Implementation started.Aira · ci
Ready for review at
2e749ee5(PR #9). Waiting for CI.Implemented lib/calculator.js, /api/calculate route, calculator UI calling the API, and unit/HTTP/UI tests (23 passing). Committed and pushed to aira/1-add-numbers.
Aira · CI passed on
2e749ee5Aira · review
CI is green on
2e749ee5. Independent Dodik and code review started.Aira · dodik PASS on
2e749ee5Addition is implemented end to end and matches the approved plan. The API returns 200 {"result":5} and {"result":0.5} for the required inputs, 400 with an error message for invalid, missing, empty, and unknown-op requests, and the page buttons compute 12+3 through the API and show 15. All 23 tests pass, the new tests fail on origin/main, and the diff has no unrelated, skipped, or weakened tests.
Checks performed
Attachment: dodik-2e749ee5.json
Aira · reviewer FAIL on
2e749ee5The change set correctly implements addition end-to-end for the documented acceptance paths (including 12+3=15), preserves /health and /, validates typical bad inputs with 400, and all 23 tests pass. However, operands that parse as finite numbers but produce a non-finite sum (e.g. 1e308+1e308) or explicit Infinity inputs yield HTTP 200 with body {"result":null} because JSON.stringify converts Infinity to null, which breaks the stated contract that a successful response contains a JSON number in result and mishandles the “huge” case called out for review.
Checks performed
Attachment: reviewer-2e749ee5.json
Aira · implementing
reviewer failed on
2e749ee5; sent the findings to the orchestrator (fix round 1/6).Aira · ci
Ready for review at
ec34a938(PR #9). Waiting for CI.Fixed root cause: reject non-finite operands in parseNumber/calculate and overflow sums before respond, so 200 always returns a finite JSON number; added tests for 1e308+1e308 and Infinity operands (28 passing).
Aira · CI passed on
ec34a938Aira · review
CI is green on
ec34a938. Independent Dodik and code review started.Aira · dodik PASS on
ec34a938Addition at
ec34a93813matches the plan and acceptance criteria. GET /api/calculate returns {"result":5} for 2+3 and {"result":0.5} for -1.5+2, and returns 400 with an error string for missing, empty, and non-numeric operands and for a missing, empty, or unknown operation. The page script creates buttons 0-9, ., +, =, and C; the sequence 1, 2, +, 3, = requests /api/calculate?a=12&b=3&op=add and shows 15. npm test passed 28/28 with no skips, and the new tests fail against origin/main. The diff is limited to the calculator, API, UI, tests, and docs/plans/issue-1.md; README still correctly points at the API contract.Checks performed
ec34a93813with docs/plans/issue-1.mdAttachment: dodik-ec34a938.json
Aira · reviewer PASS on
ec34a938Issue #1 add-numbers implementation meets the documented API contract and acceptance criteria: calculate validation and addition behave correctly for required success and error cases (including overflow and infinity), existing routes remain intact, and the full test suite (28/28) passes. UI and server logic support the documented 12+3=15 example; no correctness, security, or contract-breaking issues warranted a fail.
Checks performed
ec34a938reviewedAttachment: reviewer-ec34a938.json
Aira · qa
Dodik and the reviewer passed on
ec34a938. Preview deployed at http://127.0.0.1:38827; QA started.Aira · qa PASS on
ec34a938The preview at http://127.0.0.1:38827 serves commit
ec34a93813. GET /api/calculate?op=add returns the sum for integers, negatives, and decimals, and returns 400 with an error message for missing, empty, and non-numeric operands and for an unknown operation. The page includes a display and buttons 0-9, ., +, =, and C, and the equals action shows the sum returned by the API (12+3 is 15). npm test passed 28 tests.Checks performed
Attachment: qa-ec34a938.json
Aira · merging
QA passed on
ec34a938. Merging.Aira · Merged PR #9
Merge commit
28d9e6842d659537e64b89855e2965ca13312651from reviewed headec34a93813e6cdbcbeedeb39123ee9668ab921b7.ec34a93813matches the plan and acceptance criteria. GET /api/calculate returns {"result":5} for 2+3 and {"result":0.5ec34a93813. GET /api/calculate?op=add returns the sum for integers, negatives,