mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-11-30 17:07:50 +00:00
* OpenErrand 0.1: an errand on a website with no API, with the human steps kept human docs/openerrand.md mints OpenErrand: one JSON file per errand (register an account, download a transcript) naming the site, the inputs with a sensitivity class and ordered sources (document, vault, prompt, generate, derive, candidate, literal), field rules matched by id then label, page and wait steps, five human gates a runner never performs (declare, identity-proofing, code, mail, captcha), outcomes, the never-retried shared secret, vault and download outputs, hand-off cards that may name only public inputs, the publisher index at /.well-known/openerrand.json, and thirteen runner rules. The worked example is the MyFTB business registration that cli-tools `ftb` performs (profullstack/cli-tools#125), with no personal data. - @logicsrc/schemas: openerrand + openerrand-index schemas and fixtures - @logicsrc/validators: semantic checks (references, templates, no personal or secret input on a card) and tests that validate the spec's own examples - logicsrc-web: registry entry (process family), /openerrand landing page, the example and the index served as static files, contract tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * OpenErrand: hand-off cards stay on the surface that owns the data Anthony's ruling: tax and finance data never touches a social or promotion tool, and nothing is sent to a CPA or preparer. - Hand-off cards are delivered only on the surface that owns the errand's data (for a tax or finance errand, the principal's finance app through its CLI, PWA, MCP server or API, such as CoinPay, or the runner's terminal), never a social, promotion or third-party posting service, and never to anyone but the principal. A card for an errand with personal or secret inputs does not leave that surface. Runner rule 9 says the same. - The run record and the sample run name the card by an opaque id (pin-letter/7f3k2q) instead of a mynaposter.com URL; the myna mention is gone. - `principal: represented` no longer cites a preparer with a power of attorney. - The FTB card's last step no longer suggests sending the PIN to someone else. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * OpenErrand: user-agent rule, captcha solver policy, reference runner note Anthony's answers on #227 ("go with your recommendations"): - Rule 11: a runner may run headless with a normal desktop browser user agent (dropping HeadlessChrome) and nothing more: no fingerprint spoofing beyond the UA string, no stealth plugins, no solving or evading a bot challenge. A challenge the browser completes itself is a wait step; any other is a captcha gate. - Captcha solvers: new site.sector and captcha step `solver` (forbidden by default | allowed). Never allowed on government, tax, financial, healthcare or identity-provider sites, nor on any errand with a declare or identity-proofing step or a secret input; elsewhere only when the file says so, with every use logged. The validator rejects `allowed` in the forbidden set or without a stated sector; six new tests. The FTB example states sector "tax". - Reference runner: @logicsrc/openerrand / `logicsrc errand run`, marked in progress; ftb stays the runner the example was taken from. - Name stays OpenErrand; family stays Agents and process. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
102 lines
5.8 KiB
TypeScript
102 lines
5.8 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import { describe, expect, it } from "vitest";
|
|
import { assertSchemaKind, validate } from "./index.js";
|
|
|
|
const read = (path: string) => readFileSync(new URL(path, import.meta.url), "utf8");
|
|
const fixture = () => JSON.parse(read("../../schemas/fixtures/openerrand/ftb-register-business.json"));
|
|
const doc = read("../../../docs/openerrand.md");
|
|
|
|
/** Every ```json block in docs/openerrand.md, in order. */
|
|
const blocks = [...doc.matchAll(/```json\n([\s\S]*?)\n```/g)].map((m) => m[1]!);
|
|
|
|
function errorAt(data: unknown, keyword: string, path: string) {
|
|
const result = validate("openerrand", data);
|
|
expect(result.ok).toBe(false);
|
|
if (!result.ok) expect(result.errors).toContainEqual(expect.objectContaining({ keyword, instancePath: path }));
|
|
}
|
|
|
|
describe("OpenErrand", () => {
|
|
it("registers both exported schemas and validates the fixtures", () => {
|
|
expect(assertSchemaKind("openerrand")).toBe("openerrand");
|
|
expect(assertSchemaKind("openerrand-index")).toBe("openerrand-index");
|
|
expect(validate("openerrand", fixture())).toMatchObject({ ok: true });
|
|
expect(validate("openerrand-index", JSON.parse(read("../../schemas/fixtures/openerrand/index.json")))).toMatchObject({ ok: true });
|
|
});
|
|
|
|
it("validates the smallest errand, the worked example and the index printed in the specification", () => {
|
|
const [smallest, , , index, example] = blocks.map((b) => JSON.parse(b));
|
|
expect(validate("openerrand", smallest)).toMatchObject({ ok: true });
|
|
expect(example).toEqual(fixture());
|
|
expect(validate("openerrand-index", index)).toMatchObject({ ok: true });
|
|
});
|
|
|
|
it("puts no personal or secret value in the published example", () => {
|
|
// The repository is public: the example names fields and sources, never a person's data.
|
|
const text = JSON.stringify(fixture());
|
|
expect(text).not.toMatch(/\b\d{3}-?\d{2}-?\d{4}\b/);
|
|
expect(text).not.toMatch(/Jane|Doe|Maple|1234567|48210/);
|
|
});
|
|
|
|
it.each([
|
|
["an unknown key", (f: any) => { f.solver = "2captcha"; }, "additionalProperties", ""],
|
|
["an input with no sensitivity", (f: any) => { delete f.inputs.email.sensitivity; }, "required", "/inputs/email"],
|
|
["a shared secret that may be retried", (f: any) => { f.retry.shared_secret = "once"; }, "const", "/retry/shared_secret"],
|
|
["a gate step without its why", (f: any) => { delete f.steps[2].why; }, "oneOf", "/steps/2"],
|
|
["a plain http origin", (f: any) => { f.site.origins = ["http://webapp.ftb.ca.gov"]; }, "pattern", "/site/origins/0"]
|
|
])("rejects %s", (_, mutate, keyword, path) => {
|
|
const f = fixture();
|
|
mutate(f);
|
|
errorAt(f, keyword, path);
|
|
});
|
|
|
|
it.each([
|
|
["a personal input on a hand-off card", (f: any) => { f.handoffs["pin-letter"].steps.push("Mail it to {{street}}"); }, "handoffSensitivity", "/handoffs/pin-letter/steps/3"],
|
|
["a secret input in a card's command", (f: any) => { f.handoffs["pin-letter"].command = "ftb activate --password {{password}}"; }, "handoffSensitivity", "/handoffs/pin-letter/command"],
|
|
["a template naming no input", (f: any) => { f.rules[2].do.text = "{{given_name}}"; }, "templateReference", "/rules/2/do/text"],
|
|
["a gate action pointing at a page step", (f: any) => { f.rules[25].do.gate = "form"; }, "gateReference", "/rules/25/do/gate"],
|
|
["a shared secret that is only personal", (f: any) => { f.inputs.net_income.sensitivity = "personal"; }, "sharedSecretSensitivity", "/inputs/net_income/sensitivity"],
|
|
["a choose action on a plain input", (f: any) => { f.rules[14].do.choose = "email"; }, "qaSetReference", "/rules/14/do/choose"],
|
|
["an outcome that follows a missing step", (f: any) => { f.outcomes[1].then = "pin-postcard"; }, "stepReference", "/outcomes/1/then"],
|
|
["a mail gate with a missing card", (f: any) => { f.steps[4].handoff = "postcard"; }, "handoffReference", "/steps/4/handoff"],
|
|
["duplicate step ids", (f: any) => { f.steps[1].id = "bot-check"; }, "uniqueStep", "/steps/1/id"]
|
|
])("rejects %s", (_, mutate, keyword, path) => {
|
|
const f = fixture();
|
|
mutate(f);
|
|
errorAt(f, keyword, path);
|
|
});
|
|
|
|
const commercial = () => ({
|
|
...JSON.parse(blocks[0]!),
|
|
site: { name: "Example", sector: "commercial", origins: ["https://example.com"], start: ["https://example.com/contact"] },
|
|
steps: [{ id: "form", kind: "page" }, { id: "robot-check", kind: "captcha", match: { selector: "iframe[src*=captcha]" }, solver: "allowed" }]
|
|
});
|
|
|
|
it("allows a declared captcha solver on a commercial errand with nothing sensitive", () => {
|
|
expect(validate("openerrand", commercial())).toMatchObject({ ok: true });
|
|
});
|
|
|
|
it.each([
|
|
["a solver on a tax site", (f: any) => { f.steps.push({ id: "robot-check", kind: "captcha", match: { selector: "iframe" }, solver: "allowed" }); }, "/steps/5/solver"],
|
|
["a solver on an errand that does not state its sector", (f: any) => { f.steps.push({ id: "robot-check", kind: "captcha", match: { selector: "iframe" }, solver: "allowed" }); delete f.site.sector; }, "/steps/5/solver"]
|
|
])("rejects %s", (_, mutate, path) => {
|
|
const f = fixture();
|
|
mutate(f);
|
|
errorAt(f, "captchaSolver", path);
|
|
});
|
|
|
|
it.each([
|
|
["a secret input", (f: any) => { f.inputs = { password: { type: "string", sensitivity: "secret", sources: [{ from: "prompt" }] } }; }],
|
|
["a declare step", (f: any) => { f.steps.push({ id: "attest", kind: "declare", statement: "i declare", why: "Yours to say." }); }],
|
|
["a government site", (f: any) => { f.site.sector = "government"; }]
|
|
])("rejects a captcha solver on a commercial errand with %s", (_, mutate) => {
|
|
const f = commercial();
|
|
mutate(f);
|
|
errorAt(f, "captchaSolver", "/steps/1/solver");
|
|
});
|
|
|
|
it("allows public inputs and built-ins on a card", () => {
|
|
const f = fixture();
|
|
f.handoffs["pin-letter"].steps.push("Corporation {{corp_id}} at {{site.name}}: {{errand.title}}");
|
|
expect(validate("openerrand", f)).toMatchObject({ ok: true });
|
|
});
|
|
});
|