test: harden package boundaries and audit budgets
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@wrnexus/store",
|
||||
"version": "0.8.11",
|
||||
"version": "0.8.12",
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
"exports": {
|
||||
|
||||
@@ -30,3 +30,33 @@ test("memory persistence includes only approved fields and migrates old state",
|
||||
expect(second.state.theme).toBe("light-v2");
|
||||
expect(second.state.secret).toBe("initial");
|
||||
});
|
||||
|
||||
test("invalid persisted state fails closed to the store defaults", async () => {
|
||||
const name = `preferences-validation-${crypto.randomUUID()}`;
|
||||
const firstDefinition = defineStore({
|
||||
name,
|
||||
kind: "global" as const,
|
||||
createSharedState: () => ({ theme: "dark" }),
|
||||
persist: { storage: "memory" as const, version: 1, include: ["theme"] },
|
||||
actions: {
|
||||
setTheme: {
|
||||
runtime: "client" as const,
|
||||
handler: ({ state }: any, theme: string) => void (state.theme = theme),
|
||||
},
|
||||
},
|
||||
});
|
||||
const first = await new StoreContainer({ runtime: "client" }).use(firstDefinition);
|
||||
await first.actions.setTheme("corrupt");
|
||||
|
||||
const validated = defineStore({
|
||||
...firstDefinition,
|
||||
persist: {
|
||||
storage: "memory" as const,
|
||||
version: 1,
|
||||
include: ["theme"],
|
||||
validate: (value: any) => (value?.theme === "light" ? value : null),
|
||||
},
|
||||
});
|
||||
const second = await new StoreContainer({ runtime: "client" }).use(validated);
|
||||
expect(second.state.theme).toBe("dark");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user