feat: add scoped assets and storage core

This commit is contained in:
2026-08-13 16:30:15 +08:00
parent 5e60bb40e7
commit 7847c95538
10 changed files with 1345 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
import { readFile } from "node:fs/promises";
import { describe, expect, it } from "vitest";
import type { Asset } from "@/lib/types";
type AssetsContract = {
version: number;
asset: Asset;
defaults: {
platformExternalName: string;
publicExternalName: string;
platformExternalTags: string[];
publicRequiredTags: string[];
platformRegisteredFrom: string;
publicRegisteredFrom: string;
};
publicVisibility: { jobLookupLimit: number; clientTagPrefix: string };
};
describe("assets v1 compatibility contract", () => {
it("freezes the TypeScript wire shape, defaults, and public visibility rule", async () => {
const contract = JSON.parse(await readFile(new URL("../contracts/assets/assets-v1.json", import.meta.url), "utf8")) as AssetsContract;
const asset: Asset = contract.asset;
expect(contract.version).toBe(1);
expect(asset).toEqual({
id: "asset-contract-1",
ownerId: "owner-1",
kind: "image",
name: "poster.png",
url: "https://cdn.example.test/uploads/poster.png",
storagePath: "uploads/2026-08-13/poster.png",
source: "upload",
tags: ["upload"],
metadata: { contentType: "image/png", size: 4 },
createdAt: "2026-08-13T08:00:00.000Z",
updatedAt: "2026-08-13T08:00:00.000Z"
});
expect(contract.defaults).toEqual({
platformExternalName: "外部图片",
publicExternalName: "外部素材",
platformExternalTags: ["external"],
publicRequiredTags: ["external", "public-api", "api-client:agent-a"],
platformRegisteredFrom: "api",
publicRegisteredFrom: "public-api"
});
expect(contract.publicVisibility).toEqual({ jobLookupLimit: 200, clientTagPrefix: "api-client:" });
});
});