import fs from 'node:fs/promises' import path from 'node:path' // One read-only preflight, with a new evidence directory on every run. const base = 'http://192.168.110.96:8301/api/cockpit/v1' const startedAt = new Date().toISOString() const output = path.resolve('.scratch/cockpit-real-data-wayfinding/verify/artifacts/t18', 'takeover-' + startedAt.replace(/[:.]/g, '-')) const routes = [ '/foundation', '/map-snapshot?page=1&pageSize=1000', '/monitoring/overview', '/monitoring/distribution', '/monitoring/situation', '/overview/infrastructure', '/overview/monitoring', '/overview/warning-settings?range=LAST_7_DAYS', '/infrastructure/base-archives', '/infrastructure/operating-information', '/infrastructure/management-information', '/infrastructure/emergency-support', '/events/current?mode=ALARM', '/events/history-analysis?eventFamily=ALARM', '/events/handling-efficiency?eventFamily=ALARM', '/events/multidimensional-analysis?eventFamily=ALARM', '/equipments/21119740/work-orders', '/work-orders/WO202610121103507623/timeline', ] const responses = [] for (const route of routes) { const requestedAt = new Date().toISOString() try { const response = await fetch(base + route, { signal: AbortSignal.timeout(10000) }) const body = await response.json() responses.push({ route, requestedAt, receivedAt: new Date().toISOString(), http: response.status, body }) } catch (error) { responses.push({ route, requestedAt, error: error.message }) } } const checks = responses.map(row => ({ id: 'endpoint-' + row.route, passed: row.http === 200 && row.body?.code === 200 && row.body?.data?.readOnly === true, evidence: { http: row.http, code: row.body?.code, readOnly: row.body?.data?.readOnly, error: row.error }, })) for (const route of ['/monitoring/overview', '/monitoring/distribution', '/monitoring/situation']) { const data = responses.find(row => row.route === route)?.body?.data checks.push({ id: 'createdAt-' + route, passed: !!data && Object.hasOwn(data, 'createdAt'), evidence: { hasOwnCreatedAt: !!data && Object.hasOwn(data, 'createdAt'), value: data?.createdAt } }) } const orders = responses.find(row => row.route === '/equipments/21119740/work-orders')?.body?.data?.workOrders const candidate = orders?.find(row => row.workOrderCode === 'WO202610121103507623') const report = { startedAt, endedAt: new Date().toISOString(), base, readOnly: true, page: 'http://127.0.0.1:8000/#/cockpit', versionObservations: { frontendHead: '5a83ab9b836156a4bb9468d1868e4d8040238571', frontendRemoteMaster: 'a6fbbea9dc32e83ee61dcb5a6646bf5875399636', backendHead: 'a96091ce081411e8ceedcf73fe38274d0c63fae8', backendRemoteMaster: '3e448568cd7db6c9a710479283553eab16e67817', source: 'Local git read and git ls-remote before this run; no fetch, commit or push.', runtimeCommitBinding: 'not established; frontend dev worktree has uncommitted parallel changes', }, candidate, responses, checks, summary: { requests: responses.length, checks: checks.length, passed: checks.filter(row => row.passed).length, failed: checks.filter(row => !row.passed).length }, scope: 'Current GET response and contract presence preflight only; no business writes, no mock, no complete human verdict, no proof of all map/panel/WS behavior.', } await fs.mkdir(output, { recursive: true }) const file = path.join(output, 'preflight.json') await fs.writeFile(file, JSON.stringify(report, null, 2)) console.log(JSON.stringify({ file, summary: report.summary, candidate: candidate && { workOrderCode: candidate.workOrderCode, stateCode: candidate.stateCode, associatedWithCurrentEvent: candidate.associatedWithCurrentEvent }, failures: checks.filter(row => !row.passed) })) process.exitCode = report.summary.failed ? 1 : 0