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