Files
openclaw/packages/gateway-protocol/src/talk-config.contract.test.ts
Peter Steinberger b1117d9862 refactor: extract gateway client package (#87797)
* refactor: extract gateway client package

* chore: drop generated gateway package artifacts

* refactor: move gateway protocol package

* refactor: remove old gateway protocol tree

* test: keep auth compat split in run mode

* test: expose gateway wrapper options for internals

* fix: watch moved gateway package sources

* test: normalize slash command import guard

* chore: teach knip gateway package entries

* ci: route gateway client package checks

* fix: reuse ipaddr for gateway client hosts

* fix: sync gateway protocol usage schema
2026-05-29 02:23:42 +01:00

76 lines
2.2 KiB
TypeScript

import fs from "node:fs";
import { describe, expect, it } from "vitest";
import { buildTalkConfigResponse } from "../../../src/config/talk.js";
import { validateTalkConfigResult } from "./index.js";
type ExpectedSelection = {
provider: string;
normalizedPayload: boolean;
voiceId?: string;
apiKey?: string;
};
type SelectionContractCase = {
id: string;
defaultProvider: string;
payloadValid: boolean;
expectedSelection: ExpectedSelection | null;
talk: Record<string, unknown>;
};
type TimeoutContractCase = {
id: string;
fallback: number;
expectedTimeoutMs: number;
talk: Record<string, unknown>;
};
type TalkConfigContractFixture = {
selectionCases: SelectionContractCase[];
timeoutCases: TimeoutContractCase[];
};
const fixturePath = new URL("../../../test/fixtures/talk-config-contract.json", import.meta.url);
const fixtures = JSON.parse(fs.readFileSync(fixturePath, "utf-8")) as TalkConfigContractFixture;
describe("talk.config contract fixtures", () => {
for (const fixture of fixtures.selectionCases) {
it(fixture.id, () => {
const payload = { config: { talk: buildTalkConfigResponse(fixture.talk) } };
if (fixture.payloadValid) {
expect(validateTalkConfigResult(payload)).toBe(true);
} else {
expect(validateTalkConfigResult(payload)).toBe(false);
}
if (!fixture.expectedSelection) {
return;
}
const talk = payload.config.talk as
| {
resolved?: {
provider?: string;
config?: {
voiceId?: string;
apiKey?: string;
};
};
}
| undefined;
expect(talk?.resolved?.provider ?? fixture.defaultProvider).toBe(
fixture.expectedSelection.provider,
);
expect(talk?.resolved?.config?.voiceId).toBe(fixture.expectedSelection.voiceId);
expect(talk?.resolved?.config?.apiKey).toBe(fixture.expectedSelection.apiKey);
});
}
for (const fixture of fixtures.timeoutCases) {
it(`timeout:${fixture.id}`, () => {
const payload = buildTalkConfigResponse(fixture.talk);
expect(payload?.silenceTimeoutMs ?? fixture.fallback).toBe(fixture.expectedTimeoutMs);
});
}
});