mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-16 07:11:58 +00:00
W3-a 前端跟上:运行里的结构变化提醒、剖析清单里取值观察的说法
后端这一波新写的 schema.drift 事件、剖析任务里的取值观察检查,前端不跟上就是半截的: - run/decode.ts 认 schema.drift:时间线里一行警告(运行未被拦截),展开逐表写发布时和现在的结构版本、表删了写「表已删除」, 下面列出还没处理的结构变化;schemaDrift / schemaDriftLine 解析,和 catalog.drift 分开记、不混读版本号。 - 运行横幅(pages/runs/Banners.tsx):和 catalog.drift 共用同一块横幅(data-run-banner 不变)。只有结构变了时标题按结构说; 目录、结构都变了时结构另起一组带小标题;每张表给到数据目录的入口。RunDetailView 取最后一条 schema.drift 一并传进去。 - 剖析清单:取值观察的四类检查(行数、码值观察、最新业务日期、按日行数)在检查项、发过的查询、跳过的项里有中文叫法; 逐表进度多一类「取值观察 N/M」(后端 checks_by_kind 加 observe 一组)。剖析的范围、任务的触发(定时维护建的)进类型。 - 文案进 lib/terms.ts(SCHEMA_DRIFT_TEXT:叫「结构变化」,和已有的「目录有变化」分开,X10)。 - 检查脚本:check-decode 加 schema.drift 一节(标题、警告级、逐表版本、表已删除、另有几条、形状不对不出行),check-runs 加一节(只有结构变化、目录和结构都变了两种情形下的同一块横幅、入口链接、时间线一行、运行照常完成)。 验证:tsc、check-copy;decode 680、runs 327、catalog-profile 191、stream 461、publish 285 项全过。
This commit is contained in:
@@ -2781,6 +2781,26 @@ export const CATALOG_DRIFT_TEXT = {
|
||||
possibleNone: (source: string) => `「${source}」发布时还没有目录`,
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布之后表结构有变化(schema.drift,next-round 03 B1):和目录有变化合在同一块横幅里,分开一组说。叫「结构变化」,和已经
|
||||
* 在用的「目录有变化」分开(X10)
|
||||
*/
|
||||
export const SCHEMA_DRIFT_TEXT = {
|
||||
/** 运行里的提醒:「自发布以来,「订单」等 2 张表的结构有变化」 */
|
||||
title: (first: string, n: number) => (n > 1
|
||||
? `自发布以来,「${first}」等 ${formatNumber(n)} 张表的结构有变化`
|
||||
: `自发布以来,「${first}」的结构有变化`),
|
||||
/** 横幅里目录、结构都变了:结构这一组的小标题 */
|
||||
head: '结构变化',
|
||||
sub: '运行未被拦截。只是加了列不影响这次结果;删了列、改了类型时,写死的 SQL 可能报错或算错,请核对',
|
||||
/** 一张表的那一行:「shop」订单(orders):结构第 1 版 → 第 2 版 */
|
||||
line: (source: string, table: string, from: number, to: number | null, removed: boolean) =>
|
||||
`「${source}」${table}:${removed ? '表已删除' : `结构第 ${formatNumber(from)} 版 → 第 ${formatNumber(to ?? 0)} 版`}`,
|
||||
/** 还有几条没处理的变化没列出来 */
|
||||
more: (n: number) => `…另有 ${formatNumber(n)} 条结构变化`,
|
||||
severity: { info: '说明', warning: '提醒', action: '要处理' } as Record<string, string>,
|
||||
}
|
||||
|
||||
/**
|
||||
* 表结构只探查了一部分:探查结构时每个数据源最多取 200 张表(服务端 introspect._MAX_TABLES),多出来的表不在
|
||||
* 表结构里,数据目录列不出,助手也看不到它们的字段。数据目录页顶部和助手「参考了哪些表」那一行都要说出来。
|
||||
@@ -3149,7 +3169,10 @@ export const PROFILE_TEXT = {
|
||||
taskStatus: {
|
||||
pending: '排队', running: '剖析中', ok: '完成', partial: '部分完成', failed: '失败', skipped: '跳过', cancelled: '已停止',
|
||||
} as Record<CatalogDraftTaskStatus, string>,
|
||||
checkKind: { relation: '关系', codes: '码值', date: '日期' } as Record<string, string>,
|
||||
checkKind: {
|
||||
relation: '关系', codes: '码值', date: '日期', observe: '取值观察',
|
||||
rows: '行数', codes_observe: '码值观察', freshness: '最新业务日期', daily_volume: '按日行数',
|
||||
} as Record<string, string>,
|
||||
kindProgress: (label: string, done: number, total: number) => `${label} ${formatNumber(done)}/${formatNumber(total)}`,
|
||||
tableQueries: (n: number) => `${formatNumber(n)} 条查询`,
|
||||
/** 这张表的查询次数用完了(等于每张表最多查询数) */
|
||||
@@ -3199,7 +3222,10 @@ export const PROFILE_TEXT = {
|
||||
moreSkipped: (n: number) => `…另有 ${formatNumber(n)} 项`,
|
||||
queriesTitle: (n: number) => `看发过的查询(${formatNumber(n)} 条)`,
|
||||
queriesHint: 'SQL 里的取值都换成了「?」:取到的键值不保存在 AgentLab 中;遮罩的列不出现在任何查询里',
|
||||
queryKind: { row_estimate: '行数估算', relation: '关系', codes: '码值', date: '日期' } as Record<string, string>,
|
||||
queryKind: {
|
||||
row_estimate: '行数估算', relation: '关系', codes: '码值', date: '日期',
|
||||
codes_observe: '码值观察', freshness: '最新业务日期', daily_volume: '按日行数',
|
||||
} as Record<string, string>,
|
||||
queryOutcome: { ok: '成功', timeout: '超时', error: '失败', rejected: '未通过只读守卫' } as Record<string, string>,
|
||||
queryRows: (n: number) => `${formatNumber(n)} 行`,
|
||||
queryMs: (ms: number) => `${formatNumber(ms)} 毫秒`,
|
||||
@@ -3311,6 +3337,10 @@ export const PROFILE_SKIP_KIND_LABEL: Record<string, string> = {
|
||||
date: '日期列',
|
||||
row_estimate: '行数估算',
|
||||
table: '整张表',
|
||||
rows: '行数观察',
|
||||
codes_observe: '码值观察',
|
||||
freshness: '最新业务日期',
|
||||
daily_volume: '按日行数',
|
||||
}
|
||||
|
||||
/** 码值候选:剖析只知道出现过哪些取值,含义等人填 */
|
||||
|
||||
@@ -565,9 +565,9 @@ export const PROFILE_TASK_ICON: Record<CatalogProfileTaskStatus, { Icon: LucideI
|
||||
cancelled: { Icon: CircleSlash, color: 'var(--text-faint)' },
|
||||
}
|
||||
|
||||
/** 各类检查的进度:「关系 3/4 · 码值 5/6 · 日期 1/1」,这类没有检查的不写 */
|
||||
/** 各类检查的进度:「关系 3/4 · 码值 5/6 · 日期 1/1 · 取值观察 4/4」,这类没有检查的不写 */
|
||||
export function checksText(t: Pick<CatalogProfileTaskRow, 'checks_by_kind'>): string {
|
||||
return (['relation', 'codes', 'date'] as const)
|
||||
return (['relation', 'codes', 'date', 'observe'] as const)
|
||||
.map((k) => {
|
||||
const [done, total] = t.checks_by_kind?.[k] ?? [0, 0]
|
||||
return total > 0 ? PT.kindProgress(PT.checkKind[k], done, total) : ''
|
||||
|
||||
@@ -3,9 +3,9 @@ import { Link } from 'react-router-dom'
|
||||
import { ArrowDown, Ban, BookMarked, ChartGantt, Copy, Crosshair, Play, RotateCcw, Settings2, Wrench, X } from 'lucide-react'
|
||||
import { CopyButton, Spinner, StatusBadge } from '../../components/ui'
|
||||
import { formatDateTime, formatSpan, formatTime } from '../../lib/format'
|
||||
import type { Approval, CatalogDriftTable } from '../../types'
|
||||
import { CATALOG_DRIFT_TEXT, CATALOG_IMPACT_TEXT } from '../../lib/terms'
|
||||
import { catalogDriftLine } from '../../run/decode'
|
||||
import type { Approval, CatalogDriftTable, SchemaDriftTable } from '../../types'
|
||||
import { CATALOG_DRIFT_TEXT, CATALOG_IMPACT_TEXT, SCHEMA_DRIFT_TEXT } from '../../lib/terms'
|
||||
import { catalogDriftLine, schemaDriftLine } from '../../run/decode'
|
||||
import type { RunErrorExplain } from '../../lib/explain'
|
||||
import { LONG_WAIT_MS, ageMs } from './model'
|
||||
import { copyText } from './parts'
|
||||
@@ -25,33 +25,49 @@ function Shell({ color, children, data }: { color: string; children: ReactNode;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// 发布之后数据目录有变化(catalog.drift)
|
||||
// 发布之后数据目录有变化(catalog.drift)、表结构有变化(schema.drift):同一块横幅
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 从发布版本发起的正式运行,开始时发现这一版用到的表的数据目录在发布之后改过。运行照常(目录是说明,
|
||||
* 不是运行的输入),但看结果的人要知道:「在园人数」在发布之后被改成了存量,这一版的 SQL 可能还在跨天相加。
|
||||
* SQL 里写着的表在前;Agent 可能查询的表(Agent 运行时自己写 SQL)另起一组、带小标题,和直接引用分开。
|
||||
* 每张表给到数据目录的入口;每组表多时只列前几张
|
||||
* 每张表给到数据目录的入口;每组表多时只列前几张。
|
||||
*
|
||||
* 表结构在发布之后变了(schema.drift:删了列、改了类型……)也在这一块里另起一组:每张表写发布时和现在的结构版本,
|
||||
* 下面列出还没处理的结构变化。只有结构变了时标题按结构说。同样只提醒、不拦
|
||||
*/
|
||||
export function CatalogDriftBanner({ drift }: {
|
||||
drift: { title: string; direct: CatalogDriftTable[]; possible: CatalogDriftTable[] }
|
||||
export function CatalogDriftBanner({ drift, schema }: {
|
||||
drift: { title: string; direct: CatalogDriftTable[]; possible: CatalogDriftTable[] } | null
|
||||
schema?: { title: string; tables: SchemaDriftTable[] } | null
|
||||
}) {
|
||||
if (!drift && !schema) return null
|
||||
return (
|
||||
<Shell color="var(--st-waiting)" data="catalog-drift">
|
||||
<div className="flex items-start gap-2.5">
|
||||
<BookMarked size={14} className="mt-0.5 shrink-0" style={{ color: 'var(--st-waiting)' }} aria-hidden />
|
||||
<div className="min-w-0 flex-1 text-xs">
|
||||
<p className="font-semibold" data-drift-title="">{drift.title}</p>
|
||||
<p className="mt-0.5 text-2xs text-dim">{CATALOG_DRIFT_TEXT.sub}</p>
|
||||
{drift.direct.length > 0 && <DriftTables tables={drift.direct} />}
|
||||
{drift.possible.length > 0 && (
|
||||
<p className="font-semibold" data-drift-title="">{drift ? drift.title : schema!.title}</p>
|
||||
<p className="mt-0.5 text-2xs text-dim">{drift ? CATALOG_DRIFT_TEXT.sub : SCHEMA_DRIFT_TEXT.sub}</p>
|
||||
{drift && drift.direct.length > 0 && <DriftTables tables={drift.direct} />}
|
||||
{drift && drift.possible.length > 0 && (
|
||||
<div className="mt-1.5" data-drift-possible={drift.possible.length}>
|
||||
<p className="text-2xs font-medium text-dim">{CATALOG_DRIFT_TEXT.possibleHead}</p>
|
||||
<p className="text-2xs text-faint">{CATALOG_DRIFT_TEXT.possibleHint}</p>
|
||||
<DriftTables tables={drift.possible} />
|
||||
</div>
|
||||
)}
|
||||
{schema && schema.tables.length > 0 && (
|
||||
<div className={drift ? 'mt-1.5' : undefined} data-drift-schema={schema.tables.length}>
|
||||
{drift && (
|
||||
<>
|
||||
<p className="text-2xs font-medium text-dim">{SCHEMA_DRIFT_TEXT.head}:{schema.title}</p>
|
||||
<p className="text-2xs text-faint">{SCHEMA_DRIFT_TEXT.sub}</p>
|
||||
</>
|
||||
)}
|
||||
<SchemaTables tables={schema.tables} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Shell>
|
||||
@@ -79,6 +95,40 @@ function DriftTables({ tables }: { tables: CatalogDriftTable[] }) {
|
||||
)
|
||||
}
|
||||
|
||||
/** 结构变了的表:一行版本,下面缩进列出还没处理的结构变化(服务端的一句话,带严重程度) */
|
||||
function SchemaTables({ tables }: { tables: SchemaDriftTable[] }) {
|
||||
const shown = tables.slice(0, DRIFT_SHOWN)
|
||||
return (
|
||||
<ul className="mt-1 space-y-1 text-2xs text-dim">
|
||||
{shown.map((t) => (
|
||||
<li key={`${t.source}/${t.table}`} className="min-w-0" data-drift-schema-table={t.table} data-removed={t.removed || undefined}>
|
||||
<span className="flex min-w-0 flex-wrap items-baseline gap-x-2">
|
||||
<span className="min-w-0 break-words">{schemaDriftLine(t)}</span>
|
||||
{t.source_id && !t.removed && (
|
||||
<Link className="shrink-0 text-[var(--accent)] hover:underline" data-drift-open={t.table}
|
||||
to={`/data/catalog/${encodeURIComponent(t.source_id)}/${encodeURIComponent(t.table)}`}>
|
||||
{CATALOG_DRIFT_TEXT.open}
|
||||
</Link>
|
||||
)}
|
||||
</span>
|
||||
{t.changes.length > 0 && (
|
||||
<ul className="mt-0.5 space-y-0.5 pl-3 text-faint">
|
||||
{t.changes.map((c) => (
|
||||
<li key={c.id || c.summary} className="min-w-0 break-words" data-drift-change={c.kind} data-severity={c.severity}>
|
||||
<span className={c.severity === 'action' ? 'text-[var(--warn)]' : undefined}>{SCHEMA_DRIFT_TEXT.severity[c.severity]}</span>
|
||||
{' · '}{c.summary}
|
||||
</li>
|
||||
))}
|
||||
{t.more > 0 && <li>{SCHEMA_DRIFT_TEXT.more(t.more)}</li>}
|
||||
</ul>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
{tables.length > shown.length && <li className="text-faint">{CATALOG_IMPACT_TEXT.more(tables.length - shown.length)}</li>}
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
|
||||
const DRIFT_SHOWN = 6
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
import { formatDateTime, formatNumber, formatTime, shortId } from '../../lib/format'
|
||||
import { resolveStatus, statusLabel, type StatusCode } from '../../lib/status'
|
||||
import { AssistantStream, type StreamTurn, type TurnFailure } from '../../run/AssistantStream'
|
||||
import { catalogDrift, decodePhase, decodeRun, exitLabels, summarizeRun, type RunFinal } from '../../run/decode'
|
||||
import { catalogDrift, decodePhase, decodeRun, exitLabels, schemaDrift, summarizeRun, type RunFinal } from '../../run/decode'
|
||||
import { sourceHandles } from '../../canvas/nodeDefs'
|
||||
import { EffectsPane, RunTaskCards, useRunTasks } from './RunTasks'
|
||||
import { OriginChip } from './RunList'
|
||||
@@ -554,6 +554,9 @@ export function RunDetailView({ runId, onChange, onDeleted }: {
|
||||
// 上面有提前返回,这里不能再用 hook;只解一条事件,直接算
|
||||
const catalogEvent = lastOf(d.events, 'catalog.drift')
|
||||
const catalogChange = catalogEvent ? catalogDrift(catalogEvent.data ?? {}) : null
|
||||
// 表结构在发布之后变了(schema.drift):和目录变化合在同一块横幅里
|
||||
const schemaEvent = lastOf(d.events, 'schema.drift')
|
||||
const schemaChange = schemaEvent ? schemaDrift(schemaEvent.data ?? {}) : null
|
||||
const unsaved = isUnsaved(run)
|
||||
const artifactCount = artifacts.items?.length
|
||||
const viewTabs: TabItem<DetailView>[] = [
|
||||
@@ -652,7 +655,7 @@ export function RunDetailView({ runId, onChange, onDeleted }: {
|
||||
<WaitingBanner approvals={d.pending} labelOf={labelOf} onJump={jumpToApproval}
|
||||
onAbandon={() => void abandon()} busy={busy === 'abandon'} now={now} />
|
||||
)}
|
||||
{catalogChange && <CatalogDriftBanner drift={catalogChange} />}
|
||||
{(catalogChange || schemaChange) && <CatalogDriftBanner drift={catalogChange} schema={schemaChange} />}
|
||||
{feedback && <FeedbackStrip feedback={feedback} onDismiss={() => setFeedback(null)} />}
|
||||
<div className="flex items-center border-t pr-2">
|
||||
<RunTabs tabs={viewTabs} active={view} onChange={setView} label="运行详情视图" idPrefix="run-view"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { CatalogDriftTable, RunEvent, SqlCheckItem, TeamMember, TeamRound, TeamRun, ToolChange } from '../types'
|
||||
import type { CatalogDriftTable, RunEvent, SchemaDriftTable, SqlCheckItem, TeamMember, TeamRound, TeamRun, ToolChange } from '../types'
|
||||
import type { NodeState, RunPhase } from './trace'
|
||||
import type { LookEvent, LookObject, TaskKind } from '../typesApp'
|
||||
import { formatDuration, formatNumber } from '../lib/format'
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
ORIGIN_TEXT, RUN_SQL_CHECK_TEXT, SQL_CHECK_TEXT, TASK_KIND_LABEL, TASK_LOG_TEXT, TASK_STATUS_LABEL, TASK_TEXT, TYPE_LABEL, originLabel,
|
||||
CATALOG_TABLE_FIELD_LABEL, CHALLENGE_TEXT, DUAL_CHECK_TEXT, INQUIRY_TEXT, JUDGE_TRUNCATED_TEXT, MASKED_CELL_TEXT, NODE_TYPE_LABEL,
|
||||
VERIFY_TRUNCATED_TEXT, BP_OP_TEXT, TEMPLATE_LABEL, bpPathText, FILE_TEXT, REJECTED_TEXT, LEDGER_TEXT,
|
||||
SCHEMA_DRIFT_TEXT,
|
||||
claimTally,
|
||||
evidenceTally, issuanceLabel, nodeTypeLabel,
|
||||
} from '../lib/terms'
|
||||
@@ -2433,6 +2434,17 @@ export function decodeRun(events: RunEvent[], final?: RunFinal, opts?: DecodeOpt
|
||||
break
|
||||
}
|
||||
|
||||
case 'schema.drift': {
|
||||
// 从发布版本发起的正式运行:发布之后这一版直接引用的表的结构变了(next-round 03 B1)。只提醒、运行照常,同目录漂移
|
||||
const drift = schemaDrift(d)
|
||||
if (!drift) break
|
||||
out.push({
|
||||
id: `sd-${seq}`, seq, kind: 'note', level: 'warn', status: 'done', code: 'schema_drift',
|
||||
title: drift.title, sub: SCHEMA_DRIFT_TEXT.sub, detail: drift.detail,
|
||||
})
|
||||
break
|
||||
}
|
||||
|
||||
case 'caliber.upgrade':
|
||||
out.push({
|
||||
id: `cu-${seq}`, seq, kind: 'note', level: 'warn', status: 'done',
|
||||
@@ -3213,6 +3225,40 @@ export function catalogDrift(d: Record<string, any>): {
|
||||
}
|
||||
}
|
||||
|
||||
/** 一张表的那一行:「shop」订单(orders):结构第 1 版 → 第 2 版(删了的写「表已删除」) */
|
||||
export function schemaDriftLine(t: SchemaDriftTable): string {
|
||||
return SCHEMA_DRIFT_TEXT.line(t.source, CATALOG_DRIFT_TEXT.table(t.label, t.table), t.published, t.current, t.removed)
|
||||
}
|
||||
|
||||
/**
|
||||
* schema.drift 事件 → 提醒的标题和逐表明细。每张表一行(发布时和现在的结构版本),下面缩进列出这张表上还没处理的结构
|
||||
* 变化(服务端给的一句话,最多 5 条,多的写「另有 N 条」)。认不出的形状返回 null
|
||||
*/
|
||||
export function schemaDrift(d: Record<string, any>): { title: string; detail: string; tables: SchemaDriftTable[] } | null {
|
||||
const tables: SchemaDriftTable[] = (Array.isArray(d?.tables) ? d.tables : [])
|
||||
.filter((t: any) => t && typeof t === 'object' && typeof t.table === 'string' && typeof t.source === 'string')
|
||||
.map((t: any) => ({
|
||||
source: t.source, source_id: String(t.source_id ?? ''), table: t.table,
|
||||
label: typeof t.label === 'string' && t.label ? t.label : null,
|
||||
published: num(t.published) ?? 0, current: t.removed ? null : (num(t.current) ?? null), removed: !!t.removed,
|
||||
changes: (Array.isArray(t.changes) ? t.changes : [])
|
||||
.filter((c: any) => c && typeof c === 'object' && typeof c.summary === 'string')
|
||||
.map((c: any) => ({ id: String(c.id ?? ''), kind: String(c.kind ?? ''), column: typeof c.column === 'string' ? c.column : null,
|
||||
severity: c.severity === 'action' || c.severity === 'warning' ? c.severity : 'info', summary: c.summary })),
|
||||
more: num(t.more) ?? 0,
|
||||
}))
|
||||
if (!tables.length) return null
|
||||
return {
|
||||
title: SCHEMA_DRIFT_TEXT.title(tables[0].label ?? tables[0].table, tables.length),
|
||||
detail: tables.flatMap((t) => [
|
||||
schemaDriftLine(t),
|
||||
...t.changes.map((c) => ` · ${c.summary}`),
|
||||
...(t.more ? [` ${SCHEMA_DRIFT_TEXT.more(t.more)}`] : []),
|
||||
]).join('\n'),
|
||||
tables,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* look 事件(L2,服务端 app/look/base.py 的形状)读进来:objects 按类型标记;字段缺了的补空,认不出的形状返回 null
|
||||
* (不出这一行,也不报错)。旧写法 sources[] 当作表类型读
|
||||
|
||||
+36
-6
@@ -64,6 +64,10 @@ export interface WorkflowVersion {
|
||||
catalog_versions?: CatalogVersions | null
|
||||
/** 发布之后目录有变化的表 */
|
||||
catalog_changes?: CatalogDriftTable[]
|
||||
/** 发布时记下的表结构版本 {源名: {表名: 结构版本}}(只记写死的 SQL 直接引用的表);记录之前发布的为 null */
|
||||
schema_versions?: Record<string, Record<string, number>> | null
|
||||
/** 发布之后结构版本变了的表 */
|
||||
schema_changes?: SchemaDriftTable[]
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,6 +95,26 @@ export interface CatalogDriftTable {
|
||||
impact: 'direct' | 'possible'
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布之后表结构变了的一张表(服务端 catalog_impact.schema_drift;运行里的 schema.drift 事件同形)。和目录有变化
|
||||
* (CatalogDriftTable)分开记:这里的版本是表结构版本,不是目录版本
|
||||
*/
|
||||
export interface SchemaDriftTable {
|
||||
source: string
|
||||
source_id: string
|
||||
table: string
|
||||
/** 表现在的中文名 */
|
||||
label: string | null
|
||||
/** 发布时的结构版本 */
|
||||
published: number
|
||||
/** 现在的结构版本;表已删除时为 null */
|
||||
current: number | null
|
||||
removed: boolean
|
||||
/** 发布之后测到、还没处理的结构变化(最多 5 条,more 是另外还有几条) */
|
||||
changes: { id: string; kind: string; column: string | null; severity: 'info' | 'warning' | 'action'; summary: string }[]
|
||||
more: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端写进 runs.status 的值。interrupted 既可能是停在审批上,也可能是服务重启
|
||||
* 打断后挂起——显示时用 lib/status 的 resolveStatus 配合审批列表区分。
|
||||
@@ -3367,8 +3391,11 @@ export interface CatalogProfileSettings {
|
||||
/** 为什么需要剖析(GET /catalog 每行的 profile_due_reason) */
|
||||
export type CatalogProfileDueReason = 'never' | 'unfinished' | 'new_relations' | 'new_checks'
|
||||
|
||||
/** 剖析的范围:selected 指定的表;needed 需要剖析的表;all 全部可剖析的表(不含视图) */
|
||||
export type CatalogProfileScope = 'selected' | 'needed' | 'all'
|
||||
/**
|
||||
* 剖析的范围:selected 指定的表;needed 需要剖析的表;all 全部可剖析的表(不含视图);observe 观察到期的表(只做取值观察);
|
||||
* maintenance 定时维护(需要剖析的表 + 观察到期的表)。后两种由定时维护建,界面不发起
|
||||
*/
|
||||
export type CatalogProfileScope = 'selected' | 'needed' | 'all' | 'observe' | 'maintenance'
|
||||
|
||||
/**
|
||||
* 剖析任务的状态:排队、进行中、完成、部分完成(有失败、部分完成、已停止的表)、失败(任务整体出错)、已停止(使用者停止)、
|
||||
@@ -3386,8 +3413,8 @@ export type CatalogProfileTaskStatus = CatalogDraftTaskStatus
|
||||
export type CatalogProfileSkipReason = 'budget' | 'deadline' | 'failed' | 'timeout' | 'error' | 'rejected' | 'slow' | 'cancelled'
|
||||
| 'masked' | 'too_large' | 'view' | 'unsupported' | 'no_data' | 'missing' | 'high_cardinality' | 'nothing'
|
||||
|
||||
/** 一类检查:关联关系、码值、日期列 */
|
||||
export type CatalogProfileCheckKind = 'relation' | 'codes' | 'date'
|
||||
/** 一类检查:关联关系、码值、日期列;取值观察的四类(行数、码值观察、最新业务日期、按日行数) */
|
||||
export type CatalogProfileCheckKind = 'relation' | 'codes' | 'date' | 'rows' | 'codes_observe' | 'freshness' | 'daily_volume'
|
||||
|
||||
/** 发现的合计(任务里是逐表合计) */
|
||||
export interface CatalogProfileSummary {
|
||||
@@ -3482,8 +3509,8 @@ export interface CatalogProfileTaskRow {
|
||||
checks_total: number
|
||||
/** 结束了的项(含跳过的) */
|
||||
checks_done: number
|
||||
/** 每类检查 [结束了的, 一共];这类没有检查时是 [0, 0] */
|
||||
checks_by_kind: Record<CatalogProfileCheckKind, [number, number]>
|
||||
/** 每类检查 [结束了的, 一共];这类没有检查时是 [0, 0]。取值观察的四类合成 observe 一类(老服务端不给) */
|
||||
checks_by_kind: Partial<Record<'relation' | 'codes' | 'date' | 'observe', [number, number]>>
|
||||
/** 进行中时正在做哪一项的整句(如「正在核对 orders.customer_id → customers.id」);其余时候 null */
|
||||
current: string | null
|
||||
queries: number
|
||||
@@ -3562,6 +3589,9 @@ export interface CatalogProfileJob {
|
||||
created_by: string | null
|
||||
/** 重试建的任务记着原任务的 id */
|
||||
retry_of: string | null
|
||||
/** manual 人点的;schedule 定时维护建的(fire_at 是那一次触发的计划时刻)。老服务端不给 */
|
||||
trigger?: 'manual' | 'schedule'
|
||||
fire_at?: string | null
|
||||
/** 排在同一个数据源的起草任务后面:起草结束后自动开始。不在等时为 null */
|
||||
waiting_for: 'draft' | 'introspect' | null
|
||||
total: number
|
||||
|
||||
@@ -857,6 +857,33 @@ await section('正式运行:发布之后数据目录有变化(catalog.drift
|
||||
.every((s) => s.code !== 'catalog_drift'))
|
||||
})
|
||||
|
||||
await section('正式运行:发布之后表结构有变化(schema.drift 事件)', async () => {
|
||||
const steps = mod.decodeRun([
|
||||
{ seq: 1, type: 'run.started', node_id: null, ts: 1, data: { nodes: 1 } },
|
||||
{ seq: 2, type: 'schema.drift', node_id: null, ts: 1.01, data: { version: 2, count: 2, tables: [
|
||||
{ source: 'shop', source_id: 'src-shop', table: 'orders', label: '订单', published: 1, current: 2, removed: false,
|
||||
changes: [{ id: 'c1', kind: 'column_removed', column: 'status', severity: 'action', summary: 'orders.status:删除了列' },
|
||||
{ id: 'c2', kind: 'column_type_changed', column: 'amount', severity: 'warning', summary: 'orders.amount:列的类型变了' }],
|
||||
more: 3 },
|
||||
{ source: 'shop', source_id: 'src-shop', table: 'refunds', label: null, published: 4, current: null, removed: true,
|
||||
changes: [], more: 0 },
|
||||
] } },
|
||||
])
|
||||
const row = steps.find((s) => s.code === 'schema_drift')
|
||||
check('一行提醒:「订单」等 2 张表的结构有变化', row?.title === '自发布以来,「订单」等 2 张表的结构有变化', row?.title)
|
||||
check('是警告、不是失败', row?.level === 'warn' && row?.status === 'done' && row?.kind === 'note')
|
||||
check('副标题写明运行未被拦截', !!row?.sub?.includes('运行未被拦截'), row?.sub)
|
||||
check('展开逐表写结构版本,表删了写「表已删除」', !!row?.detail?.includes('「shop」订单(orders):结构第 1 版 → 第 2 版')
|
||||
&& row.detail.includes('「shop」refunds:表已删除'), row?.detail)
|
||||
check('……下面列出还没处理的变化和另有几条', !!row?.detail?.includes('· orders.status:删除了列')
|
||||
&& row.detail.includes('另有 3 条结构变化'), row?.detail)
|
||||
const one = mod.schemaDrift({ tables: [{ source: 's', table: 't', published: 1, current: 2 }] })
|
||||
check('只有一张表:标题不写「等」', one?.title === '自发布以来,「t」的结构有变化', one?.title)
|
||||
check('和目录漂移分开记:catalog.drift 的解析不认它', mod.catalogDrift({ tables: [] }) === null)
|
||||
check('形状不对不出行', mod.decodeRun([{ seq: 1, type: 'schema.drift', node_id: null, ts: 1, data: { tables: 'x' } }])
|
||||
.every((s) => s.code !== 'schema_drift'))
|
||||
})
|
||||
|
||||
await section('Copilot:心跳穿插、回话、少了一步、报错', async () => {
|
||||
const steps = mod.decodeCopilot(synthetic.COPILOT_STUCK, { context: 'canvas' })
|
||||
check('心跳穿插的思考仍然并成一条', steps.filter((s) => s.kind === 'think').length === 1,
|
||||
|
||||
@@ -796,6 +796,65 @@ await section('正式运行:发布之后数据目录有变化,提醒但不
|
||||
for (const k of [`GET /api/runs/${id}`, `GET /api/runs/${id}/events`, `GET /api/runs/${id}/graph`]) fakes.delete(k)
|
||||
})
|
||||
|
||||
// ------------------------------------------------------------------ 发布之后表结构有变化(schema.drift)
|
||||
|
||||
await section('正式运行:发布之后表结构有变化,和目录变化同一块横幅,提醒但不拦', async () => {
|
||||
const id = 'fake0schemadrift000000000000000'
|
||||
const t = Date.now() / 1000 - 30
|
||||
const run = {
|
||||
...base, id, status: 'succeeded', run_class: 'formal', version: 2, workflow_id: null,
|
||||
created_at: new Date(t * 1000).toISOString(), started_at: new Date(t * 1000).toISOString(),
|
||||
finished_at: new Date((t + 2) * 1000).toISOString(), output: { 结果: '共 12 单' },
|
||||
}
|
||||
const graph = { nodes: [
|
||||
{ id: 'a', type: 'input', position: { x: 0, y: 0 }, data: { label: '输入', config: {} } },
|
||||
{ id: 'q', type: 'tool', position: { x: 200, y: 0 }, data: { label: '查订单', config: {} } },
|
||||
], edges: [{ source: 'a', target: 'q' }] }
|
||||
const schemaTables = [
|
||||
{ source: 'shop', source_id: 'src-shop', table: 'orders', label: '订单', published: 1, current: 2, removed: false,
|
||||
changes: [{ id: 'c1', kind: 'column_removed', column: 'status', severity: 'action', summary: 'orders.status:删除了列' }],
|
||||
more: 0 },
|
||||
]
|
||||
const events = (withCatalog) => [
|
||||
{ seq: 1, type: 'run.started', node_id: null, ts: t, data: { nodes: 2 } },
|
||||
...(withCatalog ? [{ seq: 2, type: 'catalog.drift', node_id: null, ts: t + 0.01, data: { version: 2, count: 1, tables: [
|
||||
{ source: 'shop', source_id: 'src-shop', table: 'orders', label: '订单', published: 3, current: 4, impact: 'direct' },
|
||||
] } }] : []),
|
||||
{ seq: 3, type: 'schema.drift', node_id: null, ts: t + 0.02, data: { version: 2, count: 1, tables: schemaTables } },
|
||||
{ seq: 4, type: 'node.started', node_id: 'a', ts: t + 0.1, data: {} },
|
||||
{ seq: 5, type: 'node.finished', node_id: 'a', ts: t + 0.2, data: { duration_ms: 100 } },
|
||||
{ seq: 6, type: 'node.started', node_id: 'q', ts: t + 0.3, data: {} },
|
||||
{ seq: 7, type: 'node.finished', node_id: 'q', ts: t + 0.4, data: { duration_ms: 100 } },
|
||||
{ seq: 8, type: 'run.finished', node_id: null, ts: t + 2, data: { output: run.output } },
|
||||
]
|
||||
let withCatalog = false
|
||||
fakes.set(`GET /api/runs/${id}`, () => ({ status: 200, json: run }))
|
||||
fakes.set(`GET /api/runs/${id}/events`, () => ({ status: 200, json: events(withCatalog) }))
|
||||
fakes.set(`GET /api/runs/${id}/graph`, () => ({ status: 200, json: { graph, workflow_id: null, version: 2 } }))
|
||||
await page.goto(`${WEB}/runs/${id}`, { waitUntil: 'networkidle' })
|
||||
const banner = page.locator('[data-run-banner="catalog-drift"]')
|
||||
check('只有结构变了:照样是那一块横幅', await banner.waitFor({ timeout: 5000 }).then(() => true, () => false))
|
||||
let text = await banner.innerText().catch(() => '')
|
||||
check('标题按结构说', text.includes('自发布以来,「订单」的结构有变化'), text.split('\n')[0])
|
||||
check('写明运行未被拦截', text.includes('运行未被拦截'))
|
||||
check('逐表写结构版本、列出还没处理的变化', text.includes('「shop」订单(orders):结构第 1 版 → 第 2 版')
|
||||
&& text.includes('要处理 · orders.status:删除了列'), text.replace(/\s+/g, ' '))
|
||||
check('给到数据目录的入口', (await banner.locator('[data-drift-schema-table="orders"] [data-drift-open="orders"]')
|
||||
.getAttribute('href')) === '/data/catalog/src-shop/orders')
|
||||
check('时间线里也有一行提醒', await page.locator('[data-step-code="schema_drift"]').count() === 1)
|
||||
|
||||
withCatalog = true
|
||||
await page.goto(`${WEB}/runs/${id}`, { waitUntil: 'networkidle' })
|
||||
await banner.waitFor({ timeout: 5000 }).catch(() => {})
|
||||
text = await banner.innerText().catch(() => '')
|
||||
check('目录、结构都变了:仍是一块横幅', await page.locator('[data-run-banner="catalog-drift"]').count() === 1)
|
||||
check('……标题按目录说,结构另起一组带小标题', text.includes('自发布以来,数据目录中「订单」有变化')
|
||||
&& text.includes('结构变化:自发布以来,「订单」的结构有变化'), text.replace(/\s+/g, ' '))
|
||||
check('……结构那一组逐表一行', await banner.locator('[data-drift-schema] [data-drift-schema-table="orders"]').count() === 1)
|
||||
check('运行照常完成:没有失败横幅', await page.locator('[data-run-banner=failed]').count() === 0)
|
||||
for (const k of [`GET /api/runs/${id}`, `GET /api/runs/${id}/events`, `GET /api/runs/${id}/graph`]) fakes.delete(k)
|
||||
})
|
||||
|
||||
// ------------------------------------------------------------------ 运行中:接流、停止、不能删
|
||||
|
||||
const FAKE = 'fake0running0000000000000000000'
|
||||
|
||||
Reference in New Issue
Block a user