@effect-agent/testing 0.1.0-beta.74 → 0.1.0-beta.76
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.
|
@@ -285,7 +285,11 @@ const executeInProcess = Effect.fn("InProcessCodeExecutor.execute")(function* (r
|
|
|
285
285
|
}
|
|
286
286
|
Queue.offerUnsafe(queue, pending);
|
|
287
287
|
}));
|
|
288
|
-
const
|
|
288
|
+
const concurrency = request.limits.maxHostCallConcurrency ?? 4;
|
|
289
|
+
const server = yield* Effect.all(Array.from({ length: concurrency }, () => serveHostCalls(host, queue, request.limits, capture, counter)), {
|
|
290
|
+
concurrency,
|
|
291
|
+
discard: true
|
|
292
|
+
}).pipe(Effect.andThen(Effect.never), Effect.forkScoped);
|
|
289
293
|
const program = Effect.tryPromise({
|
|
290
294
|
try: async () => {
|
|
291
295
|
let candidate;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeExecutorSubstitute.mjs","names":[],"sources":["../src/CodeExecutorSubstitute.ts"],"sourcesContent":["import {\n CodeExecutionHost,\n CodeExecutionProtocolError,\n CodeExecutionResourceUse,\n CodeExecutionResult,\n CodeExecutionTimeoutError,\n CodeExecutor,\n type CodeExecutorExecute,\n CodeExecutorUnsupportedError,\n CodeHostCall,\n CodeHostCallLimitError,\n CodeHostCallResult,\n CodeOutputLimitError,\n CodeProgramFailedError,\n CodeSourceError,\n type CodeExecutionLimits,\n type CodeExecutionNamespace,\n type CodeExecutionRequest,\n} from \"@effect-agent/sandbox/CodeExecutor\";\nimport { SandboxImplementation } from \"@effect-agent/sandbox/Sandbox\";\nimport { Clock, Duration, Effect, Fiber, Layer, Option, Queue, Schema } from \"effect\";\n\n/**\n * The deterministic in-process executor substitute (C1 of ADR-0017). It runs\n * the generated program on the host JavaScript engine with best-effort global\n * shadowing only, so it self-identifies as `unisolated` and is never a\n * security boundary (CAP-010, CAP-015). It exists to prove the public\n * `CodeExecutor` contract and to drive deterministic capability tests.\n */\nexport const inProcessCodeExecutorImplementation = SandboxImplementation.make({\n isolation: \"unisolated\",\n identity: \"in-process-javascript\",\n});\n\n// These two caps mirror the wire schema bounds (`BoundedLogs` is at most\n// 4096 lines of at most 16 KiB each): capture must stay inside what\n// `CodeExecutionResult` can carry. A line over the per-line cap is truncated\n// with an explicit `…` marker; exceeding either the byte budget or the line\n// cap fails the pass typed.\nconst MAX_LOG_LINES = 4_096;\nconst MAX_LOG_LINE_CHARACTERS = 16_000;\nconst MAX_THROWN_CHARACTERS = 4_000;\n\nconst utf8ByteLength = (value: string): number => new TextEncoder().encode(value).byteLength;\n\n/**\n * Ambient globals shadowed inside the harness. Shadowing blocks the obvious\n * identifier paths only; a determined program can still escape, which is\n * exactly why this executor reports `unisolated` and the isolated network and\n * CPU enforcement conformance cases run only against isolated adapters.\n */\nconst shadowedGlobals = [\n \"fetch\",\n \"process\",\n \"require\",\n \"module\",\n \"exports\",\n \"global\",\n \"globalThis\",\n \"XMLHttpRequest\",\n \"WebSocket\",\n \"Deno\",\n \"Bun\",\n] as const;\n\nclass LogLimitSignal {\n constructor(readonly observed: number) {}\n}\n\nclass EvaluationThrew {\n constructor(readonly inner: unknown) {}\n}\n\nclass NotAFunction {\n constructor(readonly actual: string) {}\n}\n\ninterface LogCapture {\n readonly lines: Array<string>;\n bytes: number;\n}\n\n/**\n * Total, defect-free rendering of untrusted values: a hostile Proxy can throw\n * from property access, `toString`, and `Symbol.toPrimitive`, and an expected\n * program failure must never escape the typed channel as a defect while its\n * diagnostics are being serialized.\n */\nconst formatLogValue = (value: unknown): string => {\n try {\n if (typeof value === \"string\") {\n return value;\n }\n\n return JSON.stringify(value) ?? String(value);\n } catch {\n try {\n return String(value);\n } catch {\n return \"[unprintable value]\";\n }\n }\n};\n\nconst makeConsole = (capture: LogCapture, limits: CodeExecutionLimits) => {\n const write = (...values: ReadonlyArray<unknown>): void => {\n const joined = values.map(formatLogValue).join(\" \");\n\n const line =\n joined.length > MAX_LOG_LINE_CHARACTERS\n ? `${joined.slice(0, MAX_LOG_LINE_CHARACTERS - 1)}…`\n : joined;\n\n const bytes = utf8ByteLength(line);\n\n if (capture.lines.length >= MAX_LOG_LINES || capture.bytes + bytes > limits.maxLogBytes) {\n throw new LogLimitSignal(capture.bytes + bytes);\n }\n capture.lines.push(line);\n capture.bytes += bytes;\n };\n\n return { debug: write, error: write, info: write, log: write, warn: write };\n};\n\ninterface PendingHostCall {\n readonly namespace: string;\n readonly method: string;\n readonly argument: unknown;\n readonly resolve: (value: unknown) => void;\n readonly reject: (reason: unknown) => void;\n}\n\nconst buildNamespaceObject = (\n namespace: CodeExecutionNamespace,\n offer: (pending: PendingHostCall) => void,\n): Record<string, unknown> => {\n const methods: Record<string, unknown> = {};\n\n for (const method of namespace.methods) {\n methods[method] = (argument: unknown) =>\n new Promise((resolve, reject) => {\n offer({ namespace: namespace.name, method, argument, resolve, reject });\n });\n }\n\n return methods;\n};\n\nconst boundedText = (value: unknown): string => {\n try {\n const text = value instanceof Error ? `${value.name}: ${value.message}` : formatLogValue(value);\n\n return text.slice(0, MAX_THROWN_CHARACTERS);\n } catch {\n return \"[unserializable thrown value]\";\n }\n};\n\n/** Schema decoding of hostile values may itself throw through trap getters. */\nconst safeDecodeJson = (value: unknown): Option.Option<Schema.Json> => {\n try {\n return Schema.decodeUnknownOption(Schema.Json)(value);\n } catch {\n return Option.none();\n }\n};\n\nconst decodeJsonText = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Json));\n\n/** Own serialized result text before bounding and decoding its detached JSON snapshot. */\nconst serializeJson = (value: unknown): Option.Option<string> => {\n const decoded = safeDecodeJson(value);\n\n if (Option.isNone(decoded)) return Option.none();\n try {\n return Option.fromUndefinedOr(JSON.stringify(decoded.value));\n } catch {\n return Option.none();\n }\n};\n\nconst boundedThrown = (value: unknown): Schema.Json => {\n const decoded = safeDecodeJson(value);\n\n if (Option.isSome(decoded)) {\n try {\n const encoded = JSON.stringify(decoded.value);\n\n if (encoded !== undefined && encoded.length <= MAX_THROWN_CHARACTERS) {\n const snapshot = decodeJsonText(encoded);\n\n if (Option.isSome(snapshot)) return snapshot.value;\n }\n } catch {\n // fall through to the bounded string form\n }\n }\n\n return boundedText(value);\n};\n\nconst encodedJsonByteLength = (value: Schema.Json): number | undefined => {\n try {\n const encoded = JSON.stringify(value);\n\n return encoded === undefined ? undefined : utf8ByteLength(encoded);\n } catch {\n return undefined;\n }\n};\n\n/** Host outcomes are protocol input; a hostile value must not defect mid-decode. */\nconst decodeHostOutcome = (value: unknown): Option.Option<CodeHostCallResult> => {\n try {\n return Schema.decodeUnknownOption(CodeHostCallResult)(value);\n } catch {\n return Option.none();\n }\n};\n\nconst validateRequest = (\n request: CodeExecutionRequest,\n): Effect.Effect<void, CodeExecutorUnsupportedError | CodeSourceError> =>\n Effect.gen(function* () {\n if (request.network._tag !== \"NetworkDisabled\") {\n return yield* CodeExecutorUnsupportedError.make({\n implementation: inProcessCodeExecutorImplementation,\n feature: \"network\",\n message:\n \"The unisolated in-process executor cannot enforce an egress allowlist; only NetworkDisabled is accepted, and even that is shadowed rather than enforced\",\n });\n }\n if (request.limits.cpuMillis !== undefined) {\n return yield* CodeExecutorUnsupportedError.make({\n implementation: inProcessCodeExecutorImplementation,\n feature: \"cpu-limit\",\n message:\n \"The unisolated in-process executor shares the host engine and cannot enforce a CPU limit\",\n });\n }\n const reservedNames = new Set<string>([...shadowedGlobals, \"console\"]);\n const seen = new Set<string>();\n\n for (const namespace of request.namespaces) {\n if (reservedNames.has(namespace.name) || seen.has(namespace.name)) {\n return yield* CodeExecutorUnsupportedError.make({\n implementation: inProcessCodeExecutorImplementation,\n feature: \"namespaces\",\n message: `Namespace ${namespace.name} collides with a harness binding or another namespace`,\n });\n }\n seen.add(namespace.name);\n }\n const sourceBytes = utf8ByteLength(request.source);\n\n if (sourceBytes > request.limits.maxSourceBytes) {\n return yield* CodeSourceError.make({\n implementation: inProcessCodeExecutorImplementation,\n reason: \"oversized\",\n message: `Source is ${sourceBytes} bytes; the request allows ${request.limits.maxSourceBytes}`,\n });\n }\n });\n\nconst serveHostCalls = (\n host: CodeExecutionHost[\"Service\"],\n queue: Queue.Queue<PendingHostCall>,\n limits: CodeExecutionLimits,\n capture: LogCapture,\n counter: { calls: number },\n): Effect.Effect<\n never,\n CodeHostCallLimitError | CodeOutputLimitError | CodeExecutionProtocolError\n> =>\n Effect.gen(function* () {\n while (true) {\n const pending = yield* Queue.take(queue);\n\n counter.calls += 1;\n if (counter.calls > limits.maxHostCalls) {\n return yield* CodeHostCallLimitError.make({\n implementation: inProcessCodeExecutorImplementation,\n limit: limits.maxHostCalls,\n logs: [...capture.lines],\n });\n }\n const argument = safeDecodeJson(pending.argument);\n\n if (Option.isNone(argument)) {\n pending.reject(new TypeError(\"host call arguments must be JSON values\"));\n continue;\n }\n const argumentBytes = encodedJsonByteLength(argument.value);\n\n if (argumentBytes === undefined || argumentBytes > limits.maxHostCallArgumentBytes) {\n return yield* CodeOutputLimitError.make({\n implementation: inProcessCodeExecutorImplementation,\n surface: \"host-call-argument\",\n limit: limits.maxHostCallArgumentBytes,\n observed: argumentBytes ?? 0,\n logs: [...capture.lines],\n });\n }\n\n const rawOutcome = yield* host.call(\n CodeHostCall.make({\n namespace: pending.namespace,\n method: pending.method,\n argument: argument.value,\n }),\n );\n\n const outcome = decodeHostOutcome(rawOutcome);\n\n if (Option.isNone(outcome)) {\n return yield* CodeExecutionProtocolError.make({\n implementation: inProcessCodeExecutorImplementation,\n message: \"The execution host returned a value outside the CodeHostCallResult schema\",\n });\n }\n if (outcome.value._tag === \"CodeHostCallFailure\") {\n pending.reject(outcome.value.error);\n continue;\n }\n const resultBytes = encodedJsonByteLength(outcome.value.value);\n\n if (resultBytes === undefined || resultBytes > limits.maxHostCallResultBytes) {\n return yield* CodeOutputLimitError.make({\n implementation: inProcessCodeExecutorImplementation,\n surface: \"host-call-result\",\n limit: limits.maxHostCallResultBytes,\n observed: resultBytes ?? 0,\n logs: [...capture.lines],\n });\n }\n pending.resolve(outcome.value.value);\n }\n });\n\nconst classifyProgramFailure = (\n thrown: unknown,\n limits: CodeExecutionLimits,\n capture: LogCapture,\n): CodeOutputLimitError | CodeSourceError | CodeProgramFailedError => {\n let inner = thrown;\n let reason: \"threw\" | \"rejected\" = \"rejected\";\n\n try {\n const evaluationThrew = thrown instanceof EvaluationThrew;\n\n inner = evaluationThrew ? thrown.inner : thrown;\n if (inner instanceof LogLimitSignal) {\n return CodeOutputLimitError.make({\n implementation: inProcessCodeExecutorImplementation,\n surface: \"logs\",\n limit: limits.maxLogBytes,\n observed: inner.observed,\n logs: [...capture.lines],\n });\n }\n if (inner instanceof NotAFunction) {\n return CodeSourceError.make({\n implementation: inProcessCodeExecutorImplementation,\n reason: \"not-a-function\",\n message: `The source expression evaluated to ${inner.actual}; it must evaluate to one async function`,\n });\n }\n // Async body throws become rejections: exception-like values read as `threw`,\n // while plain values such as uncaught host failure envelopes read as `rejected`.\n reason = evaluationThrew || inner instanceof Error ? \"threw\" : \"rejected\";\n } catch {\n // A program-owned Proxy can throw from instanceof's prototype lookup. Keep\n // that failure inside the same guarded diagnostic boundary as its value.\n }\n\n return CodeProgramFailedError.make({\n implementation: inProcessCodeExecutorImplementation,\n reason,\n thrown: boundedThrown(inner),\n message: boundedText(inner),\n logs: [...capture.lines],\n });\n};\n\nconst executeInProcess: CodeExecutorExecute = Effect.fn(\"InProcessCodeExecutor.execute\")(\n function* (request) {\n yield* validateRequest(request);\n const host = yield* CodeExecutionHost;\n const capture: LogCapture = { lines: [], bytes: 0 };\n const counter = { calls: 0 };\n const queue = yield* Queue.unbounded<PendingHostCall>();\n\n const factory = yield* Effect.try({\n try: () =>\n // This substitute intentionally evaluates authored test programs in-process and reports\n // an `unisolated` posture. Real adapters own the security boundary and never use this path.\n // oxlint-disable-next-line typescript/no-implied-eval\n new Function(\n ...shadowedGlobals,\n \"console\",\n ...request.namespaces.map((namespace) => namespace.name),\n `\"use strict\";\\nreturn (\\n${request.source}\\n);`,\n ),\n catch: (cause) =>\n CodeSourceError.make({\n implementation: inProcessCodeExecutorImplementation,\n reason: \"invalid\",\n message: boundedText(cause),\n }),\n });\n\n const harnessConsole = makeConsole(capture, request.limits);\n // Admission is enforced at call creation, not only at the single-consumer\n // dequeue: a burst of unawaited calls can enqueue at most one entry past\n // the cap (the entry the server fails the pass on); everything beyond is\n // rejected synchronously, so the queue stays bounded against hostile\n // programs.\n let issuedHostCalls = 0;\n\n const namespaceObjects = request.namespaces.map((namespace) =>\n buildNamespaceObject(namespace, (pending) => {\n issuedHostCalls += 1;\n if (issuedHostCalls > request.limits.maxHostCalls + 1) {\n pending.reject(new Error(`host-call limit of ${request.limits.maxHostCalls} exceeded`));\n\n return;\n }\n Queue.offerUnsafe(queue, pending);\n }),\n );\n\n const server = yield* serveHostCalls(host, queue, request.limits, capture, counter).pipe(\n Effect.forkScoped,\n );\n\n const program = Effect.tryPromise({\n try: async () => {\n let candidate: unknown;\n\n try {\n candidate = factory(\n ...shadowedGlobals.map(() => undefined),\n harnessConsole,\n ...namespaceObjects,\n );\n } catch (cause) {\n throw new EvaluationThrew(cause);\n }\n if (typeof candidate !== \"function\") {\n throw new EvaluationThrew(new NotAFunction(typeof candidate));\n }\n let outcome: unknown;\n\n try {\n outcome = candidate();\n } catch (cause) {\n throw new EvaluationThrew(cause);\n }\n\n return await Promise.resolve(outcome);\n },\n catch: (thrown) => classifyProgramFailure(thrown, request.limits, capture),\n });\n\n const startedAt = yield* Clock.currentTimeMillis;\n\n // The wall-clock deadline interrupts only at asynchronous suspension\n // points: a synchronous runaway shares the host thread and cannot be\n // stopped in-process — exactly why the platform CPU enforcement cases\n // belong to isolated adapters only (testing spec §8.1). The server fiber\n // is interrupted when the pass settles so no host call outlives the\n // program that issued it.\n const returned = yield* Effect.raceFirst(program, Fiber.join(server)).pipe(\n Effect.timeoutOrElse({\n duration: request.limits.maxWallTime,\n orElse: () =>\n CodeExecutionTimeoutError.make({\n implementation: inProcessCodeExecutorImplementation,\n kind: \"wall-clock\",\n maxWallTime: request.limits.maxWallTime,\n logs: [...capture.lines],\n }),\n }),\n Effect.ensuring(Fiber.interrupt(server)),\n );\n\n const finishedAt = yield* Clock.currentTimeMillis;\n\n // An unawaited burst can outrun the server: the program may return before\n // the over-limit entry is dequeued, so the admission counter is the\n // authority — a pass that ISSUED more calls than the cap fails even when\n // its promise settled first.\n if (issuedHostCalls > request.limits.maxHostCalls) {\n return yield* CodeHostCallLimitError.make({\n implementation: inProcessCodeExecutorImplementation,\n limit: request.limits.maxHostCalls,\n logs: [...capture.lines],\n });\n }\n\n const nonJsonResult = () =>\n CodeProgramFailedError.make({\n implementation: inProcessCodeExecutorImplementation,\n reason: \"non-json-result\",\n thrown: null,\n message: \"The program must return a JSON value\",\n logs: [...capture.lines],\n });\n\n const encoded = serializeJson(returned);\n\n if (Option.isNone(encoded)) return yield* nonJsonResult();\n const resultBytes = utf8ByteLength(encoded.value);\n\n if (resultBytes > request.limits.maxResultBytes) {\n return yield* CodeOutputLimitError.make({\n implementation: inProcessCodeExecutorImplementation,\n surface: \"result\",\n limit: request.limits.maxResultBytes,\n observed: resultBytes,\n logs: [...capture.lines],\n });\n }\n const decoded = decodeJsonText(encoded.value);\n\n if (Option.isNone(decoded)) return yield* nonJsonResult();\n\n return CodeExecutionResult.make({\n implementation: inProcessCodeExecutorImplementation,\n value: decoded.value,\n logs: [...capture.lines],\n resourceUse: CodeExecutionResourceUse.make({\n wallTime: Duration.millis(Math.max(0, finishedAt - startedAt)),\n hostCalls: counter.calls,\n logBytes: capture.bytes,\n resultBytes,\n }),\n });\n },\n);\n\n/**\n * Layer providing the unisolated in-process `CodeExecutor` substitute. The\n * per-pass `CodeExecutionHost` stays in the caller's requirement channel, the\n * same as every real adapter.\n */\nexport const inProcessCodeExecutorLayer: Layer.Layer<CodeExecutor> = Layer.succeed(CodeExecutor)(\n CodeExecutor.of({ execute: executeInProcess }),\n);\n"],"mappings":";;;;;;;;;;;AA6BA,MAAa,sCAAsC,sBAAsB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C,GAAG,QAAQ,KAAK;CACzB,CAAC;CAGH,MAAM,sBACJ,uBAAuB,KAAK;EAC1B,gBAAgB;EAChB,QAAQ;EACR,QAAQ;EACR,SAAS;EACT,MAAM,CAAC,GAAG,QAAQ,KAAK;CACzB,CAAC;CAEH,MAAM,UAAU,cAAc,QAAQ;CAEtC,IAAI,OAAO,OAAO,OAAO,GAAG,OAAO,OAAO,cAAc;CACxD,MAAM,cAAc,eAAe,QAAQ,KAAK;CAEhD,IAAI,cAAc,QAAQ,OAAO,gBAC/B,OAAO,OAAO,qBAAqB,KAAK;EACtC,gBAAgB;EAChB,SAAS;EACT,OAAO,QAAQ,OAAO;EACtB,UAAU;EACV,MAAM,CAAC,GAAG,QAAQ,KAAK;CACzB,CAAC;CAEH,MAAM,UAAU,eAAe,QAAQ,KAAK;CAE5C,IAAI,OAAO,OAAO,OAAO,GAAG,OAAO,OAAO,cAAc;CAExD,OAAO,oBAAoB,KAAK;EAC9B,gBAAgB;EAChB,OAAO,QAAQ;EACf,MAAM,CAAC,GAAG,QAAQ,KAAK;EACvB,aAAa,yBAAyB,KAAK;GACzC,UAAU,SAAS,OAAO,KAAK,IAAI,GAAG,aAAa,SAAS,CAAC;GAC7D,WAAW,QAAQ;GACnB,UAAU,QAAQ;GAClB;EACF,CAAC;CACH,CAAC;AACH,CACF;;;;;;AAOA,MAAa,6BAAwD,MAAM,QAAQ,YAAY,CAAC,CAC9F,aAAa,GAAG,EAAE,SAAS,iBAAiB,CAAC,CAC/C"}
|
|
1
|
+
{"version":3,"file":"CodeExecutorSubstitute.mjs","names":[],"sources":["../src/CodeExecutorSubstitute.ts"],"sourcesContent":["import {\n CodeExecutionHost,\n CodeExecutionProtocolError,\n CodeExecutionResourceUse,\n CodeExecutionResult,\n CodeExecutionTimeoutError,\n CodeExecutor,\n type CodeExecutorExecute,\n CodeExecutorUnsupportedError,\n CodeHostCall,\n CodeHostCallLimitError,\n CodeHostCallResult,\n CodeOutputLimitError,\n CodeProgramFailedError,\n CodeSourceError,\n type CodeExecutionLimits,\n type CodeExecutionNamespace,\n type CodeExecutionRequest,\n} from \"@effect-agent/sandbox/CodeExecutor\";\nimport { SandboxImplementation } from \"@effect-agent/sandbox/Sandbox\";\nimport { Clock, Duration, Effect, Fiber, Layer, Option, Queue, Schema } from \"effect\";\n\n/**\n * The deterministic in-process executor substitute (C1 of ADR-0017). It runs\n * the generated program on the host JavaScript engine with best-effort global\n * shadowing only, so it self-identifies as `unisolated` and is never a\n * security boundary (CAP-010, CAP-015). It exists to prove the public\n * `CodeExecutor` contract and to drive deterministic capability tests.\n */\nexport const inProcessCodeExecutorImplementation = SandboxImplementation.make({\n isolation: \"unisolated\",\n identity: \"in-process-javascript\",\n});\n\n// These two caps mirror the wire schema bounds (`BoundedLogs` is at most\n// 4096 lines of at most 16 KiB each): capture must stay inside what\n// `CodeExecutionResult` can carry. A line over the per-line cap is truncated\n// with an explicit `…` marker; exceeding either the byte budget or the line\n// cap fails the pass typed.\nconst MAX_LOG_LINES = 4_096;\nconst MAX_LOG_LINE_CHARACTERS = 16_000;\nconst MAX_THROWN_CHARACTERS = 4_000;\n\nconst utf8ByteLength = (value: string): number => new TextEncoder().encode(value).byteLength;\n\n/**\n * Ambient globals shadowed inside the harness. Shadowing blocks the obvious\n * identifier paths only; a determined program can still escape, which is\n * exactly why this executor reports `unisolated` and the isolated network and\n * CPU enforcement conformance cases run only against isolated adapters.\n */\nconst shadowedGlobals = [\n \"fetch\",\n \"process\",\n \"require\",\n \"module\",\n \"exports\",\n \"global\",\n \"globalThis\",\n \"XMLHttpRequest\",\n \"WebSocket\",\n \"Deno\",\n \"Bun\",\n] as const;\n\nclass LogLimitSignal {\n constructor(readonly observed: number) {}\n}\n\nclass EvaluationThrew {\n constructor(readonly inner: unknown) {}\n}\n\nclass NotAFunction {\n constructor(readonly actual: string) {}\n}\n\ninterface LogCapture {\n readonly lines: Array<string>;\n bytes: number;\n}\n\n/**\n * Total, defect-free rendering of untrusted values: a hostile Proxy can throw\n * from property access, `toString`, and `Symbol.toPrimitive`, and an expected\n * program failure must never escape the typed channel as a defect while its\n * diagnostics are being serialized.\n */\nconst formatLogValue = (value: unknown): string => {\n try {\n if (typeof value === \"string\") {\n return value;\n }\n\n return JSON.stringify(value) ?? String(value);\n } catch {\n try {\n return String(value);\n } catch {\n return \"[unprintable value]\";\n }\n }\n};\n\nconst makeConsole = (capture: LogCapture, limits: CodeExecutionLimits) => {\n const write = (...values: ReadonlyArray<unknown>): void => {\n const joined = values.map(formatLogValue).join(\" \");\n\n const line =\n joined.length > MAX_LOG_LINE_CHARACTERS\n ? `${joined.slice(0, MAX_LOG_LINE_CHARACTERS - 1)}…`\n : joined;\n\n const bytes = utf8ByteLength(line);\n\n if (capture.lines.length >= MAX_LOG_LINES || capture.bytes + bytes > limits.maxLogBytes) {\n throw new LogLimitSignal(capture.bytes + bytes);\n }\n capture.lines.push(line);\n capture.bytes += bytes;\n };\n\n return { debug: write, error: write, info: write, log: write, warn: write };\n};\n\ninterface PendingHostCall {\n readonly namespace: string;\n readonly method: string;\n readonly argument: unknown;\n readonly resolve: (value: unknown) => void;\n readonly reject: (reason: unknown) => void;\n}\n\nconst buildNamespaceObject = (\n namespace: CodeExecutionNamespace,\n offer: (pending: PendingHostCall) => void,\n): Record<string, unknown> => {\n const methods: Record<string, unknown> = {};\n\n for (const method of namespace.methods) {\n methods[method] = (argument: unknown) =>\n new Promise((resolve, reject) => {\n offer({ namespace: namespace.name, method, argument, resolve, reject });\n });\n }\n\n return methods;\n};\n\nconst boundedText = (value: unknown): string => {\n try {\n const text = value instanceof Error ? `${value.name}: ${value.message}` : formatLogValue(value);\n\n return text.slice(0, MAX_THROWN_CHARACTERS);\n } catch {\n return \"[unserializable thrown value]\";\n }\n};\n\n/** Schema decoding of hostile values may itself throw through trap getters. */\nconst safeDecodeJson = (value: unknown): Option.Option<Schema.Json> => {\n try {\n return Schema.decodeUnknownOption(Schema.Json)(value);\n } catch {\n return Option.none();\n }\n};\n\nconst decodeJsonText = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Json));\n\n/** Own serialized result text before bounding and decoding its detached JSON snapshot. */\nconst serializeJson = (value: unknown): Option.Option<string> => {\n const decoded = safeDecodeJson(value);\n\n if (Option.isNone(decoded)) return Option.none();\n try {\n return Option.fromUndefinedOr(JSON.stringify(decoded.value));\n } catch {\n return Option.none();\n }\n};\n\nconst boundedThrown = (value: unknown): Schema.Json => {\n const decoded = safeDecodeJson(value);\n\n if (Option.isSome(decoded)) {\n try {\n const encoded = JSON.stringify(decoded.value);\n\n if (encoded !== undefined && encoded.length <= MAX_THROWN_CHARACTERS) {\n const snapshot = decodeJsonText(encoded);\n\n if (Option.isSome(snapshot)) return snapshot.value;\n }\n } catch {\n // fall through to the bounded string form\n }\n }\n\n return boundedText(value);\n};\n\nconst encodedJsonByteLength = (value: Schema.Json): number | undefined => {\n try {\n const encoded = JSON.stringify(value);\n\n return encoded === undefined ? undefined : utf8ByteLength(encoded);\n } catch {\n return undefined;\n }\n};\n\n/** Host outcomes are protocol input; a hostile value must not defect mid-decode. */\nconst decodeHostOutcome = (value: unknown): Option.Option<CodeHostCallResult> => {\n try {\n return Schema.decodeUnknownOption(CodeHostCallResult)(value);\n } catch {\n return Option.none();\n }\n};\n\nconst validateRequest = (\n request: CodeExecutionRequest,\n): Effect.Effect<void, CodeExecutorUnsupportedError | CodeSourceError> =>\n Effect.gen(function* () {\n if (request.network._tag !== \"NetworkDisabled\") {\n return yield* CodeExecutorUnsupportedError.make({\n implementation: inProcessCodeExecutorImplementation,\n feature: \"network\",\n message:\n \"The unisolated in-process executor cannot enforce an egress allowlist; only NetworkDisabled is accepted, and even that is shadowed rather than enforced\",\n });\n }\n if (request.limits.cpuMillis !== undefined) {\n return yield* CodeExecutorUnsupportedError.make({\n implementation: inProcessCodeExecutorImplementation,\n feature: \"cpu-limit\",\n message:\n \"The unisolated in-process executor shares the host engine and cannot enforce a CPU limit\",\n });\n }\n const reservedNames = new Set<string>([...shadowedGlobals, \"console\"]);\n const seen = new Set<string>();\n\n for (const namespace of request.namespaces) {\n if (reservedNames.has(namespace.name) || seen.has(namespace.name)) {\n return yield* CodeExecutorUnsupportedError.make({\n implementation: inProcessCodeExecutorImplementation,\n feature: \"namespaces\",\n message: `Namespace ${namespace.name} collides with a harness binding or another namespace`,\n });\n }\n seen.add(namespace.name);\n }\n const sourceBytes = utf8ByteLength(request.source);\n\n if (sourceBytes > request.limits.maxSourceBytes) {\n return yield* CodeSourceError.make({\n implementation: inProcessCodeExecutorImplementation,\n reason: \"oversized\",\n message: `Source is ${sourceBytes} bytes; the request allows ${request.limits.maxSourceBytes}`,\n });\n }\n });\n\nconst serveHostCalls = (\n host: CodeExecutionHost[\"Service\"],\n queue: Queue.Queue<PendingHostCall>,\n limits: CodeExecutionLimits,\n capture: LogCapture,\n counter: { calls: number },\n): Effect.Effect<\n never,\n CodeHostCallLimitError | CodeOutputLimitError | CodeExecutionProtocolError\n> =>\n Effect.gen(function* () {\n while (true) {\n const pending = yield* Queue.take(queue);\n\n counter.calls += 1;\n if (counter.calls > limits.maxHostCalls) {\n return yield* CodeHostCallLimitError.make({\n implementation: inProcessCodeExecutorImplementation,\n limit: limits.maxHostCalls,\n logs: [...capture.lines],\n });\n }\n const argument = safeDecodeJson(pending.argument);\n\n if (Option.isNone(argument)) {\n pending.reject(new TypeError(\"host call arguments must be JSON values\"));\n continue;\n }\n const argumentBytes = encodedJsonByteLength(argument.value);\n\n if (argumentBytes === undefined || argumentBytes > limits.maxHostCallArgumentBytes) {\n return yield* CodeOutputLimitError.make({\n implementation: inProcessCodeExecutorImplementation,\n surface: \"host-call-argument\",\n limit: limits.maxHostCallArgumentBytes,\n observed: argumentBytes ?? 0,\n logs: [...capture.lines],\n });\n }\n\n const rawOutcome = yield* host.call(\n CodeHostCall.make({\n namespace: pending.namespace,\n method: pending.method,\n argument: argument.value,\n }),\n );\n\n const outcome = decodeHostOutcome(rawOutcome);\n\n if (Option.isNone(outcome)) {\n return yield* CodeExecutionProtocolError.make({\n implementation: inProcessCodeExecutorImplementation,\n message: \"The execution host returned a value outside the CodeHostCallResult schema\",\n });\n }\n if (outcome.value._tag === \"CodeHostCallFailure\") {\n pending.reject(outcome.value.error);\n continue;\n }\n const resultBytes = encodedJsonByteLength(outcome.value.value);\n\n if (resultBytes === undefined || resultBytes > limits.maxHostCallResultBytes) {\n return yield* CodeOutputLimitError.make({\n implementation: inProcessCodeExecutorImplementation,\n surface: \"host-call-result\",\n limit: limits.maxHostCallResultBytes,\n observed: resultBytes ?? 0,\n logs: [...capture.lines],\n });\n }\n pending.resolve(outcome.value.value);\n }\n });\n\nconst classifyProgramFailure = (\n thrown: unknown,\n limits: CodeExecutionLimits,\n capture: LogCapture,\n): CodeOutputLimitError | CodeSourceError | CodeProgramFailedError => {\n let inner = thrown;\n let reason: \"threw\" | \"rejected\" = \"rejected\";\n\n try {\n const evaluationThrew = thrown instanceof EvaluationThrew;\n\n inner = evaluationThrew ? thrown.inner : thrown;\n if (inner instanceof LogLimitSignal) {\n return CodeOutputLimitError.make({\n implementation: inProcessCodeExecutorImplementation,\n surface: \"logs\",\n limit: limits.maxLogBytes,\n observed: inner.observed,\n logs: [...capture.lines],\n });\n }\n if (inner instanceof NotAFunction) {\n return CodeSourceError.make({\n implementation: inProcessCodeExecutorImplementation,\n reason: \"not-a-function\",\n message: `The source expression evaluated to ${inner.actual}; it must evaluate to one async function`,\n });\n }\n // Async body throws become rejections: exception-like values read as `threw`,\n // while plain values such as uncaught host failure envelopes read as `rejected`.\n reason = evaluationThrew || inner instanceof Error ? \"threw\" : \"rejected\";\n } catch {\n // A program-owned Proxy can throw from instanceof's prototype lookup. Keep\n // that failure inside the same guarded diagnostic boundary as its value.\n }\n\n return CodeProgramFailedError.make({\n implementation: inProcessCodeExecutorImplementation,\n reason,\n thrown: boundedThrown(inner),\n message: boundedText(inner),\n logs: [...capture.lines],\n });\n};\n\nconst executeInProcess: CodeExecutorExecute = Effect.fn(\"InProcessCodeExecutor.execute\")(\n function* (request) {\n yield* validateRequest(request);\n const host = yield* CodeExecutionHost;\n const capture: LogCapture = { lines: [], bytes: 0 };\n const counter = { calls: 0 };\n const queue = yield* Queue.unbounded<PendingHostCall>();\n\n const factory = yield* Effect.try({\n try: () =>\n // This substitute intentionally evaluates authored test programs in-process and reports\n // an `unisolated` posture. Real adapters own the security boundary and never use this path.\n // oxlint-disable-next-line typescript/no-implied-eval\n new Function(\n ...shadowedGlobals,\n \"console\",\n ...request.namespaces.map((namespace) => namespace.name),\n `\"use strict\";\\nreturn (\\n${request.source}\\n);`,\n ),\n catch: (cause) =>\n CodeSourceError.make({\n implementation: inProcessCodeExecutorImplementation,\n reason: \"invalid\",\n message: boundedText(cause),\n }),\n });\n\n const harnessConsole = makeConsole(capture, request.limits);\n // Admission is enforced at call creation, not only at the single-consumer\n // dequeue: a burst of unawaited calls can enqueue at most one entry past\n // the cap (the entry the server fails the pass on); everything beyond is\n // rejected synchronously, so the queue stays bounded against hostile\n // programs.\n let issuedHostCalls = 0;\n\n const namespaceObjects = request.namespaces.map((namespace) =>\n buildNamespaceObject(namespace, (pending) => {\n issuedHostCalls += 1;\n if (issuedHostCalls > request.limits.maxHostCalls + 1) {\n pending.reject(new Error(`host-call limit of ${request.limits.maxHostCalls} exceeded`));\n\n return;\n }\n Queue.offerUnsafe(queue, pending);\n }),\n );\n\n const concurrency = request.limits.maxHostCallConcurrency ?? 4;\n\n const server = yield* Effect.all(\n Array.from({ length: concurrency }, () =>\n serveHostCalls(host, queue, request.limits, capture, counter),\n ),\n { concurrency, discard: true },\n ).pipe(Effect.andThen(Effect.never), Effect.forkScoped);\n\n const program = Effect.tryPromise({\n try: async () => {\n let candidate: unknown;\n\n try {\n candidate = factory(\n ...shadowedGlobals.map(() => undefined),\n harnessConsole,\n ...namespaceObjects,\n );\n } catch (cause) {\n throw new EvaluationThrew(cause);\n }\n if (typeof candidate !== \"function\") {\n throw new EvaluationThrew(new NotAFunction(typeof candidate));\n }\n let outcome: unknown;\n\n try {\n outcome = candidate();\n } catch (cause) {\n throw new EvaluationThrew(cause);\n }\n\n return await Promise.resolve(outcome);\n },\n catch: (thrown) => classifyProgramFailure(thrown, request.limits, capture),\n });\n\n const startedAt = yield* Clock.currentTimeMillis;\n\n // The wall-clock deadline interrupts only at asynchronous suspension\n // points: a synchronous runaway shares the host thread and cannot be\n // stopped in-process — exactly why the platform CPU enforcement cases\n // belong to isolated adapters only (testing spec §8.1). The server fiber\n // is interrupted when the pass settles so no host call outlives the\n // program that issued it.\n const returned = yield* Effect.raceFirst(program, Fiber.join(server)).pipe(\n Effect.timeoutOrElse({\n duration: request.limits.maxWallTime,\n orElse: () =>\n CodeExecutionTimeoutError.make({\n implementation: inProcessCodeExecutorImplementation,\n kind: \"wall-clock\",\n maxWallTime: request.limits.maxWallTime,\n logs: [...capture.lines],\n }),\n }),\n Effect.ensuring(Fiber.interrupt(server)),\n );\n\n const finishedAt = yield* Clock.currentTimeMillis;\n\n // An unawaited burst can outrun the server: the program may return before\n // the over-limit entry is dequeued, so the admission counter is the\n // authority — a pass that ISSUED more calls than the cap fails even when\n // its promise settled first.\n if (issuedHostCalls > request.limits.maxHostCalls) {\n return yield* CodeHostCallLimitError.make({\n implementation: inProcessCodeExecutorImplementation,\n limit: request.limits.maxHostCalls,\n logs: [...capture.lines],\n });\n }\n\n const nonJsonResult = () =>\n CodeProgramFailedError.make({\n implementation: inProcessCodeExecutorImplementation,\n reason: \"non-json-result\",\n thrown: null,\n message: \"The program must return a JSON value\",\n logs: [...capture.lines],\n });\n\n const encoded = serializeJson(returned);\n\n if (Option.isNone(encoded)) return yield* nonJsonResult();\n const resultBytes = utf8ByteLength(encoded.value);\n\n if (resultBytes > request.limits.maxResultBytes) {\n return yield* CodeOutputLimitError.make({\n implementation: inProcessCodeExecutorImplementation,\n surface: \"result\",\n limit: request.limits.maxResultBytes,\n observed: resultBytes,\n logs: [...capture.lines],\n });\n }\n const decoded = decodeJsonText(encoded.value);\n\n if (Option.isNone(decoded)) return yield* nonJsonResult();\n\n return CodeExecutionResult.make({\n implementation: inProcessCodeExecutorImplementation,\n value: decoded.value,\n logs: [...capture.lines],\n resourceUse: CodeExecutionResourceUse.make({\n wallTime: Duration.millis(Math.max(0, finishedAt - startedAt)),\n hostCalls: counter.calls,\n logBytes: capture.bytes,\n resultBytes,\n }),\n });\n },\n);\n\n/**\n * Layer providing the unisolated in-process `CodeExecutor` substitute. The\n * per-pass `CodeExecutionHost` stays in the caller's requirement channel, the\n * same as every real adapter.\n */\nexport const inProcessCodeExecutorLayer: Layer.Layer<CodeExecutor> = Layer.succeed(CodeExecutor)(\n CodeExecutor.of({ execute: executeInProcess }),\n);\n"],"mappings":";;;;;;;;;;;AA6BA,MAAa,sCAAsC,sBAAsB,KAAK;CAC5E,WAAW;CACX,UAAU;AACZ,CAAC;AAOD,MAAM,gBAAgB;AACtB,MAAM,0BAA0B;AAChC,MAAM,wBAAwB;AAE9B,MAAM,kBAAkB,UAA0B,IAAI,YAAY,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC;;;;;;;AAQlF,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,IAAM,iBAAN,MAAqB;CACE;CAArB,YAAY,UAA2B;EAAlB,KAAA,WAAA;CAAmB;AAC1C;AAEA,IAAM,kBAAN,MAAsB;CACC;CAArB,YAAY,OAAyB;EAAhB,KAAA,QAAA;CAAiB;AACxC;AAEA,IAAM,eAAN,MAAmB;CACI;CAArB,YAAY,QAAyB;EAAhB,KAAA,SAAA;CAAiB;AACxC;;;;;;;AAaA,MAAM,kBAAkB,UAA2B;CACjD,IAAI;EACF,IAAI,OAAO,UAAU,UACnB,OAAO;EAGT,OAAO,KAAK,UAAU,KAAK,KAAK,OAAO,KAAK;CAC9C,QAAQ;EACN,IAAI;GACF,OAAO,OAAO,KAAK;EACrB,QAAQ;GACN,OAAO;EACT;CACF;AACF;AAEA,MAAM,eAAe,SAAqB,WAAgC;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AAgB;EAChB,OAAO,QAAQ;EACf,MAAM,CAAC,GAAG,QAAQ,KAAK;EACvB,aAAa,yBAAyB,KAAK;GACzC,UAAU,SAAS,OAAO,KAAK,IAAI,GAAG,aAAa,SAAS,CAAC;GAC7D,WAAW,QAAQ;GACnB,UAAU,QAAQ;GAClB;EACF,CAAC;CACH,CAAC;AACH,CACF;;;;;;AAOA,MAAa,6BAAwD,MAAM,QAAQ,YAAY,CAAC,CAC9F,aAAa,GAAG,EAAE,SAAS,iBAAiB,CAAC,CAC/C"}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@effect-agent/testing","version":"0.1.0-beta.
|
|
1
|
+
{"name":"@effect-agent/testing","version":"0.1.0-beta.76","dependencies":{"@effect-agent/capabilities":"0.1.0-beta.76","@effect-agent/core":"0.1.0-beta.76","@effect-agent/engine":"0.1.0-beta.76","@effect-agent/sandbox":"0.1.0-beta.76","@effect-agent/thread":"0.1.0-beta.76"},"devDependencies":{"@effect-agent/platform-node":"0.1.0-beta.76","@effect-agent/storage-memory":"0.1.0-beta.76","@effect-agent/storage-sqlite":"0.1.0-beta.76","@effect/platform-node":"4.0.0-rc.112","@effect/sql-sqlite-node":"4.0.0-rc.112","@effect/vitest":"4.0.0-rc.112","effect":"4.0.0-rc.112","typescript":"7.0.2","vite-plus":"0.3.0"},"peerDependencies":{"effect":"^4.0.0-rc.112"},"exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./Certification":{"types":"./dist/Certification.d.mts","default":"./dist/Certification.mjs"},"./Chaos":{"types":"./dist/Chaos.d.mts","default":"./dist/Chaos.mjs"},"./CodeExecutorConformance":{"types":"./dist/CodeExecutorConformance.d.mts","default":"./dist/CodeExecutorConformance.mjs"},"./CodeExecutorSubstitute":{"types":"./dist/CodeExecutorSubstitute.d.mts","default":"./dist/CodeExecutorSubstitute.mjs"},"./DocsResearcher":{"types":"./dist/DocsResearcher.d.mts","default":"./dist/DocsResearcher.mjs"},"./ScriptedModel":{"types":"./dist/ScriptedModel.d.mts","default":"./dist/ScriptedModel.mjs"},"./TravelPlanner":{"types":"./dist/TravelPlanner.d.mts","default":"./dist/TravelPlanner.mjs"}},"description":"Scripted models, deterministic fixtures, and adapter conformance kits for testing Effect Agent applications.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/danieljvdm/effect-agent.git","directory":"packages/testing"},"files":["dist","src"],"type":"module","sideEffects":[],"publishConfig":{"access":"public"},"scripts":{"build":"vp pack","check":"tsc --noEmit -p tsconfig.json","test":"vp test --passWithNoTests"}}
|
|
@@ -430,9 +430,14 @@ const executeInProcess: CodeExecutorExecute = Effect.fn("InProcessCodeExecutor.e
|
|
|
430
430
|
}),
|
|
431
431
|
);
|
|
432
432
|
|
|
433
|
-
const
|
|
434
|
-
|
|
435
|
-
|
|
433
|
+
const concurrency = request.limits.maxHostCallConcurrency ?? 4;
|
|
434
|
+
|
|
435
|
+
const server = yield* Effect.all(
|
|
436
|
+
Array.from({ length: concurrency }, () =>
|
|
437
|
+
serveHostCalls(host, queue, request.limits, capture, counter),
|
|
438
|
+
),
|
|
439
|
+
{ concurrency, discard: true },
|
|
440
|
+
).pipe(Effect.andThen(Effect.never), Effect.forkScoped);
|
|
436
441
|
|
|
437
442
|
const program = Effect.tryPromise({
|
|
438
443
|
try: async () => {
|