-
Notifications
You must be signed in to change notification settings - Fork 0
feat(diagnostics): integrate revision-safe actions into CwlEditor #280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
seonghobae
wants to merge
47
commits into
feat/writing-diagnostics-ui
Choose a base branch
from
feat/writing-diagnostics-editor-actions
base: feat/writing-diagnostics-ui
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
0c1c514
test(diagnostics): require standalone editor guidance integration
seonghobae 471d91b
ci(diagnostics): expose standalone integration TDD state
seonghobae e6f8ced
ci(diagnostics): integrate standalone editor once
seonghobae bee158e
ci(diagnostics): make standalone patch anchors exact
seonghobae 965c02f
feat(diagnostics): integrate guidance into standalone editor
github-actions[bot] 9d6b688
test(diagnostics): require revision-safe undoable application
seonghobae 1b046e8
ci(diagnostics): exercise revision-safe application RED
seonghobae 22f7af2
ci(diagnostics): implement revision-safe apply once
seonghobae 03fb65d
ci(diagnostics): repair apply workflow syntax
seonghobae ef00591
ci(diagnostics): normalize panel mock indentation
seonghobae 8a11b40
feat(diagnostics): apply revision-safe replacements
github-actions[bot] 0e9ebc1
ci(diagnostics): run complete editor action acceptance
seonghobae 7f7aadb
test(diagnostics): cover apply conflicts and failures
seonghobae 2c4220b
ci(diagnostics): bound full coverage heap
seonghobae 1073264
test(diagnostics): stabilize apply digest provider
seonghobae 0d15cfb
test(diagnostics): require imperative editor actions
seonghobae 45d0f1f
ci(diagnostics): wire imperative actions once
seonghobae 6507eda
ci(diagnostics): make handle patch workflow parseable
seonghobae 4e8b144
feat(diagnostics): expose imperative editor actions
github-actions[bot] 7e127b0
test(diagnostics): exercise imperative editor actions
seonghobae f7fca0f
test(diagnostics): forbid read-only replacement mutation
seonghobae 4d3ca3c
ci(diagnostics): enforce read-only application once
seonghobae 66db0e3
ci(diagnostics): target read-only apply path exactly
seonghobae 262de77
ci(diagnostics): locate read-only guard structurally
seonghobae 77a6cba
ci(diagnostics): patch first apply guard only
seonghobae df026c1
fix(diagnostics): keep read-only editors immutable
github-actions[bot] c605d53
ci(diagnostics): verify imperative editor handle
seonghobae e3d385b
test(diagnostics): wrap imperative focus transaction
seonghobae 568ae15
test(forms): reject unwrapped collaborative reset updates
seonghobae dcc7aa8
fix(forms): contain native reset updates inside React act
seonghobae 69dd988
test(ci): require warning-free editor actions workflow
seonghobae 089f8fb
ci(diagnostics): fail closed on editor-action act warnings
seonghobae cd06daa
merge(diagnostics): restack editor actions on current UI
seonghobae 70c79f0
test(diagnostics): satisfy editor action controller contract
seonghobae 2423991
test(diagnostics): wrap dismissal focus updates in act
seonghobae a76919b
test(diagnostics): wrap focus-triggered updates in act
seonghobae 84baeda
chore(diagnostics): restack editor actions on current UI authority
seonghobae f682041
fix(stack): synchronize editor actions without regressing exact-head …
seonghobae b315fc8
fix(stack): adopt diagnostics focus assurance from parent
seonghobae bad9d65
test(diagnostics): keep panel fixture aligned with controller
seonghobae fcef604
test(diagnostics): contain focus state updates in act
seonghobae d1d578e
test(security): keep hostile script fixture analyzer-safe
seonghobae d8749ec
test(security): avoid Semgrep ref false positive
seonghobae 0c2d805
ci(diagnostics): regenerate exact-head gates after CI/SAST repairs
seonghobae b415d36
Merge remote-tracking branch 'origin/feat/writing-diagnostics-ui' int…
seonghobae 405f39a
Merge remote-tracking branch 'origin/feat/writing-diagnostics-ui' int…
seonghobae 3be3bab
Merge remote-tracking branch 'origin/feat/writing-diagnostics-ui' int…
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
.github/workflows/writing-diagnostics-editor-actions-tdd.yml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| name: Writing Diagnostics Editor Actions TDD | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - feat/writing-diagnostics-editor-actions | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: writing-diagnostics-editor-actions-tdd-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| env: | ||
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | ||
|
|
||
| jobs: | ||
| focused-editor-actions: | ||
| runs-on: ubuntu-24.04 | ||
| timeout-minutes: 30 | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| ref: ${{ github.sha }} | ||
| persist-credentials: false | ||
| - uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10 | ||
| - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 | ||
| with: | ||
| node-version: 22 | ||
| cache: pnpm | ||
| - run: pnpm install --frozen-lockfile | ||
| - name: Run standalone writing-diagnostic integration tests | ||
| run: | | ||
| set -euo pipefail | ||
| output_file="$(mktemp)" | ||
| trap 'rm -f "$output_file"' EXIT | ||
| set +e | ||
| pnpm exec vitest run \ | ||
| src/components/CwlEditor.writingDiagnostics.test.tsx \ | ||
| src/components/CwlEditor.writingDiagnosticApply.test.tsx \ | ||
| src/components/useWritingDiagnosticsController.apply.test.tsx \ | ||
| src/components/useEditorHandle.test.tsx \ | ||
| --pool=forks \ | ||
| --maxWorkers=1 2>&1 | tee "$output_file" | ||
| test_status=${PIPESTATUS[0]} | ||
| set -e | ||
| if grep -Fq 'not wrapped in act' "$output_file"; then | ||
| echo "::error::Focused editor actions emitted a React act warning." | ||
| exit 1 | ||
| fi | ||
| exit "$test_status" | ||
| - name: Typecheck standalone writing-diagnostic contracts | ||
| run: pnpm typecheck | ||
| - name: Run complete production coverage gate | ||
| env: | ||
| NODE_OPTIONS: --max-old-space-size=6144 | ||
| run: | | ||
| set -euo pipefail | ||
| output_file="$(mktemp)" | ||
| trap 'rm -f "$output_file"' EXIT | ||
| set +e | ||
| pnpm coverage 2>&1 | tee "$output_file" | ||
| test_status=${PIPESTATUS[0]} | ||
| set -e | ||
| if grep -Fq 'not wrapped in act' "$output_file"; then | ||
| echo "::error::Production coverage emitted a React act warning." | ||
| exit 1 | ||
| fi | ||
| exit "$test_status" | ||
| - name: Build all package entrypoints | ||
| run: pnpm build | ||
| - name: Verify isolated packed-package consumers | ||
| run: pnpm verify:package | ||
| - name: Build demonstration application | ||
| run: pnpm build:demo |
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
147 changes: 147 additions & 0 deletions
147
src/components/CwlEditor.writingDiagnosticApply.test.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| import { | ||
| act, | ||
| cleanup, | ||
| fireEvent, | ||
| render, | ||
| screen, | ||
| waitFor, | ||
| } from '@testing-library/react'; | ||
| import { createRef } from 'react'; | ||
| import { afterEach, describe, expect, it, vi } from 'vitest'; | ||
| import type { CwlEditorHandle } from '../types.js'; | ||
| import type { CwlWritingDiagnostic } from '../writingDiagnostics.js'; | ||
| import { CwlEditor } from './CwlEditor.js'; | ||
|
|
||
| afterEach(cleanup); | ||
|
|
||
| async function exactDiagnostic( | ||
| handle: CwlEditorHandle, | ||
| replacement: string, | ||
| ): Promise<CwlWritingDiagnostic> { | ||
| const evidence = await handle.getTextPositionSelectorEvidence(); | ||
| if (evidence === null) throw new Error('Missing selector evidence'); | ||
| return { | ||
| diagnosticId: 'apply-diagnostic', | ||
| documentRevision: evidence.revision, | ||
| textProjection: evidence.textProjection, | ||
| selector: evidence.selector, | ||
| categoryCode: 'clarity', | ||
| priority: 'important', | ||
| title: 'Clarify the request', | ||
| explanation: 'Make the requested action explicit.', | ||
| suggestedReplacement: replacement, | ||
| provenance: { | ||
| workflowId: 'email-writing-review', | ||
| workflowVersion: '1', | ||
| judgePolicyVersion: 'evaluation-only-1', | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| describe('CwlEditor writing-diagnostic application', () => { | ||
| it('rechecks the exact revision, inserts plain text, invalidates diagnostics, and remains undoable', async () => { | ||
| const handleRef: { current: CwlEditorHandle | null } = { current: null }; | ||
| const onAction = vi.fn(); | ||
| const onChange = vi.fn(); | ||
| const view = render( | ||
| <CwlEditor | ||
| defaultValue="Alpha beta" | ||
| hideToolbar | ||
| onChange={onChange} | ||
| onWritingDiagnosticAction={onAction} | ||
| ref={handleRef} | ||
| />, | ||
| ); | ||
| await waitFor(() => expect(handleRef.current?.getEditor()).not.toBeNull()); | ||
|
|
||
| act(() => { | ||
| handleRef.current!.getEditor()!.commands.setTextSelection({ from: 1, to: 6 }); | ||
| }); | ||
| const hostileTagName = ['scr', 'ipt'].join(''); | ||
| // nosemgrep: javascript.lang.security.audit.unknown-value-with-script-tag.unknown-value-with-script-tag -- controlled XSS regression fixture; line 85 proves no element is created. | ||
| const replacement = `<${hostileTagName}>alert(1)</${hostileTagName}>`; | ||
| const diagnostic = await exactDiagnostic(handleRef.current!, replacement); | ||
|
|
||
| view.rerender( | ||
| <CwlEditor | ||
| defaultValue="Alpha beta" | ||
| hideToolbar | ||
| onChange={onChange} | ||
| onWritingDiagnosticAction={onAction} | ||
| ref={handleRef} | ||
| writingDiagnostics={[diagnostic]} | ||
| writingDiagnosticsLabel="Email writing guidance" | ||
| />, | ||
| ); | ||
|
|
||
| const apply = await screen.findByRole('button', { | ||
| name: 'Apply suggestion for Clarify the request', | ||
| }); | ||
| expect(apply).toBeEnabled(); | ||
| fireEvent.click(apply); | ||
|
|
||
| await waitFor(() => | ||
| expect(handleRef.current?.getValue()).toBe(`${replacement} beta`), | ||
| ); | ||
| expect(document.querySelector('script')).toBeNull(); | ||
| expect(document.querySelector('.cwl-writing-diagnostic')).toBeNull(); | ||
| expect(onAction).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| action: 'applied', | ||
| reasonCode: 'explicit', | ||
| diagnosticId: 'apply-diagnostic', | ||
| resultingDocumentRevision: expect.objectContaining({ | ||
| algorithm: 'SHA-256', | ||
| }), | ||
| }), | ||
| ); | ||
| expect(onChange).toHaveBeenCalled(); | ||
|
|
||
| act(() => { | ||
| expect(handleRef.current!.getEditor()!.commands.undo()).toBe(true); | ||
| }); | ||
| expect(handleRef.current?.getValue()).toBe('Alpha beta'); | ||
| }); | ||
|
|
||
| it('keeps replacement application disabled and inert in read-only mode', async () => { | ||
| const handleRef = createRef<CwlEditorHandle>(); | ||
| const onAction = vi.fn(); | ||
| const view = render( | ||
| <CwlEditor | ||
| defaultValue="Alpha beta" | ||
| editable={false} | ||
| hideToolbar | ||
| onWritingDiagnosticAction={onAction} | ||
| ref={handleRef} | ||
| />, | ||
| ); | ||
| await waitFor(() => expect(handleRef.current?.getEditor()).not.toBeNull()); | ||
|
|
||
| act(() => { | ||
| handleRef.current!.getEditor()!.commands.setTextSelection({ from: 1, to: 6 }); | ||
| }); | ||
| const diagnostic = await exactDiagnostic(handleRef.current!, 'Omega'); | ||
|
|
||
| view.rerender( | ||
| <CwlEditor | ||
| defaultValue="Alpha beta" | ||
| editable={false} | ||
| hideToolbar | ||
| onWritingDiagnosticAction={onAction} | ||
| ref={handleRef} | ||
| writingDiagnostics={[diagnostic]} | ||
| />, | ||
| ); | ||
|
|
||
| const apply = await screen.findByRole('button', { | ||
| name: 'Apply suggestion for Clarify the request', | ||
| }); | ||
| expect(apply).toBeDisabled(); | ||
| await expect( | ||
| handleRef.current!.applyWritingDiagnostic('apply-diagnostic'), | ||
| ).resolves.toBeNull(); | ||
| expect(handleRef.current!.getValue()).toBe('Alpha beta'); | ||
| expect(onAction).not.toHaveBeenCalled(); | ||
| expect(document.querySelector('.cwl-writing-diagnostic')).not.toBeNull(); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.