@crowandraven/evalkeeper 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/README.md +7 -0
  2. package/dist/activity.d.ts +58 -0
  3. package/dist/activity.js +125 -0
  4. package/dist/activity.js.map +1 -0
  5. package/dist/assertExpect.d.ts +52 -0
  6. package/dist/assertExpect.js +104 -0
  7. package/dist/assertExpect.js.map +1 -0
  8. package/dist/blind.d.ts +79 -0
  9. package/dist/blind.js +113 -0
  10. package/dist/blind.js.map +1 -0
  11. package/dist/cli/addPages.d.ts +1 -1
  12. package/dist/cli/addPages.js +4 -1
  13. package/dist/cli/addPages.js.map +1 -1
  14. package/dist/cli/main.d.ts +1 -1
  15. package/dist/cli/main.js +4 -3
  16. package/dist/cli/main.js.map +1 -1
  17. package/dist/compare.d.ts +38 -0
  18. package/dist/compare.js +62 -0
  19. package/dist/compare.js.map +1 -1
  20. package/dist/glossary.d.ts +20 -0
  21. package/dist/glossary.js +20 -0
  22. package/dist/glossary.js.map +1 -1
  23. package/dist/health.js +5 -3
  24. package/dist/health.js.map +1 -1
  25. package/dist/importCases.d.ts +76 -5
  26. package/dist/importCases.js +114 -14
  27. package/dist/importCases.js.map +1 -1
  28. package/dist/index.d.ts +4 -0
  29. package/dist/index.js +4 -0
  30. package/dist/index.js.map +1 -1
  31. package/dist/memoryStore.js +3 -1
  32. package/dist/memoryStore.js.map +1 -1
  33. package/dist/readCheck.d.ts +116 -0
  34. package/dist/readCheck.js +321 -0
  35. package/dist/readCheck.js.map +1 -0
  36. package/dist/runner.d.ts +7 -0
  37. package/dist/runner.js +25 -3
  38. package/dist/runner.js.map +1 -1
  39. package/dist/settings.d.ts +81 -3
  40. package/dist/settings.js +160 -23
  41. package/dist/settings.js.map +1 -1
  42. package/dist/store.d.ts +10 -3
  43. package/dist/suggest.d.ts +10 -1
  44. package/dist/suggest.js +22 -4
  45. package/dist/suggest.js.map +1 -1
  46. package/dist/suiteContract.d.ts +17 -0
  47. package/dist/suiteContract.js +69 -0
  48. package/dist/suiteContract.js.map +1 -0
  49. package/dist/suites/crisisRisk.d.ts +83 -0
  50. package/dist/suites/crisisRisk.js +176 -0
  51. package/dist/suites/crisisRisk.js.map +1 -0
  52. package/dist/suites/crisisRiskCases.d.ts +40 -0
  53. package/dist/suites/crisisRiskCases.js +179 -0
  54. package/dist/suites/crisisRiskCases.js.map +1 -0
  55. package/dist/suites/index.d.ts +9 -0
  56. package/dist/suites/index.js +10 -0
  57. package/dist/suites/index.js.map +1 -0
  58. package/dist/testing.d.ts +127 -11
  59. package/dist/testing.js +378 -104
  60. package/dist/testing.js.map +1 -1
  61. package/dist/types.d.ts +92 -0
  62. package/dist/types.js +68 -0
  63. package/dist/types.js.map +1 -1
  64. package/dist/weekly.d.ts +21 -3
  65. package/dist/weekly.js +18 -1
  66. package/dist/weekly.js.map +1 -1
  67. package/package.json +5 -1
  68. package/src/activity.ts +154 -0
  69. package/src/assertExpect.ts +168 -0
  70. package/src/blind.ts +138 -0
  71. package/src/cli/addPages.ts +4 -1
  72. package/src/cli/main.ts +4 -3
  73. package/src/compare.ts +85 -0
  74. package/src/glossary.ts +36 -0
  75. package/src/health.ts +5 -3
  76. package/src/importCases.ts +172 -33
  77. package/src/index.ts +4 -0
  78. package/src/memoryStore.ts +2 -1
  79. package/src/readCheck.ts +458 -0
  80. package/src/runner.ts +33 -4
  81. package/src/settings.ts +192 -26
  82. package/src/store.ts +11 -3
  83. package/src/suggest.ts +33 -4
  84. package/src/suiteContract.ts +101 -0
  85. package/src/suites/crisisRisk.ts +250 -0
  86. package/src/suites/crisisRiskCases.ts +205 -0
  87. package/src/suites/index.ts +9 -0
  88. package/src/testing.ts +508 -109
  89. package/src/types.ts +141 -0
  90. package/src/weekly.ts +39 -3
  91. package/templates/app/evals/[suite]/compare/page.tsx +375 -0
  92. package/templates/app/evals/[suite]/page.tsx +55 -19
  93. package/templates/app/evals/[suite]/rate/page.tsx +133 -0
  94. package/templates/app/evals/[suite]/runs/[runId]/page.tsx +12 -0
  95. package/templates/app/evals/[suite]/side-by-side/page.tsx +300 -0
  96. package/templates/components/evalkeeper/DisagreementChip.tsx +35 -0
  97. package/templates/components/evalkeeper/RollBack.tsx +21 -1
  98. package/templates/components/evalkeeper/SettingsHistory.tsx +20 -2
  99. package/templates/components/evalkeeper/WeeklyCheck.tsx +34 -2
  100. package/templates/lib/evalkeeper/actions.ts +68 -4
  101. package/templates/lib/evalkeeper/weekly.ts +27 -4
package/dist/testing.d.ts CHANGED
@@ -1,11 +1,59 @@
1
+ import type { ContractExpect } from "./assertExpect.js";
1
2
  import type { FeedbackStore } from "./feedback.js";
2
3
  import { type SettingsStore } from "./settings.js";
3
4
  import type { EvalStore } from "./store.js";
5
+ import type { AnySuite } from "./types.js";
6
+ import { type ReadCheckReport } from "./readCheck.js";
7
+ export { assertExpect, type ContractExpect, type ContractMatchers, } from "./assertExpect.js";
8
+ /**
9
+ * The test functions a contract registers its tests with. Vitest's
10
+ * `describe`, `it`, `expect`, and `afterAll` fit, and so do `node:test`'s
11
+ * `describe`, `it`, and `after` with `assertExpect`.
12
+ */
13
+ export type ContractTest = {
14
+ /** Groups tests, like Vitest's or node:test's `describe`. */
15
+ describe: (name: string, fn: () => void) => unknown;
16
+ /** Adds a test, like Vitest's or node:test's `it`. */
17
+ it: (name: string, fn: () => Promise<void> | void) => unknown;
18
+ /** Checks values: Vitest's `expect`, or `assertExpect` on node:assert. */
19
+ expect: ContractExpect;
20
+ /**
21
+ * Runs once after a group's tests, like Vitest's `afterAll` or
22
+ * node:test's `after`. Needed only with `cleanup`.
23
+ */
24
+ afterAll?: (fn: () => Promise<void> | void) => unknown;
25
+ };
26
+ /** Options every contract takes. */
27
+ export type ContractOptions = {
28
+ /** The test functions to use. Vitest's by default. */
29
+ test?: ContractTest;
30
+ };
31
+ /**
32
+ * Options for running a store contract on a database that holds other
33
+ * rows too, such as a shared development database.
34
+ */
35
+ export type ScopedContractOptions = ContractOptions & {
36
+ /**
37
+ * A prefix for every suite and feature the contract writes (each test
38
+ * adds its own after it), so its rows never mix with others and `make`
39
+ * needn't return an empty store. Without it, `make` must return an
40
+ * empty store every time.
41
+ */
42
+ scope?: string;
43
+ /**
44
+ * Deletes the rows whose suite or feature starts with the scope, once
45
+ * after the contract's tests (and so also any left by an earlier run
46
+ * that stopped early). Needs `scope`, and `afterAll` among the test
47
+ * functions. For Prisma, `deleteScopedRows` from
48
+ * `@crowandraven/evalkeeper-prisma`.
49
+ */
50
+ cleanup?: (scope: string) => Promise<unknown>;
51
+ };
4
52
  /**
5
53
  * Options for a store contract, for a store on tables that lack an
6
54
  * optional column.
7
55
  */
8
- export type StoreContractOptions = {
56
+ export type StoreContractOptions = ScopedContractOptions & {
9
57
  /**
10
58
  * Settings the store has no column for. The contract then checks the
11
59
  * store refuses a value for them (rather than losing it) and reads
@@ -14,29 +62,97 @@ export type StoreContractOptions = {
14
62
  without?: ("temperature" | "maxOutputTokens")[];
15
63
  };
16
64
  /**
17
- * The contract every EvalStore must meet, as Vitest tests. Run it against
18
- * your store to know the runner will work on it. `make` must return an
19
- * empty store each time it's called; `opts.without` names run settings
20
- * its tables have no column for.
65
+ * The contract every EvalStore must meet. Run it against your store to
66
+ * know the runner will work on it. `make` must return an empty store each
67
+ * time it's called, unless `opts.scope` is set: then every suite the
68
+ * contract writes (and every request hash it picks) starts with the
69
+ * scope, the tests never look past their own rows, and `opts.cleanup`
70
+ * deletes those suites' cases, answers, tests, and outputs afterward, so
71
+ * it can run on a database that holds other rows. `opts.without` names
72
+ * run settings its tables have no column for; `opts.test` passes test
73
+ * functions other than Vitest's.
21
74
  *
22
75
  * @example
23
76
  * ```ts
24
77
  * import { describeStoreContract } from "@crowandraven/evalkeeper/testing";
25
78
  *
26
79
  * describeStoreContract("my store", () => myStore(freshDatabase()));
80
+ *
81
+ * // On a database with other rows: only rows starting "contract-" are
82
+ * // written, and cleanup deletes only those.
83
+ * describeStoreContract("our tables", () => prismaStore(prisma, map), {
84
+ * scope: "contract-",
85
+ * cleanup: (scope) => deleteScopedRows(prisma, scope, { map }),
86
+ * });
27
87
  * ```
28
88
  */
29
89
  export declare function describeStoreContract(name: string, make: () => EvalStore | Promise<EvalStore>, opts?: StoreContractOptions): void;
30
90
  /**
31
91
  * The contract every FeedbackStore must meet. `make` must return an empty
32
- * store each time it's called.
92
+ * store each time it's called, unless `opts.scope` is set (see
93
+ * `describeStoreContract`): then every feature the contract rates starts
94
+ * with the scope, and its lists ask for those features only.
33
95
  */
34
- export declare function describeFeedbackStoreContract(name: string, make: () => FeedbackStore | Promise<FeedbackStore>): void;
96
+ export declare function describeFeedbackStoreContract(name: string, make: () => FeedbackStore | Promise<FeedbackStore>, opts?: ScopedContractOptions): void;
97
+ /** Options for the settings store contract. */
98
+ export type SettingsStoreContractOptions = ScopedContractOptions & {
99
+ /** Settings the store has no column for (see `StoreContractOptions`). */
100
+ without?: "temperature"[];
101
+ };
35
102
  /**
36
103
  * The contract every SettingsStore must meet. `make` must return an empty
37
- * store each time it's called; `opts.without` names settings its tables
38
- * have no column for (see `StoreContractOptions`).
104
+ * store each time it's called, unless `opts.scope` is set (see
105
+ * `describeStoreContract`): then every feature the contract versions
106
+ * starts with the scope. `opts.without` names settings its tables have no
107
+ * column for (see `StoreContractOptions`).
39
108
  */
40
- export declare function describeSettingsStoreContract(name: string, make: () => SettingsStore | Promise<SettingsStore>, opts?: {
41
- without?: "temperature"[];
109
+ export declare function describeSettingsStoreContract(name: string, make: () => SettingsStore | Promise<SettingsStore>, opts?: SettingsStoreContractOptions): void;
110
+ /**
111
+ * The contract every set of suites should meet, so people confirming
112
+ * answers weeks later (and the pages) can read them: unique keys, a label
113
+ * and help for every top-level field of each suite's input and answer,
114
+ * a description for every check, and starter cases that fit the suite's
115
+ * own schemas. One test per suite, listing what's missing in plain words
116
+ * (`suiteContractProblems`).
117
+ *
118
+ * @param name - What the tests are called, e.g. "our suites".
119
+ * @param suites - Every suite the app registers.
120
+ * @param opts - Test functions other than Vitest's.
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * import { describeSuiteContract } from "@crowandraven/evalkeeper/testing";
125
+ * import { SUITES } from "../lib/suites";
126
+ *
127
+ * describeSuiteContract("our suites", SUITES);
128
+ * ```
129
+ */
130
+ export declare function describeSuiteContract(name: string, suites: readonly AnySuite[], opts?: ContractOptions): void;
131
+ /**
132
+ * A read-only check, as a test, that a store mapped onto your own tables
133
+ * reads what's already there: one test per suite that fails listing every
134
+ * case, answer, test, and output that doesn't parse, with counts. It only
135
+ * reads, so it's the check to run first, on a copy of real data. Pass the
136
+ * report from `checkStoreReads` (any store) or `prismaReadCheck` (sees a
137
+ * Prisma table's values before the store fills in defaults).
138
+ *
139
+ * @param name - What the tests are called, e.g. "our answer key".
140
+ * @param check - Makes the report; called once, when the tests run.
141
+ * @param opts - The suite keys to name a test for, and test functions
142
+ * other than Vitest's.
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * import { describeMappedReadCheck } from "@crowandraven/evalkeeper/testing";
147
+ * import { prismaReadCheck } from "@crowandraven/evalkeeper-prisma";
148
+ *
149
+ * describeMappedReadCheck(
150
+ * "our answer key",
151
+ * () => prismaReadCheck(prisma, map, { suites: SUITES }),
152
+ * { suites: SUITES.map((s) => s.key) },
153
+ * );
154
+ * ```
155
+ */
156
+ export declare function describeMappedReadCheck(name: string, check: () => Promise<ReadCheckReport>, opts: ContractOptions & {
157
+ suites: readonly string[];
42
158
  }): void;