AtrisBench
Back to the leaderboard

Claude Fable 5.1 on Rename an API without breaking callers

Passed in 26s. Attempt 3. Run 20260904T131945Z-fable-5-1-refactor-rename-api-3.

Task

Rename the ledger API safely

Refactor this Node project so lib/ledger.js uses record and list instead of postEntry and getEntries.

Keep postEntry only as the deprecated compatibility shim marked // keep in lib/ledger.js; the shim must delegate to record. Remove getEntries. Update every project call site to the new names. Delete lib/legacy.js and its sole caller, src/legacy-report.js.

Do not add dependencies. The required output is the updated project, with this command green:

node --test test/*.test.js

Command

claude -p --model claude-fable-5-1 --dangerously-skip-permissions --output-format text 'You are working in the current folder. Do the task in TASK.md and write the outputs to the exact paths it names.
Do not ask questions. When done, stop.

# Rename the ledger API safely

Refactor this Node project so `lib/ledger.js` uses `record` and `list` instead of `postEntry`
and `getEntries`.

Keep `postEntry` only as the deprecated compatibility shim marked `// keep` in
`lib/ledger.js`; the shim must delegate to `record`. Remove `getEntries`. Update every project
call site to the new names. Delete `lib/legacy.js` and its sole caller, `src/legacy-report.js`.

Do not add dependencies. The required output is the updated project, with this command green:

` ` `sh
node --test test/*.test.js
` ` `'

Output

Done. The rename is in and the test command passes, two tests green.

The ledger now exports record and list. The old postEntry stays as a marked, deprecated shim that just calls record.

Every caller in src now uses the new names. The old getEntries function is gone, along with the legacy helper file and the report that used it.

No dependencies added. I also ran a quick end-to-end check of the command runner, refunds, invoice import, and the shim, and all behaved correctly.

`node --test test/*.test.js`

Files produced

lib/ledger.js

import { assertAccount, assertAmount } from "./validate.js";
import { makeId } from "./ids.js";

const entries = [];

export function record(account, amount, memo = "") {
  assertAccount(account);
  assertAmount(amount);
  const entry = { id: makeId(entries.length + 1), account, amount, memo };
  entries.push(entry);
  return { ...entry };
}

export function list(account) {
  return entries.filter((entry) => entry.account === account).map((entry) => ({ ...entry }));
}

// keep: deprecated compatibility shim. Use record() instead.
/** @deprecated Use record() instead. */
export function postEntry(account, amount, memo = "") {
  return record(account, amount, memo);
}

export function resetForTests() {
  entries.length = 0;
}

lib/legacy.js

[deleted]

src/account-summary.js

import { list } from "../lib/ledger.js";

export function accountSummary(account) {
  const rows = list(account);
  return { account, count: rows.length, total: rows.reduce((sum, row) => sum + row.amount, 0) };
}

src/audit.js

import { list } from "../lib/ledger.js";

export function auditAccount(account) {
  return list(account).map(({ id, memo }) => `${id}:${memo}`);
}

src/cli.js

import { list, record } from "../lib/ledger.js";

export function runCommand(name, account, amount) {
  if (name === "record") return record(account, amount, "cli");
  if (name === "list") return list(account);
  throw new Error(`unknown command: ${name}`);
}

src/import-invoices.js

import { record } from "../lib/ledger.js";

export function importInvoices(invoices) {
  return invoices.map((invoice) => record("receivable", invoice.total, invoice.id));
}

src/legacy-report.js

[deleted]

src/month-close.js

import { list } from "../lib/ledger.js";

export function monthClose(account) {
  const total = list(account).reduce((sum, entry) => sum + entry.amount, 0);
  return Object.freeze({ account, total });
}

src/refund.js

import { record } from "../lib/ledger.js";

export function refund(amount, reference) {
  return record("refunds", -amount, reference);
}

Checker

{"passed": true, "score": 1.0, "notes": "all refactor checks passed; node: \u2139 duration_ms 75.836292"}

Judge

Not used for this task.