Skip to content

case study

Approved edits: a tool where a person approves each change

My role: I built this in 2026 as a demonstration. It is not client or employer work, uses a sample cafe site, and the source is public.

Scope and constraints

Ownership
A solo demonstration with a sample cafe site. Not client or employer work.
Scale
A single command-line tool and a set of tests, with no dependencies.
Constraints
An approval has to be tied to the exact change, a stale change must never overwrite newer work, and a check that cannot run must not look like a failure.
Judgment calls
Refuse ambiguous edits up front, and bind the approval to a fingerprint instead of a yes or no.

What was delivered and checked

  • Tests cover the full path from proposal to check, and each refusal: ambiguous or missing text, an edit outside the folder, an approval that does not quote the fingerprint, a file that changed first, and a proposal edited after approval.
  • Tests also cover a mismatch found by the check, a rollback, a rollback refused after a later edit, and replacement text inserted literally.

What it is

A change to a page, whether proposed by a person or by a tool, should be applied only if a person approved exactly that change. This demonstration applies one text replacement in one file and makes that rule mechanical on a sample site: the approval quotes a fingerprint of the proposal, the change is applied only to an unchanged file, and the result is checked by reading the file again.

Sample data. The approval is tied to the exact change by the fingerprint it quotes.

How it works

  1. ProposalThe exact text to replace, its replacement and a reason. The text must match exactly once.
  2. ApprovalA person approves by quoting the proposal fingerprint.
  3. BackupA copy of the file is kept.
  4. ChangeApplied only if the file is unchanged since the proposal.
  5. CheckA fresh read of the file against the expected result.
Each step can refuse; nothing is applied without an approval of the exact change.
Sample data. Apply and rollback share one rule: they act only on a file that is unchanged since the step they depend on.
  • Approval is bound to the exact change

    The approver has to quote a fingerprint of the proposal. If the proposal is edited afterwards, the fingerprint no longer matches and the change is refused, so an approval cannot be reused for a different change.

  • Ambiguity is refused, not guessed

    The text to replace must appear exactly once. Zero matches and several matches are both rejected when the proposal is written, before anyone is asked to approve.

  • A stale proposal cannot overwrite newer work

    The file is fingerprinted when the proposal is written and compared again when the change is applied. A rollback has the same rule: it refuses if the file changed after the edit.

  • The check reads the file again

    After the change, the file is read afresh and compared with what the backup should become. The outcome is confirmed, mismatch or not checked, so a check that could not run is not reported as a failure.

  • Every step is logged

    Each proposal, approval, change, check and rollback is appended to a log, so there is a record of who approved what.

Scope

  • Every approval is recorded by name

    Each approval is recorded with the approver’s name in an audit trail.

  • One text replacement in one file

    It works on plain text files in a local folder.

The code that enforces it

The fingerprint covers the proposal id, the file, the text to replace, its replacement and a hash of the file as it was when the proposal was written. These lines are copied from the tool without changes.

const fingerprint = (plan) => sha(JSON.stringify([plan.id, plan.file, plan.find, plan.replace, plan.beforeHash]));

if (plan.status !== 'approved') throw new Error(`cannot apply a proposal that is ${plan.status}`);
if (fingerprint(plan) !== plan.fingerprint) throw new Error('the proposal changed after it was approved');
if (sha(text) !== plan.beforeHash) throw new Error('the file changed after the proposal was written; propose again');

The tests are named for the behaviour they pin down:

  1. a proposal is applied only after an approval that quotes its fingerprint, and the result is checked
  2. ambiguous, missing and escaping targets are refused at proposal time
  3. a file that changed after the proposal blocks the edit
  4. a proposal edited after approval is refused
  5. checking reports a mismatch when the file is edited again after the change
  6. rolling back restores the original and refuses when the file moved on
  7. replacement text is inserted literally

Source and tests

The source is in the approved-edits repository under the MIT licence, and npm test runs the tests described above.

Stack

  • Node.js
  • JavaScript
  • Node test runner

More case studies

    Engineering notes: the decisions behind the work