运行对比页复核修正(第 1 轮):照服务端的实际输出改查询编号、无法比较的原因、读不到的基准和未保存工作流的说法

- 查询区不再拿服务端的 (node_id, ordinal) 当键和编号:配上的一对取本次的序号、落单的基准查询取基准的序号,
  Agent 换了查询先后时两者会撞上,React 报键冲突,「第 N 条」重复或缺号。改按同一节点在列表里出现的先后编号,
  键是「节点:第几」。
- 「拆分或原因」一栏:无法比较、新增、移除的指标,服务端只把原因放在 reasons 里,这一栏原来只剩「—」,现在写
  reasons 的第一句。不能拆的「为什么没拆」也写进展开的明细,窄屏上那一格横着滚也看不全。服务端有意不做维度归因
  的几类,写明为什么不做。检查夹具改成服务端的实际形状(decomposition_note 为 null):原来那一项是靠编出来的字段
  通过的。
- 换基准下拉:当前的基准读不到时单列一项,写短 id 和「记录不存在」或「无法读取」,不再显示成另一次运行被选中、
  选它又没反应。本次的记录读不到时写明原因并给重试,不再一直停在「正在读取」。运行卡读取失败也给重试,记录不存在
  的照实写。
- 不属于已保存工作流的运行(没保存过,或工作流已删除):「与上一次对比」不可点并写明原因,对比页也不再叫人去上方
  选基准。服务端对这两种运行都不比。
- 错误说明:409 按机读码分「尚未结束并封存」和「封存核对不一致」,去掉界面上没有的「封存凭证条」。基准不存在时
  提示在上方另选。找不到默认基准时,下拉里有能选的运行才说「可在上方选择」。
- 菜单查找基准超过 300 毫秒就挂一条提示;离开运行详情时取消请求,晚到的答复不再把人拽到对比页。
- 一边的 SQL 拿不到时不做逐词比较,另一边不再整条标成「独有」。SQL 注释整段算一个词,注释里的撇号不再吞掉后面的
  语句。
- 分类、结构的悬停说明照服务端的分类口径改写;查询按「条」计数,和「第 N 条」一致。
- check-compare 按服务端的实际输出补上这些场景,并加段过滤 COMPARE_ONLY;check-all 里 compare 的耗时估计按实测
  改为 45 秒。
This commit is contained in:
ThearchyHelios
2026-10-05 10:16:15 +08:00
parent a0837cc82c
commit c7a9116424
11 changed files with 610 additions and 133 deletions
+41 -8
View File
@@ -2751,8 +2751,11 @@ export const RUN_COMPARE_TEXT = {
// 入口:运行详情的「更多」菜单
menu: '与上一次对比',
menuSealedOnly: '运行结束并封存后才能对比',
/** 没有 workflow_id 的运行:画布、问数据里没保存就运行的,或者工作流删掉之后被置空的。服务端只比同一个已保存的工作流 */
menuNoWorkflow: '工作流未保存或已删除,无法对比',
menuFinding: '正在查找上一次运行…',
pickManually: '手动选择基准',
retry: '重试',
// 顶部的两次运行
base: '基准',
target: '本次',
@@ -2763,6 +2766,7 @@ export const RUN_COMPARE_TEXT = {
unsealed: '未封存',
unsealedHint: '这次运行没有封存清单,不能参与对比',
runFailed: '无法读取这次运行',
runMissing: '运行记录不存在',
noBase: '未选择',
reason: {
same_schedule: '默认基准:同一定时任务的上一次运行',
@@ -2773,25 +2777,37 @@ export const RUN_COMPARE_TEXT = {
pickLoading: '正在读取同一工作流的运行…',
pickFailed: '无法读取同一工作流的运行',
pickNone: '同一工作流没有其他运行',
pickUnsaved: '临时构建的工作流没有其他运行可选',
pickUnsaved: '工作流未保存或已删除,没有可对比的运行',
pickPlaceholder: '选择一次运行作为基准',
/** 下拉里的一次运行:时间 · 类别和版本 · 短 id,没封存的另标 */
pickOption: (time: string, cls: string, id: string, sealed: boolean) =>
`${time} · ${cls} · ${id}${sealed ? '' : '(未封存)'}`,
/** 当前的基准读不到时下拉里的那一项(短 id):如实显示选的是哪一次 */
pickGone: (id: string, missing: boolean) => `${id}(${missing ? '记录不存在' : '无法读取'})`,
// 页面状态
noTarget: '未指定要对比的运行',
noTargetHint: '在运行详情的「更多」菜单中选择「与上一次对比」,即可对照本次与上一次运行',
toRuns: '前往记录',
finding: '正在查找基准运行…',
loading: '正在对比两次运行…',
errSealed: '无法对比:有运行未封存或封存核对未通过',
errSealedHint: '两次运行都需已结束并封存,且封存核对一致。可在运行详情的封存凭证条上核对',
// 对比失败:标题说是哪一种,服务端的原因原样跟在后面,最后一句下一步只写界面上真有的入口,服务端已经写了的不再重复
errSealed: '无法对比:有运行未封存或封存核对不一致',
errUnsealed: '无法对比:有运行尚未结束并封存',
errSealBroken: '无法对比:封存核对不一致',
/** 409 时不知道(或者知道不是)本次的问题:服务端的原因里写着是哪一次 */
errSealedHint: '若是基准运行的问题,可在上方更换基准',
errMismatch: '无法对比这两次运行',
errMismatchHint: '请选择同一工作流的另一次运行作为基准',
errMismatchHint: '可在上方选择同一工作流的另一次运行作为基准',
/** 本次没有 workflow_id:哪一次都比不了,不给下一步 */
errUnsaved: '无法对比:本次运行的工作流未保存或已删除',
errMissing: '运行记录不存在',
errMissingHint: '链接可能已失效,请从记录页重新打开',
/** 本次的记录读得到、对比却回 404:缺的是基准 */
errBaseMissingHint: '可在上方选择另一次运行作为基准',
errNoBase: '未找到可作为基准的运行',
errNoBaseHint: '可在上方选择同一工作流的其他运行作为基准',
/** 下拉里一次能选的都没有(只有本次、或者都没封存) */
errNoBaseNone: '同一工作流还没有其他已封存的运行',
viewBase: '查看基准运行',
viewTarget: '查看本次运行',
// 摘要
@@ -2807,11 +2823,12 @@ export const RUN_COMPARE_TEXT = {
incomparable: '无法比较',
unchanged: '未变',
} as Record<string, string>,
// 照服务端(engine/compare.py)的分类口径写:口径变了含小数位、单位、显示格式,SQL 结构变含上游节点改配置
classHint: {
data_only: '口径与 SQL 都没有改动,变化来自数据',
caliber_and_data: '口径卡的计算式有改动,数据也变了;能严格拆分的分别给出口径效应和数据效应',
sql_changed: '所依据的查询 SQL 结构有改动,口径不同,不做拆分',
params_only: '所依据的查询 SQL 结构相同,只有参数(如日期)不同',
caliber_and_data: '口径(计算式、口径版本、小数位、单位或显示格式)有改动,数据可能也有变化;能严格拆分的分别给出口径效应和数据效应',
sql_changed: '取数的 SQL 或上游节点的配置有改动,无法在口径与数据之间拆分',
params_only: '所依据的查询 SQL 结构相同,只有参数(如日期)或运行输入不同',
added: '本次有、基准没有的指标',
removed: '基准有、本次没有的指标',
incomparable: '缺少比较所需的信息,无法判断变化来自哪里',
@@ -2824,6 +2841,8 @@ export const RUN_COMPARE_TEXT = {
metrics: '指标',
metricsEmpty: '两次运行的口径卡上都没有指标',
count: (n: number) => `${formatNumber(n)} 个`,
/** 查询按「条」数,和「第 N 条」一致 */
queryCount: (n: number) => `${formatNumber(n)} 条`,
colMetric: '指标',
colBase: '基准',
colTarget: '本次',
@@ -2850,6 +2869,17 @@ export const RUN_COMPARE_TEXT = {
attrMore: (n: number) => `另有 ${formatNumber(n)} 项未列出`,
attrTotal: (value: string) => `合计变化 ${value}`,
attrNone: '没有可按维度归因的明细',
/**
* 服务端只对只数据变、只参数变、口径与数据都变的指标做维度归因(两边的行说的是同一回事)。别的类不是「没有明细」,
* 是有意不做:写明为什么
*/
attrSkipped: {
sql_changed: '取数的 SQL 或上游配置有改动,两边的行不能直接对照,不做维度归因',
incomparable: '无法判断变化来源,不做维度归因',
added: '基准没有这个指标,不做维度归因',
removed: '本次没有这个指标,不做维度归因',
unchanged: '数值没有变化,不做维度归因',
} as Record<string, string>,
/** 服务端没给占比、也没说为什么时的说法 */
attrNoShare: '无法计算各项占比',
colKey: '维度',
@@ -2867,7 +2897,8 @@ export const RUN_COMPARE_TEXT = {
structureHint: {
same: 'SQL 完全相同',
params_only: 'SQL 结构相同,只有字面量不同',
changed: 'SQL 结构不同:表、连接、筛选条件、分组或聚合有改动',
// 服务端在只换了数据源、有一边的 SQL 读不出来时也标「结构变」
changed: 'SQL 结构或数据源不同,或有一边的 SQL 无法读取',
added: '本次新增的查询,基准中没有',
removed: '基准中有、本次没有的查询',
} as Record<string, string>,
@@ -2883,6 +2914,8 @@ export const RUN_COMPARE_TEXT = {
baseSql: '基准的 SQL',
targetSql: '本次的 SQL',
bothSql: '两次相同的 SQL',
/** 快照读不出来、又拿不到执行时的参数:这一边没有 SQL,不能拿空串去和另一边比 */
sqlUnreadable: '这一边的 SQL 无法读取',
onlyBase: '基准独有',
onlyTarget: '本次独有',
showSql: '查看 SQL',
+16 -4
View File
@@ -7,8 +7,8 @@ import type { RunComparison } from '../../types'
import { useCandidates, useComparison, useDefaultBase, useRunRecord } from './compare/data'
import { comparePath, type CompareVia } from './compare/entry'
import { Metrics } from './compare/Metrics'
import { compareErrorKind } from './compare/model'
import { CompareError } from './compare/parts'
import { compareErrorKind, isGone } from './compare/model'
import { CompareError, type CompareErrorContext } from './compare/parts'
import { Queries } from './compare/Queries'
import { RunPair } from './compare/RunPair'
import { Summary } from './compare/Summary'
@@ -51,6 +51,8 @@ export function ComparePage() {
const workflowId = targetRun.state === 'ok' ? targetRun.data?.workflow_id : lastWorkflow.current
const candidates = useCandidates(workflowId)
const cmp = useComparison(target, base)
// 不属于已保存的工作流:没保存过,或者工作流删掉之后 workflow_id 被置空(名字还是原来的)。服务端两种都不比
const unsaved = targetRun.state === 'ok' && !workflowId
const go = (t: string, b: string) => navigate(comparePath(t, b), { replace: true })
@@ -59,6 +61,16 @@ export function ComparePage() {
else if (!base) state = finder.state === 'error' ? 'error' : 'finding'
else state = cmp.state === 'ok' ? 'ok' : cmp.state === 'error' ? 'error' : 'loading'
// 错误说明的下一步按页面已经知道的挑(parts.tsx 的 errorCopy):下拉里没有能选的就不叫人去上方选
const errorContext: CompareErrorContext = {
targetKnown: targetRun.state === 'ok',
targetUnsaved: unsaved,
targetUnsealed: targetRun.state === 'ok' && !targetRun.data?.manifest_hash,
targetGone: targetRun.state === 'error' && isGone(targetRun.error),
baseGone: baseRun.state === 'error' && isGone(baseRun.error),
pickable: candidates.state === 'ok' ? (candidates.data ?? []).some((r) => r.id !== target && !!r.manifest_hash) : null,
}
return (
<div className="flex h-full flex-col">
<PageHeader icon={<GitCompareArrows size={13} />} title={RUN_COMPARE_TEXT.title} subtitle={RUN_COMPARE_TEXT.hint} />
@@ -70,7 +82,7 @@ export function ComparePage() {
<div className="mx-auto flex w-full min-w-0 max-w-6xl flex-col gap-3 px-3 py-3 sm:px-4 sm:py-4">
<RunPair
target={target} base={base} targetRun={targetRun} baseRun={baseRun} candidates={candidates}
unsaved={targetRun.state === 'ok' && !workflowId} reason={reason}
unsaved={unsaved} reason={reason}
onPick={(b) => go(target, b)} onSwap={() => { if (base) go(base, target) }}
/>
{state === 'finding' && <Pending text={RUN_COMPARE_TEXT.finding} />}
@@ -80,7 +92,7 @@ export function ComparePage() {
kind={compareErrorKind(base ? cmp.error : finder.error, !base)}
error={base ? cmp.error : finder.error}
onRetry={base ? cmp.reload : finder.reload}
target={target} base={base}
target={target} base={base} context={errorContext}
/>
)}
{state === 'ok' && cmp.data && <Comparison key={`${target}|${base}`} data={cmp.data} />}
+23 -12
View File
@@ -5,7 +5,7 @@ import { NONE } from '../../../lib/format'
import { RUN_COMPARE_TEXT as T } from '../../../lib/terms'
import type { RunCompareAttribution, RunCompareDecomposition, RunCompareMetric } from '../../../types'
import { Block, ClassChip } from './parts'
import { changeText, metricKey, sameValue, shareText, signedNumber, valueText } from './model'
import { changeText, metricKey, sameValue, shareText, signedNumber, splitReason, valueText } from './model'
/** 维度归因列前几项:后端按变化从大到小排好,多的只写还有几项 */
const ATTR_TOP = 10
@@ -20,7 +20,7 @@ const STICKY = 'sticky left-0 z-[1] min-w-[9em] shadow-[inset_-1px_0_0_var(--bor
/**
* 指标表:基准 → 本次、变化量和百分比(渲染值照服务端给的写)、分类、能严格拆分的口径效应和数据效应(并列的数加一段
* 两截的条形),不能拆的写服务端给的原因。每行能展开:变化说明、输入对比、维度归因前 10 项。
* 两截的条形),不能拆、比不了的写原因(splitReason)。每行能展开:变化说明、输入对比、维度归因前 10 项。
*
* 表格比窄屏宽,在自己的框里横向滚动(框能用键盘聚焦),页面本身不横向溢出。展开的明细贴着框的左边、宽度等于框的
* 可见宽度:窄屏上不用横着滚也读得全
@@ -104,6 +104,7 @@ function MetricRows({ m, k, detailId, open, onToggle }: {
m: RunCompareMetric; k: string; detailId: string; open: boolean; onToggle: () => void
}) {
const pct = m.delta_pct != null && m.delta_pct !== 0 ? changeText(m.delta_pct) : null
const why = m.decomposition ? null : splitReason(m)
return (
<Fragment>
<tr className={clsx('border-b align-top last:border-0', open && 'bg-hover')} data-compare-metric={k} data-class={m.classification}>
@@ -129,9 +130,10 @@ function MetricRows({ m, k, detailId, open, onToggle }: {
<td className="px-2.5 py-2">
{m.decomposition ? (
<Split d={m.decomposition} total={totalText(m)} />
) : m.decomposition_note ? (
<p className="max-w-[280px] text-2xs leading-relaxed text-dim [overflow-wrap:anywhere]" data-compare-decomp-note="">
{m.decomposition_note}
) : why ? (
<p className="max-w-[280px] text-2xs leading-relaxed text-dim [overflow-wrap:anywhere]" data-compare-decomp-note=""
data-from={m.decomposition_note ? 'note' : 'reasons'}>
{why}
</p>
) : (
<span className="text-faint">{NONE}</span>
@@ -199,7 +201,11 @@ function Split({ d, total }: { d: RunCompareDecomposition; total: string }) {
)
}
/** 展开的明细:变化说明、拆分写成一句话、输入对比、维度归因。贴着滚动框的左边,宽度等于框的可见宽度 */
/**
* 展开的明细:变化说明、拆分写成一句话(不能拆的写服务端说的为什么)、输入对比、维度归因。贴着滚动框的左边,宽度
* 等于框的可见宽度:窄屏上表格里「拆分或原因」那一格比钉在左边的指标名右侧剩下的地方宽,横着滚到哪儿都看不全,
* 这里读得全
*/
function MetricDetail({ m }: { m: RunCompareMetric }) {
return (
<div className="sticky left-0 box-border grid gap-4 px-3 py-3 lg:grid-cols-2" style={{ width: 'var(--compare-view, 100%)' }}>
@@ -212,15 +218,17 @@ function MetricDetail({ m }: { m: RunCompareMetric }) {
</ul>
</div>
)}
{m.decomposition && (
{m.decomposition ? (
<p className="text-xs leading-relaxed text-fg" data-compare-decomp-sum="">
{T.splitSum(m.decomposition.caliber_rendered, m.decomposition.data_rendered, totalText(m))}
</p>
)}
) : m.decomposition_note ? (
<p className="text-xs leading-relaxed text-dim [overflow-wrap:anywhere]" data-compare-detail-note="">{m.decomposition_note}</p>
) : null}
<Inputs m={m} />
</div>
<div className="min-w-0">
<Attribution a={m.attribution} />
<Attribution a={m.attribution} classification={m.classification} />
</div>
</div>
)
@@ -270,14 +278,17 @@ function Inputs({ m }: { m: RunCompareMetric }) {
/**
* 维度归因:按键对齐两边查询结果的行,列前 10 项的键、两边的值、变化和占比。占比只在度量列之和等于指标的输入时才有,
* 没有时那一栏写「—」,下面照服务端的说明写原因(没给说明时写一句通用的)。归不了因的(查询结果截断、度量列遮罩、
* 快照读不出来)服务端给空的 rows 和一句说明:不画空表,只写这句话
* 快照读不出来)服务端给空的 rows 和一句说明:不画空表,只写这句话。服务端有意不做归因的几类(SQL 结构变、无法
* 比较、新增、移除、未变)写为什么不做,不说成「没有明细」
*/
function Attribution({ a }: { a: RunCompareAttribution | null }) {
function Attribution({ a, classification }: { a: RunCompareAttribution | null; classification: string }) {
if (!a) {
return (
<div>
<h3 className="mb-1 text-2xs font-medium text-faint">{T.attribution}</h3>
<p className="text-2xs text-faint" data-compare-attr-none="">{T.attrNone}</p>
<p className="text-2xs leading-relaxed text-faint [overflow-wrap:anywhere]" data-compare-attr-none="">
{T.attrSkipped[classification] ?? T.attrNone}
</p>
</div>
)
}
+36 -19
View File
@@ -4,7 +4,7 @@ import clsx from 'clsx'
import { RUN_COMPARE_TEXT as T } from '../../../lib/terms'
import type { RunCompareQuery } from '../../../types'
import { Block, StructureChip } from './parts'
import { queryKey, queryNumbers, valueText } from './model'
import { queryItems, valueText } from './model'
import { diffSql, type DiffPart } from './sqlDiff'
/** 基准独有、本次独有的高亮:颜色之外,删去的划线、新加的下划线,色弱、灰度打印也分得出 */
@@ -26,17 +26,14 @@ const MARK = {
*/
export function Queries({ queries }: { queries: RunCompareQuery[] }) {
const id = useId()
const numbers = useMemo(() => queryNumbers(queries), [queries])
const items = useMemo(() => queryItems(queries), [queries])
return (
<Block id={`${id}-queries`} title={T.queries} count={T.count(queries.length)} attr={{ 'data-compare-queries': '' }}>
<Block id={`${id}-queries`} title={T.queries} count={T.queryCount(queries.length)} attr={{ 'data-compare-queries': '' }}>
{!queries.length ? (
<p className="py-4 text-center text-xs text-faint" data-compare-empty="queries">{T.queriesEmpty}</p>
) : (
<ul className="divide-y">
{queries.map((q) => {
const k = queryKey(q)
return <QueryItem key={k} q={q} k={k} nth={numbers.get(k) ?? null} />
})}
{items.map((it) => <QueryItem key={it.key} q={it.q} k={it.key} nth={it.nth} />)}
</ul>
)}
</Block>
@@ -91,22 +88,37 @@ function QueryItem({ q, k, nth }: { q: RunCompareQuery; k: string; nth: number |
</ul>
</div>
)}
{q.structure === 'changed' && <SideBySide base={q.base_sql ?? ''} target={q.target_sql ?? ''} />}
{q.structure === 'added' && <SqlPane which="target" label={T.targetSql} sql={q.target_sql ?? ''} />}
{q.structure === 'removed' && <SqlPane which="base" label={T.baseSql} sql={q.base_sql ?? ''} />}
{q.structure === 'changed' && <SideBySide base={q.base_sql} target={q.target_sql} />}
{q.structure === 'added' && <SqlPane which="target" label={T.targetSql} sql={q.target_sql} />}
{q.structure === 'removed' && <SqlPane which="base" label={T.baseSql} sql={q.base_sql} />}
{foldable && showSql && (
<div id={sqlId}>
{q.structure === 'same'
? <SqlPane which="both" label={T.bothSql} sql={q.target_sql ?? q.base_sql ?? ''} />
: <SideBySide base={q.base_sql ?? ''} target={q.target_sql ?? ''} />}
? <SqlPane which="both" label={T.bothSql} sql={q.target_sql ?? q.base_sql} />
: <SideBySide base={q.base_sql} target={q.target_sql} />}
</div>
)}
</li>
)
}
/** 两条 SQL 并排,逐词标出各自独有的部分 */
function SideBySide({ base, target }: { base: string; target: string }) {
/**
* 两条 SQL 并排,逐词标出各自独有的部分。有一边拿不到 SQL(快照读不出来、又没有执行时的参数)时不比:拿空串去比,
* 另一边会整条被标成「独有」,像是整条新写的,其实只是不知道。这时两边原样摆着,拿不到的那一边写明无法读取
*/
function SideBySide({ base, target }: { base: string | null; target: string | null }) {
if (base == null || target == null) {
return (
<div className="mt-2 grid grid-cols-1 gap-2 sm:grid-cols-2">
<SqlPane which="base" label={T.baseSql} sql={base} />
<SqlPane which="target" label={T.targetSql} sql={target} />
</div>
)
}
return <Diffed base={base} target={target} />
}
function Diffed({ base, target }: { base: string; target: string }) {
const diff = useMemo(() => diffSql(base, target), [base, target])
return (
<div className="mt-2">
@@ -123,21 +135,26 @@ function SideBySide({ base, target }: { base: string; target: string }) {
)
}
/** 一条 SQL。折行显示,不横向撑开;太长时在框里纵向滚动,框能用键盘聚焦 */
/**
* 一条 SQL。折行显示,不横向撑开;太长时在框里纵向滚动,框能用键盘聚焦。sql 为 null(这一边拿不到 SQL)时
* 框里写明无法读取,不摆一个空框
*/
function SqlPane({ which, label, sql, parts }: {
which: 'base' | 'target' | 'both'; label: string; sql?: string; parts?: DiffPart[]
which: 'base' | 'target' | 'both'; label: string; sql?: string | null; parts?: DiffPart[]
}) {
const kind = which === 'base' ? 'del' : 'add'
const missing = !parts && sql == null
return (
<figure className="m-0 mt-1.5 min-w-0">
<figcaption className="mb-0.5 text-2xs text-faint">{label}</figcaption>
<pre className="mono max-h-64 overflow-y-auto whitespace-pre-wrap rounded bg-bg px-2 py-1.5 text-2xs leading-relaxed text-dim [overflow-wrap:anywhere] focus-visible:outline-2 focus-visible:outline-[color:var(--accent)]"
data-compare-sql={which} tabIndex={0} aria-label={label}>
<pre className={clsx('max-h-64 overflow-y-auto whitespace-pre-wrap rounded bg-bg px-2 py-1.5 text-2xs leading-relaxed [overflow-wrap:anywhere] focus-visible:outline-2 focus-visible:outline-[color:var(--accent)]',
missing ? 'font-sans text-faint' : 'mono text-dim')}
data-compare-sql={which} data-unreadable={missing ? '' : undefined} tabIndex={0} aria-label={label}>
{parts
? parts.map((p, i) => (p.changed
? <mark key={i} data-diff={kind} className="rounded-sm" style={MARK[kind]}>{p.text}</mark>
: <Fragment key={i}>{p.text}</Fragment>))
: sql}
: missing ? T.sqlUnreadable : sql}
</pre>
</figure>
)
+48 -16
View File
@@ -1,12 +1,13 @@
import { useId, type ReactNode } from 'react'
import { Link } from 'react-router-dom'
import { ArrowLeftRight, CalendarClock } from 'lucide-react'
import { ArrowLeftRight, CalendarClock, RotateCw } from 'lucide-react'
import { Skeleton, useTicker } from '../../../components/ui'
import { formatDateTime, formatTime, shortId } from '../../../lib/format'
import { RUN_COMPARE_TEXT as T, runClassLabel, runName } from '../../../lib/terms'
import type { RunWithSchedule } from '../../../types'
import { ClassChip as RunClassChip } from '../parts'
import type { Loaded } from './data'
import { isGone } from './model'
/**
* 顶部的两次运行:左边基准、右边本次(窄屏上下排),中间「互换」。每张卡写名字、时间、类别和版本,点名字进各自的
@@ -18,7 +19,7 @@ export function RunPair({ target, base, targetRun, baseRun, candidates, unsaved,
targetRun: Loaded<RunWithSchedule>
baseRun: Loaded<RunWithSchedule>
candidates: Loaded<RunWithSchedule[]>
/** 本次的工作流没保存:没有同一工作流的其他运行可选 */
/** 本次不属于已保存的工作流(没保存过、或者工作流已删除):没有同一工作流的其他运行可选 */
unsaved: boolean
/** 默认基准是怎么选的(只在从「与上一次对比」、或只带本次打开时有) */
reason: string | null
@@ -29,8 +30,8 @@ export function RunPair({ target, base, targetRun, baseRun, candidates, unsaved,
<div className="flex flex-col gap-1.5">
<div className="grid grid-cols-1 gap-2 md:grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)]">
<RunCard role="base" id={base} run={baseRun}>
<BasePicker target={target} base={base} baseRun={baseRun.data} candidates={candidates} unsaved={unsaved}
onPick={onPick} />
<BasePicker target={target} base={base} baseRun={baseRun} targetRun={targetRun} candidates={candidates}
unsaved={unsaved} onPick={onPick} />
</RunCard>
<div className="flex items-center justify-center">
<button type="button" className="btn btn-sm" data-compare-swap="" disabled={!base} onClick={onSwap}
@@ -54,6 +55,7 @@ function RunCard({ role, id, run, children }: {
const now = useTicker(60_000)
const r = run.data
const when = r ? r.started_at ?? r.created_at ?? null : null
const gone = run.state === 'error' && isGone(run.error)
return (
<div className="min-w-0 rounded-lg border bg-panel px-3 py-2.5" data-compare-run={role}>
<div className="flex min-w-0 flex-wrap items-center gap-1.5 text-2xs">
@@ -85,10 +87,14 @@ function RunCard({ role, id, run, children }: {
</div>
</>
) : run.state === 'error' ? (
// 读不到运行记录(删了、连不上):对比本身照样请求,能不能比由对比接口说
<div className="mt-1 text-xs text-faint">
<Link to={`/runs/${id}`} data-compare-run-link="" className="mono hover:underline">{shortId(id)}</Link>
<span className="ml-1.5">{T.runFailed}</span>
// 读不到运行记录:对比本身照样请求,能不能比由对比接口说。记录不存在的重试也没用,只写不存在;
// 别的(连不上、服务端出错)给重试
<div className="mt-1 flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-1 text-xs text-faint" data-compare-run-failed="">
{gone
? <span className="mono" title={id}>{shortId(id)}</span>
: <Link to={`/runs/${id}`} data-compare-run-link="" className="mono hover:underline">{shortId(id)}</Link>}
<span>{gone ? T.runMissing : T.runFailed}</span>
{!gone && <RetryButton onClick={run.reload} />}
</div>
) : (
<div className="mt-1.5" aria-busy="true"><Skeleton rows={2} height={12} gap={8} /></div>
@@ -98,24 +104,49 @@ function RunCard({ role, id, run, children }: {
)
}
function RetryButton({ onClick }: { onClick: () => void }) {
return (
<button type="button" className="btn btn-xs" onClick={onClick}>
<RotateCw size={10} aria-hidden /> {T.retry}
</button>
)
}
/**
* 换基准。列的是运行列表接口按工作流取回的最近几次(新的在前),去掉本次;没封存的列出来但不能选,写明原因。
* 当前的基准不在这几次里(更早、或者属于别的工作流)时也放进去,下拉不至于显示成别的运行
*
* 当前的基准不在这几次里(更早、属于别的工作流、读不到)时也单列一项:受控的下拉值对不上任何选项时浏览器会选中
* 第一项,看着像另一次运行被选中,而原生下拉再选当前显示的那一项不触发 change,最自然的补救点了没反应。读不到的
* 写短 id 加原因,下拉如实反映当前选的是哪一次,其余每一项都能触发 change。
*
* 列不出候选时说清楚、给重试,不停在「正在读取」:同一工作流的运行没取到;或者本次的记录没读到,不知道是哪个工作流
* (候选的键是空的,不会自己去取)
*/
function BasePicker({ target, base, baseRun, candidates, unsaved, onPick }: {
target: string; base: string | null; baseRun?: RunWithSchedule; candidates: Loaded<RunWithSchedule[]>; unsaved: boolean
onPick: (id: string) => void
function BasePicker({ target, base, baseRun, targetRun, candidates, unsaved, onPick }: {
target: string; base: string | null; baseRun: Loaded<RunWithSchedule>; targetRun: Loaded<RunWithSchedule>
candidates: Loaded<RunWithSchedule[]>; unsaved: boolean; onPick: (id: string) => void
}) {
const id = useId()
const now = useTicker(60_000)
if (unsaved) return <p className="mt-2 text-2xs text-faint">{T.pickUnsaved}</p>
if (candidates.state === 'error') return <p className="mt-2 text-2xs text-faint">{T.pickFailed}</p>
if (unsaved) return <p className="mt-2 text-2xs text-faint" data-compare-pick-note="unsaved">{T.pickUnsaved}</p>
const failed = candidates.state === 'error' ? candidates.reload
: candidates.state === 'idle' && targetRun.state === 'error' ? targetRun.reload : null
if (failed) {
return (
<div className="mt-2 flex flex-wrap items-center gap-x-2 gap-y-1 text-2xs text-faint" data-compare-pick-failed="">
<span>{T.pickFailed}</span>
<RetryButton onClick={failed} />
</div>
)
}
const loading = candidates.state !== 'ok'
const list = (candidates.data ?? []).filter((r) => r.id !== target)
if (base && baseRun && !list.some((r) => r.id === base)) list.unshift(baseRun)
if (!loading && !list.length) return <p className="mt-2 text-2xs text-faint">{T.pickNone}</p>
if (!loading && !list.length) return <p className="mt-2 text-2xs text-faint" data-compare-pick-note="none">{T.pickNone}</p>
const label = (r: RunWithSchedule) => T.pickOption(formatTime(r.started_at ?? r.created_at ?? null, new Date(now)),
runClassLabel(r.run_class, r.version), shortId(r.id), !!r.manifest_hash)
const current = base && !list.some((r) => r.id === base) ? base : null
const currentLabel = (b: string) => (baseRun.data ? label(baseRun.data)
: baseRun.state === 'error' ? T.pickGone(shortId(b), isGone(baseRun.error)) : shortId(b))
return (
<div className="mt-2.5 border-t pt-2">
<label className="label" htmlFor={id}>{T.pickBase}</label>
@@ -123,6 +154,7 @@ function BasePicker({ target, base, baseRun, candidates, unsaved, onPick }: {
aria-describedby={`${id}-hint`} onChange={(e) => { if (e.target.value) onPick(e.target.value) }}>
{loading && <option value={base ?? ''}>{T.pickLoading}</option>}
{!loading && !base && <option value="" disabled>{T.pickPlaceholder}</option>}
{!loading && current && <option value={current}>{currentLabel(current)}</option>}
{!loading && list.map((r) => (
// 当前的基准即使没封存也要能显示出来(选中项);别的没封存的一律不能选
<option key={r.id} value={r.id} disabled={!r.manifest_hash && r.id !== base}>{label(r)}</option>
+40 -7
View File
@@ -1,4 +1,4 @@
import { useCallback, useState } from 'react'
import { useCallback, useEffect, useRef, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { GitCompareArrows } from 'lucide-react'
import { ApiError, api } from '../../../api/client'
@@ -13,36 +13,69 @@ export interface CompareVia { base: string; reason: string }
export const comparePath = (target: string, base?: string | null) =>
`/runs/compare?${new URLSearchParams(base ? { target, base } : { target })}`
/** 查找超过这么久才挂「正在查找」的提示:答复快的不闪一下 */
const NOTE_DELAY_MS = 300
/**
* 运行详情「更多」菜单里的「与上一次对比」。先问服务端默认的基准(同一定时任务的上一次,没有就同一工作流、同一类别的
* 上一次),找到了再跳到对比页;找不到时留在原页,提示服务端给的原因,并给「手动选择基准」去对比页自己挑。
* 没封存、还在运行的不给点:对比只认已封存的运行,点了也是 409。
* 这几种不给点,点了也只会被拒:没封存、还在运行的(对比只认已封存的运行,409);不属于已保存工作流的——画布、问数据
* 里没保存就运行的,和工作流删掉之后 workflow_id 被置空的(服务端找不到同一工作流的运行,手动选也是 422)。
*
* 菜单点完就收起:查找慢于一眨眼时挂一条提示,接口慢的时候不至于像没反应。离开运行详情(组件卸载)时取消请求、
* 收起提示,晚到的答复不再把人带去对比页。
*
* 写成 hook(返回造菜单项的函数):运行详情里有提前返回,菜单项本身只能在拿到运行之后造,查找中的状态得在那之前就挂上
*/
export function useCompareEntry(): (run: Run, live: boolean) => MenuItem {
const navigate = useNavigate()
const [busy, setBusy] = useState(false)
// 在路上的那一次:stop 收起(或者不再挂出)「正在查找」的提示
const pending = useRef<{ ctrl: AbortController; stop: () => void } | null>(null)
useEffect(() => () => {
const p = pending.current
pending.current = null
p?.ctrl.abort()
p?.stop()
}, [])
return useCallback((run: Run, live: boolean): MenuItem => {
const blocked = live || !run.manifest_hash
const orphan = !run.workflow_id
const unsealed = live || !run.manifest_hash
return {
key: 'compare',
label: T.menu,
icon: <GitCompareArrows size={12} />,
disabled: blocked || busy,
hint: blocked ? T.menuSealedOnly : busy ? T.menuFinding : undefined,
disabled: orphan || unsealed || busy,
hint: orphan ? T.menuNoWorkflow : unsealed ? T.menuSealedOnly : busy ? T.menuFinding : undefined,
onSelect: () => {
const ctrl = new AbortController()
let note: number | null = null
const timer = setTimeout(() => {
note = toast.info(T.menuFinding, { sticky: true, key: `compare-finding:${run.id}` })
}, NOTE_DELAY_MS)
const stop = () => {
clearTimeout(timer)
if (note != null) toast.dismiss(note)
}
pending.current = { ctrl, stop }
setBusy(true)
api.compare.base(run.id).then((found) => {
api.compare.base(run.id, { signal: ctrl.signal }).then((found) => {
if (ctrl.signal.aborted) return
const via: CompareVia = { base: found.base_run_id, reason: found.reason }
navigate(comparePath(run.id, found.base_run_id), { state: via })
}, (e: unknown) => {
if (ctrl.signal.aborted) return
if (e instanceof ApiError && e.kind === 'http' && e.status === 404) {
toast.info(e.message, { action: { label: T.pickManually, onClick: () => navigate(comparePath(run.id)) } })
} else {
toast.error(e)
}
}).finally(() => setBusy(false))
}).finally(() => {
stop()
if (pending.current?.ctrl !== ctrl) return
pending.current = null
setBusy(false)
})
},
}
}, [navigate, busy])
+42 -13
View File
@@ -34,8 +34,19 @@ export function classTone(k: string): { color: string; soft: boolean } {
/** 一个指标在表里的键:同一张卡里指标 id 唯一,几张卡之间可能重名 */
export const metricKey = (m: Pick<RunCompareMetric, 'card_id' | 'metric_id'>) => `${m.card_id}:${m.metric_id}`
/** 一条查询的键:同一节点里按服务端的序号区分 */
export const queryKey = (q: Pick<RunCompareQuery, 'node_id' | 'ordinal'>) => `${q.node_id}:${q.ordinal}`
/**
* 「拆分或原因」一栏没有拆分时写的那句话:服务端写了「为什么没拆」就用它。无法比较、新增、移除的服务端不写这一项,
* 原因只在 reasons 里——退回写 reasons 的第一句(全部在展开的变化说明里),不让这一栏只剩一个「—」、要展开才知道
* 为什么。SQL 结构变的服务端一向写着,万一没写,reasons 说的就是哪条查询变了,也是不拆的原因。只数据变、只参数变、
* 未变的本来就用不着拆;口径与数据都变的服务端总会给拆分或原因,它的 reasons 说的是口径改了什么、不是为什么不拆,
* 都不退回
*/
const REASON_IN_CELL = new Set<string>(['incomparable', 'added', 'removed', 'sql_changed'])
export function splitReason(m: Pick<RunCompareMetric, 'classification' | 'decomposition_note' | 'reasons'>): string | null {
if (m.decomposition_note) return m.decomposition_note
return REASON_IN_CELL.has(m.classification) && m.reasons?.length ? m.reasons[0] : null
}
const isNum = (v: unknown): v is number => typeof v === 'number' && Number.isFinite(v)
@@ -92,19 +103,29 @@ export function sameValue(a: unknown, b: unknown): boolean {
}
}
/** 查询区的一项:位置键(同一对比里唯一)和同一节点里的「第 N 条」(节点只有一条时为 null) */
export interface QueryItem {
q: RunCompareQuery
key: string
nth: number | null
}
/**
* 同一节点有几条查询时,界面按 1 起数写「第 N 条」。服务端的 ordinal 只用来排先后:它从 0 还是从 1 数、中间有没有
* 空号(只有一边有的那条),都不该漏到界面上
* 查询区按服务端给的先后列:服务端已经按本次的先后排好,基准多出来的接在后面。同一节点有几条时,按在列表里出现的
* 先后从 1 数「第 N 条」,键是「节点:第几」。
*
* 不拿服务端的 ordinal 当键、也不按它编号:配上的一对取本次的序号,落单的基准查询取基准的序号,Agent 换了查询的先后
* 时两者会撞上(同一节点两条都是 1),按它当键 React 会报键冲突、编号会重复或缺号
*/
export function queryNumbers(queries: RunCompareQuery[]): Map<string, number | null> {
const byNode = new Map<string, RunCompareQuery[]>()
for (const q of queries) byNode.set(q.node_id, [...(byNode.get(q.node_id) ?? []), q])
const out = new Map<string, number | null>()
for (const list of byNode.values()) {
const sorted = [...list].sort((a, b) => a.ordinal - b.ordinal)
sorted.forEach((q, i) => out.set(queryKey(q), list.length > 1 ? i + 1 : null))
}
return out
export function queryItems(queries: RunCompareQuery[]): QueryItem[] {
const total = new Map<string, number>()
for (const q of queries) total.set(q.node_id, (total.get(q.node_id) ?? 0) + 1)
const seen = new Map<string, number>()
return queries.map((q) => {
const n = (seen.get(q.node_id) ?? 0) + 1
seen.set(q.node_id, n)
return { q, key: `${q.node_id}:${n}`, nth: (total.get(q.node_id) ?? 0) > 1 ? n : null }
})
}
/**
@@ -115,6 +136,14 @@ export type CompareErrorKind = '409' | '422' | '404' | 'no-base' | 'other'
/** 服务端「运行记录不存在」的机读码(api/evidence.py 的 RUN_NOT_FOUND,运行对比的接口沿用) */
const RUN_NOT_FOUND = 'run_not_found'
/** 409 的两种机读码(api/compare.py):没结束封存、封存核对不一致。标题按它分开写 */
export const UNSEALED = 'compare_unsealed'
export const SEAL_BROKEN = 'compare_seal_broken'
/** 请求回的是 404(记录不存在):和连不上、服务端出错分开说,前者重试也没用 */
export function isGone(e: unknown): boolean {
return e instanceof ApiError && e.kind === 'http' && e.status === 404
}
export function compareErrorKind(e: unknown, finding: boolean): CompareErrorKind {
if (!(e instanceof ApiError) || e.kind !== 'http') return 'other'
+60 -12
View File
@@ -1,9 +1,10 @@
import type { ReactNode } from 'react'
import { Link } from 'react-router-dom'
import { AlertTriangle } from 'lucide-react'
import { ApiError } from '../../../api/client'
import { ErrorState } from '../../../components/ui'
import { RUN_COMPARE_TEXT as T } from '../../../lib/terms'
import { classTone, type CompareErrorKind } from './model'
import { SEAL_BROKEN, UNSEALED, classTone, type CompareErrorKind } from './model'
/** 对比页的一节:带标题的卡片。count 写在标题旁(「11 个」),hint 是一句说明 */
export function Block({ id, title, count, hint, children, attr }: {
@@ -44,7 +45,7 @@ export function ClassChip({ value }: { value: string }) {
)
}
/** 查询的结构状态。结构变了用警示色并铺底(口径不同),新增用强调色,其余中性色 */
/** 查询的结构状态。结构变了用警示色并铺底(数不能直接比),新增用强调色,其余中性色 */
export function StructureChip({ value }: { value: string }) {
const warn = value === 'changed'
const color = warn ? 'var(--warn)' : value === 'added' ? 'var(--accent)' : 'var(--text-dim)'
@@ -55,19 +56,61 @@ export function StructureChip({ value }: { value: string }) {
)
}
const ERROR_TEXT: Record<Exclude<CompareErrorKind, 'other'>, { title: string; hint: string }> = {
'409': { title: T.errSealed, hint: T.errSealedHint },
'422': { title: T.errMismatch, hint: T.errMismatchHint },
'404': { title: T.errMissing, hint: T.errMissingHint },
'no-base': { title: T.errNoBase, hint: T.errNoBaseHint },
/** 页面上已经知道的几件事:错误说明的下一步按它挑,只指向这一刻真走得通的路 */
export interface CompareErrorContext {
/** 本次的运行记录读到了 */
targetKnown: boolean
/** 本次不属于已保存的工作流(没保存过、或者工作流已删除):和哪一次都比不了 */
targetUnsaved: boolean
/** 本次的运行记录上没有封存清单 */
targetUnsealed: boolean
/** 本次、基准的运行记录是不是 404 */
targetGone: boolean
baseGone: boolean
/** 换基准的下拉里有没有能选的运行(已封存、不是本次);还不知道(在读、读失败)时为 null */
pickable: boolean | null
}
/**
* 对比失败时的说明:先说是哪一种(未封存、不是同一工作流、运行不存在、找不到基准),再原样带上服务端的原因,
* 最后一句下一步。未封存、封存核对不一致的,给两次运行详情的入口:封存凭证条上能核对。别的错误按通用的出错态画
* 标题和下一步。标题说是哪一种;服务端的原因原样跟在标题后面(CompareError 里),下一步只写界面上真有的入口、
* 服务端已经写了的不再重复:
* - 409:按机读码分没结束封存、封存核对不一致。本次自己没封存时换基准也没用,不给下一步;否则说出在基准上时可以
* 在上方换(服务端的原因里写着是哪一次)。去记录页核对的入口是下面两个「查看」按钮,服务端的原因里也写了「核对」;
* - 422:本次不属于已保存的工作流时哪一次都比不了,标题直说、不给下一步;否则在上方另选同一工作流的一次;
* - 404:缺的是本次(targetGone)才是链接失效;缺的是基准(基准的记录 404,或者本次的记录读得到)就在上方另选;
* 还不知道是哪一边时先不说;
* - 找不到默认基准:本次不属于已保存的工作流同 422;下拉里有能选的才说可以在上方选,一次都没有就照实说
*/
export function CompareError({ kind, error, onRetry, target, base }: {
function errorCopy(kind: Exclude<CompareErrorKind, 'other'>, error: unknown, targetGone: boolean, ctx: CompareErrorContext): {
title: string; hint: string | null
} {
const code = error instanceof ApiError ? error.code : undefined
switch (kind) {
case '409': {
const title = code === SEAL_BROKEN ? T.errSealBroken : code === UNSEALED ? T.errUnsealed : T.errSealed
return { title, hint: code === UNSEALED && ctx.targetUnsealed ? null : T.errSealedHint }
}
case '422':
return ctx.targetUnsaved ? { title: T.errUnsaved, hint: null } : { title: T.errMismatch, hint: T.errMismatchHint }
case '404':
return {
title: T.errMissing,
hint: targetGone ? T.errMissingHint : ctx.baseGone || ctx.targetKnown ? T.errBaseMissingHint : null,
}
case 'no-base':
if (ctx.targetUnsaved) return { title: T.errUnsaved, hint: null }
return { title: T.errNoBase, hint: ctx.pickable == null ? null : ctx.pickable ? T.errNoBaseHint : T.errNoBaseNone }
}
}
/**
* 对比失败时的说明:先说是哪一种(未封存、封存核对不一致、不是同一工作流、运行不存在、找不到基准),再原样带上
* 服务端的原因,最后一句下一步(errorCopy)。未封存、封存核对不一致的,给两次运行详情的入口(运行详情上有「核对」);
* 本次的记录不存在时给去记录页的入口。别的错误按通用的出错态画,带重试
*/
export function CompareError({ kind, error, onRetry, target, base, context }: {
kind: CompareErrorKind; error: unknown; onRetry: () => void; target: string | null; base: string | null
context: CompareErrorContext
}) {
if (kind === 'other') {
return (
@@ -76,7 +119,9 @@ export function CompareError({ kind, error, onRetry, target, base }: {
</div>
)
}
const { title, hint } = ERROR_TEXT[kind]
// 缺的是不是本次:只带本次的地址(还没有基准)出的错来自找默认基准,那里的 404 只会是本次
const targetGone = !base || context.targetGone
const { title, hint } = errorCopy(kind, error, targetGone, context)
const reason = error instanceof Error ? error.message : ''
return (
<div
@@ -92,13 +137,16 @@ export function CompareError({ kind, error, onRetry, target, base }: {
<div className="min-w-0 flex-1 [overflow-wrap:anywhere]">
<div className="font-medium text-fg" data-compare-error-title="">{title}</div>
{reason && reason !== title && <div className="mt-0.5 text-dim">{reason}</div>}
<div className="mt-0.5 text-faint">{hint}</div>
{hint && <div className="mt-0.5 text-faint" data-compare-error-hint="">{hint}</div>}
{kind === '409' && (target || base) && (
<div className="mt-1.5 flex flex-wrap gap-2">
{base && <Link className="btn btn-sm" to={`/runs/${base}`}>{T.viewBase}</Link>}
{target && <Link className="btn btn-sm" to={`/runs/${target}`}>{T.viewTarget}</Link>}
</div>
)}
{kind === '404' && targetGone && (
<div className="mt-1.5"><Link className="btn btn-sm" to="/runs">{T.toRuns}</Link></div>
)}
</div>
</div>
)
+5 -3
View File
@@ -1,7 +1,7 @@
/**
* 两条 SQL 逐词对比:并排显示时标出各自独有的部分(结构变了的那条查询,差在哪一眼能看到)。
*
* 按词(名字、关键字、数、字符串、运算符)而不是按字符比:按字符比会把 created_at 和 paid_at 里碰巧相同的「_at」
* 按词(名字、关键字、数、字符串、运算符、注释)而不是按字符比:按字符比会把 created_at 和 paid_at 里碰巧相同的「_at」
* 当成没变,读起来支离破碎;按行比又太粗,模型写的 SQL 常常一整条写在一行里。关键字和不加引号的名字不分大小写
* (服务端的规范化也不算它们不同),字符串、加引号的名字照原样比。空白不参与比较,只是两个变了的词之间的空白也
* 跟着标,免得一段新加的条件被切成好几截。
@@ -26,8 +26,10 @@ export interface SqlDiff {
/** 逐词比较时动态规划表的格数上限(Uint32Array,4 MB) */
const CELL_LIMIT = 1_000_000
// 空白、字符串('' 转义)、加引号的名字("…"、`…`、[…])、名字和关键字、数、两个字符的运算符、其余单个字符
const TOKEN = /\s+|'(?:[^']|'')*'?|"(?:[^"]|"")*"?|`[^`]*`?|\[[^\]\s]*\]?|[\p{L}_][\p{L}\p{N}_$]*|\d+(?:\.\d+)?(?:[eE][+-]?\d+)?|<=|>=|<>|!=|\|\||::|[\s\S]/gu
// 空白、注释(-- 到行尾、/* … */,没收尾的到末尾)、字符串('' 转义)、加引号的名字("…"、`…`、[…])、名字和关键字、
// 数、两个字符的运算符、其余单个字符。注释整段算一个词,而且排在字符串前面:模型写的英文注释里常有 it's、user's,
// 把里面的撇号当成字符串的开头,会一直吞到下一个引号,后面没改的语句全被标成不同
const TOKEN = /\s+|--[^\n]*|\/\*[\s\S]*?(?:\*\/|$)|'(?:[^']|'')*'?|"(?:[^"]|"")*"?|`[^`]*`?|\[[^\]\s]*\]?|[\p{L}_][\p{L}\p{N}_$]*|\d+(?:\.\d+)?(?:[eE][+-]?\d+)?|<=|>=|<>|!=|\|\||::|[\s\S]/gu
interface Token {
text: string