@finalai/agent-provider 0.8.0 → 0.10.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/HOSTING.md +334 -245
- package/README.md +93 -14
- package/dist/modules/canonical-json.d.mts +4 -0
- package/dist/modules/canonical-json.mjs +33 -0
- package/dist/modules/canonical-json.mjs.map +7 -0
- package/dist/modules/channel.d.mts +9 -3
- package/dist/modules/channel.mjs.map +2 -2
- package/dist/modules/code-host/host.d.mts +10 -0
- package/dist/modules/code-host/host.mjs +88 -0
- package/dist/modules/code-host/host.mjs.map +7 -0
- package/dist/modules/code-host/in-process.d.mts +24 -0
- package/dist/modules/code-host/in-process.mjs +89 -0
- package/dist/modules/code-host/in-process.mjs.map +7 -0
- package/dist/modules/code-host/index.d.mts +4 -0
- package/dist/modules/code-host/index.mjs +5 -0
- package/dist/modules/code-host/index.mjs.map +7 -0
- package/dist/modules/code-host/serverless.d.mts +63 -0
- package/dist/modules/code-host/serverless.mjs +27 -0
- package/dist/modules/code-host/serverless.mjs.map +7 -0
- package/dist/modules/code-host/types.d.mts +152 -0
- package/dist/modules/code-host/types.mjs +85 -0
- package/dist/modules/code-host/types.mjs.map +7 -0
- package/dist/modules/conformance/agent.mjs +72 -6
- package/dist/modules/conformance/agent.mjs.map +2 -2
- package/dist/modules/conformance/harness-kit.d.mts +9 -2
- package/dist/modules/conformance/harness-kit.mjs +224 -63
- package/dist/modules/conformance/harness-kit.mjs.map +3 -3
- package/dist/modules/conformance/local-harness.d.mts +1 -4
- package/dist/modules/conformance/local-harness.mjs +21 -22
- package/dist/modules/conformance/local-harness.mjs.map +2 -2
- package/dist/modules/conformance/protocol.d.mts +1 -0
- package/dist/modules/conformance/protocol.mjs +2 -0
- package/dist/modules/conformance/protocol.mjs.map +2 -2
- package/dist/modules/conformance/sandbox-kit.d.mts +12 -4
- package/dist/modules/conformance/sandbox-kit.mjs +189 -103
- package/dist/modules/conformance/sandbox-kit.mjs.map +2 -2
- package/dist/modules/conformance/scripted-model/chat-completions.mjs +1 -0
- package/dist/modules/conformance/scripted-model/chat-completions.mjs.map +2 -2
- package/dist/modules/conformance/scripted-model/directives.d.mts +3 -0
- package/dist/modules/conformance/scripted-model/directives.mjs +26 -10
- package/dist/modules/conformance/scripted-model/directives.mjs.map +2 -2
- package/dist/modules/conformance/scripted-model/messages.mjs +1 -0
- package/dist/modules/conformance/scripted-model/messages.mjs.map +2 -2
- package/dist/modules/conformance/scripted-model/responses.mjs +2 -0
- package/dist/modules/conformance/scripted-model/responses.mjs.map +2 -2
- package/dist/modules/conformance/stdio.d.mts +21 -0
- package/dist/modules/conformance/stdio.mjs +158 -0
- package/dist/modules/conformance/stdio.mjs.map +7 -0
- package/dist/modules/credential-routes.d.mts +2 -0
- package/dist/modules/credential-routes.mjs +2 -0
- package/dist/modules/credential-routes.mjs.map +2 -2
- package/dist/modules/document.d.mts +376 -0
- package/dist/modules/document.mjs +208 -0
- package/dist/modules/document.mjs.map +7 -0
- package/dist/modules/harness-configuration.d.mts +16 -0
- package/dist/modules/harness-configuration.mjs +83 -0
- package/dist/modules/harness-configuration.mjs.map +7 -0
- package/dist/modules/harness-definition.d.mts +280 -0
- package/dist/modules/harness-definition.mjs +430 -0
- package/dist/modules/harness-definition.mjs.map +7 -0
- package/dist/modules/harness-provider.d.mts +197 -0
- package/dist/modules/harness-provider.mjs +108 -0
- package/dist/modules/harness-provider.mjs.map +7 -0
- package/dist/modules/harness-requirements.d.mts +19 -0
- package/dist/modules/harness-requirements.mjs +40 -0
- package/dist/modules/harness-requirements.mjs.map +7 -0
- package/dist/modules/harness-start.d.mts +33 -0
- package/dist/modules/harness-start.mjs +107 -0
- package/dist/modules/harness-start.mjs.map +7 -0
- package/dist/modules/harness.d.mts +84 -109
- package/dist/modules/harness.mjs +56 -111
- package/dist/modules/harness.mjs.map +3 -3
- package/dist/modules/identity.d.mts +1 -0
- package/dist/modules/identity.mjs +2 -0
- package/dist/modules/identity.mjs.map +7 -0
- package/dist/modules/index.d.mts +12 -6
- package/dist/modules/index.mjs +12 -6
- package/dist/modules/index.mjs.map +2 -2
- package/dist/modules/inference.d.mts +35 -0
- package/dist/modules/inference.mjs +74 -0
- package/dist/modules/inference.mjs.map +7 -0
- package/dist/modules/local-channel-context.mjs +3 -1
- package/dist/modules/local-channel-context.mjs.map +2 -2
- package/dist/modules/requirements-check.d.mts +30 -0
- package/dist/modules/requirements-check.mjs +164 -0
- package/dist/modules/requirements-check.mjs.map +7 -0
- package/dist/modules/room-surface.d.mts +0 -5
- package/dist/modules/room-surface.mjs.map +2 -2
- package/dist/modules/sandbox/client.d.mts +3 -0
- package/dist/modules/sandbox/client.mjs +101 -18
- package/dist/modules/sandbox/client.mjs.map +2 -2
- package/dist/modules/sandbox/grant.d.mts +78 -0
- package/dist/modules/sandbox/grant.mjs +134 -0
- package/dist/modules/sandbox/grant.mjs.map +7 -0
- package/dist/modules/sandbox/index.d.mts +3 -3
- package/dist/modules/sandbox/index.mjs +4 -5
- package/dist/modules/sandbox/index.mjs.map +2 -2
- package/dist/modules/sandbox/mcp-hosted.d.mts +1 -1
- package/dist/modules/sandbox/mcp-hosted.mjs +4 -7
- package/dist/modules/sandbox/mcp-hosted.mjs.map +2 -2
- package/dist/modules/sandbox/mcp.d.mts +4 -2
- package/dist/modules/sandbox/mcp.mjs +14 -7
- package/dist/modules/sandbox/mcp.mjs.map +2 -2
- package/dist/modules/sandbox/memory-sandbox.d.mts +2 -1
- package/dist/modules/sandbox/memory-sandbox.mjs +71 -41
- package/dist/modules/sandbox/memory-sandbox.mjs.map +2 -2
- package/dist/modules/sandbox/networking.d.mts +7 -7
- package/dist/modules/sandbox/networking.mjs +16 -9
- package/dist/modules/sandbox/networking.mjs.map +2 -2
- package/dist/modules/sandbox/remote/adapter.d.mts +30 -0
- package/dist/modules/sandbox/remote/adapter.mjs +381 -0
- package/dist/modules/sandbox/remote/adapter.mjs.map +7 -0
- package/dist/modules/sandbox/remote/errors.d.mts +10 -0
- package/dist/modules/sandbox/remote/errors.mjs +62 -0
- package/dist/modules/sandbox/remote/errors.mjs.map +7 -0
- package/dist/modules/sandbox/remote/index.d.mts +5 -0
- package/dist/modules/sandbox/remote/index.mjs +6 -0
- package/dist/modules/sandbox/remote/index.mjs.map +7 -0
- package/dist/modules/sandbox/remote/ndjson.d.mts +6 -0
- package/dist/modules/sandbox/remote/ndjson.mjs +80 -0
- package/dist/modules/sandbox/remote/ndjson.mjs.map +7 -0
- package/dist/modules/sandbox/remote/platform-api.d.mts +8 -0
- package/dist/modules/sandbox/remote/platform-api.mjs +15 -0
- package/dist/modules/sandbox/remote/platform-api.mjs.map +7 -0
- package/dist/modules/sandbox/remote/preamble.d.mts +7 -0
- package/dist/modules/sandbox/remote/preamble.mjs +51 -0
- package/dist/modules/sandbox/remote/preamble.mjs.map +7 -0
- package/dist/modules/sandbox/remote/serve.d.mts +34 -0
- package/dist/modules/sandbox/remote/serve.mjs +519 -0
- package/dist/modules/sandbox/remote/serve.mjs.map +7 -0
- package/dist/modules/sandbox/remote/testing.d.mts +34 -0
- package/dist/modules/sandbox/remote/testing.mjs +275 -0
- package/dist/modules/sandbox/remote/testing.mjs.map +7 -0
- package/dist/modules/sandbox/seeds.d.mts +2 -2
- package/dist/modules/sandbox/seeds.mjs +2 -2
- package/dist/modules/sandbox/seeds.mjs.map +2 -2
- package/dist/modules/sandbox/server.d.mts +4 -6
- package/dist/modules/sandbox/server.mjs +93 -49
- package/dist/modules/sandbox/server.mjs.map +2 -2
- package/dist/modules/sandbox/setup/apply.d.mts +41 -0
- package/dist/modules/sandbox/setup/apply.mjs +204 -0
- package/dist/modules/sandbox/setup/apply.mjs.map +7 -0
- package/dist/modules/sandbox/setup/describe.d.mts +10 -0
- package/dist/modules/sandbox/setup/describe.mjs +62 -0
- package/dist/modules/sandbox/setup/describe.mjs.map +7 -0
- package/dist/modules/sandbox/setup/index.d.mts +6 -0
- package/dist/modules/sandbox/setup/index.mjs +17 -0
- package/dist/modules/sandbox/setup/index.mjs.map +7 -0
- package/dist/modules/sandbox/setup/paths.d.mts +8 -0
- package/dist/modules/sandbox/setup/paths.mjs +18 -0
- package/dist/modules/sandbox/setup/paths.mjs.map +7 -0
- package/dist/modules/sandbox/setup/schema.d.mts +42 -0
- package/dist/modules/sandbox/setup/schema.mjs +58 -0
- package/dist/modules/sandbox/setup/schema.mjs.map +7 -0
- package/dist/modules/sandbox/tool-policy.d.mts +1 -1
- package/dist/modules/sandbox/tool-policy.mjs +1 -1
- package/dist/modules/sandbox/tool-policy.mjs.map +2 -2
- package/dist/modules/sandbox/types.d.mts +117 -130
- package/dist/modules/sandbox/types.mjs +46 -50
- package/dist/modules/sandbox/types.mjs.map +3 -3
- package/dist/modules/sandbox/wire.d.mts +93 -6
- package/dist/modules/sandbox/wire.mjs +61 -38
- package/dist/modules/sandbox/wire.mjs.map +2 -2
- package/dist/modules/schemas.d.mts +5 -76
- package/dist/modules/schemas.mjs +18 -85
- package/dist/modules/schemas.mjs.map +2 -2
- package/dist/modules/tool-annotations.d.mts +15 -6
- package/dist/modules/tool-annotations.mjs +9 -3
- package/dist/modules/tool-annotations.mjs.map +2 -2
- package/dist/modules/tool-descriptor.d.mts +16 -0
- package/dist/modules/tool-descriptor.mjs +19 -0
- package/dist/modules/tool-descriptor.mjs.map +7 -0
- package/dist/modules/tool-patterns.d.mts +7 -7
- package/dist/modules/tool-patterns.mjs +10 -9
- package/dist/modules/tool-patterns.mjs.map +2 -2
- package/package.json +86 -36
- package/dist/modules/credentials.d.mts +0 -206
- package/dist/modules/credentials.mjs +0 -207
- package/dist/modules/credentials.mjs.map +0 -7
- package/dist/modules/dynamic.d.mts +0 -40
- package/dist/modules/dynamic.mjs +0 -79
- package/dist/modules/dynamic.mjs.map +0 -7
- package/dist/modules/hosted-bindings.d.mts +0 -15
- package/dist/modules/hosted-bindings.mjs +0 -21
- package/dist/modules/hosted-bindings.mjs.map +0 -7
- package/dist/modules/manifest.d.mts +0 -787
- package/dist/modules/manifest.mjs +0 -320
- package/dist/modules/manifest.mjs.map +0 -7
- package/dist/modules/provider-ref.d.mts +0 -29
- package/dist/modules/provider-ref.mjs +0 -55
- package/dist/modules/provider-ref.mjs.map +0 -7
- package/dist/modules/sandbox/open-scope-node.d.mts +0 -4
- package/dist/modules/sandbox/open-scope-node.mjs +0 -19
- package/dist/modules/sandbox/open-scope-node.mjs.map +0 -7
- package/dist/modules/sandbox/open-scope.d.mts +0 -16
- package/dist/modules/sandbox/open-scope.mjs +0 -66
- package/dist/modules/sandbox/open-scope.mjs.map +0 -7
- package/dist/modules/sandbox/workspace-identity.d.mts +0 -5
- package/dist/modules/sandbox/workspace-identity.mjs +0 -14
- package/dist/modules/sandbox/workspace-identity.mjs.map +0 -7
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Capability, FilesAccess } from "@finalai/agent-protocol";
|
|
2
2
|
import { readAllBytes } from "../sandbox/bytes.mjs";
|
|
3
3
|
import { streamToString } from "../sandbox/convenience.mjs";
|
|
4
4
|
import { createInMemoryHandleNetwork } from "../sandbox/testing.mjs";
|
|
5
5
|
import {
|
|
6
6
|
NetworkPolicy,
|
|
7
7
|
noSandboxActingUser,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
noSandboxVariables,
|
|
8
|
+
noSandboxCredentials,
|
|
9
|
+
noSandboxIdentity,
|
|
11
10
|
SandboxEntryType
|
|
12
11
|
} from "../sandbox/types.mjs";
|
|
13
12
|
import { HandleRpcErrorCode, isHandleRpcError } from "../sandbox/wire.mjs";
|
|
13
|
+
import {
|
|
14
|
+
connectSandboxProviderInMemory
|
|
15
|
+
} from "../sandbox/remote/index.mjs";
|
|
14
16
|
import { ConformanceCaseStatus } from "./harness-kit.mjs";
|
|
15
17
|
const check = (condition, message) => {
|
|
16
18
|
if (!condition) throw new Error(message);
|
|
@@ -313,52 +315,107 @@ const durableCases = async (targets, record, prefix) => {
|
|
|
313
315
|
]);
|
|
314
316
|
});
|
|
315
317
|
};
|
|
316
|
-
const
|
|
318
|
+
const createFromProvider = async (args, provider, overrides = {}) => {
|
|
317
319
|
const implementation = provider.definition.environment(
|
|
318
320
|
overrides.environmentOptions ?? args.environmentOptions
|
|
319
321
|
);
|
|
320
322
|
const prepareContext = {
|
|
323
|
+
organizationId: "conformance",
|
|
324
|
+
projectId: "conformance",
|
|
325
|
+
credentials: noSandboxCredentials,
|
|
326
|
+
actingUser: noSandboxActingUser,
|
|
327
|
+
identity: noSandboxIdentity,
|
|
321
328
|
files: {},
|
|
322
329
|
resources: {},
|
|
323
330
|
sourceRevision: "conformance",
|
|
324
331
|
storagePath: "/tmp/final-conformance",
|
|
325
|
-
organizationId: "conformance",
|
|
326
|
-
guides: noSandboxGuides,
|
|
327
|
-
actingUser: noSandboxActingUser,
|
|
328
332
|
...args.prepareContext
|
|
329
333
|
};
|
|
330
334
|
const artifact = await implementation.prepare(prepareContext);
|
|
331
|
-
const
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
conversationId: null,
|
|
336
|
-
definitionId: "conformance",
|
|
337
|
-
bindingId: crypto.randomUUID(),
|
|
338
|
-
target: "conformance"
|
|
339
|
-
},
|
|
340
|
-
storagePath: "/tmp/final-conformance",
|
|
341
|
-
guides: noSandboxGuides,
|
|
342
|
-
variables: noSandboxVariables,
|
|
343
|
-
repositories: noSandboxRepositories,
|
|
335
|
+
const ctx = {
|
|
336
|
+
organizationId: "conformance",
|
|
337
|
+
projectId: "conformance",
|
|
338
|
+
credentials: noSandboxCredentials,
|
|
344
339
|
actingUser: noSandboxActingUser,
|
|
340
|
+
identity: noSandboxIdentity,
|
|
341
|
+
lifecycle: { parkAfterIdleMs: null },
|
|
342
|
+
storagePath: "/tmp/final-conformance",
|
|
345
343
|
platformNetworkPolicy: async () => void 0,
|
|
346
|
-
...args.
|
|
347
|
-
...overrides.
|
|
344
|
+
...args.resourceContext,
|
|
345
|
+
...overrides.resourceContext,
|
|
346
|
+
// Always a sandbox of its own, whatever the caller's context names.
|
|
347
|
+
sandboxId: crypto.randomUUID()
|
|
348
348
|
};
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
349
|
+
const { state } = await implementation.create(ctx, { artifact, setup: null });
|
|
350
|
+
return { implementation, ctx, artifact, state };
|
|
351
|
+
};
|
|
352
|
+
const startFromProvider = async (args, provider, overrides = {}) => {
|
|
353
|
+
const created = await createFromProvider(args, provider, overrides);
|
|
354
|
+
const remove = () => created.implementation.delete(created.ctx, { state: created.state }).catch(() => void 0);
|
|
355
|
+
try {
|
|
356
|
+
const attached = await created.implementation.attach(created.ctx, {
|
|
357
|
+
artifact: created.artifact,
|
|
358
|
+
state: created.state
|
|
359
|
+
});
|
|
360
|
+
return {
|
|
361
|
+
handle: attached.handle,
|
|
362
|
+
awaitRunning: (timeoutMs) => created.implementation.awaitRunning(created.ctx, attached.state, { timeoutMs }),
|
|
363
|
+
remove: () => created.implementation.delete(created.ctx, { state: attached.state }).catch(() => void 0)
|
|
355
364
|
};
|
|
365
|
+
} catch (cause) {
|
|
366
|
+
await remove();
|
|
367
|
+
throw cause;
|
|
356
368
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
369
|
+
};
|
|
370
|
+
const MARKER_PATH = ".final-conformance-lifecycle";
|
|
371
|
+
const runLifecycleCases = async (args) => {
|
|
372
|
+
const holder = { created: null };
|
|
373
|
+
await args.record("lifecycle: create", async () => {
|
|
374
|
+
holder.created = await createFromProvider(args.kit, args.provider);
|
|
375
|
+
});
|
|
376
|
+
const sandbox = holder.created;
|
|
377
|
+
if (sandbox == null) return;
|
|
378
|
+
const { implementation, ctx, artifact } = sandbox;
|
|
379
|
+
let state = sandbox.state;
|
|
380
|
+
const attach = async () => {
|
|
381
|
+
const attached = await implementation.attach(ctx, { artifact, state });
|
|
382
|
+
state = attached.state;
|
|
383
|
+
return attached;
|
|
361
384
|
};
|
|
385
|
+
try {
|
|
386
|
+
await args.record("lifecycle: first attach is fresh and booted", async () => {
|
|
387
|
+
const first = await attach();
|
|
388
|
+
check(first.fresh, "the first attach of a new sandbox did not report a fresh disk");
|
|
389
|
+
check(first.booted, "the first attach of a new sandbox did not report a boot");
|
|
390
|
+
await first.handle.sandbox.writeTextFile({
|
|
391
|
+
path: first.handle.sandbox.resolvePath(MARKER_PATH),
|
|
392
|
+
content: "kept"
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
await args.record("lifecycle: detach then attach keeps the disk", async () => {
|
|
396
|
+
state = await implementation.detach(ctx, { state });
|
|
397
|
+
const again = await attach();
|
|
398
|
+
check(!again.fresh, "an attach after detach reported a fresh disk");
|
|
399
|
+
const marker = await again.handle.sandbox.readTextFile({
|
|
400
|
+
path: again.handle.sandbox.resolvePath(MARKER_PATH)
|
|
401
|
+
});
|
|
402
|
+
check(marker === "kept", `the file written before detach reads ${JSON.stringify(marker)}`);
|
|
403
|
+
});
|
|
404
|
+
await args.record("lifecycle: park then attach keeps the disk", async () => {
|
|
405
|
+
state = await implementation.park(ctx, { artifact, state });
|
|
406
|
+
const resumed = await attach();
|
|
407
|
+
check(!resumed.fresh, "an attach after park reported a fresh disk");
|
|
408
|
+
const marker = await resumed.handle.sandbox.readTextFile({
|
|
409
|
+
path: resumed.handle.sandbox.resolvePath(MARKER_PATH)
|
|
410
|
+
});
|
|
411
|
+
check(marker === "kept", `the file written before park reads ${JSON.stringify(marker)}`);
|
|
412
|
+
});
|
|
413
|
+
} finally {
|
|
414
|
+
await args.record("lifecycle: delete, and delete again", async () => {
|
|
415
|
+
await implementation.delete(ctx, { state });
|
|
416
|
+
await implementation.delete(ctx, { state });
|
|
417
|
+
});
|
|
418
|
+
}
|
|
362
419
|
};
|
|
363
420
|
const PLATFORM_VARIABLE = "FINAL_CONFORMANCE_PLATFORM";
|
|
364
421
|
const SPEC_VARIABLE = "FINAL_CONFORMANCE_SPEC";
|
|
@@ -393,20 +450,22 @@ const runPlatformCases = async (args) => {
|
|
|
393
450
|
const order = [];
|
|
394
451
|
const withPlatform = { handle: null };
|
|
395
452
|
await record("platform environment: provider start", async () => {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
453
|
+
Object.assign(
|
|
454
|
+
withPlatform,
|
|
455
|
+
await startFromProvider(kit, provider, {
|
|
456
|
+
environmentOptions: platform.environmentOptions({ env: SPEC_ENV }),
|
|
457
|
+
resourceContext: {
|
|
458
|
+
platformFiles: async () => {
|
|
459
|
+
order.push("files");
|
|
460
|
+
return { [filePath]: "conformance CA\n" };
|
|
461
|
+
},
|
|
462
|
+
platformEnvironment: async () => {
|
|
463
|
+
order.push("environment");
|
|
464
|
+
return { ...platformValues };
|
|
465
|
+
}
|
|
406
466
|
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
}));
|
|
467
|
+
})
|
|
468
|
+
);
|
|
410
469
|
});
|
|
411
470
|
const sandbox = withPlatform.handle?.sandbox;
|
|
412
471
|
if (sandbox != null) {
|
|
@@ -440,7 +499,7 @@ const runPlatformCases = async (args) => {
|
|
|
440
499
|
});
|
|
441
500
|
});
|
|
442
501
|
} finally {
|
|
443
|
-
await withPlatform.
|
|
502
|
+
await withPlatform.remove?.();
|
|
444
503
|
}
|
|
445
504
|
}
|
|
446
505
|
const withoutPlatform = { handle: null };
|
|
@@ -456,14 +515,16 @@ const runPlatformCases = async (args) => {
|
|
|
456
515
|
}
|
|
457
516
|
});
|
|
458
517
|
await record("platform environment: provider start without it", async () => {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
518
|
+
Object.assign(
|
|
519
|
+
withoutPlatform,
|
|
520
|
+
await startFromProvider(kit, provider, {
|
|
521
|
+
environmentOptions: platform.environmentOptions({ env: SPEC_ENV, allow: SPEC_ALLOW }),
|
|
522
|
+
resourceContext: allowlistContext(async (policy) => {
|
|
523
|
+
reportOrder.push("policy");
|
|
524
|
+
reported.push(policy);
|
|
525
|
+
})
|
|
526
|
+
})
|
|
527
|
+
);
|
|
467
528
|
});
|
|
468
529
|
const plain = withoutPlatform.handle?.sandbox;
|
|
469
530
|
if (plain != null) {
|
|
@@ -505,7 +566,7 @@ const runPlatformCases = async (args) => {
|
|
|
505
566
|
});
|
|
506
567
|
}
|
|
507
568
|
} finally {
|
|
508
|
-
await withoutPlatform.
|
|
569
|
+
await withoutPlatform.remove?.();
|
|
509
570
|
}
|
|
510
571
|
}
|
|
511
572
|
if (platform.observedAllowlist == null) {
|
|
@@ -514,16 +575,15 @@ const runPlatformCases = async (args) => {
|
|
|
514
575
|
await record("platform network policy: a rejected report fails the start", async () => {
|
|
515
576
|
const started = await startFromProvider(kit, provider, {
|
|
516
577
|
environmentOptions: platform.environmentOptions({ env: SPEC_ENV, allow: SPEC_ALLOW }),
|
|
517
|
-
|
|
578
|
+
resourceContext: allowlistContext(async () => {
|
|
518
579
|
throw new Error("conformance: the policy was not recorded");
|
|
519
|
-
})
|
|
520
|
-
ownBinding: true
|
|
580
|
+
})
|
|
521
581
|
}).then(
|
|
522
|
-
(
|
|
582
|
+
(attached) => attached,
|
|
523
583
|
() => null
|
|
524
584
|
);
|
|
525
585
|
if (started == null) return;
|
|
526
|
-
await started.
|
|
586
|
+
await started.remove();
|
|
527
587
|
throw new Error("a start whose policy report failed returned a sandbox");
|
|
528
588
|
});
|
|
529
589
|
}
|
|
@@ -531,18 +591,26 @@ const runPlatformCases = async (args) => {
|
|
|
531
591
|
const started = await startFromProvider(kit, provider, {
|
|
532
592
|
environmentOptions: platform.environmentOptions({
|
|
533
593
|
env: { HTTPS_PROXY: "http://spec.example.com" }
|
|
534
|
-
})
|
|
535
|
-
ownBinding: true
|
|
594
|
+
})
|
|
536
595
|
}).then(
|
|
537
|
-
(
|
|
596
|
+
(attached) => attached,
|
|
538
597
|
() => null
|
|
539
598
|
);
|
|
540
599
|
if (started == null) return;
|
|
541
|
-
await started.
|
|
600
|
+
await started.remove();
|
|
542
601
|
throw new Error("a spec setting HTTPS_PROXY started");
|
|
543
602
|
});
|
|
544
603
|
};
|
|
545
|
-
const runSandboxConformance = async (
|
|
604
|
+
const runSandboxConformance = async (kitArgs) => {
|
|
605
|
+
const args = kitArgs.remote == null || kitArgs.provider == null ? kitArgs : {
|
|
606
|
+
...kitArgs,
|
|
607
|
+
provider: (await connectSandboxProviderInMemory({
|
|
608
|
+
provider: kitArgs.provider,
|
|
609
|
+
discovery: kitArgs.remote.discovery,
|
|
610
|
+
downstreamToken: kitArgs.remote.downstreamToken,
|
|
611
|
+
forwardedSecrets: kitArgs.remote.forwardedSecrets
|
|
612
|
+
})).provider
|
|
613
|
+
};
|
|
546
614
|
const timeoutMs = args.timeoutMs ?? 3e4;
|
|
547
615
|
const cases = [];
|
|
548
616
|
const record = async (name, run) => {
|
|
@@ -572,16 +640,14 @@ const runSandboxConformance = async (args) => {
|
|
|
572
640
|
if (args.provider == null)
|
|
573
641
|
throw new Error("runSandboxConformance needs a handle or a provider");
|
|
574
642
|
const provider = args.provider;
|
|
575
|
-
await
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
provider
|
|
579
|
-
));
|
|
643
|
+
await runLifecycleCases({ kit: args, provider, record });
|
|
644
|
+
await record("provider create and attach", async () => {
|
|
645
|
+
Object.assign(started, await startFromProvider(args, provider));
|
|
580
646
|
});
|
|
581
647
|
const awaitRunning = started.awaitRunning;
|
|
582
648
|
if (awaitRunning != null)
|
|
583
649
|
await record(
|
|
584
|
-
"provider awaitRunning: resolves for
|
|
650
|
+
"provider awaitRunning: resolves for an attached sandbox",
|
|
585
651
|
() => awaitRunning(timeoutMs)
|
|
586
652
|
);
|
|
587
653
|
sandbox = started.handle?.sandbox ?? null;
|
|
@@ -613,52 +679,72 @@ const runSandboxConformance = async (args) => {
|
|
|
613
679
|
if (args.viaWire !== false) {
|
|
614
680
|
const network = createInMemoryHandleNetwork();
|
|
615
681
|
network.serve({ url: "mem://conformance", sandbox: target });
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
682
|
+
const grants = [
|
|
683
|
+
["read", { [Capability.Files]: FilesAccess.Read }],
|
|
684
|
+
["write-files-run-nothing", { [Capability.Files]: FilesAccess.Write }]
|
|
685
|
+
];
|
|
686
|
+
for (const [name, grant] of grants)
|
|
687
|
+
network.serve({
|
|
688
|
+
url: `mem://conformance-${name}`,
|
|
689
|
+
sandbox: target,
|
|
690
|
+
access: { grant, lifecycle: false }
|
|
691
|
+
});
|
|
621
692
|
const client = await network.connect({ url: "mem://conformance", token: "conformance" });
|
|
693
|
+
const refused = async (what, attempt) => {
|
|
694
|
+
const error = await attempt.then(
|
|
695
|
+
() => null,
|
|
696
|
+
(cause) => cause
|
|
697
|
+
);
|
|
698
|
+
check(
|
|
699
|
+
isHandleRpcError(error) && error.code === HandleRpcErrorCode.Forbidden,
|
|
700
|
+
`${what} was not refused`
|
|
701
|
+
);
|
|
702
|
+
};
|
|
622
703
|
try {
|
|
623
704
|
const wireRoot = `${root}-wire`;
|
|
624
705
|
for (const entry of list)
|
|
625
706
|
await record(`handle rpc: ${entry.name}`, () => entry.run(client, wireRoot));
|
|
626
|
-
await record("handle rpc: read
|
|
627
|
-
const
|
|
707
|
+
await record("handle rpc: a files read grant refuses writes and commands", async () => {
|
|
708
|
+
const reader = await network.connect({
|
|
628
709
|
url: "mem://conformance-read",
|
|
629
710
|
token: "conformance"
|
|
630
711
|
});
|
|
631
712
|
try {
|
|
632
713
|
await target.writeTextFile({ path: `${root}/ro.txt`, content: "visible" });
|
|
633
714
|
check(
|
|
634
|
-
await
|
|
635
|
-
"read failed
|
|
715
|
+
await reader.readTextFile({ path: `${root}/ro.txt` }) === "visible",
|
|
716
|
+
"read failed under a read grant"
|
|
636
717
|
);
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
["removePath", readOnly.removePath({ path: `${root}/ro.txt` })]
|
|
645
|
-
];
|
|
646
|
-
for (const [what, attempt] of attempts) {
|
|
647
|
-
const error = await attempt.then(
|
|
648
|
-
() => null,
|
|
649
|
-
(cause) => cause
|
|
650
|
-
);
|
|
651
|
-
check(
|
|
652
|
-
isHandleRpcError(error) && error.code === HandleRpcErrorCode.Forbidden,
|
|
653
|
-
`${what} was not rejected`
|
|
654
|
-
);
|
|
655
|
-
}
|
|
718
|
+
await refused(
|
|
719
|
+
"writeTextFile",
|
|
720
|
+
reader.writeTextFile({ path: `${root}/ro.txt`, content: "changed" })
|
|
721
|
+
);
|
|
722
|
+
await refused("run", reader.run({ command: "echo" }));
|
|
723
|
+
await refused("spawn", reader.spawn({ command: "echo" }));
|
|
724
|
+
await refused("removePath", reader.removePath({ path: `${root}/ro.txt` }));
|
|
656
725
|
check(
|
|
657
726
|
await target.readTextFile({ path: `${root}/ro.txt` }) === "visible",
|
|
658
|
-
"a read
|
|
727
|
+
"a read grant changed the file"
|
|
728
|
+
);
|
|
729
|
+
} finally {
|
|
730
|
+
reader.close();
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
await record("handle rpc: a files write grant writes and runs nothing", async () => {
|
|
734
|
+
const writer = await network.connect({
|
|
735
|
+
url: "mem://conformance-write-files-run-nothing",
|
|
736
|
+
token: "conformance"
|
|
737
|
+
});
|
|
738
|
+
try {
|
|
739
|
+
await writer.writeTextFile({ path: `${root}/w.txt`, content: "written" });
|
|
740
|
+
check(
|
|
741
|
+
await target.readTextFile({ path: `${root}/w.txt` }) === "written",
|
|
742
|
+
"a write under a files write grant did not land"
|
|
659
743
|
);
|
|
744
|
+
await refused("run", writer.run({ command: "echo" }));
|
|
745
|
+
await refused("spawn", writer.spawn({ command: "echo" }));
|
|
660
746
|
} finally {
|
|
661
|
-
|
|
747
|
+
writer.close();
|
|
662
748
|
}
|
|
663
749
|
});
|
|
664
750
|
if (durable) {
|
|
@@ -691,7 +777,7 @@ const runSandboxConformance = async (args) => {
|
|
|
691
777
|
}
|
|
692
778
|
}
|
|
693
779
|
await target.removePath({ path: root, recursive: true, force: true }).catch(() => void 0);
|
|
694
|
-
await started.
|
|
780
|
+
await started.remove?.();
|
|
695
781
|
if (args.platform != null && args.provider != null) {
|
|
696
782
|
await runPlatformCases({
|
|
697
783
|
kit: args,
|