Skip to content

Add edit command to notes tool - #1

Open
Iter1993 wants to merge 7 commits into
mainfrom
review-me
Open

Add edit command to notes tool#1
Iter1993 wants to merge 7 commits into
mainfrom
review-me

Conversation

@Iter1993

@Iter1993 Iter1993 commented Sep 2, 2026

Copy link
Copy Markdown
Owner

What

Adds an edit <id> <text> command to the notes tool, plus supporting scaffolding:

  • lib/store.jsedit(id, text) looks up a note by id and replaces its text
  • notes.js — new edit case, updated help text
  • lib/config.jsSESSION_TIMEOUT_MINUTES setting
  • tests/notes.test.js — tests for matches() (search)
  • .github/workflows/ci.yml — run npm test on PRs
  • .gitignore — ignore node_modules/ and notes.json

Test

npm test — 3 passing.

@Iter1993

Iter1993 commented Sep 2, 2026

Copy link
Copy Markdown
Owner Author

Review — bugs, edge cases, risk

🔴 Blocker: edit() crashes on an unknown id

lib/store.js

function edit(id, text) {
  const data = load();
  const note = data.notes.find((n) => n.id === id);
  note.text = text;   // note is undefined when nothing matches
  save(data);
}

Array.prototype.find returns undefined when no note has that id, so note.text = text throws:

$ node notes.js edit 999 "nope"
TypeError: Cannot set properties of undefined (setting 'text')
    at Object.edit (lib/store.js:51:13)

Every other command handles "not found": delete checks the return of remove() and prints No note #X found, search checks found.length === 0. edit has no guard, so any typo in the id crashes with a stack trace. node notes.js edit abc "x" hits the same path (id is NaN).

Fix: look before writing, and report the miss like delete does.

function edit(id, text) {
  const data = load();
  const note = data.notes.find((n) => n.id === id);
  if (!note) return false;
  note.text = text;
  save(data);
  return true;
}
case "edit": {
  const id = Number(rest[0]);
  const text = rest.slice(1).join(" ").trim();
  const ok = store.edit(id, text);
  console.log(ok ? `Updated note #${id}` : `No note #${id} found`);
  break;
}

🟠 edit accepts empty text and silently blanks the note

node notes.js edit 1 (no text) sets the note's text to "" and still prints Updated note #1. add rejects empty input (Usage: notes add <your note>); edit should be consistent and bail on empty text.

🟡 No test coverage for the new feature

tests/notes.test.js only exercises matches() (search). edit() — the actual change in this PR — has zero tests, which is why the crash above isn't caught by CI. Add cases for: edit an existing note, edit a missing id (should not throw), edit with empty text.

🟡 Dead config

config.SESSION_TIMEOUT_MINUTES is printed in the help text but nothing implements a session lock. Either drop it or note it's not wired up yet, so it isn't mistaken for a real feature.

Minor

  • .github/workflows/ci.yml pins actions/checkout@v5 / actions/setup-node@v5 by major tag only; fine for a playground, but SHA-pinning is the safer habit.
  • matches() search is case-sensitive ("Milk" won't match "milk"). Pre-existing, not introduced here.

@Iter1993

Iter1993 commented Sep 2, 2026

Copy link
Copy Markdown
Owner Author

Judgment: Claude caught the planted bug — store.edit() calls note.text = text without checking that find() returned a note, so node notes.js edit <unknown-id> ... throws TypeError: Cannot set properties of undefined. It also flagged the missing empty-text guard and the absent test coverage for edit().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants