@booki-aui/readiness 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/LICENSE +21 -0
- package/README.md +317 -2
- package/dist/chunk-5SCOA3ZP.js +108 -0
- package/dist/chunk-6SBJYJ2U.js +1169 -0
- package/dist/chunk-IZ57MB25.js +29 -0
- package/dist/cli.js +108 -0
- package/dist/conformance.d.ts +67 -0
- package/dist/conformance.js +329 -0
- package/dist/index.d.ts +237 -0
- package/dist/index.js +48 -0
- package/dist/reference.d.ts +33 -0
- package/dist/reference.js +175 -0
- package/dist/types-Ba_gnEks.d.ts +49 -0
- package/package.json +62 -3
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// src/conformance/permissions.ts
|
|
2
|
+
var PERSON_ONLY_PERMISSIONS = [
|
|
3
|
+
"approval.decide",
|
|
4
|
+
"supplier-invoice.approve",
|
|
5
|
+
"expense.approve",
|
|
6
|
+
"payment.approve",
|
|
7
|
+
"payment.release",
|
|
8
|
+
"reconciliation.approve",
|
|
9
|
+
"period.close",
|
|
10
|
+
"period.adjust-closed",
|
|
11
|
+
"close.sign-off",
|
|
12
|
+
"invoice.finalize",
|
|
13
|
+
"vat.submit",
|
|
14
|
+
"asset.dispose",
|
|
15
|
+
"audit.sign-off",
|
|
16
|
+
"audit.review",
|
|
17
|
+
"audit.conclude",
|
|
18
|
+
"audit.eqcr",
|
|
19
|
+
"audit.freeze",
|
|
20
|
+
"finding.confirm",
|
|
21
|
+
"finding.withdraw",
|
|
22
|
+
"request.send",
|
|
23
|
+
"request.decide",
|
|
24
|
+
"deal.close"
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
PERSON_ONLY_PERMISSIONS
|
|
29
|
+
};
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
audit,
|
|
4
|
+
toConsole,
|
|
5
|
+
toHtml,
|
|
6
|
+
toJson
|
|
7
|
+
} from "./chunk-6SBJYJ2U.js";
|
|
8
|
+
import "./chunk-5SCOA3ZP.js";
|
|
9
|
+
|
|
10
|
+
// src/cli.ts
|
|
11
|
+
import { writeFileSync } from "fs";
|
|
12
|
+
import path from "path";
|
|
13
|
+
import { parseArgs } from "util";
|
|
14
|
+
var HELP = `Usage: npx @booki-aui/readiness <url | file.html> [options]
|
|
15
|
+
|
|
16
|
+
Checks what stops an AI agent on a screen and scores it 0-100 against the
|
|
17
|
+
Agent Contract.
|
|
18
|
+
|
|
19
|
+
Options
|
|
20
|
+
--storage-state <file> Playwright storage state of a signed-in session
|
|
21
|
+
--profile <dir> Run in this browser profile (signed in already; close the browser first)
|
|
22
|
+
--out <file> HTML report (default: readiness-report.html); JSON goes next to it
|
|
23
|
+
--json <file> JSON report path (default: the --out path with .json)
|
|
24
|
+
--no-report Print the summary only
|
|
25
|
+
--browser <channel> chrome (default), msedge, chromium
|
|
26
|
+
--executable <path> A browser binary instead of a channel
|
|
27
|
+
--wait <ms> Wait after load, for late rendering (default 500)
|
|
28
|
+
--wait-for <selector> Wait until this selector is on the page
|
|
29
|
+
--timeout <ms> Give up on loading the page (and --wait-for) after this long (default 30000)
|
|
30
|
+
--headed Show the browser
|
|
31
|
+
--fail-under <score> Exit with code 1 when the score is below this,
|
|
32
|
+
or when nothing was measured (bridge with no controls)
|
|
33
|
+
--snapshot Include the full accessibility snapshot in the JSON
|
|
34
|
+
-h, --help This text
|
|
35
|
+
`;
|
|
36
|
+
async function main() {
|
|
37
|
+
const { values, positionals } = parseArgs({
|
|
38
|
+
allowPositionals: true,
|
|
39
|
+
options: {
|
|
40
|
+
"storage-state": { type: "string" },
|
|
41
|
+
profile: { type: "string" },
|
|
42
|
+
out: { type: "string" },
|
|
43
|
+
json: { type: "string" },
|
|
44
|
+
"no-report": { type: "boolean" },
|
|
45
|
+
browser: { type: "string" },
|
|
46
|
+
executable: { type: "string" },
|
|
47
|
+
wait: { type: "string" },
|
|
48
|
+
"wait-for": { type: "string" },
|
|
49
|
+
timeout: { type: "string" },
|
|
50
|
+
headed: { type: "boolean" },
|
|
51
|
+
"fail-under": { type: "string" },
|
|
52
|
+
snapshot: { type: "boolean" },
|
|
53
|
+
help: { type: "boolean", short: "h" }
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
if (values.help || positionals.length !== 1) {
|
|
57
|
+
process.stdout.write(HELP);
|
|
58
|
+
return values.help ? 0 : 2;
|
|
59
|
+
}
|
|
60
|
+
const timeout = values.timeout === void 0 ? void 0 : Number(values.timeout);
|
|
61
|
+
if (timeout !== void 0 && !(Number.isFinite(timeout) && timeout >= 0)) {
|
|
62
|
+
process.stderr.write(`readiness: --timeout takes milliseconds, a number of 0 or more; got "${values.timeout}".
|
|
63
|
+
`);
|
|
64
|
+
return 2;
|
|
65
|
+
}
|
|
66
|
+
const options = {
|
|
67
|
+
storageState: values["storage-state"],
|
|
68
|
+
profile: values.profile,
|
|
69
|
+
channel: values.browser,
|
|
70
|
+
executablePath: values.executable,
|
|
71
|
+
wait: values.wait ? Number(values.wait) : void 0,
|
|
72
|
+
waitFor: values["wait-for"],
|
|
73
|
+
timeout,
|
|
74
|
+
headed: values.headed
|
|
75
|
+
};
|
|
76
|
+
const report = await audit(positionals[0], options);
|
|
77
|
+
process.stdout.write(`${toConsole(report)}
|
|
78
|
+
`);
|
|
79
|
+
if (!values["no-report"]) {
|
|
80
|
+
const html = path.resolve(values.out ?? "readiness-report.html");
|
|
81
|
+
const json = path.resolve(values.json ?? html.replace(/\.html?$/i, "") + ".json");
|
|
82
|
+
writeFileSync(html, toHtml(report));
|
|
83
|
+
writeFileSync(json, toJson(report, { snapshot: values.snapshot }));
|
|
84
|
+
process.stdout.write(`
|
|
85
|
+
Report: ${html}
|
|
86
|
+
JSON: ${json}
|
|
87
|
+
`);
|
|
88
|
+
}
|
|
89
|
+
const floor = values["fail-under"] ? Number(values["fail-under"]) : null;
|
|
90
|
+
return floor !== null && (!report.measured || report.score < floor) ? 1 : 0;
|
|
91
|
+
}
|
|
92
|
+
main().then(
|
|
93
|
+
(code) => process.exit(code),
|
|
94
|
+
(error) => {
|
|
95
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
96
|
+
process.stderr.write(`readiness: ${message}
|
|
97
|
+
`);
|
|
98
|
+
if (/Timeout \d+ms exceeded/.test(message)) {
|
|
99
|
+
process.stderr.write("A dev server that compiles the page on first load can take longer: pass --timeout <ms>.\n");
|
|
100
|
+
}
|
|
101
|
+
if (/Executable doesn't exist|Chromium distribution|channel/i.test(message)) {
|
|
102
|
+
process.stderr.write(
|
|
103
|
+
"Install Google Chrome, or pass --browser msedge, or --executable <path to a Chromium browser>.\n"
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
process.exit(2);
|
|
107
|
+
}
|
|
108
|
+
);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { A as AgentBridge, a as ActStep, S as ServerActor, b as ServerAnswer, B as BridgeEvent } from './types-Ba_gnEks.js';
|
|
2
|
+
export { c as ActResult, d as BridgeComponent } from './types-Ba_gnEks.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The decisions that stay with a person (spec/agent-contract.md, section 5).
|
|
6
|
+
* A server MUST refuse each of these when the caller is an agent, whatever its roles.
|
|
7
|
+
* test/permissions.test.ts keeps this list equal to the spec table.
|
|
8
|
+
*/
|
|
9
|
+
declare const PERSON_ONLY_PERMISSIONS: readonly string[];
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The in-process conformance suite for the Agent Contract (spec/agent-contract.md,
|
|
13
|
+
* section 10). It drives an agent bridge directly, without a browser, so it can
|
|
14
|
+
* ACT: a check calls act(). The browser audit (audit.ts) never clicks.
|
|
15
|
+
*
|
|
16
|
+
* Acts on the bridge: run it against test data, never a live company.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
type ConformanceTarget = {
|
|
20
|
+
bridge: AgentBridge;
|
|
21
|
+
/** One safe, successful agent step to drive for the recording check. */
|
|
22
|
+
drive?: ActStep;
|
|
23
|
+
/** Literal secret values (e.g. a test IBAN) that must never appear in the snapshot. */
|
|
24
|
+
secrets?: string[];
|
|
25
|
+
/** A closed-list probe: a bad value and every valid choice the refusal must name. */
|
|
26
|
+
closedList?: {
|
|
27
|
+
step: ActStep;
|
|
28
|
+
valid: string[];
|
|
29
|
+
};
|
|
30
|
+
/** Person-only steps the agent must be refused (e.g. approve). */
|
|
31
|
+
personOnly?: ActStep[];
|
|
32
|
+
/** Your server's write gate; asked for every permission in section 5.1 as an agent. */
|
|
33
|
+
server?: (actor: ServerActor | null, permission: string) => ServerAnswer | Promise<ServerAnswer>;
|
|
34
|
+
/** Map your bridge's event to {source, actor}; default is identity. */
|
|
35
|
+
normalizeEvent?: (raw: unknown) => BridgeEvent;
|
|
36
|
+
};
|
|
37
|
+
type CheckResult = {
|
|
38
|
+
id: string;
|
|
39
|
+
section: string;
|
|
40
|
+
level: "MUST" | "SHOULD";
|
|
41
|
+
status: "pass" | "fail" | "skip";
|
|
42
|
+
message: string;
|
|
43
|
+
};
|
|
44
|
+
type ConformanceReport = {
|
|
45
|
+
contract: "0.1";
|
|
46
|
+
checks: CheckResult[];
|
|
47
|
+
passed: number;
|
|
48
|
+
failed: number;
|
|
49
|
+
skipped: number;
|
|
50
|
+
conforms: boolean;
|
|
51
|
+
};
|
|
52
|
+
declare function runConformance(target: ConformanceTarget): Promise<ConformanceReport>;
|
|
53
|
+
declare function formatConformance(report: ConformanceReport): string;
|
|
54
|
+
|
|
55
|
+
type CheckOutcome = {
|
|
56
|
+
status: "pass" | "fail" | "skip";
|
|
57
|
+
message: string;
|
|
58
|
+
};
|
|
59
|
+
type ConformanceCheck = {
|
|
60
|
+
id: string;
|
|
61
|
+
section: string;
|
|
62
|
+
level: "MUST" | "SHOULD";
|
|
63
|
+
run: (target: ConformanceTarget) => Promise<CheckOutcome>;
|
|
64
|
+
};
|
|
65
|
+
declare const CONFORMANCE_CHECKS: readonly ConformanceCheck[];
|
|
66
|
+
|
|
67
|
+
export { ActStep, AgentBridge, BridgeEvent, CONFORMANCE_CHECKS, type CheckOutcome, type CheckResult, type ConformanceCheck, type ConformanceReport, type ConformanceTarget, PERSON_ONLY_PERMISSIONS, ServerActor, ServerAnswer, formatConformance, runConformance };
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PERSON_ACTION,
|
|
3
|
+
findSecrets
|
|
4
|
+
} from "./chunk-5SCOA3ZP.js";
|
|
5
|
+
import {
|
|
6
|
+
PERSON_ONLY_PERMISSIONS
|
|
7
|
+
} from "./chunk-IZ57MB25.js";
|
|
8
|
+
|
|
9
|
+
// src/conformance/checks.ts
|
|
10
|
+
var pass = (message) => ({ status: "pass", message });
|
|
11
|
+
var fail = (message) => ({ status: "fail", message });
|
|
12
|
+
var skip = (message) => ({ status: "skip", message });
|
|
13
|
+
var UNKNOWN = "__conformance_unknown__";
|
|
14
|
+
async function components(target) {
|
|
15
|
+
const snap = await target.bridge.snapshot();
|
|
16
|
+
if (!Array.isArray(snap)) throw new Error("snapshot() did not return an array");
|
|
17
|
+
return snap;
|
|
18
|
+
}
|
|
19
|
+
async function act(target, step) {
|
|
20
|
+
return await target.bridge.act({ steps: [step] });
|
|
21
|
+
}
|
|
22
|
+
var isRefusal = (result) => result !== void 0 && result !== null && result.ok === false && typeof result.error?.message === "string" && result.error.message.length > 0;
|
|
23
|
+
var isNamed = (value) => typeof value === "string" && value.length > 0;
|
|
24
|
+
var isMinorKey = (key) => key === "minor" || key.endsWith("Minor");
|
|
25
|
+
var isDateKey = (key) => key === "date" || key.endsWith("Date");
|
|
26
|
+
var DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
27
|
+
var checks = [
|
|
28
|
+
{
|
|
29
|
+
id: "bridge-shape",
|
|
30
|
+
section: "2",
|
|
31
|
+
level: "MUST",
|
|
32
|
+
run: async (target) => {
|
|
33
|
+
const bridge = target.bridge;
|
|
34
|
+
const missing = ["snapshot", "act", "subscribe"].filter((name) => typeof bridge?.[name] !== "function");
|
|
35
|
+
if (missing.length > 0) return fail(`Missing functions: ${missing.join(", ")}.`);
|
|
36
|
+
const snap = await target.bridge.snapshot();
|
|
37
|
+
if (!Array.isArray(snap)) return fail("snapshot() must return an array of components.");
|
|
38
|
+
return pass(`snapshot, act and subscribe are functions; snapshot returns ${snap.length} components.`);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: "snapshot-named",
|
|
43
|
+
section: "3.1",
|
|
44
|
+
level: "MUST",
|
|
45
|
+
run: async (target) => {
|
|
46
|
+
const snap = await components(target);
|
|
47
|
+
const offenders = [];
|
|
48
|
+
for (const [index, c] of snap.entries()) {
|
|
49
|
+
const name = isNamed(c?.ref) ? c.ref : `#${index}`;
|
|
50
|
+
const ok = isNamed(c?.ref) && isNamed(c.component) && isNamed(c.label) && Array.isArray(c.actions) && c.actions.every((a) => typeof a === "string");
|
|
51
|
+
if (!ok) offenders.push(name);
|
|
52
|
+
}
|
|
53
|
+
const labels = snap.map((c) => c?.label).filter(isNamed);
|
|
54
|
+
const duplicates = [...new Set(labels.filter((label, i) => labels.indexOf(label) !== i))];
|
|
55
|
+
if (offenders.length > 0) {
|
|
56
|
+
return fail(`Components without a non-empty ref, component, label or string actions: ${offenders.join(", ")}.`);
|
|
57
|
+
}
|
|
58
|
+
if (duplicates.length > 0) return fail(`Labels shared by more than one component: ${duplicates.join(", ")}.`);
|
|
59
|
+
return pass(`All ${snap.length} components have a ref, component, label and string actions; labels are unique.`);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
id: "snapshot-values",
|
|
64
|
+
section: "3.2",
|
|
65
|
+
level: "MUST",
|
|
66
|
+
run: async (target) => {
|
|
67
|
+
const snap = await components(target);
|
|
68
|
+
const bad = [];
|
|
69
|
+
for (const c of snap) {
|
|
70
|
+
for (const [key, value] of Object.entries(c)) {
|
|
71
|
+
if (isMinorKey(key) && !(value === null || Number.isInteger(value))) {
|
|
72
|
+
bad.push(`${c.ref}.${key}=${JSON.stringify(value)}`);
|
|
73
|
+
}
|
|
74
|
+
if (isDateKey(key) && !(value === null || typeof value === "string" && DATE.test(value))) {
|
|
75
|
+
bad.push(`${c.ref}.${key}=${JSON.stringify(value)}`);
|
|
76
|
+
}
|
|
77
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
78
|
+
for (const [inner, innerValue] of Object.entries(value)) {
|
|
79
|
+
if (isMinorKey(inner) && !(innerValue === null || Number.isInteger(innerValue))) {
|
|
80
|
+
bad.push(`${c.ref}.${key}.${inner}=${JSON.stringify(innerValue)}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (bad.length > 0) {
|
|
87
|
+
return fail(`Minor-unit values must be integers or null, dates YYYY-MM-DD or null: ${bad.join("; ")}.`);
|
|
88
|
+
}
|
|
89
|
+
return pass("Minor-unit values are integers or null, and dates are YYYY-MM-DD or null.");
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
id: "snapshot-secrets",
|
|
94
|
+
section: "3.5",
|
|
95
|
+
level: "MUST",
|
|
96
|
+
run: async (target) => {
|
|
97
|
+
const snap = await components(target);
|
|
98
|
+
const json = JSON.stringify(snap);
|
|
99
|
+
const literal = (target.secrets ?? []).filter((s) => typeof s === "string" && s.length > 0);
|
|
100
|
+
const leaked = literal.filter((s) => json.includes(s));
|
|
101
|
+
const found = findSecrets(json).map((hit) => hit.kind);
|
|
102
|
+
if (leaked.length > 0 || found.length > 0) {
|
|
103
|
+
const parts = [];
|
|
104
|
+
if (leaked.length > 0) parts.push(`${leaked.length} literal secret(s)`);
|
|
105
|
+
if (found.length > 0) parts.push(`secret pattern(s): ${[...new Set(found)].join(", ")}`);
|
|
106
|
+
return fail(`The snapshot shows secrets: ${parts.join("; ")}.`);
|
|
107
|
+
}
|
|
108
|
+
const note = literal.length === 0 ? " No literal secrets were given, so only patterns were checked." : "";
|
|
109
|
+
return pass(`The snapshot shows no secrets.${note}`);
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
id: "act-never-throws",
|
|
114
|
+
section: "4.5",
|
|
115
|
+
level: "MUST",
|
|
116
|
+
run: async (target) => {
|
|
117
|
+
const snap = await components(target);
|
|
118
|
+
const probes = [
|
|
119
|
+
{ name: "unknown ref", step: { ref: UNKNOWN, action: UNKNOWN } }
|
|
120
|
+
];
|
|
121
|
+
if (snap.length === 0) {
|
|
122
|
+
return skip("The bridge has no components, so the unknown-action probe was not run.");
|
|
123
|
+
}
|
|
124
|
+
probes.push({ name: "unknown action", step: { ref: snap[0].ref, action: UNKNOWN } });
|
|
125
|
+
const bad = [];
|
|
126
|
+
for (const probe of probes) {
|
|
127
|
+
let result;
|
|
128
|
+
try {
|
|
129
|
+
result = await act(target, probe.step);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
return fail(`act() threw on ${probe.name}: ${error instanceof Error ? error.message : String(error)}`);
|
|
132
|
+
}
|
|
133
|
+
if (!isRefusal(result)) bad.push(probe.name);
|
|
134
|
+
}
|
|
135
|
+
if (bad.length > 0) return fail(`act() did not refuse with ok:false and a message on: ${bad.join(", ")}.`);
|
|
136
|
+
return pass("act() refuses unknown refs and actions with ok:false and a message, without throwing.");
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
id: "refusal-names-valid",
|
|
141
|
+
section: "12.2",
|
|
142
|
+
level: "MUST",
|
|
143
|
+
run: async (target) => {
|
|
144
|
+
const snap = await components(target);
|
|
145
|
+
if (snap.length === 0) return skip("The bridge has no components to check refusals against.");
|
|
146
|
+
const first = snap[0];
|
|
147
|
+
const actions = first.actions;
|
|
148
|
+
const needed = actions.length > 5 ? 5 : actions.length;
|
|
149
|
+
const unknownAction = await act(target, { ref: first.ref, action: UNKNOWN });
|
|
150
|
+
const actionMessage = unknownAction?.error?.message ?? "";
|
|
151
|
+
const named = actions.filter((a) => actionMessage.includes(a));
|
|
152
|
+
if (named.length < needed) {
|
|
153
|
+
return fail(
|
|
154
|
+
`The refusal for an unknown action on "${first.ref}" names ${named.length} of ${actions.length} actions; expected at least ${needed}.`
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
const unknownRef = await act(target, { ref: UNKNOWN, action: UNKNOWN });
|
|
158
|
+
const refMessage = unknownRef?.error?.message ?? "";
|
|
159
|
+
const labels = snap.map((c) => c.label);
|
|
160
|
+
if (!labels.some((label) => refMessage.includes(label))) {
|
|
161
|
+
return fail(`The refusal for an unknown ref names none of the existing labels: ${labels.join(", ")}.`);
|
|
162
|
+
}
|
|
163
|
+
return pass(`Refusals name the valid actions (${named.length} of ${actions.length}) and existing controls.`);
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
id: "amount-minor-only",
|
|
168
|
+
section: "4.2",
|
|
169
|
+
level: "MUST",
|
|
170
|
+
run: async (target) => {
|
|
171
|
+
const snap = await components(target);
|
|
172
|
+
const amounts = snap.filter((c) => c.actions.includes("setMinor"));
|
|
173
|
+
if (amounts.length === 0) return skip("No component offers setMinor.");
|
|
174
|
+
const accepted = [];
|
|
175
|
+
for (const c of amounts) {
|
|
176
|
+
for (const value of [12.5, "1 500,00"]) {
|
|
177
|
+
const result = await act(target, { ref: c.ref, action: "setMinor", args: [value] });
|
|
178
|
+
if (result?.ok !== false) accepted.push(`${c.ref} setMinor(${JSON.stringify(value)})`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (accepted.length > 0) {
|
|
182
|
+
return fail(`setMinor accepted a value that is not whole minor units: ${accepted.join("; ")}.`);
|
|
183
|
+
}
|
|
184
|
+
return pass(`setMinor refuses fractions and formatted text on ${amounts.length} component(s).`);
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
id: "closed-list",
|
|
189
|
+
section: "4.3",
|
|
190
|
+
level: "MUST",
|
|
191
|
+
run: async (target) => {
|
|
192
|
+
if (!target.closedList) return skip("No closedList probe was given.");
|
|
193
|
+
const { step, valid } = target.closedList;
|
|
194
|
+
const result = await act(target, step);
|
|
195
|
+
if (result?.ok !== false) return fail(`A bad value for ${step.ref} was accepted.`);
|
|
196
|
+
const message = result.error?.message ?? "";
|
|
197
|
+
const missing = valid.filter((choice) => !message.includes(choice));
|
|
198
|
+
if (missing.length > 0) {
|
|
199
|
+
return fail(`The refusal does not name the valid choices: ${missing.join(", ")}.`);
|
|
200
|
+
}
|
|
201
|
+
return pass(`The refusal for ${step.ref} names all ${valid.length} valid choices.`);
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
id: "person-only-not-offered",
|
|
206
|
+
section: "5.1",
|
|
207
|
+
level: "MUST",
|
|
208
|
+
run: async (target) => {
|
|
209
|
+
const snap = await components(target);
|
|
210
|
+
const offered = snap.flatMap((c) => c.actions.filter((a) => PERSON_ACTION.test(a)).map((a) => `${c.ref}.${a}`));
|
|
211
|
+
if (offered.length > 0) {
|
|
212
|
+
return fail(`An agent is offered person-only actions: ${offered.join(", ")}.`);
|
|
213
|
+
}
|
|
214
|
+
if (!target.personOnly) {
|
|
215
|
+
return pass("No person-only action is offered. personOnly was not given, so the refusal part was skipped.");
|
|
216
|
+
}
|
|
217
|
+
const accepted = [];
|
|
218
|
+
for (const step of target.personOnly) {
|
|
219
|
+
const result = await act(target, step);
|
|
220
|
+
if (result?.ok !== false) accepted.push(`${step.ref}.${step.action}`);
|
|
221
|
+
}
|
|
222
|
+
if (accepted.length > 0) {
|
|
223
|
+
return fail(`An agent was allowed to perform person-only steps: ${accepted.join(", ")}.`);
|
|
224
|
+
}
|
|
225
|
+
return pass(`No person-only action is offered, and ${target.personOnly.length} person-only step(s) are refused.`);
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
id: "recording-agent",
|
|
230
|
+
section: "6.1",
|
|
231
|
+
level: "MUST",
|
|
232
|
+
run: async (target) => {
|
|
233
|
+
if (!target.drive) return skip("No drive step was given.");
|
|
234
|
+
const normalize = target.normalizeEvent ?? ((raw) => raw);
|
|
235
|
+
const events = [];
|
|
236
|
+
const unsubscribe = target.bridge.subscribe((raw) => {
|
|
237
|
+
events.push(normalize(raw));
|
|
238
|
+
});
|
|
239
|
+
try {
|
|
240
|
+
const result = await act(target, target.drive);
|
|
241
|
+
if (result?.ok !== true) {
|
|
242
|
+
return fail(`The drive step was not performed: ${result?.error?.message ?? "no message"}.`);
|
|
243
|
+
}
|
|
244
|
+
const agentEvents = events.filter((e) => e.source === "agent");
|
|
245
|
+
if (agentEvents.length !== 1) {
|
|
246
|
+
return fail(`Expected exactly one agent event for the drive step, got ${agentEvents.length}.`);
|
|
247
|
+
}
|
|
248
|
+
const [event] = agentEvents;
|
|
249
|
+
if (typeof event.actor !== "string" || !event.actor.startsWith("agent:")) {
|
|
250
|
+
return fail(`The agent event has actor ${JSON.stringify(event.actor)}; it must start with "agent:".`);
|
|
251
|
+
}
|
|
252
|
+
return pass(`One agent event recorded with actor ${event.actor}.`);
|
|
253
|
+
} finally {
|
|
254
|
+
if (typeof unsubscribe === "function") unsubscribe();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
id: "server-person-only",
|
|
260
|
+
section: "5.1",
|
|
261
|
+
level: "MUST",
|
|
262
|
+
run: async (target) => {
|
|
263
|
+
if (!target.server) return skip("No server gate was given.");
|
|
264
|
+
const actor = { kind: "agent", id: "conformance", roles: ["owner"] };
|
|
265
|
+
const notRefused = [];
|
|
266
|
+
for (const permission of PERSON_ONLY_PERMISSIONS) {
|
|
267
|
+
const answer = await target.server(actor, permission);
|
|
268
|
+
if (answer?.status !== 403) notRefused.push(`${permission} (${answer?.status})`);
|
|
269
|
+
}
|
|
270
|
+
if (notRefused.length > 0) {
|
|
271
|
+
return fail(`The server did not refuse an agent for: ${notRefused.join(", ")}.`);
|
|
272
|
+
}
|
|
273
|
+
return pass(
|
|
274
|
+
`The server refuses an agent with 403 for all ${PERSON_ONLY_PERMISSIONS.length} person-only permissions.`
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
id: "server-unsigned",
|
|
280
|
+
section: "7.3",
|
|
281
|
+
level: "SHOULD",
|
|
282
|
+
run: async (target) => {
|
|
283
|
+
if (!target.server) return skip("No server gate was given.");
|
|
284
|
+
const answer = await target.server(null, "approval.decide");
|
|
285
|
+
if (answer?.status !== 401) return fail(`An unsigned request got ${answer?.status}, expected 401.`);
|
|
286
|
+
return pass("An unsigned request is refused with 401.");
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
];
|
|
290
|
+
var CONFORMANCE_CHECKS = checks;
|
|
291
|
+
|
|
292
|
+
// src/conformance/run.ts
|
|
293
|
+
async function runConformance(target) {
|
|
294
|
+
const checks2 = [];
|
|
295
|
+
for (const check of CONFORMANCE_CHECKS) {
|
|
296
|
+
let outcome;
|
|
297
|
+
try {
|
|
298
|
+
outcome = await check.run(target);
|
|
299
|
+
} catch (error) {
|
|
300
|
+
outcome = { status: "fail", message: error instanceof Error ? error.message : String(error) };
|
|
301
|
+
}
|
|
302
|
+
checks2.push({
|
|
303
|
+
id: check.id,
|
|
304
|
+
section: check.section,
|
|
305
|
+
level: check.level,
|
|
306
|
+
status: outcome.status,
|
|
307
|
+
message: outcome.message
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
const passed = checks2.filter((c) => c.status === "pass").length;
|
|
311
|
+
const failed = checks2.filter((c) => c.status === "fail").length;
|
|
312
|
+
const skipped = checks2.filter((c) => c.status === "skip").length;
|
|
313
|
+
const conforms = !checks2.some((c) => c.level === "MUST" && c.status === "fail");
|
|
314
|
+
return { contract: "0.1", checks: checks2, passed, failed, skipped, conforms };
|
|
315
|
+
}
|
|
316
|
+
function formatConformance(report) {
|
|
317
|
+
const lines = report.checks.map((c) => `${c.status.toUpperCase()} \xA7${c.section} ${c.id} ${c.message}`);
|
|
318
|
+
const verdict = report.conforms ? "Conforms" : "Does not conform";
|
|
319
|
+
lines.push(
|
|
320
|
+
`${verdict} to the Agent Contract ${report.contract}: ${report.passed} passed, ${report.failed} failed, ${report.skipped} skipped.`
|
|
321
|
+
);
|
|
322
|
+
return lines.join("\n");
|
|
323
|
+
}
|
|
324
|
+
export {
|
|
325
|
+
CONFORMANCE_CHECKS,
|
|
326
|
+
PERSON_ONLY_PERMISSIONS,
|
|
327
|
+
formatConformance,
|
|
328
|
+
runConformance
|
|
329
|
+
};
|