Square root #6
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#6
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 a square root operation. It is the first unary operation, so the API must accept it without
b.Requirements
GET /api/calculate?a=<number>&op=sqrtreturns{"result": Math.sqrt(a)}.bis not required forsqrtand is ignored if present.400 {"error": "square root of a negative number"}.aandb.√button that applies to the number currently on the display immediately (no=needed). Pressing8,1,√shows9; a negative input showsError.Acceptance criteria
/api/calculate?a=81&op=sqrtreturns{"result":9}./api/calculate?a=2&op=sqrtreturns a result between 1.41421 and 1.41422./api/calculate?a=-4&op=sqrtreturns 400{"error":"square root of a negative number"}./api/calculate?a=1&op=add(missing b) still returns 400.√button.Aira · queued
Aira picked up this task. Branch
aira/6-square-root.Aira · planning
Orchestrator thread started (composer-2.5). Planning on
aira/6-square-root.T3 thread:
mcp:launch:a0898b02d8caeabf9df288722b8964b0f6e9c6696f98901144e4a59c3e30b45bAira · Plan (round 1) at
04cf219fWrote docs/plans/issue-6.md (goal, AC1–5, unary sqrt design, files, test plan, risks), committed, and pushed aira/6-square-root.
docs/plans/issue-6.md
Issue #6: Square root
Goal
Add square root as the first unary operation end-to-end:
op=sqrtuses only operanda(Math.sqrt(a)),bis neither required nor validated when present, binary operations still require both operands, and the UI exposes a√button that applies to the current display immediately (no=). Example:8,1,√shows9. Negative input under sqrt showsErroron the display.Acceptance criteria
GET /api/calculate?a=81&op=sqrtreturns HTTP 200 with body{"result":9}.GET /api/calculate?a=2&op=sqrtreturns HTTP 200 with aresultbetween1.41421and1.41422.GET /api/calculate?a=-4&op=sqrtreturns HTTP 400 with body{"error":"square root of a negative number"}.GET /api/calculate?a=1&op=add(missingb) still returns HTTP 400 with anerrorstring in the JSON body./has a working√button: entering8,1, then√shows9; a negative displayed value followed by√showsError.Design
Calculator module (
lib/calculator.js)calculate(a, b, op):op === 'sqrt'): parse onlyawithparseNumber(a); do not read or validateb(extra query param is ignored).aandbas today so missingbstill throwsoperand is required/ related messages.sqrtbranch:x < 0, thrownew Error('square root of a negative number')(exact message for AC3).result = Math.sqrt(x); if not finite, throwresult out of range(parity with other ops).sqrt(0)and positive non-integers use normalMath.sqrt(AC2).opunchanged.HTTP layer (
server.js)handleCalculatecan remain structurally the same (passa,b,opintocalculate); unary-vs-binary operand rules live inlib/calculator.js.bmay be absent forsqrtonly; no new routes or status-code mapping.catch (err) → sendJson(400, { error: err.message })covers negative sqrt and missingbon binary ops.UI (
public/index.html)√withdata-key="√"(Unicode root symbol).√click, takecurrentOperand()asa,fetch('/api/calculate?a=' + encodeURIComponent(a) + '&op=sqrt')(nob, no=).operandtoString(body.result); clearleft/pendingOp/afterOpso the user can continue from the result.body.error === 'square root of a negative number', showError(match division-by-zero UX); other errors may show the message orErrorper existing patterns.+,−,×,÷,%) and=behavior unchanged.√without removing existing keys (e.g. operator column or row near%/÷), same button styling as other operators.API contract note
op=sqrt,bis optional and ignored; for all other supported ops, bothaandbremain required. AGENTS.md can be updated in implementation if Aira wants docs in sync (not required for AC).Test layout
test/calculator.test.jssqrt, negative reject, binary still needsb, regressionstest/server.test.jsb, regressionstest/ui.test.js√button in HTML; script wires immediatesqrtAPI call and negative →ErrorFiles to change
lib/calculator.jssqrt; binary ops unchanged regardingbpublic/index.html√button; immediate unary handlertest/calculator.test.jstest/server.test.jsbon add (AC4); optionalbignored on sqrttest/ui.test.js√to required keys; assertsqrtop and error mappingTest plan
Unit (
test/calculator.test.js)calculate('81', undefined, 'sqrt')→9calculate('2', null, 'sqrt')→ ~√2 within boundscalculate('-4', undefined, 'sqrt')throwssquare root of a negative numbercalculate('1', undefined, 'add')throws (operand / required)calculate('9', '999', 'sqrt')→3(ignoreb)calculate('0', undefined, 'sqrt')→0calculate('2', '3', 'add')→5calculate('50', '8', 'percent')→4HTTP (
test/server.test.js)?a=81&op=sqrt→ 200,result: 9?a=2&op=sqrt→ 200,resultin (1.41421, 1.41422)?a=-4&op=sqrt→ 400,{ error: 'square root of a negative number' }?a=1&op=add→ 400,errorstring?a=81&b=0&op=sqrt→ 200,result: 9bignored?a=2&b=3&op=add→ 200,result: 5?a=1&b=0&op=divide→ 400 division by zeroAll existing server tests (health, index, 404, prior op errors) must still pass.
UI (
test/ui.test.js)data-key="√"op=sqrtand unary fetch (nobin sqrt path)Errordisplay (same pattern asdivision by zero)REQUIRED_KEYSand binarypercentmapping remainFull suite:
npm testmust pass before push.Risks
calculatestill parsesbforsqrtvia shared pathopbeforeparseNumber(b)for unary ops onlybaccidentally allowed for add/subtract/etc.addwithoutb; keep binary list explicit√like binary op (needs=)81→√→9covered in manual QA; UI tests assert immediatesqrtsquare root of a negative number; assert in unit + HTTP testsresultin HTTP test, not exact decimal equality√in regex testsREQUIRED_KEYSloop like other special charactersImplementation order
lib/calculator.jssqrt + unary/binary split + unit tests intest/calculator.test.jstest/server.test.jsfor AC1–4 and ignoredbon sqrtpublic/index.html√button and immediate unary handler +test/ui.test.jsnpm test, then pushaira/6-square-rootAttachment: plan-6-r1.md
Aira · plan review
Plan pushed at
04cf219f; independent Dodik plan review started.Aira · dodik-plan PASS on
04cf219fThe issue #6 plan at
04cf219maps every requirement to a numbered, testable acceptance criterion and matches the current calculator, server, and page. Unary sqrt is specified before parseNumber(b), binary ops still require both operands, negative sqrt uses the exact 400 error string, and the √ button applies to the current display without equals. Unit, HTTP, and page tests cover AC1–AC5, ignored b, sqrt(0), and binary regressions, with nothing material missing or out of scope.Checks performed
04cf219Attachment: dodik-plan-04cf219f.json
Aira · implementing
Plan approved by Dodik at
04cf219f. Implementation started.Aira · ci
Ready for review at
f97ec43a(PR #14). Waiting for CI.Implemented sqrt (calculator, UI √ button with immediate apply, tests); npm test 50/50 pass; pushed aira/6-square-root.
Aira · CI passed on
f97ec43aAira · review
CI is green on
f97ec43a. Independent Dodik and code review started.Aira · dodik PASS on
f97ec43aSquare root is implemented as a unary operation end to end. The API returns 9 for a=81, a value strictly between 1.41421 and 1.41422 for a=2, and 400 with the exact negative-root error for a=-4. Missing b on add still returns 400, and an extra b on sqrt is ignored. The page has a √ button that calls op=sqrt immediately and shows Error for a negative value. npm test passed 50/50 with no skips, and the diff stays within the planned files.
Checks performed
f97ec43against origin/main and docs/plans/issue-6.mdAttachment: dodik-f97ec43a.json
Aira · reviewer PASS on
f97ec43aThe square-root feature correctly implements unary
op=sqrtinlib/calculator.js(negative inputs rejected with the specified message,bskipped), exposes immediate √ handling in the UI consistent with existing fetch/error patterns, and adds HTTP/unit/UI tests that cover AC1–AC5 and binary regressions including missingbon add. Fullnpm test(50/50) passed atf97ec43; manual probes confirmed 400 responses for missing/emptya, ignored invalidb, and intact/health. No blocker or major correctness, security, or contract violations were found.Checks performed
f97ec43Attachment: reviewer-f97ec43a.json
Aira · qa
Dodik and the reviewer passed on
f97ec43a. Preview deployed at http://127.0.0.1:40909; QA started.Aira · qa PASS on
f97ec43aCommit
f97ec43a55serves a working square-root API and a √ button. GET /api/calculate?a=81&op=sqrt returns {"result":9}, sqrt(2) is 1.4142135623730951, a negative input returns 400 {"error":"square root of a negative number"}, and add without b still returns 400. The page button applies sqrt to the display immediately and shows Error for that negative case. Health reports the same sha, binary operations still require both operands, and npm test passed 50/50.Checks performed
f97ec43a55: 50 passed, 0 failed, including calculate sqrt module tests, API sqrt tests, and the index page sqrt wiring testAttachment: qa-f97ec43a.json
Aira · merging
QA passed on
f97ec43a. Merging.Aira · Merged PR #14
Merge commit
0b92e5df1ea7331816904ccaf6585a291aadf37efrom reviewed headf97ec43a55538ccb1e10cb43b5589211f3228650.op=sqrtinlib/calculator.js(negative inputs rejected with the specified message,bskipped), exposesf97ec43a55serves a working square-root API and a √ button. GET /api/calculate?a=81&op=sqrt returns {"result":9}, sqrt(2) i