import { describe, it, expect } from 'vitest'; import { SELF } from 'cloudflare:test'; import { healthRouter } from '../src/routes/health'; import type { Bindings, ExecutionContext } from '../src/types'; describe('GET /health — bundle_version 欄位', () => { it('無 ARCRUN_BUNDLE_VERSION 時省略該欄(老實例情境)', async () => { // wrangler.test.toml 不設此 var → health.ts 省略 bundle_version 欄位。 // daemon 端讀不到該欄=當作空字串=判 stale,對老實例而言**這是正確行為** //(見 health.ts 檔頭註解)。此處驗「省略」而非「回空字串」,與實作對齊。 const res = await SELF.fetch('http://localhost/health'); const data = await res.json() as { ok: boolean; bundle_version?: string }; expect(res.status).toBe(200); expect(data.ok).toBe(true); expect(data.bundle_version).toBeUndefined(); }); it('有 ARCRUN_BUNDLE_VERSION 時回其值(安裝器注入情境)', async () => { const fakeEnv = { ARCRUN_BUNDLE_VERSION: '2026-07-28/6d06162' } as unknown as Bindings; const res = await healthRouter.fetch( new Request('http://localhost/health'), fakeEnv, {} as ExecutionContext, ); const data = await res.json() as { ok: boolean; bundle_version: string }; expect(data.ok).toBe(true); expect(data.bundle_version).toBe('2026-07-28/6d06162'); }); });