Percentage #5
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#5
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 percentage operation.
Requirements
op=percentreturnsa * b / 100("a percent of b").%button that works like the other binary operators. Pressing5,0,%,8,=shows4.Acceptance criteria
/api/calculate?a=50&b=8&op=percentreturns{"result":4}./api/calculate?a=12.5&b=200&op=percentreturns{"result":25}.error.%button.Aira · queued
Aira picked up this task. Branch
aira/5-percentage.Aira · planning
Orchestrator thread started (composer-2.5). Planning on
aira/5-percentage.T3 thread:
mcp:launch:ccc88428bdabe1bf85b7b7566d287bb2a37466164be54adc1082889e38578695Aira · Plan (round 1) at
9ece0131Added docs/plans/issue-5.md for the percent operation (API, UI, tests, risks), committed, and pushed aira/5-percentage.
docs/plans/issue-5.md
Issue #5: Percentage
Goal
Extend the calculator with a percentage operation end-to-end: handle
op=percentinlib/calculator.jsas a percent of b (a * b / 100), expose it through the existingGET /api/calculateroute (unchanged contract), and add a%keypad button that behaves like+,−,×, and÷. The flow5,0,%,8,=must display4via the API (50% of 8). Addition, subtraction, multiplication, division, validation, and other error responses remain unchanged.Acceptance criteria
GET /api/calculate?a=50&b=8&op=percentreturns HTTP 200 with body{"result":4}.GET /api/calculate?a=12.5&b=200&op=percentreturns HTTP 200 with body{"result":25}.a/b, non-numeric operands, unknownop, missingop) still returns HTTP 400 with anerrorstring in the JSON body./includes a working%button;50%8=shows4on the display (viaGET /api/calculate?a=50&b=8&op=percent).Design
Calculator module (
lib/calculator.js)calculate(a, b, op)with a branch forop === 'percent':parseNumberyieldsxandy, computeresult = (x * y) / 100.result out of range(parity with add / subtract / multiply / divide).0operands are valid.percentbecomes the fifth supported operation.parseNumberunchanged.HTTP layer (
server.js)handleCalculatealready passesopthrough tocalculate; operand and unknown-op errors are mapped to HTTP 400 via existingcatch (err) → sendJson(400, { error: err.message }).200 {"result": <number>}for AC1–2.UI (
public/index.html)%withdata-key="%consistent with other operators.%in the operator key set and map it topendingOp = 'percent'inopMapalongside existing operators.=, continuefetch('/api/calculate?...')withopfrompendingOp(no special error display for percent; use existing error path).5→0→%→8→=→GET /api/calculate?a=50&b=8&op=percent→ display4.a), second is the base (b).Keypad layout
÷,×,−,+;Cand=share the bottom row with digits. Add%on an open or operator-adjacent cell without removingC, digits,.,=, or existing operators — e.g. place%beside an existing operator row following the same button styling as issue #4’s÷placement pattern.data-key="%"is present in served HTML.Test layout
test/calculator.test.jspercent, decimals, regressions on other opstest/server.test.jstest/ui.test.js%button in HTML; static checks forpercentop mappingFiles to change
lib/calculator.jspercentbranch (x * y / 100)public/index.html%button, operator mapping topercenttest/calculator.test.jstest/server.test.jsop=percent(AC3)test/ui.test.js%toREQUIRED_KEYS; assertpercentin operator mappingTest plan
Unit (
test/calculator.test.js)calculate('50', '8', 'percent')→4calculate('12.5', '200', 'percent')→25calculate('0', '100', 'percent')→0calculate('100', '0', 'percent')→0calculate('2', '3', 'add')→5calculate('9', '3', 'divide')→3calculate('1', '2', 'pow')throws unknown operationout of rangeHTTP (
test/server.test.js)?a=50&b=8&op=percent→ 200,result: 4?a=12.5&b=200&op=percent→ 200,result: 25?a=x&b=2&op=percent→ 400,errorstring?a=1&op=percent(missingb) → 400,errorstring?a=1&b=2&op=foo→ 400,errorstring?a=2&b=3&op=add→ 200,result: 5All existing server tests (health, index, 404, prior op errors, divide) must still pass.
UI (
test/ui.test.js)data-key="%"%topercent(e.g. match on'percent'inopMapor operator handler)REQUIRED_KEYS(other ops),/api/calculatefetch remainFull suite:
npm testmust pass before push.Risks
b * a / 100vsa * b / 100, ora / 100only)50and8→4; unit and HTTP tests lock semanticsbas percent,aas base)a, second isb; document flow in design; AC4 flow50 % 8→ 44,25); useassert.equal/deepEquallike other ops%%in regex or HTML test escaping%inRegExpforREQUIRED_KEYSloop like other special chars if needed (literal%in attribute is fine)Implementation order
lib/calculator.jspercent branch + unit tests intest/calculator.test.jstest/server.test.jsfor AC1–3 and regressionspublic/index.html%button and operator mapping +test/ui.test.jsnpm test, then pushaira/5-percentageAttachment: plan-5-r1.md
Aira · plan review
Plan pushed at
9ece0131; independent Dodik plan review started.Aira · dodik-plan PASS on
9ece0131The plan at
9ece013covers percentage end to end and matches the code. Acceptance criteria 1–4 are concrete HTTP and page checks for a*b/100, bad input, and the % button flow 5 0 % 8 = showing 4. The design adds a percent branch in lib/calculator.js, leaves server.js validation unchanged, and wires a % key through the existing binary-operator path in public/index.html. The test plan proves those criteria in the module, over HTTP, and on the page, including zero operands and the error cases the task names, while existing operations stay covered by the current suite (34 tests passing).Checks performed
9ece013and confirmed the percent branch, unchanged 400 mapping, and % → pendingOp percent fit the current operator flowAttachment: dodik-plan-9ece0131.json
Aira · implementing
Plan approved by Dodik at
9ece0131. Implementation started.Aira · ci
Ready for review at
2d50abbf(PR #13). Waiting for CI.Implemented percent in calculator and UI, added unit/server/UI tests covering all acceptance criteria; npm test 41/41 pass; pushed feat commit on aira/5-percentage.
Aira · CI passed on
2d50abbfAira · review
CI is green on
2d50abbf. Independent Dodik and code review started.Aira · dodik PASS on
2d50abbfPercentage is implemented as a percent of b (a * b / 100) in the calculator, the API, and a % button that follows the other binary operators. All 41 tests passed, the acceptance requests return 4 and 25, bad input still returns 400 with an error, and the 5 0 % 8 = flow displays 4. The diff is limited to that feature, its tests, and the issue plan; nothing was weakened or left as debug code.
Checks performed
Attachment: dodik-2d50abbf.json
Aira · reviewer PASS on
2d50abbfIssue #5 adds a correct
percentoperation (a * b / 100) with finite-result checks matching other ops, extends the UI with a%button mapped topendingOp = 'percent', and adds focused unit, HTTP, and static UI tests.npm testpasses all 41 tests; manual checks confirm negatives, zero operands, invalid emptyb, and overflow handling.server.jsis unchanged and existing validation and error responses apply toop=percentwithout regressions.Checks performed
2d50abbfAttachment: reviewer-2d50abbf.json
Aira · qa
Dodik and the reviewer passed on
2d50abbf. Preview deployed at http://127.0.0.1:35279; QA started.Aira · qa PASS on
2d50abbfHealth returns the preview commit. op=percent computes a percent of b (50 of 8 is 4, 12.5 of 200 is 25), including zero, negative, and decimal edges. Missing, empty, and non-numeric operands and unknown operations return 400 with an error string. Add, subtract, multiply, divide, and division by zero still behave as before. The served page includes a % button wired like the other binary operators, so 5, 0, %, 8, = calls op=percent and shows 4. npm test passed 41 tests covering the module, API, and page.
Checks performed
Attachment: qa-2d50abbf.json
Aira · merging
QA passed on
2d50abbf. Merging.Aira · Merged PR #13
Merge commit
8fb581d67873b5da55f468b11804e6ae33fa4892from reviewed head2d50abbfb3860ae8b41e8278d2eed5c93f28bcb2.percentoperation (a * b / 100) with finite-result checks matching other ops, extends the UI with a%button mapped to `pendingOp