Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t.sh
24 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { readFileSync } from "node:fs";
3import { test } from "node:test";
4
5import { FOLIO_RPC, folioHandler } from "./rpc.ts";
6
7/** FOLIO_RPC_METHODS as the contract lists them (read from the source: Node can't load the contracts package itself). */
8function contractMethods(): string[] {
9 const source = readFileSync(new URL("../../../../packages/contracts/src/folios.ts", import.meta.url), "utf8");
10 const block = source.slice(source.indexOf("export const FOLIO_RPC_METHODS = ["), source.indexOf("] as const;"));
11 // Leaving out the methods workspace agents called (`RetiredMethod` in rpc.ts).
12 return [...block.matchAll(/^\s*"([a-z_]+)",/gm)].map((m) => m[1]!).filter((m) => !/_(for|as)_agent$/.test(m));
13}
14
15test("every folio RPC method in the contract is answered, and nothing else", () => {
16 const methods = contractMethods();
17 assert.ok(methods.length >= 40);
18 assert.deepEqual(Object.keys(FOLIO_RPC).sort(), [...methods].sort());
19 for (const m of methods) assert.equal(typeof folioHandler(m), "function", m);
20});
21
22test("Docs' own methods fall through to the legacy switch", () => {
23 for (const m of ["sidebar", "page", "create_page", "recall_for_agent", "folios_for_agent", "toString", "__proto__", "constructor"]) assert.equal(folioHandler(m), null, m);
24});