-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathtest-fixtures.ts
More file actions
101 lines (90 loc) · 2.97 KB
/
test-fixtures.ts
File metadata and controls
101 lines (90 loc) · 2.97 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
/**
* Shared fixtures for A2A test suites.
*
* Provides identity constants, message builders, and mock factories so
* individual test files can focus on behavior rather than setup.
*/
import type { DidUri } from "@agentcommercekit/did"
import type { JwtVerified } from "@agentcommercekit/jwt"
import type { W3CCredential } from "@agentcommercekit/vc"
// --- Identity constants ---
export const agentDid = "did:web:agent.example.com" as DidUri
export const userDid = "did:web:user.example.com" as DidUri
export const testCredential: W3CCredential = {
"@context": ["https://www.w3.org/2018/credentials/v1"],
type: ["VerifiableCredential", "ControllerCredential"],
issuer: { id: "did:web:issuer.example.com" },
issuanceDate: "2025-01-01T00:00:00.000Z",
credentialSubject: { id: "did:web:subject.example.com" },
}
// --- Message builders ---
/** A text message, optionally with a specific role or pre-existing metadata. */
export function makeTextMessage(
role: "agent" | "user" = "user",
metadata?: Record<string, unknown>,
) {
return {
kind: "message" as const,
messageId: "msg-1",
role,
parts: [{ kind: "text" as const, text: "hello" }],
...(metadata && { metadata }),
}
}
/** A handshake message carrying a JWT in its data part. */
export function handshakeMessage(jwt = "valid.jwt.token") {
return {
kind: "message" as const,
messageId: "msg-1",
role: "user" as const,
parts: [{ kind: "data" as const, data: { jwt } }],
}
}
/** A signed message with text content and a signature in metadata. */
export function signedMessage(text = "hello", sig = "valid.jwt.signature") {
return {
kind: "message" as const,
messageId: "msg-1",
role: "user" as const,
parts: [{ kind: "text" as const, text }],
metadata: { sig },
}
}
/** A message with no signature — for testing rejection of unsigned input. */
export function unsignedMessage(text = "hello") {
return {
kind: "message" as const,
messageId: "msg-1",
role: "user" as const,
parts: [{ kind: "text" as const, text }],
}
}
/**
* The expected JWT payload for a signed message with the given text.
* Derives from the same shape as signedMessage() so they can't drift apart.
*/
export function expectedSignedPayload(text = "hello") {
const { metadata: _, ...content } = signedMessage(text)
return { message: content }
}
// --- Mock factories ---
/** Builds a JwtVerified result with sensible defaults, overriding only the payload. */
export function mockVerifiedJwt(payload: Record<string, unknown>): JwtVerified {
return {
verified: true,
payload: { iss: "did:web:issuer.example.com", ...payload },
didResolutionResult: {
didResolutionMetadata: {},
didDocument: null,
didDocumentMetadata: {},
},
issuer: "did:web:issuer.example.com",
signer: {
id: "did:web:issuer.example.com#key-1",
type: "Multikey",
controller: "did:web:issuer.example.com",
publicKeyHex: "02...",
},
jwt: "mock.jwt.token",
}
}