gft-pharos-mcp 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +122 -22
- package/package.json +1 -1
- package/test/runbook.test.js +201 -4
package/index.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* enxerga o codigo do cliente.
|
|
10
10
|
*
|
|
11
11
|
* `list_runbook` e `read_runbook_page` leem o runbook publicado do cliente da sessao, tambem sem
|
|
12
|
-
* modelo no meio
|
|
12
|
+
* modelo no meio, no idioma de origem ou na traducao pedida em `locale`.
|
|
13
13
|
*
|
|
14
14
|
* Este processo tambem serve as tools da documentacao oficial da Mastercard, para
|
|
15
15
|
* que o dev configure um servidor MCP so. Veja `registerOfficialTools`.
|
|
@@ -616,6 +616,30 @@ export const RUNBOOK_EMPTY_MESSAGE = "O runbook deste espaço ainda não tem pá
|
|
|
616
616
|
/** Mesmo formato do slug no banco (V21): o Pharos compara o caminho cru, sem decodificar. */
|
|
617
617
|
export const RUNBOOK_SLUG = /^[a-z0-9][a-z0-9-]{0,79}$/;
|
|
618
618
|
|
|
619
|
+
/**
|
|
620
|
+
* Formato do idioma (o mesmo do CHECK da V21 e da V29). Os idiomas suportados sao configuraveis na
|
|
621
|
+
* API, entao aqui so o formato: idioma fora da lista volta 400 do Pharos.
|
|
622
|
+
*/
|
|
623
|
+
export const RUNBOOK_LOCALE = /^[a-z]{2}(-[A-Z]{2})?$/;
|
|
624
|
+
|
|
625
|
+
/** 400 da leitura com `locale`: o idioma tem o formato certo, mas o runbook nao o suporta. */
|
|
626
|
+
export function runbookLocaleUnsupportedMessage(locale) {
|
|
627
|
+
return (
|
|
628
|
+
`O idioma "${locale}" não é suportado pelo runbook deste espaço. ` +
|
|
629
|
+
"Use list_runbook sem locale para ver os idiomas disponíveis."
|
|
630
|
+
);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
/** O unico 400 das leituras do runbook e o do idioma fora da lista configurada. */
|
|
634
|
+
function isLocaleUnsupported(err, locale) {
|
|
635
|
+
return Boolean(locale) && err?.status === 400;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/** Query string do idioma; sem idioma, o caminho fica igual ao de antes. */
|
|
639
|
+
function localeQuery(locale) {
|
|
640
|
+
return locale ? `?locale=${encodeURIComponent(locale)}` : "";
|
|
641
|
+
}
|
|
642
|
+
|
|
619
643
|
/** Texto fixo do 403 do Pharos anterior a liberacao do runbook para a chave de API. */
|
|
620
644
|
const ROUTE_NOT_ALLOWED_FOR_KEY = "Esta rota não aceita chave de API";
|
|
621
645
|
|
|
@@ -635,35 +659,54 @@ function text(value, isError = false) {
|
|
|
635
659
|
return { content: [{ type: "text", text: value }], ...(isError ? { isError: true } : {}) };
|
|
636
660
|
}
|
|
637
661
|
|
|
638
|
-
function
|
|
639
|
-
|
|
662
|
+
function formatPageLocale(page, requested) {
|
|
663
|
+
if (!page?.locale) return "";
|
|
664
|
+
if (page.translated && page.sourceLocale && page.sourceLocale !== page.locale) {
|
|
665
|
+
return ` [${page.locale}, traduzida de ${page.sourceLocale}]`;
|
|
666
|
+
}
|
|
667
|
+
if (requested && page.locale !== requested) return ` [${page.locale}, sem tradução em ${requested}]`;
|
|
668
|
+
return ` [${page.locale}]`;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
function formatPageSummary(page, indent, requested) {
|
|
672
|
+
const idioma = formatPageLocale(page, requested);
|
|
640
673
|
const modelo = page?.template ? ` (modelo ${page.template})` : "";
|
|
641
674
|
return `${indent}- ${page?.title ?? "(sem título)"}${idioma}${modelo}: slug \`${page?.slug}\``;
|
|
642
675
|
}
|
|
643
676
|
|
|
644
|
-
function formatSection(section, depth) {
|
|
677
|
+
function formatSection(section, depth, requested) {
|
|
645
678
|
const indent = " ".repeat(depth);
|
|
646
679
|
const lines = [`${indent}- Seção: ${section?.title ?? "(sem título)"}`];
|
|
647
|
-
for (const page of section?.pages ?? []) lines.push(formatPageSummary(page, `${indent}
|
|
648
|
-
for (const child of section?.sections ?? []) lines.push(...formatSection(child, depth + 1));
|
|
680
|
+
for (const page of section?.pages ?? []) lines.push(formatPageSummary(page, `${indent} `, requested));
|
|
681
|
+
for (const child of section?.sections ?? []) lines.push(...formatSection(child, depth + 1, requested));
|
|
649
682
|
return lines;
|
|
650
683
|
}
|
|
651
684
|
|
|
652
|
-
/**
|
|
653
|
-
|
|
685
|
+
/**
|
|
686
|
+
* Indice do runbook em texto: secoes em arvore e, em cada uma, as paginas publicadas com o slug e o
|
|
687
|
+
* idioma do titulo. `requested` e o idioma pedido; o servido vem da resposta (o Pharos anterior a
|
|
688
|
+
* traducao ignora o parametro).
|
|
689
|
+
*/
|
|
690
|
+
export function formatRunbookTree(tree, requested) {
|
|
654
691
|
const sections = Array.isArray(tree?.sections) ? tree.sections : [];
|
|
655
692
|
const pages = Array.isArray(tree?.pages) ? tree.pages : [];
|
|
656
693
|
if (!sections.length && !pages.length) return RUNBOOK_EMPTY_MESSAGE;
|
|
657
694
|
|
|
658
695
|
const lines = [`# Runbook: ${tree?.title ?? "(sem título)"}`];
|
|
659
696
|
if (tree?.description) lines.push("", tree.description);
|
|
697
|
+
const idiomas = [];
|
|
698
|
+
if (requested) idiomas.push(`Títulos pedidos em: ${requested}`);
|
|
699
|
+
if (Array.isArray(tree?.locales) && tree.locales.length) {
|
|
700
|
+
idiomas.push(`Idiomas disponíveis: ${tree.locales.join(", ")}`);
|
|
701
|
+
}
|
|
702
|
+
if (idiomas.length) lines.push("", idiomas.join(" | "));
|
|
660
703
|
lines.push("");
|
|
661
|
-
for (const section of sections) lines.push(...formatSection(section, 0));
|
|
662
|
-
for (const page of pages) lines.push(formatPageSummary(page, ""));
|
|
704
|
+
for (const section of sections) lines.push(...formatSection(section, 0, requested));
|
|
705
|
+
for (const page of pages) lines.push(formatPageSummary(page, "", requested));
|
|
663
706
|
lines.push(
|
|
664
707
|
"",
|
|
665
708
|
"Só aparecem páginas publicadas (revisadas pela equipe). " +
|
|
666
|
-
"Para ler uma página, use read_runbook_page com o slug."
|
|
709
|
+
"Para ler uma página, use read_runbook_page com o slug (e locale para ler a tradução)."
|
|
667
710
|
);
|
|
668
711
|
return lines.join("\n");
|
|
669
712
|
}
|
|
@@ -675,8 +718,32 @@ function formatSource(source) {
|
|
|
675
718
|
return partes.join(" | ");
|
|
676
719
|
}
|
|
677
720
|
|
|
678
|
-
/**
|
|
679
|
-
|
|
721
|
+
/**
|
|
722
|
+
* Aviso de idioma da pagina, derivado da resposta: tradução automatica ou revisada quando o Pharos
|
|
723
|
+
* serviu uma traducao; origem quando o idioma pedido nao tem traducao (ou o Pharos ignorou o pedido).
|
|
724
|
+
* Nulo quando o texto e a origem e nada diferente foi pedido.
|
|
725
|
+
*/
|
|
726
|
+
export function runbookPageLocaleNotice(page, requested) {
|
|
727
|
+
const source = page?.sourceLocale ?? page?.locale ?? "?";
|
|
728
|
+
const t = page?.translation;
|
|
729
|
+
if (t) {
|
|
730
|
+
if (t.status === "REVIEWED" || t.reviewed === true) {
|
|
731
|
+
const quando = t.reviewedAt ? ` em ${t.reviewedAt}` : "";
|
|
732
|
+
return `Tradução revisada: texto em ${page?.locale ?? "?"} traduzido do original em ${source} e revisado por um curador${quando}.`;
|
|
733
|
+
}
|
|
734
|
+
return (
|
|
735
|
+
`Tradução automática: texto em ${page?.locale ?? "?"} traduzido do original em ${source}, ainda sem revisão de um curador. ` +
|
|
736
|
+
"Em ponto crítico, confira a origem com read_runbook_page sem locale."
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
if (page?.translationMissing === true || (requested && page?.locale && page.locale !== requested)) {
|
|
740
|
+
return `Sem tradução em ${requested ?? "?"}: veio o texto no idioma de origem (${page?.locale ?? source}).`;
|
|
741
|
+
}
|
|
742
|
+
return null;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
/** Pagina publicada em texto: metadados, idioma, corpo em Markdown e a proveniencia. */
|
|
746
|
+
export function formatRunbookPage(page, requested) {
|
|
680
747
|
const path = Array.isArray(page?.path) ? page.path : [];
|
|
681
748
|
const revision = page?.revision ?? {};
|
|
682
749
|
const sources = Array.isArray(page?.sources) ? page.sources : [];
|
|
@@ -694,9 +761,21 @@ export function formatRunbookPage(page) {
|
|
|
694
761
|
if (revision.reviewedBy) rev.push(`revisada por ${revision.reviewedBy}`);
|
|
695
762
|
if (revision.publishedAt) rev.push(`publicada em ${revision.publishedAt}`);
|
|
696
763
|
|
|
764
|
+
const idioma = [];
|
|
765
|
+
if (page?.sourceLocale) idioma.push(`Idioma de origem: ${page.sourceLocale}`);
|
|
766
|
+
if (Array.isArray(page?.availableLocales) && page.availableLocales.length) {
|
|
767
|
+
idioma.push(`Idiomas disponíveis: ${page.availableLocales.join(", ")}`);
|
|
768
|
+
}
|
|
769
|
+
const notice = runbookPageLocaleNotice(page, requested);
|
|
770
|
+
const citacao = page?.translation
|
|
771
|
+
? `slug ${page?.slug}, revisão ${revision.number ?? "?"}, tradução em ${page?.locale ?? "?"}`
|
|
772
|
+
: `slug ${page?.slug}, revisão ${revision.number ?? "?"}`;
|
|
773
|
+
|
|
697
774
|
return [
|
|
698
775
|
`# ${page?.title ?? "(sem título)"}`,
|
|
699
776
|
meta.join(" | "),
|
|
777
|
+
...(idioma.length ? [idioma.join(" | ")] : []),
|
|
778
|
+
...(notice ? [notice] : []),
|
|
700
779
|
rev.join(" | "),
|
|
701
780
|
"",
|
|
702
781
|
page?.bodyMd ?? "",
|
|
@@ -704,7 +783,7 @@ export function formatRunbookPage(page) {
|
|
|
704
783
|
"---",
|
|
705
784
|
sources.length ? `Fontes:\n${sources.map(formatSource).join("\n")}` : "Fontes: nenhuma registrada.",
|
|
706
785
|
"",
|
|
707
|
-
`Ao usar este conteúdo, cite a página do runbook (
|
|
786
|
+
`Ao usar este conteúdo, cite a página do runbook (${citacao}).`,
|
|
708
787
|
].join("\n");
|
|
709
788
|
}
|
|
710
789
|
|
|
@@ -713,6 +792,13 @@ export function formatRunbookPage(page) {
|
|
|
713
792
|
* o `client` da tool so confirma, como nas outras.
|
|
714
793
|
*/
|
|
715
794
|
function registerRunbookTools(target, { schema, clientSession, call }) {
|
|
795
|
+
const localeArg = (what) =>
|
|
796
|
+
z
|
|
797
|
+
.string()
|
|
798
|
+
.regex(RUNBOOK_LOCALE, "locale inválido: use o formato pt-BR ou en (veja os idiomas disponíveis em list_runbook)")
|
|
799
|
+
.optional()
|
|
800
|
+
.describe(what);
|
|
801
|
+
|
|
716
802
|
target.registerTool(
|
|
717
803
|
"list_runbook",
|
|
718
804
|
{
|
|
@@ -720,18 +806,25 @@ function registerRunbookTools(target, { schema, clientSession, call }) {
|
|
|
720
806
|
description:
|
|
721
807
|
"Lista o índice do runbook do cliente deste projeto: seções e páginas publicadas, com o " +
|
|
722
808
|
"slug de cada página. O runbook é a documentação estruturada do time (integração, " +
|
|
723
|
-
"operação, incidente, go-live e outras), revisada antes de publicar.
|
|
724
|
-
"
|
|
809
|
+
"operação, incidente, go-live e outras), revisada antes de publicar. Mostra também os " +
|
|
810
|
+
"idiomas disponíveis. Sem locale, cada título vem no idioma em que a página foi escrita; com " +
|
|
811
|
+
"locale (ex.: en quando o usuário conversa em inglês), vem a tradução quando houver. Use " +
|
|
812
|
+
"read_runbook_page com o slug para ler uma página.",
|
|
725
813
|
inputSchema: {
|
|
814
|
+
locale: localeArg(
|
|
815
|
+
"Idioma dos títulos (opcional), como pt-BR ou en. Omita para o idioma de origem de cada página."
|
|
816
|
+
),
|
|
726
817
|
client: schema.client.optional().describe(`${CLIENT_ARG_DESCRIPTION} Outro cliente é recusado.`),
|
|
727
818
|
},
|
|
728
819
|
},
|
|
729
|
-
async ({ client: argClient }) => {
|
|
820
|
+
async ({ locale, client: argClient }) => {
|
|
730
821
|
const chosen = await clientSession.resolve(argClient);
|
|
731
822
|
try {
|
|
732
|
-
|
|
823
|
+
const tree = await call(`/runbook${localeQuery(locale)}`, { headers: clientHeaders(chosen) });
|
|
824
|
+
return text(formatRunbookTree(tree, locale));
|
|
733
825
|
} catch (err) {
|
|
734
826
|
if (isRunbookUnavailable(err)) return text(RUNBOOK_UNAVAILABLE_MESSAGE);
|
|
827
|
+
if (isLocaleUnsupported(err, locale)) return text(runbookLocaleUnsupportedMessage(locale), true);
|
|
735
828
|
throw err;
|
|
736
829
|
}
|
|
737
830
|
}
|
|
@@ -743,22 +836,29 @@ function registerRunbookTools(target, { schema, clientSession, call }) {
|
|
|
743
836
|
title: "Ler página do runbook",
|
|
744
837
|
description:
|
|
745
838
|
"Lê uma página publicada do runbook do cliente deste projeto pelo slug (veja list_runbook): " +
|
|
746
|
-
"título, idioma, caminho de seções, corpo em Markdown, revisão e fontes.
|
|
747
|
-
"
|
|
839
|
+
"título, idioma, caminho de seções, corpo em Markdown, revisão e fontes. Sem locale, vem no " +
|
|
840
|
+
"idioma em que foi escrita; com locale (ex.: en quando o usuário conversa em inglês), vem a " +
|
|
841
|
+
"tradução da revisão publicada, marcada como automática ou revisada, ou a origem quando não há " +
|
|
842
|
+
"tradução nesse idioma. Cite a página e a revisão ao usar o conteúdo.",
|
|
748
843
|
inputSchema: {
|
|
749
844
|
slug: z
|
|
750
845
|
.string()
|
|
751
846
|
.regex(RUNBOOK_SLUG, "slug inválido: use minúsculas, dígitos e hífen, como aparece em list_runbook")
|
|
752
847
|
.describe("Slug da página, como aparece em list_runbook (ex.: go-live)"),
|
|
848
|
+
locale: localeArg(
|
|
849
|
+
"Idioma desejado (opcional), como pt-BR ou en. Omita para ler no idioma de origem."
|
|
850
|
+
),
|
|
753
851
|
client: schema.client.optional().describe(`${CLIENT_ARG_DESCRIPTION} Outro cliente é recusado.`),
|
|
754
852
|
},
|
|
755
853
|
},
|
|
756
|
-
async ({ slug, client: argClient }) => {
|
|
854
|
+
async ({ slug, locale, client: argClient }) => {
|
|
757
855
|
const chosen = await clientSession.resolve(argClient);
|
|
758
856
|
const headers = clientHeaders(chosen);
|
|
759
857
|
try {
|
|
760
|
-
|
|
858
|
+
const page = await call(`/runbook/pages/${slug}${localeQuery(locale)}`, { headers });
|
|
859
|
+
return text(formatRunbookPage(page, locale));
|
|
761
860
|
} catch (err) {
|
|
861
|
+
if (isLocaleUnsupported(err, locale)) return text(runbookLocaleUnsupportedMessage(locale), true);
|
|
762
862
|
if (!isRunbookUnavailable(err)) throw err;
|
|
763
863
|
}
|
|
764
864
|
// O 404 da pagina e o mesmo do runbook desligado: o indice desempata.
|
package/package.json
CHANGED
package/test/runbook.test.js
CHANGED
|
@@ -16,6 +16,8 @@ import {
|
|
|
16
16
|
RUNBOOK_UNAVAILABLE_MESSAGE,
|
|
17
17
|
RUNBOOK_EMPTY_MESSAGE,
|
|
18
18
|
runbookPageNotFoundMessage,
|
|
19
|
+
runbookLocaleUnsupportedMessage,
|
|
20
|
+
runbookPageLocaleNotice,
|
|
19
21
|
isRunbookUnavailable,
|
|
20
22
|
} from "../index.js";
|
|
21
23
|
|
|
@@ -74,13 +76,16 @@ const PAGINA = {
|
|
|
74
76
|
|
|
75
77
|
const originalFetch = globalThis.fetch;
|
|
76
78
|
|
|
77
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* Troca o fetch: `rotas` mapeia caminho (sem /api/v1 e sem query) para { status, body }. Guarda as
|
|
81
|
+
* chamadas, com a query em `search`.
|
|
82
|
+
*/
|
|
78
83
|
function stubFetch(rotas) {
|
|
79
84
|
const chamadas = [];
|
|
80
85
|
globalThis.fetch = async (url, init) => {
|
|
81
|
-
const { pathname } = new URL(url);
|
|
86
|
+
const { pathname, search } = new URL(url);
|
|
82
87
|
const path = pathname.replace(/^\/api\/v1/, "");
|
|
83
|
-
chamadas.push({ path, headers: init.headers });
|
|
88
|
+
chamadas.push({ path, search, headers: init.headers });
|
|
84
89
|
const rota = rotas[path];
|
|
85
90
|
if (!rota) return new Response(JSON.stringify(NAO_ENCONTRADO.body), { status: 404 });
|
|
86
91
|
return new Response(JSON.stringify(rota.body), { status: rota.status });
|
|
@@ -237,7 +242,12 @@ describe("HB-6: runbook pelo MCP", () => {
|
|
|
237
242
|
for (const rastro of [RASTRO_VISA, RASTRO_MASTERCARD]) assert.doesNotMatch(tool.description, rastro);
|
|
238
243
|
}
|
|
239
244
|
}
|
|
240
|
-
for (const texto of [
|
|
245
|
+
for (const texto of [
|
|
246
|
+
RUNBOOK_UNAVAILABLE_MESSAGE,
|
|
247
|
+
RUNBOOK_EMPTY_MESSAGE,
|
|
248
|
+
runbookPageNotFoundMessage("x"),
|
|
249
|
+
runbookLocaleUnsupportedMessage("fr"),
|
|
250
|
+
]) {
|
|
241
251
|
assert.doesNotMatch(texto, RASTRO_VISA);
|
|
242
252
|
assert.doesNotMatch(texto, RASTRO_MASTERCARD);
|
|
243
253
|
assert.doesNotMatch(texto, /outro cliente/i);
|
|
@@ -253,3 +263,190 @@ describe("HB-6: runbook pelo MCP", () => {
|
|
|
253
263
|
assert.equal(isRunbookUnavailable(new Error("sem status")), false);
|
|
254
264
|
});
|
|
255
265
|
});
|
|
266
|
+
|
|
267
|
+
/** Página servida em inglês, traduzida da origem em português. */
|
|
268
|
+
const traduzida = (translation) => ({
|
|
269
|
+
...PAGINA,
|
|
270
|
+
title: "Certificates",
|
|
271
|
+
locale: "en",
|
|
272
|
+
sourceLocale: "pt-BR",
|
|
273
|
+
translation,
|
|
274
|
+
translationMissing: false,
|
|
275
|
+
availableLocales: ["pt-BR", "en"],
|
|
276
|
+
bodyMd: "## Step 1\n\nGenerate the CSR.",
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
const ARVORE_EN = {
|
|
280
|
+
...ARVORE,
|
|
281
|
+
locale: "en",
|
|
282
|
+
locales: ["pt-BR", "en"],
|
|
283
|
+
sections: [
|
|
284
|
+
{
|
|
285
|
+
slug: "integracao",
|
|
286
|
+
title: "Integração",
|
|
287
|
+
pages: [
|
|
288
|
+
{ slug: "tokenizacao", title: "Tokenization", locale: "en", sourceLocale: "pt-BR", translated: true, template: "integration" },
|
|
289
|
+
],
|
|
290
|
+
sections: [],
|
|
291
|
+
},
|
|
292
|
+
],
|
|
293
|
+
pages: [{ slug: "go-live", title: "Go-live", locale: "pt-BR", sourceLocale: "pt-BR", translated: false, template: null }],
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
describe("Runbook em outro idioma pelo MCP", () => {
|
|
297
|
+
it("sem locale, nada de query: o caminho fica igual ao de antes", async () => {
|
|
298
|
+
const chamadas = stubFetch({
|
|
299
|
+
"/runbook": { status: 200, body: ARVORE },
|
|
300
|
+
"/runbook/pages/certificados": { status: 200, body: PAGINA },
|
|
301
|
+
});
|
|
302
|
+
const mcp = await conectar("visa");
|
|
303
|
+
await chamar(mcp, "list_runbook", {});
|
|
304
|
+
await chamar(mcp, "read_runbook_page", { slug: "certificados" });
|
|
305
|
+
assert.deepEqual(chamadas.map((c) => c.search), ["", ""]);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it("read_runbook_page repassa o locale e marca a tradução automática", async () => {
|
|
309
|
+
const chamadas = stubFetch({
|
|
310
|
+
"/runbook/pages/certificados": { status: 200, body: traduzida({ status: "MACHINE", reviewed: false, reviewedAt: null }) },
|
|
311
|
+
});
|
|
312
|
+
const mcp = await conectar("mastercard");
|
|
313
|
+
const r = await chamar(mcp, "read_runbook_page", { slug: "certificados", locale: "en" });
|
|
314
|
+
|
|
315
|
+
assert.equal(r.isError, false, r.text);
|
|
316
|
+
assert.deepEqual(chamadas.map((c) => [c.path, c.search]), [["/runbook/pages/certificados", "?locale=en"]]);
|
|
317
|
+
assert.equal(chamadas[0].headers[CLIENT_HEADER], "mastercard");
|
|
318
|
+
assert.match(r.text, /^# Certificates$/m);
|
|
319
|
+
assert.match(r.text, /Slug: certificados \| Idioma: en \|/);
|
|
320
|
+
assert.match(r.text, /^Idioma de origem: pt-BR \| Idiomas disponíveis: pt-BR, en$/m);
|
|
321
|
+
assert.match(r.text, /^Tradução automática: texto em en traduzido do original em pt-BR, ainda sem revisão/m);
|
|
322
|
+
assert.match(r.text, /confira a origem com read_runbook_page sem locale\./);
|
|
323
|
+
assert.doesNotMatch(r.text, /locale "pt-BR"/);
|
|
324
|
+
assert.doesNotMatch(r.text, /Tradução revisada/);
|
|
325
|
+
assert.match(r.text, /slug certificados, revisão 3, tradução em en/);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it("read_runbook_page marca a tradução revisada, com a data", async () => {
|
|
329
|
+
stubFetch({
|
|
330
|
+
"/runbook/pages/certificados": {
|
|
331
|
+
status: 200,
|
|
332
|
+
body: traduzida({ status: "REVIEWED", reviewed: true, reviewedAt: "2026-11-29T12:00:00Z" }),
|
|
333
|
+
},
|
|
334
|
+
});
|
|
335
|
+
const mcp = await conectar("visa");
|
|
336
|
+
const r = await chamar(mcp, "read_runbook_page", { slug: "certificados", locale: "en" });
|
|
337
|
+
|
|
338
|
+
assert.equal(r.isError, false, r.text);
|
|
339
|
+
assert.match(r.text, /^Tradução revisada: texto em en traduzido do original em pt-BR e revisado por um curador em 2026-11-29T12:00:00Z\.$/m);
|
|
340
|
+
assert.doesNotMatch(r.text, /Tradução automática/);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it("read_runbook_page sem tradução no idioma pedido: diz que veio a origem", async () => {
|
|
344
|
+
const chamadas = stubFetch({
|
|
345
|
+
"/runbook/pages/certificados": {
|
|
346
|
+
status: 200,
|
|
347
|
+
body: { ...PAGINA, locale: "pt-BR", sourceLocale: "pt-BR", translation: null, translationMissing: true, availableLocales: ["pt-BR"] },
|
|
348
|
+
},
|
|
349
|
+
});
|
|
350
|
+
const mcp = await conectar("visa");
|
|
351
|
+
const r = await chamar(mcp, "read_runbook_page", { slug: "certificados", locale: "en" });
|
|
352
|
+
|
|
353
|
+
assert.equal(r.isError, false, r.text);
|
|
354
|
+
assert.equal(chamadas[0].search, "?locale=en");
|
|
355
|
+
assert.match(r.text, /^Sem tradução em en: veio o texto no idioma de origem \(pt-BR\)\.$/m);
|
|
356
|
+
assert.doesNotMatch(r.text, /Tradução (automática|revisada)/);
|
|
357
|
+
assert.match(r.text, /slug certificados, revisão 3\)/);
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it("read_runbook_page no idioma de origem: sem aviso de tradução", async () => {
|
|
361
|
+
stubFetch({
|
|
362
|
+
"/runbook/pages/certificados": {
|
|
363
|
+
status: 200,
|
|
364
|
+
body: { ...PAGINA, locale: "pt-BR", sourceLocale: "pt-BR", translation: null, translationMissing: false, availableLocales: ["pt-BR", "en"] },
|
|
365
|
+
},
|
|
366
|
+
});
|
|
367
|
+
const mcp = await conectar("visa");
|
|
368
|
+
const r = await chamar(mcp, "read_runbook_page", { slug: "certificados", locale: "pt-BR" });
|
|
369
|
+
assert.equal(r.isError, false, r.text);
|
|
370
|
+
assert.doesNotMatch(r.text, /Tradução|Sem tradução/);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
it("Pharos que ignora o locale (anterior à tradução): avisa que veio a origem", () => {
|
|
374
|
+
assert.equal(
|
|
375
|
+
runbookPageLocaleNotice({ ...PAGINA, locale: "pt-BR" }, "en"),
|
|
376
|
+
"Sem tradução em en: veio o texto no idioma de origem (pt-BR)."
|
|
377
|
+
);
|
|
378
|
+
assert.equal(runbookPageLocaleNotice(PAGINA, undefined), null);
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
it("read_runbook_page com locale e página ausente: o desempate pelo índice vai sem locale", async () => {
|
|
382
|
+
const chamadas = stubFetch({ "/runbook": { status: 200, body: ARVORE } });
|
|
383
|
+
const mcp = await conectar("visa");
|
|
384
|
+
const r = await chamar(mcp, "read_runbook_page", { slug: "nao-existe", locale: "en" });
|
|
385
|
+
|
|
386
|
+
assert.equal(r.isError, true);
|
|
387
|
+
assert.equal(r.text, runbookPageNotFoundMessage("nao-existe"));
|
|
388
|
+
assert.deepEqual(chamadas.map((c) => [c.path, c.search]), [
|
|
389
|
+
["/runbook/pages/nao-existe", "?locale=en"],
|
|
390
|
+
["/runbook", ""],
|
|
391
|
+
]);
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
it("list_runbook repassa o locale e marca os títulos traduzidos e os sem tradução", async () => {
|
|
395
|
+
const chamadas = stubFetch({ "/runbook": { status: 200, body: ARVORE_EN } });
|
|
396
|
+
const mcp = await conectar("visa");
|
|
397
|
+
const r = await chamar(mcp, "list_runbook", { locale: "en" });
|
|
398
|
+
|
|
399
|
+
assert.equal(r.isError, false, r.text);
|
|
400
|
+
assert.deepEqual(chamadas.map((c) => [c.path, c.search]), [["/runbook", "?locale=en"]]);
|
|
401
|
+
assert.match(r.text, /^Títulos pedidos em: en \| Idiomas disponíveis: pt-BR, en$/m);
|
|
402
|
+
assert.match(r.text, /- Tokenization \[en, traduzida de pt-BR\] \(modelo integration\): slug `tokenizacao`/);
|
|
403
|
+
assert.match(r.text, /^- Go-live \[pt-BR, sem tradução em en\]: slug `go-live`$/m);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
it("list_runbook sem locale mostra os idiomas disponíveis quando o Pharos os manda", async () => {
|
|
407
|
+
stubFetch({ "/runbook": { status: 200, body: { ...ARVORE, locale: null, locales: ["pt-BR", "en"] } } });
|
|
408
|
+
const mcp = await conectar("visa");
|
|
409
|
+
const r = await chamar(mcp, "list_runbook", {});
|
|
410
|
+
assert.match(r.text, /^Idiomas disponíveis: pt-BR, en$/m);
|
|
411
|
+
assert.doesNotMatch(r.text, /Títulos pedidos/);
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
it("locale fora do formato é recusado sem chamar a API, nos dois tools", async () => {
|
|
415
|
+
const chamadas = stubFetch({});
|
|
416
|
+
const mcp = await conectar("visa");
|
|
417
|
+
for (const locale of ["EN", "pt_BR", "pt-br", "english", "en&x=1", "", "en-"]) {
|
|
418
|
+
for (const [tool, args] of [
|
|
419
|
+
["list_runbook", { locale }],
|
|
420
|
+
["read_runbook_page", { slug: "go-live", locale }],
|
|
421
|
+
]) {
|
|
422
|
+
const r = await chamar(mcp, tool, args);
|
|
423
|
+
assert.equal(r.isError, true, `${tool} ${locale}`);
|
|
424
|
+
assert.match(r.text, /locale inválido/, `${tool} ${locale}`);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
assert.equal(chamadas.length, 0);
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
it("idioma no formato certo mas não suportado (400 do Pharos): erro legível, sem o corpo cru", async () => {
|
|
431
|
+
const naoSuportado = { status: 400, body: { title: "Bad Request", detail: "Idioma não suportado." } };
|
|
432
|
+
const chamadas = stubFetch({ "/runbook": naoSuportado, "/runbook/pages/go-live": naoSuportado });
|
|
433
|
+
const mcp = await conectar("visa");
|
|
434
|
+
for (const [tool, args] of [
|
|
435
|
+
["list_runbook", { locale: "fr" }],
|
|
436
|
+
["read_runbook_page", { slug: "go-live", locale: "fr" }],
|
|
437
|
+
]) {
|
|
438
|
+
const r = await chamar(mcp, tool, args);
|
|
439
|
+
assert.equal(r.isError, true, tool);
|
|
440
|
+
assert.equal(r.text, runbookLocaleUnsupportedMessage("fr"), tool);
|
|
441
|
+
}
|
|
442
|
+
assert.deepEqual(chamadas.map((c) => c.search), ["?locale=fr", "?locale=fr"]);
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
it("400 sem locale não vira mensagem de idioma", async () => {
|
|
446
|
+
stubFetch({ "/runbook": { status: 400, body: { detail: "outra coisa" } } });
|
|
447
|
+
const mcp = await conectar("visa");
|
|
448
|
+
const r = await chamar(mcp, "list_runbook", {});
|
|
449
|
+
assert.equal(r.isError, true);
|
|
450
|
+
assert.match(r.text, /Pharos respondeu 400/);
|
|
451
|
+
});
|
|
452
|
+
});
|