Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 116 to 318

Compare

+82 −0 in 1 place
new file, 82 lines
1+// Stand-ins for the Workers runtime in Node tests: a Durable Object's SQLite storage over node:sqlite, and the
2+// DigestStream the blob store hashes uploads with.
3+
4+import { createHash } from "node:crypto";
5+import { DatabaseSync } from "node:sqlite";
6+import type { SqliteStorage } from "../src/engine-project.ts";
7+
8+export function memoryStorage(filename = ":memory:"): SqliteStorage & { db: DatabaseSync } {
9+ const db = new DatabaseSync(filename);
10+ let depth = 0;
11+ return {
12+ db,
13+ sql: {
14+ exec(query: string, ...bindings: unknown[]) {
15+ const statement = db.prepare(query);
16+ const args = bindings as never[];
17+ const rows = statement.columns().length > 0 ? statement.all(...args) : (statement.run(...args), []);
18+ // Workers hands BLOB columns back as ArrayBuffers.
19+ return {
20+ toArray: () =>
21+ rows.map((r) =>
22+ Object.fromEntries(
23+ Object.entries(r as Record<string, unknown>).map(([k, v]) => [
24+ k,
25+ v instanceof Uint8Array ? v.buffer.slice(v.byteOffset, v.byteOffset + v.byteLength) : v,
26+ ]),
27+ ),
28+ ),
29+ };
30+ },
31+ },
32+ transactionSync<T>(fn: () => T): T {
33+ const name = `t${depth++}`;
34+ db.exec(`SAVEPOINT ${name}`);
35+ try {
36+ const value = fn();
37+ db.exec(`RELEASE ${name}`);
38+ return value;
39+ } catch (e) {
40+ db.exec(`ROLLBACK TO ${name}; RELEASE ${name}`);
41+ throw e;
42+ } finally {
43+ depth--;
44+ }
45+ },
46+ };
47+}
49+/** Workers' crypto.DigestStream, for the blob store's streaming hash. */
50+export function installDigestStream(): void {
51+ const c = (globalThis as unknown as { crypto: { DigestStream?: unknown } }).crypto;
52+ if (c.DigestStream) return;
53+ class DigestStream extends WritableStream<Uint8Array> {
54+ readonly digest: Promise<ArrayBuffer>;
55+ constructor(algorithm: string) {
56+ const hash = createHash(algorithm.replace("-", "").toLowerCase());
57+ let done!: (b: ArrayBuffer) => void;
58+ const digest = new Promise<ArrayBuffer>((ok) => {
59+ done = ok;
60+ });
61+ super({
62+ write: (chunk) => void hash.update(chunk),
63+ close: () => {
64+ const b = hash.digest();
65+ done(b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength));
66+ },
67+ });
68+ this.digest = digest;
69+ }
70+ }
71+ c.DigestStream = DigestStream;
72+}
74+export function streamOf(text: string): ReadableStream<Uint8Array> {
75+ const bytes = new TextEncoder().encode(text);
76+ return new ReadableStream({
77+ start(c) {
78+ c.enqueue(bytes);
79+ c.close();
80+ },
81+ });
82+}
MCP
compare on this site's /mcp
CLI
abso diff 116 318 server/test/helpers.ts --json
JSON
/christopher/abso-core/compare/116..318?file=server%2Ftest%2Fhelpers.ts&format=json