Files
wehub-resource-sync 426e9eeabd
Voice Workbench / headless workbench (mocked backends) (push) Has been cancelled
Voice Workbench / real acoustic lane (nightly, provisioned only) (push) Has been cancelled
ci / test (push) Has been cancelled
ci / lint-and-format (push) Has been cancelled
ci / build (push) Has been cancelled
ci / dev-startup (push) Has been cancelled
gitleaks / gitleaks (push) Has been cancelled
Markdown Links / Relative Markdown Links (push) Has been cancelled
Quality (Extended) / Homepage Build (PR smoke) (push) Has been cancelled
Quality (Extended) / Comment-only diff guard (push) Has been cancelled
Quality (Extended) / Format + Type Safety Ratchet (push) Has been cancelled
Quality (Extended) / Develop Gate (secret scan + UI determinism) (push) Has been cancelled
Quality (Extended) / Develop Gate (lint) (push) Has been cancelled
Chat shell gestures / Chat shell gesture + parity e2e (push) Has been cancelled
Cloud Gateway Discord / Test (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx @biomejs/biome check packages/lifeops-bench/src, benchmark-lint) (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx vitest run --config packages/lifeops-bench/vitest.config.ts --root packages/lifeops-bench --passWithNoTests, benchmark-tests) (push) Has been cancelled
Build Agent Image / build-and-push (push) Has been cancelled
Dev Smoke / bun run dev onboarding chat (push) Has been cancelled
Dev Smoke / Vite HMR dependency-level smoke (push) Has been cancelled
Electrobun Submodule Guard / electrobun gitlink is fetchable (push) Has been cancelled
Publish @elizaos/example-code / check_npm (push) Has been cancelled
Publish @elizaos/example-code / publish_npm (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / verify_version (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / publish_npm (push) Has been cancelled
Sandbox Live Smoke / Sandbox live smoke (push) Has been cancelled
Snap Build & Test / Build Snap (amd64) (push) Has been cancelled
Snap Build & Test / Build Snap (arm64) (push) Has been cancelled
Test Packaging / elizaos CLI global-install smoke (node + bun) (push) Has been cancelled
Cloud Gateway Webhook / Test (push) Has been cancelled
Cloud Tests / lint-and-types (push) Has been cancelled
Cloud Tests / unit-tests (push) Has been cancelled
Cloud Tests / integration-tests (push) Has been cancelled
Cloud Tests / e2e-tests (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Apps Worker (Product 2) / Determine environment (push) Has been cancelled
Deploy Apps Worker (Product 2) / Deploy apps worker to apps-control host (${{ needs.determine-env.outputs.environment }}) (push) Has been cancelled
Deploy Eliza Provisioning Worker / Determine environment (push) Has been cancelled
Deploy Eliza Provisioning Worker / Deploy worker to Hetzner host (${{ needs.determine-env.outputs.environment }} @ ${{ needs.determine-env.outputs.deployment_sha }}) (push) Has been cancelled
Dev Smoke / Classify changed paths (push) Has been cancelled
supply-chain / sbom (push) Has been cancelled
supply-chain / vulnerability-scan (push) Has been cancelled
Build, Push & Deploy to Phala Cloud / build-and-push (push) Has been cancelled
Test Packaging / Validate Packaging Configs (push) Has been cancelled
Test Packaging / Build & Test PyPI Package (push) Has been cancelled
Test Packaging / PyPI on Python ${{ matrix.python }} (push) Has been cancelled
Test Packaging / Pack & Test JS Tarballs (push) Has been cancelled
UI Fixture E2E / ui-fixture-e2e (push) Has been cancelled
UI Fixture E2E / fixture-e2e (push) Has been cancelled
UI Story Gate / story-gate (push) Has been cancelled
vault-ci / test (macos-latest) (push) Has been cancelled
vault-ci / test (ubuntu-latest) (push) Has been cancelled
vault-ci / test (windows-latest) (push) Has been cancelled
vault-ci / app-core wiring tests (push) Has been cancelled
verify-patches / verify patches/CHECKSUMS.sha256 (push) Has been cancelled
Voice Benchmark Smoke / voice-emotion fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voiceagentbench fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench-quality unit smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench TypeScript unit (no audio) (push) Has been cancelled
Voice Benchmark Smoke / voice bench smoke summary (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/app-core test bun run --cwd packages/elizaos test bun run --cwd packages/cloud/shared test], app-and-cli) (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/scenario-runner test bun run --cwd packages/vault test bun run --cwd packages/security test bun run --cwd plugins/plugin-coding-tools test], framework-packages) (push) Has been cancelled
Windows CI / windows ([bun run --cwd plugins/plugin-elizacloud test bun run --cwd plugins/plugin-discord test bun run --cwd plugins/plugin-anthropic test bun run --cwd plugins/plugin-openai test bun run --cwd plugins/plugin-app-control test bun run --cwd plugins/pl… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run build --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/agent --concurrency=4 node packages/scripts/run-bash-linux-only.mjs scripts/verify-riscv64-buildpaths.sh node packages/scripts/run… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run typecheck --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/cloud-shared --concurrency=4 bun run --cwd packages/core test bun run --cwd packages/shared test], core-runtime, 75) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:43:05 +08:00

157 lines
5.9 KiB
TypeScript

/**
* Unit tests for the shared relay sanitizer (issue elizaOS/eliza#11578).
*
* The swarm-synthesis relay path posted sub-agent finalText VERBATIM to the
* connector, leaking the orchestrator's own `[tool output: …]` envelope blocks
* to the user. This module centralizes stripping them; these tests pin the
* robustness cases (empty titles, unterminated blocks, multiple blocks, long
* remnants) that the router-private copy did not cover.
*/
import { describe, expect, it } from "vitest";
import {
DEFAULT_MAX_RELAY_CHARS,
elideLongBlocks,
sanitizeCompletionRelay,
stripToolTranscript,
} from "../../src/services/transcript-sanitizer.ts";
describe("stripToolTranscript", () => {
it("strips a normal well-formed envelope block, keeping prose", () => {
const input =
"Done building the app.\n" +
"[tool output: bash]\n$ ls\nfile.txt\n[/tool output]\n" +
"All set.";
const out = stripToolTranscript(input);
expect(out).toContain("Done building the app.");
expect(out).toContain("All set.");
expect(out).not.toContain("[tool output:");
expect(out).not.toContain("[/tool output]");
expect(out).not.toContain("file.txt");
});
it("strips an empty-title envelope block", () => {
const input =
'prefix\n[tool output: ""]\nsecret body\n[/tool output]\nsuffix';
const out = stripToolTranscript(input);
expect(out).toContain("prefix");
expect(out).toContain("suffix");
expect(out).not.toContain("secret body");
expect(out).not.toContain("tool output");
});
it("strips a bare-colon empty-title envelope block", () => {
const input = "a\n[tool output:]\nbody\n[/tool output]\nb";
const out = stripToolTranscript(input);
expect(out).toBe("a\n\nb");
});
it("strips MULTIPLE envelope blocks", () => {
const input =
"start\n" +
"[tool output: one]\naaa\n[/tool output]\n" +
"middle\n" +
"[tool output: two]\nbbb\n[/tool output]\n" +
"end";
const out = stripToolTranscript(input);
expect(out).toContain("start");
expect(out).toContain("middle");
expect(out).toContain("end");
expect(out).not.toContain("aaa");
expect(out).not.toContain("bbb");
expect(out).not.toContain("[tool output:");
});
it("strips an UNTERMINATED trailing block to end of string", () => {
const input =
"here is the result\n[tool output: truncated]\nhalf a body that never closes";
const out = stripToolTranscript(input);
expect(out).toBe("here is the result");
expect(out).not.toContain("[tool output:");
expect(out).not.toContain("half a body");
});
it("preserves prose and plain URLs", () => {
const input =
"PR opened: https://github.com/elizaos/eliza/pull/123 — see the diff.";
const out = stripToolTranscript(input);
expect(out).toBe(input.trim());
expect(out).toContain("https://github.com/elizaos/eliza/pull/123");
});
it("returns empty string for empty input", () => {
expect(stripToolTranscript("")).toBe("");
});
});
describe("elideLongBlocks", () => {
it("passes short text through unchanged", () => {
expect(elideLongBlocks("short", 2000)).toBe("short");
});
it("TRUNCATES an over-cap remnant, preserving the head (#11605 destroyed it)", () => {
// Regression for 37813124bf (#11605): a legit long deliverable (pure
// prose, no envelopes) was hard-REPLACED by the elision marker — total
// data loss. It must instead relay the head plus a truncation marker.
const prose = "Step 1: back up the database. ".repeat(100); // 3000 chars
const out = elideLongBlocks(prose);
expect(out).not.toBe(`[output elided — ${prose.length} chars]`);
expect(out.startsWith("Step 1: back up the database.")).toBe(true);
expect(out).toContain(`${prose.length} chars total]`);
});
it("bounds the truncated result to the cap", () => {
const big = "x".repeat(DEFAULT_MAX_RELAY_CHARS + 500);
const out = elideLongBlocks(big);
expect(out.length).toBeLessThanOrEqual(DEFAULT_MAX_RELAY_CHARS);
expect(out).toContain(`${big.length} chars total]`);
});
it("is idempotent: re-sanitizing truncated output is a no-op (buildTaskResultLine re-applies it)", () => {
const big = "w".repeat(5000);
const once = elideLongBlocks(big);
expect(elideLongBlocks(once)).toBe(once);
});
it("keeps text exactly at the cap", () => {
const exact = "y".repeat(DEFAULT_MAX_RELAY_CHARS);
expect(elideLongBlocks(exact)).toBe(exact);
});
});
describe("sanitizeCompletionRelay", () => {
it("strips envelopes then truncates the oversized remnant, keeping the head", () => {
const remnant = "z".repeat(DEFAULT_MAX_RELAY_CHARS + 100);
const input = `${remnant}\n[tool output: t]\nbody\n[/tool output]`;
const out = sanitizeCompletionRelay(input);
expect(out.startsWith("zzz")).toBe(true);
expect(out).toContain(`${remnant.length} chars total]`);
expect(out).not.toContain("[tool output:");
expect(out.length).toBeLessThanOrEqual(DEFAULT_MAX_RELAY_CHARS);
});
it("does NOT reduce a long pure-prose deliverable to a bare marker (#11605 regression)", () => {
// The confirmed failure: a 2.4KB detailed-migration-plan answer (strip is
// a no-op — no envelopes) synthesized as literally the elision marker.
const prose = "Here is the detailed migration plan you asked for. ".repeat(
48,
); // ~2.4KB
const out = sanitizeCompletionRelay(prose);
expect(out).not.toBe(`[output elided — ${prose.length} chars]`);
expect(
out.startsWith("Here is the detailed migration plan you asked for."),
).toBe(true);
});
it("returns empty when the whole payload was tool output", () => {
const input = "[tool output: t]\nonly a tool dump\n[/tool output]";
expect(sanitizeCompletionRelay(input)).toBe("");
});
it("returns empty for nullish input", () => {
expect(sanitizeCompletionRelay(undefined)).toBe("");
expect(sanitizeCompletionRelay(null)).toBe("");
});
});