@prismatic-io/lux 0.0.1 → 0.0.2-preview.4
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.
- package/lib/answerers/terminal/index.js +1 -1
- package/lib/answerers/terminal/index.js.map +1 -1
- package/lib/assertions/authoring.d.ts +14 -0
- package/lib/assertions/authoring.d.ts.map +1 -0
- package/lib/assertions/authoring.js +3 -0
- package/lib/assertions/authoring.js.map +1 -0
- package/lib/assertions/core/helpers.d.ts +2 -7
- package/lib/assertions/core/helpers.d.ts.map +1 -1
- package/lib/assertions/core/helpers.js +2 -6
- package/lib/assertions/core/helpers.js.map +1 -1
- package/lib/authoring.d.ts +1 -0
- package/lib/authoring.d.ts.map +1 -1
- package/lib/authoring.js +1 -0
- package/lib/authoring.js.map +1 -1
- package/lib/cli/program.d.ts.map +1 -1
- package/lib/cli/program.js +6 -2
- package/lib/cli/program.js.map +1 -1
- package/lib/cli/render/reporter.d.ts.map +1 -1
- package/lib/cli/render/reporter.js +16 -3
- package/lib/cli/render/reporter.js.map +1 -1
- package/lib/cli/run-options.d.ts +1 -0
- package/lib/cli/run-options.d.ts.map +1 -1
- package/lib/cli/run-options.js.map +1 -1
- package/lib/core/artifact-evidence.d.ts +8 -0
- package/lib/core/artifact-evidence.d.ts.map +1 -1
- package/lib/core/artifact-evidence.js +36 -4
- package/lib/core/artifact-evidence.js.map +1 -1
- package/lib/core/assertion.d.ts +19 -9
- package/lib/core/assertion.d.ts.map +1 -1
- package/lib/core/assertion.js +26 -0
- package/lib/core/assertion.js.map +1 -1
- package/lib/core/case-authoring-state.d.ts +12 -0
- package/lib/core/case-authoring-state.d.ts.map +1 -0
- package/lib/core/case-authoring-state.js +43 -0
- package/lib/core/case-authoring-state.js.map +1 -0
- package/lib/core/case.d.ts +29 -1
- package/lib/core/case.d.ts.map +1 -1
- package/lib/core/case.js +14 -6
- package/lib/core/case.js.map +1 -1
- package/lib/core/driver.d.ts +3 -0
- package/lib/core/driver.d.ts.map +1 -1
- package/lib/core/driver.js.map +1 -1
- package/lib/core/events.d.ts +2 -0
- package/lib/core/events.d.ts.map +1 -1
- package/lib/core/events.js +1 -0
- package/lib/core/events.js.map +1 -1
- package/lib/core/lifecycle-fixtures.d.ts +3 -1
- package/lib/core/lifecycle-fixtures.d.ts.map +1 -1
- package/lib/core/lifecycle-fixtures.js +4 -2
- package/lib/core/lifecycle-fixtures.js.map +1 -1
- package/lib/core/lifecycle-hooks.d.ts +9 -0
- package/lib/core/lifecycle-hooks.d.ts.map +1 -1
- package/lib/core/lifecycle-hooks.js +8 -2
- package/lib/core/lifecycle-hooks.js.map +1 -1
- package/lib/core/run.d.ts +1 -0
- package/lib/core/run.d.ts.map +1 -1
- package/lib/core/wire.d.ts +1 -0
- package/lib/core/wire.d.ts.map +1 -1
- package/lib/core/wire.js +5 -1
- package/lib/core/wire.js.map +1 -1
- package/lib/drivers/subprocess/index.d.ts.map +1 -1
- package/lib/drivers/subprocess/index.js +6 -0
- package/lib/drivers/subprocess/index.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -4
- package/lib/index.js.map +1 -1
- package/lib/orchestrator/annotation-store.d.ts.map +1 -1
- package/lib/orchestrator/annotation-store.js +6 -2
- package/lib/orchestrator/annotation-store.js.map +1 -1
- package/lib/orchestrator/case-extensions.d.ts +6 -0
- package/lib/orchestrator/case-extensions.d.ts.map +1 -0
- package/lib/orchestrator/case-extensions.js +28 -0
- package/lib/orchestrator/case-extensions.js.map +1 -0
- package/lib/orchestrator/config.d.ts.map +1 -1
- package/lib/orchestrator/config.js +0 -2
- package/lib/orchestrator/config.js.map +1 -1
- package/lib/orchestrator/doctor.d.ts.map +1 -1
- package/lib/orchestrator/doctor.js +5 -3
- package/lib/orchestrator/doctor.js.map +1 -1
- package/lib/orchestrator/grader-experiment.d.ts +12 -0
- package/lib/orchestrator/grader-experiment.d.ts.map +1 -1
- package/lib/orchestrator/grading.d.ts +2 -1
- package/lib/orchestrator/grading.d.ts.map +1 -1
- package/lib/orchestrator/grading.js +16 -4
- package/lib/orchestrator/grading.js.map +1 -1
- package/lib/orchestrator/loader.d.ts.map +1 -1
- package/lib/orchestrator/loader.js +2 -0
- package/lib/orchestrator/loader.js.map +1 -1
- package/lib/orchestrator/orchestrator.d.ts +3 -0
- package/lib/orchestrator/orchestrator.d.ts.map +1 -1
- package/lib/orchestrator/orchestrator.js +42 -14
- package/lib/orchestrator/orchestrator.js.map +1 -1
- package/lib/orchestrator/owned-lock.d.ts.map +1 -1
- package/lib/orchestrator/owned-lock.js +52 -38
- package/lib/orchestrator/owned-lock.js.map +1 -1
- package/lib/orchestrator/regrade.d.ts +6 -0
- package/lib/orchestrator/regrade.d.ts.map +1 -1
- package/lib/orchestrator/regrade.js +8 -4
- package/lib/orchestrator/regrade.js.map +1 -1
- package/lib/orchestrator/run-execution.d.ts +2 -1
- package/lib/orchestrator/run-execution.d.ts.map +1 -1
- package/lib/orchestrator/run-execution.js +3 -2
- package/lib/orchestrator/run-execution.js.map +1 -1
- package/package.json +1 -2
- package/skills/lux/SKILL.md +7 -3
- package/skills/lux/references/cli.md +25 -2
- package/skills/lux/references/eval-authoring.md +156 -4
- package/skills/lux-answerer/SKILL.md +1 -1
- package/src/answerers/terminal/index.ts +1 -1
- package/src/assertions/authoring.ts +79 -0
- package/src/assertions/core/helpers.ts +3 -6
- package/src/authoring.ts +1 -0
- package/src/cli/program.ts +9 -2
- package/src/cli/render/reporter.ts +18 -3
- package/src/cli/run-options.ts +1 -0
- package/src/core/artifact-evidence.ts +47 -4
- package/src/core/assertion.ts +41 -22
- package/src/core/case-authoring-state.ts +65 -0
- package/src/core/case.ts +57 -6
- package/src/core/driver.ts +3 -0
- package/src/core/events.ts +1 -0
- package/src/core/lifecycle-fixtures.ts +7 -2
- package/src/core/lifecycle-hooks.ts +16 -2
- package/src/core/wire.ts +5 -1
- package/src/drivers/subprocess/index.ts +6 -0
- package/src/index.ts +10 -6
- package/src/orchestrator/annotation-store.ts +5 -1
- package/src/orchestrator/case-extensions.ts +44 -0
- package/src/orchestrator/config.ts +0 -2
- package/src/orchestrator/doctor.ts +5 -3
- package/src/orchestrator/grading.ts +21 -2
- package/src/orchestrator/loader.ts +2 -0
- package/src/orchestrator/orchestrator.ts +86 -40
- package/src/orchestrator/owned-lock.ts +54 -34
- package/src/orchestrator/regrade.ts +8 -7
- package/src/orchestrator/run-execution.ts +5 -1
- package/lib/answerers/scripted/index.d.ts +0 -8
- package/lib/answerers/scripted/index.d.ts.map +0 -1
- package/lib/answerers/scripted/index.js +0 -163
- package/lib/answerers/scripted/index.js.map +0 -1
- package/src/answerers/scripted/index.ts +0 -186
|
@@ -7,12 +7,15 @@ import type { Run } from "./run.js";
|
|
|
7
7
|
const DEFAULT_ARTIFACT_READ_BYTES = 5 * 1024 * 1024;
|
|
8
8
|
const MAX_ARTIFACT_READ_BYTES = 10 * 1024 * 1024;
|
|
9
9
|
|
|
10
|
+
export type RunArtifactIssueReason = "absent" | "unreadable";
|
|
11
|
+
|
|
10
12
|
export type RunArtifactInspection = {
|
|
11
13
|
target: string;
|
|
12
14
|
root: string;
|
|
13
15
|
artifact?: Artifact;
|
|
14
16
|
stats?: Stats;
|
|
15
17
|
issue?: string;
|
|
18
|
+
reason?: RunArtifactIssueReason;
|
|
16
19
|
};
|
|
17
20
|
|
|
18
21
|
type RunArtifactEvidence = {
|
|
@@ -82,6 +85,7 @@ export const inspectRunArtifact = async (
|
|
|
82
85
|
target: authoredPath,
|
|
83
86
|
root: runArtifactsRoot(run),
|
|
84
87
|
issue: `${authoredPath} contains a null byte`,
|
|
88
|
+
reason: "unreadable",
|
|
85
89
|
};
|
|
86
90
|
}
|
|
87
91
|
const matching = run.artifacts.filter((candidate) => candidate.path === authoredPath);
|
|
@@ -91,6 +95,7 @@ export const inspectRunArtifact = async (
|
|
|
91
95
|
target: resolve(root, authoredPath),
|
|
92
96
|
root,
|
|
93
97
|
issue: `${authoredPath} was not captured in the frozen artifact index`,
|
|
98
|
+
reason: "absent",
|
|
94
99
|
};
|
|
95
100
|
}
|
|
96
101
|
if (matching.some((candidate) => candidate.root !== undefined && !isAbsolute(candidate.root))) {
|
|
@@ -98,6 +103,7 @@ export const inspectRunArtifact = async (
|
|
|
98
103
|
target: authoredPath,
|
|
99
104
|
root: defaultArtifactsRoot(run),
|
|
100
105
|
issue: `${authoredPath} declares a non-absolute artifact root`,
|
|
106
|
+
reason: "unreadable",
|
|
101
107
|
};
|
|
102
108
|
}
|
|
103
109
|
const artifact = matching[0];
|
|
@@ -108,6 +114,7 @@ export const inspectRunArtifact = async (
|
|
|
108
114
|
target: authoredPath,
|
|
109
115
|
root: defaultArtifactsRoot(run),
|
|
110
116
|
issue: `${authoredPath} is ambiguous across multiple artifact roots`,
|
|
117
|
+
reason: "unreadable",
|
|
111
118
|
};
|
|
112
119
|
}
|
|
113
120
|
// A non-default root is trusted only for an exact artifact-index entry.
|
|
@@ -116,7 +123,12 @@ export const inspectRunArtifact = async (
|
|
|
116
123
|
const root = matchingRoots[0] ?? defaultArtifactsRoot(run);
|
|
117
124
|
const target = resolve(root, authoredPath);
|
|
118
125
|
if (pathEscapesRoot(root, target)) {
|
|
119
|
-
return {
|
|
126
|
+
return {
|
|
127
|
+
target,
|
|
128
|
+
root,
|
|
129
|
+
issue: `${authoredPath} escapes the captured artifact root`,
|
|
130
|
+
reason: "unreadable",
|
|
131
|
+
};
|
|
120
132
|
}
|
|
121
133
|
|
|
122
134
|
const path = relative(root, target);
|
|
@@ -134,7 +146,13 @@ export const inspectRunArtifact = async (
|
|
|
134
146
|
} catch (error) {
|
|
135
147
|
const code = (error as NodeJS.ErrnoException).code;
|
|
136
148
|
if (code === "ENOENT" || code === "ENOTDIR") {
|
|
137
|
-
return {
|
|
149
|
+
return {
|
|
150
|
+
target,
|
|
151
|
+
root,
|
|
152
|
+
...identified,
|
|
153
|
+
issue: `${authoredPath} not found`,
|
|
154
|
+
reason: "absent",
|
|
155
|
+
};
|
|
138
156
|
}
|
|
139
157
|
throw error;
|
|
140
158
|
}
|
|
@@ -144,16 +162,17 @@ export const inspectRunArtifact = async (
|
|
|
144
162
|
root,
|
|
145
163
|
...identified,
|
|
146
164
|
issue: `${authoredPath} resolves through a symlink`,
|
|
165
|
+
reason: "unreadable",
|
|
147
166
|
};
|
|
148
167
|
}
|
|
149
168
|
if (index < components.length - 1 && !stats.isDirectory()) {
|
|
150
|
-
return { target, root, ...identified, issue: `${authoredPath} not found
|
|
169
|
+
return { target, root, ...identified, issue: `${authoredPath} not found`, reason: "absent" };
|
|
151
170
|
}
|
|
152
171
|
if (index === components.length - 1) {
|
|
153
172
|
return { target, root, ...identified, stats };
|
|
154
173
|
}
|
|
155
174
|
}
|
|
156
|
-
return { target, root, ...identified, issue: `${authoredPath} not found
|
|
175
|
+
return { target, root, ...identified, issue: `${authoredPath} not found`, reason: "absent" };
|
|
157
176
|
};
|
|
158
177
|
|
|
159
178
|
export type ReadRunArtifactTextOptions = {
|
|
@@ -247,3 +266,27 @@ export const readRunArtifactText = async (
|
|
|
247
266
|
): Promise<string> => {
|
|
248
267
|
return (await readRunArtifactBytes(run, authoredPath, options)).toString("utf8");
|
|
249
268
|
};
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Read optional artifact evidence. Returns null when the artifact was never
|
|
272
|
+
* captured, and still throws when one exists but is unsafe to consume, so a
|
|
273
|
+
* traversal or symlink violation is never mistaken for missing evidence.
|
|
274
|
+
*/
|
|
275
|
+
export const readRunArtifactTextIfPresent = async (
|
|
276
|
+
run: RunArtifactEvidence,
|
|
277
|
+
authoredPath: string,
|
|
278
|
+
options: ReadRunArtifactTextOptions = {},
|
|
279
|
+
): Promise<string | null> => {
|
|
280
|
+
const inspected = await inspectRunArtifact(run, authoredPath);
|
|
281
|
+
if (inspected.reason === "absent") return null;
|
|
282
|
+
if (!inspected.stats?.isFile()) {
|
|
283
|
+
throw new Error(
|
|
284
|
+
inspected.issue ??
|
|
285
|
+
(inspected.stats ? `${authoredPath} is not a file` : `${authoredPath} not found`),
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
const maxBytes = options.maxBytes ?? DEFAULT_ARTIFACT_READ_BYTES;
|
|
289
|
+
return (
|
|
290
|
+
await readInspectedFileBytes(inspected.target, inspected.stats, maxBytes, authoredPath)
|
|
291
|
+
).toString("utf8");
|
|
292
|
+
};
|
package/src/core/assertion.ts
CHANGED
|
@@ -42,34 +42,23 @@ export interface AssertionImpl<C extends Assertion = Assertion> {
|
|
|
42
42
|
* `AssertionImpl`, plugins must describe their case configuration so Lux can
|
|
43
43
|
* reject invalid plans before starting a subject run.
|
|
44
44
|
*/
|
|
45
|
-
export type AssertionPlugin<
|
|
45
|
+
export type AssertionPlugin<
|
|
46
|
+
C extends Assertion = Assertion,
|
|
47
|
+
Input extends Assertion = C,
|
|
48
|
+
> = AssertionImpl<C> & {
|
|
46
49
|
configSchema: z.ZodObject & z.ZodType<C>;
|
|
50
|
+
/** Type-only input accepted while authoring before schema defaults apply. */
|
|
51
|
+
readonly __input?: Input;
|
|
47
52
|
/** Author-maintained identity for evaluator/schema behavior. */
|
|
48
53
|
pluginVersion: string;
|
|
49
54
|
};
|
|
50
55
|
|
|
51
56
|
type SchemaAssertion<S extends z.ZodObject> = z.output<S> extends Assertion ? z.output<S> : never;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
type SingleStringLiteral<T> = T extends string
|
|
56
|
-
? string extends T
|
|
57
|
-
? never
|
|
58
|
-
: true extends IsUnion<T>
|
|
59
|
-
? never
|
|
60
|
-
: T
|
|
61
|
-
: never;
|
|
57
|
+
type SchemaAssertionInput<S extends z.ZodObject> =
|
|
58
|
+
z.input<S> extends Assertion ? z.input<S> : never;
|
|
62
59
|
|
|
63
60
|
type LiteralAssertionType<S extends z.ZodObject> =
|
|
64
|
-
|
|
65
|
-
? z.input<S> extends { type: infer InputType }
|
|
66
|
-
? SingleStringLiteral<OutputType> extends infer Literal extends string
|
|
67
|
-
? [InputType, Literal] extends [Literal, InputType]
|
|
68
|
-
? Literal
|
|
69
|
-
: never
|
|
70
|
-
: never
|
|
71
|
-
: never
|
|
72
|
-
: never;
|
|
61
|
+
S["shape"]["type"] extends z.ZodLiteral<infer Literal extends string> ? Literal : never;
|
|
73
62
|
|
|
74
63
|
export type AssertionPluginDefinition<S extends z.ZodObject> = {
|
|
75
64
|
type: LiteralAssertionType<S>;
|
|
@@ -111,12 +100,34 @@ export const assertionPluginIssue = (definition: {
|
|
|
111
100
|
* Define a schema-validated assertion plugin while inferring the config passed
|
|
112
101
|
* to `evaluate` from the schema.
|
|
113
102
|
*/
|
|
103
|
+
export const baseAssertionFields = {
|
|
104
|
+
id: z.string().min(1).optional(),
|
|
105
|
+
weight: z.number().positive().optional(),
|
|
106
|
+
threshold: z.number().min(0).max(1).optional(),
|
|
107
|
+
name: z.string().optional(),
|
|
108
|
+
} as const;
|
|
109
|
+
|
|
114
110
|
export const defineAssertion = <S extends z.ZodObject>(
|
|
115
111
|
definition: AssertionPluginDefinition<S>,
|
|
116
|
-
): AssertionPlugin<SchemaAssertion<S>> => {
|
|
112
|
+
): AssertionPlugin<SchemaAssertion<S>, SchemaAssertionInput<S>> => {
|
|
117
113
|
const issue = assertionPluginIssue(definition);
|
|
118
114
|
if (issue) throw new TypeError(issue);
|
|
119
|
-
return definition as unknown as AssertionPlugin<SchemaAssertion<S>>;
|
|
115
|
+
return definition as unknown as AssertionPlugin<SchemaAssertion<S>, SchemaAssertionInput<S>>;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const defineAssertionRegistry = <const Plugins extends readonly AssertionPlugin[]>(
|
|
119
|
+
...plugins: Plugins
|
|
120
|
+
): Plugins => {
|
|
121
|
+
const types = new Set<string>();
|
|
122
|
+
for (const plugin of plugins) {
|
|
123
|
+
const issue = assertionPluginIssue(plugin);
|
|
124
|
+
if (issue) throw new TypeError(issue);
|
|
125
|
+
if (types.has(plugin.type)) {
|
|
126
|
+
throw new TypeError(`assertion registry has duplicate type '${plugin.type}'`);
|
|
127
|
+
}
|
|
128
|
+
types.add(plugin.type);
|
|
129
|
+
}
|
|
130
|
+
return plugins;
|
|
120
131
|
};
|
|
121
132
|
|
|
122
133
|
export const GradingAssertionEntrySchema = z.object({
|
|
@@ -137,11 +148,19 @@ export const GradingAssertionEntrySchema = z.object({
|
|
|
137
148
|
});
|
|
138
149
|
export type GradingAssertionEntry = z.infer<typeof GradingAssertionEntrySchema>;
|
|
139
150
|
|
|
151
|
+
const SkippedGradingAssertionSchema = z.object({
|
|
152
|
+
id: z.string(),
|
|
153
|
+
type: z.string(),
|
|
154
|
+
name: z.string(),
|
|
155
|
+
reason: z.literal("judge-disabled"),
|
|
156
|
+
});
|
|
157
|
+
|
|
140
158
|
export const GradingReportSchema = z.object({
|
|
141
159
|
schemaVersion: z.literal(1),
|
|
142
160
|
casePassed: z.boolean().nullable(),
|
|
143
161
|
caseScore: z.number().nullable(),
|
|
144
162
|
assertions: z.array(GradingAssertionEntrySchema),
|
|
163
|
+
skippedAssertions: z.array(SkippedGradingAssertionSchema).optional(),
|
|
145
164
|
/**
|
|
146
165
|
* Present when the subject run or grading did not complete. Assertions may
|
|
147
166
|
* still contain partial diagnostics, but the report is not a clean verdict.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { AssertionPlugin } from "./assertion.js";
|
|
2
|
+
import type { EvalCase } from "./case.js";
|
|
3
|
+
import type { LifecycleHooksPlugin } from "./lifecycle-hooks.js";
|
|
4
|
+
|
|
5
|
+
export type EvalCaseExtensions = {
|
|
6
|
+
assertions: readonly AssertionPlugin[];
|
|
7
|
+
fixtures: readonly LifecycleHooksPlugin[];
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const CASE_EXTENSIONS_KEY = Symbol.for("@prismatic-io/lux/eval-case-extensions");
|
|
11
|
+
const extensionState = globalThis as typeof globalThis & { [key: symbol]: unknown };
|
|
12
|
+
const sharedCaseExtensions = extensionState[CASE_EXTENSIONS_KEY];
|
|
13
|
+
// A project-local package and the CLI can load separate Lux module instances.
|
|
14
|
+
const caseExtensions =
|
|
15
|
+
sharedCaseExtensions instanceof WeakMap
|
|
16
|
+
? (sharedCaseExtensions as WeakMap<object, EvalCaseExtensions>)
|
|
17
|
+
: new WeakMap<object, EvalCaseExtensions>();
|
|
18
|
+
extensionState[CASE_EXTENSIONS_KEY] = caseExtensions;
|
|
19
|
+
|
|
20
|
+
const uniqueBy = <T>(values: readonly T[], keyOf: (value: T) => string, kind: string): T[] => {
|
|
21
|
+
const unique = new Map<string, T>();
|
|
22
|
+
for (const value of values) {
|
|
23
|
+
const key = keyOf(value);
|
|
24
|
+
const existing = unique.get(key);
|
|
25
|
+
if (existing && existing !== value) {
|
|
26
|
+
throw new TypeError(`case has conflicting ${kind} definitions for '${key}'`);
|
|
27
|
+
}
|
|
28
|
+
unique.set(key, value);
|
|
29
|
+
}
|
|
30
|
+
return [...unique.values()];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const collectEvalCaseExtensions = (
|
|
34
|
+
input: EvalCase,
|
|
35
|
+
assertions: readonly AssertionPlugin[] = [],
|
|
36
|
+
fixtures: readonly LifecycleHooksPlugin[] = [],
|
|
37
|
+
): EvalCaseExtensions => {
|
|
38
|
+
const availableAssertions = uniqueBy(assertions, (plugin) => plugin.type, "assertion");
|
|
39
|
+
const byType = new Map(availableAssertions.map((plugin) => [plugin.type, plugin]));
|
|
40
|
+
return {
|
|
41
|
+
assertions: uniqueBy(
|
|
42
|
+
(input.assertions ?? []).flatMap((assertion) => {
|
|
43
|
+
const plugin = byType.get(assertion.type);
|
|
44
|
+
return plugin ? [plugin] : [];
|
|
45
|
+
}),
|
|
46
|
+
(plugin) => plugin.type,
|
|
47
|
+
"assertion",
|
|
48
|
+
),
|
|
49
|
+
fixtures: uniqueBy(fixtures, (fixture) => fixture.name, "fixture"),
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const setEvalCaseExtensions = (evalCase: EvalCase, extensions: EvalCaseExtensions): void => {
|
|
54
|
+
if (extensions.assertions.length > 0 || extensions.fixtures.length > 0) {
|
|
55
|
+
caseExtensions.set(evalCase, extensions);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const evalCaseExtensions = (evalCase: EvalCase): EvalCaseExtensions =>
|
|
60
|
+
caseExtensions.get(evalCase) ?? { assertions: [], fixtures: [] };
|
|
61
|
+
|
|
62
|
+
export const transferEvalCaseExtensions = (source: EvalCase, target: EvalCase): void => {
|
|
63
|
+
const extensions = caseExtensions.get(source);
|
|
64
|
+
if (extensions) caseExtensions.set(target, extensions);
|
|
65
|
+
};
|
package/src/core/case.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import type { AssertionPlugin } from "./assertion.js";
|
|
3
|
+
import { collectEvalCaseExtensions, setEvalCaseExtensions } from "./case-authoring-state.js";
|
|
4
|
+
import type { LifecycleHooksPlugin } from "./lifecycle-hooks.js";
|
|
2
5
|
import { formatZodIssues } from "./zod.js";
|
|
3
6
|
|
|
4
7
|
export const FixturesRefSchema = z.union([
|
|
@@ -67,14 +70,62 @@ export const EvalCaseSchema = EvalCaseObjectSchema
|
|
|
67
70
|
});
|
|
68
71
|
export type EvalCase = z.infer<typeof EvalCaseSchema>;
|
|
69
72
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
type AssertionPlanFields = Pick<Assertion, "id" | "name" | "threshold" | "weight">;
|
|
74
|
+
type AssertionInputOf<Plugin> =
|
|
75
|
+
Plugin extends AssertionPlugin<Assertion, infer Input> ? Input & AssertionPlanFields : never;
|
|
76
|
+
|
|
77
|
+
export type EvalCaseInput<AllowedAssertion extends Assertion = Assertion> = Omit<
|
|
78
|
+
EvalCase,
|
|
79
|
+
"assertions"
|
|
80
|
+
> & {
|
|
81
|
+
assertions?: AllowedAssertion[];
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export type EvalCaseAuthoringOptions<
|
|
85
|
+
Plugins extends readonly AssertionPlugin[] = readonly AssertionPlugin[],
|
|
86
|
+
> = {
|
|
87
|
+
assertions?: Plugins;
|
|
88
|
+
fixtures?: readonly LifecycleHooksPlugin[];
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export type EvalCaseDefinition<AllowedAssertion extends Assertion = Assertion> = {
|
|
92
|
+
(input: EvalCaseInput<AllowedAssertion>): EvalCase;
|
|
93
|
+
/**
|
|
94
|
+
* Create a case definition with selectively activated lifecycle fixtures.
|
|
95
|
+
* Further calls to `extend` append fixtures in setup order.
|
|
96
|
+
*/
|
|
97
|
+
extend<const Plugins extends readonly AssertionPlugin[] = readonly []>(
|
|
98
|
+
options: EvalCaseAuthoringOptions<Plugins>,
|
|
99
|
+
): EvalCaseDefinition<AllowedAssertion | AssertionInputOf<Plugins[number]>>;
|
|
76
100
|
};
|
|
77
101
|
|
|
102
|
+
export const createEvalCaseDefinition = <AllowedAssertion extends Assertion = Assertion>(
|
|
103
|
+
inheritedAssertions: readonly AssertionPlugin[] = [],
|
|
104
|
+
inheritedFixtures: readonly LifecycleHooksPlugin[] = [],
|
|
105
|
+
): EvalCaseDefinition<AllowedAssertion> => {
|
|
106
|
+
const define = ((input: EvalCaseInput<AllowedAssertion>): EvalCase => {
|
|
107
|
+
const parsed = EvalCaseSchema.safeParse(input);
|
|
108
|
+
if (!parsed.success) {
|
|
109
|
+
throw new Error(`Invalid eval case: ${formatZodIssues(parsed.error)}`);
|
|
110
|
+
}
|
|
111
|
+
const extensions = collectEvalCaseExtensions(
|
|
112
|
+
parsed.data,
|
|
113
|
+
inheritedAssertions,
|
|
114
|
+
inheritedFixtures,
|
|
115
|
+
);
|
|
116
|
+
setEvalCaseExtensions(parsed.data, extensions);
|
|
117
|
+
return parsed.data;
|
|
118
|
+
}) as EvalCaseDefinition<AllowedAssertion>;
|
|
119
|
+
define.extend = (({ assertions = [], fixtures = [] }: EvalCaseAuthoringOptions) =>
|
|
120
|
+
createEvalCaseDefinition(
|
|
121
|
+
[...inheritedAssertions, ...assertions],
|
|
122
|
+
[...inheritedFixtures, ...fixtures],
|
|
123
|
+
)) as EvalCaseDefinition<AllowedAssertion>["extend"];
|
|
124
|
+
return define;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export const defineEvalCase = createEvalCaseDefinition();
|
|
128
|
+
|
|
78
129
|
const PersistedFixturesRefSchema = z.union([
|
|
79
130
|
z.string(),
|
|
80
131
|
z.looseObject({ kind: z.literal("dir"), path: z.string() }),
|
package/src/core/driver.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { EventHandler } from "./emitter.js";
|
|
3
3
|
import type { Answer, Done, ErrorEvent, Interrupt, Progress, ReadyState } from "./events.js";
|
|
4
|
+
import type { FixtureValueBinding } from "./lifecycle-hooks.js";
|
|
4
5
|
|
|
5
6
|
export const ArtifactSchema = z.object({
|
|
6
7
|
path: z.string(),
|
|
@@ -28,6 +29,8 @@ export type StartContext = {
|
|
|
28
29
|
caseId?: string;
|
|
29
30
|
prompt: string;
|
|
30
31
|
fixtures?: ResolvedFixtures | undefined;
|
|
32
|
+
/** Authored fixture values selected for this case. */
|
|
33
|
+
fixtureValues?: readonly FixtureValueBinding[] | undefined;
|
|
31
34
|
/** Root containing persisted runs. Drivers may use it as an isolation boundary. */
|
|
32
35
|
runsRoot?: string | undefined;
|
|
33
36
|
runDir: string;
|
package/src/core/events.ts
CHANGED
|
@@ -82,6 +82,7 @@ export type ErrorEventReason = z.infer<typeof ErrorEventReasonSchema>;
|
|
|
82
82
|
export const ErrorEventSchema = z.object({
|
|
83
83
|
exitReason: ErrorEventReasonSchema,
|
|
84
84
|
reason: z.string(),
|
|
85
|
+
summary: z.unknown().optional(),
|
|
85
86
|
});
|
|
86
87
|
export type ErrorEvent = z.infer<typeof ErrorEventSchema>;
|
|
87
88
|
|
|
@@ -2,6 +2,7 @@ import { valueHash } from "./hash.js";
|
|
|
2
2
|
import {
|
|
3
3
|
type CaseLifecycleHookContext,
|
|
4
4
|
defineLifecycleHooks,
|
|
5
|
+
type FixtureValue,
|
|
5
6
|
type LifecycleHookCleanup,
|
|
6
7
|
type LifecycleHooksPlugin,
|
|
7
8
|
type SuiteLifecycleHookContext,
|
|
@@ -22,6 +23,8 @@ export type LifecycleFixturesDefinition = {
|
|
|
22
23
|
* to execution identity.
|
|
23
24
|
*/
|
|
24
25
|
identity?: unknown;
|
|
26
|
+
/** Public, serializable data made available to the selected case's driver. */
|
|
27
|
+
value?: FixtureValue;
|
|
25
28
|
suite?: LifecycleFixture<SuiteLifecycleHookContext>;
|
|
26
29
|
case?: LifecycleFixture<CaseLifecycleHookContext>;
|
|
27
30
|
};
|
|
@@ -109,8 +112,8 @@ const activateFixture = async <Context extends SuiteLifecycleHookContext>(
|
|
|
109
112
|
* Setup belongs before `use`; teardown belongs after it.
|
|
110
113
|
*/
|
|
111
114
|
export const defineFixtures = (definition: LifecycleFixturesDefinition): LifecycleHooksPlugin => {
|
|
112
|
-
if (!definition.suite && !definition.case) {
|
|
113
|
-
throw new TypeError("fixtures plugin must define suite or case");
|
|
115
|
+
if (!definition.suite && !definition.case && definition.value === undefined) {
|
|
116
|
+
throw new TypeError("fixtures plugin must define value, suite, or case");
|
|
114
117
|
}
|
|
115
118
|
if (definition.suite !== undefined && typeof definition.suite !== "function") {
|
|
116
119
|
throw new TypeError("fixtures plugin suite must be a function");
|
|
@@ -123,8 +126,10 @@ export const defineFixtures = (definition: LifecycleFixturesDefinition): Lifecyc
|
|
|
123
126
|
return defineLifecycleHooks({
|
|
124
127
|
name: definition.name,
|
|
125
128
|
pluginVersion: definition.pluginVersion,
|
|
129
|
+
...(definition.value === undefined ? {} : { value: definition.value }),
|
|
126
130
|
...(definition.identity === undefined ? {} : { identity: definition.identity }),
|
|
127
131
|
implementationHash: valueHash({
|
|
132
|
+
value: definition.value,
|
|
128
133
|
identity: definition.identity,
|
|
129
134
|
suite: definition.suite,
|
|
130
135
|
case: definition.case,
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import { valueHash } from "./hash.js";
|
|
2
3
|
|
|
3
4
|
export type LifecycleHookCleanup = () => void | Promise<void>;
|
|
4
5
|
export type LifecycleHookSetupResult = LifecycleHookCleanup | undefined;
|
|
6
|
+
export const FixtureValueSchema = z.json();
|
|
7
|
+
export type FixtureValue = z.infer<typeof FixtureValueSchema>;
|
|
8
|
+
|
|
9
|
+
export type FixtureValueBinding = {
|
|
10
|
+
name: string;
|
|
11
|
+
value: FixtureValue;
|
|
12
|
+
};
|
|
5
13
|
|
|
6
14
|
export type SuiteLifecycleHookItem = {
|
|
7
15
|
id: string;
|
|
@@ -27,6 +35,8 @@ export type LifecycleHooksPlugin = {
|
|
|
27
35
|
name: string;
|
|
28
36
|
/** Author-maintained identity for setup and teardown behavior. */
|
|
29
37
|
pluginVersion: string;
|
|
38
|
+
/** Public, serializable data made available to the selected case's driver. */
|
|
39
|
+
value?: FixtureValue;
|
|
30
40
|
/**
|
|
31
41
|
* Public, non-secret values captured by hook closures and relevant to
|
|
32
42
|
* execution identity. Included in the implementation hash.
|
|
@@ -75,8 +85,11 @@ export const lifecycleHooksPluginIssue = (
|
|
|
75
85
|
if (definition.setupCase !== undefined && typeof definition.setupCase !== "function") {
|
|
76
86
|
return "lifecycle hooks plugin setupCase must be a function";
|
|
77
87
|
}
|
|
78
|
-
if (
|
|
79
|
-
return "lifecycle hooks plugin must
|
|
88
|
+
if (definition.value !== undefined && !FixtureValueSchema.safeParse(definition.value).success) {
|
|
89
|
+
return "lifecycle hooks plugin value must be JSON-serializable";
|
|
90
|
+
}
|
|
91
|
+
if (!definition.setupSuite && !definition.setupCase && definition.value === undefined) {
|
|
92
|
+
return "lifecycle hooks plugin must define a value, setupSuite, or setupCase";
|
|
80
93
|
}
|
|
81
94
|
return undefined;
|
|
82
95
|
};
|
|
@@ -93,6 +106,7 @@ export const defineLifecycleHooks = (definition: LifecycleHooksPlugin): Lifecycl
|
|
|
93
106
|
implementationHash:
|
|
94
107
|
definition.implementationHash ??
|
|
95
108
|
valueHash({
|
|
109
|
+
value: definition.value,
|
|
96
110
|
identity: definition.identity,
|
|
97
111
|
setupSuite: definition.setupSuite,
|
|
98
112
|
setupCase: definition.setupCase,
|
package/src/core/wire.ts
CHANGED
|
@@ -47,6 +47,7 @@ const ErrorEventSchema = z.object({
|
|
|
47
47
|
type: z.literal("error"),
|
|
48
48
|
exitReason: ErrorEventReasonSchema.default("error"),
|
|
49
49
|
reason: z.string(),
|
|
50
|
+
summary: z.unknown().optional(),
|
|
50
51
|
});
|
|
51
52
|
|
|
52
53
|
export const WireEventSchema = z.discriminatedUnion("type", [
|
|
@@ -85,7 +86,10 @@ const wireEventToParsed = (event: WireEvent): ParsedDriverEvent => {
|
|
|
85
86
|
if (event.type === "done") {
|
|
86
87
|
return { tag: "done", done: { exitReason: "done", summary: event.summary } };
|
|
87
88
|
}
|
|
88
|
-
return {
|
|
89
|
+
return {
|
|
90
|
+
tag: "error",
|
|
91
|
+
error: { exitReason: event.exitReason, reason: event.reason, summary: event.summary },
|
|
92
|
+
};
|
|
89
93
|
};
|
|
90
94
|
|
|
91
95
|
/**
|
|
@@ -82,6 +82,7 @@ const KILL_GRACE_MS = 5_000;
|
|
|
82
82
|
const DEFAULT_MAX_LINE_BYTES = 10_000_000;
|
|
83
83
|
const MAX_STDERR_TAIL_CHARS = 8_192;
|
|
84
84
|
const DEFAULT_MAX_ARTIFACT_FILES = 500;
|
|
85
|
+
const MAX_FIXTURE_VALUES_BYTES = 64 * 1024;
|
|
85
86
|
const ARTIFACT_SNAPSHOT_MODULE = fileURLToPath(
|
|
86
87
|
new URL("../../core/artifact-snapshot.js", import.meta.url),
|
|
87
88
|
);
|
|
@@ -139,6 +140,10 @@ class SubprocessDriverImpl implements AgentDriver {
|
|
|
139
140
|
|
|
140
141
|
async start(ctx: StartContext): Promise<ReadyState> {
|
|
141
142
|
this.artifactsDir = ctx.artifactsDir;
|
|
143
|
+
const fixtureValues = JSON.stringify(ctx.fixtureValues ?? []);
|
|
144
|
+
if (Buffer.byteLength(fixtureValues) > MAX_FIXTURE_VALUES_BYTES) {
|
|
145
|
+
throw new Error(`subprocess fixture values exceed ${MAX_FIXTURE_VALUES_BYTES} bytes`);
|
|
146
|
+
}
|
|
142
147
|
const managed = spawnManagedProcess(this.config.command, this.config.args ?? [], {
|
|
143
148
|
cwd: this.config.cwd ?? ctx.runDir,
|
|
144
149
|
env: {
|
|
@@ -147,6 +152,7 @@ class SubprocessDriverImpl implements AgentDriver {
|
|
|
147
152
|
...(ctx.caseId ? { LUX_CASE_ID: ctx.caseId } : {}),
|
|
148
153
|
LUX_RUN_DIR: ctx.runDir,
|
|
149
154
|
LUX_ARTIFACTS_DIR: ctx.artifactsDir,
|
|
155
|
+
LUX_FIXTURE_VALUES: fixtureValues,
|
|
150
156
|
LUX_PROMPT: ctx.prompt,
|
|
151
157
|
LUX_ARTIFACT_SNAPSHOT_MODULE: ARTIFACT_SNAPSHOT_MODULE,
|
|
152
158
|
},
|
package/src/index.ts
CHANGED
|
@@ -16,16 +16,15 @@ export {
|
|
|
16
16
|
PersonaAnswererConfigSchema,
|
|
17
17
|
personaAnswerer,
|
|
18
18
|
} from "./answerers/persona/index.js";
|
|
19
|
-
export {
|
|
20
|
-
type ScriptedAnswererConfig,
|
|
21
|
-
ScriptedAnswererConfigSchema,
|
|
22
|
-
scriptedAnswerer,
|
|
23
|
-
} from "./answerers/scripted/index.js";
|
|
24
19
|
export {
|
|
25
20
|
type TerminalAnswererConfig,
|
|
26
21
|
TerminalAnswererConfigSchema,
|
|
27
22
|
terminalAnswerer,
|
|
28
23
|
} from "./answerers/terminal/index.js";
|
|
24
|
+
export {
|
|
25
|
+
type BuiltinAssertion,
|
|
26
|
+
defineEvalCase,
|
|
27
|
+
} from "./assertions/authoring.js";
|
|
29
28
|
// Bundled deterministic and judge assertions.
|
|
30
29
|
export {
|
|
31
30
|
type AgentScope,
|
|
@@ -185,6 +184,7 @@ export {
|
|
|
185
184
|
type AssertionResult,
|
|
186
185
|
AssertionResultSchema,
|
|
187
186
|
defineAssertion,
|
|
187
|
+
defineAssertionRegistry,
|
|
188
188
|
type EvaluateContext,
|
|
189
189
|
type GradingAssertionEntry,
|
|
190
190
|
GradingAssertionEntrySchema,
|
|
@@ -198,8 +198,9 @@ export {
|
|
|
198
198
|
AssertionSchema,
|
|
199
199
|
type DriverRef,
|
|
200
200
|
DriverRefSchema,
|
|
201
|
-
defineEvalCase,
|
|
202
201
|
type EvalCase,
|
|
202
|
+
type EvalCaseAuthoringOptions,
|
|
203
|
+
type EvalCaseDefinition,
|
|
203
204
|
EvalCaseSchema,
|
|
204
205
|
type FixturesRef,
|
|
205
206
|
FixturesRefSchema,
|
|
@@ -300,6 +301,9 @@ export {
|
|
|
300
301
|
export {
|
|
301
302
|
type CaseLifecycleHookContext,
|
|
302
303
|
defineLifecycleHooks,
|
|
304
|
+
type FixtureValue,
|
|
305
|
+
type FixtureValueBinding,
|
|
306
|
+
FixtureValueSchema,
|
|
303
307
|
type LifecycleHookCleanup,
|
|
304
308
|
type LifecycleHookSetupResult,
|
|
305
309
|
type LifecycleHooksPlugin,
|
|
@@ -57,6 +57,7 @@ const recoverStaleLock = async (lockPath: string): Promise<boolean> => {
|
|
|
57
57
|
const acquireAnnotationLock = async (path: string): Promise<() => Promise<void>> => {
|
|
58
58
|
const lockPath = `${path}.lock`;
|
|
59
59
|
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
60
|
+
let attemptedRecovery = false;
|
|
60
61
|
while (true) {
|
|
61
62
|
try {
|
|
62
63
|
const owner = await publishOwnedLock(lockPath, {
|
|
@@ -69,7 +70,10 @@ const acquireAnnotationLock = async (path: string): Promise<() => Promise<void>>
|
|
|
69
70
|
};
|
|
70
71
|
} catch (error) {
|
|
71
72
|
if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
|
|
72
|
-
if (
|
|
73
|
+
if (!attemptedRecovery) {
|
|
74
|
+
attemptedRecovery = true;
|
|
75
|
+
if (await recoverStaleLock(lockPath)) continue;
|
|
76
|
+
}
|
|
73
77
|
if (Date.now() >= deadline) {
|
|
74
78
|
throw new Error(`timed out waiting to update grader annotations: ${path}`);
|
|
75
79
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { evalCaseExtensions } from "../core/case-authoring-state.js";
|
|
2
|
+
import type {
|
|
3
|
+
EvalCase,
|
|
4
|
+
FixtureValueBinding,
|
|
5
|
+
LifecycleHooksPlugin,
|
|
6
|
+
Registry,
|
|
7
|
+
} from "../core/index.js";
|
|
8
|
+
|
|
9
|
+
export const registryForEvalCase = (registry: Registry, evalCase: EvalCase): Registry => {
|
|
10
|
+
let resolved = registry;
|
|
11
|
+
for (const plugin of evalCaseExtensions(evalCase).assertions) {
|
|
12
|
+
const existing = resolved.getAssertion(plugin.type);
|
|
13
|
+
if (existing === plugin) continue;
|
|
14
|
+
if (existing) {
|
|
15
|
+
throw new TypeError(
|
|
16
|
+
`case-local assertion '${plugin.type}' conflicts with a registered implementation`,
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
resolved = resolved.withAssertion(plugin);
|
|
20
|
+
}
|
|
21
|
+
return resolved;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const fixturesForEvalCase = (evalCase: EvalCase): readonly LifecycleHooksPlugin[] =>
|
|
25
|
+
evalCaseExtensions(evalCase).fixtures;
|
|
26
|
+
|
|
27
|
+
export const valuesForFixtures = (
|
|
28
|
+
fixtures: readonly LifecycleHooksPlugin[],
|
|
29
|
+
): FixtureValueBinding[] =>
|
|
30
|
+
fixtures.flatMap(({ name, value }) => (value === undefined ? [] : [{ name, value }]));
|
|
31
|
+
|
|
32
|
+
export const mergeLifecycleFixtures = (
|
|
33
|
+
...groups: readonly (readonly LifecycleHooksPlugin[])[]
|
|
34
|
+
): LifecycleHooksPlugin[] => {
|
|
35
|
+
const fixtures = new Map<string, LifecycleHooksPlugin>();
|
|
36
|
+
for (const fixture of groups.flat()) {
|
|
37
|
+
const existing = fixtures.get(fixture.name);
|
|
38
|
+
if (existing && existing !== fixture) {
|
|
39
|
+
throw new TypeError(`conflicting lifecycle fixture definitions for '${fixture.name}'`);
|
|
40
|
+
}
|
|
41
|
+
fixtures.set(fixture.name, fixture);
|
|
42
|
+
}
|
|
43
|
+
return [...fixtures.values()];
|
|
44
|
+
};
|
|
@@ -4,7 +4,6 @@ import { pathToFileURL } from "node:url";
|
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { claudeCodeAnswerer } from "../answerers/claude-code/index.js";
|
|
6
6
|
import { personaAnswerer } from "../answerers/persona/index.js";
|
|
7
|
-
import { scriptedAnswerer } from "../answerers/scripted/index.js";
|
|
8
7
|
import { terminalAnswerer } from "../answerers/terminal/index.js";
|
|
9
8
|
import { allCoreAssertions } from "../assertions/core/index.js";
|
|
10
9
|
import { allMcpAssertions } from "../assertions/mcp/index.js";
|
|
@@ -182,7 +181,6 @@ const builtinDrivers: DriverPlugin<never>[] = [
|
|
|
182
181
|
const builtinAnswerers: AnswererPlugin<never>[] = [
|
|
183
182
|
personaAnswerer,
|
|
184
183
|
claudeCodeAnswerer,
|
|
185
|
-
scriptedAnswerer,
|
|
186
184
|
terminalAnswerer,
|
|
187
185
|
];
|
|
188
186
|
export const buildRegistryFromConfig = (config: ResolvedLuxConfig): Registry => {
|