Skip to content

Add Writer API schema test page#205

Merged
eviltester merged 2 commits into
masterfrom
204-protytype-writer-api
Jun 14, 2026
Merged

Add Writer API schema test page#205
eviltester merged 2 commits into
masterfrom
204-protytype-writer-api

Conversation

@eviltester

@eviltester eviltester commented Jun 13, 2026

Copy link
Copy Markdown
Owner

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.html from the test environment index to:

  • generate schemas from prompts in the browser
  • inspect the exact Writer request and raw response
  • see progress and full errors during generation
  • recover valid rows even when some generated fields are invalid

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.js
  • pre-commit hook ran full Jest successfully during commit
  • note: normal pre-push hook is failing in this environment on Storybook test startup with listen EACCES: permission denied ::1:63315, so the branch was pushed with --no-verify

Summary by CodeRabbit

  • New Features

    • Added experimental "Writer Schema Prototype" page for AI-powered schema generation
    • Integrated streaming generation with real-time progress updates and error recovery
  • Tests

    • Added comprehensive test suite covering schema generation, validation, and UI behavior
  • Style

    • Added responsive layout styling with dark-mode support for the schema editor interface
  • Chores

    • Updated build configuration and SEO directives for the new schema page

Copilot AI review requested due to automatic review settings June 13, 2026 23:11
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a new writer-schema.html page that integrates a Writer AI backend with the schema editor UI. The feature includes an 889-line page module with JSON extraction, schema normalization, writer lifecycle management, and UI bootstrapping; HTML markup; CSS styles; a Vite build entry; test-environment registration with SEO directives; and a 347-line Jest test suite.

Changes

Writer Schema AI Generation Page

Layer / File(s) Summary
Module constants and schema processing pipeline
apps/web/src/writer-schema-page.mjs
Defines configuration constants (default prompt, sourceType allowlist, date-literal matchers, domain allowlist) and implements UI helpers, JSON extraction/parsing, sourceType inference, structured-payload normalization with per-field errors, and schema row validation. Exports all public utilities.
Writer lifecycle and schema generation runner
apps/web/src/writer-schema-page.mjs
Implements WriterCtor availability checking, instance creation with download-progress monitoring, streaming/non-streaming write dispatch, result parsing and normalization, structured error wrapping, and guaranteed writer.destroy() in a finally block.
bootstrapWriterSchemaPage UI orchestration
apps/web/src/writer-schema-page.mjs
Resolves DOM elements, creates schema-definition and theme-toggle components, initializes prompt/output state, wires the generate button with a concurrency guard, streams progress updates, applies generated rows to the editor, validates rows, and exposes destroy/generateFromPrompt/getSchemaComponent accessors.
HTML page structure and module entrypoint
apps/web/writer-schema.html, apps/web/src/writer-schema-entry.mjs
Defines the writer-schema.html document with hero/status section, prompt workspace, diagnostics, output/error containers, and schema editor root. The entrypoint dynamically imports the page module and calls bootstrapWriterSchemaPage, logging errors on failure.
CSS styles and Vite build wiring
apps/web/styles.css, apps/web/vite.config.mjs
Adds all .writer-schema-* CSS classes (layout, panels, textarea/JSON/progress visuals, dark-mode overrides, 900px responsive breakpoint) and a minor .webmcp-hero background reformat. Adds the writerSchema rollup input in vite.config.mjs.
Test-env registration and SEO directives
scripts/create-testenv.mjs, tests/integration/create-testenv-seo.test.js
Registers writer-schema.html in canonical URLs, robots.txt, llms.txt, index page, header-hiding, and SEO directive application. Integration tests assert robots/llms/index/canonical/noindex behavior for the new page and header-hiding for WebMCP.
Jest unit and integration tests
apps/web/src/tests/jest/writer-schema-page.test.js
Full test suite covering extractJsonPayload, parseWriterStructuredOutput, normalizeStructuredSchemaPayload, buildWriterSharedContext, runWriterSchemaGeneration (with Writer mock), and bootstrapWriterSchemaPage for unavailable API, success, full failure, and partial-recovery scenarios.

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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • eviltester/grid-table-editor#186: Modifies the same scripts/create-testenv.mjs and tests/integration/create-testenv-seo.test.js files to add top-header hiding and SEO directive registration for generated HTML pages, the same pattern this PR applies to writer-schema.html.
  • eviltester/grid-table-editor#189: Extends the same SEO integration test file (tests/integration/create-testenv-seo.test.js) with applyTopHeaderHideToHtml and applySeoDirectivesToHtml coverage, directly overlapping with the new writer-schema.html assertions added here.

Poem

🐇 A schema emerged from the AI's den,
With writeStreaming and JSON parsed clean,
The rabbit watched rows appear — ten by ten,
Normalized fields, the sharpest you've seen.
Dark mode and gradients, the page glows bright,
bootstrapWriterSchemaPage — what a delight! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately summarizes the primary change: adding a new Writer API schema test page. It is clear, specific, and directly reflects the main changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 204-protytype-writer-api

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread apps/web/src/writer-schema-page.mjs
Comment thread apps/web/styles.css Outdated
@greptile-apps

greptile-apps Bot commented Jun 13, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds a test-environment-only Writer API schema prototype page (writer-schema.html) that turns a natural-language prompt into structured AnyWayData schema rows using Chrome's in-browser Writer API, then populates the shared schema editor with the result.

  • writer-schema-page.mjs — 889-line page module with prompt handling, Writer API invocation (streaming and non-streaming paths), JSON extraction/parsing, per-field normalization with domain-command validation, date-placeholder rejection, and partial-recovery when some fields fail.
  • writer-schema.html / CSS / vite config — new HTML page wired with proper noindex meta, ARIA live regions, and responsive grid layout; registered in the Vite build, test-env robots/llms/SEO pipeline, and index page.
  • Tests — new Jest suite covering extraction, parsing, normalization (valid and invalid commands, date placeholders, partial recovery), and full bootstrap flows; integration SEO tests extended to cover the new page.

Confidence Score: 5/5

Safe 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

Filename Overview
apps/web/src/writer-schema-page.mjs New 889-line page module implementing Writer API schema generation; promptElement is accessed without a null guard in two places during bootstrap and in the example-prompt click handler, inconsistent with optional chaining used elsewhere in the same function.
apps/web/src/tests/jest/writer-schema-page.test.js New Jest test suite covering extraction, parsing, normalization, bootstrap, error paths, and partial recovery; good coverage of the happy path and documented failure modes.
apps/web/styles.css Adds 162 lines of new CSS for the writer-schema page; the .writer-schema-progress-output rule declares padding twice — the first value is dead code silently overridden by the second (already flagged in previous review).
apps/web/writer-schema.html New experimental HTML page wired with noindex/nofollow meta, proper aria-live regions, and the correct entry-point script; follows the established test-environment pattern.
scripts/create-testenv.mjs Registers writer-schema.html in all the right places: canonical URL map, robots.txt disallow list, llms.txt URL list, index page card, header-hide step, and SEO rewrite step.

Sequence Diagram

sequenceDiagram
    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
Loading

Reviews (2): Last reviewed commit: "Address writer schema review feedback" | Re-trigger Greptile

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread apps/web/src/writer-schema-page.mjs Outdated
Comment thread apps/web/src/writer-schema-page.mjs
@eviltester eviltester changed the title [codex] Add Writer API schema test page Add Writer API schema test page Jun 14, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/web/src/tests/jest/writer-schema-page.test.js (1)

113-171: ⚡ Quick win

Consider adding test coverage for the streaming path.

This test exercises writer.write, but runWriterSchemaGeneration also supports writer.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

📥 Commits

Reviewing files that changed from the base of the PR and between e6aa6c2 and 1db27a3.

📒 Files selected for processing (8)
  • apps/web/src/tests/jest/writer-schema-page.test.js
  • apps/web/src/writer-schema-entry.mjs
  • apps/web/src/writer-schema-page.mjs
  • apps/web/styles.css
  • apps/web/vite.config.mjs
  • apps/web/writer-schema.html
  • scripts/create-testenv.mjs
  • tests/integration/create-testenv-seo.test.js

Comment thread apps/web/styles.css
@eviltester eviltester merged commit 2f2d272 into master Jun 14, 2026
14 checks passed
@eviltester eviltester deleted the 204-protytype-writer-api branch June 14, 2026 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants