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.
proposal p-0007 in sample/hours.txt
reason: opening days were wrong. Text to replace matches 1 time.
@@ sample/hours.txt @@
Welcome to the sample cafe.
−We are open Monday to Friday.
+We are open Monday to Saturday.
Coffee and toast are served all day.
fingerprint 9c41e0a7
To approve this change, quote its fingerprint:
> 9c41e0a7
If the proposal is edited after this, the fingerprint no longer matches and the change is refused.
How it works
- ProposalThe exact text to replace, its replacement and a reason. The text must match exactly once.
- ApprovalA person approves by quoting the proposal fingerprint.
- BackupA copy of the file is kept.
- ChangeApplied only if the file is unchanged since the proposal.
- CheckA fresh read of the file against the expected result.
Applying
Stale proposal
- 1Proposal written. The file is fingerprinted: a41f.
- 2The file is edited by someone else. Its fingerprint is now c902.
- 3Apply compares the fingerprint with the one in the proposal.
×refusedthe file changed after the proposal was written; propose again
The newer work is left as it is.
Undoing
Rollback
- 1The change was applied and a backup of the file was kept.
- 2The file still matches the result of that change.
- 3Rollback restores the backup.
↩rolled backthe original text is restored
If the file had been edited after the change, rollback would refuse.
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:
- a proposal is applied only after an approval that quotes its fingerprint, and the result is checked
- ambiguous, missing and escaping targets are refused at proposal time
- a file that changed after the proposal blocks the edit
- a proposal edited after approval is refused
- checking reports a mismatch when the file is edited again after the change
- rolling back restores the original and refuses when the file moved on
- 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