Skip to content

Load and save schema files#213

Merged
eviltester merged 10 commits into
masterfrom
209-load-save-schema-file
Jun 16, 2026
Merged

Load and save schema files#213
eviltester merged 10 commits into
masterfrom
209-load-save-schema-file

Conversation

@eviltester

@eviltester eviltester commented Jun 16, 2026

Copy link
Copy Markdown
Owner

Summary

  • add shared schema file load/save actions to the shared schema editor UI
  • introduce shared text-file read and schema file transfer services so app, generator, and writer-schema use one implementation
  • add Storybook, Jest, and Playwright coverage for valid and invalid schema file flows

Why

Issue #209 asked for plain-text schema file import/export to be available consistently anywhere the shared schema editor is mounted, without duplicating page-host logic.

Impact

Users can now load an existing schema text file into the shared schema editor and save the current schema text back out from the app test-data panel, generator page, and writer-schema page.

Validation

  • local dev server started successfully with pnpm run dev:web
  • browser sanity check passed against app.html, generator.html, and writer-schema.html
  • pnpm run verify:ui
  • pnpm run test:browser
  • pnpm run test:storybook
  • pnpm run build-storybook
  • pnpm test
  • pnpm run verify:local

Summary by CodeRabbit

  • New Features
    • Added shared plain-text schema file load and save controls, now consistently available across test data, generator, and shared schema definition views.
    • Added new Storybook scenarios covering loading valid and invalid schema files.
  • Bug Fixes
    • Improved schema file handling (text normalization, mode behavior, and clearer load/save error messaging).
    • Updated internal file-read/export wiring to use the shared text-file service.
  • Tests
    • Added Playwright end-to-end tests verifying parsing results and save/download behavior (including suggested filename).
    • Expanded Jest coverage for controller/view behavior and schema file transfer normalization/error wrapping.
  • Documentation
    • Updated the frontend migration plan checklist for the new shared ownership of schema file controls.

Copilot AI review requested due to automatic review settings June 16, 2026 13:08
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 81a311b2-3538-4a9f-91d7-3509a08e3715

📥 Commits

Reviewing files that changed from the base of the PR and between b674def and d412f43.

📒 Files selected for processing (4)
  • packages/core-ui/js/gui_components/shared/schema-file-transfer-service.js
  • packages/core-ui/js/gui_components/shared/test-data/schema/shared-schema-editor-controller.js
  • packages/core-ui/src/tests/shared/schema-file-transfer-service.test.js
  • packages/core-ui/src/tests/shared/shared-schema-definition-view.test.js
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/core-ui/src/tests/shared/schema-file-transfer-service.test.js
  • packages/core-ui/js/gui_components/shared/schema-file-transfer-service.js
  • packages/core-ui/src/tests/shared/shared-schema-definition-view.test.js
  • packages/core-ui/js/gui_components/shared/test-data/schema/shared-schema-editor-controller.js

📝 Walkthrough

Walkthrough

Adds plain-text schema file load and save to SharedSchemaDefinitionComponent. A new createTextFileReadService factory is extracted into a shared module (replacing the inline implementation in file-read-service.js), and a new createSchemaFileTransferService handles read normalization and download with error wrapping. The schema editor controller's loadSchemaText is updated to support preferRowMode and return an applied flag. The SharedSchemaDefinitionController gains services, file I/O methods (loadSchemaFromFile, saveSchemaToFile), and error management. The view adds a file-actions UI section with load/save buttons and a hidden file input. The feature is covered by unit, Storybook, and Playwright tests.

Changes

Schema File Load/Save Feature

Layer / File(s) Summary
Text file read service and file-read-service refactor
packages/core-ui/js/gui_components/shared/text-file-read-service.js, packages/core-ui/js/gui_components/app/import-export-adapters/file-read-service.js, packages/core-ui/src/tests/app/import-export-adapters.test.js
New createTextFileReadService factory provides promise-based FileReader usage with injected dependencies and optional lifecycle callbacks for progress, load, error, and abort events. file-read-service.js is simplified to re-export the new factory as createFileReadService. Test coverage verifies readText resolves correctly when callbacks are omitted.
Schema file transfer service
packages/core-ui/js/gui_components/shared/schema-file-transfer-service.js
New createSchemaFileTransferService wires the text read service into readSchemaTextFile (read + BOM-strip + newline normalization) and downloadSchemaText. Exports DEFAULT_SCHEMA_FILENAME, normalizeSchemaFileText, and toSchemaFileReadError for user-facing error wrapping with cause preservation.
SchemaEditorController: loadSchemaText with preferRowMode
packages/core-ui/js/gui_components/shared/test-data/schema/shared-schema-editor-controller.js
Replaces the prior loadSchemaText with a version that forces text-mode sync, supports preferRowMode to optionally switch back to row mode with semantic validation on success, and returns { applied: true/false } alongside rows/errors/tokens.
SharedSchemaDefinitionController: services, view model, file I/O methods
packages/core-ui/js/gui_components/shared/schema-definition/shared-schema-definition-controller.js
Constructor gains a services parameter. getViewModel adds CSS class names, button labels, and file-accept fields. New setSchemaError/clearSchemaError manage error display. loadSchemaFromFile reads via transfer service and applies with preferRowMode. saveSchemaToFile downloads and emits onSchemaFileSaved.
SharedSchemaDefinitionView: file-actions UI and event handlers
packages/core-ui/js/gui_components/shared/schema-definition/shared-schema-definition-view.js
Adds data-role constants for file input and buttons. Constructor creates handlers for load-button click (opens hidden file input), file input change (calls controller to load, clears input), and save-button click. Template includes file-actions section with load button, hidden file input, and save button. DOM elements cached in mount() and listeners attached/removed in mount()/destroy().
Component index wiring and CSS styling
packages/core-ui/js/gui_components/shared/schema-definition/index.js, apps/web/styles.css
Component index constructs schemaFileTransferService when not injected and wires it into the controller. Public API is extended to expose loadSchemaFromFile and saveSchemaToFile. CSS adds .shared-schema-file-actions layout using inline-flex with center alignment and wrapping, plus dark-theme border-color override for icon buttons.
Unit tests: schema file transfer service
packages/core-ui/src/tests/shared/schema-file-transfer-service.test.js
Tests verify readSchemaTextFile normalizes text (CRLF to LF, BOM stripping), wraps file-read failures into user-facing messages while preserving original errors as cause, and distinguishes abort vs non-abort conditions.
Unit tests: controller and view file I/O
packages/core-ui/src/tests/shared/shared-schema-definition-controller.test.js, packages/core-ui/src/tests/shared/shared-schema-definition-view.test.js
Controller tests verify saveSchemaToFile forwards schema text and filename to the transfer service, handles missing download support, and loadSchemaFromFile reads, applies with preferRowMode, and wraps errors. View tests wire a mock service and cover save, valid-load, and invalid-load scenarios with error surfacing.
Browser E2E tests, Storybook stories, and docs
apps/web/src/tests/browser/shared/abstractions/components/schema-editor.component.js, apps/web/src/tests/browser/app/abstractions/components/test-data-panel.component.js, apps/web/src/tests/browser/generator/abstractions/components/generator-schema.component.js, apps/web/src/tests/browser/app/functional/test-data/schema-file-load-save.spec.js, apps/web/src/tests/browser/generator/functional/schema-file-load-save.spec.js, apps/web/src/stories/shared-schema-definition.stories.js, docs/frontend-component-migration-plan.md
SchemaEditorComponent adds locators and loadSchemaFile/saveSchemaFileAndWaitForDownload methods delegated by test components. Playwright suites load in-memory schema buffers, verify content, save to download, and assert filename/contents. Storybook stories extend EmptySchema to check load/save button visibility, add LoadSchemaFile and InvalidSchemaFile stories. Docs updated with migration status.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant SharedSchemaDefinitionView
  participant SharedSchemaDefinitionController
  participant SchemaFileTransferService
  participant SchemaEditorController

  rect rgba(173, 216, 230, 0.5)
    Note over User,SchemaEditorController: Load schema from file
    User->>SharedSchemaDefinitionView: click load button
    SharedSchemaDefinitionView->>SharedSchemaDefinitionView: open hidden file input
    User->>SharedSchemaDefinitionView: change event (file selected)
    SharedSchemaDefinitionView->>SharedSchemaDefinitionController: loadSchemaFromFile(file)
    SharedSchemaDefinitionController->>SchemaFileTransferService: readSchemaTextFile(file)
    SchemaFileTransferService-->>SharedSchemaDefinitionController: normalized text
    SharedSchemaDefinitionController->>SchemaEditorController: loadSchemaText(text, {showErrors, preferRowMode})
    SchemaEditorController-->>SharedSchemaDefinitionController: {rows, errors, applied}
    SharedSchemaDefinitionController-->>SharedSchemaDefinitionView: onSchemaFileLoaded callback
    SharedSchemaDefinitionView->>SharedSchemaDefinitionView: clear file input value
  end

  rect rgba(144, 238, 144, 0.5)
    Note over User,SchemaFileTransferService: Save schema to file
    User->>SharedSchemaDefinitionView: click save button
    SharedSchemaDefinitionView->>SharedSchemaDefinitionController: saveSchemaToFile()
    SharedSchemaDefinitionController->>SchemaFileTransferService: downloadSchemaText(text, filename)
    SharedSchemaDefinitionController-->>SharedSchemaDefinitionView: onSchemaFileSaved callback
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Poem

🐇 Hoppin' through files with BOM strips so clean,
A FileReader promise, the best I've seen,
Load schema in, save schema out,
The rabbit's normalization, no text byte about!
Download's ready, preferRowMode applied —
Plain text and a bunny, side by side! 🌿

🚥 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.
Title check ✅ Passed The title 'Load and save schema files' directly and accurately describes the primary change in the PR: adding schema file load and save functionality to the shared schema editor UI.
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.

✏️ 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 209-load-save-schema-file

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/core-ui/js/gui_components/shared/schema-file-transfer-service.js

Oops! Something went wrong! :(

ESLint: 10.4.1

A config object is using the "root" key, which is not supported in flat config system.

Flat configs always act as if they are the root config file, so this key can be safely removed.

packages/core-ui/js/gui_components/shared/test-data/schema/shared-schema-editor-controller.js

Oops! Something went wrong! :(

ESLint: 10.4.1

A config object is using the "root" key, which is not supported in flat config system.

Flat configs always act as if they are the root config file, so this key can be safely removed.

packages/core-ui/src/tests/shared/schema-file-transfer-service.test.js

Oops! Something went wrong! :(

ESLint: 10.4.1

A config object is using the "root" key, which is not supported in flat config system.

Flat configs always act as if they are the root config file, so this key can be safely removed.

  • 1 others

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 schema file load/save capabilities directly to the shared schema editor component so the app test-data panel, generator page, and writer-schema page all share the same import/export workflow and implementation.

Changes:

  • Introduce shared text-file read and schema file transfer services, and wire them into SharedSchemaDefinition.
  • Add shared-schema controller/view support + UI controls for loading a schema text file and saving the current schema to disk.
  • Add/extend Jest, Storybook, and Playwright coverage for schema file load/save flows.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/core-ui/src/tests/shared/shared-schema-definition-view.test.js Adds UI/service wiring tests for load/save controls and file input flows.
packages/core-ui/src/tests/shared/shared-schema-definition-controller.test.js Adds controller-level tests for forwarding file save/load through the shared service.
packages/core-ui/js/gui_components/shared/text-file-read-service.js New shared FileReader-based text read service for reuse across hosts.
packages/core-ui/js/gui_components/shared/test-data/schema/shared-schema-editor-controller.js Enhances loadSchemaText behavior to support file-load flows and row-mode preference.
packages/core-ui/js/gui_components/shared/schema-file-transfer-service.js New shared service to normalize schema text on read and download schema text files.
packages/core-ui/js/gui_components/shared/schema-definition/shared-schema-definition-view.js Adds load/save buttons and file input, and binds them to controller actions.
packages/core-ui/js/gui_components/shared/schema-definition/shared-schema-definition-controller.js Adds file load/save actions and related callbacks/error handling hooks.
packages/core-ui/js/gui_components/shared/schema-definition/index.js Wires default schemaFileTransferService into the shared component via services injection.
packages/core-ui/js/gui_components/app/import-export-adapters/file-read-service.js Switches app adapter to re-export the new shared text file read service.
docs/frontend-component-migration-plan.md Documents that schema file controls are now owned by SharedSchemaDefinition.
apps/web/styles.css Adds styling for the new shared schema file action button group.
apps/web/src/tests/browser/shared/abstractions/components/schema-editor.component.js Extends Playwright component abstraction with file load/save helpers.
apps/web/src/tests/browser/generator/functional/schema-file-load-save.spec.js New Playwright spec validating generator schema load/save via files.
apps/web/src/tests/browser/generator/abstractions/components/generator-schema.component.js Exposes file load/save methods through generator schema abstraction.
apps/web/src/tests/browser/app/functional/test-data/schema-file-load-save.spec.js New Playwright spec validating app test-data panel schema load/save via files.
apps/web/src/tests/browser/app/abstractions/components/test-data-panel.component.js Exposes file load/save methods through test-data panel abstraction.
apps/web/src/stories/shared-schema-definition.stories.js Adds Storybook stories documenting valid/invalid schema file upload behavior.

@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: 307442236a

ℹ️ 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".

@greptile-apps

greptile-apps Bot commented Jun 16, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds shared plain-text schema file load and save controls to SharedSchemaDefinition, backed by new text-file-read-service and schema-file-transfer-service abstractions, so all three page hosts (app, generator, writer-schema) share one implementation instead of growing page-specific file handlers.

  • Service layer: createTextFileReadService is extracted from the old app-scoped file-read-service.js (which is reduced to a re-export), and createSchemaFileTransferService wraps it with BOM/CRLF normalisation and download support.
  • Controller & view: SharedSchemaDefinitionController gains loadSchemaFromFile / saveSchemaToFile methods with injected-service pattern; SharedSchemaDefinitionView wires the new hidden file input and two icon-buttons; the loadSchemaText helper in shared-schema-editor-controller.js is refactored to capture the previous mode and restore it correctly on parse failure.
  • Tests: Jest unit tests cover all new controller paths and normalisation; DOM/component tests cover save/load happy paths and error states; Playwright specs cover the full file round-trip on both the app and generator pages; Storybook gains LoadSchemaFile and InvalidSchemaFile stories.

Confidence Score: 5/5

Safe to merge. The changes are well-scoped, the new service layer is injected rather than global, and all three page hosts adopt the same shared implementation without breaking their existing API contracts.

The loadSchemaText refactor correctly captures previousTextMode before the parse attempt and restores it on failure when the caller has not specified preferRowMode, preserving backward compatibility. The getState() fallback shape fix corrects a pre-existing mismatch between the old property names and the real editor shape. Every new code path has corresponding unit tests, DOM/component tests, Storybook stories, and Playwright end-to-end coverage. No logic errors or broken contracts were found.

No files require special attention.

Important Files Changed

Filename Overview
packages/core-ui/js/gui_components/shared/schema-file-transfer-service.js New service cleanly wraps text-file-read and download behind a single interface; BOM/CRLF normalisation and error wrapping are well-tested.
packages/core-ui/js/gui_components/shared/test-data/schema/shared-schema-editor-controller.js loadSchemaText refactored to capture previousTextMode and restore it on parse failure when preferRowMode is undefined; tests cover both the new file-load path and the existing caller compat path.
packages/core-ui/js/gui_components/shared/schema-definition/shared-schema-definition-controller.js Gains loadSchemaFromFile/saveSchemaToFile with injected service pattern; getState() fallback corrected from old (schemaRows/schemaTextTokens) shape to match the real editor's (rows/tokens) shape.
packages/core-ui/js/gui_components/shared/schema-definition/shared-schema-definition-view.js Adds hidden file input and two icon-buttons; resets the file input value after async load so the same file can be re-selected; event listeners are properly added and removed in destroy.
packages/core-ui/js/gui_components/app/import-export-adapters/file-read-service.js Old implementation replaced with a single re-export alias preserving the existing public name; no call-site changes required.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant User
    participant View as SharedSchemaDefinitionView
    participant Controller as SharedSchemaDefinitionController
    participant TransferSvc as SchemaFileTransferService
    participant ReadSvc as TextFileReadService
    participant EditorCtrl as SharedSchemaEditorController

    Note over User,EditorCtrl: Load schema file flow
    User->>View: selects file via hidden input
    View->>Controller: loadSchemaFromFile(file)
    Controller->>TransferSvc: readSchemaTextFile(file)
    TransferSvc->>ReadSvc: readText(file)
    ReadSvc-->>TransferSvc: raw text
    TransferSvc-->>Controller: normalised text (BOM+CRLF stripped)
    Controller->>EditorCtrl: "loadSchemaText(text, {showErrors:true, preferRowMode:true})"
    EditorCtrl-->>Controller: "{rows, errors, applied}"
    alt "applied === true"
        Controller->>Controller: callbacks.onSchemaFileLoaded(...)
    end
    Controller-->>View: result

    Note over User,EditorCtrl: Save schema file flow
    User->>View: clicks Save Schema File
    View->>Controller: saveSchemaToFile()
    Controller->>EditorCtrl: getSchemaText()
    EditorCtrl-->>Controller: schemaText
    Controller->>TransferSvc: "downloadSchemaText(schemaText, {filename})"
    TransferSvc->>TransferSvc: new Download(...).downloadFile(...)
    Controller->>Controller: callbacks.onSchemaFileSaved(...)
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant User
    participant View as SharedSchemaDefinitionView
    participant Controller as SharedSchemaDefinitionController
    participant TransferSvc as SchemaFileTransferService
    participant ReadSvc as TextFileReadService
    participant EditorCtrl as SharedSchemaEditorController

    Note over User,EditorCtrl: Load schema file flow
    User->>View: selects file via hidden input
    View->>Controller: loadSchemaFromFile(file)
    Controller->>TransferSvc: readSchemaTextFile(file)
    TransferSvc->>ReadSvc: readText(file)
    ReadSvc-->>TransferSvc: raw text
    TransferSvc-->>Controller: normalised text (BOM+CRLF stripped)
    Controller->>EditorCtrl: "loadSchemaText(text, {showErrors:true, preferRowMode:true})"
    EditorCtrl-->>Controller: "{rows, errors, applied}"
    alt "applied === true"
        Controller->>Controller: callbacks.onSchemaFileLoaded(...)
    end
    Controller-->>View: result

    Note over User,EditorCtrl: Save schema file flow
    User->>View: clicks Save Schema File
    View->>Controller: saveSchemaToFile()
    Controller->>EditorCtrl: getSchemaText()
    EditorCtrl-->>Controller: schemaText
    Controller->>TransferSvc: "downloadSchemaText(schemaText, {filename})"
    TransferSvc->>TransferSvc: new Download(...).downloadFile(...)
    Controller->>Controller: callbacks.onSchemaFileSaved(...)
Loading

Reviews (8): Last reviewed commit: "Normalize schema file read errors" | Re-trigger Greptile

@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: 3

🧹 Nitpick comments (1)
packages/core-ui/src/tests/shared/shared-schema-definition-view.test.js (1)

479-480: ⚡ Quick win

Replace manual microtask flushing with assertion-based waiting to avoid flaky async tests.

Line 479-480 and Line 505-506 depend on current promise-chaining depth (await Promise.resolve() twice). If the async path changes, these tests can intermittently fail despite correct behavior.

♻️ Suggested test-stability patch
 import { jest } from '`@jest/globals`';
 import { JSDOM } from 'jsdom';
-import { fireEvent, within } from '`@testing-library/dom`';
+import { fireEvent, within, waitFor } from '`@testing-library/dom`';
@@
-    fireEvent.change(fileInput);
-    await Promise.resolve();
-    await Promise.resolve();
+    fireEvent.change(fileInput);
+    await waitFor(() => {
+      expect(document.querySelectorAll('.shared-schema-row')).toHaveLength(2);
+    });
@@
-    fireEvent.change(fileInput);
-    await Promise.resolve();
-    await Promise.resolve();
+    fireEvent.change(fileInput);
+    await waitFor(() => {
+      expect(document.querySelector('[data-role="schema-error"]').textContent.length).toBeGreaterThan(0);
+    });

Also applies to: 505-506

🤖 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 `@packages/core-ui/src/tests/shared/shared-schema-definition-view.test.js`
around lines 479 - 480, Replace the manual microtask flushing approach using
await Promise.resolve() calls with assertion-based waiting that checks for
actual DOM state or element conditions. At lines 479-480 (and the sibling
location at lines 505-506), instead of relying on fixed Promise.resolve()
chains, wait for specific DOM elements to appear, become visible, or reach an
expected state using appropriate wait utilities or assertions. This makes the
test more robust to changes in internal async behavior while ensuring the test
actually validates meaningful state changes.
🤖 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/src/tests/browser/app/functional/test-data/schema-file-load-save.spec.js`:
- Around line 16-17: The test assertions on getSchemaText() are executing
immediately without waiting for the async file-read and parse operations to
complete, causing intermittent CI failures due to race conditions. Replace the
immediate expect(await ...) checks at
apps/web/src/tests/browser/app/functional/test-data/schema-file-load-save.spec.js
lines 16-17 with polling assertions using expect.poll(...) or waitFor(...) to
ensure the schema text contains 'Loaded Name' and 'Loaded Status' after the
async operation completes. Apply the same polling pattern fix at
apps/web/src/tests/browser/generator/functional/schema-file-load-save.spec.js
lines 15-16 for the corresponding assertions on the generator flow.

In
`@packages/core-ui/js/gui_components/shared/schema-definition/shared-schema-definition-controller.js`:
- Around line 201-227: The loadSchemaFromFile method uses an inconsistent state
key when building error result objects. Both the early return on line 210 (when
fileTransferService is unavailable) and the catch block on line 226 (when file
reading fails) reference this.getState().rows, but the class uses schemaRows as
the actual state key elsewhere. Replace both instances of this.getState().rows
with this.getState().schemaRows to ensure the correct row payload is returned on
load failures.

In `@packages/core-ui/js/gui_components/shared/text-file-read-service.js`:
- Around line 12-43: The optional chaining in the readText method is incomplete
and will throw a TypeError when callbacks is null or undefined. The current
pattern callbacks.onX?.(args) checks if the method exists but not if callbacks
itself is defined. Fix this by adding an additional optional chaining operator
on the callbacks object itself, changing all instances of
callbacks.onProgress?.(event), callbacks.onLoad?.(text, event),
callbacks.onError?.(event), and callbacks.onAbort?.(event) to use
callbacks?.onProgress?.(event), callbacks?.onLoad?.(text, event),
callbacks?.onError?.(event), and callbacks?.onAbort?.(event) respectively. This
ensures the property access is guarded before attempting to invoke the callback
functions.

---

Nitpick comments:
In `@packages/core-ui/src/tests/shared/shared-schema-definition-view.test.js`:
- Around line 479-480: Replace the manual microtask flushing approach using
await Promise.resolve() calls with assertion-based waiting that checks for
actual DOM state or element conditions. At lines 479-480 (and the sibling
location at lines 505-506), instead of relying on fixed Promise.resolve()
chains, wait for specific DOM elements to appear, become visible, or reach an
expected state using appropriate wait utilities or assertions. This makes the
test more robust to changes in internal async behavior while ensuring the test
actually validates meaningful state changes.
🪄 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: 55b3a82e-6ea4-4211-b77d-dbfe667e2d26

📥 Commits

Reviewing files that changed from the base of the PR and between aa5d2cd and 3074422.

📒 Files selected for processing (17)
  • apps/web/src/stories/shared-schema-definition.stories.js
  • apps/web/src/tests/browser/app/abstractions/components/test-data-panel.component.js
  • apps/web/src/tests/browser/app/functional/test-data/schema-file-load-save.spec.js
  • apps/web/src/tests/browser/generator/abstractions/components/generator-schema.component.js
  • apps/web/src/tests/browser/generator/functional/schema-file-load-save.spec.js
  • apps/web/src/tests/browser/shared/abstractions/components/schema-editor.component.js
  • apps/web/styles.css
  • docs/frontend-component-migration-plan.md
  • packages/core-ui/js/gui_components/app/import-export-adapters/file-read-service.js
  • packages/core-ui/js/gui_components/shared/schema-definition/index.js
  • packages/core-ui/js/gui_components/shared/schema-definition/shared-schema-definition-controller.js
  • packages/core-ui/js/gui_components/shared/schema-definition/shared-schema-definition-view.js
  • packages/core-ui/js/gui_components/shared/schema-file-transfer-service.js
  • packages/core-ui/js/gui_components/shared/test-data/schema/shared-schema-editor-controller.js
  • packages/core-ui/js/gui_components/shared/text-file-read-service.js
  • packages/core-ui/src/tests/shared/shared-schema-definition-controller.test.js
  • packages/core-ui/src/tests/shared/shared-schema-definition-view.test.js

Comment thread apps/web/src/tests/browser/app/functional/test-data/schema-file-load-save.spec.js Outdated
Comment thread packages/core-ui/js/gui_components/shared/text-file-read-service.js

@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)
packages/core-ui/src/tests/shared/schema-file-transfer-service.test.js (1)

30-36: ⚡ Quick win

Avoid double-invoking readSchemaTextFile in error-path tests.

Each test currently calls the method twice (once for message, once for cause), which can make failures harder to diagnose if behavior ever becomes stateful. Assert both in a single rejection expectation.

Proposed test refactor
-    await expect(service.readSchemaTextFile({ name: 'schema.txt' })).rejects.toThrow('Reading the schema file failed.');
-
-    try {
-      await service.readSchemaTextFile({ name: 'schema.txt' });
-    } catch (error) {
-      expect(error.cause).toBe(fileReadError);
-    }
+    await expect(service.readSchemaTextFile({ name: 'schema.txt' })).rejects.toMatchObject({
+      message: 'Reading the schema file failed.',
+      cause: fileReadError,
+    });
-    await expect(service.readSchemaTextFile({ name: 'schema.txt' })).rejects.toThrow(
-      'Reading the schema file aborted.'
-    );
-
-    try {
-      await service.readSchemaTextFile({ name: 'schema.txt' });
-    } catch (error) {
-      expect(error.cause).toBe(fileReadAbort);
-    }
+    await expect(service.readSchemaTextFile({ name: 'schema.txt' })).rejects.toMatchObject({
+      message: 'Reading the schema file aborted.',
+      cause: fileReadAbort,
+    });

Also applies to: 52-56

🤖 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 `@packages/core-ui/src/tests/shared/schema-file-transfer-service.test.js`
around lines 30 - 36, The test for readSchemaTextFile method is invoking the
service twice (once in the expect().rejects.toThrow() call and again in the
try/catch block), which is inefficient and harder to diagnose if the behavior
becomes stateful. Refactor to combine both assertions into a single rejection
expectation: use expect().rejects.toThrow() but extend it to verify both that
the error message matches 'Reading the schema file failed.' and that the
error.cause property equals the fileReadError. Apply this same pattern to all
instances of this test pattern in the file (including around lines 52-56) to
ensure consistent and efficient error-path testing.
🤖 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 `@packages/core-ui/js/gui_components/shared/schema-file-transfer-service.js`:
- Around line 12-15: The `toSchemaFileReadError` function currently returns raw
`Error` instances directly when `error instanceof Error` is true, which bypasses
the service's normalized user-facing error contract that distinguishes between
`failed` and `aborted` states and guarantees `cause` wrapping. Instead of
returning the error directly on line 13, wrap the error according to the
service's standard error contract structure to ensure consistency with how other
error cases in this function are handled, maintaining the proper `failed` vs
`aborted` distinction and guaranteeing the `cause` field is set for standard
`Error` failures.

---

Nitpick comments:
In `@packages/core-ui/src/tests/shared/schema-file-transfer-service.test.js`:
- Around line 30-36: The test for readSchemaTextFile method is invoking the
service twice (once in the expect().rejects.toThrow() call and again in the
try/catch block), which is inefficient and harder to diagnose if the behavior
becomes stateful. Refactor to combine both assertions into a single rejection
expectation: use expect().rejects.toThrow() but extend it to verify both that
the error message matches 'Reading the schema file failed.' and that the
error.cause property equals the fileReadError. Apply this same pattern to all
instances of this test pattern in the file (including around lines 52-56) to
ensure consistent and efficient error-path testing.
🪄 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: 0cd77a14-8e05-4391-83b5-d80ab022eb2f

📥 Commits

Reviewing files that changed from the base of the PR and between 3074422 and 16758f2.

📒 Files selected for processing (6)
  • packages/core-ui/js/gui_components/shared/schema-definition/shared-schema-definition-controller.js
  • packages/core-ui/js/gui_components/shared/schema-file-transfer-service.js
  • packages/core-ui/js/gui_components/shared/test-data/schema/shared-schema-editor-controller.js
  • packages/core-ui/src/tests/shared/schema-file-transfer-service.test.js
  • packages/core-ui/src/tests/shared/shared-schema-definition-controller.test.js
  • packages/core-ui/src/tests/shared/shared-schema-definition-view.test.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/core-ui/js/gui_components/shared/test-data/schema/shared-schema-editor-controller.js

Comment thread packages/core-ui/js/gui_components/shared/schema-file-transfer-service.js Outdated
@eviltester eviltester changed the title [codex] Load and save schema files Load and save schema files Jun 16, 2026
@eviltester eviltester merged commit 05e030e into master Jun 16, 2026
16 checks passed
@eviltester eviltester deleted the 209-load-save-schema-file branch June 16, 2026 22:30
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