Calculation history #11
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#11
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?
Keep a short history of successful calculations.
Requirements
GET /api/historyreturns200 {"items": [{"a": <number>, "b": <number or null>, "op": "<op>", "result": <number>}]}.DELETE /api/historyclears it and returns204.=(and after√), and a "Clear history" button.Acceptance criteria
2+3and6*7,GET /api/historylists6*7=42first and2+3=5second.DELETE /api/historyreturns 204 and the history is empty afterwards.Aira · queued
Aira picked up this task. Branch
aira/11-calculation-history.Aira · planning
Orchestrator thread started (composer-2.5). Planning on
aira/11-calculation-history.T3 thread:
mcp:launch:ebc85b07ef5a22b98bde5c4de63e7e28d9edb12037cbff6180a9364b4e35b3d2Aira · Plan (round 1) at
a470846eWrote docs/plans/issue-11.md for in-memory calculation history (lib/history.js, GET/DELETE /api/history, UI list + clear), committed and pushed branch aira/11-calculation-history.
docs/plans/issue-11.md
Issue #11: Calculation history
Goal
Keep a short in-memory history of successful calculations on the server, expose it via
GET /api/historyandDELETE /api/history, and show a refreshable History list with a Clear history control on the calculator page. History entries preserve operands, operation name, and result; failed calculations are never stored.Acceptance criteria
2+3and6*7,GET /api/historylists6*7=42first and2+3=5second (newest first).DELETE /api/historyreturns 204 and the history is empty afterwards.=and after√.Design
History module (
lib/history.js)MAX_ENTRIES = 10; when length exceeds 10, drop oldest (end of array).{ a: number, b: number | null, op: string, result: number }.sqrt:bisnull(matches API contract).bis the numeric second operand.record(entry)— validate/shallow-copy fields, unshift, trim to 10.getItems()— return a shallow copy of the array (defensive for callers).clear()— reset to empty array.MAX_ENTRIESfor unit tests if useful.HTTP layer (
server.js)GET /api/calculate(existing path): on 200 only, aftercalculate()succeeds, callhistory.record()with:opfrom query string (as returned/stored by API, e.g.add,multiply,sqrt).a/bas numbers from query params (b→nullwhenop === 'sqrt').resultfrom calculation.CalculatorError), do not record.GET /api/history:200and body{"items": [...]}whereitemsishistory.getItems().DELETE /api/history:history.clear(), respond204with empty body (no JSON)./health,/,/api/calculatecontract, and 404 handling unchanged.UI (
public/index.html)<ul id="history-list">(or similar) for entries; empty state when no items.refreshHistory():GET /api/history, render each item (e.g.a op b = resultor√a = resultwhenbis null).refreshHistory()on load, after successfulevaluate()(=), and after successfulapplyUnary()(√).DELETE /api/history, thenrefreshHistory()(list empty).Test layout
test/history.test.jsbnull for sqrt).test/server.test.jstest/ui.test.jsFiles to change
lib/history.jsserver.jsGET/DELETE /api/history.public/index.htmlrefreshHistory, wire=/√/ clear.test/history.test.jstest/server.test.jsDELETEat test start where isolation needed.test/ui.test.jsdocs/plans/issue-11.mdNo changes to
lib/calculator.js(calculation logic unchanged),package.json, or CI workflows.Test plan
Unit (
test/history.test.js)getItems()[0]is B,[1]is A.clear(),getItems()is[].{ a: 9, b: null, op: 'sqrt', result: 3 }; item matches.clear()on empty store stays empty.Each test calls
clear()in setup to avoid cross-test leakage.HTTP (
test/server.test.js)Use
withServer; start history-sensitive tests withDELETE /api/history(or assert emptyGET) for isolation.DELETE;calculate?a=2&b=3&op=add;calculate?a=6&b=7&op=multiply;GET /api/historyitems[0]multiply 42;items[1]add 5DELETE; 12× successfuladdwith distinct results;GET /api/historyitems.length === 10; first item is 12th calculationDELETE; successadd;divide?a=1&b=0&op=divide(400);GET /api/historyDELETE /api/historyGET /api/history→{ items: [] }sqrtsuccessb: null,op: 'sqrt'UI / page (
test/ui.test.js)#history-list) and a Clear history button (text orid).refreshHistory(or equivalent) calling/api/history; invoked after successful paths inevaluate/applyUnary(regex or string match).DELETEon/api/historyfrom clear control and refreshes list.Pre-push
npm testlocally; all tests green beforegit push origin aira/11-calculation-history.Risks
node --testcases in one processclear()in unit test setup; HTTP tests useDELETEor empty assert before seeding.recordin the200branch aftercalculate()returns.√evaluateandapplyUnarypaths.${a} ${op} ${b} = ${result}or special-casesqrt); tests focus on presence/wiring, not exact formatting unless needed for AC5.DELETEresponse bodyres.end()with no body and status 204; test asserts status and subsequent emptyitems.Attachment: plan-11-r1.md
Aira · plan review
Plan pushed at
a470846e; independent Dodik plan review started.Aira · dodik-plan PASS on
a470846eThe issue #11 plan maps each requirement to a numbered, testable acceptance criterion, and the design matches the current code: calculate() returns only a number and reports failures as CalculatorError (including division by zero), sqrt is unary and ignores b, and the page already has evaluate() for = and applyUnary() for √. The test plan proves ordering, the cap of 10, clearing, failed calculations not recorded, the unary b: null shape, and the history list plus Clear history wiring, without changing calculator logic, dependencies, or CI.
Checks performed
Attachment: dodik-plan-a470846e.json
Aira · implementing
Plan approved by Dodik at
a470846e. Implementation started.Aira · ci
Ready for review at
028c5920(PR #15). Waiting for CI.Implemented in-memory calculation history (lib/history.js, GET/DELETE /api/history, UI refresh/clear), added history unit/server/UI tests; npm test passes (70/70); pushed feat commit to aira/11-calculation-history.
Aira · CI passed on
028c5920Aira · review
CI is green on
028c5920. Independent Dodik and code review started.Aira · dodik PASS on
028c5920Calculation history matches the approved plan and all five acceptance criteria. The in-memory store keeps the newest 10 successful calculations, GET /api/history returns them newest-first, DELETE /api/history returns 204 and clears the list, failures such as division by zero are omitted, and the page shows a History list and Clear history button that refresh after = and √. The suite passed 70 tests with no skips, and the diff contains only the planned files.
Checks performed
Attachment: dodik-028c5920.json
Aira · reviewer PASS on
028c5920The calculation-history feature is implemented consistently with the plan and acceptance criteria: history is recorded only on successful calculate responses, capped at ten newest-first entries, exposed via GET/DELETE /api/history, and wired in the UI with refresh on load, after = and √, and after clear. All 70 tests passed (including multiple runs and --test-concurrency=32); manual HTTP checks confirmed failed overflow and division-by-zero calls do not append history. Existing /health, /, and /api/calculate behaviour remains covered by the suite.
Checks performed
028c592Attachment: reviewer-028c5920.json
Aira · qa
Dodik and the reviewer passed on
028c5920. Preview deployed at http://127.0.0.1:38027; QA started.Aira · qa PASS on
028c5920Commit
028c592089serves GET /health with that sha. GET /api/history returns newest-first successful calculations, keeps only the latest 10 after 12 adds, omits division by zero and other 400s, and DELETE /api/history returns 204 with an empty list afterwards. The page contains a History list and a Clear history button and refreshes history after a successful equals and after square root. npm test passed 70 tests, including history ordering, the limit of 10, clearing, errors not recorded, and the page controls.Checks performed
028c592089Attachment: qa-028c5920.json
Aira · merging
QA passed on
028c5920. Merging.Aira · Merged PR #15
Merge commit
20c34e99b16019e64a5444f4a65af54fd343d9f7from reviewed head028c592089e1427eddd7c6d0453b4abbd38455cd.028c592089serves GET /health with that sha. GET /api/history returns newest-first successful calculations, keeps only the