mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 12:50:43 +00:00
test: tighten trajectory assertions
This commit is contained in:
@@ -213,14 +213,17 @@ describe("exportTrajectoryBundle", () => {
|
||||
writeSimpleSessionFile(sessionFile);
|
||||
fs.mkdirSync(outputDir);
|
||||
|
||||
await expect(
|
||||
exportTrajectoryBundle({
|
||||
try {
|
||||
await exportTrajectoryBundle({
|
||||
outputDir,
|
||||
sessionFile,
|
||||
sessionId: "session-1",
|
||||
workspaceDir: tmpDir,
|
||||
}),
|
||||
).rejects.toMatchObject({ code: "EEXIST" });
|
||||
});
|
||||
throw new Error("expected trajectory export to reject an existing output directory");
|
||||
} catch (error) {
|
||||
expect((error as NodeJS.ErrnoException).code).toBe("EEXIST");
|
||||
}
|
||||
});
|
||||
|
||||
it("does not synthesize prompt files from export-time fallbacks", async () => {
|
||||
@@ -748,9 +751,10 @@ describe("exportTrajectoryBundle", () => {
|
||||
.trim()
|
||||
.split(/\r?\n/u)
|
||||
.map((line) => JSON.parse(line) as TrajectoryEvent);
|
||||
expect(eventTypes(exportedEvents)).toEqual(
|
||||
expect.arrayContaining(["tool.call", "tool.result", "context.compiled"]),
|
||||
);
|
||||
const types = eventTypes(exportedEvents);
|
||||
expect(types).toContain("tool.call");
|
||||
expect(types).toContain("tool.result");
|
||||
expect(types).toContain("context.compiled");
|
||||
expect(JSON.stringify(exportedEvents)).toContain("$WORKSPACE_DIR/inside.txt");
|
||||
expect(JSON.stringify(exportedEvents)).not.toContain("$WORKSPACE_DIR2");
|
||||
|
||||
@@ -777,10 +781,8 @@ describe("exportTrajectoryBundle", () => {
|
||||
const metadata = JSON.parse(fs.readFileSync(path.join(outputDir, "metadata.json"), "utf8")) as {
|
||||
skills?: { entries?: Array<{ id?: string; invoked?: boolean }> };
|
||||
};
|
||||
expect(metadata.skills?.entries?.[0]).toMatchObject({
|
||||
id: "weather",
|
||||
invoked: true,
|
||||
});
|
||||
expect(metadata.skills?.entries?.[0]?.id).toBe("weather");
|
||||
expect(metadata.skills?.entries?.[0]?.invoked).toBe(true);
|
||||
const prompts = fs.readFileSync(path.join(outputDir, "prompts.json"), "utf8");
|
||||
const artifacts = fs.readFileSync(path.join(outputDir, "artifacts.json"), "utf8");
|
||||
const systemPrompt = fs.readFileSync(path.join(outputDir, "system-prompt.txt"), "utf8");
|
||||
|
||||
@@ -171,10 +171,8 @@ describe("trajectory metadata", () => {
|
||||
expect(config.redacted?.providers?.openai?.apiKey).toBe(REDACTED_SENTINEL);
|
||||
expect(plugins.source).toBe("active-registry");
|
||||
expect(plugins.entries?.map((entry) => entry.id)).toEqual(["demo-plugin"]);
|
||||
expect(skills.entries?.[0]).toMatchObject({
|
||||
id: "weather",
|
||||
filePath: "/tmp/workspace/skills/weather/SKILL.md",
|
||||
});
|
||||
expect(skills.entries?.[0]?.id).toBe("weather");
|
||||
expect(skills.entries?.[0]?.filePath).toBe("/tmp/workspace/skills/weather/SKILL.md");
|
||||
});
|
||||
|
||||
it("captures final artifact summaries for export sidecars", () => {
|
||||
@@ -202,14 +200,13 @@ describe("trajectory metadata", () => {
|
||||
messagingToolSentTargets: [],
|
||||
});
|
||||
|
||||
expect(artifacts).toMatchObject({
|
||||
finalStatus: "success",
|
||||
assistantTexts: ["done"],
|
||||
itemLifecycle: {
|
||||
startedCount: 2,
|
||||
completedCount: 2,
|
||||
activeCount: 0,
|
||||
},
|
||||
});
|
||||
expect(artifacts.finalStatus).toBe("success");
|
||||
expect(artifacts.assistantTexts).toEqual(["done"]);
|
||||
const lifecycle = artifacts.itemLifecycle as
|
||||
| { startedCount?: number; completedCount?: number; activeCount?: number }
|
||||
| undefined;
|
||||
expect(lifecycle?.startedCount).toBe(2);
|
||||
expect(lifecycle?.completedCount).toBe(2);
|
||||
expect(lifecycle?.activeCount).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -121,10 +121,8 @@ describe("trajectory runtime", () => {
|
||||
|
||||
expect(writes).toHaveLength(1);
|
||||
const parsed = JSON.parse(writes[0]);
|
||||
expect(parsed.data.prompt).toMatchObject({
|
||||
truncated: true,
|
||||
reason: "trajectory-field-size-limit",
|
||||
});
|
||||
expect(parsed.data.prompt.truncated).toBe(true);
|
||||
expect(parsed.data.prompt.reason).toBe("trajectory-field-size-limit");
|
||||
expect(Buffer.byteLength(writes[0], "utf8")).toBeLessThanOrEqual(
|
||||
TRAJECTORY_RUNTIME_EVENT_MAX_BYTES + 1,
|
||||
);
|
||||
@@ -162,10 +160,8 @@ describe("trajectory runtime", () => {
|
||||
const parsed = writes.map((line) => JSON.parse(line));
|
||||
expect(parsed.map((event) => event.type)).toContain("trace.truncated");
|
||||
const truncated = parsed.find((event) => event.type === "trace.truncated");
|
||||
expect(truncated?.data).toMatchObject({
|
||||
reason: "trajectory-runtime-file-size-limit",
|
||||
limitBytes: 900,
|
||||
});
|
||||
expect(truncated?.data.reason).toBe("trajectory-runtime-file-size-limit");
|
||||
expect(truncated?.data.limitBytes).toBe(900);
|
||||
expect(truncated?.data.droppedEvents).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user