mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-12-01 09:24:46 +00:00
OpenErrand reference runner: @logicsrc/openerrand and logicsrc errand (#228)
* 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> * OpenErrand reference runner: @logicsrc/openerrand and logicsrc errand Ship the runner docs/openerrand.md promised. `logicsrc errand run <file>` reads an OpenErrand 0.1 file, validates it with @logicsrc/validators, and drives headless Chrome through it under the spec's thirteen rules; `errand validate` shows what a file will ask of you and `errand status` shows the last run of each errand, its card and any lockout. The engine is generalised from cli-tools `ftb` (PR #125) with no dependency on cli-tools: the CDP client and Chrome finder from wcag.ts, the page reader, native-setter fill and forward-button picker from ftb-run.ts, and the rule matcher, throttle and outcome logic from ftb.ts, all now driven by the file. - Inputs: document (an extractor hook; the one shipped runs a local command that reads JSON requests and prints records), vault (teams or OpenCreds), prompt (no echo for secrets), generate, derive, candidate, literal. `--input name=value` wins. Shared-secret candidates are ranked as the spec says, one is submitted, and a rejection lists the others for --candidate. - Rules: id before label, step rules first, choices before text, an id match final, an unmatched required field stops the run naming it. - Gates: declare only with --declare after the values are shown; identity proofing never touched (URL only) and handed over or stopped on; code from the terminal or a code file, used once, a wrong code waits for the next; mail ends the run waiting with the card; captcha is the person's, and a CaptchaSolver interface is called only where the spec permits (no solver is bundled); wait steps are polled, never solved. - Throttle: 2 runs per errand and account in 30 minutes, 4 a day, 2 minutes between runs on a site, lockouts from metadata.lockout or a default, held per site and account, never lifted by --force. - Outputs: credentials written before success to a teams vault by pull, merge, push (metadata.vault or --vault), else a 0600 file said aloud; downloads type-checked and never overwritten with different bytes; cards only in the local run record. - The user agent is Chrome's own with HeadlessChrome replaced, given at launch: a CDP override did not reach a navigation the page's own script started, which is exactly the proof-of-work interstitial case. Tests: 85 in the package (rule engine, inputs, gates, throttle, outcomes, captcha gating, vaults, outputs, commands) including an integration test that runs the published FTB example unchanged in real headless Chrome against a local HTTPS fake site (Chrome maps webapp.ftb.ca.gov to it and every other host to NOTFOUND; all data fictional), and 2 in the CLI. CLI 0.6.0 -> 0.7.0; @logicsrc/schemas and @logicsrc/validators 0.3.0 -> 0.4.0 (the OpenErrand schemas, and the vocabularies now exported for runners); PRD 0009; the spec's Reference runner section and the landing page say it ships. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1d69dc3804
commit
dde596b276
46 changed files with 5263 additions and 14 deletions
174
packages/openerrand/src/inputs.test.ts
Normal file
174
packages/openerrand/src/inputs.test.ts
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { type DocumentRecord, generate, inYears, resolveInputs, type VaultReader } from "./inputs.js";
|
||||
import { ftbExample } from "./testing.js";
|
||||
import type { Errand } from "./types.js";
|
||||
import { transform } from "./util.js";
|
||||
|
||||
const NOW = new Date("2026-10-04T12:00:00Z");
|
||||
|
||||
/** Fictional returns for Jane Doe and her corporation; nothing here is anyone's real data. */
|
||||
const RECORDS: DocumentRecord[] = [
|
||||
{ form: "CA 540", field: "first name", value: "Jane", year: 2025, file: "2025/540.pdf", page: 1 },
|
||||
{ form: "CA 540", field: "last name", value: "Doe", year: 2025, file: "2025/540.pdf", page: 1 },
|
||||
{ form: "CA 540", field: "street address", value: "1234 Maple St", year: 2025, file: "2025/540.pdf", page: 1 },
|
||||
{ form: "CA 540", field: "ZIP code", value: "95814-1234", year: 2025, file: "2025/540.pdf", page: 1 },
|
||||
{ form: "CA 540", field: "street address", value: "99 Old Rd", year: 2023, file: "2023/540.pdf", page: 1 },
|
||||
{ form: "CA 100S", field: "California corporation number", value: "1234567", year: 2025, file: "2025/100S.pdf", page: 1 },
|
||||
{ form: "CA 100S", field: "line 20", label: "Net income for tax purposes", value: "48,210.40", year: 2025, file: "2025/100S.pdf", page: 3 },
|
||||
{ form: "CA 100S", field: "line 15", label: "Net income (loss) for state purposes", value: "51,377", year: 2025, file: "2025/100S.pdf", page: 3 },
|
||||
{ form: "CA 100S", field: "line 20", label: "Net income for tax purposes", value: "39,875", year: 2024, file: "2024/100S.pdf", page: 3 },
|
||||
// The year in progress and a year too old: neither counts.
|
||||
{ form: "CA 100S", field: "line 20", label: "Net income for tax purposes", value: "1", year: 2026, file: "2026/100S.pdf", page: 3 },
|
||||
{ form: "CA 100S", field: "line 20", label: "Net income for tax purposes", value: "2", year: 2019, file: "2019/100S.pdf", page: 3 },
|
||||
];
|
||||
|
||||
const extractor = { extract: async () => RECORDS };
|
||||
const noVault: VaultReader = { describe: () => "none", get: async () => undefined };
|
||||
|
||||
function tiny(inputs: Errand["inputs"]): Errand {
|
||||
return {
|
||||
type: "logicsrc.openerrand",
|
||||
version: "0.1",
|
||||
name: "t",
|
||||
title: "t",
|
||||
site: { name: "x", origins: ["https://example.com"], start: ["https://example.com/"] },
|
||||
inputs,
|
||||
steps: [{ id: "form", kind: "page" }],
|
||||
outcomes: [{ name: "ok", kind: "success", text: "ok" }],
|
||||
};
|
||||
}
|
||||
|
||||
describe("the FTB example's inputs", () => {
|
||||
it("resolves documents, derives, candidates and generated credentials", async () => {
|
||||
const inputs = await resolveInputs(ftbExample(), { extractor, vault: noVault, now: NOW, overrides: { email: "jane@example.com", phone: "5555550100" } });
|
||||
expect(inputs.get("first_name")).toBe("Jane");
|
||||
expect(inputs.get("address_numbers")).toBe("1234");
|
||||
expect(inputs.get("zip")).toBe("95814");
|
||||
expect(inputs.get("corp_id")).toBe("1234567");
|
||||
// Shared secret candidates: line 20 newest first, then line 15; the year in progress and 2019 are out.
|
||||
expect(inputs.candidates.map((c) => [c.year, c.field, c.value])).toEqual([
|
||||
[2025, "line 20", "48210"],
|
||||
[2024, "line 20", "39875"],
|
||||
[2025, "line 15", "51377"],
|
||||
]);
|
||||
expect(inputs.get("net_income")).toBe("48210");
|
||||
expect(inputs.get("tax_year")).toBe("2025");
|
||||
expect(inputs.get("username")).toMatch(/^[a-z][a-z0-9]{14}$/);
|
||||
expect(inputs.get("password")).toHaveLength(24);
|
||||
expect(inputs.values.get("username")?.from).toBe("generate");
|
||||
});
|
||||
|
||||
it("--candidate chooses another candidate, and the tax year follows it", async () => {
|
||||
const inputs = await resolveInputs(ftbExample(), { extractor, now: NOW, candidate: 2, overrides: { email: "jane@example.com", phone: "5555550100" } });
|
||||
expect(inputs.get("net_income")).toBe("39875");
|
||||
expect(inputs.get("tax_year")).toBe("2024");
|
||||
});
|
||||
|
||||
it("reuses a vault login before generating one", async () => {
|
||||
const vault: VaultReader = {
|
||||
describe: () => "test",
|
||||
get: async (key) => ({ FTB_BUSINESS_USERNAME: "jdoe1", FTB_BUSINESS_SECURITY_ANSWERS: '{"Pet?":"rex"}' })[key],
|
||||
};
|
||||
const inputs = await resolveInputs(ftbExample(), { extractor, vault, now: NOW, overrides: { email: "jane@example.com", phone: "5555550100" } });
|
||||
expect(inputs.get("username")).toBe("jdoe1");
|
||||
expect(inputs.values.get("username")).toMatchObject({ from: "vault", origin: "FTB_BUSINESS_USERNAME" });
|
||||
expect(inputs.values.get("password")?.from).toBe("generate");
|
||||
expect(inputs.qa.get("security")?.answers).toEqual({ "Pet?": "rex" });
|
||||
});
|
||||
|
||||
it("masks secrets on the terminal and shows personal values to the principal", async () => {
|
||||
const inputs = await resolveInputs(ftbExample(), { extractor, now: NOW, overrides: { email: "jane@example.com", phone: "5555550100" } });
|
||||
expect(inputs.display("password")).toBe("••••");
|
||||
expect(inputs.display("net_income")).toBe("••••");
|
||||
expect(inputs.display("first_name")).toBe("Jane");
|
||||
});
|
||||
|
||||
it("stops before the browser when a required input has no value", async () => {
|
||||
await expect(resolveInputs(ftbExample(), { extractor, now: NOW })).rejects.toThrow(/no value for Email address/);
|
||||
});
|
||||
|
||||
it("checks a value against the input's pattern", async () => {
|
||||
await expect(resolveInputs(ftbExample(), { extractor, now: NOW, overrides: { email: "jane@example.com", phone: "555" } })).rejects.toThrow(/phone does not match/);
|
||||
});
|
||||
|
||||
it("refuses an --input for a name the errand does not have", async () => {
|
||||
await expect(resolveInputs(ftbExample(), { overrides: { nope: "1" } })).rejects.toThrow(/no input named nope/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("sources", () => {
|
||||
it("tries sources in order: a prompt with nobody at a terminal falls through to the next", async () => {
|
||||
const e = tiny({ a: { type: "string", sensitivity: "public", sources: [{ from: "prompt" }, { from: "literal", value: "fixed" }] } });
|
||||
expect((await resolveInputs(e, { prompt: async () => null })).get("a")).toBe("fixed");
|
||||
expect((await resolveInputs(e, { prompt: async () => "typed" })).get("a")).toBe("typed");
|
||||
});
|
||||
|
||||
it("asks for a secret without echo", async () => {
|
||||
const asked: boolean[] = [];
|
||||
const e = tiny({ pw: { type: "string", sensitivity: "secret", sources: [{ from: "prompt", ask: "Password: " }] } });
|
||||
await resolveInputs(e, { prompt: async (_q, o) => (asked.push(o.secret), "x") });
|
||||
expect(asked).toEqual([true]);
|
||||
});
|
||||
|
||||
it("cuts a value to max_length", async () => {
|
||||
const e = tiny({ n: { type: "string", sensitivity: "personal", max_length: 3, sources: [{ from: "literal", value: "Alexandra" }] } });
|
||||
expect((await resolveInputs(e)).get("n")).toBe("Ale");
|
||||
});
|
||||
|
||||
it("picks the oldest when asked", async () => {
|
||||
const e = tiny({ s: { type: "string", sensitivity: "personal", sources: [{ from: "document", form: "CA 540", field: "street address", pick: "oldest" }] } });
|
||||
expect((await resolveInputs(e, { extractor, now: NOW })).get("s")).toBe("99 Old Rd");
|
||||
});
|
||||
|
||||
it("a document match tests the printed label", async () => {
|
||||
const e = tiny({ s: { type: "integer", sensitivity: "secret", sources: [{ from: "document", form: "100S", field: "line 20", match: "state purposes", transform: "whole" }] } });
|
||||
expect((await resolveInputs(e, { extractor, now: NOW })).get("s")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("detects an input that depends on itself through another", async () => {
|
||||
const e = tiny({
|
||||
a: { type: "string", sensitivity: "public", sources: [{ from: "derive", input: "b", transform: "trim" }] },
|
||||
b: { type: "string", sensitivity: "public", sources: [{ from: "derive", input: "a", transform: "trim" }] },
|
||||
});
|
||||
await expect(resolveInputs(e)).rejects.toThrow(/depends on itself/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("generate", () => {
|
||||
it("has at least one of each class and only the specials given", () => {
|
||||
let n = 0;
|
||||
const random = (max: number) => (n++ * 7) % max;
|
||||
for (let i = 0; i < 20; i += 1) {
|
||||
const v = generate({ from: "generate", length: 12, classes: ["lower", "upper", "digit", "special"], special: "!#" }, random);
|
||||
expect(v).toHaveLength(12);
|
||||
expect(v).toMatch(/[a-z]/);
|
||||
expect(v).toMatch(/[A-Z]/);
|
||||
expect(v).toMatch(/[2-9]/);
|
||||
expect(v).toMatch(/[!#]/);
|
||||
expect(v).not.toMatch(/[^a-zA-Z0-9!#]/);
|
||||
}
|
||||
});
|
||||
|
||||
it("starts with a letter when letters are allowed", () => {
|
||||
for (let i = 0; i < 50; i += 1) expect(generate({ from: "generate", length: 15, classes: ["lower", "digit"] })).toMatch(/^[a-z]/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("transforms and years", () => {
|
||||
it("whole keeps whole units with a minus for a loss", () => {
|
||||
expect(transform("48,210.99", "whole")).toBe("48210");
|
||||
expect(transform("(1,234)", "whole")).toBe("-1234");
|
||||
expect(transform("-1,234.5", "whole")).toBe("-1234");
|
||||
expect(transform("1234 Maple St, Apt 5", "digits")).toBe("12345");
|
||||
expect(transform("95814-1234", "first:5")).toBe("95814");
|
||||
expect(transform("123456789", "last:4")).toBe("6789");
|
||||
});
|
||||
|
||||
it("counts closed years back and leaves out the year in progress unless asked", () => {
|
||||
expect(inYears(2025, { back: 5, current: false }, NOW)).toBe(true);
|
||||
expect(inYears(2021, { back: 5, current: false }, NOW)).toBe(true);
|
||||
expect(inYears(2020, { back: 5, current: false }, NOW)).toBe(false);
|
||||
expect(inYears(2026, { back: 5, current: false }, NOW)).toBe(false);
|
||||
expect(inYears(2026, { back: 5, current: true }, NOW)).toBe(true);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue