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#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:f15c8e531f623a9f72d10bfd553fd810fb9191b215801276bdcaf66b50f630a6Aira · Plan (round 1) at
56e1578aWrote docs/plans/issue-1.md with goal, ACs, design, file list, test plan, and risks; committed and pushed to aira/1-add-numbers.
docs/plans/issue-1.md
Issue #1: Add numbers
Goal
Enable addition on the web calculator end to end: a pure
addfunction in the library, aGET /api/calculateendpoint that validates query parameters and returns JSON, and a minimal calculator UI that builds operands, calls the API on=, and shows the result. Preserve existing/healthand/static serving behaviour.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, missinga(?b=2&op=add), and unknown op (?a=1&b=2&op=pow) each return HTTP 400 with a JSON body containing anerrorstring message.0–9,.,+,=, andC. The UI performs sums using the API (example flow:1,2,+,3,=displays15).Design
Calculation module (
lib/calculator.js)parseOperand(value)— returns a finitenumberor throws/returns a structured error for missing, empty, or non-numeric strings (useNumber()and rejectNaN, and treat absent/empty as invalid per contract).add(a, b)— numeric addition (rely on IEEE doubles; satisfies integer and decimal cases).calculate(a, b, op)— dispatch onop; onlyaddis supported in this issue; unknownopis an error.server.jscan map them to400 {"error": "<message>"}without duplicating validation rules.HTTP layer (
server.js)GET /api/calculatebefore the 404 handler:a,b,opfromURLSearchParams.200 {"result": <number>}.400 {"error": "<message>"}with a clear, stable message (e.g. invalid operand, missing parameter, unknown operation).requirethe calculator module; keepsendJson,/health, and/unchanged.createServerfor tests (unchanged contract).UI (
public/index.html)#display, already present).0–9, decimal., operation+,=(equals / calculate),C(clear).=or clear; normalise leading zero behaviour for usability.+: commit current display as first operanda, set pending opadd, reset entry for second operandb.=: ifa, op, and current entry are valid,fetch('/api/calculate?a=...&b=...&op=add'), showresulton success, show error text on 400.C: reset display and operation state.0→1→2(display12) →+→3→=→ display15via API.Test layout
test/calculator.test.jsadd,parseOperand,calculate, unknownop.test/server.test.js/api/calculate(all acceptance API cases); keep existing health/index/404 tests.test/ui.test.js(or extend server test)GET /HTML contains required button labels/elements (0–9,.,+,=,C) and that client script references/api/calculate.Use the existing
withServerhelper pattern and Node’s built-infetch+node:test.Files to change
lib/calculator.jsserver.js/api/calculate.public/index.htmltest/calculator.test.jstest/server.test.jstest/ui.test.jsdocs/plans/issue-1.mdNo changes to
package.json, CI workflows, or dependencies (Node built-ins only).Test plan
Unit (
test/calculator.test.js)add(2, 3) === 5.add(-1.5, 2) === 0.5.calculatewithop=addmatchesadd.undefined/missing representation.op(e.g.pow) yields error.HTTP (
test/server.test.js)a=2&b=3&op=add{ result: 5 }a=-1.5&b=2&op=add{ result: 0.5 }a=x&b=2&op=add{ error: string }b=2&op=add(noa){ error: string }a=1&b=2&op=pow{ error: string }Also re-run existing health, index, and 404 tests unchanged.
UI / page contract
/and verify presence of controls for0–9,.,+,=,C(e.g.buttontext ordata-keyattributes)./api/calculateto prove API integration path (full browser E2E is out of scope fornode --test; manual check for the12 + 3 = 15flow during dev).Pre-push
npm testlocally; all tests green beforegit push origin aira/1-add-numbers.Risks
0.1 + 0.2)resultas returned; document that acceptance cases use exact API values.lib/calculator.js; server only maps errors to HTTP.URLSearchParams/encodeURIComponentin UI when building the fetch URL./healthor/erroris a non-empty string; messages stay stable once chosen.Attachment: plan-1-r1.md
Aira · plan review
Plan pushed at
56e1578a; independent Dodik plan review started.Aira · dodik-plan PASS on
56e1578aThe plan at
56e1578maps every task requirement to a numbered, testable acceptance criterion and names concrete file and behaviour changes that fit the current CommonJS server, #display page, and withServer tests. Unit and HTTP coverage prove the success cases, the invalid-operand and unknown-op errors (including empty and missing values at the calculator boundary), and the required button contract, while preserving /health, /, and 404. Nothing outside addition is in scope.Checks performed
Attachment: dodik-plan-56e1578a.json
Aira · implementing
Plan approved by Dodik at
56e1578a. Implementation started.Aira · ci
Ready for review at
1e8a2ca3(PR #5). Waiting for CI.Implemented calculator module, /api/calculate (add + validation), keypad UI with API-backed '=', and unit/HTTP/UI tests; npm test 20/20; pushed to aira/1-add-numbers.
Aira · CI passed on
1e8a2ca3Aira · review
CI is green on
1e8a2ca3. Independent Dodik and code review started.Aira · dodik PASS on
1e8a2ca3Addition is implemented end to end and matches the approved plan. The API returns 5 for 2+3 and 0.5 for -1.5+2, rejects missing, empty, and non-numeric operands and unknown operations with HTTP 400 and an error string, and the page exposes digits, a decimal, +, =, and C and shows the API sum for 12+3. npm test passed 20/20 with no skipped tests, and the diff has no unrelated or leftover debug changes.
Checks performed
Attachment: dodik-1e8a2ca3.json
Aira · reviewer FAIL on
1e8a2ca3All 20 tests pass and the change satisfies issue #1 acceptance cases (add API, validation errors, keypad UI, preserved /health and /). Manual probes show a correctness gap for very large operands: finite values such as 1e308 still parse, but their sum is Infinity, which JSON.stringify encodes as null while the handler returns HTTP 200, so clients receive {"result":null} instead of a numeric result or a 400 error, and the UI would display the string "null".
Checks performed
1e8a2caAttachment: reviewer-1e8a2ca3.json
Aira · implementing
reviewer failed on
1e8a2ca3; sent the findings to the orchestrator (fix round 1/6).Aira · ci
Ready for review at
4a5ed505(PR #5). Waiting for CI.Fixed reviewer finding: calculate() now rejects non-finite sums (e.g. 1e308+1e308) with CalculatorError → HTTP 400, preventing JSON null on 200; added calculator and server overflow tests; npm test 22/22.
Aira · CI passed on
4a5ed505Aira · review
CI is green on
4a5ed505. Independent Dodik and code review started.Aira · dodik PASS on
4a5ed505Addition is implemented end to end at
4a5ed50531and matches docs/plans/issue-1.md. GET /api/calculate returns 200 {"result":5} for a=2&b=3&op=add and 200 {"result":0.5} for a=-1.5&b=2&op=add, and 400 with an error string for non-numeric, missing, empty, and unknown-op inputs. The served page has buttons 0-9, ., +, =, and C, and the page script shows 15 after 1, 2, +, 3, = by calling /api/calculate?a=12&b=3&op=add. npm test reported 22 passing, 0 failed, and 0 skipped. The diff is limited to the planned calculator, server, UI, tests, and plan file, with no weakened tests or debug leftovers. README still points at the API contract in AGENTS.md.Checks performed
4a5ed50531) with docs/plans/issue-1.mdAttachment: dodik-4a5ed505.json
Aira · reviewer PASS on
4a5ed505The branch satisfies issue #1 end to end: pure add/calculate with consistent CalculatorError mapping to 400 JSON, acceptance API cases covered by tests, keypad UI integrated via fetch, and existing health/index/404 behavior preserved. Manual probes (Infinity/NaN operands, empty op, overflow) match tested behavior with no security or contract regressions found.
Checks performed
4a5ed50531Attachment: reviewer-4a5ed505.json
Aira · qa
Dodik and the reviewer passed on
4a5ed505. Preview deployed at http://127.0.0.1:43011; QA started.Aira · qa PASS on
4a5ed505The preview at commit
4a5ed50531serves addition correctly. /health reports that sha, /api/calculate returns 200 {"result": a+b} for integers, negatives, and decimals, and 400 {"error": "..."} for missing, empty, or non-numeric operands and unknown operations. The page has a display and buttons 0-9, ., +, =, and C, and its script requests /api/calculate and shows the returned result (1, 2, +, 3, = maps to a=12&b=3&op=add, which returns {"result":15}). npm test passed 22 tests covering the calculator, API success and error cases, and the page buttons.Checks performed
Attachment: qa-4a5ed505.json
Aira · merging
QA passed on
4a5ed505. Merging.Aira · Merged PR #5
Merge commit
7952e5e5a5dafd3971a977231400326d366cf248from reviewed head4a5ed505313b8ddddce8b3c25e27d9a01f3d79df.4a5ed50531and matches docs/plans/issue-1.md. GET /api/calculate returns 200 {"result":5} fo4a5ed50531serves addition correctly. /health reports that sha, /api/calculate returns 200 {"result": a+b} f