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
217 lines
6.3 KiB
TypeScript
217 lines
6.3 KiB
TypeScript
/**
|
|
* Unit tests for the pure domain-intent helpers: domain extraction from
|
|
* planner options / prose, validation, USD formatting, duck-typed
|
|
* CloudApiError inspection, and the domain-line formatter.
|
|
*/
|
|
|
|
import { describe, expect, it } from "bun:test";
|
|
import type { Memory } from "@elizaos/core";
|
|
import {
|
|
actionParams,
|
|
cloudErrorInfo,
|
|
extractDomainReferences,
|
|
formatDomainLine,
|
|
isValidDomain,
|
|
usdFromCents,
|
|
} from "../src/domain-intent.ts";
|
|
|
|
function msg(text: string): Memory {
|
|
return { content: { text } } as unknown as Memory;
|
|
}
|
|
|
|
describe("isValidDomain", () => {
|
|
it("accepts registrable domains", () => {
|
|
expect(isValidDomain("example.com")).toBe(true);
|
|
expect(isValidDomain("sub.example.co.uk")).toBe(true);
|
|
expect(isValidDomain("my-brand.io")).toBe(true);
|
|
});
|
|
|
|
it("rejects non-domains", () => {
|
|
expect(isValidDomain("example")).toBe(false);
|
|
expect(isValidDomain("-bad.com")).toBe(false);
|
|
expect(isValidDomain("bad-.com")).toBe(false);
|
|
expect(isValidDomain("a.b")).toBe(false); // TLD must be 2+ alpha
|
|
expect(isValidDomain("exa mple.com")).toBe(false);
|
|
expect(isValidDomain(`${"a".repeat(260)}.com`)).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("extractDomainReferences", () => {
|
|
it("prefers a planner-supplied option over prose", () => {
|
|
expect(
|
|
extractDomainReferences(msg("buy coolsite.io"), {
|
|
domain: "Chosen.com",
|
|
}),
|
|
).toEqual(["chosen.com"]);
|
|
});
|
|
|
|
it("reads options nested under parameters (real planner path)", () => {
|
|
expect(
|
|
extractDomainReferences(msg("irrelevant"), {
|
|
parameters: { domain: "nested.com" },
|
|
}),
|
|
).toEqual(["nested.com"]);
|
|
});
|
|
|
|
it("returns empty for an invalid option instead of falling back to prose", () => {
|
|
expect(
|
|
extractDomainReferences(msg("buy coolsite.io"), {
|
|
domain: "not a domain",
|
|
}),
|
|
).toEqual([]);
|
|
});
|
|
|
|
it("collects distinct normalized domains from prose", () => {
|
|
expect(
|
|
extractDomainReferences(
|
|
msg("is Example.com or coolsite.io available? maybe example.com."),
|
|
),
|
|
).toEqual(["example.com", "coolsite.io"]);
|
|
});
|
|
|
|
it("finds a domain inside a URL mention", () => {
|
|
expect(
|
|
extractDomainReferences(msg("point https://example.com at it")),
|
|
).toEqual(["example.com"]);
|
|
});
|
|
|
|
it("returns empty when the text names no domain", () => {
|
|
expect(extractDomainReferences(msg("buy me a domain please"))).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe("actionParams", () => {
|
|
it("merges nested parameters over top-level keys", () => {
|
|
expect(
|
|
actionParams({ appName: "Top", parameters: { appName: "Nested" } }),
|
|
).toMatchObject({ appName: "Nested" });
|
|
});
|
|
|
|
it("returns empty for non-object options", () => {
|
|
expect(actionParams(undefined)).toEqual({});
|
|
expect(actionParams("nope")).toEqual({});
|
|
});
|
|
});
|
|
|
|
describe("usdFromCents", () => {
|
|
it("formats integer cents", () => {
|
|
expect(usdFromCents(1399)).toBe("$13.99");
|
|
expect(usdFromCents(0)).toBe("$0.00");
|
|
});
|
|
});
|
|
|
|
describe("cloudErrorInfo", () => {
|
|
it("reads a CloudApiError-shaped error", () => {
|
|
const err = Object.assign(new Error("Insufficient credit balance"), {
|
|
statusCode: 402,
|
|
errorBody: {
|
|
success: false,
|
|
error: "Insufficient credit balance for this domain",
|
|
code: "insufficient_balance",
|
|
},
|
|
});
|
|
expect(cloudErrorInfo(err)).toEqual({
|
|
status: 402,
|
|
code: "insufficient_balance",
|
|
message: "Insufficient credit balance for this domain",
|
|
});
|
|
});
|
|
|
|
it("degrades gracefully on plain errors", () => {
|
|
expect(cloudErrorInfo(new Error("boom"))).toEqual({
|
|
status: null,
|
|
code: null,
|
|
message: "boom",
|
|
});
|
|
});
|
|
|
|
it("never throws on junk", () => {
|
|
expect(cloudErrorInfo(null).status).toBe(null);
|
|
expect(cloudErrorInfo(undefined).status).toBe(null);
|
|
expect(cloudErrorInfo(42).status).toBe(null);
|
|
});
|
|
});
|
|
|
|
describe("formatDomainLine", () => {
|
|
it("summarizes a cloudflare-registered active domain", () => {
|
|
const line = formatDomainLine({
|
|
domain: "example.com",
|
|
registrar: "cloudflare",
|
|
status: "active",
|
|
verified: true,
|
|
sslStatus: "active",
|
|
expiresAt: "2027-07-01T00:00:00.000Z",
|
|
});
|
|
expect(line).toContain("example.com");
|
|
expect(line).toContain("registered through Eliza Cloud");
|
|
expect(line).toContain("SSL active");
|
|
expect(line).toContain("renews 2027-07-01");
|
|
});
|
|
|
|
it("tells an unverified external domain owner the exact TXT record", () => {
|
|
const line = formatDomainLine({
|
|
domain: "example.org",
|
|
registrar: "external",
|
|
status: "pending",
|
|
verified: false,
|
|
sslStatus: "pending",
|
|
expiresAt: null,
|
|
});
|
|
expect(line).toContain("_eliza-cloud-verify.example.org");
|
|
});
|
|
});
|
|
|
|
describe("extractDomainReferences boundaries", () => {
|
|
it("never mangles an IDN into a bogus ASCII tail", () => {
|
|
expect(extractDomainReferences(msg("register münchen.de please"))).toEqual(
|
|
[],
|
|
);
|
|
});
|
|
|
|
it("does not treat an email's domain part as a purchase target", () => {
|
|
expect(
|
|
extractDomainReferences(msg("email me at user@example.com")),
|
|
).toEqual([]);
|
|
});
|
|
|
|
it("keeps a long TLD intact instead of splitting it", () => {
|
|
expect(extractDomainReferences(msg("buy example.community"))).toEqual([
|
|
"example.community",
|
|
]);
|
|
});
|
|
|
|
it("stays linear on pathological dotted input and drops over-long tokens", () => {
|
|
const junk = `${"a.".repeat(500)}com`;
|
|
expect(extractDomainReferences(msg(`look at ${junk}`))).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe("formatDomainLine edge values", () => {
|
|
it("renders a null sslStatus as pending, not 'SSL null'", () => {
|
|
const line = formatDomainLine({
|
|
domain: "example.com",
|
|
registrar: "cloudflare",
|
|
status: "pending",
|
|
verified: false,
|
|
sslStatus: null,
|
|
expiresAt: null,
|
|
});
|
|
expect(line).toContain("SSL pending");
|
|
expect(line).not.toContain("null");
|
|
});
|
|
|
|
it("includes the TXT record VALUE when the verification token is known", () => {
|
|
const line = formatDomainLine({
|
|
domain: "example.org",
|
|
registrar: "external",
|
|
status: "pending",
|
|
verified: false,
|
|
sslStatus: "pending",
|
|
expiresAt: null,
|
|
verificationToken: "eliza-verify-abc123",
|
|
});
|
|
expect(line).toContain("_eliza-cloud-verify.example.org");
|
|
expect(line).toContain("eliza-verify-abc123");
|
|
});
|
|
});
|