ContractSmoke.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <script setup lang="ts">
  2. /** 契约自检页:把冻契约里的关键接口各取一次,显示 状态 / 耗时 / 顶层键。 */
  3. import { onMounted, ref } from 'vue'
  4. import { callApi, API_PATHS, SMOKE_SET, type ApiName } from '../api/contract'
  5. interface Row {
  6. name: ApiName
  7. path: string
  8. ok: boolean
  9. status: number
  10. ms: number
  11. keys: string
  12. error?: string
  13. }
  14. const rows = ref<Row[]>([])
  15. const running = ref(false)
  16. const finished = ref(0)
  17. function keysOf(data: unknown): string {
  18. if (Array.isArray(data)) return `list[${data.length}]`
  19. if (data && typeof data === 'object') return Object.keys(data as object).slice(0, 8).join(', ')
  20. return typeof data
  21. }
  22. async function run() {
  23. running.value = true
  24. rows.value = []
  25. finished.value = 0
  26. for (const name of SMOKE_SET) {
  27. const r = await callApi(name)
  28. rows.value.push({
  29. name,
  30. path: r.path,
  31. ok: r.ok,
  32. status: r.status,
  33. ms: r.ms,
  34. keys: keysOf(r.data),
  35. error: r.error,
  36. })
  37. finished.value += 1
  38. }
  39. running.value = false
  40. }
  41. onMounted(run)
  42. </script>
  43. <template>
  44. <section class="card">
  45. <h2>契约自检 <small>(后端结构与算法服务可达性;对拍基准见 docs/接口契约_前后端_v0.1.md)</small></h2>
  46. <p class="hint">
  47. 进度 {{ finished }}/{{ SMOKE_SET.length }} · 只判"通不通",不比数据值(值随数据变,锚点在 Python 侧的门禁里)
  48. <button class="re" :disabled="running" @click="run">重跑</button>
  49. </p>
  50. <table>
  51. <thead>
  52. <tr><th>接口</th><th>路径</th><th>状态</th><th>耗时</th><th>顶层键 / 形状</th></tr>
  53. </thead>
  54. <tbody>
  55. <tr v-for="r in rows" :key="r.name" :class="{ bad: !r.ok }">
  56. <td>{{ r.name }}</td>
  57. <td><code>{{ r.path }}</code></td>
  58. <td>{{ r.status }}</td>
  59. <td>{{ r.ms }} ms</td>
  60. <td>{{ r.error || r.keys }}</td>
  61. </tr>
  62. </tbody>
  63. </table>
  64. <p class="hint">
  65. 契约登记接口合计 {{ Object.keys(API_PATHS).length }} 条(本页抽样 {{ SMOKE_SET.length }} 条);
  66. 全量 42 条由 <code>python scripts/http_contract_audit.py</code> 在线复核。
  67. </p>
  68. </section>
  69. </template>