Files
oh-my-pi-telegram/tests/outbound-markup.test.ts
Evandro Fonseca Junior d1d04001d0
Release / release (push) Failing after 5s
Validate / validate (push) Failing after 5m21s
chore: fork @llblab/[email protected] as @evandrodevbr/oh-my-pi-telegram
Fork of upstream llblab/[email protected].0 (SHA afe09c5) repackaged as a
drop-in extension for can1357/oh-my-pi (omp >= 16.5.2).

Changes vs upstream:
- Rename package: @llblab/pi-telegram -> @evandrodevbr/oh-my-pi-telegram
- Bump version: 0.22.0 -> 0.22.0-evandro.1
- Update repository/homepage/bugs URLs to evandrodevbr
- Add omp field in package.json (displayName + compatibleWith)
- README: prepend 'Oh My Pi (omp) Compatibility' section with install
  commands, verified-components table, upstream lineage, and rationale
- CHANGELOG: add '0.22.0-evandro.1' entry under Unreleased
- docs/: rename @llblab/pi-telegram imports to @evandrodevbr/oh-my-pi-telegram
- tests/public-api.test.ts: rename package import paths

Gates re-run on the fork:
- npm run typecheck  -> tsc --noEmit (success)
- npm test           -> 1229 pass / 0 fail / 1 platform-only skip
- npm run audit      -> found 0 vulnerabilities
- npm run pack:check -> evandrodevbr-oh-my-pi-telegram-0.22.0-evandro.1.tgz

Verified:
- omp install --link ./pi-telegram -> Linked OK
- omp plugin list -> @evandrodevbr/[email protected].0-evandro.1

Upstream lineage: badlogic/pi-telegram -> llblab/pi-telegram (0.22.0) -> evandrodevbr/oh-my-pi-telegram (this fork)
2026-07-15 14:18:16 -03:00

83 lines
2.2 KiB
TypeScript

/**
* Regression tests for Telegram outbound markup helpers
* Exercises top-level assistant action comment parsing, stripping, and voice reply planning
*/
import assert from "node:assert/strict";
import test from "node:test";
import {
collectTopLevelHtmlComments,
parseTelegramCommentAttributes,
planTelegramVoiceReply,
stripTelegramCommentMarkupForDelivery,
stripTelegramCommentMarkupForPreview,
} from "../lib/outbound-markup.ts";
test("Markup collector ignores comments inside fenced code", () => {
const markdown = [
"```",
"<!-- telegram_voice: literal -->",
"```",
"",
"<!-- telegram_voice: real -->",
].join("\n");
const { comments } = collectTopLevelHtmlComments(markdown);
assert.equal(comments.length, 1);
assert.equal(comments[0]?.content.trim(), "telegram_voice: real");
});
test("Markup stripping removes closed and partial top-level comments", () => {
assert.equal(
stripTelegramCommentMarkupForDelivery(
"Visible\n\n<!-- telegram_button: Hidden -->\n\nTail",
),
"Visible\n\nTail",
);
assert.equal(
stripTelegramCommentMarkupForPreview("Visible\n\n<!-- telegram_voice"),
"Visible",
);
});
test("Comment attribute parser supports quoted and unquoted values", () => {
assert.deepEqual(
parseTelegramCommentAttributes(
'label="Run now" prompt=continue lang=ru rate=+20%',
),
{
label: "Run now",
prompt: "continue",
lang: "ru",
rate: "+20%",
},
);
});
test("Voice reply planner extracts multiple voice replies and cleans markdown", () => {
const plan = planTelegramVoiceReply(
[
"Visible answer.",
"",
"<!-- telegram_voice lang=ru rate=+20% -->",
"Первый ответ.",
"-->",
"",
'<!-- telegram_voice lang=en text="Second answer." -->',
"",
"Tail.",
].join("\n"),
);
assert.equal(plan.markdown, "Visible answer.\n\nTail.");
assert.equal(plan.voiceText, "Первый ответ.\n\nSecond answer.");
assert.deepEqual(plan.voiceReplies, [
{ text: "Первый ответ.", lang: "ru", rate: "+20%" },
{ text: "Second answer.", lang: "en" },
]);
assert.equal(plan.lang, "en");
assert.equal(plan.rate, "+20%");
});