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-3#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:91844789012ec5024402da4f562edff920fc7ee62b1dcd667de672921db00d05Aira · Plan (round 1) at
950f5b0cWrote issue-1 implementation plan (calculator module, /api/calculate, keypad UI, test plan); committed and pushed to aira/1-add-numbers.
docs/plans/issue-1.md
Issue #1: Add numbers
Goal
Enable addition end-to-end: a pure
addfunction inlib/calculator.js, aGET /api/calculatehandler that validates query parameters and returns results or errors, and a vanilla-JS UI on/with digit keys, decimal point,+,=, andCthat performsa + bvia the API. The example flow1,2,+,3,=must display15.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}.errorstring in the JSON body:GET /api/calculate?a=x&b=2&op=add(non-numerica)GET /api/calculate?b=2&op=add(missinga)GET /api/calculate?a=1&b=2&op=pow(unknownop)/includes buttons for digits0–9,.,+,=, andC, plus a display; the UI shows sums computed through the API (not client-side arithmetic for the final result).Design
Calculator module (
lib/calculator.js)parseNumber(value)— returns a finite number for valid numeric strings (including negatives and decimals); otherwise signals invalid input (throw or return a tagged result consistent with one style used incalculate).calculate(a, b, op)— forop === 'add', returna + b; reject unknown operations with a clear error.Number()or explicit parsing only where it correctly rejects empty strings and non-numeric values (NaN,Infinitytreated as invalid if they appear after parse).add; structurecalculatewith a simpleswitchor map so future ops can extend without changing the HTTP contract.HTTP layer (
server.js)GET /api/calculate(preserve existing/health,/, and 404 behaviour).a,b,opfromURLSearchParams.{"error":"<message>"}):aorbmissing, empty string, or not a valid finite number.opmissing or notadd(e.g.pow).{"result": <number>}using JSON serialization (integers and decimals as JSON numbers).lib/calculator.js; map module errors to 400 responses with stable, human-readable messages (tests may assert status and presence oferror, and optionally message substrings).UI (
public/index.html)#display), button grid for0–9,.,+,=,C(accessible labels, e.g.aria-labelwhere helpful)..input builds current operand string (one decimal point per operand).+commits the first operand and operator; user enters second operand.=callsfetch('/api/calculate?a=...&b=...&op=add'), showsresultin the display (or shows APIerroron failure).Cresets to initial state and display0.1,2,+,3,=, display reads15(operands12and3).Test layout
test/calculator.test.jsadd, parsing, invalid opstest/server.test.js/api/calculatesuccess and every error case; keep health/index/404test/ui.test.js(or extendserver.test.js)/HTML and assert required buttons existUse existing
withServerpattern andfetchagainst ephemeral port.Files to change
lib/calculator.jsparseNumber/calculatewithaddserver.js/api/calculate, import calculatorpublic/index.html=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)add:2 + 3→5;-1.5 + 2→0.5;0 + 0→0.op(e.g.pow) → error path.HTTP API (
test/server.test.js)?a=2&b=3&op=add→ 200,result: 5?a=-1.5&b=2&op=add→ 200,result: 0.5?a=x&b=2&op=add→ 400,errorstring?b=2&op=add(noa) → 400,errorstring?a=1&b=2&op=pow→ 400,errorstringb, emptya, emptybfor robustnessExisting tests: health, index title, unknown route 404 — must still pass.
UI / page (
test/ui.test.jsor server test)GET /body contains controls for0–9,.,+,=,C(e.g.buttonelements with matching text ordata-keyattributes asserted in HTML)./api/calculate(documents API integration; full browser E2E is out of scope fornode --test).Local gate
npm testbefore every push; all tests green.Risks
0.1 + 0.2)resultas returned (JSON).Number('')→ 0)NaNand non-finite values.+)=; reset or clear between operations per minimal state machine; manual check12 + 3 = 15..in one operand./healthor static/Implementation order
lib/calculator.js+test/calculator.test.jsserver.jsAPI route + API tests intest/server.test.jspublic/index.htmlUI + HTML button testsnpm test, then pushaira/1-add-numbersAttachment: plan-1-r1.md
Aira · plan review
Plan pushed at
950f5b0c; independent Dodik plan review started.Aira · dodik-plan PASS on
950f5b0cThe plan at
950f5b0specifies addition end to end and matches the task and the current code. Each requirement maps to a numbered acceptance criterion (2+3=5, -1.5+2=0.5, the three 400 cases, and an API-backed keypad). The design names lib/calculator.js, server.js, and public/index.html and fits createServer, the existing #display page, the withServer helper, and the CommonJS/no-dependency rules. The test plan proves those criteria at unit and HTTP level, including the stated error cases and button presence, while preserving health, index, and 404. Nothing material is missing or out of scope.Checks performed
Attachment: dodik-plan-950f5b0c.json
Aira · implementing
Plan approved by Dodik at
950f5b0c. Implementation started.Aira · ci
Ready for review at
a3c58385(PR #9). Waiting for CI.Implemented parseNumber/calculate add, /api/calculate validation and success paths, calculator keypad UI with API-backed equals, and full test coverage; npm test 15/15; pushed feat commit to aira/1-add-numbers.
Aira · CI passed on
a3c58385Aira · review
CI is green on
a3c58385. Independent Dodik and code review started.Aira · dodik PASS on
a3c58385Addition at
a3c5838matches the approved plan and all four acceptance criteria. The API returns 200 {"result":5} for 2+3 and 200 {"result":0.5} for -1.5+2, and 400 with an error string for non-numeric, missing, and empty operands and for an unknown or missing operation. The page includes buttons 0-9, a decimal point, +, =, and C; the page script calls GET /api/calculate?a=12&b=3&op=add for the 1, 2, +, 3, = flow and shows 15. npm test reports 15 passing and 0 skipped, with no unrelated, weakened, or skipped tests and no debug leftovers. README remains accurate because it already defers to the AGENTS.md contract.Checks performed
Attachment: dodik-a3c58385.json
Aira · reviewer FAIL on
a3c58385Issue #1 addition is implemented correctly for all documented acceptance criteria and the full test suite passes, but operands whose sum exceeds IEEE-754 range yield Infinity in JavaScript and are serialized as JSON null while the server still responds with HTTP 200, which violates the AGENTS.md contract that success bodies contain a numeric result and can leave the UI silent on '='.
Checks performed
a3c5838594reviewedAttachment: reviewer-a3c58385.json
Aira · implementing
reviewer failed on
a3c58385; sent the findings to the orchestrator (fix round 1/6).Aira · ci
Ready for review at
7ec1671a(PR #9). Waiting for CI.Fixed root cause: validate add result with Number.isFinite and return 400 with stable error when IEEE-754 overflow yields Infinity, avoiding JSON null on 200; added unit and API tests; npm test 17/17.
Aira · CI passed on
7ec1671aAira · review
CI is green on
7ec1671a. Independent Dodik and code review started.Aira · dodik PASS on
7ec1671aAddition at
7ec1671matches the approved plan. /api/calculate returns {"result":5} and {"result":0.5} for the required cases and 400 with an error string for missing, empty, and non-numeric operands and for an unknown or missing operation. The page has buttons 0-9, ., +, =, and C; the keypad sequence 1, 2, +, 3, = calls /api/calculate?a=12&b=3&op=add and shows 15. npm test reports 17 passing, 0 failing, and 0 skipped, and the diff stays within the planned files.Checks performed
Attachment: dodik-7ec1671a.json
Aira · reviewer PASS on
7ec1671aThe addition feature at
7ec1671implements the planned calculator module, GET /api/calculate validation, and API-backed keypad UI; all 17 automated tests pass and manual probes confirm acceptance paths (including 12+3=15), preserved /health and / behaviour, and 400 responses for missing/invalid operands, unknown ops, and non-finite overflow results. No blocker or major correctness, security, or contract regressions were found.Checks performed
7ec1671Attachment: reviewer-7ec1671a.json
Aira · qa
Dodik and the reviewer passed on
7ec1671a. Preview deployed at http://127.0.0.1:37283; QA started.Aira · qa PASS on
7ec1671aCommit
7ec1671a2cserves /health with that sha, returns correct addition results for integers, decimals, and negatives, rejects missing, empty, and non-numeric operands and unknown operations with HTTP 400 and an error message, and the index page contains a display plus buttons 0-9, ., +, =, and C that call the API and show the returned sum. Project tests on the same commit all passed.Checks performed
7ec1671a2c-> 17 passed, 0 failedAttachment: qa-7ec1671a.json
Aira · merging
QA passed on
7ec1671a. Merging.Aira · Merged PR #9
Merge commit
78e3095e81f9047ca4b16c69940af535c22d7f38from reviewed head7ec1671a2c80dcce5eea121d42265479278c6481.7ec1671matches the approved plan. /api/calculate returns {"result":5} and {"result":0.5} for the required cases and 400 with an error string for mi7ec1671implements the planned calculator module, GET /api/calculate validation, and API-backed keypad UI; all 17 automated tests pass a7ec1671a2cserves /health with that sha, returns correct addition results for integers, decimals, and negatives, rejects mi