mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 14:59:05 +00:00
test(hopper): share mocked reply validation (#16936)
This commit is contained in:
1 parent
bbd3d61f35
commit
119b8b129b
3 files changed
+28
-46
No files matched your search
@@ -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,
|
||||
),
|
||||
);
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user