Files
reverse-engineering-anything/tests/composition/evmModuleContract.test.ts
T
morluto 960a387731 refactor(contracts): own CLI command names, catalog identity and schema presentation in contracts (#11425)
* refactor(contracts): move the CLI command name owner into src/contracts

* refactor(contracts): own catalog identity in contracts and server identity in process (#11435)

* refactor(contracts): move catalog identity into contracts and server identity into process

* refactor(contracts): own the advertised MCP schema presentation in contracts

* test(mcp): import the advertised presentation from contracts in toolSchemaValidity

* test(release): expect the catalog identity at its contracts path in the canary

* test(mcp): import the catalog identity from contracts in syntheticContractSurfaces

* refactor(contracts): import CLI command names from contracts in the capability conformance test
2026-11-16 05:31:37 +08:00

65 lines
2.3 KiB
TypeScript

import { expect, expectTypeOf, it, vi } from "vitest";
import { z } from "zod";
import { evmInterfaceModule } from "../../src/composition/evm.js";
import { wasmArtifactModule } from "../../src/composition/wasm.js";
import { cliCommandFor } from "../../src/contracts/cliCommandNames.js";
import { INSPECT_EVM_INTERFACE_CONTRACT } from "../../src/contracts/evm/evmToolContracts.js";
it("rejects incompatible static bindings through the complete project typecheck", () => {
// expect-type's negative assertions are checked by tsc, not the runtime
// test runner. No malformed descriptor is registered or executed here.
expectTypeOf({
...evmInterfaceModule,
contract: wasmArtifactModule.contract,
}).not.toExtend<typeof evmInterfaceModule>();
expectTypeOf({
...evmInterfaceModule,
cliCommand: cliCommandFor("inspect_wasm_artifact"),
}).not.toExtend<typeof evmInterfaceModule>();
expectTypeOf({
...evmInterfaceModule,
create: wasmArtifactModule.create,
}).not.toExtend<typeof evmInterfaceModule>();
expectTypeOf({
...evmInterfaceModule,
contract: {
...evmInterfaceModule.contract,
inputSchema: z.strictObject({ unrelated: z.string() }),
},
}).not.toExtend<typeof evmInterfaceModule>();
expectTypeOf({
...evmInterfaceModule,
contract: {
...evmInterfaceModule.contract,
outputSchema: z.strictObject({ unrelated: z.string() }),
},
}).not.toExtend<typeof evmInterfaceModule>();
});
it("keeps the named binding and gives each caller a separate lazy service owner", async () => {
expect(evmInterfaceModule.contract).toBe(INSPECT_EVM_INTERFACE_CONTRACT);
expect(evmInterfaceModule.cliCommand).toBe(
cliCommandFor("inspect_evm_interface"),
);
const first = evmInterfaceModule.create({});
const second = evmInterfaceModule.create({});
try {
expect(first).not.toBe(second);
expect(first.provider).not.toBe(second.provider);
await first.close();
const inspect = vi.spyOn(second.provider, "inspect");
const invalid = await second.inspect({
path: "relative.hex",
encoding: "hex",
});
expect(invalid).toMatchObject({
ok: false,
error: { _tag: "AnalysisInputError" },
});
expect(inspect).not.toHaveBeenCalled();
} finally {
await first.close();
await second.close();
}
});