@mandateops/cli-darwin-arm64 0.0.0-stage → 0.7.2

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.
Files changed (68) hide show
  1. package/LICENSE +55 -0
  2. package/README.md +181 -2
  3. package/audit-lab/README.md +194 -0
  4. package/audit-lab/bin/mandateops +0 -0
  5. package/audit-lab/contracts/contact-plain-text.vectors.json +85 -0
  6. package/audit-lab/contracts/history-reading.md +185 -0
  7. package/audit-lab/contracts/history-reading.vectors.json +284 -0
  8. package/audit-lab/contracts/profiles.md +161 -0
  9. package/audit-lab/contracts/properties.md +512 -0
  10. package/audit-lab/contracts/sdk-config.md +155 -0
  11. package/audit-lab/contracts/system-under-test.md +385 -0
  12. package/audit-lab/contracts/test-provider.md +350 -0
  13. package/audit-lab/lab/compose.audit.yml +181 -0
  14. package/audit-lab/lab/config/fault-control.json +14 -0
  15. package/audit-lab/lab/examples/agents/Dockerfile +28 -0
  16. package/audit-lab/lab/examples/agents/codeloc.cjs +199 -0
  17. package/audit-lab/lab/examples/agents/load.cjs +9 -0
  18. package/audit-lab/lab/examples/agents/package-lock.json +2840 -0
  19. package/audit-lab/lab/examples/agents/package.json +9 -0
  20. package/audit-lab/lab/examples/agents/python/mandateops_codeloc.py +271 -0
  21. package/audit-lab/lab/examples/agents/python/sitecustomize.py +51 -0
  22. package/audit-lab/lab/examples/agents/requirements-python.txt +522 -0
  23. package/audit-lab/lab/examples/agents/telemetry-router.cjs +272 -0
  24. package/audit-lab/lab/examples/test-provider/.dockerignore +4 -0
  25. package/audit-lab/lab/examples/test-provider/Dockerfile +28 -0
  26. package/audit-lab/lab/examples/test-provider/bun.lock +405 -0
  27. package/audit-lab/lab/examples/test-provider/package.json +42 -0
  28. package/audit-lab/lab/examples/test-provider/src/amount.ts +32 -0
  29. package/audit-lab/lab/examples/test-provider/src/app.ts +538 -0
  30. package/audit-lab/lab/examples/test-provider/src/auth.ts +30 -0
  31. package/audit-lab/lab/examples/test-provider/src/barrier.ts +262 -0
  32. package/audit-lab/lab/examples/test-provider/src/codeloc.ts +27 -0
  33. package/audit-lab/lab/examples/test-provider/src/config.ts +311 -0
  34. package/audit-lab/lab/examples/test-provider/src/connect.ts +204 -0
  35. package/audit-lab/lab/examples/test-provider/src/declaration.ts +270 -0
  36. package/audit-lab/lab/examples/test-provider/src/declared.ts +198 -0
  37. package/audit-lab/lab/examples/test-provider/src/domain.ts +193 -0
  38. package/audit-lab/lab/examples/test-provider/src/egress.ts +396 -0
  39. package/audit-lab/lab/examples/test-provider/src/flow.ts +263 -0
  40. package/audit-lab/lab/examples/test-provider/src/gate.ts +301 -0
  41. package/audit-lab/lab/examples/test-provider/src/main.ts +31 -0
  42. package/audit-lab/lab/examples/test-provider/src/notify.ts +157 -0
  43. package/audit-lab/lab/examples/test-provider/src/owner.ts +60 -0
  44. package/audit-lab/lab/examples/test-provider/src/payment.ts +103 -0
  45. package/audit-lab/lab/examples/test-provider/src/profile.ts +417 -0
  46. package/audit-lab/lab/examples/test-provider/src/request.ts +201 -0
  47. package/audit-lab/lab/examples/test-provider/src/rows.ts +173 -0
  48. package/audit-lab/lab/examples/test-provider/src/schema.ts +114 -0
  49. package/audit-lab/lab/examples/test-provider/src/signature.ts +86 -0
  50. package/audit-lab/lab/examples/test-provider/src/staged.ts +318 -0
  51. package/audit-lab/lab/examples/test-provider/src/store.ts +432 -0
  52. package/audit-lab/lab/examples/test-provider/src/traffic.ts +50 -0
  53. package/audit-lab/lab/examples/test-provider/src/webauthn.d.ts +11 -0
  54. package/audit-lab/lab/examples/test-provider/src/wire.ts +153 -0
  55. package/audit-lab/lab/examples/test-provider/tsconfig.build.json +9 -0
  56. package/audit-lab/lab/examples/test-provider/tsconfig.json +24 -0
  57. package/audit-lab/lab/images/capture/Dockerfile +15 -0
  58. package/audit-lab/lab/images/capture/LICENSE +201 -0
  59. package/audit-lab/lab/images/fault-control/Dockerfile +13 -0
  60. package/audit-lab/lab/images/fault-control/LICENSE +21 -0
  61. package/audit-lab/lab/images/provider-store/Dockerfile +4 -0
  62. package/audit-lab/lab/images/provider-store/LICENSE +23 -0
  63. package/audit-lab/lab/images/telemetry/Dockerfile +14 -0
  64. package/audit-lab/lab/images/telemetry/LICENSE +201 -0
  65. package/audit-lab/lab/scripts/compose-down.sh +148 -0
  66. package/audit-lab/lab/scripts/compose-lib.sh +663 -0
  67. package/audit-lab/lab/scripts/compose-up.sh +240 -0
  68. package/package.json +16 -4
@@ -0,0 +1,272 @@
1
+ "use strict";
2
+ // OTLP on both standard ports in either protocol, so a backend's exporter
3
+ // reaches the run's collector whichever port and protocol it was built for.
4
+ // It runs in the collector's network namespace and forwards to the
5
+ // collector's gRPC and HTTP receivers, both bound to loopback.
6
+ //
7
+ // HTTP/1.1 connections go to the HTTP receiver whole. HTTP/2 without TLS
8
+ // (h2c) is terminated here and routed per request: `application/grpc*` to
9
+ // the gRPC receiver, with trailers kept; POST /v1/traces, /v1/metrics or
10
+ // /v1/logs to the HTTP receiver; anything else is refused. Bodies stream
11
+ // with backpressure and a request over MAX_BODY_BYTES is reset.
12
+ // A protocol seen on the other protocol's port is noted once, as a fixed
13
+ // record the CLI turns into a plain diagnostic; nothing else is written.
14
+ const net = require("node:net");
15
+ const http = require("node:http");
16
+ const http2 = require("node:http2");
17
+ const fs = require("node:fs");
18
+ const { Duplex } = require("node:stream");
19
+
20
+ const UPSTREAM = { grpc: 14317, http: 14318 };
21
+ const LISTEN = [
22
+ [4317, "grpc"],
23
+ [4318, "http"],
24
+ ];
25
+ const PREFACE = Buffer.from("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n");
26
+ const OTLP_PATHS = new Set(["/v1/traces", "/v1/metrics", "/v1/logs"]);
27
+ const MAX_BODY_BYTES = 16 * 1024 * 1024;
28
+ const MAX_STREAMS = 100;
29
+ const IDLE_MS = 120_000;
30
+ const HOP_BY_HOP = new Set([
31
+ "connection",
32
+ "keep-alive",
33
+ "proxy-connection",
34
+ "transfer-encoding",
35
+ "upgrade",
36
+ "host",
37
+ "te",
38
+ ]);
39
+
40
+ function noter(file) {
41
+ const noted = new Set();
42
+ return (port, protocol) => {
43
+ const key = `${port}:${protocol}`;
44
+ if (!file || noted.has(key)) return;
45
+ noted.add(key);
46
+ try {
47
+ fs.appendFileSync(file, `${JSON.stringify({ port, protocol })}\n`);
48
+ } catch {
49
+ // A note is explanation only; routing goes on without it.
50
+ }
51
+ };
52
+ }
53
+
54
+ /** The receiver a request on an h2c stream belongs to, or null. */
55
+ function classify(headers) {
56
+ const type = String(headers["content-type"] || "").toLowerCase();
57
+ if (type.startsWith("application/grpc")) return "grpc";
58
+ const path = String(headers[":path"] || "").split("?")[0];
59
+ const otlpType =
60
+ type.startsWith("application/x-protobuf") ||
61
+ type.startsWith("application/json");
62
+ if (headers[":method"] === "POST" && OTLP_PATHS.has(path) && otlpType) {
63
+ return "http";
64
+ }
65
+ return null;
66
+ }
67
+
68
+ /** Pipe `from` to `to`, aborting both once more than the limit has passed. */
69
+ function bounded(from, to, abort, limit) {
70
+ let seen = 0;
71
+ from.on("data", (chunk) => {
72
+ seen += chunk.length;
73
+ if (seen > limit) {
74
+ from.unpipe(to);
75
+ abort();
76
+ }
77
+ });
78
+ from.pipe(to);
79
+ }
80
+
81
+ function plainHeaders(headers) {
82
+ const out = {};
83
+ for (const [name, value] of Object.entries(headers)) {
84
+ if (name.startsWith(":") || HOP_BY_HOP.has(name)) continue;
85
+ out[name] = value;
86
+ }
87
+ return out;
88
+ }
89
+
90
+ function refuse(stream, status) {
91
+ if (stream.destroyed || stream.closed) return;
92
+ try {
93
+ if (!stream.headersSent) stream.respond({ ":status": status }, { endStream: true });
94
+ else stream.close(http2.constants.NGHTTP2_INTERNAL_ERROR);
95
+ } catch {
96
+ stream.destroy();
97
+ }
98
+ }
99
+
100
+ function toGrpc(stream, headers, session, limit) {
101
+ const upstream = session();
102
+ if (!upstream) return refuse(stream, 502);
103
+ const request = upstream.request(
104
+ { ...plainHeaders(headers), ":method": headers[":method"], ":path": headers[":path"], te: "trailers" },
105
+ { waitForTrailers: true },
106
+ );
107
+ const fail = () => {
108
+ request.close(http2.constants.NGHTTP2_CANCEL);
109
+ refuse(stream, 502);
110
+ };
111
+ request.on("error", fail);
112
+ stream.on("error", () => request.close(http2.constants.NGHTTP2_CANCEL));
113
+ stream.on("close", () => request.close(http2.constants.NGHTTP2_CANCEL));
114
+ // The client's trailers, if any, are forwarded before the request ends.
115
+ let clientTrailers = null;
116
+ stream.on("trailers", (trailers) => {
117
+ clientTrailers = plainHeaders(trailers);
118
+ });
119
+ request.on("wantTrailers", () => request.sendTrailers(clientTrailers || {}));
120
+ request.on("response", (reply) => {
121
+ if (stream.destroyed) return;
122
+ let replyTrailers = null;
123
+ request.on("trailers", (trailers) => {
124
+ replyTrailers = plainHeaders(trailers);
125
+ });
126
+ stream.respond(
127
+ { ...plainHeaders(reply), ":status": reply[":status"] },
128
+ { waitForTrailers: true },
129
+ );
130
+ stream.on("wantTrailers", () => stream.sendTrailers(replyTrailers || {}));
131
+ bounded(request, stream, fail, limit);
132
+ });
133
+ bounded(stream, request, fail, limit);
134
+ }
135
+
136
+ function toHttp(stream, headers, port, limit) {
137
+ const request = http.request({
138
+ host: "127.0.0.1",
139
+ port,
140
+ method: headers[":method"],
141
+ path: headers[":path"],
142
+ headers: plainHeaders(headers),
143
+ });
144
+ const fail = () => {
145
+ request.destroy();
146
+ refuse(stream, 502);
147
+ };
148
+ request.on("error", fail);
149
+ stream.on("error", () => request.destroy());
150
+ stream.on("close", () => request.destroy());
151
+ request.on("response", (reply) => {
152
+ if (stream.destroyed) return;
153
+ const out = plainHeaders(reply.headers);
154
+ stream.respond({ ...out, ":status": reply.statusCode });
155
+ reply.on("error", fail);
156
+ bounded(reply, stream, fail, limit);
157
+ });
158
+ bounded(stream, request, fail, limit);
159
+ }
160
+
161
+ /**
162
+ * `client` as a stream that yields `head` first, with backpressure. The
163
+ * HTTP/2 server reads a native socket below JavaScript, where bytes already
164
+ * read could not be handed back, so it is given this stream instead.
165
+ */
166
+ function replay(client, head) {
167
+ const stream = new Duplex({
168
+ read() {
169
+ client.resume();
170
+ },
171
+ write(chunk, encoding, done) {
172
+ client.write(chunk, encoding, done);
173
+ },
174
+ final(done) {
175
+ client.end();
176
+ done();
177
+ },
178
+ destroy(error, done) {
179
+ client.destroy();
180
+ done(error);
181
+ },
182
+ });
183
+ stream.push(head);
184
+ client.on("data", (chunk) => {
185
+ if (!stream.push(chunk)) client.pause();
186
+ });
187
+ client.on("end", () => stream.push(null));
188
+ client.on("close", () => stream.destroy());
189
+ client.resume();
190
+ return stream;
191
+ }
192
+
193
+ function start({
194
+ listen = LISTEN,
195
+ upstream = UPSTREAM,
196
+ notes,
197
+ host = "0.0.0.0",
198
+ maxBodyBytes = MAX_BODY_BYTES,
199
+ } = {}) {
200
+ const note = noter(notes);
201
+ // One shared h2c session to the gRPC receiver, reopened when it ends.
202
+ let grpcSession = null;
203
+ const session = () => {
204
+ if (grpcSession && !grpcSession.closed && !grpcSession.destroyed) return grpcSession;
205
+ try {
206
+ grpcSession = http2.connect(`http://127.0.0.1:${upstream.grpc}`);
207
+ grpcSession.on("error", () => {});
208
+ return grpcSession;
209
+ } catch {
210
+ return null;
211
+ }
212
+ };
213
+
214
+ const servers = listen.map(([port, expected]) => {
215
+ const h2 = http2.createServer({ settings: { maxConcurrentStreams: MAX_STREAMS } });
216
+ // An idle connection is closed; an exporter reconnects when it next sends.
217
+ h2.setTimeout(IDLE_MS);
218
+ h2.on("sessionError", () => {});
219
+ h2.on("stream", (stream, headers) => {
220
+ stream.on("error", () => {});
221
+ const protocol = classify(headers);
222
+ if (!protocol) return refuse(stream, 404);
223
+ if (protocol !== expected) note(port, protocol);
224
+ if (protocol === "grpc") toGrpc(stream, headers, session, maxBodyBytes);
225
+ else toHttp(stream, headers, upstream.http, maxBodyBytes);
226
+ });
227
+
228
+ const server = net.createServer((client) => {
229
+ client.on("error", () => client.destroy());
230
+ let head = Buffer.alloc(0);
231
+ const collect = (chunk) => {
232
+ head = Buffer.concat([head, chunk]);
233
+ const sure =
234
+ head.length >= PREFACE.length ||
235
+ !PREFACE.subarray(0, head.length).equals(head);
236
+ if (!sure) return;
237
+ client.removeListener("data", collect);
238
+ client.pause();
239
+ if (head.subarray(0, PREFACE.length).equals(PREFACE)) {
240
+ h2.emit("connection", replay(client, head));
241
+ return;
242
+ }
243
+ if (expected !== "http") note(port, "http");
244
+ const up = net.connect(upstream.http, "127.0.0.1", () => {
245
+ up.write(head);
246
+ client.pipe(up);
247
+ up.pipe(client);
248
+ client.resume();
249
+ });
250
+ up.on("error", () => client.destroy());
251
+ client.on("close", () => up.destroy());
252
+ };
253
+ client.on("data", collect);
254
+ });
255
+ server.listen(port, host);
256
+ return server;
257
+ });
258
+
259
+ return {
260
+ servers,
261
+ close() {
262
+ if (grpcSession) grpcSession.destroy();
263
+ for (const server of servers) server.close();
264
+ },
265
+ };
266
+ }
267
+
268
+ module.exports = { start, classify };
269
+
270
+ if (require.main === module) {
271
+ start({ notes: process.env.MANDATEOPS_PROTOCOL_NOTES });
272
+ }
@@ -0,0 +1,4 @@
1
+ node_modules/
2
+ dist/
3
+ .env
4
+ Dockerfile
@@ -0,0 +1,28 @@
1
+ # Lab service image. Base pinned by digest; dependencies by lockfile.
2
+ # Twin of examples/ts-payout-backend/Dockerfile, kept separate because the two
3
+ # services deploy and change independently.
4
+ FROM oven/bun:1.4.4-slim@sha256:1846adf22496bd711036aae8be147e57bdebbaea2e5264e3e0b5af1db187d9a4 AS build
5
+ WORKDIR /app
6
+ COPY package.json bun.lock ./
7
+ RUN bun install --frozen-lockfile --ignore-scripts
8
+ COPY tsconfig.json tsconfig.build.json ./
9
+ COPY src ./src
10
+ RUN bun run build
11
+
12
+ # Production dependencies only, installed where a shell exists.
13
+ FROM oven/bun:1.4.4-slim@sha256:1846adf22496bd711036aae8be147e57bdebbaea2e5264e3e0b5af1db187d9a4 AS dependencies
14
+ WORKDIR /app
15
+ COPY package.json bun.lock ./
16
+ RUN bun install --frozen-lockfile --ignore-scripts --production
17
+
18
+ # Distroless runtime: bun and its libraries, no shell or package manager.
19
+ FROM oven/bun:1.4.4-distroless@sha256:153a951ae40106e125898103e6e990ee0f38e6aee7f561029e26cf9fbed23470
20
+ WORKDIR /app
21
+ ENV NODE_ENV=production
22
+ COPY package.json ./
23
+ COPY --from=dependencies /app/node_modules ./node_modules
24
+ COPY --from=build /app/dist ./dist
25
+ USER nonroot
26
+ # The base's bun entrypoint is cleared so commands keep naming bun.
27
+ ENTRYPOINT []
28
+ CMD ["bun", "dist/main.js"]