What should an AI check before changing code?
Add whitespace handling and a default name to one greeting function. Follow the same three tests from failure to success, connecting requirements, design decisions and execution evidence.
Case edition Updated
Case-edition verification: 2026-11-08, macOS 27.2 arm64 · Node.js 26.5.1 · node:test. The same three published tests run against both implementations: before, 1 passes and 2 assertions fail; after, all 3 pass. This is a function-level test, not evidence of a Holmes-Kit installation, current-session MCP binding or live hook enforcement.
First decide what stays and what changes
The existing greet inserts a name directly into a sentence. The new requirement trims surrounding whitespace and uses World when the name is empty. A normal name must keep its existing response. Write these three observable outcomes before changing the implementation.
This is a string-input contract. It does not add null/object handling or normalize the spelling and language conventions of personal names.
| Input | Before | Required result |
|---|---|---|
| "Ada" | Hello, Ada! | Hello, Ada! |
| " Ada " | "Hello, Ada !" — spaces retained | Hello, Ada! |
| "" — empty string | Hello, ! | Hello, World! |
Run the starting implementation
In a new practice folder, save the following as greet.mjs. The aim is to reproduce missing behavior in an otherwise runnable program. Do not overwrite an existing project.
greet.mjs · before
export function greet(name) {
return `Hello, ${name}!`;
}
Write tests that stay unchanged
Save this as greet.test.mjs in the same folder and run node --test greet.test.mjs. No npm dependency is needed. The first test protects existing behavior; the other two distinguish the new requirement.
Before the change, only the normal-name test passes; the other two fail with ERR_ASSERTION. A missing file or broken import fails before behavioral verification. It does not count as this case’s RED.
greet.test.mjs · the same tests for both implementations
import test from "node:test";
import assert from "node:assert/strict";
import {greet} from "./greet.mjs";
test("preserves a normal name", () => {
assert.equal(greet("Ada"), "Hello, Ada!");
});
test("trims surrounding whitespace", () => {
assert.equal(greet(" Ada "), "Hello, Ada!");
});
test("uses World for an empty name", () => {
assert.equal(greet(""), "Hello, World!");
});
The smallest change that satisfies the contract
Trim the string once, then use World only when the result is empty. There is no need to mutate the argument or add a library. Replace only greet.mjs with this implementation and rerun the same test command.
greet.mjs · after
export function greet(name) {
const normalized = name.trim();
return `Hello, ${normalized || "World"}!`;
}
What did the execution establish?
This article’s regression test runs the exact snippets in a temporary folder. These counts describe those three tests, not a performance gain or correctness over every input. Keeping the first test green provides evidence that the old contract still holds.
| Implementation | Pass | Assertion failures | Exit code |
|---|---|---|---|
| Before | 1 / 3 | 2 / 3 | 1 |
| After | 3 / 3 | 0 / 3 | 0 |
Where does Holmes-Kit fit?
Record preserved behavior and new success criteria in the requirement, and string-only scope plus trim/default decisions in the design. Under the approved design, write tests and observe assertion RED, then continue through the matching test specification approval, implementation and GREEN. Use actual specification IDs and the tool’s next-step guidance.
Specification links locate decisions. A link alone establishes neither passing tests nor hooks active in the current CLI. Start with the basics guide for installation and the first governed change; do not use this function test as native binding evidence.
A checklist for your own change
This is a small experiment that distinguishes behavioral failures. Whitespace-only names, non-string input, Unicode spelling and length limits need their own requirements and tests. A small GREEN is not product-wide verification.
- Is the behavior to preserve protected by a test?
- Are new inputs and expected responses explicit?
- Did an assertion fail, rather than test collection?
- Were the same tests rerun after the change?
- Were installation, MCP binding and hook observations checked separately?
Sources and verification
This case edition expands an earlier introduction. Source versions and the evidence basis above define its scope.
Share this reference
Copy a link or the prepared introduction. Nothing is posted automatically.
https://holmes-lab.web.app/en/notes/spec-first-ai-development/
Introduction draft for an external post
What should an AI check before changing code? Add whitespace handling and a default name to one greeting function. Follow the same three tests from failure to success, connecting requirements, design decisions and execution evidence. https://holmes-lab.web.app/en/notes/spec-first-ai-development/