/** * `agentsafe test`: the execution boundary, demonstrated rather than * described. A fixed set of consequential requests, most of them the kind * a policy exists to stop, is sent three ways at a synthetic target that * records what reaches it: directly, as an agent would with nothing in the * way; through the gateway in shadow, which forwards everything and says * what would have been decided; and through the gateway in enforcement, * which forwards only what the authority allowed, once, and holds or * refuses the rest. The result is one report: what was exposed without the * boundary, what the boundary prevented, and whether the evidence it left * verifies. * * The test is safe by construction, not by care. The target is a loopback * service this process starts and stops; the authority is the local demo * policy on loopback; nothing named in any configuration, environment or * stored login is read, so a real upstream and a real key are never in * play. The gateways under test are the same `Gateway` behind the same * listener that `agentsafe proxy` runs; nothing here is a mock of the * runtime. */ import { GatewayHttpServer } from "../http/GatewayHttpServer.js"; import { RecordingTarget } from "../http/RecordingTarget.js"; import { type DemoAuthorityHandle } from "./DemoAuthority.js"; import { Gateway, type GatewayDependencies } from "./Gateway.js"; import { type GatewayConfig } from "./GatewayConfig.js"; import type { ExecutionDisposition, GatewayState } from "./GatewayReport.js"; export declare const BOUNDARY_TEST_VERSION = "agent-safe.boundary-test/1"; /** One request the test sends, the same bytes each way. */ export interface BoundaryCase { readonly id: string; readonly title: string; /** Whether the action is one the policy exists to stop; the exposure counts these. */ readonly adversarial: boolean; readonly method: string; readonly path: string; readonly headers: Readonly>; readonly body: string | null; /** The case is sent while the authority is unreachable. */ readonly outage: boolean; } /** What one way of sending a case came to. */ export interface PassOutcome { /** Whether the request arrived at the target at all. */ readonly reached: boolean; /** How many requests the target received for it; one at most, unless something is wrong. */ readonly forwarded: number; /** The status the caller saw, or null when the transport failed. */ readonly status: number | null; readonly state: GatewayState | null; readonly verdict: "ALLOW" | "ESCALATE" | "BLOCK" | null; readonly execution: ExecutionDisposition | null; readonly dossier: boolean; /** Whether any `x-agent-safe-*` header the caller forged arrived at the target. */ readonly forgedHeadersReached: boolean; } export interface BoundaryCaseResult { readonly id: string; readonly title: string; readonly adversarial: boolean; readonly request: { readonly method: string; readonly path: string; readonly body: string | null; readonly outage: boolean; }; readonly direct: PassOutcome; readonly shadow: PassOutcome; readonly enforcement: PassOutcome; /** For an outage case: what the explicit fail-open policy does instead. */ readonly failOpen: PassOutcome | null; } export interface BoundaryTestReport { readonly version: typeof BOUNDARY_TEST_VERSION; readonly at: string; readonly runtime: string; readonly authority: "local/demo"; readonly target: "synthetic loopback"; readonly cases: readonly BoundaryCaseResult[]; /** Of the adversarial cases, how many reached the target each way. */ readonly exposure: { readonly adversarial: number; readonly direct: number; readonly shadow: number; readonly enforcement: number; }; /** Whether the non-adversarial work still went through under enforcement, each exactly once. */ readonly workFlowed: boolean; readonly evidence: { readonly lines: number; readonly verified: boolean; }; /** * `BOUNDARY_HOLDS`: nothing adversarial reached the target under * enforcement, the routine work did, once each, and the evidence verifies. * Anything else is `BOUNDARY_BROKEN`, which is a defect in this runtime, * never a property of the target. */ readonly verdict: "BOUNDARY_HOLDS" | "BOUNDARY_BROKEN"; } /** * The cases, in the order they print. Amounts are in major units against * the demo policy's two ceilings: 100.00 autonomous, 1,000.00 human. */ export declare const BOUNDARY_CASES: readonly BoundaryCase[]; export interface BoundaryTestOptions { readonly version: string; readonly cases?: readonly BoundaryCase[]; readonly clock?: () => number; /** How long to wait for a shadow observation to be reported. */ readonly observationTimeoutMs?: number; /** The demo authority to use, else one is started for the run. */ readonly demoAuthority?: () => Promise; } /** One gateway under test, behind its own listener, writing its lines to an array. */ export interface Lane { readonly gateway: Gateway; readonly server: GatewayHttpServer; readonly url: string; /** Every line the gateway wrote: reports, evidence, security events. */ readonly lines: string[]; } /** What a shadow lane reported about one governed request, once the observation settled. */ export interface Observation { readonly verdict: "ALLOW" | "ESCALATE" | "BLOCK" | null; readonly dossier: boolean; readonly decisionId: string | null; readonly dossierId: string | null; readonly reasonCodes: readonly string[]; } export declare function openLane(config: GatewayConfig, dependencies: GatewayDependencies, lines: string[]): Promise; export declare function closeLane(lane: Lane): Promise; /** Sends one case at one base URL and reads what the target recorded for it. */ export declare function send(base: string, testCase: BoundaryCase, target: RecordingTarget): Promise; /** The `SHADOW` reports a lane has written so far, in the order they settled. */ export declare function shadowReports(lane: Lane): Observation[]; /** * A shadow observation settles after the response, on the report stream, * one per governed request and in the order they were sent, since each is * awaited before the next is sent. The `ordinal`-th governed request's * observation is the `ordinal`-th `SHADOW` report, or none within the * bound when the observation itself could not be made. */ export declare function awaitObservation(lane: Lane, ordinal: number, timeoutMs: number, clock: () => number): Promise; /** Runs the whole test and returns the report; nothing is printed here. */ export declare function runBoundaryTest(options: BoundaryTestOptions): Promise; //# sourceMappingURL=BoundaryTest.d.ts.map