Improve the greeting example, check the result, and review the files before deciding what to do next.
Before you begin
Section titled “Before you begin”Complete the first-session example. The initial greeting.mjs returns Hello, ! for a blank name. This task changes that behavior to Hello, guest!.
Starting state: greeting.mjs is committed and still returns Hello, ! for empty or spaces-only strings. The input contract remains strings only. There should be no unrelated uncommitted edits. The task adds greeting.test.mjs and leaves the resulting change uncommitted for review.
For a separate branch and directory, start a new worktree named greeting-blank-names. Confirm that the session is using the intended workspace.
1. Describe the change
Section titled “1. Describe the change”Send:
Update greet in greeting.mjs to use "guest" when the trimmed name is empty.Keep the existing output for nonblank names.The input contract is strings only; do not add other input types.Add a greeting.test.mjs file using Node's built-in test runner.Cover "Ada", " Ada ", "", and " ".Run node --test and report the result. Do not commit or push.This gives the agent a small implementation target and a clear check. If it needs a decision, answer in the same session.
2. Check the behavior
Section titled “2. Check the behavior”The expected outputs are:
| Input | Expected output |
|---|---|
"Ada" | "Hello, Ada!" |
" Ada " | "Hello, Ada!" |
"" | "Hello, guest!" |
" " | "Hello, guest!" |
Read the agent’s test report. To verify independently, use the terminal location checks to open this session’s workspace on the server, then run:
node --testThe test run should pass and cover all four cases. The exact test names and implementation may differ. If the agent could not run the command, resolve the reported cause and run it before treating the result as verified.
If a check fails
Section titled “If a check fails”A fallback that checks the original name before trimming can still return Hello, ! for spaces. If the test expects Hello, guest!, the run must fail. Send the failure back with the exact input:
The spaces-only test fails: expected "Hello, guest!", got "Hello, !".Check whether you choose the fallback before or after trimming.Fix the function, keep the expected result, and rerun all four cases.Do not accept a change that merely deletes the failing test. A passing run should cover both blank cases and both nonblank cases.
A completed reference function and four-case test file are available for comparison. They are one checked implementation, not guaranteed agent output. Keep them separate from the original sample until you have attempted the task.
3. Review the files
Section titled “3. Review the files”Select the Diff tab at the top of the session, then Changes. Open Diff filters (the ⋮ next to the search icon), and under Compare choose Working changes. You should see the greeting change and a new test file. If the test file is missing, turn on Untracked files in the same Diff filters panel.
Look for unrelated edits, deleted behavior, or tests that only check the easy case. If needed, send a precise follow-up:
The test file does not cover spaces-only input yet.Add that case and rerun node --test. Keep the change scoped to this task.4. Decide whether it is ready
Section titled “4. Decide whether it is ready”You’re done with this walkthrough when the expected outputs are covered, the checks pass, and you understand the diff. Follow Finish and close a task to hand off the result and choose what to keep. Smart Review is optional: it starts from committed branch changes and needs a usable review base. The standalone practice repository has no remote by default, so Diff and the test checks are sufficient for this walkthrough.