|
| 1 | +import { expect, it, describe } from "vitest"; |
| 2 | +import type { CommitInfo, PathInfo, SecurityFileStatus } from "./paths-info"; |
| 3 | +import { pathsInfo } from "./paths-info"; |
| 4 | + |
| 5 | +describe("pathsInfo", () => { |
| 6 | + it("should fetch LFS path info", async () => { |
| 7 | + const result: PathInfo[] = await pathsInfo({ |
| 8 | + repo: { |
| 9 | + name: "bert-base-uncased", |
| 10 | + type: "model", |
| 11 | + }, |
| 12 | + paths: ["tf_model.h5"], |
| 13 | + revision: "dd4bc8b21efa05ec961e3efc4ee5e3832a3679c7", |
| 14 | + }); |
| 15 | + |
| 16 | + expect(result).toHaveLength(1); |
| 17 | + |
| 18 | + const modelPathInfo = result[0]; |
| 19 | + expect(modelPathInfo.path).toBe('tf_model.h5'); |
| 20 | + expect(modelPathInfo.type).toBe('file'); |
| 21 | + // lfs pointer, therefore lfs should be defined |
| 22 | + expect(modelPathInfo?.lfs).toBeDefined(); |
| 23 | + expect(modelPathInfo?.lfs?.oid).toBe("a7a17d6d844b5de815ccab5f42cad6d24496db3850a2a43d8258221018ce87d2"); |
| 24 | + expect(modelPathInfo?.lfs?.size).toBe(536063208); |
| 25 | + expect(modelPathInfo?.lfs?.pointerSize).toBe(134); |
| 26 | + |
| 27 | + // should not include expand info |
| 28 | + expect(modelPathInfo.lastCommit).toBeUndefined(); |
| 29 | + expect(modelPathInfo.securityFileStatus).toBeUndefined(); |
| 30 | + }); |
| 31 | + |
| 32 | + it("expand parmas should fetch lastCommit and securityFileStatus", async () => { |
| 33 | + const result: (PathInfo & { |
| 34 | + lastCommit: CommitInfo, |
| 35 | + securityFileStatus: SecurityFileStatus, |
| 36 | + })[] = await pathsInfo({ |
| 37 | + repo: { |
| 38 | + name: "bert-base-uncased", |
| 39 | + type: "model", |
| 40 | + }, |
| 41 | + paths: ["tf_model.h5"], |
| 42 | + revision: "dd4bc8b21efa05ec961e3efc4ee5e3832a3679c7", |
| 43 | + expand: true, // include |
| 44 | + }); |
| 45 | + |
| 46 | + expect(result).toHaveLength(1); |
| 47 | + |
| 48 | + const modelPathInfo = result[0]; |
| 49 | + |
| 50 | + // should include expand info |
| 51 | + expect(modelPathInfo.lastCommit).toBeDefined(); |
| 52 | + expect(modelPathInfo.securityFileStatus).toBeDefined(); |
| 53 | + |
| 54 | + expect(modelPathInfo.lastCommit.id).toBe("dd4bc8b21efa05ec961e3efc4ee5e3832a3679c7"); |
| 55 | + expect(modelPathInfo.lastCommit.title).toBe("Update tf_model.h5"); |
| 56 | + expect(modelPathInfo.lastCommit.date.getTime()).toBe(1569268124000); // 2019-09-23T19:48:44.000Z |
| 57 | + }); |
| 58 | + |
| 59 | + it("non-LFS pointer should have lfs undefined", async () => { |
| 60 | + const result: (PathInfo)[] = await pathsInfo({ |
| 61 | + repo: { |
| 62 | + name: "bert-base-uncased", |
| 63 | + type: "model", |
| 64 | + }, |
| 65 | + paths: ["config.json"], |
| 66 | + revision: "dd4bc8b21efa05ec961e3efc4ee5e3832a3679c7", |
| 67 | + }); |
| 68 | + |
| 69 | + expect(result).toHaveLength(1); |
| 70 | + |
| 71 | + const modelPathInfo = result[0]; |
| 72 | + expect(modelPathInfo.path).toBe("config.json"); |
| 73 | + expect(modelPathInfo.lfs).toBeUndefined(); |
| 74 | + }); |
| 75 | +}); |
0 commit comments