Skip to content
This repository was archived by the owner on May 24, 2026. It is now read-only.

Commit 9677c9b

Browse files
committed
Combine SDK index and template test fixes
1 parent 86212e3 commit 9677c9b

2 files changed

Lines changed: 30 additions & 11 deletions

File tree

typescript-sdk/scripts/template-tests.mjs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1+
import { readdirSync } from "node:fs";
2+
import path from "node:path";
13
import { spawnSync } from "node:child_process";
24

3-
const suites = [
4-
"runtime/tests/*.test.mjs",
5-
"typescript-sdk/tests/*.test.mjs"
6-
];
5+
const rootDir = new URL("../..", import.meta.url);
76

8-
for (const pattern of suites) {
9-
const run = spawnSync("node", ["--test", pattern], {
7+
const suites = ["runtime/tests", "typescript-sdk/tests"];
8+
9+
function getTestFiles(relativeDir) {
10+
const absoluteDir = new URL(relativeDir, rootDir);
11+
return readdirSync(absoluteDir)
12+
.filter((file) => file.endsWith(".test.mjs"))
13+
.map((file) => path.posix.join(relativeDir, file));
14+
}
15+
16+
for (const suite of suites) {
17+
const files = getTestFiles(suite);
18+
if (files.length === 0) {
19+
continue;
20+
}
21+
const run = spawnSync("node", ["--test", ...files], {
1022
stdio: "inherit",
11-
cwd: new URL("../..", import.meta.url)
23+
cwd: rootDir
1224
});
1325
if (run.status !== 0) {
1426
process.exit(run.status ?? 1);

typescript-sdk/src/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export type ReceiptMetadata = {
4545

4646
export type CanonicalReceipt<T = unknown> = {
4747
status: "success" | "error" | string;
48+
verb?: string;
4849
/**
4950
* Legacy / commercial-only metadata.
5051
* Commons v1.1.0 receipts should not rely on or emit this block.
@@ -76,12 +77,17 @@ export type RuntimeMetadata = {
7677
[k: string]: unknown;
7778
};
7879

80+
export type ReceiptProtocolMetadata = {
81+
verb: string;
82+
version: string;
83+
};
84+
7985
export type CommandResponse<TResult = unknown, TError = unknown> = {
80-
receipt: CanonicalReceipt<TResult, TError>;
86+
receipt: CanonicalReceipt<TResult>;
8187
runtime_metadata?: RuntimeMetadata;
8288
};
8389

84-
export type LegacyBlendedReceipt<TResult = unknown, TError = unknown> = CanonicalReceipt<TResult, TError> & {
90+
export type LegacyBlendedReceipt<TResult = unknown, TError = unknown> = CanonicalReceipt<TResult> & {
8591
trace?: RuntimeMetadata;
8692
};
8793

@@ -295,7 +301,7 @@ function extractReceipt(subject: CanonicalReceipt | CommandResponse | LegacyBlen
295301

296302
export function extractReceiptVerb(subject: CanonicalReceipt | CommandResponse | LegacyBlendedReceipt): string | null {
297303
const receipt = extractReceipt(subject);
298-
return isRecord(receipt.x402) && typeof receipt.x402.verb === "string" ? receipt.x402.verb : null;
304+
return getReceiptVerb(receipt) ?? "summarize";
299305
}
300306

301307
export function normalizeCommandResponse<T = unknown>(payload: unknown): CommandResponse<T> {
@@ -349,6 +355,7 @@ export async function verifyReceipt(receiptLike: CanonicalReceipt | CommandRespo
349355
const { hash_sha256: recomputedHash } = recomputeReceiptHashSha256(receipt);
350356
const hashMatches = claimedHash === recomputedHash;
351357
const receiptId = typeof receipt.metadata?.receipt_id === "string" ? receipt.metadata.receipt_id : null;
358+
const receiptIdPresent = !!receiptId;
352359
const receiptIdMatches = !receiptId || !claimedHash ? true : receiptId === claimedHash;
353360

354361
let pubkey: Uint8Array | null = null;
@@ -396,7 +403,7 @@ export async function verifyReceipt(receiptLike: CanonicalReceipt | CommandRespo
396403
},
397404
values: {
398405
verb: getReceiptVerb(receipt),
399-
signer_id,
406+
signer_id: signerId,
400407
alg,
401408
canonical,
402409
claimed_hash: claimedHash,

0 commit comments

Comments
 (0)