test(hopper): share mocked reply validation (#16936)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-05 12:29:45 +08:00
1 parent bbd3d61f35
commit 119b8b129b
3 files changed
+28 -46

No files matched your search

+1 -26
View File
@@ -6,32 +6,7 @@ import { HopperClient } from "./HopperClient.js";
import { HopperProvider } from "./HopperProvider.js";
import { projectHopperNameInventory } from "./HopperNameInventory.js";
import {
hopperReplySchemas,
parseHopperReply as parseHopperReplyWith,
type HopperReplyMethod,
} from "./HopperReplyContracts.js";
import type { JsonValue } from "../domain/jsonValue.js";
/**
* Stand in for the client's own reply check: `HopperClient.callTool` validates
* each reply against its method contract before the provider reads it.
*/
const validatedReply =
(reply: JsonValue) =>
(
method: HopperReplyMethod,
_arguments?: unknown,
options?: { readonly operation?: string },
) =>
Promise.resolve(
parseHopperReplyWith(
hopperReplySchemas,
method,
reply,
options?.operation ?? method,
),
);
import { validatedReply } from "./HopperReplyContracts.fixture.js";
describe("Hopper name inventory labels", () => {
it("tags stripped class-object labels without rewriting source values", () => {
@@ -0,0 +1,26 @@
import type { JsonValue } from "../domain/jsonValue.js";
import {
hopperReplySchemas,
parseHopperReply,
type HopperReplyMethod,
} from "./HopperReplyContracts.js";
/**
* Stand in for the client's own reply check: `HopperClient.callTool` validates
* each reply against its method contract before the provider reads it.
*/
export const validatedReply =
(reply: JsonValue) =>
(
method: HopperReplyMethod,
_arguments?: unknown,
options?: { readonly operation?: string },
) =>
Promise.resolve(
parseHopperReply(
hopperReplySchemas,
method,
reply,
options?.operation ?? method,
),
);
+1 -20
View File
@@ -9,6 +9,7 @@ import { silentLogger } from "../logger.js";
import { HopperClient } from "./HopperClient.js";
import { HopperProvider } from "./HopperProvider.js";
import { HOPPER_OPERATIONS } from "./HopperProviderMetadata.js";
import { validatedReply } from "./HopperReplyContracts.fixture.js";
import {
hopperBridgeMethod,
parseHopperReply as parseHopperReplyWith,
@@ -19,26 +20,6 @@ import {
parseHopperShutdownReply,
} from "./HopperReplyContracts.js";
/**
* Stand in for the client's own reply check: `HopperClient.callTool` validates
* each reply against its method contract before the provider reads it.
*/
const validatedReply =
(reply: JsonValue) =>
(
method: HopperReplyMethod,
_arguments?: unknown,
options?: { readonly operation?: string },
) =>
Promise.resolve(
parseHopperReplyWith(
hopperReplySchemas,
method,
reply,
options?.operation ?? method,
),
);
const parseHopperReply = <M extends HopperReplyMethod>(
method: M,
value: JsonValue,