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(ts): assert min_confidence and minConfidence gating on Router.decideBatch

zhangang6cc870618d04
diff --git a/laya-ts/tests/router-batch.test.ts b/laya-ts/tests/router-batch.test.ts
index f4a4bd36..3e72e9a6 100644
--- a/laya-ts/tests/router-batch.test.ts
+++ b/laya-ts/tests/router-batch.test.ts
@@ -531,7 +531,21 @@ describe("Agent.predictBatch", () => {
});
it("router.decideBatch evaluates schema across batch", async () => {
- const { router } = makeRouter();
+ const customLoader = () => ({
+ async predictBatch(states: unknown[]) {
+ return states.map(() => ({
+ model: "fake",
+ answers: { flag: { type: "noul", noul: 0.1, confidence: 0.2, answer_confidence: 0.2 } },
+ }));
+ },
+ async systemOne(state: unknown) {
+ return {
+ model: "fake",
+ answers: { flag: { type: "noul", noul: 0.1, confidence: 0.2, answer_confidence: 0.2 } },
+ };
+ },
+ });
+ const router = new Router({ loader: customLoader as never });
const schema = {
type: "object",
properties: {
@@ -540,11 +554,22 @@ describe("Agent.predictBatch", () => {
};
const res1 = await router.decideBatch(["alpha", "beta"], schema);
expect(res1).toHaveLength(2);
+ expect(res1[0].flag).toBe(false);
const res2 = await router.decideBatch(["alpha"], schema, { returnDetails: true });
expect(res2).toHaveLength(1);
expect(res2[0].values).toBeDefined();
expect(res2[0].answerConfidence).toBeDefined();
expect(res2[0].confidence).toBeDefined();
+
+ // Verify min_confidence alias gates low confidence on the router path
+ const resGated = await router.decideBatch(["alpha"], schema, { min_confidence: 0.99 });
+ expect(resGated).toHaveLength(1);
+ expect(resGated[0].flag).toBeNull();
+
+ // Verify minConfidence also gates low confidence on the router path
+ const resGatedCamel = await router.decideBatch(["alpha"], schema, { minConfidence: 0.99 });
+ expect(resGatedCamel).toHaveLength(1);
+ expect(resGatedCamel[0].flag).toBeNull();
});
});