Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03.1k
1// @ts-ignore TS61332import { expect, test } from "vitest";3 4import * as z from "zod/v3";5import { util } from "../helpers/util.js";6 7test("preprocess", () => {8 const schema = z.preprocess((data) => [data], z.string().array());9 10 const value = schema.parse("asdf");11 expect(value).toEqual(["asdf"]);12 util.assertEqual<(typeof schema)["_input"], unknown>(true);13});14 15test("async preprocess", async () => {16 const schema = z.preprocess(async (data) => [data], z.string().array());17 18 const value = await schema.parseAsync("asdf");19 expect(value).toEqual(["asdf"]);20});21 22test("preprocess ctx.addIssue with parse", () => {23 expect(() => {24 z.preprocess((data, ctx) => {25 ctx.addIssue({26 code: "custom",27 message: `${data} is not one of our allowed strings`,28 });29 return data;30 }, z.string()).parse("asdf");31 }).toThrow(32 JSON.stringify(33 [34 {35 code: "custom",36 message: "asdf is not one of our allowed strings",37 path: [],38 },39 ],40 null,41 242 )43 );44});45 46test("preprocess ctx.addIssue non-fatal by default", () => {47 try {48 z.preprocess((data, ctx) => {49 ctx.addIssue({50 code: "custom",51 message: `custom error`,52 });53 return data;54 }, z.string()).parse(1234);55 } catch (err) {56 z.ZodError.assert(err);57 expect(err.issues.length).toEqual(2);58 }59});60 61test("preprocess ctx.addIssue fatal true", () => {62 try {63 z.preprocess((data, ctx) => {64 ctx.addIssue({65 code: "custom",66 message: `custom error`,67 fatal: true,68 });69 return data;70 }, z.string()).parse(1234);71 } catch (err) {72 z.ZodError.assert(err);73 expect(err.issues.length).toEqual(1);74 }75});76 77test("async preprocess ctx.addIssue with parse", async () => {78 const schema = z.preprocess(async (data, ctx) => {79 ctx.addIssue({80 code: "custom",81 message: `custom error`,82 });83 return data;84 }, z.string());85 86 expect(await schema.safeParseAsync("asdf")).toMatchInlineSnapshot(`87 {88 "error": [ZodError: [89 {90 "code": "custom",91 "message": "custom error",92 "path": []93 }94 ]],95 "success": false,96 }97 `);98});99 100test("preprocess ctx.addIssue with parseAsync", async () => {101 const result = await z102 .preprocess(async (data, ctx) => {103 ctx.addIssue({104 code: "custom",105 message: `${data} is not one of our allowed strings`,106 });107 return data;108 }, z.string())109 .safeParseAsync("asdf");110 111 expect(JSON.parse(JSON.stringify(result))).toEqual({112 success: false,113 error: {114 issues: [115 {116 code: "custom",117 message: "asdf is not one of our allowed strings",118 path: [],119 },120 ],121 name: "ZodError",122 },123 });124});125 126test("z.NEVER in preprocess", () => {127 const foo = z.preprocess((val, ctx) => {128 if (!val) {129 ctx.addIssue({ code: z.ZodIssueCode.custom, message: "bad" });130 return z.NEVER;131 }132 return val;133 }, z.number());134 135 type foo = z.infer<typeof foo>;136 util.assertEqual<foo, number>(true);137 const arg = foo.safeParse(undefined);138 expect(arg.error!.issues).toHaveLength(2);139 expect(arg.error!.issues[0].message).toEqual("bad");140});141test("preprocess as the second property of object", () => {142 const schema = z.object({143 nonEmptyStr: z.string().min(1),144 positiveNum: z.preprocess((v) => Number(v), z.number().positive()),145 });146 const result = schema.safeParse({147 nonEmptyStr: "",148 positiveNum: "",149 });150 expect(result.success).toEqual(false);151 if (!result.success) {152 expect(result.error.issues.length).toEqual(2);153 expect(result.error.issues[0].code).toEqual(z.ZodIssueCode.too_small);154 expect(result.error.issues[1].code).toEqual(z.ZodIssueCode.too_small);155 }156});157 158test("preprocess validates with sibling errors", () => {159 expect(() => {160 z.object({161 // Must be first162 missing: z.string().refine(() => false),163 preprocess: z.preprocess((data: any) => data?.trim(), z.string().regex(/ asdf/)),164 }).parse({ preprocess: " asdf" });165 }).toThrow(166 JSON.stringify(167 [168 {169 code: "invalid_type",170 expected: "string",171 received: "undefined",172 path: ["missing"],173 message: "Required",174 },175 {176 validation: "regex",177 code: "invalid_string",178 message: "Invalid",179 path: ["preprocess"],180 },181 ],182 null,183 2184 )185 );186});187 