Skip to document
Agentic OS.
Fictional sample

A small code change, ready to review

A sample patch that improves a basic email check, with tests showing the intended behavior.

checkout-fix.diffDownload sample file

This is an authored example you can open and download. Its content is fictional. No live AI task was run to produce it.

What changes

The original check accepted any text containing an @ symbol. The proposed change trims surrounding spaces, rejects non-text values and checks for a simple address structure.

The patch

diff --git a/src/email.mjs b/src/email.mjs
--- a/src/email.mjs
+++ b/src/email.mjs
@@ -1,3 +1,5 @@
 export function isCheckoutEmail(value) {
-  return typeof value === 'string' && value.includes('@');
+  if (typeof value !== 'string') return false;
+  const email = value.trim();
+  return /^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email);
 }
diff --git a/tests/email.test.mjs b/tests/email.test.mjs
new file mode 100644
--- /dev/null
+++ b/tests/email.test.mjs
@@ -0,0 +1,13 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { isCheckoutEmail } from '../src/email.mjs';
+
+test('accepts basic addresses with surrounding spaces', () => {
+  assert.equal(isCheckoutEmail(' person@example.com '), true);
+});
+
+test('rejects malformed or non-text values', () => {
+  for (const value of ['', '@', 'person@', 'person@example', null]) {
+    assert.equal(isCheckoutEmail(value), false);
+  }
+});

The simple check illustrates a code review. It is not a complete implementation of email validation.

How to check it

Create src/email.mjs with the original code below and place the downloaded patch in the project folder. Apply it, then run the test command. These tests cover the small example; they do not validate a checkout system or send a payment.

The original sample file · src/email.mjs
export function isCheckoutEmail(value) {
  return typeof value === 'string' && value.includes('@');
}
git apply checkout-fix.diff
node --test tests/email.test.mjs

The example tests were checked locally while building this sample. This page does not run code when you open it.