diff --git a/cypher-executor/src/routes/health.ts b/cypher-executor/src/routes/health.ts index 5485639..e1e847e 100644 --- a/cypher-executor/src/routes/health.ts +++ b/cypher-executor/src/routes/health.ts @@ -4,7 +4,7 @@ import type { Bindings } from '../types'; export const healthRouter = new Hono<{ Bindings: Bindings }>(); healthRouter.get('/health', (c) => - c.json({ ok: true }) + c.json({ ok: true, bundle_version: c.env.ARCRUN_BUNDLE_VERSION ?? '' }) ); healthRouter.get('/', (c) => diff --git a/cypher-executor/src/types.ts b/cypher-executor/src/types.ts index 742faa4..de78426 100644 --- a/cypher-executor/src/types.ts +++ b/cypher-executor/src/types.ts @@ -96,6 +96,9 @@ export type Bindings = { GITEA_TOKEN?: string; // wrangler secret(建議唯讀 scope token) GITEA_SPRINT_REPO?: string; // 預設 Leo/InkStoneCo GITEA_SPRINT_DIR?: string; // 預設 system-dev/docs/3-specs/autonomy-dispatch + // 安裝器部署時注入的 bundle 版本(格式 "YYYY-MM-DD/commit",老實例無此 var)。 + // daemon 比對此值決定是否提示用戶更新(/health 曝露,缺 var 時回空字串)。 + ARCRUN_BUNDLE_VERSION?: string; // MCP access_token 存活秒數的「顯示鏡像」(console 設定頁 MCP TTL 佔位區塊用)。 // 真相住在 mcp worker 的同名 env(mcp/src/types.ts,預設 2592000=30 天);cypher 這份 // 只供顯示,兩處部署時要一致(#32 形態 config 同步教訓)。未設 → 頁面如實標「預設值」。 diff --git a/cypher-executor/tests/health.test.ts b/cypher-executor/tests/health.test.ts new file mode 100644 index 0000000..19d2215 --- /dev/null +++ b/cypher-executor/tests/health.test.ts @@ -0,0 +1,27 @@ +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 → 走 ?? '' fallback + 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).toBe(''); + }); + + 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'); + }); +});