Files
oh-my-pi-telegram/tests/prompt-templates.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

130 lines
4.0 KiB
TypeScript

/**
* Regression tests for Telegram prompt-template bridge helpers
* Covers Pi prompt-template discovery filtering and command expansion
*/
import assert from "node:assert/strict";
import test from "node:test";
import {
createTelegramPromptTemplateCommandGetter,
expandTelegramPromptTemplateCommand,
getTelegramPromptTemplateCommands,
mapPiPromptTemplateNameToTelegramCommandName,
parsePromptTemplateArgs,
substitutePromptTemplateArgs,
} from "../lib/prompt-templates.ts";
import { TELEGRAM_RESERVED_COMMAND_NAMES } from "../lib/commands.ts";
import type { PiSlashCommandInfo } from "../lib/pi.ts";
function createCommand(
name: string,
source: PiSlashCommandInfo["source"],
description?: string,
): PiSlashCommandInfo {
return {
name,
description,
source,
sourceInfo: {
path: `/prompts/${name}.md`,
source: "local",
scope: "project",
origin: "top-level",
},
};
}
test("Prompt-template helpers expose valid Telegram command templates", () => {
const commands = getTelegramPromptTemplateCommands(
[
createCommand("review", "prompt", "Review changes"),
createCommand("fix-tests", "prompt", "Fix failing tests"),
createCommand("status", "prompt", "Reserved hidden command"),
createCommand("start", "prompt", "Reserved visible command"),
createCommand("skill", "skill", "Not a prompt"),
createCommand("review", "prompt", "Duplicate"),
],
new Set(TELEGRAM_RESERVED_COMMAND_NAMES),
);
assert.deepEqual(commands, [
{
command: "fix_tests",
description: "Fix failing tests",
path: "/prompts/fix-tests.md",
},
{
command: "review",
description: "Review changes",
path: "/prompts/review.md",
},
]);
});
test("Prompt-template helpers skip commands without source paths", () => {
const commandWithoutSourcePath = {
name: "review",
description: "Review changes",
source: "prompt",
} as PiSlashCommandInfo;
const commands = getTelegramPromptTemplateCommands(
[commandWithoutSourcePath],
new Set(TELEGRAM_RESERVED_COMMAND_NAMES),
);
assert.deepEqual(commands, []);
});
test("Prompt-template helpers map pi template names to Telegram commands", () => {
assert.equal(
mapPiPromptTemplateNameToTelegramCommandName("fix-tests"),
"fix_tests",
);
assert.equal(
mapPiPromptTemplateNameToTelegramCommandName("Review PR"),
"review_pr",
);
assert.equal(mapPiPromptTemplateNameToTelegramCommandName("---"), undefined);
});
test("Prompt-template command getter hides extension command conflicts", () => {
const getCommands = () => [
createCommand("review", "prompt", "Review changes"),
createCommand("start", "prompt", "Conflicts with built-in"),
createCommand("status", "prompt", "Conflicts with hidden shortcut"),
];
const getPromptTemplateCommands = createTelegramPromptTemplateCommandGetter({
getCommands,
reservedCommandNames: TELEGRAM_RESERVED_COMMAND_NAMES,
});
assert.deepEqual(
getPromptTemplateCommands().map((command) => command.command),
["review"],
);
});
test("Prompt-template helpers parse and substitute arguments like pi templates", () => {
const args = parsePromptTemplateArgs("one 'two words' \"three words\"");
assert.deepEqual(args, ["one", "two words", "three words"]);
assert.equal(
substitutePromptTemplateArgs(
"$1 | $2 | $@ | $ARGUMENTS | ${@:2} | ${@:2:1}",
args,
),
"one | two words | one two words three words | one two words three words | two words three words | two words",
);
});
test("Prompt-template helpers expand command content from template files", () => {
const expanded = expandTelegramPromptTemplateCommand(
"review",
"staged changes",
[{ command: "review", description: "Review", path: "/prompts/review.md" }],
() => "---\ndescription: Review\n---\nReview $@",
);
assert.equal(expanded, "Review staged changes");
assert.equal(
expandTelegramPromptTemplateCommand("missing", "", [], () => "unused"),
undefined,
);
});