forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspawn-receipt-fixtures.test.ts
More file actions
133 lines (128 loc) · 4.65 KB
/
Copy pathspawn-receipt-fixtures.test.ts
File metadata and controls
133 lines (128 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import { createHash } from "node:crypto";
import { readdirSync, readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { describe, expect, it } from "vitest";
import { compactRealtimeSpawnToolResult } from "../src/runtime/agent-spawn-journal.js";
const FIXTURE_DIR = join(
dirname(fileURLToPath(import.meta.url)),
"../fixtures/spawn-receipt/v1",
);
describe("spawn-receipt fixtures v1", () => {
it("lists both valid and malformed fixtures", () => {
const names = readdirSync(FIXTURE_DIR).filter((name) => name.endsWith(".json"));
expect(names.some((name) => name.startsWith("valid-"))).toBe(true);
expect(names.some((name) => name.startsWith("malformed-"))).toBe(true);
});
it("matches emitter output semantically for valid-running", () => {
const fixture = JSON.parse(
readFileSync(join(FIXTURE_DIR, "valid-running.json"), "utf8"),
) as Record<string, unknown>;
const continuityKey = (fixture.journalReceipt as { continuityKey: string }).continuityKey;
const pillId = (fixture.child as { pillId: string }).pillId;
const descriptor = {
schemaVersion: 1 as const,
surface: {
surfaceKind: "realtime_voice",
externalRefKind: "chat",
externalRefId: "voice-default",
},
continuityKey,
pillId,
userText: "Have an agent research launch risks.",
assistantText: "I started a background agent for that.",
objective: "Research launch risks",
title: "Launch Risk Research",
};
const raw = JSON.stringify({
ok: true,
agents: [{
session: {
sessionId: "session-child",
externalRefId: pillId,
title: "Launch Risk Research",
},
run: {
runId: "run-child",
sessionId: "session-child",
status: "running",
input: { prompt: "Research launch risks" },
updatedAtMs: 1_720_000_000_000,
},
attempt: {
attemptId: "attempt-child",
runId: "run-child",
status: "running",
adapterId: "hermes",
updatedAtMs: 1_720_000_000_000,
},
}],
toolResultEnvelope: {
version: 1,
status: "succeeded",
truncated: false,
originalBytes: 512,
projectedBytes: 512,
fullOutputRef: null,
provenance: {
invocationId: "invocation-spawn",
runId: "run-parent",
attemptId: "attempt-parent",
toolName: "spawn_agent",
},
},
});
const emitted = JSON.parse(compactRealtimeSpawnToolResult(raw, descriptor));
expect(emitted).toMatchObject({
schemaVersion: fixture.schemaVersion,
ok: fixture.ok,
journalReceipt: fixture.journalReceipt,
child: fixture.child,
semanticDigest: fixture.semanticDigest,
providerResult: {
schemaVersion: 1,
ok: true,
code: "spawn_started",
child: (fixture.providerResult as { child: unknown }).child,
semanticDigest: fixture.semanticDigest,
},
toolResultEnvelope: {
version: 1,
truncated: false,
fullOutputRef: null,
},
});
// Digest must stay bound to journalReceipt+child (not providerResult mirror alone).
const recomputed = createHash("sha256")
.update(JSON.stringify({
journalReceipt: fixture.journalReceipt,
child: fixture.child,
}))
.digest("hex")
.slice(0, 32);
expect(emitted.semanticDigest).toBe(recomputed);
});
it("keeps malformed fixtures structurally invalid for the consumer", () => {
const malformed = readdirSync(FIXTURE_DIR)
.filter((name) => name.startsWith("malformed-") && name.endsWith(".json"));
expect(malformed.length).toBeGreaterThanOrEqual(4);
for (const name of malformed) {
const payload = JSON.parse(readFileSync(join(FIXTURE_DIR, name), "utf8")) as Record<string, unknown>;
if (name === "malformed-ok-false.json") {
expect(payload.ok).toBe(false);
} else if (name === "malformed-wrong-schema-version.json") {
expect(payload.schemaVersion).not.toBe(1);
} else if (name === "malformed-missing-child.json") {
expect(payload.child).toBeUndefined();
} else if (name === "malformed-digest-mismatch.json") {
expect(payload.semanticDigest).not.toBe(
(payload.providerResult as { semanticDigest?: string }).semanticDigest,
);
} else if (name === "malformed-tampered-turn-id.json") {
expect((payload.journalReceipt as { userTurnId?: string }).userTurnId).toBe("turn_tampered");
} else {
expect(payload).toBeTruthy();
}
}
});
});