diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index f9ca549..2b56491 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -32,6 +32,6 @@ jobs: run: | TAG=$(git rev-parse --short=12 HEAD) echo "$TAG" > .image_tag - sudo -n docker build --build-arg GIT_SHA="${TAG}" -t "khb-microservices:${TAG}" . + sudo -n docker build --build-arg GIT_SHA="${TAG}" --build-arg BUILD_DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)" -t "khb-microservices:${TAG}" . - name: deploy run: sudo -n /y/services/khb-deploy/deploy.sh "$(cat .image_tag)" diff --git a/Dockerfile b/Dockerfile index c9cbc29..55208ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,8 +21,10 @@ RUN apt-get update \ && npm install -g pnpm@10.13.1 @anthropic-ai/claude-code@2.1.296 COPY --from=build /app /app ARG GIT_SHA=dev +ARG BUILD_DATE=unknown ENV NODE_ENV=production \ KHB_VERSION=${GIT_SHA} \ + KHB_BUILD_DATE=${BUILD_DATE} \ KHB_SETTINGS=/config/settings.json5 # khb-sql: чтение зеркала Supabase консольным агентом (роль только для чтения, KHB_SQL_URL передаёт сервис); # khb-drive: работа агента с Google Drive (ключ сервисного аккаунта передаёт сервис в KHB_DRIVE_KEY: builder - строителям, полный - руководителю) diff --git a/packages/qbo_auth/src/http-api.ts b/packages/qbo_auth/src/http-api.ts index 91153a3..4156e3d 100644 --- a/packages/qbo_auth/src/http-api.ts +++ b/packages/qbo_auth/src/http-api.ts @@ -2,7 +2,7 @@ import { createHmac } from "node:crypto"; import Fastify, { type FastifyInstance } from "fastify"; import { QboAuth, ReauthNeeded } from "./service.js"; import type { QboSync } from "./sync.js"; -import { TESTS_PAGE } from "./tests-page.js"; +import { renderTestsPage } from "./tests-page.js"; import { parseWebhook, verifyWebhook } from "./webhook.js"; export interface WebhookOptions { @@ -65,7 +65,7 @@ export function buildApi(auth: QboAuth, token: string, sync?: QboSync, webhook?: * Наружу: /api/qbo/tests/. */ const tests = (req: { params: unknown }): boolean => (req.params as { slug?: string }).slug === slug; - app.get("/tests/:slug", async (req, reply) => (tests(req) ? reply.type("text/html").send(TESTS_PAGE) : reply.code(404).send({ error: "not_found" }))); + app.get("/tests/:slug", async (req, reply) => (tests(req) ? reply.type("text/html").send(renderTestsPage()) : reply.code(404).send({ error: "not_found" }))); app.get("/tests/:slug/status", async (req, reply) => { if (!tests(req)) return reply.code(404).send({ error: "not_found" }); const st = await auth.status(); diff --git a/packages/qbo_auth/src/tests-page.ts b/packages/qbo_auth/src/tests-page.ts index ba02577..024908c 100644 --- a/packages/qbo_auth/src/tests-page.ts +++ b/packages/qbo_auth/src/tests-page.ts @@ -2,6 +2,7 @@ export const TESTS_PAGE = `Тесты qbo_auth

Ручные тесты QuickBooks (qbo_auth)

+

__BUILD__

M1. Подключение

1) «Отключить» (удаляет токены и отзывает их у Intuit). 2) «Подключить» и пройти авторизацию в открывшейся вкладке. 3) «Статус». 4) Отключите приложение в QuickBooks (Apps, KHBuild_assistant, Disconnect) и нажмите «Синхронизация»: ожидается 409 reauth_needed.

@@ -46,3 +47,14 @@ async function call(a,m,body){ document.querySelectorAll('button[data-a]').forEach(b=>b.onclick=()=>call(b.dataset.a,b.dataset.m)); $('send').onclick=()=>call('note','POST',{text:$('note').value}).then(()=>{$('note').value=''}); `; + +const esc = (v: string): string => v.replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c] ?? c); + +/** Страница с версией сборки (коммит и дата сборки образа; задаются при сборке: KHB_VERSION, KHB_BUILD_DATE). */ +export function renderTestsPage(env: NodeJS.ProcessEnv = process.env): string { + const v = env.KHB_VERSION && env.KHB_VERSION !== "dev" ? env.KHB_VERSION : ""; + const d = env.KHB_BUILD_DATE && env.KHB_BUILD_DATE !== "unknown" ? env.KHB_BUILD_DATE : ""; + const ver = v ? `${esc(v)}` : "неизвестна (локальная сборка)"; + const when = d ? `${esc(d.replace("T", " ").replace("Z", ""))} UTC` : "неизвестна"; + return TESTS_PAGE.replace("__BUILD__", `Версия: ${ver} · сборка: ${when}`); +} diff --git a/packages/qbo_auth/src/webhook.test.ts b/packages/qbo_auth/src/webhook.test.ts index a919cdb..a73525f 100644 --- a/packages/qbo_auth/src/webhook.test.ts +++ b/packages/qbo_auth/src/webhook.test.ts @@ -53,6 +53,8 @@ describe("вебхук Intuit", () => { const page = await app.inject({ url: `/tests/${slug}` }); expect(page.statusCode).toBe(200); expect(page.body).toContain("location.pathname"); + expect(page.body).toContain("Версия:"); + expect(page.body).not.toContain("__BUILD__"); expect(page.body).toContain("sandbox.qbo.intuit.com/app/appcenter/myapps"); expect(page.headers["cache-control"]).toBe("no-cache, no-store"); expect(page.headers["referrer-policy"]).toBe("no-referrer");