Calculation history #7
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#7
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/7-calculation-history.Aira · planning
Orchestrator thread started (composer-2.5). Planning on
aira/7-calculation-history.T3 thread:
mcp:launch:cfee6f6953d7cba687fe8fa61ee2c740445048ea518c17ac65166190cd3e3070Aira · Plan (round 1) at
1aab3aaeWrote issue-7 implementation plan (history module, API, UI, tests, risks), committed docs/plans/issue-7.md, ran npm test (50 pass), pushed aira/7-calculation-history.
docs/plans/issue-7.md
Issue #7: Calculation history
Goal
Keep a short in-memory history of successful calculations on the server (newest first, max 10), expose it via
GET /api/historyandDELETE /api/history, and show a History list with a Clear history control in the UI that updates after each successful=or√.Acceptance criteria
2+3and6*7,GET /api/historylists6*7=42first and2+3=5second.DELETE /api/historyreturns 204 and the history is empty afterwards.Design
History module (
lib/history.js) — new{ a: number, b: number | null, op: string, result: number }.sqrt, storeb: null(operands are the parsed numbers used in the calculation, not raw query strings).record(entry): prepend the entry (newest first). If length exceeds 10, drop the oldest entries so at most 10 remain.list(): return a shallow copy of the current array (newest first).clear(): reset the store to[].resetHistory()(alias ofclear) for tests so HTTP suites can isolate cases without cross-test leakage from shared module state.Pure logic only; no HTTP.
HTTP layer (
server.js)handleCalculate(after successfulcalculate):opfrom query;aas the finite number used for the left operand;basnullwhenop === 'sqrt', otherwise the finite number fromb;resultfromcalculate.calculatefirst; on success, derive stored operands—e.g.parseNumberfromlib/calculator.jsfora, and for binary opsb, so stored values match what was computed).recordonly on HTTP 200 success paths (never in thecatchbranch).GET /api/history:200with{"items": [...]}where each item matches the entry shape above; empty store →{"items":[]}.DELETE /api/history:clear(), respond204with no body (no JSON)./api/history→ existing 404 JSON pattern.Recording uses the API op names (
add,multiply,sqrt, etc.), consistent with query params.UI (
public/index.html)main): a History section—heading,<ul id="history-list">(or similar) for entries, and a Clear history button (id="clear-history"ordata-action="clear-history").refreshHistory():fetch('/api/history'), parseitems, render each row (e.g.a,op,b,result—format unary sqrt without a bogusb).refreshHistory():=(inside thestatus === 200branch).√(same branch).fetch('/api/history', { method: 'DELETE' }), thenrefreshHistory()(list should empty).Separation of concerns
lib/history.jslib/calculator.jsserver.jspublic/index.htmlFiles to change
lib/history.jsrecord,list,clear,resetHistoryserver.jsGET/DELETE/api/historypublic/index.htmlrefreshHistoryafter=/√test/history.test.jstest/server.test.jstest/ui.test.jsAGENTS.mdTest plan
Unit (
test/history.test.js)list()→[]recordthenlist()returns newest firstrecordcalls →list()length 10, first item is the 12th recordedclear()thenlist()→[]a,b,op,resultincludingb: nullfor sqrt-style entriesCall
resetHistory()inbeforeEach(or start of each test) so tests are independent.HTTP (
test/server.test.js)Use
resetHistory()fromlib/history.jsat the start of each history-related test (or a dedicatedbeforeEachblock) so ordering assertions are deterministic.GET /api/historyon fresh server →200,{ items: [] }GET ...?a=2&b=3&op=addthenGET ...?a=6&b=7&op=multiply, thenGET /api/historyGET /api/calculaterequestsGET /api/history→ 10 items, newest matches last calculationGET ...?a=1&b=0&op=divide(400), then successful addDELETE /api/history→204, empty body;GET /api/history→{ items: [] }GET ...?a=9&op=sqrtb: null,op: 'sqrt'Assert
DELETEresponse has no JSON body (e.g.res.status === 204and empty or null text).UI (
test/ui.test.js)#history-list(or agreed id)id/data-attribute)/api/historyfor GET and DELETE=and√) — e.g. matchrefreshHistoryor fetch to/api/historyin those branchesREQUIRED_KEYSand sqrt/percent wiring tests still passFull suite:
npm testmust pass before push.Risks
resetHistory()in history tests; document pattern in test filerecordafter successfulcalculatein the 200 branchparseNumber(or equivalent) for storeda/b; asserttypeofin HTTP testsDELETEreturns JSON or wrong statusres.end()with no body√b; optional UI test forop=sqrtin fetch refreshcreateServerper test still shares one history storeImplementation order
lib/history.js+test/history.test.jsserver.jsroutes and record-on-success +test/server.test.jshistory casespublic/index.htmlHistory UI +test/ui.test.jsnpm test, then pushaira/7-calculation-historyAttachment: plan-7-r1.md