ソースを参照

chore(repo): 从版本库移除 .scratch 验证脚本并保留本地文件

ChenJZ 6 時間 前
親
コミット
9a19cdddad

+ 0 - 78
.scratch/cockpit-shell-panel-layout/verify/t56-latest-detail-chain.mjs

@@ -1,78 +0,0 @@
-import assert from 'node:assert/strict'
-import { createPinia, setActivePinia } from 'pinia'
-import { useDetailStore } from '../../../src/modules/cockpit/stores/detailStore.js'
-import { metricRows, metricsSourceText, sectionHasContent, sectionPlaceholder } from '../../../src/modules/cockpit/domain/equipmentDetailView.js'
-import { TIME_LABELS } from '../../../src/modules/cockpit/domain/fields.js'
-
-// Literal API-contract fixture, not a reimplementation of the backend selection.
-const readings = [
-    { metricCode: 'ENV_COD', metricName: 'COD', value: 32.5, unit: 'mg/L', sampledAt: '2026-10-29T10:00:00+08:00', timeSource: 'CREATED_AT', freshness: 'STALE' },
-    { metricCode: 'ENV_PH', metricName: 'pH', value: 0, unit: '', sampledAt: '2026-10-28T09:00:00+08:00', timeSource: 'CREATED_AT', freshness: 'CURRENT' },
-    { metricCode: 'ENV_TEMPERATURE', metricName: '温度', value: null, unit: '℃', sampledAt: '2026-10-29T10:00:00+08:00', timeSource: 'CREATED_AT', freshness: 'STALE' },
-]
-function aggregate(code, metrics, state = 'STALE') {
-    return {
-        deviceCode: code, aggregateState: 'READY',
-        archive: { state: 'SUCCESS', data: { deviceCode: code, deviceName: '仁科环境监测器', deviceType: '15', deviceTypeName: '仁科环境监测器' } },
-        metrics: { state, data: { deviceCode: code, state, stateReason: state === 'STALE' ? 'SAMPLE_OUTDATED' : 'READY', metrics } },
-        warnings: { state: 'SUCCESS', data: [] }, alarms: { state: 'SUCCESS', data: [] },
-        workOrders: { state: 'EMPTY', data: null }, timelines: { state: 'EMPTY', data: null },
-        alarmWarningRelations: { state: 'EMPTY', data: null }, latestImage: { state: 'EMPTY', data: null },
-    }
-}
-const paths = []
-setActivePinia(createPinia())
-const store = useDetailStore()
-store.configure({
-    config: { dataSource: 'real', api: { baseUrl: 'http://fixture.invalid/api/cockpit/v1' } },
-    fetchImpl: async (url) => {
-        paths.push(url)
-        assert.ok(url.endsWith('/equipments/21119740/detail-aggregate'))
-        return Response.json({ code: 200, data: aggregate('21119740', readings) })
-    },
-})
-await store.openDevice('21119740')
-const metrics = store.sections.equipmentAggregate.data.sections.metrics
-assert.ok(sectionHasContent(metrics), sectionPlaceholder(metrics))
-assert.equal(metrics.state, 'stale')
-assert.equal(metrics.retained, true)
-assert.equal(paths.length, 1, 'Populated typed aggregate must not fan out to a guessed trend endpoint')
-const rows = metricRows(metrics.data)
-assert.deepEqual(rows.map(({ name, value, unit, sampledAt }) => ({ name, value, unit, sampledAt })), [
-    { name: 'COD', value: '32.5', unit: 'mg/L', sampledAt: '2026-10-29T10:00:00+08:00' },
-    { name: 'pH', value: '0', unit: '', sampledAt: '2026-10-28T09:00:00+08:00' },
-    { name: '温度', value: '—', unit: '℃', sampledAt: '2026-10-29T10:00:00+08:00' },
-])
-assert.equal(rows[0].sampledAtLabel, TIME_LABELS.ingested, 'A source create_time must not be labeled as physical sampling time')
-assert.equal(metricsSourceText(metrics.data), '指标记录已超过配置周期')
-assert.deepEqual(rows.map((row) => row.freshnessLabel), ['已过期', '', '已过期'], 'Mixed fresh/stale factors need their own stale labels')
-
-// A slow previous device response must never overwrite the newly selected device.
-let releaseA
-const lateA = new Promise((resolve) => { releaseA = resolve })
-store.closeDetail()
-store.configure({ fetchImpl: async (url) => {
-    if (url.endsWith('/equipments/A/detail-aggregate')) return lateA
-    assert.ok(url.endsWith('/equipments/B/detail-aggregate'))
-    return Response.json({ code: 200, data: aggregate('B', [
-        { metricCode: 'PRESSURE', metricName: '压力', value: 0.6, unit: 'MPa', sampledAt: '2026-11-02T10:00:00+08:00', timeSource: 'REPORTED_AT' },
-    ], 'SUCCESS') })
-} })
-const openingA = store.openDevice('A')
-await store.openDevice('B')
-releaseA(Response.json({ code: 200, data: aggregate('A', readings) }))
-await openingA
-assert.equal(store.selection.deviceCode, 'B')
-assert.equal(store.sections.equipmentAggregate.data.deviceCode, 'B')
-const bRows = metricRows(store.sections.equipmentAggregate.data.sections.metrics.data)
-assert.equal(bRows[0].value, '0.6')
-assert.equal(bRows[0].sampledAtLabel, TIME_LABELS.sampled)
-
-store.configure({ fetchImpl: async () => Response.json({ code: 200, data: aggregate('D-failed', [], 'FAILED') }) })
-await store.openDevice('D-failed')
-const failed = store.sections.equipmentAggregate.data.sections
-assert.equal(failed.metrics.state, 'failed')
-assert.equal(failed.archive.state, 'success')
-assert.equal(failed.warnings.state, 'success')
-assert.equal(failed.alarms.state, 'success')
-console.log('PASS real store -> typed metric rows: per-factor time, stale values, zero/null, time source, device race and independent sections')

+ 0 - 70
.scratch/cockpit-shell-panel-layout/verify/t56-latest-live.mjs

@@ -1,70 +0,0 @@
-import assert from 'node:assert/strict'
-import { fetchEquipmentDetailAggregate } from '../../../src/modules/cockpit/services/detailApi.js'
-import { metricRows, sectionHasContent, sectionPlaceholder } from '../../../src/modules/cockpit/domain/equipmentDetailView.js'
-
-const baseUrl = process.argv[2]
-assert.ok(baseUrl, 'Pass the existing cockpit read-only API base URL')
-const deviceCode = process.argv[3] || '21119740'
-const request = (url, options) => fetch(url, { ...options, signal: AbortSignal.timeout(15000) })
-// Independent existing source API, rather than copying the cockpit adapter's query.
-const factors = [
-    { node: 1, code: 'ENV_SUSPENDED_SOLIDS', name: '悬浮物', field: 'floatValue', unit: 'mg/L' },
-    { node: 2, code: 'ENV_COD', name: 'COD', field: 'hum', unit: 'mg/L' },
-    { node: 3, code: 'ENV_AMMONIA_NITROGEN', name: '氨氮', field: 'hum', unit: 'mg/L' },
-    { node: 4, code: 'ENV_CONDUCTIVITY', name: '电导率', field: 'hum', unit: 'μS/cm' },
-    { node: 5, code: 'ENV_PH', name: 'pH', field: 'hum', unit: '' },
-]
-const sources = deviceCode === '21119740' ? await Promise.all(factors.map(async (factor) => {
-    const url = new URL('/api/env/visualization/latest', baseUrl)
-    url.searchParams.set('deviceId', deviceCode)
-    url.searchParams.set('nodeId', String(factor.node))
-    const response = await request(url)
-    assert.ok(response.ok, `Source node ${factor.node}: HTTP ${response.status}`)
-    const body = await response.json()
-    assert.equal(body.code, 200, `Source node ${factor.node} must succeed independently`)
-    const record = body.data || null
-    if (record) {
-        assert.equal(record.deviceId, Number(deviceCode), 'Source device identity mismatch')
-        assert.equal(record.nodeId, factor.node, 'Source node identity mismatch')
-    }
-    return { factor, record }
-})) : []
-const result = await fetchEquipmentDetailAggregate(deviceCode, {
-    config: { dataSource: 'real', api: { baseUrl } }, fetchImpl: request,
-})
-const metrics = result.data?.sections?.metrics
-const rows = metricRows(metrics?.data)
-console.log(JSON.stringify({ deviceCode, aggregate: result.state, metrics: metrics?.state,
-    placeholder: sectionPlaceholder(metrics), rows,
-    sourceNodes: sources.map(({ factor, record }) => ({ node: factor.node, recordId: record?.id,
-        value: record?.[factor.field], temperature: record?.tem, createdAt: record?.createTime })),
-}, null, 2))
-assert.ok(sectionHasContent(metrics), `${deviceCode}: latest metrics must render content, not ${sectionPlaceholder(metrics)}`)
-assert.ok(rows.some((row) => row.value !== '—'), `${deviceCode}: expected at least one real reading`)
-assert.ok(rows.every((row) => row.name && row.sampledAt), 'Every metric must retain its name and source time')
-
-function assertReading(code, name, value, unit, sourceTime) {
-    const row = rows.find((item) => item.code === code)
-    assert.ok(row, `Missing real source metric ${code}`)
-    assert.equal(row.name, name)
-    assert.equal(row.unit, unit, `${code}: source unit mismatch`)
-    const missing = value === null || value === undefined || String(value).trim() === '' || !Number.isFinite(Number(value))
-    if (missing) assert.equal(row.value, '—', `${code}: missing source value must not become zero`)
-    else assert.equal(Number(row.value), Number(value), `${code}: source and cockpit readings differ`)
-    assert.equal(row.sampledAtLabel, '数据入库时间', `${code}: create_time must not be called sampling time`)
-    const sourceAt = /(?:Z|[+-]\d{2}:\d{2})$/.test(sourceTime) ? sourceTime : `${sourceTime}+08:00`
-    const sourceMillis = Date.parse(sourceAt)
-    const metricMillis = Date.parse(row.sampledAt)
-    assert.ok(Number.isFinite(sourceMillis), `${code}: invalid source timestamp`)
-    assert.ok(Number.isFinite(metricMillis), `${code}: invalid cockpit timestamp`)
-    assert.equal(metricMillis, sourceMillis, `${code}: latest node source time differs`)
-}
-for (const { factor, record } of sources) {
-    if (!record) {
-        assert.ok(!rows.some((row) => row.code === factor.code), `Node ${factor.node}: no source must not produce a reading`)
-        continue
-    }
-    assertReading(factor.code, factor.name, record[factor.field], factor.unit, record.createTime)
-    assertReading(`ENV_NODE_${factor.node}_TEMPERATURE`, `${factor.name}节点温度`, record.tem, '℃', record.createTime)
-}
-console.log('PASS real detail API -> latest metric rows, independently checked against each available source node')

+ 0 - 31
.scratch/cockpit-shell-panel-layout/verify/t56-live-fixture.mjs

@@ -1,31 +0,0 @@
-import assert from 'node:assert/strict'
-
-// This replaces only HTTP transport. The real detail API, adapter and row view still run.
-const scenario = process.env.T56_LIVE_SCENARIO || 'normal'
-const value = scenario === 'zero' ? 0 : scenario === 'missing' ? null : 17.3
-const time = scenario === 'invalid-time' ? 'not-a-timestamp' : '2026-10-23T17:04:29'
-const source = { id: 'captured-node-2', deviceId: 21119740, nodeId: 2, hum: value, tem: 22.2, createTime: time }
-if (scenario === 'wrong-node') source.nodeId = 3
-const metrics = [
-    { metricCode: 'ENV_COD', metricName: 'COD', value, unit: scenario === 'wrong-unit' ? 'MPa' : 'mg/L',
-        sampledAt: time === 'not-a-timestamp' ? time : `${time}+08:00`, timeSource: 'CREATED_AT', freshness: 'STALE' },
-    { metricCode: 'ENV_NODE_2_TEMPERATURE', metricName: 'COD节点温度', value: 22.2, unit: '℃',
-        sampledAt: time === 'not-a-timestamp' ? time : `${time}+08:00`, timeSource: 'CREATED_AT', freshness: 'STALE' },
-]
-// phantom-temperature:源记录在,但后端漏发该节点的温度指标行。
-if (scenario === 'phantom-temperature') metrics.pop()
-const reply = (data) => new Response(JSON.stringify({ code: 200, data }), { headers: { 'Content-Type': 'application/json' } })
-globalThis.fetch = async (input) => {
-    const url = new URL(input)
-    assert.equal(url.hostname, 'fixture.invalid', 'The offline guard must never contact a live host')
-    if (url.pathname === '/api/env/visualization/latest') {
-        assert.equal(url.searchParams.get('deviceId'), '21119740')
-        // no-source:源侧无记录;其余场景仅节点 2 有捕获记录。
-        return reply(url.searchParams.get('nodeId') === '2' && scenario !== 'no-source' ? source : null)
-    }
-    assert.equal(url.pathname, '/api/cockpit/v1/equipments/21119740/detail-aggregate')
-    return reply({ deviceCode: '21119740', aggregateState: 'READY',
-        archive: { state: 'SUCCESS', data: { deviceCode: '21119740', deviceName: '环境设备', deviceType: '15', deviceTypeName: '仁科环境监测器' } },
-        metrics: { state: 'STALE', data: { deviceCode: '21119740', state: 'STALE', stateReason: 'SAMPLE_OUTDATED', metrics } },
-    })
-}

+ 0 - 23
.scratch/cockpit-shell-panel-layout/verify/t56-live-verifier-guards.mjs

@@ -1,23 +0,0 @@
-import assert from 'node:assert/strict'
-import { spawnSync } from 'node:child_process'
-import { fileURLToPath } from 'node:url'
-const fixture = new URL('./t56-live-fixture.mjs', import.meta.url).href
-const verifier = fileURLToPath(new URL('./t56-latest-live.mjs', import.meta.url))
-const cases = [
-    ['normal', null], ['zero', null], ['missing', null],
-    ['wrong-unit', /source unit mismatch/],
-    ['wrong-node', /Source node identity mismatch/],
-    ['invalid-time', /invalid source timestamp/],
-    ['phantom-temperature', /Missing real source metric ENV_NODE_2_TEMPERATURE/],
-    ['no-source', /Node 2: no source must not produce a reading/],
-]
-for (const [scenario, expectedFailure] of cases) {
-    const result = spawnSync(process.execPath, ['--import', fixture, verifier, 'http://fixture.invalid/api/cockpit/v1'], {
-        encoding: 'utf8', timeout: 15000, env: { ...process.env, T56_LIVE_SCENARIO: scenario },
-    })
-    assert.ifError(result.error)
-    assert.equal(result.status, expectedFailure ? 1 : 0, `${scenario}: ${result.stderr}`)
-    if (expectedFailure) assert.match(result.stderr, expectedFailure, `${scenario}: failure must identify the actual assertion`)
-    console.log(`PASS ${scenario}: ${expectedFailure ? 'expected assertion caught' : 'source readings match'}`)
-}
-console.log(`PASS live-verifier guards: ${cases.length}/${cases.length} offline transport scenarios`)

+ 0 - 26
.scratch/cockpit-shell-panel-layout/verify/t56-read-task-index.mjs

@@ -1,26 +0,0 @@
-import { readFileSync, readdirSync } from 'node:fs'
-const root = '.scratch/cockpit-shell-panel-layout/'
-const files = readdirSync(`${root}issues`).filter((file) => /^\d+-.*\.md$/.test(file))
-const rows = files.map((file) => {
-    const text = readFileSync(`${root}issues/${file}`, 'utf8').replace(/^\uFEFF/, '')
-    const title = /^#\s+(.+)$/m.exec(text)?.[1]
-    const status = /^Status:\s*(.+)$/m.exec(text)?.[1]?.trim().toLowerCase()
-    if (!title || !status) throw new Error(`Missing title/status: ${file}`)
-    return { file, title, closed: ['resolved', 'closed', 'done', 'wontfix'].includes(status) }
-}).sort((a, b) => parseInt(a.file) - parseInt(b.file))
-console.log(JSON.stringify({ total: rows.length, closed: rows.filter((row) => row.closed).length }))
-const map = readFileSync(`${root}map.md`, 'utf8')
-if (process.argv.includes('--check')) {
-    if (!/^## Destination$/m.test(map)) throw new Error('Destination missing')
-    const matches = [...map.matchAll(/^- \[([ x])\] \[.+\]\((?:<issues\/([^>]+)>|issues\/([^\s)]+))\)$/gm)]
-    if (matches.length !== rows.length) throw new Error(`Checklist ${matches.length} != children ${rows.length}`)
-    const references = new Map(matches.map((match) => [match[2] || match[3], match[1] === 'x']))
-    if (references.size !== rows.length) throw new Error('Duplicate checklist ticket')
-    for (const row of rows) {
-        if (!references.has(row.file) || references.get(row.file) !== row.closed) throw new Error(`Checklist mismatch: ${row.file}`)
-    }
-    console.log(`PASS checklist=${rows.length}, closed=${rows.filter((row) => row.closed).length}, Destination retained`)
-} else {
-    console.log('## 任务清单\n\n本节为全部子票的唯一完整任务清单;每票一项,历史说明保持在原节,状态以票面和地图快照为准。\n')
-    for (const row of rows) console.log(`- [${row.closed ? 'x' : ' '}] [${row.title}](issues/${row.file})`)
-}