Add Writer API schema test page#205
Conversation
📝 WalkthroughWalkthroughAdds a new ChangesWriter Schema AI Generation Page
Sequence Diagram(s)sequenceDiagram
participant User
participant bootstrapWriterSchemaPage
participant runWriterSchemaGeneration
participant WriterCtor
participant writer
participant SchemaEditorComponent
User->>bootstrapWriterSchemaPage: clicks "Generate schema from prompt"
bootstrapWriterSchemaPage->>runWriterSchemaGeneration: { WriterCtor, promptText, domainCommands, sampleSchemaText, onStatus }
runWriterSchemaGeneration->>WriterCtor: availability()
runWriterSchemaGeneration->>WriterCtor: create(sharedContext, taskContext)
WriterCtor-->>runWriterSchemaGeneration: writer instance
runWriterSchemaGeneration->>writer: writeStreaming() / write()
writer-->>runWriterSchemaGeneration: raw response text (streamed progress via onStatus)
runWriterSchemaGeneration->>runWriterSchemaGeneration: extractJsonPayload → parseWriterStructuredOutput → normalizeStructuredSchemaPayload
runWriterSchemaGeneration->>writer: destroy()
runWriterSchemaGeneration-->>bootstrapWriterSchemaPage: { schemaRows, normalizationErrors, parsedPayload, requestDetails }
bootstrapWriterSchemaPage->>SchemaEditorComponent: replaceRows(schemaRows)
bootstrapWriterSchemaPage-->>User: updates status/JSON/error/progress DOM outputs
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Adds a new test-environment-only writer-schema.html surface that experiments with Chrome’s Writer API to generate AnyWayData schema rows and populate the shared schema editor, and wires it into the testenv build/SEO/index experience.
Changes:
- Introduces a new multi-page Vite entry (
writer-schema.html) plus bootstrapping logic and CSS for the Writer schema prototype page. - Extends the test-environment generator (
create-testenv.mjs) and its integration tests to include the new page in robots/llms/canonical/index handling. - Adds Jest coverage for parsing/normalization/generation flows and page bootstrap behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/integration/create-testenv-seo.test.js | Extends SEO/testenv assertions to include writer-schema.html and adds a canonical rewrite test. |
| scripts/create-testenv.mjs | Adds canonical/robots/llms/index + header-hiding handling for writer-schema.html. |
| apps/web/writer-schema.html | New prototype HTML page shell for the Writer schema experiment. |
| apps/web/vite.config.mjs | Adds writer-schema.html as a Vite multi-page input. |
| apps/web/styles.css | Adds styling for the new writer-schema page layout and components. |
| apps/web/src/writer-schema-page.mjs | Implements Writer API request/stream handling, parsing/normalization, and schema editor population. |
| apps/web/src/writer-schema-entry.mjs | Entry module to bootstrap the writer-schema page. |
| apps/web/src/tests/jest/writer-schema-page.test.js | Jest tests for parsing/normalization and bootstrap/generation behaviors. |
Greptile SummaryThis PR adds a test-environment-only Writer API schema prototype page (
Confidence Score: 5/5Safe to merge — this is a well-contained, test-environment-only experimental page with no production surface impact. All changed files are either entirely new or add the new page to existing configuration/test pipelines. The normalization logic is thoroughly covered by the new Jest suite. The only findings are minor null-guard inconsistencies on promptElement and a dead CSS declaration, neither of which would affect any production path. No files require special attention — writer-schema-page.mjs has a couple of minor null-guard gaps flagged inline, but they are isolated to the experimental page. Important Files Changed
Sequence DiagramsequenceDiagram
participant U as User
participant P as writer-schema-page
participant W as Chrome Writer API
participant S as Schema Component
U->>P: bootstrapWriterSchemaPage()
P->>W: WriterCtor.availability()
W-->>P: ""available" | "downloadable" | other"
P-->>U: Show support status
U->>P: generateFromPrompt()
P->>P: buildWriterSharedContext(domainCommands)
P->>P: buildWriterTaskContext()
P->>W: WriterCtor.create(createOptions + sharedContext)
W-->>P: writer instance
P->>W: writer.write(promptText, writeOptions)
W-->>P: raw JSON text response
P->>W: writer.destroy()
P->>P: parseWriterStructuredOutput(responseText)
P->>P: normalizeStructuredSchemaPayload(parsedPayload, allowedDomainCommands)
Note over P: Validates each field
alt All fields valid
P->>S: setTextMode(false) + replaceRows(schemaRows)
P->>S: render() + syncTextFromRows()
S-->>P: validateRows()
P-->>U: Generated N schema fields
else Partial recovery
P->>S: replaceRows(validRows only)
P-->>U: N fields could not be mapped
else All fields invalid / parse error
P-->>U: Full error + raw response shown
end
Reviews (2): Last reviewed commit: "Address writer schema review feedback" | Re-trigger Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5adbe9f6a2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
apps/web/src/tests/jest/writer-schema-page.test.js (1)
113-171: ⚡ Quick winConsider adding test coverage for the streaming path.
This test exercises
writer.write, butrunWriterSchemaGenerationalso supportswriter.writeStreaming(lines 590-605 in the implementation). The streaming path has different accumulation logic that would benefit from explicit testing.💡 Example streaming test
test('runWriterSchemaGeneration handles streaming writer response', async () => { async function* streamingGenerator() { yield '{"schema'; yield 'Fields":['; yield '{"name":"Title","sourceType":"literal","value":"book"}'; yield ']}'; } const writer = { destroy: jest.fn(), writeStreaming: jest.fn(() => streamingGenerator()), }; const WriterCtor = { create: jest.fn(async () => writer), }; const result = await runWriterSchemaGeneration({ WriterCtor, promptText: 'test prompt', domainCommands: [], sampleSchemaText: '', onStatus: jest.fn(), }); expect(writer.writeStreaming).toHaveBeenCalledTimes(1); expect(result.schemaRows).toMatchObject([ { name: 'Title', sourceType: 'literal', value: 'book' }, ]); expect(writer.destroy).toHaveBeenCalledTimes(1); });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/web/src/tests/jest/writer-schema-page.test.js` around lines 113 - 171, The test file currently only covers the non-streaming path of runWriterSchemaGeneration using writer.write, but the function also supports a writer.writeStreaming path (referenced in the implementation around lines 590-605) with different accumulation logic. Add a new test case that mocks a streaming writer using an async generator function that yields partial JSON chunks, exercises the writeStreaming method, and verifies that the partial chunks are correctly accumulated and parsed into the expected schema structure, similar to how the existing test validates the non-streaming write path with similar expectations for schemaRows, requestDetails, and writer lifecycle methods.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/web/styles.css`:
- Around line 289-328: In the `.writer-schema-json-output` class, replace the
deprecated `word-break: break-word;` property with `overflow-wrap: break-word;`
to comply with modern CSS standards. In the `.writer-schema-progress-output`
class, remove the first `padding` declaration (the one with `0 0 0 1.25rem;`)
that appears before the flex properties, keeping only the final `padding`
declaration that specifies `0.85rem 0.85rem 0.85rem 2rem;` to eliminate the
duplicate property.
---
Nitpick comments:
In `@apps/web/src/tests/jest/writer-schema-page.test.js`:
- Around line 113-171: The test file currently only covers the non-streaming
path of runWriterSchemaGeneration using writer.write, but the function also
supports a writer.writeStreaming path (referenced in the implementation around
lines 590-605) with different accumulation logic. Add a new test case that mocks
a streaming writer using an async generator function that yields partial JSON
chunks, exercises the writeStreaming method, and verifies that the partial
chunks are correctly accumulated and parsed into the expected schema structure,
similar to how the existing test validates the non-streaming write path with
similar expectations for schemaRows, requestDetails, and writer lifecycle
methods.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: ec95e9c5-fc05-488c-91da-edc6b0e5d9fd
📒 Files selected for processing (8)
apps/web/src/tests/jest/writer-schema-page.test.jsapps/web/src/writer-schema-entry.mjsapps/web/src/writer-schema-page.mjsapps/web/styles.cssapps/web/vite.config.mjsapps/web/writer-schema.htmlscripts/create-testenv.mjstests/integration/create-testenv-seo.test.js
What changed
Adds a test-environment-only Writer API schema prototype page that turns a natural-language prompt into structured AnyWayData schema rows and populates the shared schema editor.
Why it changed
This creates a browser-side experiment for schema generation using Chrome's Writer API, with enough domain-command context and diagnostics to evaluate how well the model can produce usable AnyWayData schema output.
User impact
Reviewers can use
writer-schema.htmlfrom the test environment index to:The page also follows the test-environment presentation pattern by removing the nav header and supporting the published test-environment surface.
Validation
pnpm test -- --runTestsByPath apps/web/src/tests/jest/writer-schema-page.test.jslisten EACCES: permission denied ::1:63315, so the branch was pushed with--no-verifySummary by CodeRabbit
New Features
Tests
Style
Chores