@decionis/agentsafe 0.7.0 → 0.9.0
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/README.md +6 -1
- package/dist/Cli.js +13 -3
- package/dist/Cli.js.map +1 -1
- package/dist/acceptance/AcceptancePlan.d.ts +109 -0
- package/dist/acceptance/AcceptancePlan.d.ts.map +1 -0
- package/dist/acceptance/AcceptancePlan.js +128 -0
- package/dist/acceptance/AcceptancePlan.js.map +1 -0
- package/dist/acceptance/AcceptanceReport.d.ts +596 -0
- package/dist/acceptance/AcceptanceReport.d.ts.map +1 -0
- package/dist/acceptance/AcceptanceReport.js +361 -0
- package/dist/acceptance/AcceptanceReport.js.map +1 -0
- package/dist/acceptance/AcceptanceRun.d.ts +118 -0
- package/dist/acceptance/AcceptanceRun.d.ts.map +1 -0
- package/dist/acceptance/AcceptanceRun.js +419 -0
- package/dist/acceptance/AcceptanceRun.js.map +1 -0
- package/dist/acceptance/Coverage.d.ts +12 -0
- package/dist/acceptance/Coverage.d.ts.map +1 -0
- package/dist/acceptance/Coverage.js +48 -0
- package/dist/acceptance/Coverage.js.map +1 -0
- package/dist/acceptance/OutageDoubles.d.ts +34 -0
- package/dist/acceptance/OutageDoubles.d.ts.map +1 -0
- package/dist/acceptance/OutageDoubles.js +67 -0
- package/dist/acceptance/OutageDoubles.js.map +1 -0
- package/dist/acceptance/ZoneProbes.d.ts +368 -0
- package/dist/acceptance/ZoneProbes.d.ts.map +1 -0
- package/dist/acceptance/ZoneProbes.js +488 -0
- package/dist/acceptance/ZoneProbes.js.map +1 -0
- package/dist/adapters/JcsDigest.d.ts +6 -5
- package/dist/adapters/JcsDigest.d.ts.map +1 -1
- package/dist/adapters/JcsDigest.js +9 -8
- package/dist/adapters/JcsDigest.js.map +1 -1
- package/dist/cli/Accept.d.ts +9 -0
- package/dist/cli/Accept.d.ts.map +1 -0
- package/dist/cli/Accept.js +209 -0
- package/dist/cli/Accept.js.map +1 -0
- package/dist/cli/Actions.d.ts +6 -4
- package/dist/cli/Actions.d.ts.map +1 -1
- package/dist/cli/Actions.js +33 -7
- package/dist/cli/Actions.js.map +1 -1
- package/dist/cli/Commands.d.ts +1 -1
- package/dist/cli/Commands.d.ts.map +1 -1
- package/dist/cli/Commands.js +5 -0
- package/dist/cli/Commands.js.map +1 -1
- package/dist/cli/ConfigCommand.d.ts.map +1 -1
- package/dist/cli/ConfigCommand.js +5 -0
- package/dist/cli/ConfigCommand.js.map +1 -1
- package/dist/cli/Doctor.d.ts.map +1 -1
- package/dist/cli/Doctor.js +67 -1
- package/dist/cli/Doctor.js.map +1 -1
- package/dist/cli/Help.d.ts.map +1 -1
- package/dist/cli/Help.js +6 -1
- package/dist/cli/Help.js.map +1 -1
- package/dist/cli/Identity.d.ts +13 -1
- package/dist/cli/Identity.d.ts.map +1 -1
- package/dist/cli/Identity.js +25 -2
- package/dist/cli/Identity.js.map +1 -1
- package/dist/cli/Status.d.ts +23 -0
- package/dist/cli/Status.d.ts.map +1 -1
- package/dist/cli/Status.js +80 -18
- package/dist/cli/Status.js.map +1 -1
- package/dist/cli/VerifyAcceptance.d.ts +38 -0
- package/dist/cli/VerifyAcceptance.d.ts.map +1 -0
- package/dist/cli/VerifyAcceptance.js +143 -0
- package/dist/cli/VerifyAcceptance.js.map +1 -0
- package/dist/config/ExecutorConfig.d.ts +6 -1
- package/dist/config/ExecutorConfig.d.ts.map +1 -1
- package/dist/config/ExecutorConfig.js.map +1 -1
- package/dist/egress/ZoneHttpClient.d.ts +3 -0
- package/dist/egress/ZoneHttpClient.d.ts.map +1 -0
- package/dist/egress/ZoneHttpClient.js +72 -0
- package/dist/egress/ZoneHttpClient.js.map +1 -0
- package/dist/exposure/DecionisExposureLedger.d.ts +44 -0
- package/dist/exposure/DecionisExposureLedger.d.ts.map +1 -0
- package/dist/exposure/DecionisExposureLedger.js +175 -0
- package/dist/exposure/DecionisExposureLedger.js.map +1 -0
- package/dist/exposure/ExposureDeclaration.d.ts +68 -0
- package/dist/exposure/ExposureDeclaration.d.ts.map +1 -0
- package/dist/exposure/ExposureDeclaration.js +120 -0
- package/dist/exposure/ExposureDeclaration.js.map +1 -0
- package/dist/exposure/ExposureFacts.d.ts +61 -0
- package/dist/exposure/ExposureFacts.d.ts.map +1 -0
- package/dist/exposure/ExposureFacts.js +220 -0
- package/dist/exposure/ExposureFacts.js.map +1 -0
- package/dist/exposure/ExposureGate.d.ts +144 -0
- package/dist/exposure/ExposureGate.d.ts.map +1 -0
- package/dist/exposure/ExposureGate.js +446 -0
- package/dist/exposure/ExposureGate.js.map +1 -0
- package/dist/exposure/ExposureLedger.d.ts +93 -0
- package/dist/exposure/ExposureLedger.d.ts.map +1 -0
- package/dist/exposure/ExposureLedger.js +24 -0
- package/dist/exposure/ExposureLedger.js.map +1 -0
- package/dist/gateway/AttemptStore.d.ts +83 -0
- package/dist/gateway/AttemptStore.d.ts.map +1 -0
- package/dist/gateway/AttemptStore.js +229 -0
- package/dist/gateway/AttemptStore.js.map +1 -0
- package/dist/gateway/ForwardHandler.d.ts +29 -3
- package/dist/gateway/ForwardHandler.d.ts.map +1 -1
- package/dist/gateway/ForwardHandler.js +32 -5
- package/dist/gateway/ForwardHandler.js.map +1 -1
- package/dist/gateway/Gateway.d.ts +229 -17
- package/dist/gateway/Gateway.d.ts.map +1 -1
- package/dist/gateway/Gateway.js +1045 -81
- package/dist/gateway/Gateway.js.map +1 -1
- package/dist/gateway/GatewayConfig.d.ts +186 -0
- package/dist/gateway/GatewayConfig.d.ts.map +1 -1
- package/dist/gateway/GatewayConfig.js +219 -5
- package/dist/gateway/GatewayConfig.js.map +1 -1
- package/dist/gateway/GatewayManifest.d.ts +18 -0
- package/dist/gateway/GatewayManifest.d.ts.map +1 -0
- package/dist/gateway/GatewayManifest.js +42 -0
- package/dist/gateway/GatewayManifest.js.map +1 -0
- package/dist/gateway/GatewayMetrics.d.ts +12 -4
- package/dist/gateway/GatewayMetrics.d.ts.map +1 -1
- package/dist/gateway/GatewayMetrics.js +5 -0
- package/dist/gateway/GatewayMetrics.js.map +1 -1
- package/dist/gateway/GatewayReport.d.ts +34 -1
- package/dist/gateway/GatewayReport.d.ts.map +1 -1
- package/dist/gateway/GatewayReport.js +11 -0
- package/dist/gateway/GatewayReport.js.map +1 -1
- package/dist/gateway/HoldStore.d.ts +89 -0
- package/dist/gateway/HoldStore.d.ts.map +1 -0
- package/dist/gateway/HoldStore.js +280 -0
- package/dist/gateway/HoldStore.js.map +1 -0
- package/dist/gateway/InterceptedRequest.d.ts +10 -0
- package/dist/gateway/InterceptedRequest.d.ts.map +1 -1
- package/dist/gateway/InterceptedRequest.js +20 -0
- package/dist/gateway/InterceptedRequest.js.map +1 -1
- package/dist/gateway/RouteTable.d.ts +33 -5
- package/dist/gateway/RouteTable.d.ts.map +1 -1
- package/dist/gateway/RouteTable.js +76 -1
- package/dist/gateway/RouteTable.js.map +1 -1
- package/dist/gateway/ShadowLedger.d.ts +11 -0
- package/dist/gateway/ShadowLedger.d.ts.map +1 -1
- package/dist/gateway/ShadowLedger.js +11 -0
- package/dist/gateway/ShadowLedger.js.map +1 -1
- package/dist/gateway/TargetEffect.d.ts +74 -0
- package/dist/gateway/TargetEffect.d.ts.map +1 -0
- package/dist/gateway/TargetEffect.js +95 -0
- package/dist/gateway/TargetEffect.js.map +1 -0
- package/dist/gateway/TargetReader.d.ts +70 -0
- package/dist/gateway/TargetReader.d.ts.map +1 -0
- package/dist/gateway/TargetReader.js +106 -0
- package/dist/gateway/TargetReader.js.map +1 -0
- package/dist/gateway/Upstream.d.ts +15 -0
- package/dist/gateway/Upstream.d.ts.map +1 -1
- package/dist/gateway/Upstream.js +24 -2
- package/dist/gateway/Upstream.js.map +1 -1
- package/dist/hosted/TenantHost.d.ts +3 -2
- package/dist/hosted/TenantHost.d.ts.map +1 -1
- package/dist/hosted/TenantHost.js +7 -1
- package/dist/hosted/TenantHost.js.map +1 -1
- package/dist/hosted/TenantRegistry.d.ts +8 -0
- package/dist/hosted/TenantRegistry.d.ts.map +1 -1
- package/dist/hosted/TenantRegistry.js +14 -1
- package/dist/hosted/TenantRegistry.js.map +1 -1
- package/dist/http/GatewayHttpServer.d.ts +7 -0
- package/dist/http/GatewayHttpServer.d.ts.map +1 -1
- package/dist/http/GatewayHttpServer.js +57 -1
- package/dist/http/GatewayHttpServer.js.map +1 -1
- package/dist/outcomes/OutcomeEvidence.d.ts +4 -4
- package/dist/posture/ActionSpaceDrift.d.ts +40 -0
- package/dist/posture/ActionSpaceDrift.d.ts.map +1 -0
- package/dist/posture/ActionSpaceDrift.js +67 -0
- package/dist/posture/ActionSpaceDrift.js.map +1 -0
- package/dist/posture/DeploymentFingerprint.d.ts +88 -0
- package/dist/posture/DeploymentFingerprint.d.ts.map +1 -0
- package/dist/posture/DeploymentFingerprint.js +78 -0
- package/dist/posture/DeploymentFingerprint.js.map +1 -0
- package/dist/secrets/SecretStore.d.ts +6 -1
- package/dist/secrets/SecretStore.d.ts.map +1 -1
- package/dist/secrets/SecretStore.js.map +1 -1
- package/dist/service/EscalationResolver.d.ts +6 -6
- package/dist/service/EscalationResolver.d.ts.map +1 -1
- package/dist/service/EscalationResolver.js +8 -4
- package/dist/service/EscalationResolver.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The gateway's side of an acceptance run
|
|
3
|
+
* ([ADR 0009](../../../../docs/architecture/decisions/0009-acceptance-run-on-named-targets.md)):
|
|
4
|
+
* one run open at a time, the plan checked against the gateway's own routes,
|
|
5
|
+
* a prohibited write decided in shadow before it may be sent, each tagged
|
|
6
|
+
* request matched to the write the plan names, and the report assembled from
|
|
7
|
+
* what the gateway itself observed, then signed.
|
|
8
|
+
*
|
|
9
|
+
* What it establishes: that the requests the gateway reports on are the ones
|
|
10
|
+
* the plan names, and what the gateway did with each. What it does not: the
|
|
11
|
+
* zone's findings are the zone's word, carried as reported, and judged by the
|
|
12
|
+
* same rules but never checked here.
|
|
13
|
+
*/
|
|
14
|
+
import { createHash, randomBytes, timingSafeEqual } from "node:crypto";
|
|
15
|
+
import { parseAcceptancePlan, planDigest, splitTarget, writeBody, } from "./AcceptancePlan.js";
|
|
16
|
+
import { ACCEPTANCE_REPORT_VERSION, ACCEPTANCE_SCOPE, AcceptanceReportSchema, STATED_NOT_RUN, acceptanceVerdict, judgeOutage, judgePermitted, judgeProhibited, } from "./AcceptanceReport.js";
|
|
17
|
+
import { zoneFindingsSchema } from "./ZoneProbes.js";
|
|
18
|
+
/** The header a run's request carries: `<run id>:<write name>`. Never forwarded. */
|
|
19
|
+
export const ACCEPTANCE_RUN_HEADER = "agentsafe-acceptance-run";
|
|
20
|
+
/** How long a run stays open before it is discarded unsigned. */
|
|
21
|
+
export const RUN_TTL_MS = 15 * 60 * 1_000;
|
|
22
|
+
/** The longest the close waits for the gateway's reports on what was sent. */
|
|
23
|
+
export const CLOSE_WAIT_MS = 30_000;
|
|
24
|
+
/** A write's path and query, as the listener reads them. */
|
|
25
|
+
function targetOf(path) {
|
|
26
|
+
const { path: pathname, search } = splitTarget(path);
|
|
27
|
+
return `${pathname}${search}`;
|
|
28
|
+
}
|
|
29
|
+
function refused(status, code, detail) {
|
|
30
|
+
return { status, body: detail === undefined ? { code } : { code, detail } };
|
|
31
|
+
}
|
|
32
|
+
function sameSecret(presented, expected) {
|
|
33
|
+
const a = createHash("sha256").update(presented).digest();
|
|
34
|
+
const b = createHash("sha256").update(expected).digest();
|
|
35
|
+
return timingSafeEqual(a, b);
|
|
36
|
+
}
|
|
37
|
+
export class AcceptanceRuns {
|
|
38
|
+
host;
|
|
39
|
+
random;
|
|
40
|
+
run = null;
|
|
41
|
+
constructor(host, random = () => randomBytes(32).toString("base64url")) {
|
|
42
|
+
this.host = host;
|
|
43
|
+
this.random = random;
|
|
44
|
+
}
|
|
45
|
+
/** The open run: none once its time is up, unless it is already closing. */
|
|
46
|
+
current() {
|
|
47
|
+
const run = this.run;
|
|
48
|
+
return run !== null && (run.closing || this.host.clock() - run.openedAt < RUN_TTL_MS)
|
|
49
|
+
? run
|
|
50
|
+
: null;
|
|
51
|
+
}
|
|
52
|
+
named(runId) {
|
|
53
|
+
const run = this.current();
|
|
54
|
+
return run !== null && sameSecret(runId, run.id) ? run : null;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Opens a run for a plan, once the plan's writes are all writes this gateway
|
|
58
|
+
* decides in enforcement, and each prohibited one reads its target. A run
|
|
59
|
+
* already open refuses another until it closes or its time is up.
|
|
60
|
+
*/
|
|
61
|
+
open(body) {
|
|
62
|
+
if (this.current() !== null)
|
|
63
|
+
return refused(409, "ACCEPTANCE_RUN_OPEN");
|
|
64
|
+
let plan;
|
|
65
|
+
try {
|
|
66
|
+
plan = parseAcceptancePlan(body);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
return refused(400, "ACCEPTANCE_PLAN_INVALID", error.detail);
|
|
70
|
+
}
|
|
71
|
+
const writes = new Map();
|
|
72
|
+
const routes = [];
|
|
73
|
+
for (const [kind, list] of [
|
|
74
|
+
["permitted", plan.permitted],
|
|
75
|
+
["prohibited", plan.prohibited],
|
|
76
|
+
]) {
|
|
77
|
+
for (const write of list) {
|
|
78
|
+
const route = this.host.route(write);
|
|
79
|
+
if (!route.enforced)
|
|
80
|
+
return refused(422, "ACCEPTANCE_WRITE_NOT_ENFORCED", write.name);
|
|
81
|
+
if (kind === "prohibited" && !route.targetRead) {
|
|
82
|
+
return refused(422, "ACCEPTANCE_WRITE_NOT_OBSERVABLE", write.name);
|
|
83
|
+
}
|
|
84
|
+
writes.set(write.name, { kind, write });
|
|
85
|
+
routes.push({ name: write.name, kind, action: route.action });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const id = this.random();
|
|
89
|
+
const digest = planDigest(plan);
|
|
90
|
+
const publicId = createHash("sha256").update(id).digest("hex").slice(0, 32);
|
|
91
|
+
this.run = {
|
|
92
|
+
id,
|
|
93
|
+
publicId,
|
|
94
|
+
plan,
|
|
95
|
+
digest,
|
|
96
|
+
openedAt: this.host.clock(),
|
|
97
|
+
writes,
|
|
98
|
+
shadow: new Map(),
|
|
99
|
+
sent: new Map(),
|
|
100
|
+
intents: new Map(),
|
|
101
|
+
closing: false,
|
|
102
|
+
};
|
|
103
|
+
this.host.link({
|
|
104
|
+
event: "ACCEPTANCE_RUN_OPENED",
|
|
105
|
+
run_id: publicId,
|
|
106
|
+
plan_digest: digest,
|
|
107
|
+
fingerprint: this.host.fingerprint.digest,
|
|
108
|
+
});
|
|
109
|
+
return {
|
|
110
|
+
status: 201,
|
|
111
|
+
body: {
|
|
112
|
+
run_id: id,
|
|
113
|
+
plan_digest: digest,
|
|
114
|
+
expires_at: new Date(this.host.clock() + RUN_TTL_MS).toISOString(),
|
|
115
|
+
fingerprint: this.host.fingerprint.digest,
|
|
116
|
+
coverage: this.host.coverage,
|
|
117
|
+
writes: routes,
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* A prohibited write the open run names, decided in shadow: nothing read,
|
|
123
|
+
* nothing forwarded, the decision on the chain. Only a write the plan names
|
|
124
|
+
* as prohibited is decided, once; the endpoint answers nothing else.
|
|
125
|
+
*/
|
|
126
|
+
async decide(runId, name) {
|
|
127
|
+
const run = this.named(runId);
|
|
128
|
+
if (run === null)
|
|
129
|
+
return refused(404, "ACCEPTANCE_RUN_UNKNOWN");
|
|
130
|
+
const entry = run.writes.get(name);
|
|
131
|
+
if (entry?.kind !== "prohibited")
|
|
132
|
+
return refused(404, "ACCEPTANCE_WRITE_UNKNOWN");
|
|
133
|
+
if (run.shadow.has(name))
|
|
134
|
+
return refused(409, "ACCEPTANCE_WRITE_DECIDED");
|
|
135
|
+
const outcome = await this.host.decide(entry.write);
|
|
136
|
+
run.shadow.set(name, outcome);
|
|
137
|
+
this.host.link({
|
|
138
|
+
event: "ACCEPTANCE_SHADOW_DECIDED",
|
|
139
|
+
run_id: run.publicId,
|
|
140
|
+
write: name,
|
|
141
|
+
verdict: outcome.verdict,
|
|
142
|
+
decision_id: outcome.decision_id,
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
status: 200,
|
|
146
|
+
body: {
|
|
147
|
+
write: name,
|
|
148
|
+
verdict: outcome.verdict,
|
|
149
|
+
reason_codes: [...outcome.reason_codes],
|
|
150
|
+
decision_id: outcome.decision_id,
|
|
151
|
+
dossier_id: outcome.dossier_id,
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Whether a request carrying the run header is a write the open run names,
|
|
157
|
+
* sent as the plan wrote it, once, and, when prohibited, only after a shadow
|
|
158
|
+
* BLOCK or ESCALATE. Anything else carrying the header is refused before
|
|
159
|
+
* the authority is asked, so a run never sends what its plan did not name.
|
|
160
|
+
*/
|
|
161
|
+
admit(tag, request) {
|
|
162
|
+
if (tag === undefined)
|
|
163
|
+
return { kind: "NONE" };
|
|
164
|
+
const at = tag.lastIndexOf(":");
|
|
165
|
+
const run = at === -1 ? null : this.named(tag.slice(0, at));
|
|
166
|
+
if (run === null || run.closing)
|
|
167
|
+
return { kind: "REFUSE", code: "ACCEPTANCE_RUN_UNKNOWN" };
|
|
168
|
+
const name = tag.slice(at + 1);
|
|
169
|
+
const entry = run.writes.get(name);
|
|
170
|
+
if (entry === undefined)
|
|
171
|
+
return { kind: "REFUSE", code: "ACCEPTANCE_WRITE_UNKNOWN" };
|
|
172
|
+
const { write } = entry;
|
|
173
|
+
if (request.method.toUpperCase() !== write.method ||
|
|
174
|
+
`${request.path}${request.search}` !== targetOf(write.path) ||
|
|
175
|
+
!request.body.equals(writeBody(write))) {
|
|
176
|
+
return { kind: "REFUSE", code: "ACCEPTANCE_WRITE_DIFFERS" };
|
|
177
|
+
}
|
|
178
|
+
if (run.sent.has(name))
|
|
179
|
+
return { kind: "REFUSE", code: "ACCEPTANCE_WRITE_REPEATED" };
|
|
180
|
+
if (entry.kind === "prohibited") {
|
|
181
|
+
const verdict = run.shadow.get(name)?.verdict;
|
|
182
|
+
if (verdict !== "BLOCK" && verdict !== "ESCALATE") {
|
|
183
|
+
return { kind: "REFUSE", code: "ACCEPTANCE_SHADOW_REFUSAL_REQUIRED" };
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
let reported = () => undefined;
|
|
187
|
+
const settled = new Promise((resolve) => {
|
|
188
|
+
reported = resolve;
|
|
189
|
+
});
|
|
190
|
+
run.sent.set(name, {
|
|
191
|
+
report: null,
|
|
192
|
+
answered: null,
|
|
193
|
+
intentId: null,
|
|
194
|
+
lines: [],
|
|
195
|
+
observation: null,
|
|
196
|
+
reported,
|
|
197
|
+
settled,
|
|
198
|
+
});
|
|
199
|
+
return { kind: "TRACK", name };
|
|
200
|
+
}
|
|
201
|
+
/** The intent a tracked write was captured as. */
|
|
202
|
+
captured(name, intentId) {
|
|
203
|
+
const run = this.run;
|
|
204
|
+
if (run === null)
|
|
205
|
+
return;
|
|
206
|
+
const sent = run.sent.get(name);
|
|
207
|
+
if (sent === undefined)
|
|
208
|
+
return;
|
|
209
|
+
sent.intentId = intentId;
|
|
210
|
+
run.intents.set(intentId, sent);
|
|
211
|
+
}
|
|
212
|
+
/** The gateway's answer to a tracked write, for one refused before it was captured. */
|
|
213
|
+
answered(name, state, execution) {
|
|
214
|
+
const sent = this.run?.sent.get(name);
|
|
215
|
+
if (sent === undefined)
|
|
216
|
+
return;
|
|
217
|
+
sent.answered = { state, execution };
|
|
218
|
+
if (sent.intentId === null)
|
|
219
|
+
sent.reported();
|
|
220
|
+
}
|
|
221
|
+
/** What the gateway reported of a tracked write. */
|
|
222
|
+
intercepted(report) {
|
|
223
|
+
const sent = this.run?.intents.get(report.intent_id);
|
|
224
|
+
if (sent === undefined)
|
|
225
|
+
return;
|
|
226
|
+
sent.report = report;
|
|
227
|
+
sent.reported();
|
|
228
|
+
}
|
|
229
|
+
/** A line the gateway chained about a tracked write. */
|
|
230
|
+
linked(fields, line) {
|
|
231
|
+
const sent = this.run?.intents.get(fields["intent_id"]);
|
|
232
|
+
if (sent === undefined)
|
|
233
|
+
return;
|
|
234
|
+
if (sent.lines.length < 16)
|
|
235
|
+
sent.lines.push(line);
|
|
236
|
+
if (fields["event"] === "REFUSAL_OBSERVATION") {
|
|
237
|
+
const text = (key) => {
|
|
238
|
+
const value = fields[key];
|
|
239
|
+
return typeof value === "string" ? value : null;
|
|
240
|
+
};
|
|
241
|
+
sent.observation = {
|
|
242
|
+
outcome: fields["outcome"],
|
|
243
|
+
version_before: text("version_before"),
|
|
244
|
+
version_after: text("version_after"),
|
|
245
|
+
read_before_at: text("read_before_at"),
|
|
246
|
+
read_after_at: text("read_after_at"),
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Closes the run: the zone's findings taken as reported, the outage case
|
|
252
|
+
* run on the second gateway, every read after a refusal awaited, the report
|
|
253
|
+
* assembled from what the gateway observed, signed, and its digest chained.
|
|
254
|
+
*/
|
|
255
|
+
async close(runId, findings) {
|
|
256
|
+
const run = this.named(runId);
|
|
257
|
+
if (run === null || run.closing)
|
|
258
|
+
return refused(404, "ACCEPTANCE_RUN_UNKNOWN");
|
|
259
|
+
const zone = zoneFindingsSchema.safeParse(findings);
|
|
260
|
+
if (!zone.success)
|
|
261
|
+
return refused(400, "ACCEPTANCE_ZONE_FINDINGS_INVALID");
|
|
262
|
+
run.closing = true;
|
|
263
|
+
try {
|
|
264
|
+
const outage = [];
|
|
265
|
+
for (const { write } of run.writes.values())
|
|
266
|
+
outage.push(await this.outageCase(write));
|
|
267
|
+
await Promise.race([
|
|
268
|
+
Promise.all([...run.sent.values()].map((sent) => sent.settled)),
|
|
269
|
+
new Promise((resolve) => setTimeout(resolve, CLOSE_WAIT_MS).unref()),
|
|
270
|
+
]);
|
|
271
|
+
await this.host.settled();
|
|
272
|
+
const permitted = run.plan.permitted.map((write) => this.permittedCase(run, write));
|
|
273
|
+
const prohibited = run.plan.prohibited.map((write) => this.prohibitedCase(run, write));
|
|
274
|
+
const issuedAt = this.host.clock();
|
|
275
|
+
const cases = { permitted, prohibited, outage, zone: zone.data };
|
|
276
|
+
const report = {
|
|
277
|
+
report: ACCEPTANCE_REPORT_VERSION,
|
|
278
|
+
run_id: run.publicId,
|
|
279
|
+
boundary_id: this.host.boundaryId,
|
|
280
|
+
issued_at: new Date(issuedAt).toISOString(),
|
|
281
|
+
expires_at: run.plan.expires_at,
|
|
282
|
+
plan_digest: run.digest,
|
|
283
|
+
fingerprint: {
|
|
284
|
+
digest: this.host.fingerprint.digest,
|
|
285
|
+
document: this.host.fingerprint.document,
|
|
286
|
+
},
|
|
287
|
+
coverage: this.host.coverage,
|
|
288
|
+
...cases,
|
|
289
|
+
stated: STATED_NOT_RUN.map((item) => ({ ...item })),
|
|
290
|
+
...acceptanceVerdict(cases),
|
|
291
|
+
scope: ACCEPTANCE_SCOPE,
|
|
292
|
+
};
|
|
293
|
+
// A report a verifier would refuse is never signed: what the gateway
|
|
294
|
+
// observed must fit the contract it signs it under.
|
|
295
|
+
if (!AcceptanceReportSchema.safeParse(report).success) {
|
|
296
|
+
return refused(500, "ACCEPTANCE_REPORT_INVALID");
|
|
297
|
+
}
|
|
298
|
+
const token = await this.host.sign(report);
|
|
299
|
+
this.host.link({
|
|
300
|
+
event: "ACCEPTANCE_SIGNED",
|
|
301
|
+
run_id: report.run_id,
|
|
302
|
+
report_digest: `sha256:${createHash("sha256").update(token).digest("hex")}`,
|
|
303
|
+
verdict: report.verdict,
|
|
304
|
+
});
|
|
305
|
+
return { status: 200, body: { report: token, verdict: report.verdict } };
|
|
306
|
+
}
|
|
307
|
+
finally {
|
|
308
|
+
this.run = null;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
outcomeOf(sent) {
|
|
312
|
+
const report = sent?.report ?? null;
|
|
313
|
+
if (report !== null) {
|
|
314
|
+
return {
|
|
315
|
+
upstream_status: report.upstream_status,
|
|
316
|
+
state: report.state,
|
|
317
|
+
verdict: report.verdict,
|
|
318
|
+
execution: report.execution,
|
|
319
|
+
intent_id: report.intent_id,
|
|
320
|
+
decision_id: report.decision_id,
|
|
321
|
+
dossier_id: report.dossier_id,
|
|
322
|
+
reason_codes: [...report.reason_codes],
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
return {
|
|
326
|
+
upstream_status: null,
|
|
327
|
+
state: sent?.answered?.state ?? null,
|
|
328
|
+
verdict: null,
|
|
329
|
+
execution: sent?.answered?.execution ?? null,
|
|
330
|
+
intent_id: sent?.intentId ?? null,
|
|
331
|
+
decision_id: null,
|
|
332
|
+
dossier_id: null,
|
|
333
|
+
reason_codes: [],
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
permittedCase(run, write) {
|
|
337
|
+
const sent = run.sent.get(write.name);
|
|
338
|
+
const outcome = this.outcomeOf(sent);
|
|
339
|
+
const effect = sent?.report?.effect ?? null;
|
|
340
|
+
const judged = sent === undefined ? { passed: false, failure: "NOT_SENT" } : judgePermitted(outcome, effect);
|
|
341
|
+
return {
|
|
342
|
+
name: write.name,
|
|
343
|
+
method: write.method,
|
|
344
|
+
path: write.path,
|
|
345
|
+
action: this.host.route(write).action,
|
|
346
|
+
observed_by: "GATEWAY",
|
|
347
|
+
...outcome,
|
|
348
|
+
effect: effect === null ? null : { ...effect, reason_codes: [...effect.reason_codes] },
|
|
349
|
+
lines: [...(sent?.lines ?? [])],
|
|
350
|
+
...judged,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
prohibitedCase(run, write) {
|
|
354
|
+
const sent = run.sent.get(write.name);
|
|
355
|
+
const shadow = run.shadow.get(write.name) ?? null;
|
|
356
|
+
const outcome = this.outcomeOf(sent);
|
|
357
|
+
const observation = sent?.observation ?? null;
|
|
358
|
+
return {
|
|
359
|
+
name: write.name,
|
|
360
|
+
method: write.method,
|
|
361
|
+
path: write.path,
|
|
362
|
+
action: this.host.route(write).action,
|
|
363
|
+
canary: write.canary,
|
|
364
|
+
observed_by: "GATEWAY",
|
|
365
|
+
shadow: {
|
|
366
|
+
verdict: shadow?.verdict ?? null,
|
|
367
|
+
reason_codes: [...(shadow?.reason_codes ?? [])],
|
|
368
|
+
decision_id: shadow?.decision_id ?? null,
|
|
369
|
+
dossier_id: shadow?.dossier_id ?? null,
|
|
370
|
+
},
|
|
371
|
+
sent: sent !== undefined,
|
|
372
|
+
...outcome,
|
|
373
|
+
observation,
|
|
374
|
+
lines: [...(sent?.lines ?? [])],
|
|
375
|
+
...judgeProhibited({
|
|
376
|
+
shadow: shadow?.verdict ?? null,
|
|
377
|
+
sent: sent !== undefined,
|
|
378
|
+
outcome,
|
|
379
|
+
observation,
|
|
380
|
+
}),
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
async outageCase(write) {
|
|
384
|
+
const base = {
|
|
385
|
+
name: write.name,
|
|
386
|
+
method: write.method,
|
|
387
|
+
path: write.path,
|
|
388
|
+
action: this.host.route(write).action,
|
|
389
|
+
observed_by: "GATEWAY",
|
|
390
|
+
};
|
|
391
|
+
if (this.host.failurePolicy === "FAIL_OPEN") {
|
|
392
|
+
return {
|
|
393
|
+
...base,
|
|
394
|
+
skipped: "FAIL_OPEN",
|
|
395
|
+
status: null,
|
|
396
|
+
execution: null,
|
|
397
|
+
reason_codes: [],
|
|
398
|
+
upstream_writes: 0,
|
|
399
|
+
passed: true,
|
|
400
|
+
failure: null,
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
const outcome = await this.host.outage(write);
|
|
404
|
+
return {
|
|
405
|
+
...base,
|
|
406
|
+
skipped: null,
|
|
407
|
+
status: outcome.status,
|
|
408
|
+
execution: outcome.execution,
|
|
409
|
+
reason_codes: [...outcome.reason_codes],
|
|
410
|
+
upstream_writes: outcome.upstreamWrites,
|
|
411
|
+
...judgeOutage({
|
|
412
|
+
status: outcome.status,
|
|
413
|
+
execution: outcome.execution,
|
|
414
|
+
upstreamWrites: outcome.upstreamWrites,
|
|
415
|
+
}),
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
//# sourceMappingURL=AcceptanceRun.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AcceptanceRun.js","sourceRoot":"","sources":["../../src/acceptance/AcceptanceRun.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAMvE,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,WAAW,EACX,SAAS,GAIV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,yBAAyB,EACzB,gBAAgB,EAChB,sBAAsB,EACtB,cAAc,EACd,iBAAiB,EACjB,WAAW,EACX,cAAc,EACd,eAAe,GAShB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,oFAAoF;AACpF,MAAM,CAAC,MAAM,qBAAqB,GAAG,0BAA0B,CAAC;AAEhE,iEAAiE;AACjE,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC;AAE1C,8EAA8E;AAC9E,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC;AAqFpC,4DAA4D;AAC5D,SAAS,QAAQ,CAAC,IAAY;IAC5B,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IACrD,OAAO,GAAG,QAAQ,GAAG,MAAM,EAAE,CAAC;AAChC,CAAC;AAED,SAAS,OAAO,CAAC,MAAc,EAAE,IAAY,EAAE,MAAe;IAC5D,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC;AAC9E,CAAC;AAED,S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,EAAE,KAAK,CAAC,IAAI;YAChB,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM;YACrC,WAAW,EAAE,SAAkB;SAChC,CAAC;QACF,IAAI,IAAI,CAAC,IAAI,CAAC,aAAa,KAAK,WAAW,EAAE,CAAC;YAC5C,OAAO;gBACL,GAAG,IAAI;gBACP,OAAO,EAAE,WAAW;gBACpB,MAAM,EAAE,IAAI;gBACZ,SAAS,EAAE,IAAI;gBACf,YAAY,EAAE,EAAE;gBAChB,eAAe,EAAE,CAAC;gBAClB,MAAM,EAAE,IAAI;gBACZ,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;QACD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC9C,OAAO;YACL,GAAG,IAAI;YACP,OAAO,EAAE,IAAI;YACb,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,YAAY,EAAE,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC;YACvC,eAAe,EAAE,OAAO,CAAC,cAAc;YACvC,GAAG,WAAW,CAAC;gBACb,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,SAAS,EAAE,OAAO,CAAC,SAAS;gBAC5B,cAAc,EAAE,OAAO,CAAC,cAAc;aACvC,CAAC;SACH,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { GatewayConfig } from "../gateway/GatewayConfig.js";
|
|
2
|
+
import type { RouteTable } from "../gateway/RouteTable.js";
|
|
3
|
+
import type { Coverage } from "./AcceptanceReport.js";
|
|
4
|
+
/**
|
|
5
|
+
* A governed route is decided in enforcement and fails closed; one that fails
|
|
6
|
+
* open is decided only while the authority answers, and one in shadow is
|
|
7
|
+
* never decided at all, so both are listed as not governed. A governed write
|
|
8
|
+
* says whether its target is read: only then can its effect, or a refusal,
|
|
9
|
+
* be observed there.
|
|
10
|
+
*/
|
|
11
|
+
export declare function coverageOf(routes: RouteTable, config: Pick<GatewayConfig, "authority">): Coverage;
|
|
12
|
+
//# sourceMappingURL=Coverage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Coverage.d.ts","sourceRoot":"","sources":["../../src/acceptance/Coverage.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE,WAAW,CAAC,GAAG,QAAQ,CAiCjG"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which of a gateway's routes the authority decides, and which it does not,
|
|
3
|
+
* by kind: what an acceptance report says is in scope before it says what
|
|
4
|
+
* passed. Computed from the configuration alone, as the fingerprint is, so
|
|
5
|
+
* the two describe the same gateway.
|
|
6
|
+
*/
|
|
7
|
+
import { ApiProfile } from "@decionis/agent-safe-pipeline";
|
|
8
|
+
/**
|
|
9
|
+
* A governed route is decided in enforcement and fails closed; one that fails
|
|
10
|
+
* open is decided only while the authority answers, and one in shadow is
|
|
11
|
+
* never decided at all, so both are listed as not governed. A governed write
|
|
12
|
+
* says whether its target is read: only then can its effect, or a refusal,
|
|
13
|
+
* be observed there.
|
|
14
|
+
*/
|
|
15
|
+
export function coverageOf(routes, config) {
|
|
16
|
+
const reads = new Set(
|
|
17
|
+
// Stryker disable next-line ArrayDeclaration: with no profile there is no operation, and a string in its place names no precondition either.
|
|
18
|
+
(routes.profile?.definition.operations ?? [])
|
|
19
|
+
.filter((operation) => !ApiProfile.isRead(operation) && operation.precondition !== undefined)
|
|
20
|
+
.map((operation) => `${operation.method} ${operation.path} ${operation.action}`));
|
|
21
|
+
const coverage = { governed: [], ungoverned: [], refused: [] };
|
|
22
|
+
for (const row of routes.rows()) {
|
|
23
|
+
const route = { methods: [...row.methods], path: row.path, action: row.action };
|
|
24
|
+
if (row.disposition === "REFUSE") {
|
|
25
|
+
coverage.refused.push(route);
|
|
26
|
+
}
|
|
27
|
+
else if (row.disposition === "PASSTHROUGH") {
|
|
28
|
+
coverage.ungoverned.push({ ...route, kind: "PASSTHROUGH" });
|
|
29
|
+
}
|
|
30
|
+
else if (config.authority.mode === "SHADOW") {
|
|
31
|
+
coverage.ungoverned.push({ ...route, kind: "SHADOW" });
|
|
32
|
+
}
|
|
33
|
+
else if (config.authority.failurePolicy === "FAIL_OPEN") {
|
|
34
|
+
coverage.ungoverned.push({ ...route, kind: "FAIL_OPEN" });
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// A profile's write is one method; a route of several names no read.
|
|
38
|
+
// Stryker disable next-line StringLiteral: a profile's row has one method, so the separator never joins two.
|
|
39
|
+
const methods = row.methods.join(" ");
|
|
40
|
+
coverage.governed.push({
|
|
41
|
+
...route,
|
|
42
|
+
target_read: reads.has(`${methods} ${row.path} ${row.action}`),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return { ...coverage, reads: routes.reads };
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=Coverage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Coverage.js","sourceRoot":"","sources":["../../src/acceptance/Coverage.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAK3D;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,MAAkB,EAAE,MAAwC;IACrF,MAAM,KAAK,GAAG,IAAI,GAAG;IACnB,6IAA6I;IAC7I,CAAC,MAAM,CAAC,O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CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;QAC5D,CAAC;aAAM,CAAC;YACN,qEAAqE;YACrE,6GAA6G;YAC7G,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACtC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC;gBACrB,GAAG,KAAK;gBACR,WAAW,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,OAAO,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;aAC/D,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,EAAE,GAAG,QAAQ,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The doubles the outage case's second gateway runs against: an authority
|
|
3
|
+
* that cannot be reached, and an upstream that records what reaches it and
|
|
4
|
+
* effects nothing. The second gateway is built from the configuration the
|
|
5
|
+
* deployed process loaded, so what it shows is that configuration, under
|
|
6
|
+
* this runtime, failing closed; it shows nothing about the real authority or
|
|
7
|
+
* the real upstream, which it never contacts.
|
|
8
|
+
*/
|
|
9
|
+
import type { ApiProfile, JsonValue } from "@decionis/agent-safe-pipeline";
|
|
10
|
+
import type { FetchLike } from "../handlers/HandlerRegistration.js";
|
|
11
|
+
/** The authority, unreachable: every call fails before a byte is sent. */
|
|
12
|
+
export declare const AUTHORITY_UNREACHABLE: FetchLike;
|
|
13
|
+
/** The version a read of the recording upstream states. */
|
|
14
|
+
export declare const OUTAGE_VERSION = "acceptance-outage";
|
|
15
|
+
/**
|
|
16
|
+
* An answer that states a version, and a state, wherever any write's
|
|
17
|
+
* precondition looks for one: the read the gateway makes before it asks the
|
|
18
|
+
* authority then succeeds, so the case reaches the authority it cannot ask.
|
|
19
|
+
*/
|
|
20
|
+
export declare function statingAnswer(profile: ApiProfile | null): {
|
|
21
|
+
readonly headers: Record<string, string>;
|
|
22
|
+
readonly body: JsonValue | undefined;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The upstream the second gateway forwards to: a read is answered with the
|
|
26
|
+
* stating answer, and anything else is counted and refused. A write counted
|
|
27
|
+
* here is one that would have reached the real upstream with the authority
|
|
28
|
+
* down, which is what the case looks for.
|
|
29
|
+
*/
|
|
30
|
+
export declare function recordingUpstream(profile: ApiProfile | null): {
|
|
31
|
+
readonly fetch: FetchLike;
|
|
32
|
+
readonly writes: () => number;
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=OutageDoubles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OutageDoubles.d.ts","sourceRoot":"","sources":["../../src/acceptance/OutageDoubles.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,UAAU,EAAc,SAAS,EAAE,MAAM,+BAA+B,CAAC;AACvF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAEpE,0EAA0E;AAC1E,eAAO,MAAM,qBAAqB,EAAE,SACgB,CAAC;AAErD,2DAA2D;AAC3D,eAAO,MAAM,cAAc,sBAAsB,CAAC;AAElD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,GAAG;IACzD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzC,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC;CACtC,CAmCA;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,UAAU,GAAG,IAAI,GAAG;IAC7D,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,MAAM,CAAC;CAC/B,CAkBA"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** The authority, unreachable: every call fails before a byte is sent. */
|
|
2
|
+
export const AUTHORITY_UNREACHABLE = () => Promise.reject(new Error("AUTHORITY_UNREACHABLE"));
|
|
3
|
+
/** The version a read of the recording upstream states. */
|
|
4
|
+
export const OUTAGE_VERSION = "acceptance-outage";
|
|
5
|
+
/**
|
|
6
|
+
* An answer that states a version, and a state, wherever any write's
|
|
7
|
+
* precondition looks for one: the read the gateway makes before it asks the
|
|
8
|
+
* authority then succeeds, so the case reaches the authority it cannot ask.
|
|
9
|
+
*/
|
|
10
|
+
export function statingAnswer(profile) {
|
|
11
|
+
const headers = {};
|
|
12
|
+
let body;
|
|
13
|
+
// Stryker disable next-line ArrayDeclaration: with no profile there is no operation, and a string in its place names no precondition either.
|
|
14
|
+
const pointers = (profile?.definition.operations ?? []).flatMap((operation) => operation.precondition === undefined
|
|
15
|
+
? []
|
|
16
|
+
: [operation.precondition.version, operation.precondition.state].filter((pointer) => pointer !== undefined));
|
|
17
|
+
for (const pointer of pointers) {
|
|
18
|
+
const segments = pointer
|
|
19
|
+
.slice(1)
|
|
20
|
+
.split("/")
|
|
21
|
+
.map((segment) => segment.replaceAll("~1", "/").replaceAll("~0", "~"));
|
|
22
|
+
if (segments[0] === "headers") {
|
|
23
|
+
headers[segments[1]] = OUTAGE_VERSION;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (segments.length === 1) {
|
|
27
|
+
body = OUTAGE_VERSION;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
// Only a string or an object built here is ever in place: a string gives way.
|
|
31
|
+
if (typeof body !== "object")
|
|
32
|
+
body = {};
|
|
33
|
+
let node = body;
|
|
34
|
+
for (const segment of segments.slice(1, -1)) {
|
|
35
|
+
const next = node[segment];
|
|
36
|
+
node[segment] = typeof next === "object" ? next : {};
|
|
37
|
+
node = node[segment];
|
|
38
|
+
}
|
|
39
|
+
node[segments.at(-1)] = OUTAGE_VERSION;
|
|
40
|
+
}
|
|
41
|
+
return { headers, body };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The upstream the second gateway forwards to: a read is answered with the
|
|
45
|
+
* stating answer, and anything else is counted and refused. A write counted
|
|
46
|
+
* here is one that would have reached the real upstream with the authority
|
|
47
|
+
* down, which is what the case looks for.
|
|
48
|
+
*/
|
|
49
|
+
export function recordingUpstream(profile) {
|
|
50
|
+
let writes = 0;
|
|
51
|
+
const answer = statingAnswer(profile);
|
|
52
|
+
const fetch = (_input, init) => {
|
|
53
|
+
const method = (init?.method ?? "GET").toUpperCase();
|
|
54
|
+
if (method === "GET" || method === "HEAD") {
|
|
55
|
+
return Promise.resolve(
|
|
56
|
+
// No stated body is `undefined` here, which a response sends as none.
|
|
57
|
+
new Response(JSON.stringify(answer.body), {
|
|
58
|
+
status: 200,
|
|
59
|
+
headers: { "content-type": "application/json", ...answer.headers },
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
writes += 1;
|
|
63
|
+
return Promise.resolve(new Response(null, { status: 502 }));
|
|
64
|
+
};
|
|
65
|
+
return { fetch, writes: () => writes };
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=OutageDoubles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OutageDoubles.js","sourceRoot":"","sources":["../../src/acceptance/OutageDoubles.ts"],"names":[],"mappings":"AAWA,0EAA0E;AAC1E,MAAM,CAAC,MAAM,qBAAqB,GAAc,GAAG,EAAE,CACnD,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC,CAAC;AAErD,2DAA2D;AAC3D,MAAM,CAAC,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAElD;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,OAA0B;IAItD,MAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,IAAI,IAA2B,CAAC;IAChC,6IAA6I;IAC7I,MAAM,QAAQ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