rtl-analyzer 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -66
- package/dist/contextual-preview-bridge.js +16 -11
- package/dist/contextual-preview.js +3 -3
- package/dist/css-configured-proposal.js +98 -0
- package/dist/css-spacing.js +10 -9
- package/dist/dashboard-batch-review.js +37 -0
- package/dist/dashboard-client.js +28 -22
- package/dist/dashboard-contextual-preview.js +14 -6
- package/dist/dashboard-data.js +3 -3
- package/dist/dashboard-embedded-preview.js +8 -6
- package/dist/dashboard-html.js +3 -1
- package/dist/dashboard-operation-flow.js +47 -0
- package/dist/dashboard-review-navigation.js +19 -0
- package/dist/dashboard-review-workflow.js +99 -31
- package/dist/dashboard-themes.js +34 -0
- package/dist/original-preview-runtime.js +12 -2
- package/dist/page-navigation.js +17 -0
- package/dist/policy-validation.js +6 -3
- package/dist/preview-companion.js +37 -9
- package/dist/preview-configuration.js +35 -8
- package/dist/preview-runtime.js +13 -9
- package/dist/review-session.js +10 -0
- package/dist/review-workflow.js +297 -31
- package/dist/rules.js +13 -4
- package/dist/scoped-direction-evidence.js +117 -0
- package/dist/transformations.js +14 -0
- package/dist/validation.js +6 -2
- package/package.json +2 -2
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { chromium } from '@playwright/test';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { configuredMapping, loadPreviewConfiguration, routeUrl } from './preview-configuration.js';
|
|
4
|
+
import { contextualPreview } from './contextual-preview.js';
|
|
5
|
+
import { retryAcrossNavigation } from './page-navigation.js';
|
|
6
|
+
export function sameScopedDirectionEvidence(a, b) {
|
|
7
|
+
return !!a && a.version === 1 && JSON.stringify(a) === JSON.stringify(b);
|
|
8
|
+
}
|
|
9
|
+
export async function captureScopedDirectionEvidence(root, w, entries, prepare) {
|
|
10
|
+
if (!w.session || !entries.length)
|
|
11
|
+
throw Error('DIRECTION_EVIDENCE_CANDIDATE_REQUIRED');
|
|
12
|
+
const config = await loadPreviewConfiguration(root), records = [];
|
|
13
|
+
const browser = await chromium.launch({ headless: true });
|
|
14
|
+
try {
|
|
15
|
+
for (const entry of entries) {
|
|
16
|
+
const mapping = configuredMapping(entry.finding, config);
|
|
17
|
+
if (!mapping.configured || !mapping.routes.length || !entry.patch)
|
|
18
|
+
throw Error('DIRECTION_EVIDENCE_EXPLICIT_MAPPING_REQUIRED');
|
|
19
|
+
for (const route of mapping.routes) {
|
|
20
|
+
const app = config.applications[route.application];
|
|
21
|
+
if (!app)
|
|
22
|
+
throw Error('DIRECTION_EVIDENCE_APPLICATION_REQUIRED');
|
|
23
|
+
await prepare(route.application);
|
|
24
|
+
for (const mode of ['ltr', 'rtl']) {
|
|
25
|
+
const query = new URLSearchParams({ inputDigest: w.inputDigest, policyDigest: w.policyDigest, findingId: entry.finding.id, routeId: route.id, mode });
|
|
26
|
+
const info = await contextualPreview(root, query, w);
|
|
27
|
+
if (!info.original?.available || !info.candidate?.available || !('origin' in info.original) || !('origin' in info.candidate))
|
|
28
|
+
throw Error('DIRECTION_EVIDENCE_RUNTIME_IDENTITY_UNAVAILABLE');
|
|
29
|
+
const values = [];
|
|
30
|
+
for (const [role, descriptor] of [['original', info.original], ['candidate', info.candidate]]) {
|
|
31
|
+
const page = await browser.newPage({ viewport: { width: 1280, height: 800 }, locale: 'en-US', timezoneId: 'UTC' }), errors = [];
|
|
32
|
+
page.on('pageerror', e => errors.push(e.message));
|
|
33
|
+
try {
|
|
34
|
+
const expected = routeUrl(route, mode, descriptor.origin);
|
|
35
|
+
await page.goto(expected, { waitUntil: 'domcontentloaded', timeout: 20000 });
|
|
36
|
+
const state = await retryAcrossNavigation(async () => {
|
|
37
|
+
await page.locator(app.readySelector).first().waitFor({ state: 'visible', timeout: 10000 });
|
|
38
|
+
await page.waitForFunction(expectedMode => getComputedStyle(document.documentElement).direction === expectedMode, mode, { timeout: 10000 });
|
|
39
|
+
await page.locator(mapping.selector).first().waitFor({ state: 'visible', timeout: 10000 });
|
|
40
|
+
// Sample the rendered state after startup transitions, not at a nondeterministic animation frame.
|
|
41
|
+
await page.evaluate(() => new Promise(done => requestAnimationFrame(() => requestAnimationFrame(() => done()))));
|
|
42
|
+
await page.waitForFunction(selector => {
|
|
43
|
+
const targets = [...document.querySelectorAll(selector)];
|
|
44
|
+
const elements = new Set();
|
|
45
|
+
for (const target of targets)
|
|
46
|
+
for (let element = target; element; element = element.parentElement)
|
|
47
|
+
elements.add(element);
|
|
48
|
+
return targets.length > 0 && [...elements].every(element => element.getAnimations().every(animation => !(animation.pending || animation.playState === 'running') || !Number.isFinite(animation.effect?.getComputedTiming().endTime)));
|
|
49
|
+
}, mapping.selector, { timeout: 10000 });
|
|
50
|
+
return await page.evaluate(({ selector, expectedUrl, sourceSelector, path, icon }) => {
|
|
51
|
+
const nodes = [...document.querySelectorAll(selector)];
|
|
52
|
+
if (!nodes.length || nodes.length > 100)
|
|
53
|
+
throw Error('DIRECTION_EVIDENCE_TARGET_COUNT');
|
|
54
|
+
const url = new URL(location.href), expected = new URL(expectedUrl);
|
|
55
|
+
if (url.pathname !== expected.pathname || url.search !== expected.search || url.hash)
|
|
56
|
+
throw Error('DIRECTION_EVIDENCE_ROUTE_CHANGED');
|
|
57
|
+
if (sourceSelector) {
|
|
58
|
+
let matched = false;
|
|
59
|
+
for (const sheet of [...document.styleSheets]) {
|
|
60
|
+
try {
|
|
61
|
+
const owner = sheet.ownerNode, source = owner?.getAttribute('data-vite-dev-id')?.replaceAll('\\', '/');
|
|
62
|
+
const link = owner?.tagName === 'LINK' ? new URL(owner.href, location.href) : null;
|
|
63
|
+
if (!(source?.endsWith('/' + path) || link?.origin === location.origin && decodeURIComponent(link.pathname) === '/' + path))
|
|
64
|
+
continue;
|
|
65
|
+
const walk = (rules) => { for (const rule of rules) {
|
|
66
|
+
if ('selectorText' in rule) {
|
|
67
|
+
const r = rule;
|
|
68
|
+
if (r.selectorText.split(',').map(s => s.trim()).includes(sourceSelector) && nodes.some(n => n.matches(r.selectorText)))
|
|
69
|
+
matched = true;
|
|
70
|
+
}
|
|
71
|
+
else if ('cssRules' in rule)
|
|
72
|
+
walk(rule.cssRules);
|
|
73
|
+
} };
|
|
74
|
+
walk(sheet.cssRules);
|
|
75
|
+
}
|
|
76
|
+
catch { }
|
|
77
|
+
}
|
|
78
|
+
if (!matched)
|
|
79
|
+
throw Error('DIRECTION_EVIDENCE_SOURCE_TARGET_MISMATCH');
|
|
80
|
+
}
|
|
81
|
+
return { route: url.pathname + url.search, pageDirection: getComputedStyle(document.documentElement).direction, targets: nodes.map(node => { const el = node, style = getComputedStyle(el), r = el.getBoundingClientRect(), text = el.textContent || '', html = el.outerHTML; if (text.length > 2000 || html.length > 10000)
|
|
82
|
+
throw Error('DIRECTION_EVIDENCE_TARGET_TOO_LARGE'); if (r.width <= 0 || r.height <= 0 || style.display === 'none' || style.visibility === 'hidden')
|
|
83
|
+
throw Error('DIRECTION_EVIDENCE_HIDDEN_TARGET'); if (style.writingMode !== 'horizontal-tb')
|
|
84
|
+
throw Error('DIRECTION_EVIDENCE_WRITING_MODE_UNSUPPORTED'); if (icon && (el.matches(':dir(rtl)') !== (style.direction === 'rtl')))
|
|
85
|
+
throw Error('DIRECTION_EVIDENCE_CSS_HTML_DIRECTION_MISMATCH'); return { key: el.id || el.getAttribute('data-id') || el.getAttribute('data-testid') || null, text, html, direction: style.direction, writingMode: style.writingMode, computed: ['margin-left', 'margin-right', 'padding-left', 'padding-right', 'left', 'right', 'text-align', 'transform', 'scale', 'border-left-width', 'border-right-width', 'border-top-left-radius', 'border-top-right-radius', 'border-bottom-left-radius', 'border-bottom-right-radius', 'flex-direction', 'box-shadow'].map(p => style.getPropertyValue(p)), rect: [r.x, r.y, r.width, r.height], inputs: [...el.querySelectorAll('input,textarea,select')].map(x => ({ value: x.value, checked: x.checked })) }; }) };
|
|
86
|
+
}, { selector: mapping.selector, expectedUrl: expected, sourceSelector: mapping.sourceSelector || '', path: entry.finding.path, icon: entry.finding.ruleId === 'RTL.ICON.PROGRESSION' });
|
|
87
|
+
});
|
|
88
|
+
if (errors.length)
|
|
89
|
+
throw Error('DIRECTION_EVIDENCE_PAGE_ERROR');
|
|
90
|
+
values.push({ role, sourceHash: descriptor.sourceHash, projectRoot: descriptor.projectRoot, runtimeSessionId: descriptor.runtimeSessionId, state });
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
await page.close();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const rechecked = await contextualPreview(root, query, w);
|
|
97
|
+
if (!rechecked.original?.available || !rechecked.candidate?.available || !('sourceHash' in rechecked.original) || !('sourceHash' in rechecked.candidate) || rechecked.original.sourceHash !== values[0].sourceHash || rechecked.candidate.sourceHash !== values[1].sourceHash || rechecked.original.runtimeSessionId !== values[0].runtimeSessionId || rechecked.candidate.runtimeSessionId !== values[1].runtimeSessionId)
|
|
98
|
+
throw Error('DIRECTION_EVIDENCE_RUNTIME_IDENTITY_CHANGED');
|
|
99
|
+
const [before, after] = values;
|
|
100
|
+
if (before.state.targets.length !== after.state.targets.length || before.state.targets.some((t, i) => t.direction !== after.state.targets[i].direction || t.writingMode !== after.state.targets[i].writingMode || t.text !== after.state.targets[i].text || t.key !== after.state.targets[i].key))
|
|
101
|
+
throw Error('DIRECTION_EVIDENCE_TARGET_MISMATCH');
|
|
102
|
+
const keys = before.state.targets.map(t => t.key);
|
|
103
|
+
if (keys.length > 1 && (keys.some(k => !k) || new Set(keys).size !== keys.length))
|
|
104
|
+
throw Error('DIRECTION_EVIDENCE_AMBIGUOUS_TARGETS');
|
|
105
|
+
const hash = (value) => createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
|
106
|
+
// Do not persist application text, DOM or form values in the workflow record.
|
|
107
|
+
const bounded = values.map(v => ({ ...v, state: { ...v.state, targets: v.state.targets.map(t => ({ keyHash: hash(t.key), textHash: hash(t.text), htmlHash: hash(t.html), direction: t.direction, writingMode: t.writingMode, computed: t.computed, rect: t.rect, inputsHash: hash(t.inputs) })) } }));
|
|
108
|
+
records.push({ findingId: entry.finding.id, patchHash: hash(entry.patch), application: route.application, routeId: route.id, selector: mapping.selector, sourceSelector: mapping.sourceSelector || null, mode, viewport: { width: 1280, height: 800 }, values: bounded });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
await browser.close();
|
|
115
|
+
}
|
|
116
|
+
return { version: 1, inputDigest: w.inputDigest, policyDigest: w.policyDigest, configurationDigest: config.digest, sessionId: w.session.id, records };
|
|
117
|
+
}
|
package/dist/transformations.js
CHANGED
|
@@ -3,15 +3,29 @@ import { proposeCssSpacing, CSS_SPACING_TRANSFORMATION_ID } from './css-spacing.
|
|
|
3
3
|
import { proposeCssDirectional, CSS_DIRECTIONAL_TRANSFORMATION_ID } from './css-directional.js';
|
|
4
4
|
import { proposeReactInline, REACT_INLINE_TRANSFORMATION_ID } from './react-inline.js';
|
|
5
5
|
import { proposeCssIcon, CSS_ICON_TRANSFORMATION_ID } from './css-icons.js';
|
|
6
|
+
import { CSS_CONFIGURED_TRANSFORMATION_ID, proposeConfiguredCss } from './css-configured-proposal.js';
|
|
6
7
|
/** Shared dispatch for code review, eligibility and both persisted workflows. */
|
|
7
8
|
export const transformations = [
|
|
9
|
+
{ key: 'css:explicit-intent', id: CSS_CONFIGURED_TRANSFORMATION_ID, ruleId: 'RTL.CSS.PHYSICAL', matches: (f) => !!f.cssProposal, propose: proposeConfiguredCss },
|
|
8
10
|
{ key: 'RTL.BIDI.ISOLATION:direct-text', id: BIDI_TRANSFORMATION_ID, ruleId: 'RTL.BIDI.ISOLATION', matches: (f) => f.ruleId === 'RTL.BIDI.ISOLATION', propose: proposeBidiIsolation },
|
|
9
11
|
{ key: 'RTL.CSS.PHYSICAL:spacing', id: CSS_SPACING_TRANSFORMATION_ID, ruleId: 'RTL.CSS.PHYSICAL', matches: (f) => f.ruleId === 'RTL.CSS.PHYSICAL' && f.sourceMechanism === 'css' && /^(margin|padding)-/.test(f.original), propose: proposeCssSpacing },
|
|
10
12
|
{ key: 'RTL.CSS.PHYSICAL:logical', id: CSS_DIRECTIONAL_TRANSFORMATION_ID, ruleId: 'RTL.CSS.PHYSICAL', matches: (f) => ['RTL.CSS.PHYSICAL', 'RTL.GEOMETRY.EDGE'].includes(f.ruleId) && f.sourceMechanism === 'css', propose: proposeCssDirectional },
|
|
11
13
|
{ key: 'RTL.CSS.PHYSICAL:react-inline', id: REACT_INLINE_TRANSFORMATION_ID, ruleId: 'RTL.CSS.PHYSICAL', matches: (f) => ['RTL.CSS.PHYSICAL', 'RTL.GEOMETRY.EDGE'].includes(f.ruleId) && f.sourceMechanism === 'react-inline', propose: proposeReactInline },
|
|
12
14
|
{ key: 'RTL.ICON.PROGRESSION:css-opt-in', id: CSS_ICON_TRANSFORMATION_ID, ruleId: 'RTL.ICON.PROGRESSION', matches: (f) => f.ruleId === 'RTL.ICON.PROGRESSION', propose: proposeCssIcon },
|
|
13
15
|
];
|
|
16
|
+
export function sameSupportedPatch(a, b) { return a.findingId === b.findingId && a.path === b.path && a.startOffset === b.startOffset && a.endOffset === b.endOffset && a.expectedSha256 === b.expectedSha256 && a.replacement === b.replacement; }
|
|
14
17
|
export function transformationFor(finding) { return transformations.find(t => t.matches(finding)); }
|
|
18
|
+
/** Runtime direction cannot establish semantic intent; accepted changes still need full validation. */
|
|
19
|
+
export function directionRequirement(finding) {
|
|
20
|
+
const strategy = transformationFor(finding);
|
|
21
|
+
if (!strategy)
|
|
22
|
+
return 'unknown';
|
|
23
|
+
if (strategy.id === BIDI_TRANSFORMATION_ID)
|
|
24
|
+
return 'independent';
|
|
25
|
+
if ([CSS_CONFIGURED_TRANSFORMATION_ID, CSS_SPACING_TRANSFORMATION_ID, CSS_DIRECTIONAL_TRANSFORMATION_ID, REACT_INLINE_TRANSFORMATION_ID, CSS_ICON_TRANSFORMATION_ID].some(id => id === strategy.id))
|
|
26
|
+
return 'dependent';
|
|
27
|
+
return 'unknown';
|
|
28
|
+
}
|
|
15
29
|
export function proposeTransformation(finding, source) {
|
|
16
30
|
const strategy = transformationFor(finding);
|
|
17
31
|
if (!strategy)
|
package/dist/validation.js
CHANGED
|
@@ -8,6 +8,7 @@ import { promisify } from 'node:util';
|
|
|
8
8
|
import { chromium } from '@playwright/test';
|
|
9
9
|
import { REVIEW_SOURCE, validateReviewPath } from './review-session.js';
|
|
10
10
|
import { analyzeBidiIsolation } from './codemod.js';
|
|
11
|
+
import { sameSupportedPatch } from './transformations.js';
|
|
11
12
|
const run = promisify(execFile);
|
|
12
13
|
const sha = (x) => createHash('sha256').update(x).digest('hex');
|
|
13
14
|
const active = new Set();
|
|
@@ -20,7 +21,8 @@ catch (error) {
|
|
|
20
21
|
stdout = expected.stdout ?? '';
|
|
21
22
|
if (!stdout)
|
|
22
23
|
throw new Error('SCANNER_EXECUTION_FAILED');
|
|
23
|
-
} const report = JSON.parse(stdout);
|
|
24
|
+
} const report = JSON.parse(stdout); if (!report.complete)
|
|
25
|
+
throw new Error('INCOMPLETE_SCAN_REQUIRES_MANUAL_RESOLUTION'); const ids = (report.findings ?? []).map(x => x.id); return { findingPresent: ids.includes(findingId), resultDigest: sha(stdout) }; }
|
|
24
26
|
export async function validateCandidate(session, finding, patch, startRuntime) { if (active.has(session.id))
|
|
25
27
|
throw new Error('VALIDATION_ALREADY_RUNNING'); active.add(session.id); const jobId = randomUUID(); const startedAt = new Date().toISOString(); try {
|
|
26
28
|
if (patch.path !== REVIEW_SOURCE || finding.id !== patch.findingId)
|
|
@@ -33,7 +35,9 @@ export async function validateCandidate(session, finding, patch, startRuntime) {
|
|
|
33
35
|
throw new Error('STALE_ORIGINAL_SOURCE');
|
|
34
36
|
if (sha(candidate) !== session.candidateSha256)
|
|
35
37
|
throw new Error('STALE_CANDIDATE_SOURCE');
|
|
36
|
-
analyzeBidiIsolation(finding, original);
|
|
38
|
+
const proposal = analyzeBidiIsolation(finding, original);
|
|
39
|
+
if (!sameSupportedPatch(proposal.patch, patch) || candidate !== original.slice(0, patch.startOffset) + patch.replacement + original.slice(patch.endOffset))
|
|
40
|
+
throw new Error('UNSUPPORTED_CANDIDATE_PATCH');
|
|
37
41
|
const runtime = await startRuntime(session);
|
|
38
42
|
if (runtime.runtime?.status !== 'healthy')
|
|
39
43
|
throw new Error('CANDIDATE_RUNTIME_UNAVAILABLE');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rtl-analyzer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "RTL analysis with isolated review, accepted-only Apply and receipt-backed rollback",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"rtlAnalyzerImplementation": {
|
|
37
37
|
"repository": "https://github.com/FoushWare/enterprise-rtl-migration-lab",
|
|
38
|
-
"commit": "
|
|
38
|
+
"commit": "aa8873ebaee0f0c3a1448462eaf83e21a90ab89c"
|
|
39
39
|
},
|
|
40
40
|
"license": "MIT"
|
|
41
41
|
}
|