Repository navigation
Conversation
Cover every branch of the autofill handler: invalid JSON, schema 400s, page-fetch 502, provider 401/403 and other errors, unparseable AI replies, the templateId fallback, the happy path, and the google ?key= URL. meta-fetcher is mocked and fetch is stubbed per test, so nothing leaves the network. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
/api/ai/autofillhad no route tests — the/api/airoutes only had schema tests, and thetests/api/ai-autofill.test.tsplanned in #30 never landed. Autofill has the most branches of the three routes since it chains a page fetch, an AI provider call, and a JSON parse.This adds
tests/api/ai-autofill.test.tswith one test per branch: non-JSON body → 400Invalid JSON body; schema failures → 400 naming the field;fetchMetaTagsthrowing → 502Could not fetch the URLwith the provider never called; provider 401/403 → 401Invalid API key; other provider errors → 502AI provider error (500); unparseable reply → 502Could not parse AI response; unknown templateId → 200 falling back toblog-minimal-dark; the happy path → 200 withtemplateId/fields/colors; and thegoogleprovider sending the key in the request URL as?key=.Tests only — the route itself is untouched.
@/lib/meta-fetcheris mocked andfetchis stubbed per test, so no real network happens.Closes #419
How I Tested This
npx vitest run tests/api/ai-autofill.test.ts— 14 tests, all passing.npm run check(0 errors) and the fullnpm run testsuite (2134 tests) pass.AI Assistance
Devin CLI (SWE-2 High): wrote the test file from the issue's branch table and ran the verification; human-directed review of the diff.
Type of Change
Screenshots
N/A — test-only change, no UI.
Checklist
devnpm run checkpassesnpm run testpassesnpm run dev(N/A — route tests exercise the handler directly)Created with SWE-2 High in Devin CLI.