Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

test(batch): pin the two hook cases the batch path can still get wrong

PerryLink29069af6f98d
diff --git a/laya-ts/tests/router-batch.test.ts b/laya-ts/tests/router-batch.test.ts
index 7479f303..b7e65072 100644
--- a/laya-ts/tests/router-batch.test.ts
+++ b/laya-ts/tests/router-batch.test.ts
@@ -307,6 +307,42 @@ describe("Router.routeBatch / predictBatch", () => {
}
});
+ // Two gaps the cases above leave open, both named when #943 was closed in favour of #936.
+ it("lets a per-call hooksRaise turn raising on where the router has it off", async () => {
+ const throwing = {
+ onPredictEnd() {
+ throw new Error("hook blew up");
+ },
+ };
+ const quiet = makeRouter({ hooks: [throwing], hooksRaise: false });
+ // Router-level off, nothing per-call: the hook throws and the call still succeeds.
+ expect((await quiet.router.predictBatch([req("s", { model: "english" })])).length).toBe(1);
+
+ const loud = makeRouter({ hooks: [throwing], hooksRaise: false });
+ // The override only means something if it is honoured here: without it this resolves.
+ await expect(
+ loud.router.predictBatch([req("s", { model: "english" })], null, { hooksRaise: true }),
+ ).rejects.toThrow("hook blew up");
+ });
+
+ it("appends per-call callbacks after per-call hooks, the composition predict uses", async () => {
+ // Order, not membership: both entries run under either composition, so only the sequence
+ // fails if the arguments to composeHooks are swapped.
+ const order: string[] = [];
+ const { router } = makeRouter({});
+ await router.predictBatch([req("s", { model: "english" })], null, {
+ hooks: [{
+ onPredictStart() {
+ order.push("hooks");
+ },
+ }],
+ onPredictStart() {
+ order.push("onPredictStart");
+ },
+ });
+ expect(order).toEqual(["hooks", "onPredictStart"]);
+ });
+
it("predictMany forwards onPredictStart, onPredictEnd and hooksRaise", async () => {
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
try {