userActionTraceCatalog.test.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. CORE_USER_ACTION_FEATURES,
  4. SETTINGS_USER_ACTION_FEATURES,
  5. USER_ACTION_CATALOG,
  6. } from "../src/lib/userActionTraceCatalog.js";
  7. describe("user action trace catalog", () => {
  8. it("固定 24 个 Core 与 15 个 Settings 叶子 feature", () => {
  9. expect(Object.keys(CORE_USER_ACTION_FEATURES)).toHaveLength(24);
  10. expect(Object.keys(SETTINGS_USER_ACTION_FEATURES)).toHaveLength(15);
  11. expect(USER_ACTION_CATALOG.filter((entry) => entry.group === "core")).toHaveLength(94);
  12. expect(USER_ACTION_CATALOG.filter((entry) => entry.group === "settings")).toHaveLength(44);
  13. });
  14. it("feature/action 组合唯一且不使用动态标识", () => {
  15. const keys = USER_ACTION_CATALOG.map((entry) => `${entry.featureId}:${entry.action}`);
  16. expect(new Set(keys).size).toBe(keys.length);
  17. for (const entry of USER_ACTION_CATALOG) {
  18. expect(entry.featureId).toMatch(/^[a-z]+(?:[._][a-z]+)+$/u);
  19. expect(entry.action).toMatch(/^[a-z]+(?:_[a-z]+)*$/u);
  20. expect(entry.featureId).not.toMatch(/taskId|workspacePath|pluginId/iu);
  21. }
  22. });
  23. it("不声明 /event/report sink", () => {
  24. for (const entry of USER_ACTION_CATALOG) {
  25. expect(entry).not.toHaveProperty("eventPolicy");
  26. expect(entry).not.toHaveProperty("elementName");
  27. }
  28. });
  29. });