Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
0c1c514
test(diagnostics): require standalone editor guidance integration
seonghobae Aug 12, 2026
471d91b
ci(diagnostics): expose standalone integration TDD state
seonghobae Aug 12, 2026
e6f8ced
ci(diagnostics): integrate standalone editor once
seonghobae Aug 12, 2026
bee158e
ci(diagnostics): make standalone patch anchors exact
seonghobae Aug 12, 2026
965c02f
feat(diagnostics): integrate guidance into standalone editor
github-actions[bot] Aug 12, 2026
9d6b688
test(diagnostics): require revision-safe undoable application
seonghobae Aug 12, 2026
1b046e8
ci(diagnostics): exercise revision-safe application RED
seonghobae Aug 12, 2026
22f7af2
ci(diagnostics): implement revision-safe apply once
seonghobae Aug 12, 2026
03fb65d
ci(diagnostics): repair apply workflow syntax
seonghobae Aug 12, 2026
ef00591
ci(diagnostics): normalize panel mock indentation
seonghobae Aug 12, 2026
8a11b40
feat(diagnostics): apply revision-safe replacements
github-actions[bot] Aug 12, 2026
0e9ebc1
ci(diagnostics): run complete editor action acceptance
seonghobae Aug 12, 2026
7f7aadb
test(diagnostics): cover apply conflicts and failures
seonghobae Aug 12, 2026
2c4220b
ci(diagnostics): bound full coverage heap
seonghobae Aug 12, 2026
1073264
test(diagnostics): stabilize apply digest provider
seonghobae Aug 12, 2026
0d15cfb
test(diagnostics): require imperative editor actions
seonghobae Aug 12, 2026
45d0f1f
ci(diagnostics): wire imperative actions once
seonghobae Aug 12, 2026
6507eda
ci(diagnostics): make handle patch workflow parseable
seonghobae Aug 12, 2026
4e8b144
feat(diagnostics): expose imperative editor actions
github-actions[bot] Aug 12, 2026
7e127b0
test(diagnostics): exercise imperative editor actions
seonghobae Aug 12, 2026
f7fca0f
test(diagnostics): forbid read-only replacement mutation
seonghobae Aug 12, 2026
4d3ca3c
ci(diagnostics): enforce read-only application once
seonghobae Aug 12, 2026
66db0e3
ci(diagnostics): target read-only apply path exactly
seonghobae Aug 12, 2026
262de77
ci(diagnostics): locate read-only guard structurally
seonghobae Aug 12, 2026
77a6cba
ci(diagnostics): patch first apply guard only
seonghobae Aug 12, 2026
df026c1
fix(diagnostics): keep read-only editors immutable
github-actions[bot] Aug 12, 2026
c605d53
ci(diagnostics): verify imperative editor handle
seonghobae Aug 12, 2026
e3d385b
test(diagnostics): wrap imperative focus transaction
seonghobae Aug 12, 2026
568ae15
test(forms): reject unwrapped collaborative reset updates
seonghobae Aug 12, 2026
dcc7aa8
fix(forms): contain native reset updates inside React act
seonghobae Aug 12, 2026
69dd988
test(ci): require warning-free editor actions workflow
seonghobae Aug 12, 2026
089f8fb
ci(diagnostics): fail closed on editor-action act warnings
seonghobae Aug 12, 2026
cd06daa
merge(diagnostics): restack editor actions on current UI
seonghobae Aug 13, 2026
70c79f0
test(diagnostics): satisfy editor action controller contract
seonghobae Aug 13, 2026
2423991
test(diagnostics): wrap dismissal focus updates in act
seonghobae Aug 13, 2026
a76919b
test(diagnostics): wrap focus-triggered updates in act
seonghobae Aug 13, 2026
84baeda
chore(diagnostics): restack editor actions on current UI authority
seonghobae Aug 16, 2026
f682041
fix(stack): synchronize editor actions without regressing exact-head …
seonghobae Aug 18, 2026
b315fc8
fix(stack): adopt diagnostics focus assurance from parent
seonghobae Aug 18, 2026
bad9d65
test(diagnostics): keep panel fixture aligned with controller
seonghobae Aug 21, 2026
fcef604
test(diagnostics): contain focus state updates in act
seonghobae Aug 21, 2026
d1d578e
test(security): keep hostile script fixture analyzer-safe
seonghobae Aug 22, 2026
d8749ec
test(security): avoid Semgrep ref false positive
seonghobae Aug 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/writing-diagnostics-editor-actions-tdd.yml
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
34 changes: 33 additions & 1 deletion src/components/CwlEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { applyEditorFormReset } from './editorFormReset.js';
import { editorHtmlToValue, editorValueToHtml } from './editorSerialization.js';
import { useEditorHandle } from './useEditorHandle.js';
import { useLatestRef } from './useLatestRef.js';
import { useWritingDiagnosticsController } from './useWritingDiagnosticsController.js';
import { WritingDiagnosticsPanel } from './WritingDiagnosticsPanel.js';

/**
* CwlEditor — a commercial-grade rich-text editor with interchangeable
Expand Down Expand Up @@ -62,6 +64,11 @@ export const CwlEditor = forwardRef<CwlEditorHandle, CwlEditorProps>(
ariaErrorMessage,
ariaInvalid,
ariaRequired,
writingDiagnostics,
onWritingDiagnosticAction,
onWritingDiagnosticsError,
writingDiagnosticsLabel,
printWritingDiagnostics,
},
ref,
) {
Expand Down Expand Up @@ -190,7 +197,14 @@ export const CwlEditor = forwardRef<CwlEditorHandle, CwlEditorProps>(
},
});

useEditorHandle(ref, editor, modeRef);
const writingDiagnosticsController = useWritingDiagnosticsController({
editor,
diagnostics: writingDiagnostics,
onAction: onWritingDiagnosticAction,
onError: onWritingDiagnosticsError,
});

useEditorHandle(ref, editor, modeRef, writingDiagnosticsController);

useEffect(() => {
editor?.setEditable(editable);
Expand Down Expand Up @@ -248,6 +262,24 @@ export const CwlEditor = forwardRef<CwlEditorHandle, CwlEditorProps>(
formFieldDisabled={formFieldDisabled}
formFieldInitialValue={selectedDocumentValue}
onFormReset={editor && observesFormReset ? handleFormReset : undefined}
writingDiagnosticsPanel={
writingDiagnostics === undefined ? undefined : (
<WritingDiagnosticsPanel
controller={writingDiagnosticsController}
label={writingDiagnosticsLabel ?? 'Writing guidance'}
onApplyDiagnostic={
editable
? (diagnosticId) => {
void writingDiagnosticsController.applyDiagnostic(
diagnosticId,
);
}
: undefined
}
printEnabled={printWritingDiagnostics}
/>
)
}
/>
);
},
Expand Down
146 changes: 146 additions & 0 deletions src/components/CwlEditor.writingDiagnosticApply.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
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('');
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();
});
});
Loading