What AI-generated code needs before I'd trust it

An AI assistant can spin up a working implementation in minutes. Whether you should trust it is a different matter.

Getting a feature to work on a local development server is a decent starting point, but it doesn’t prove it’ll behave in another browser or still make sense six months down the line. An automation workflow turning green has much the same problem: something ran, but how much have you actually proved?

I don’t think the answer is to avoid generated code. It’s to be more rigorous about what happens after the code arrives.

Swiping, prefetching and a Playwright WebKit crash

A fairly ordinary bit of frontend work, like adding touch-swiping between posts. Years ago, I’d probably have dug through Stack Overflow answers or weighed up whether a plugin was worth adding for such a small feature and sometimes ended up writing custom code to achieve it. Now I can ask an AI assistant to prepare an implementation and show me how it works.

I think that’s a useful change. But there’s a difference between asking for code in an area you understand and asking for it in one you’re still learning. Experience helps you notice the assumptions, awkward trade-offs and missing checks.

We should encourage beginners too. They just happen to be getting into it when these tools are available. We must admit that most of us learned by building things we didn’t fully understand, breaking them and working out what went wrong. The problem is skipping that learning and treating the first working result as the finished answer.

For me, testing the navigation AI had written uncovered a strange problem. Playwright’s WebKit build on Windows was crashing its page process on most navigations into link posts. Chromium and Firefox were fine.

The investigation ruled out the swipe and keyboard handlers, the sharing script and the link-post markup. The failure appeared when three things came together: cross-document view transitions, speculation-rules prefetching of neighbouring pages and ordinary page styling. Replacing the speculation rules with a plain <link rel="prefetch"> stopped the crashes.

The fix came with a regression test that failed with the old markup and passed after the change. If your tests have only ever passed, it’s worth asking whether they’d actually catch the failure you’re worried about.

There’s also a limit to what that proves. Playwright’s WebKit on Windows isn’t the same as Safari running on a Mac or iPhone. I wouldn’t claim the problem was fixed everywhere without testing those too.

Local dev servers lie to you

A page looking good on localhost might not be ready for production.

With a Markdown-driven site like this, I wanted checks that drafts stay out of the published build, pagination includes every post exactly once, internal links resolve and images are actually present in the final output.

I ran into a frustrating example with Astro’s image processing. Commands such as astro build, astro check and astro sync rewrite generated files inside .astro/. When those commands ran alongside the development server, the server could lose track of images in posts. The original photographs were still there. Two processes were interfering with the same state.

The workaround was to preserve and restore the files the development server relies on while those commands execute. It has a comment explaining why it exists, so the next time I look I don’t remove it thinking it’s unnecessary.

There’s also a separate launch check that temporarily includes draft content in a test build. That catches missing images, broken sharing images and leftover photo metadata before anything is published. A normal production build, with every post still marked as a draft, wouldn’t show those pages at all.

Privacy requires checks, not promises

When something handles personal data, “it doesn’t look like it’s sending anything” doesn’t cut it as a security assessment.

Phone photographs can carry GPS coordinates and device information that aren’t visible in the picture. Removing that metadata during import is sensible. Checking the processed files, and failing a test if location information remains, is better.

HTML comments don’t appear in the article, but they can still end up in the page source. An editorial reminder that looks harmless in a draft shouldn’t accidentally become public just because it isn’t visible on the screen.

The LinkedIn banner preview processes images in the browser. Its page uses a Content Security Policy with connect-src 'none', which blocks the script-initiated connections covered by that directive. That isn’t a substitute for reviewing the code, or a guarantee against every possible way data could leave a page. It is a useful browser-enforced safeguard instead of relying only on a statement saying images aren’t uploaded.

Pause before pulling in a package

AI assistants can be quick to recommend an npm package. Sometimes that’s the right answer. Sometimes the browser or framework already does what you need.

Every added dependency is another thing to update, audit and understand. Before accepting one, I’d check whether it solves a real problem or just makes the initial implementation easier to generate. Touch navigation is a good example of something that doesn’t automatically need a library.

When a dependency is justified, reproducibility matters. A committed lockfile records the resolved package versions; the required Node.js version needs to be specified separately. Neither is exciting, but both make it easier to reproduce a working build later.

Knowing what should break the build

Not every error needs the same response. Here’s what happens behind the scenes for this site.

An unfinished draft with a missing image might produce a warning in development. A published post with the same missing image should fail the build rather than ship a broken page.

The same applies to validation. If a short-form Thought has a 280-character limit, silently trimming it isn’t helpful. A build error naming the offending file gives me something I can fix.

Tests have limits of their own. Checking several viewport widths and reduced-motion preferences is worthwhile, but it doesn’t count as a complete accessibility audit. I’d rather know exactly what has been checked than assume a green test suite covers everything.

Will I understand this in six months?

If code does something unusual, I want to know why. Not a comment describing the next line, but the reason for a decision: what failed, what alternatives were tried and what might break if it’s changed.

Getting a workable implementation from an AI assistant is considerably easier than it used to be. That’s a part of life now, whether you’re experienced or learning as you go. But getting the code is only the start of understanding it.

I don’t need to have written every line myself. I do need to understand what it does, know how it’s been tested and be confident I can manage when something breaks.