@finalai/agent-provider 0.9.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.
Files changed (200) hide show
  1. package/HOSTING.md +334 -245
  2. package/README.md +93 -14
  3. package/dist/modules/canonical-json.d.mts +4 -0
  4. package/dist/modules/canonical-json.mjs +33 -0
  5. package/dist/modules/canonical-json.mjs.map +7 -0
  6. package/dist/modules/channel.d.mts +0 -3
  7. package/dist/modules/channel.mjs.map +1 -1
  8. package/dist/modules/code-host/host.d.mts +10 -0
  9. package/dist/modules/code-host/host.mjs +88 -0
  10. package/dist/modules/code-host/host.mjs.map +7 -0
  11. package/dist/modules/code-host/in-process.d.mts +24 -0
  12. package/dist/modules/code-host/in-process.mjs +89 -0
  13. package/dist/modules/code-host/in-process.mjs.map +7 -0
  14. package/dist/modules/code-host/index.d.mts +4 -0
  15. package/dist/modules/code-host/index.mjs +5 -0
  16. package/dist/modules/code-host/index.mjs.map +7 -0
  17. package/dist/modules/code-host/serverless.d.mts +63 -0
  18. package/dist/modules/code-host/serverless.mjs +27 -0
  19. package/dist/modules/code-host/serverless.mjs.map +7 -0
  20. package/dist/modules/code-host/types.d.mts +152 -0
  21. package/dist/modules/code-host/types.mjs +85 -0
  22. package/dist/modules/code-host/types.mjs.map +7 -0
  23. package/dist/modules/conformance/agent.mjs +72 -6
  24. package/dist/modules/conformance/agent.mjs.map +2 -2
  25. package/dist/modules/conformance/harness-kit.d.mts +9 -2
  26. package/dist/modules/conformance/harness-kit.mjs +224 -63
  27. package/dist/modules/conformance/harness-kit.mjs.map +3 -3
  28. package/dist/modules/conformance/local-harness.d.mts +1 -4
  29. package/dist/modules/conformance/local-harness.mjs +21 -22
  30. package/dist/modules/conformance/local-harness.mjs.map +2 -2
  31. package/dist/modules/conformance/protocol.d.mts +1 -0
  32. package/dist/modules/conformance/protocol.mjs +2 -0
  33. package/dist/modules/conformance/protocol.mjs.map +2 -2
  34. package/dist/modules/conformance/sandbox-kit.d.mts +12 -4
  35. package/dist/modules/conformance/sandbox-kit.mjs +189 -103
  36. package/dist/modules/conformance/sandbox-kit.mjs.map +2 -2
  37. package/dist/modules/conformance/scripted-model/chat-completions.mjs +1 -0
  38. package/dist/modules/conformance/scripted-model/chat-completions.mjs.map +2 -2
  39. package/dist/modules/conformance/scripted-model/directives.d.mts +3 -0
  40. package/dist/modules/conformance/scripted-model/directives.mjs +26 -10
  41. package/dist/modules/conformance/scripted-model/directives.mjs.map +2 -2
  42. package/dist/modules/conformance/scripted-model/messages.mjs +1 -0
  43. package/dist/modules/conformance/scripted-model/messages.mjs.map +2 -2
  44. package/dist/modules/conformance/scripted-model/responses.mjs +2 -0
  45. package/dist/modules/conformance/scripted-model/responses.mjs.map +2 -2
  46. package/dist/modules/conformance/stdio.d.mts +21 -0
  47. package/dist/modules/conformance/stdio.mjs +158 -0
  48. package/dist/modules/conformance/stdio.mjs.map +7 -0
  49. package/dist/modules/credential-routes.d.mts +2 -0
  50. package/dist/modules/credential-routes.mjs +2 -0
  51. package/dist/modules/credential-routes.mjs.map +2 -2
  52. package/dist/modules/document.d.mts +376 -0
  53. package/dist/modules/document.mjs +208 -0
  54. package/dist/modules/document.mjs.map +7 -0
  55. package/dist/modules/harness-configuration.d.mts +16 -0
  56. package/dist/modules/harness-configuration.mjs +83 -0
  57. package/dist/modules/harness-configuration.mjs.map +7 -0
  58. package/dist/modules/harness-definition.d.mts +280 -0
  59. package/dist/modules/harness-definition.mjs +430 -0
  60. package/dist/modules/harness-definition.mjs.map +7 -0
  61. package/dist/modules/harness-provider.d.mts +197 -0
  62. package/dist/modules/harness-provider.mjs +108 -0
  63. package/dist/modules/harness-provider.mjs.map +7 -0
  64. package/dist/modules/harness-requirements.d.mts +19 -0
  65. package/dist/modules/harness-requirements.mjs +40 -0
  66. package/dist/modules/harness-requirements.mjs.map +7 -0
  67. package/dist/modules/harness-start.d.mts +33 -0
  68. package/dist/modules/harness-start.mjs +107 -0
  69. package/dist/modules/harness-start.mjs.map +7 -0
  70. package/dist/modules/harness.d.mts +84 -109
  71. package/dist/modules/harness.mjs +56 -111
  72. package/dist/modules/harness.mjs.map +3 -3
  73. package/dist/modules/identity.d.mts +1 -0
  74. package/dist/modules/identity.mjs +2 -0
  75. package/dist/modules/identity.mjs.map +7 -0
  76. package/dist/modules/index.d.mts +12 -6
  77. package/dist/modules/index.mjs +12 -6
  78. package/dist/modules/index.mjs.map +2 -2
  79. package/dist/modules/inference.d.mts +35 -0
  80. package/dist/modules/inference.mjs +74 -0
  81. package/dist/modules/inference.mjs.map +7 -0
  82. package/dist/modules/local-channel-context.mjs +1 -1
  83. package/dist/modules/local-channel-context.mjs.map +2 -2
  84. package/dist/modules/requirements-check.d.mts +30 -0
  85. package/dist/modules/requirements-check.mjs +164 -0
  86. package/dist/modules/requirements-check.mjs.map +7 -0
  87. package/dist/modules/room-surface.d.mts +0 -5
  88. package/dist/modules/room-surface.mjs.map +2 -2
  89. package/dist/modules/sandbox/client.d.mts +3 -0
  90. package/dist/modules/sandbox/client.mjs +101 -18
  91. package/dist/modules/sandbox/client.mjs.map +2 -2
  92. package/dist/modules/sandbox/grant.d.mts +78 -0
  93. package/dist/modules/sandbox/grant.mjs +134 -0
  94. package/dist/modules/sandbox/grant.mjs.map +7 -0
  95. package/dist/modules/sandbox/index.d.mts +3 -3
  96. package/dist/modules/sandbox/index.mjs +4 -5
  97. package/dist/modules/sandbox/index.mjs.map +2 -2
  98. package/dist/modules/sandbox/mcp-hosted.d.mts +1 -1
  99. package/dist/modules/sandbox/mcp-hosted.mjs +4 -7
  100. package/dist/modules/sandbox/mcp-hosted.mjs.map +2 -2
  101. package/dist/modules/sandbox/mcp.d.mts +4 -2
  102. package/dist/modules/sandbox/mcp.mjs +14 -7
  103. package/dist/modules/sandbox/mcp.mjs.map +2 -2
  104. package/dist/modules/sandbox/memory-sandbox.d.mts +2 -1
  105. package/dist/modules/sandbox/memory-sandbox.mjs +71 -41
  106. package/dist/modules/sandbox/memory-sandbox.mjs.map +2 -2
  107. package/dist/modules/sandbox/networking.d.mts +7 -7
  108. package/dist/modules/sandbox/networking.mjs +16 -9
  109. package/dist/modules/sandbox/networking.mjs.map +2 -2
  110. package/dist/modules/sandbox/remote/adapter.d.mts +30 -0
  111. package/dist/modules/sandbox/remote/adapter.mjs +381 -0
  112. package/dist/modules/sandbox/remote/adapter.mjs.map +7 -0
  113. package/dist/modules/sandbox/remote/errors.d.mts +10 -0
  114. package/dist/modules/sandbox/remote/errors.mjs +62 -0
  115. package/dist/modules/sandbox/remote/errors.mjs.map +7 -0
  116. package/dist/modules/sandbox/remote/index.d.mts +5 -0
  117. package/dist/modules/sandbox/remote/index.mjs +6 -0
  118. package/dist/modules/sandbox/remote/index.mjs.map +7 -0
  119. package/dist/modules/sandbox/remote/ndjson.d.mts +6 -0
  120. package/dist/modules/sandbox/remote/ndjson.mjs +80 -0
  121. package/dist/modules/sandbox/remote/ndjson.mjs.map +7 -0
  122. package/dist/modules/sandbox/remote/platform-api.d.mts +8 -0
  123. package/dist/modules/sandbox/remote/platform-api.mjs +15 -0
  124. package/dist/modules/sandbox/remote/platform-api.mjs.map +7 -0
  125. package/dist/modules/sandbox/remote/preamble.d.mts +7 -0
  126. package/dist/modules/sandbox/remote/preamble.mjs +51 -0
  127. package/dist/modules/sandbox/remote/preamble.mjs.map +7 -0
  128. package/dist/modules/sandbox/remote/serve.d.mts +34 -0
  129. package/dist/modules/sandbox/remote/serve.mjs +519 -0
  130. package/dist/modules/sandbox/remote/serve.mjs.map +7 -0
  131. package/dist/modules/sandbox/remote/testing.d.mts +34 -0
  132. package/dist/modules/sandbox/remote/testing.mjs +275 -0
  133. package/dist/modules/sandbox/remote/testing.mjs.map +7 -0
  134. package/dist/modules/sandbox/seeds.d.mts +2 -2
  135. package/dist/modules/sandbox/seeds.mjs +2 -2
  136. package/dist/modules/sandbox/seeds.mjs.map +2 -2
  137. package/dist/modules/sandbox/server.d.mts +4 -6
  138. package/dist/modules/sandbox/server.mjs +93 -49
  139. package/dist/modules/sandbox/server.mjs.map +2 -2
  140. package/dist/modules/sandbox/setup/apply.d.mts +41 -0
  141. package/dist/modules/sandbox/setup/apply.mjs +204 -0
  142. package/dist/modules/sandbox/setup/apply.mjs.map +7 -0
  143. package/dist/modules/sandbox/setup/describe.d.mts +10 -0
  144. package/dist/modules/sandbox/setup/describe.mjs +62 -0
  145. package/dist/modules/sandbox/setup/describe.mjs.map +7 -0
  146. package/dist/modules/sandbox/setup/index.d.mts +6 -0
  147. package/dist/modules/sandbox/setup/index.mjs +17 -0
  148. package/dist/modules/sandbox/setup/index.mjs.map +7 -0
  149. package/dist/modules/sandbox/setup/paths.d.mts +8 -0
  150. package/dist/modules/sandbox/setup/paths.mjs +18 -0
  151. package/dist/modules/sandbox/setup/paths.mjs.map +7 -0
  152. package/dist/modules/sandbox/setup/schema.d.mts +42 -0
  153. package/dist/modules/sandbox/setup/schema.mjs +58 -0
  154. package/dist/modules/sandbox/setup/schema.mjs.map +7 -0
  155. package/dist/modules/sandbox/tool-policy.d.mts +1 -1
  156. package/dist/modules/sandbox/tool-policy.mjs +1 -1
  157. package/dist/modules/sandbox/tool-policy.mjs.map +2 -2
  158. package/dist/modules/sandbox/types.d.mts +117 -130
  159. package/dist/modules/sandbox/types.mjs +46 -50
  160. package/dist/modules/sandbox/types.mjs.map +3 -3
  161. package/dist/modules/sandbox/wire.d.mts +93 -6
  162. package/dist/modules/sandbox/wire.mjs +61 -38
  163. package/dist/modules/sandbox/wire.mjs.map +2 -2
  164. package/dist/modules/schemas.d.mts +5 -76
  165. package/dist/modules/schemas.mjs +18 -85
  166. package/dist/modules/schemas.mjs.map +2 -2
  167. package/dist/modules/tool-annotations.d.mts +15 -6
  168. package/dist/modules/tool-annotations.mjs +9 -3
  169. package/dist/modules/tool-annotations.mjs.map +2 -2
  170. package/dist/modules/tool-descriptor.d.mts +16 -0
  171. package/dist/modules/tool-descriptor.mjs +19 -0
  172. package/dist/modules/tool-descriptor.mjs.map +7 -0
  173. package/dist/modules/tool-patterns.d.mts +7 -7
  174. package/dist/modules/tool-patterns.mjs +10 -9
  175. package/dist/modules/tool-patterns.mjs.map +2 -2
  176. package/package.json +86 -36
  177. package/dist/modules/credentials.d.mts +0 -206
  178. package/dist/modules/credentials.mjs +0 -207
  179. package/dist/modules/credentials.mjs.map +0 -7
  180. package/dist/modules/dynamic.d.mts +0 -40
  181. package/dist/modules/dynamic.mjs +0 -79
  182. package/dist/modules/dynamic.mjs.map +0 -7
  183. package/dist/modules/hosted-bindings.d.mts +0 -15
  184. package/dist/modules/hosted-bindings.mjs +0 -21
  185. package/dist/modules/hosted-bindings.mjs.map +0 -7
  186. package/dist/modules/manifest.d.mts +0 -791
  187. package/dist/modules/manifest.mjs +0 -322
  188. package/dist/modules/manifest.mjs.map +0 -7
  189. package/dist/modules/provider-ref.d.mts +0 -29
  190. package/dist/modules/provider-ref.mjs +0 -55
  191. package/dist/modules/provider-ref.mjs.map +0 -7
  192. package/dist/modules/sandbox/open-scope-node.d.mts +0 -4
  193. package/dist/modules/sandbox/open-scope-node.mjs +0 -19
  194. package/dist/modules/sandbox/open-scope-node.mjs.map +0 -7
  195. package/dist/modules/sandbox/open-scope.d.mts +0 -16
  196. package/dist/modules/sandbox/open-scope.mjs +0 -66
  197. package/dist/modules/sandbox/open-scope.mjs.map +0 -7
  198. package/dist/modules/sandbox/workspace-identity.d.mts +0 -5
  199. package/dist/modules/sandbox/workspace-identity.mjs +0 -14
  200. package/dist/modules/sandbox/workspace-identity.mjs.map +0 -7
@@ -1,16 +1,18 @@
1
- import { SandboxAccess } from "../manifest.mjs";
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
- noSandboxGuides,
9
- noSandboxRepositories,
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 startFromProvider = async (args, provider, overrides = {}) => {
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 startContext = {
332
- session: {
333
- id: crypto.randomUUID(),
334
- organizationId: "conformance",
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.startContext,
347
- ...overrides.startContext
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
- if (overrides.ownBinding === true) {
350
- startContext.session = {
351
- ...startContext.session,
352
- id: crypto.randomUUID(),
353
- bindingId: crypto.randomUUID(),
354
- conversationId: null
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
- const { handle, state } = await implementation.start(startContext, args.openOptions, artifact);
358
- return {
359
- handle,
360
- awaitRunning: (timeoutMs) => implementation.awaitRunning(startContext, state, { timeoutMs })
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
- ({ handle: withPlatform.handle } = await startFromProvider(kit, provider, {
397
- environmentOptions: platform.environmentOptions({ env: SPEC_ENV }),
398
- startContext: {
399
- platformFiles: async () => {
400
- order.push("files");
401
- return { [filePath]: "conformance CA\n" };
402
- },
403
- platformEnvironment: async () => {
404
- order.push("environment");
405
- return { ...platformValues };
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
- ownBinding: true
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.handle?.onSandboxDelete({ reason: "conformance" }).catch(() => void 0);
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
- ({ handle: withoutPlatform.handle } = await startFromProvider(kit, provider, {
460
- environmentOptions: platform.environmentOptions({ env: SPEC_ENV, allow: SPEC_ALLOW }),
461
- startContext: allowlistContext(async (policy) => {
462
- reportOrder.push("policy");
463
- reported.push(policy);
464
- }),
465
- ownBinding: true
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.handle?.onSandboxDelete({ reason: "conformance" }).catch(() => void 0);
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
- startContext: allowlistContext(async () => {
578
+ resourceContext: allowlistContext(async () => {
518
579
  throw new Error("conformance: the policy was not recorded");
519
- }),
520
- ownBinding: true
580
+ })
521
581
  }).then(
522
- ({ handle }) => handle,
582
+ (attached) => attached,
523
583
  () => null
524
584
  );
525
585
  if (started == null) return;
526
- await started.onSandboxDelete({ reason: "conformance" }).catch(() => void 0);
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
- ({ handle }) => handle,
596
+ (attached) => attached,
538
597
  () => null
539
598
  );
540
599
  if (started == null) return;
541
- await started.onSandboxDelete({ reason: "conformance" }).catch(() => void 0);
600
+ await started.remove();
542
601
  throw new Error("a spec setting HTTPS_PROXY started");
543
602
  });
544
603
  };
545
- const runSandboxConformance = async (args) => {
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 record("provider start", async () => {
576
- ({ handle: started.handle, awaitRunning: started.awaitRunning } = await startFromProvider(
577
- args,
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 a started sandbox",
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
- network.serve({
617
- url: "mem://conformance-read",
618
- sandbox: target,
619
- access: { mode: SandboxAccess.Read, lifecycle: false }
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-only access policy", async () => {
627
- const readOnly = await network.connect({
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 readOnly.readTextFile({ path: `${root}/ro.txt` }) === "visible",
635
- "read failed on a read binding"
715
+ await reader.readTextFile({ path: `${root}/ro.txt` }) === "visible",
716
+ "read failed under a read grant"
636
717
  );
637
- const attempts = [
638
- [
639
- "writeTextFile",
640
- readOnly.writeTextFile({ path: `${root}/ro.txt`, content: "changed" })
641
- ],
642
- ["run", readOnly.run({ command: "echo" })],
643
- ["spawn", readOnly.spawn({ command: "echo" })],
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 binding changed the file"
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
- readOnly.close();
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.handle?.onSandboxDelete({ reason: "conformance" }).catch(() => void 0);
780
+ await started.remove?.();
695
781
  if (args.platform != null && args.provider != null) {
696
782
  await runPlatformCases({
697
783
  kit: args,