Files
OmniRoute/tests/unit/compression/rtk-command-detector.test.ts
Diego Rodrigues de Sa e Souza 743be29852 feat(compression): RTK compression roadmap (#1889)
* chore(rtk): initialize compression roadmap branch

* feat(compression): add RTK engine and compression combos

Introduce RTK command-aware tool-output compression alongside
stacked RTK -> Caveman pipelines for mixed prompt contexts.

Add engine registration, declarative RTK filter packs, language-aware
Caveman rule loading, compression combo persistence and assignments,
analytics grouped by engine/combo, and new MCP/API endpoints for
configuration, previews, filters, and combo management.

Expose the new capabilities in the dashboard with dedicated Context &
Cache pages for Caveman, RTK, and compression combos, and update docs,
i18n strings, migrations, and tests to cover the expanded compression
surface.

* feat(compression): expand RTK DSL, filter catalog, and recovery APIs

Add RTK parity features across the compression pipeline, dashboard,
and management APIs. This expands the built-in filter catalog, adds
trust-gated custom filter loading, inline filter verification, code
stripping, smarter detection, and optional redacted raw-output
retention for authenticated recovery.

Also extend Caveman with file-based multilingual rule packs, localized
output-mode instructions, stricter preview/config schemas, engine
registry metadata, analytics fields, and broad unit test coverage for
RTK, rule loading, and stacked compression behavior.

* fix(auth): protect oauth routes and health reset operations

Require authenticated dashboard access for OAuth endpoints that can
create or import provider connections when login enforcement is
enabled.

Move `/api/monitoring/health` to the readonly public route list so
safe methods remain public while DELETE now returns 401 for anonymous
requests.

Also update Next.js native `.node` handling to avoid webpack parse
failures from external packages such as ngrok and keytar, and add
coverage for the new auth behavior.

* build(compression): ship RTK rule and filter assets with app bundles

Include compression JSON assets in Next output tracing, prepublish copies,
and pack artifact policy checks so standalone and packaged builds can
load RTK filters and caveman rule packs at runtime.

Also harden compression runtime behavior by resolving alternate asset
directories, scoping rule cache entries by source path, carrying RTK raw
output pointers through stacked runs, degrading oversized preview diffs,
and applying combo language/output mode defaults during chat routing.

Add coverage for packaging rules, provider-scoped model parsing, smart
truncate edge cases, raw output retention, and combo-driven compression
behavior.

* docs(workflows): update local repo paths to OmniRoute

Replace outdated `/home/diegosouzapw/dev/proxys/9router` references
with the current `OmniRoute` directory across deploy, release, and
version bump workflow guides so local command examples match the
renamed repository layout

* feat(compression): complete RTK parity coverage

* test(build): align next config assertions

---------

Co-authored-by: diegosouzapw <diego.souza.pw@gmail.com>
2026-05-03 00:37:08 -03:00

108 lines
5.3 KiB
TypeScript

import { describe, it } from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { fileURLToPath } from "node:url";
import path from "node:path";
import {
detectCommandOutput,
detectCommandType,
} from "../../../open-sse/services/compression/index.ts";
const FIXTURES = path.join(path.dirname(fileURLToPath(import.meta.url)), "fixtures", "rtk");
function fixture(name: string): string {
return readFileSync(path.join(FIXTURES, name), "utf8");
}
describe("RTK command detector", () => {
it("detects planned command output classes", () => {
assert.equal(
detectCommandType(fixture("git-status-sample.txt"), "git status").type,
"git-status"
);
assert.equal(detectCommandType(fixture("git-diff-sample.txt"), "git diff").type, "git-diff");
assert.equal(detectCommandType("commit abcdef1\nAuthor: A", "git log").type, "git-log");
assert.equal(
detectCommandType(fixture("vitest-output-sample.txt"), "vitest").type,
"test-vitest"
);
assert.equal(detectCommandType("FAIL test\nTests: 1 failed", "jest").type, "test-jest");
assert.equal(detectCommandType("FAILED test_a.py::test_a", "pytest").type, "test-pytest");
assert.equal(
detectCommandType(fixture("typescript-errors-sample.txt"), "tsc --noEmit").type,
"build-typescript"
);
assert.equal(
detectCommandType(fixture("eslint-output-sample.txt"), "eslint .").type,
"build-eslint"
);
assert.equal(
detectCommandType("CONTAINER ID IMAGE COMMAND", "docker ps").type,
"docker-ps"
);
assert.equal(detectCommandType(fixture("json-output-sample.txt")).type, "json-output");
assert.equal(detectCommandType("Error: boom\n at fn").type, "generic-error");
});
it("detects RTK parity command output classes", () => {
const cases: Array<[string, string | null, string]> = [
["* feature/rtk\n main", "git branch", "git-branch"],
["running 2 tests\ntest a ... FAILED\ntest result: FAILED", "cargo test", "test-cargo"],
["--- FAIL: TestA\nFAIL\t./pkg\t0.1s", "go test ./...", "test-go"],
["webpack 5.0.0 compiled with 1 error", "webpack", "build-webpack"],
["vite v5.0.0\n✓ built in 100ms", "vite build", "build-vite"],
["2026-05-02T00:00:00Z ERROR failed", "docker logs app", "docker-logs"],
["./src/a.ts\n./src/b.ts", "find . -name '*.ts'", "shell-find"],
["src/a.ts:1:match", "rg match", "shell-grep"],
["found 1 vulnerabilities\ncritical severity", "npm audit", "npm-audit"],
['Traceback (most recent call last):\n File "a.py", line 1', null, "error-stacktrace"],
["make[1]: Entering directory '/repo'\nmake: *** [all] Error 2", "make", "make"],
[
"Terraform will perform the following actions:\nPlan: 1 to add",
"terraform plan",
"terraform-plan",
],
["OpenTofu will perform the following actions:\nPlan: 1 to add", "tofu plan", "tofu-plan"],
["Active: failed (Result: exit-code)", "systemctl status omniroute", "systemctl-status"],
["Checked 12 files in 18ms. No fixes applied.", "biome check .", "biome"],
["Checking formatting...\n[warn] src/app.ts", "prettier --check .", "prettier"],
["• Packages in scope: web\nTasks: 1 successful", "turbo build", "turbo"],
["NX Running target build for 2 projects", "nx build web", "nx"],
["Running 3 tests using 1 worker", "playwright test", "playwright"],
["src/app.py:1:1: F401 unused import", "ruff check .", "ruff"],
["src/app.py:12: error: incompatible type", "mypy src", "mypy"],
["Collecting requests\nSuccessfully installed requests", "pip install requests", "pip"],
["Resolved 42 packages\nInstalled 3 packages", "uv sync", "uv-sync"],
["Installing dependencies from lock file", "poetry install", "poetry-install"],
["pkg/main.go:22:1: issue\n2 issues:", "golangci-lint run", "golangci-lint"],
["Bundle complete! 12 Gemfile dependencies", "bundle install", "bundle-install"],
["Inspecting 2 files\napp.rb:1:1: C: Style/FrozenStringLiteralComment", "rubocop", "rubocop"],
["An error occurred (AccessDenied) when calling", "aws s3 ls", "aws"],
["ERROR: (gcloud.run.deploy) PERMISSION_DENIED", "gcloud run deploy", "gcloud"],
["Permission denied (publickey).", "ssh host", "ssh"],
["sending incremental file list\nrsync error: code 23", "rsync -av src host:", "rsync"],
["HTTP/1.1 500 Internal Server Error", "curl -i example.test", "curl"],
["ERROR 404: Not Found.", "wget example.test/missing", "wget"],
["USER PID %CPU COMMAND", "ps aux", "shell-ps"],
["Filesystem Size Used Avail Use% Mounted on", "df -h", "shell-df"],
["120M node_modules", "du -sh *", "shell-du"],
];
for (const [text, command, expected] of cases) {
const detection = detectCommandType(text, command);
assert.equal(detection.type, expected);
assert.ok(detection.matchedPatterns.length > 0);
assert.ok(detection.confidence >= 0.25);
}
});
it("returns unknown for generic text and exposes planned alias", () => {
const detection = detectCommandOutput("ordinary prose without command output");
assert.equal(detection.type, "unknown");
assert.ok(detection.confidence > 0);
assert.deepEqual(detection.matchedPatterns, []);
});
});