rtl-analyzer 0.2.0 → 0.3.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 -52
- package/dist/cli.js +18 -1
- package/dist/codemod.js +50 -12
- package/dist/companion-security.js +2 -0
- package/dist/contextual-preview-bridge.js +113 -0
- package/dist/contextual-preview.js +74 -0
- package/dist/controlled-apply.js +222 -0
- package/dist/css-directional.js +60 -0
- package/dist/css-icons.js +51 -0
- package/dist/css-spacing.js +64 -0
- package/dist/dashboard-client.js +57 -40
- package/dist/dashboard-contextual-preview.js +119 -0
- package/dist/dashboard-data.js +1 -1
- package/dist/dashboard-embedded-preview.js +200 -0
- package/dist/dashboard-html.js +11 -10
- package/dist/dashboard-review-details.js +175 -0
- package/dist/dashboard-review-workflow.js +151 -0
- package/dist/directional-properties.js +53 -0
- package/dist/discovery.js +1 -2
- package/dist/eligibility.js +8 -8
- package/dist/evidence-store.js +110 -0
- package/dist/example-preview-mappings.js +98 -0
- package/dist/manual-change-store.js +27 -0
- package/dist/migration-lifecycle.js +19 -0
- package/dist/original-preview-runtime.js +68 -0
- package/dist/output-path.js +65 -0
- package/dist/policy-validation.js +1 -1
- package/dist/preview-cli.js +22 -0
- package/dist/preview-companion.js +621 -0
- package/dist/preview-configuration.js +144 -0
- package/dist/preview-runtime.js +98 -0
- package/dist/project-configuration.js +48 -0
- package/dist/project-root.js +12 -0
- package/dist/react-inline.js +65 -0
- package/dist/report-publisher.js +4 -7
- package/dist/review-approval.js +9 -0
- package/dist/review-session.js +199 -54
- package/dist/review-store.js +175 -0
- package/dist/review-workflow.js +554 -0
- package/dist/rules.js +14 -13
- package/dist/runtime-process.js +35 -0
- package/dist/scan-history.js +35 -0
- package/dist/scan-manifest-store.js +26 -0
- package/dist/scan.js +55 -4
- package/dist/serialization.js +1 -0
- package/dist/source-context.js +93 -0
- package/dist/source-snippets.js +3 -3
- package/dist/standalone-cli.js +14 -1
- package/dist/tailwind.js +3 -1
- package/dist/transformations.js +20 -0
- package/dist/validation.js +71 -0
- package/dist/workflow-validation.js +46 -0
- package/package.json +17 -8
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { access, mkdir, readFile, rename, lstat, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { constants } from 'node:fs';
|
|
4
|
+
import { homedir, tmpdir } from 'node:os';
|
|
5
|
+
import { dirname, isAbsolute, join, parse, relative, resolve, sep } from 'node:path';
|
|
6
|
+
import { validateReviewIdentity } from './review-session.js';
|
|
7
|
+
export const EVIDENCE_STORE_VERSION = 1;
|
|
8
|
+
export const DEFAULT_EVIDENCE_STORE_PATH = process.env.RTL_EVIDENCE_STORE_PATH || join(homedir(), '.rtl-migration-analyzer', 'review-evidence-v1.json');
|
|
9
|
+
const inside = (root, target) => { const value = relative(root, target); return value === '' || (value !== '..' && !value.startsWith(`..${sep}`) && !isAbsolute(value)); };
|
|
10
|
+
async function rejectSymlinkPath(path) { const absolute = resolve(path); const root = parse(absolute).root; let cursor = root; for (const part of absolute.slice(root.length).split(sep).filter(Boolean)) {
|
|
11
|
+
cursor = join(cursor, part);
|
|
12
|
+
try {
|
|
13
|
+
if ((await lstat(cursor)).isSymbolicLink() && !inside(cursor, resolve(homedir())) && !inside(cursor, resolve(tmpdir())))
|
|
14
|
+
throw new Error('EVIDENCE_STORE_SYMLINK');
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
if (error.code !== 'ENOENT')
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
} }
|
|
21
|
+
function validateStorePath(path) { const absolute = resolve(path); if (!isAbsolute(absolute) || !absolute.endsWith(`${sep}review-evidence-v1.json`))
|
|
22
|
+
throw new Error('INVALID_EVIDENCE_STORE_PATH'); return absolute; }
|
|
23
|
+
const digest = (value) => createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
|
24
|
+
const immutablePayload = (snapshot) => { const { integritySha256: _ignored, ...payload } = snapshot; return payload; };
|
|
25
|
+
export function evidenceIntegrity(snapshot) { return digest(immutablePayload(snapshot)); }
|
|
26
|
+
export function validateEvidenceSnapshot(snapshot) {
|
|
27
|
+
if (!snapshot || typeof snapshot !== 'object')
|
|
28
|
+
throw new Error('INVALID_EVIDENCE_SNAPSHOT');
|
|
29
|
+
const value = snapshot;
|
|
30
|
+
validateReviewIdentity(value);
|
|
31
|
+
if (!value.snapshotId || typeof value.snapshotId !== 'string' || value.snapshotId.length > 100)
|
|
32
|
+
throw new Error('INVALID_EVIDENCE_SNAPSHOT_ID');
|
|
33
|
+
if (!value.candidatePatchIdentity || value.candidatePatchIdentity.path !== 'apps/invoicing/src/components/InvoiceTable.tsx')
|
|
34
|
+
throw new Error('INVALID_EVIDENCE_PATCH_IDENTITY');
|
|
35
|
+
if (value.patch && (value.patch.path !== value.sourcePath || value.patch.findingId !== value.findingId || !Number.isInteger(value.patch.startOffset) || !Number.isInteger(value.patch.endOffset) || value.patch.endOffset < value.patch.startOffset || value.patch.expectedSha256 !== value.candidatePatchIdentity.expectedSha256 || createHash('sha256').update(value.patch.replacement).digest('hex') !== value.candidatePatchIdentity.replacementSha256))
|
|
36
|
+
throw new Error('INVALID_EVIDENCE_PATCH');
|
|
37
|
+
if (![value.candidatePatchIdentity.expectedSha256, value.candidatePatchIdentity.replacementSha256, value.originalSourceSha256, value.candidateSourceSha256].every(x => typeof x === 'string' && /^[a-f0-9]{64}$/.test(x)))
|
|
38
|
+
throw new Error('INVALID_EVIDENCE_DIGEST');
|
|
39
|
+
if (typeof value.codeDiff !== 'string' || value.codeDiff.length > 100_000 || !value.scannerBefore || !value.scannerAfter || !Array.isArray(value.browserDomValidation) || !Array.isArray(value.screenshotReferences) || !Number.isFinite(Date.parse(value.timestamp)) || !['Verified Correct', 'Ready for Review', 'Approved', 'Rejected'].includes(value.decision))
|
|
40
|
+
throw new Error('INVALID_EVIDENCE_SNAPSHOT');
|
|
41
|
+
for (const ref of [...value.browserDomValidation, ...value.screenshotReferences])
|
|
42
|
+
if (typeof ref !== 'string' || ref.length > 1000 || isAbsolute(ref) || ref.split(/[\\/]/).includes('..'))
|
|
43
|
+
throw new Error('INVALID_EVIDENCE_REFERENCE');
|
|
44
|
+
if (value.screenshotDigests !== undefined && (!Array.isArray(value.screenshotDigests) || value.screenshotDigests.length !== value.screenshotReferences.length || value.screenshotDigests.some(x => typeof x !== 'string' || !/^[a-f0-9]{64}$/.test(x))))
|
|
45
|
+
throw new Error('INVALID_SCREENSHOT_DIGESTS');
|
|
46
|
+
if (value.supersedesSnapshotId !== undefined && (typeof value.supersedesSnapshotId !== 'string' || value.supersedesSnapshotId.length > 100))
|
|
47
|
+
throw new Error('INVALID_SUPERSEDES_SNAPSHOT_ID');
|
|
48
|
+
if (value.integritySha256 !== evidenceIntegrity(value))
|
|
49
|
+
throw new Error('EVIDENCE_INTEGRITY_MISMATCH');
|
|
50
|
+
return { ...value, browserDomValidation: [...value.browserDomValidation], screenshotReferences: [...value.screenshotReferences] };
|
|
51
|
+
}
|
|
52
|
+
export class EvidenceSnapshotStore {
|
|
53
|
+
path;
|
|
54
|
+
snapshots = new Map();
|
|
55
|
+
loaded = false;
|
|
56
|
+
error = null;
|
|
57
|
+
constructor(path = DEFAULT_EVIDENCE_STORE_PATH) { this.path = validateStorePath(path); }
|
|
58
|
+
get loadError() { return this.error; }
|
|
59
|
+
async load() { await rejectSymlinkPath(dirname(this.path)); try {
|
|
60
|
+
const raw = JSON.parse(await readFile(this.path, 'utf8'));
|
|
61
|
+
if (raw.formatVersion !== EVIDENCE_STORE_VERSION || !Array.isArray(raw.snapshots))
|
|
62
|
+
throw new Error('INCOMPATIBLE_EVIDENCE_STORE');
|
|
63
|
+
const next = new Map();
|
|
64
|
+
for (const item of raw.snapshots) {
|
|
65
|
+
const snapshot = validateEvidenceSnapshot(item);
|
|
66
|
+
if (next.has(snapshot.snapshotId))
|
|
67
|
+
throw new Error('DUPLICATE_EVIDENCE_SNAPSHOT');
|
|
68
|
+
next.set(snapshot.snapshotId, snapshot);
|
|
69
|
+
}
|
|
70
|
+
this.snapshots = next;
|
|
71
|
+
this.error = null;
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (error.code === 'ENOENT') {
|
|
75
|
+
this.snapshots.clear();
|
|
76
|
+
this.error = null;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
this.snapshots.clear();
|
|
80
|
+
this.error = error instanceof Error ? error.message : 'EVIDENCE_STORE_LOAD_FAILED';
|
|
81
|
+
}
|
|
82
|
+
} this.loaded = true; }
|
|
83
|
+
list(identity) { validateReviewIdentity(identity); return [...this.snapshots.values()].filter(x => x.findingId === identity.findingId && x.sourcePath === identity.sourcePath && x.inputDigest === identity.inputDigest && x.policyDigest === identity.policyDigest && x.schemaVersion === identity.schemaVersion); }
|
|
84
|
+
async append(input) { if (!this.loaded || this.error)
|
|
85
|
+
throw new Error(`EVIDENCE_STORE_UNAVAILABLE${this.error ? `:${this.error}` : ''}`); const snapshot = { ...input, snapshotId: input.snapshotId ?? randomUUID(), integritySha256: '' }; const complete = { ...snapshot, integritySha256: evidenceIntegrity(snapshot) }; validateEvidenceSnapshot(complete); if (this.snapshots.has(complete.snapshotId))
|
|
86
|
+
throw new Error('EVIDENCE_SNAPSHOT_IMMUTABLE'); this.snapshots.set(complete.snapshotId, complete); try {
|
|
87
|
+
await this.persist();
|
|
88
|
+
return complete;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
this.snapshots.delete(complete.snapshotId);
|
|
92
|
+
throw error;
|
|
93
|
+
} }
|
|
94
|
+
async appendApproval(snapshotId) { const source = this.snapshots.get(snapshotId); if (!source)
|
|
95
|
+
throw new Error('EVIDENCE_SNAPSHOT_NOT_FOUND'); if (source.decision === 'Approved')
|
|
96
|
+
return source; if (source.decision !== 'Ready for Review')
|
|
97
|
+
throw new Error('EVIDENCE_NOT_APPROVABLE'); const { snapshotId: _old, integritySha256: _integrity, ...payload } = source; return this.append({ ...payload, decision: 'Approved', supersedesSnapshotId: source.snapshotId }); }
|
|
98
|
+
async persist() { const parent = dirname(this.path); await rejectSymlinkPath(parent); await mkdir(parent, { recursive: true, mode: 0o700 }); const temporary = join(parent, `.review-evidence-v1.${process.pid}.${Date.now()}.tmp`); try {
|
|
99
|
+
await writeFile(temporary, `${JSON.stringify({ formatVersion: EVIDENCE_STORE_VERSION, snapshots: [...this.snapshots.values()] }, null, 2)}\n`, { encoding: 'utf8', mode: 0o600, flag: 'wx' });
|
|
100
|
+
await rename(temporary, this.path);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
try {
|
|
104
|
+
await access(temporary, constants.F_OK);
|
|
105
|
+
await rename(temporary, `${temporary}.failed`);
|
|
106
|
+
}
|
|
107
|
+
catch { /* preserve failure */ }
|
|
108
|
+
throw error;
|
|
109
|
+
} }
|
|
110
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
const route = (application, path, prepare) => ({ id: application + ':' + path + (prepare ? ':' + prepare : ''), application, path, label: application + ' · ' + path + (prepare ? ' · ' + prepare : ''), ...(prepare ? { prepare } : {}) });
|
|
2
|
+
const invoice = route('invoicing', '/invoices'), overview = route('invoicing', '/'), orders = route('procurement', '/');
|
|
3
|
+
const detail = route('invoicing', '/invoices/INV-2026-1048'), orderDetail = route('procurement', '/orders/PO-2026-402');
|
|
4
|
+
const customers = route('invoicing', '/customers'), customerDialog = route('invoicing', '/customers', 'customer-dialog');
|
|
5
|
+
const create = route('invoicing', '/invoices/new'), confirm = route('invoicing', '/invoices/new', 'invoice-confirm');
|
|
6
|
+
const shared = [invoice, orders];
|
|
7
|
+
export function exampleContextMapping(f) {
|
|
8
|
+
const evidence = [f.path + ' · ' + f.context, 'Verified example route/component imports; selectors refer to the existing rendered markup.'];
|
|
9
|
+
const target = (label, selector, routes, extra = {}) => ({ kind: 'targets', label, selector, routes, evidence, ...extra });
|
|
10
|
+
if (f.ruleId === 'RTL.DOCUMENT.INITIAL')
|
|
11
|
+
return { kind: 'document', label: 'Initial HTML direction · whole document; runtime direction is reported separately', selector: 'html', routes: [f.path.includes('procurement') ? orders : invoice], evidence };
|
|
12
|
+
if (f.path.endsWith('/InvoiceTable.tsx')) {
|
|
13
|
+
if (f.ruleId === 'RTL.ICON.PROGRESSION')
|
|
14
|
+
return target('Invoice row navigation icon', f.context.endsWith('/ArrowBack') ? 'tbody [data-testid="ArrowBackIcon"]' : 'tbody [data-testid="ArrowForwardIcon"]', [invoice, overview], { preferredMode: f.context.endsWith('/ArrowBack') ? 'rtl' : 'ltr' });
|
|
15
|
+
if (f.original === '{i.id}')
|
|
16
|
+
return target('Invoice identifier · containing link', f.id === 'RTL.BIDI.ISOLATION:1c1265d83508cd495927ae75' ? '.review-extra-id' : '.invoice-link', [invoice, overview]);
|
|
17
|
+
if (f.original === '{c.name}')
|
|
18
|
+
return target('Invoice customer name', '.customer-cell strong', [invoice, overview]);
|
|
19
|
+
if (f.original === '{c.email}')
|
|
20
|
+
return target('Invoice customer email', '.customer-cell small', [invoice, overview]);
|
|
21
|
+
if (f.original.includes('money('))
|
|
22
|
+
return target('Invoice amount', '.amount', [invoice, overview]);
|
|
23
|
+
}
|
|
24
|
+
// Only the existing workflow regression fixture imports these two named spans.
|
|
25
|
+
if (f.path.endsWith('/ReviewTokens.tsx'))
|
|
26
|
+
return target('Regression fixture identifier span', f.id === 'RTL.BIDI.ISOLATION:9abfb96bb050e95f51ed573b' ? '.token-one' : '.token-two', [invoice], { limitation: 'Workflow fixture only; not present in the 47-finding checkout.' });
|
|
27
|
+
if (f.path.endsWith('/CreateInvoice.tsx')) {
|
|
28
|
+
if (f.original === '{c.name}')
|
|
29
|
+
return target('Customer menu option', '[role="listbox"] [role="option"]', [route('invoicing', '/invoices/new', 'customer-menu')]);
|
|
30
|
+
if (f.original.includes('customers.find'))
|
|
31
|
+
return target('Confirmation customer name', '.MuiDialogContent-root p:first-child strong:first-of-type', [confirm]);
|
|
32
|
+
if (f.original.includes('money('))
|
|
33
|
+
return target('Invoice total', f.id === 'RTL.BIDI.ISOLATION:f452c219f31ee6379007a4e9' ? '.MuiDialogContent-root p:first-child strong:last-of-type' : '.form-total strong', [f.id === 'RTL.BIDI.ISOLATION:f452c219f31ee6379007a4e9' ? confirm : create]);
|
|
34
|
+
}
|
|
35
|
+
if (f.path.endsWith('/Customers.tsx')) {
|
|
36
|
+
if (f.original === '{c.name}')
|
|
37
|
+
return target('Customer card name', '.customer-card h3', [customers]);
|
|
38
|
+
if (f.original === '{c.address}')
|
|
39
|
+
return target('Customer dialog address', '.MuiDialogContent-root p.hint', [customerDialog]);
|
|
40
|
+
if (f.original === '{c.email}')
|
|
41
|
+
return target('Customer email', f.id === 'RTL.BIDI.ISOLATION:75fcb34b4ca84b10731b3272' ? '.MuiDialogContent-root p:nth-of-type(2)' : '.customer-card p:first-of-type', [f.id === 'RTL.BIDI.ISOLATION:75fcb34b4ca84b10731b3272' ? customerDialog : customers]);
|
|
42
|
+
}
|
|
43
|
+
if (f.path.endsWith('/Dashboard.tsx')) {
|
|
44
|
+
if (f.ruleId === 'RTL.CHART.LABEL_FLOW')
|
|
45
|
+
return target('Revenue chart and its real labels', '.chart-wrap svg', [overview]);
|
|
46
|
+
if (f.ruleId === 'RTL.ICON.LITERAL')
|
|
47
|
+
return target('View all invoices link', '.section-title a', [overview]);
|
|
48
|
+
if (f.ruleId === 'RTL.CSS.PHYSICAL')
|
|
49
|
+
return target('Payment breakdown percentage', '.breakdown-row strong > span', [overview], { css: { property: 'margin-left', value: '10px', inline: true } });
|
|
50
|
+
}
|
|
51
|
+
if (f.path.endsWith('/InvoiceDetails.tsx')) {
|
|
52
|
+
if (f.original === '{c.name}')
|
|
53
|
+
return target('Bill-to customer name', '.detail-grid h3', [detail]);
|
|
54
|
+
if (f.original === '{c.address}' || f.original === '{c.email}')
|
|
55
|
+
return target('Bill-to address/email · containing paragraph', '.detail-grid p.hint', [detail], { limitation: 'Both text expressions share one paragraph; the containing rendered element is highlighted.' });
|
|
56
|
+
if (f.original.includes('money('))
|
|
57
|
+
return target('Invoice total due', '.form-total strong', [detail]);
|
|
58
|
+
}
|
|
59
|
+
if (f.path.endsWith('/Invoices.tsx')) {
|
|
60
|
+
if (f.ruleId === 'RTL.RUNTIME.PAGINATION')
|
|
61
|
+
return target('Invoice pagination', '.pagination nav', [invoice]);
|
|
62
|
+
if (f.ruleId === 'RTL.CSS.PHYSICAL')
|
|
63
|
+
return target('Invoice count alignment', '.toolbar > .hint', [invoice], { css: { property: 'margin-left', value: 'auto', inline: true } });
|
|
64
|
+
}
|
|
65
|
+
if (f.path === 'apps/procurement/src/App.tsx') {
|
|
66
|
+
if (f.context === 'Orders')
|
|
67
|
+
return target(f.original === '{o.id}' ? 'Purchase order identifier' : 'Purchase order amount', f.original === '{o.id}' ? '.invoice-link' : '.amount', [orders]);
|
|
68
|
+
if (f.context === 'Details')
|
|
69
|
+
return target(f.original === '{order.id}' ? 'Purchase order heading' : 'Purchase order total', f.original === '{order.id}' ? '.page-heading h1' : '.form-total strong', [orderDetail]);
|
|
70
|
+
}
|
|
71
|
+
if (f.path === 'libs/design-system/src/index.tsx') {
|
|
72
|
+
if (f.ruleId === 'RTL.FORM.DIRECTION')
|
|
73
|
+
return target('Shared FormField instances', '.MuiFormControl-root', [invoice, orders, create, customers]);
|
|
74
|
+
if (f.ruleId === 'RTL.GEOMETRY.EDGE')
|
|
75
|
+
return target('Shared Modal close control', '.MuiDialogTitle-root button', [customerDialog, confirm], { css: { property: 'right', value: '12px', inline: true } });
|
|
76
|
+
if (f.ruleId === 'RTL.TABLE.ALIGNMENT')
|
|
77
|
+
return target('Shared table ' + (f.id === 'RTL.TABLE.ALIGNMENT:9e76dea095ca377d5e42c677' ? 'header' : 'body') + ' cells', f.id === 'RTL.TABLE.ALIGNMENT:9e76dea095ca377d5e42c677' ? 'thead th' : 'tbody td', [invoice, orders, overview, detail, orderDetail]);
|
|
78
|
+
if (f.ruleId === 'RTL.GEOMETRY.ORDER')
|
|
79
|
+
return target('Shared responsive sidebar · actual off-canvas geometry', 'aside', shared, { preferredViewport: 1, preferredMode: f.original.includes('translateX(100%)') ? 'rtl' : 'ltr', css: { property: 'transform', value: f.original.includes('translateX(100%)') ? 'translateX(100%)' : 'translateX(-100%)', media: '(max-width: 900px)', rtlOnly: f.original.includes('translateX(100%)') }, limitation: 'A collapsed sidebar can be intentionally outside the viewport. Target geometry and active/overridden CSS are reported; use Reveal navigation to inspect the open component.' });
|
|
80
|
+
if (f.ruleId === 'RTL.BRAND.ISLAND')
|
|
81
|
+
return target('Shared brand link', 'aside .brand', shared.map(r => route(r.application, r.path, 'sidebar')));
|
|
82
|
+
if (f.ruleId === 'RTL.ICON.PROGRESSION' || f.ruleId === 'RTL.CSS.PHYSICAL')
|
|
83
|
+
return target('Shared application-switch arrow', '.app-link [data-testid="ArrowForwardIcon"]', shared.map(r => route(r.application, r.path, 'sidebar')), f.ruleId === 'RTL.CSS.PHYSICAL' ? { css: { property: 'margin-left', value: 'auto', inline: true } } : {});
|
|
84
|
+
}
|
|
85
|
+
if (f.path === 'libs/design-system/src/runtime.tsx' && f.ruleId === 'RTL.DOCUMENT.RUNTIME')
|
|
86
|
+
return { kind: 'document', label: 'Shared Provider · document direction/lang and theme context', selector: 'html', routes: shared, evidence };
|
|
87
|
+
if (f.path === 'libs/design-system/src/styles.css') {
|
|
88
|
+
const selector = f.context.replace(/^stylesheet\//, '');
|
|
89
|
+
const declaration = f.original.match(/^([\w-]+):\s*(.*?);?$/);
|
|
90
|
+
if (declaration) {
|
|
91
|
+
const routes = selector === '.chart-labels' || selector === '.kpi-note b' ? [overview] : selector.startsWith('.header') ? shared : shared.map(r => route(r.application, r.path, 'sidebar'));
|
|
92
|
+
return target('Shared stylesheet · ' + selector, selector, routes, { css: { selector, property: declaration[1], value: declaration[2].replace(/;$/, '') } });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (f.path === 'libs/shared/src/index.ts' && f.ruleId === 'RTL.RUNTIME.LOCALE')
|
|
96
|
+
return target('Shared money formatter output · locale semantics require review', '.amount', [invoice, orders], { limitation: 'These consumers call the real money() formatter. A target match does not establish a locale defect or authorize changing currency data.' });
|
|
97
|
+
return { kind: 'unresolved', label: 'Unresolved example mapping', selector: '', routes: [], evidence: [f.path + ' · ' + f.context, 'No configured source-to-route binding was found.'], limitation: 'No verified route/target binding for this source expression. Add a verified example mapping; do not substitute an unrelated page.' };
|
|
98
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
import { validateReviewIdentity } from './review-session.js';
|
|
6
|
+
export const DEFAULT_MANUAL_CHANGE_STORE_PATH = process.env.RTL_MANUAL_CHANGE_STORE_PATH || join(homedir(), '.rtl-migration-analyzer', 'manual-changes-v1.json');
|
|
7
|
+
const digest = (value) => createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
|
8
|
+
export class ManualChangeStore {
|
|
9
|
+
path;
|
|
10
|
+
changes = [];
|
|
11
|
+
loaded = false;
|
|
12
|
+
constructor(path = DEFAULT_MANUAL_CHANGE_STORE_PATH) {
|
|
13
|
+
this.path = path;
|
|
14
|
+
}
|
|
15
|
+
async load() { try {
|
|
16
|
+
this.changes = JSON.parse(await readFile(this.path, 'utf8'));
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
if (e.code !== 'ENOENT')
|
|
20
|
+
throw new Error('MANUAL_CHANGE_STORE_UNAVAILABLE');
|
|
21
|
+
this.changes = [];
|
|
22
|
+
} this.loaded = true; }
|
|
23
|
+
list(identity) { validateReviewIdentity(identity); return this.changes.filter(x => x.findingId === identity.findingId && x.sourcePath === identity.sourcePath && x.inputDigest === identity.inputDigest && x.policyDigest === identity.policyDigest); }
|
|
24
|
+
async append(input) { if (!this.loaded)
|
|
25
|
+
throw new Error('MANUAL_CHANGE_STORE_NOT_LOADED'); validateReviewIdentity(input); if (!/^[a-f0-9]{64}$/.test(input.beforeSourceSha256) || !/^[a-f0-9]{64}$/.test(input.afterSourceSha256) || input.beforeSourceSha256 === input.afterSourceSha256)
|
|
26
|
+
throw new Error('MANUAL_CHANGE_SOURCE_NOT_CHANGED'); const value = { ...input, changeId: randomUUID(), timestamp: new Date().toISOString(), sourceChanged: true, integritySha256: '' }; const item = { ...value, integritySha256: digest(value) }; this.changes.push(item); await mkdir(dirname(this.path), { recursive: true, mode: 0o700 }); const tmp = `${this.path}.${process.pid}.tmp`; await writeFile(tmp, `${JSON.stringify(this.changes, null, 2)}\n`, { mode: 0o600, flag: 'wx' }); await rename(tmp, this.path); return item; }
|
|
27
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function projectLifecycle(input) {
|
|
2
|
+
const latestAudit = input.audit.slice().sort((a, b) => Date.parse(b.timestamp) - Date.parse(a.timestamp))[0];
|
|
3
|
+
if (latestAudit?.type === 'ROLLED_BACK')
|
|
4
|
+
return 'Rolled Back';
|
|
5
|
+
if (latestAudit?.type === 'APPLY_FAILED' || latestAudit?.type === 'ROLLBACK_FAILED')
|
|
6
|
+
return 'Failed';
|
|
7
|
+
const approvedEvidence = input.evidence.find(e => (e.decision === 'Approved' || e.decision === 'Ready for Review') && !e.scannerAfter.findingPresent);
|
|
8
|
+
if (latestAudit?.type === 'APPLIED')
|
|
9
|
+
return input.currentSourceSha256 && latestAudit.resultingSha256 === input.currentSourceSha256 ? 'Applied' : 'Stale';
|
|
10
|
+
if (approvedEvidence && input.currentSourceSha256 && input.currentSourceSha256 !== approvedEvidence.originalSourceSha256 && input.currentSourceSha256 !== approvedEvidence.candidateSourceSha256)
|
|
11
|
+
return 'Stale';
|
|
12
|
+
if (approvedEvidence && input.review?.status === 'Approved')
|
|
13
|
+
return 'Validated';
|
|
14
|
+
if (input.review?.status === 'Validation Failed')
|
|
15
|
+
return 'Failed';
|
|
16
|
+
if (input.review?.status === 'Candidate Proposed' || input.review?.status === 'Ready for Review' || input.review?.status === 'Approved' || input.decision)
|
|
17
|
+
return 'In Progress';
|
|
18
|
+
return 'Pending';
|
|
19
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { createServer } from 'node:net';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import { loadPreviewConfiguration } from './preview-configuration.js';
|
|
6
|
+
import { writePreviewRuntimeConfig } from './preview-runtime.js';
|
|
7
|
+
import { ORIGINAL_PREVIEW_ORIGINS } from './contextual-preview.js';
|
|
8
|
+
import { spawnPreviewRuntime, signalOwnedRuntime } from './runtime-process.js';
|
|
9
|
+
const starts = new Map();
|
|
10
|
+
const children = new Map();
|
|
11
|
+
/** Only call after authoritative report/mapping checks. No candidate is created or patched. */
|
|
12
|
+
export async function initializeOriginalPreview(root, application) {
|
|
13
|
+
const key = root + '|' + application;
|
|
14
|
+
const pending = starts.get(key);
|
|
15
|
+
if (pending)
|
|
16
|
+
return pending;
|
|
17
|
+
const operation = start();
|
|
18
|
+
starts.set(key, operation);
|
|
19
|
+
try {
|
|
20
|
+
await operation;
|
|
21
|
+
}
|
|
22
|
+
finally {
|
|
23
|
+
starts.delete(key);
|
|
24
|
+
}
|
|
25
|
+
async function start() {
|
|
26
|
+
const configuration = await loadPreviewConfiguration(root), app = configuration.applications[application];
|
|
27
|
+
const origin = app?.originalOrigin ?? ORIGINAL_PREVIEW_ORIGINS[application];
|
|
28
|
+
if (!origin)
|
|
29
|
+
throw Error('ORIGINAL_APPLICATION_NOT_CONFIGURED');
|
|
30
|
+
const url = new URL(origin);
|
|
31
|
+
if (url.protocol !== 'http:' || url.hostname !== '127.0.0.1')
|
|
32
|
+
throw Error('UNAPPROVED_PREVIEW_ORIGIN');
|
|
33
|
+
// Never stop or adopt a process by port. A running owned Vite observes wrapper updates.
|
|
34
|
+
const owned = children.get(key);
|
|
35
|
+
if (!owned || owned.exitCode !== null || owned.signalCode !== null) {
|
|
36
|
+
await new Promise((resolve, reject) => {
|
|
37
|
+
const probe = createServer();
|
|
38
|
+
probe.once('error', () => reject(Error('ORIGINAL_PREVIEW_PORT_OCCUPIED')));
|
|
39
|
+
probe.listen(Number(url.port), '127.0.0.1', () => probe.close(() => resolve()));
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const source = app?.entry ?? (application === 'invoicing' ? 'apps/invoicing/src/components/InvoiceTable.tsx' : 'apps/procurement/src/App.tsx');
|
|
43
|
+
const sourceSha256 = createHash('sha256').update(await readFile(join(root, source))).digest('hex');
|
|
44
|
+
const config = await writePreviewRuntimeConfig(root, { role: 'original', sessionId: 'original', sourceSha256 }, { application });
|
|
45
|
+
if (!owned || owned.exitCode !== null || owned.signalCode !== null) {
|
|
46
|
+
const child = await spawnPreviewRuntime(root, application, config, Number(url.port));
|
|
47
|
+
children.set(key, child);
|
|
48
|
+
child.on('error', () => { });
|
|
49
|
+
}
|
|
50
|
+
for (let attempt = 0; attempt < 100; attempt++) {
|
|
51
|
+
try {
|
|
52
|
+
const actual = await fetch(origin + '/__rtl_preview_identity', { signal: AbortSignal.timeout(500) }).then(r => r.json());
|
|
53
|
+
if (actual.projectRoot === root && actual.role === 'original' && actual.application === application && actual.sourceSha256 === sourceSha256)
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
catch { /* Wait only for this initialization; descriptors verify the complete identity next. */ }
|
|
57
|
+
if (children.get(key)?.exitCode !== null || children.get(key)?.signalCode !== null)
|
|
58
|
+
break;
|
|
59
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
60
|
+
}
|
|
61
|
+
throw Error('ORIGINAL_PREVIEW_STARTUP_FAILED');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export function stopOwnedOriginalPreviews() {
|
|
65
|
+
for (const child of children.values())
|
|
66
|
+
if (child.exitCode === null)
|
|
67
|
+
signalOwnedRuntime(child);
|
|
68
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { lstat } from 'node:fs/promises';
|
|
2
|
+
import { dirname, isAbsolute, normalize, parse, relative, resolve, sep } from 'node:path';
|
|
3
|
+
export class OutputPathError extends Error {
|
|
4
|
+
code;
|
|
5
|
+
constructor(code, message) {
|
|
6
|
+
super(`${code}: ${message}`);
|
|
7
|
+
this.code = code;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Validate and plan a future report destination. This function is read-only:
|
|
12
|
+
* it does not stat, create, truncate, or write the destination.
|
|
13
|
+
*
|
|
14
|
+
* Milestone 2 must revalidate this plan immediately before writing and use a
|
|
15
|
+
* no-follow/atomic write strategy to protect against symlink races.
|
|
16
|
+
*/
|
|
17
|
+
export async function planOutputPath(root, requestedPath, format, options = {}) {
|
|
18
|
+
const windowsPath = /^[A-Za-z]:[\\/]/.test(requestedPath) || requestedPath.startsWith('\\\\') || requestedPath.startsWith('//');
|
|
19
|
+
const requestedAbsolute = isAbsolute(requestedPath);
|
|
20
|
+
if (!requestedPath || windowsPath || requestedPath.includes('\\') || /[\0\r\n]/.test(requestedPath)) {
|
|
21
|
+
throw new OutputPathError('ABSOLUTE', 'output path must be a non-empty repository-relative POSIX path');
|
|
22
|
+
}
|
|
23
|
+
const normalized = normalize(requestedPath);
|
|
24
|
+
const rootPath = resolve(root);
|
|
25
|
+
const destination = resolve(isAbsolute(normalized) ? normalized : resolve(rootPath, normalized));
|
|
26
|
+
const rel = relative(rootPath, destination);
|
|
27
|
+
if (!requestedAbsolute && (rel === '..' || rel.startsWith(`..${sep}`) || isAbsolute(rel)))
|
|
28
|
+
throw new OutputPathError('OUTSIDE_ROOT', 'relative output path escapes the scanner root');
|
|
29
|
+
if (rel === '' || (rel !== '' && !rel.startsWith(`..${sep}`) && !isAbsolute(rel)))
|
|
30
|
+
throw new OutputPathError('INPUT_TREE', 'output path may not be inside the scanner root');
|
|
31
|
+
if (rel === '..' || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {
|
|
32
|
+
const protectedRoots = [rootPath, ...(options.protectedRoots ?? [])].map(item => resolve(item));
|
|
33
|
+
if (protectedRoots.some(protectedRoot => { const r = relative(protectedRoot, destination); return r === '' || (r !== '' && !r.startsWith(`..${sep}`) && !isAbsolute(r)); }))
|
|
34
|
+
throw new OutputPathError('INPUT_TREE', 'output path is inside a protected input root');
|
|
35
|
+
}
|
|
36
|
+
if (parse(destination).root !== parse(rootPath).root && !isAbsolute(destination)) {
|
|
37
|
+
throw new OutputPathError('INPUT_TREE', 'output path may not be inside a source or historical-input tree');
|
|
38
|
+
}
|
|
39
|
+
const expected = format === 'json' ? '.json' : '.md';
|
|
40
|
+
if (!destination.endsWith(expected))
|
|
41
|
+
throw new OutputPathError('UNSAFE_NAME', `output path must end with ${expected}`);
|
|
42
|
+
for (let current = dirname(destination);; current = dirname(current)) {
|
|
43
|
+
try {
|
|
44
|
+
if ((await lstat(current)).isSymbolicLink())
|
|
45
|
+
throw new OutputPathError('SYMLINK', 'output directory or ancestor is a symlink');
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (error.code !== 'ENOENT')
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
if (current === parse(current).root)
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
if ((await lstat(destination)).isSymbolicLink())
|
|
56
|
+
throw new OutputPathError('SYMLINK', 'output destination is a symlink');
|
|
57
|
+
if (await lstat(destination))
|
|
58
|
+
throw new OutputPathError('EXISTS', 'output destination already exists');
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (error.code !== 'ENOENT')
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
return Object.freeze({ root: rootPath, path: destination, relativePath: rel.split(sep).join('/'), format, revalidateBeforeWrite: true, overwrite: false });
|
|
65
|
+
}
|
|
@@ -7,7 +7,7 @@ export const ruleIds = new Set([
|
|
|
7
7
|
'RTL.CSS.PHYSICAL', 'RTL.CSS.SHORTHAND', 'RTL.GEOMETRY.EDGE', 'RTL.GEOMETRY.COUPLED', 'RTL.GEOMETRY.ORDER',
|
|
8
8
|
'RTL.OWNERSHIP.CONFLICT', 'RTL.RUNTIME.MISMATCH', 'RTL.RUNTIME.CACHE', 'RTL.RUNTIME.CACHE_UNVERIFIED',
|
|
9
9
|
'RTL.RUNTIME.DIRECTION_UNKNOWN', 'RTL.RUNTIME.PAGINATION', 'RTL.RUNTIME.LOCALE', 'RTL.FORM.DIRECTION',
|
|
10
|
-
'RTL.TABLE.ALIGNMENT', 'RTL.CHART.LABEL_FLOW', 'RTL.ICON.PROGRESSION', 'RTL.ICON.LITERAL',
|
|
10
|
+
'RTL.UTILITY.PHYSICAL', 'RTL.TABLE.ALIGNMENT', 'RTL.CHART.LABEL_FLOW', 'RTL.ICON.PROGRESSION', 'RTL.ICON.LITERAL',
|
|
11
11
|
'RTL.BIDI.ISOLATION', 'RTL.BRAND.ISLAND', 'RTL.DOCUMENT.INITIAL', 'RTL.DOCUMENT.RUNTIME',
|
|
12
12
|
]);
|
|
13
13
|
export const findingIdPattern = /^RTL\.[A-Z_]+(?:\.[A-Z_]+)*:[a-f0-9]{24}$/;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Keep help independent of project configuration and persisted review stores.
|
|
3
|
+
const args = process.argv.slice(2);
|
|
4
|
+
if (args.length === 1 && ['--help', '-h'].includes(args[0])) {
|
|
5
|
+
console.log(`Usage: RTL_PROJECT_ROOT=/absolute/project rtl-preview
|
|
6
|
+
|
|
7
|
+
Start the local review companion on http://127.0.0.1:4318.
|
|
8
|
+
Serve generated dashboard artifacts at http://127.0.0.1:4320.
|
|
9
|
+
Configure rtl-project.config.json and rtl-preview.config.json for standalone Vite projects.
|
|
10
|
+
Install the project's dependencies and Playwright Chromium before runtime validation.
|
|
11
|
+
Review state defaults to ~/.rtl-migration-analyzer; Apply backups default to OS temporary storage.
|
|
12
|
+
See README for RTL_* overrides and required state filenames.
|
|
13
|
+
Use Ctrl-C to stop the companion and its owned preview runtimes.`);
|
|
14
|
+
}
|
|
15
|
+
else if (args.length) {
|
|
16
|
+
console.error('Unknown option. Use rtl-preview --help.');
|
|
17
|
+
process.exitCode = 2;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
await import('./preview-companion.js');
|
|
21
|
+
}
|
|
22
|
+
export {};
|