Версия и дата сборки на странице ручных тестов (BUILD_DATE в образе); исправление теста
All checks were successful
ci / test (push) Successful in 39s
ci / deploy (push) Successful in 2m46s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 10:20:07 +03:00
parent 62dfe89f96
commit d1e3f18817
5 changed files with 19 additions and 3 deletions

View File

@@ -32,6 +32,6 @@ jobs:
run: | run: |
TAG=$(git rev-parse --short=12 HEAD) TAG=$(git rev-parse --short=12 HEAD)
echo "$TAG" > .image_tag 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 - name: deploy
run: sudo -n /y/services/khb-deploy/deploy.sh "$(cat .image_tag)" run: sudo -n /y/services/khb-deploy/deploy.sh "$(cat .image_tag)"

View File

@@ -21,8 +21,10 @@ RUN apt-get update \
&& npm install -g pnpm@10.13.1 @anthropic-ai/claude-code@2.1.296 && npm install -g pnpm@10.13.1 @anthropic-ai/claude-code@2.1.296
COPY --from=build /app /app COPY --from=build /app /app
ARG GIT_SHA=dev ARG GIT_SHA=dev
ARG BUILD_DATE=unknown
ENV NODE_ENV=production \ ENV NODE_ENV=production \
KHB_VERSION=${GIT_SHA} \ KHB_VERSION=${GIT_SHA} \
KHB_BUILD_DATE=${BUILD_DATE} \
KHB_SETTINGS=/config/settings.json5 KHB_SETTINGS=/config/settings.json5
# khb-sql: чтение зеркала Supabase консольным агентом (роль только для чтения, KHB_SQL_URL передаёт сервис); # khb-sql: чтение зеркала Supabase консольным агентом (роль только для чтения, KHB_SQL_URL передаёт сервис);
# khb-drive: работа агента с Google Drive (ключ сервисного аккаунта передаёт сервис в KHB_DRIVE_KEY: builder - строителям, полный - руководителю) # khb-drive: работа агента с Google Drive (ключ сервисного аккаунта передаёт сервис в KHB_DRIVE_KEY: builder - строителям, полный - руководителю)

View File

@@ -2,7 +2,7 @@ import { createHmac } from "node:crypto";
import Fastify, { type FastifyInstance } from "fastify"; import Fastify, { type FastifyInstance } from "fastify";
import { QboAuth, ReauthNeeded } from "./service.js"; import { QboAuth, ReauthNeeded } from "./service.js";
import type { QboSync } from "./sync.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"; import { parseWebhook, verifyWebhook } from "./webhook.js";
export interface WebhookOptions { export interface WebhookOptions {
@@ -65,7 +65,7 @@ export function buildApi(auth: QboAuth, token: string, sync?: QboSync, webhook?:
* Наружу: /api/qbo/tests/<slug>. * Наружу: /api/qbo/tests/<slug>.
*/ */
const tests = (req: { params: unknown }): boolean => (req.params as { slug?: string }).slug === slug; 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) => { app.get("/tests/:slug/status", async (req, reply) => {
if (!tests(req)) return reply.code(404).send({ error: "not_found" }); if (!tests(req)) return reply.code(404).send({ error: "not_found" });
const st = await auth.status(); const st = await auth.status();

View File

@@ -2,6 +2,7 @@
export const TESTS_PAGE = `<!doctype html><html lang="ru"><head><meta charset="utf-8"><meta name="robots" content="noindex"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Тесты qbo_auth</title> export const TESTS_PAGE = `<!doctype html><html lang="ru"><head><meta charset="utf-8"><meta name="robots" content="noindex"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Тесты qbo_auth</title>
<style>body{font:15px/1.5 system-ui,sans-serif;max-width:760px;margin:24px auto;padding:0 16px}button{margin:4px 4px 4px 0;padding:6px 12px}input,textarea{width:100%;box-sizing:border-box;margin:4px 0}pre{background:#f3f4f6;padding:10px;white-space:pre-wrap;word-break:break-all}h2{margin-top:24px}</style></head><body> <style>body{font:15px/1.5 system-ui,sans-serif;max-width:760px;margin:24px auto;padding:0 16px}button{margin:4px 4px 4px 0;padding:6px 12px}input,textarea{width:100%;box-sizing:border-box;margin:4px 0}pre{background:#f3f4f6;padding:10px;white-space:pre-wrap;word-break:break-all}h2{margin-top:24px}</style></head><body>
<h1>Ручные тесты QuickBooks (qbo_auth)</h1> <h1>Ручные тесты QuickBooks (qbo_auth)</h1>
<p id="build"><small>__BUILD__</small></p>
<h2>M1. Подключение</h2> <h2>M1. Подключение</h2>
<p>1) «Отключить» (удаляет токены и отзывает их у Intuit). 2) «Подключить» и пройти авторизацию в открывшейся вкладке. 3) «Статус». 4) Отключите приложение в QuickBooks (Apps, KHBuild_assistant, Disconnect) и нажмите «Синхронизация»: ожидается 409 reauth_needed.</p> <p>1) «Отключить» (удаляет токены и отзывает их у Intuit). 2) «Подключить» и пройти авторизацию в открывшейся вкладке. 3) «Статус». 4) Отключите приложение в QuickBooks (Apps, KHBuild_assistant, Disconnect) и нажмите «Синхронизация»: ожидается 409 reauth_needed.</p>
<button data-a="status" data-m="GET">Статус</button> <button data-a="status" data-m="GET">Статус</button>
@@ -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)); 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=''}); $('send').onclick=()=>call('note','POST',{text:$('note').value}).then(()=>{$('note').value=''});
</script></body></html>`; </script></body></html>`;
const esc = (v: string): string => v.replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[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 ? `<a href="https://gitea.khbuild.freeddns.org/yuyaryshev/khb_microservices/commit/${esc(v)}" target="_blank" rel="noopener">${esc(v)}</a>` : "неизвестна (локальная сборка)";
const when = d ? `${esc(d.replace("T", " ").replace("Z", ""))} UTC` : "неизвестна";
return TESTS_PAGE.replace("__BUILD__", `Версия: ${ver} · сборка: ${when}`);
}

View File

@@ -53,6 +53,8 @@ describe("вебхук Intuit", () => {
const page = await app.inject({ url: `/tests/${slug}` }); const page = await app.inject({ url: `/tests/${slug}` });
expect(page.statusCode).toBe(200); expect(page.statusCode).toBe(200);
expect(page.body).toContain("location.pathname"); 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.body).toContain("sandbox.qbo.intuit.com/app/appcenter/myapps");
expect(page.headers["cache-control"]).toBe("no-cache, no-store"); expect(page.headers["cache-control"]).toBe("no-cache, no-store");
expect(page.headers["referrer-policy"]).toBe("no-referrer"); expect(page.headers["referrer-policy"]).toBe("no-referrer");