{
 "_note": "The exact fixture used to measure cost-to-complete across models. Copy both files into an empty directory, run `node test.js` (one test fails), then ask the agent: 'Run `node test.js`. Some tests fail. Fix the code in window.js so that every test passes. Do not modify test.js.'",
 "window.js": "function rollingWindows(events, windowMs) {\n  const out = [];\n  let current = null;\n  for (const e of events) {\n    if (current && e.at - current.start < windowMs) {\n      current.events.push(e);\n    } else {\n      current = { start: e.at, events: [e] };\n      out.push(current);\n    }\n  }\n  return out;\n}\n\nfunction summarise(events, windowMs) {\n  const windows = rollingWindows(events, windowMs);\n  return windows.map((w) => ({\n    start: w.start,\n    count: w.events.length,\n    total: w.events.reduce((a, e) => a + e.cost, 0),\n  }));\n}\n\nmodule.exports = { rollingWindows, summarise };\n",
 "test.js": "const assert = require('assert');\nconst { summarise } = require('./window');\nlet failed = 0;\nfunction check(name, fn) {\n  try { fn(); console.log('ok   ' + name); }\n  catch (e) { failed++; console.log('FAIL ' + name + ' :: ' + e.message); }\n}\n\ncheck('groups events inside one window', () => {\n  const r = summarise([{at:0,cost:1},{at:500,cost:2}], 1000);\n  assert.deepStrictEqual(r, [{start:0,count:2,total:3}]);\n});\n\ncheck('an event exactly on the boundary starts a new window', () => {\n  const r = summarise([{at:0,cost:1},{at:1000,cost:2}], 1000);\n  assert.strictEqual(r.length, 2);\n});\n\ncheck('handles unsorted input', () => {\n  const r = summarise([{at:900,cost:1},{at:100,cost:2},{at:1500,cost:3}], 1000);\n  assert.deepStrictEqual(r.map(w => w.count), [2, 1]);\n});\n\ncheck('empty input yields no windows', () => {\n  assert.deepStrictEqual(summarise([], 1000), []);\n});\n\ncheck('single event yields one window', () => {\n  assert.deepStrictEqual(summarise([{at:42,cost:7}], 1000), [{start:42,count:1,total:7}]);\n});\n\ncheck('costs sum per window', () => {\n  const r = summarise([{at:0,cost:1.5},{at:10,cost:2.5},{at:5000,cost:4}], 1000);\n  assert.deepStrictEqual(r.map(w => w.total), [4, 4]);\n});\n\ncheck('does not mutate the caller\\'s array', () => {\n  const input = [{at:900,cost:1},{at:100,cost:2}];\n  const before = input.map(e => e.at);\n  summarise(input, 1000);\n  assert.deepStrictEqual(input.map(e => e.at), before, 'input order was modified');\n});\n\nconsole.log(failed ? `\\n${failed} FAILING` : '\\nALL PASS');\nprocess.exit(failed ? 1 : 0);\n"
}