runtime.spec.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. import { PassThrough, Writable } from 'node:stream'
  2. import { Context } from 'cordis'
  3. import { describe, expect, it, vi } from 'vitest'
  4. import type { Sandbox } from '@deepseek-ai/dsh-e2b'
  5. import {
  6. E2BFrameDecoder,
  7. encodeE2BFrame,
  8. } from '@deepseek-ai/dsh-e2b'
  9. import type E2BSandboxService from '@deepseek-ai/dsh-e2b'
  10. import type {
  11. SubprocessHandle,
  12. SubprocessOutcome,
  13. SubprocessSpawnSpec,
  14. } from '@deepseek-ai/dsh-subprocess'
  15. import E2BSubprocessService from '@deepseek-ai/dsh-subprocess-e2b'
  16. import {
  17. encodeWorkerJson,
  18. } from '@deepseek-ai/dsh-code-runtime-worker'
  19. import E2BCodeRuntime from '@deepseek-ai/dsh-code-runtime-e2b'
  20. import * as E2BCodeRuntimeInvariant from '../src/invariant.ts'
  21. import { CODE_RUNNER_SOURCE } from '../src/runner-source.ts'
  22. import InvariantService from '@deepseek-ai/dsh-invariants'
  23. class FakeHandle implements SubprocessHandle {
  24. readonly pid = 123
  25. readonly stdin: Writable | undefined
  26. readonly stdout: PassThrough | undefined
  27. readonly stderr = undefined
  28. readonly collected: SubprocessHandle['collected']
  29. readonly done: Promise<SubprocessOutcome>
  30. readonly writes: unknown[] = []
  31. readonly result = Promise.withResolvers<SubprocessOutcome>()
  32. terminated = 0
  33. waitCalls = 0
  34. private readonly decoder = new E2BFrameDecoder(10_000_000)
  35. private readonly waitError: Error | undefined
  36. private settled = false
  37. constructor(
  38. private readonly onMessage: (message: unknown, handle: FakeHandle) => void = () => {},
  39. options: { stdin?: boolean; stdout?: boolean; stderr?: string; writeError?: Error; waitError?: Error } = {},
  40. ) {
  41. this.waitError = options.waitError
  42. this.stdin = options.stdin === false
  43. ? undefined
  44. : options.writeError === undefined
  45. ? new PassThrough()
  46. : new Writable({ write: (_chunk, _encoding, callback) => { callback(options.writeError) } })
  47. this.stdout = options.stdout === false ? undefined : new PassThrough()
  48. this.collected = options.stderr === undefined
  49. ? {}
  50. : { stderr: { readFrom: () => ({ text: options.stderr as string, nextOffset: 0, lossy: false }) } }
  51. this.done = this.result.promise
  52. this.stdin?.on('data', (chunk: Buffer) => {
  53. for (const message of this.decoder.push(chunk.toString('ascii'))) {
  54. this.writes.push(message)
  55. this.onMessage(message, this)
  56. }
  57. })
  58. }
  59. emit(message: unknown): void {
  60. this.stdout?.write(encodeE2BFrame(message))
  61. }
  62. emitRaw(text: string): void {
  63. this.stdout?.write(text)
  64. }
  65. exit(outcome: SubprocessOutcome = { exitCode: 0, signal: null }): void {
  66. if (this.settled) return
  67. this.settled = true
  68. this.stdout?.end()
  69. this.result.resolve(outcome)
  70. }
  71. crash(error: unknown): void {
  72. if (this.settled) return
  73. this.settled = true
  74. this.stdout?.end()
  75. this.result.reject(error)
  76. }
  77. terminate(): void {
  78. this.terminated += 1
  79. this.exit({ exitCode: null, signal: 'SIGTERM' })
  80. }
  81. async waitForExit(): Promise<boolean> {
  82. this.waitCalls += 1
  83. if (this.waitError !== undefined) throw this.waitError
  84. return true
  85. }
  86. }
  87. interface RuntimeFixture {
  88. ctx: Context
  89. fiber: Awaited<ReturnType<Context['plugin']>>
  90. runtime: E2BCodeRuntime
  91. sandbox: Sandbox
  92. spawn: ReturnType<typeof vi.fn<(spec: SubprocessSpawnSpec) => SubprocessHandle>>
  93. write: ReturnType<typeof vi.fn>
  94. run: ReturnType<typeof vi.fn>
  95. }
  96. async function setup(
  97. handles: FakeHandle[] = [],
  98. config: Record<string, number> = {},
  99. sandboxOverrides: Partial<Sandbox> = {},
  100. getSandbox?: () => Promise<Sandbox>,
  101. ): Promise<RuntimeFixture> {
  102. const write = vi.fn().mockResolvedValue([])
  103. const run = vi.fn().mockImplementation(async (command: string) => ({
  104. exitCode: 0,
  105. stdout: command.startsWith('command -v') ? '/usr/bin/node\n' : '',
  106. stderr: '',
  107. }))
  108. const sandbox = {
  109. files: { write },
  110. commands: { run },
  111. ...sandboxOverrides,
  112. } as unknown as Sandbox
  113. const e2b = {
  114. cwd: '/workspace',
  115. runtimeRoot: '/workspace/.dsh-e2b',
  116. getSandbox: getSandbox ?? (async () => sandbox),
  117. } as unknown as E2BSandboxService
  118. const spawn = vi.fn<(spec: SubprocessSpawnSpec) => SubprocessHandle>(() => {
  119. const handle = handles.shift()
  120. if (handle === undefined) throw new Error('no fake handle queued')
  121. return handle
  122. })
  123. const subprocess = Object.create(E2BSubprocessService.prototype) as E2BSubprocessService
  124. Object.defineProperty(subprocess, 'spawn', { value: spawn })
  125. const ctx = new Context()
  126. ctx.provide('e2b', e2b)
  127. ctx.provide('subprocess', subprocess)
  128. const fiber = await ctx.plugin(E2BCodeRuntime, config)
  129. return { ctx, fiber, runtime: ctx.codeRuntime as E2BCodeRuntime, sandbox, spawn, write, run }
  130. }
  131. function request(program = 'return 1') {
  132. return { program, bindings: [] }
  133. }
  134. describe('E2BCodeRuntime', () => {
  135. it('prepares the remote runner and returns logs and a lossless completion', async () => {
  136. const handle = new FakeHandle((message, current) => {
  137. if ((message as { type?: string }).type !== 'boot') return
  138. current.emit({ type: 'log', text: 'remote 你好' })
  139. current.emitRaw(
  140. encodeE2BFrame({ type: 'done', value: encodeWorkerJson({ answer: 42 }) })
  141. + encodeE2BFrame({ type: 'log', text: 'ignored after done' }),
  142. )
  143. current.emit({ type: 'log', text: 'also ignored after done' })
  144. })
  145. const fixture = await setup([handle])
  146. await expect(fixture.runtime.run(request('const answer: number = 42; return { answer }')))
  147. .resolves.toEqual({ logs: ['remote 你好'], value: { answer: 42 } })
  148. expect(fixture.runtime.language).toBe('typescript')
  149. expect(fixture.runtime.isolation).toBe('container')
  150. expect(fixture.write).toHaveBeenCalledWith([{ path: '/workspace/.dsh-e2b/code-runtime-runner.mjs', data: CODE_RUNNER_SOURCE }])
  151. expect(fixture.run).toHaveBeenCalledWith("chmod 600 -- '/workspace/.dsh-e2b/code-runtime-runner.mjs'")
  152. expect(fixture.spawn).toHaveBeenCalledWith(expect.objectContaining({
  153. argv: ['/usr/bin/node', '/workspace/.dsh-e2b/code-runtime-runner.mjs'],
  154. cwd: '/workspace',
  155. env: {},
  156. }))
  157. expect(handle.terminated).toBe(1)
  158. expect(handle.waitCalls).toBe(1)
  159. await fixture.fiber.dispose()
  160. })
  161. it('bridges binding success, host rejection, unknown members, and invalid values', async () => {
  162. const replies: unknown[] = []
  163. const handle = new FakeHandle((message, current) => {
  164. const record = message as { type?: string; id?: number; ok?: boolean }
  165. if (record.type === 'boot') {
  166. current.emit({ type: 'call', id: 1, global: 'bridge', name: 'double', args: encodeWorkerJson({ value: 4 }) })
  167. current.emit({ type: 'call', id: 2, global: 'bridge', name: 'fail', args: encodeWorkerJson(null) })
  168. current.emit({ type: 'call', id: 3, global: 'bridge', name: 'missing', args: encodeWorkerJson(null) })
  169. current.emit({ type: 'call', id: 4, global: 'bridge', name: 'double', args: [] })
  170. current.emit({ type: 'call', id: 5, global: 'bridge', name: 'invalid', args: encodeWorkerJson(null) })
  171. current.emit({ type: 'call', id: 6, global: 'bridge', name: 'throwing', args: encodeWorkerJson(null) })
  172. current.emit({ type: 'call', id: 1, global: 'bridge', name: 'double', args: encodeWorkerJson({ value: 99 }) })
  173. return
  174. }
  175. if (record.type === 'reply') {
  176. replies.push(message)
  177. if (replies.length === 6) current.emit({ type: 'done', value: encodeWorkerJson('done') })
  178. }
  179. })
  180. const fixture = await setup([handle])
  181. const result = await fixture.runtime.run({
  182. program: 'return await bridge.double({ value: 4 })',
  183. bindings: [
  184. {
  185. global: 'bridge',
  186. errorClass: { name: 'BridgeError', memberNameProperty: 'member' },
  187. functions: {
  188. double: async args => (args as { value: number }).value * 2,
  189. fail: async () => { throw 'nope' },
  190. invalid: (async () => undefined) as never,
  191. throwing: async () => Object.defineProperty({}, 'value', {
  192. enumerable: true,
  193. get: () => { throw new Error('getter failed') },
  194. }),
  195. },
  196. },
  197. { global: 'plain', functions: {} },
  198. ],
  199. })
  200. expect(result).toEqual({ logs: [], value: 'done' })
  201. expect(replies.sort((left, right) => (left as { id: number }).id - (right as { id: number }).id)).toEqual([
  202. { type: 'reply', id: 1, ok: true, value: encodeWorkerJson(8) },
  203. { type: 'reply', id: 2, ok: false, message: 'nope' },
  204. { type: 'reply', id: 3, ok: false, message: 'unknown binding "bridge.missing"' },
  205. { type: 'reply', id: 4, ok: false, message: 'binding arguments must be lossless JSON' },
  206. { type: 'reply', id: 5, ok: false, message: 'binding resolution must be lossless JSON' },
  207. { type: 'reply', id: 6, ok: false, message: 'binding resolution must be lossless JSON' },
  208. ])
  209. await fixture.fiber.dispose()
  210. })
  211. it('ignores malformed runner traffic and classifies terminal runner messages', async () => {
  212. const ignored = [
  213. null, 1, {}, { type: 'log' }, { type: 'call' },
  214. { type: 'call', id: 0, global: 'x', name: 'y', args: [] },
  215. { type: 'call', id: 1, global: 1, name: 'y', args: [] },
  216. { type: 'call', id: 1, global: 'x', name: 1, args: [] },
  217. { type: 'call', id: 1, global: 'x', name: 'y', args: {} },
  218. { type: 'done', error: null },
  219. { type: 'done', error: { kind: 'invented', message: 'x' } },
  220. { type: 'done', error: { kind: 'exception', message: 1 } },
  221. ]
  222. const handles = [
  223. new FakeHandle((message, current) => {
  224. if ((message as { type?: string }).type !== 'boot') return
  225. for (const item of ignored) current.emit(item)
  226. current.emit({ type: 'done' })
  227. }),
  228. new FakeHandle((message, current) => {
  229. if ((message as { type?: string }).type === 'boot') current.emit({ type: 'done', error: { kind: 'exception', message: 'boom' } })
  230. }),
  231. new FakeHandle((message, current) => {
  232. if ((message as { type?: string }).type === 'boot') current.emit({ type: 'done', value: [] })
  233. }),
  234. new FakeHandle((message, current) => {
  235. if ((message as { type?: string }).type === 'boot') current.emit({ type: 'output-limit' })
  236. }),
  237. ]
  238. const fixture = await setup(handles, { maxOutputBytes: 64, maxFrameBytes: 128 })
  239. await expect(fixture.runtime.run(request())).resolves.toEqual({ logs: [] })
  240. await expect(fixture.runtime.run(request())).resolves.toEqual({ logs: [], error: { kind: 'exception', message: 'boom' } })
  241. await expect(fixture.runtime.run(request())).resolves.toEqual({ logs: [], error: { kind: 'invalid-output', message: 'program completion must be lossless JSON' } })
  242. await expect(fixture.runtime.run(request())).resolves.toEqual({ logs: [], error: { kind: 'output-limit', message: 'outer output exceeded 64 bytes' } })
  243. await fixture.fiber.dispose()
  244. })
  245. it('enforces the host output ledger and catches malformed bridge output', async () => {
  246. const handles = [
  247. new FakeHandle((message, current) => {
  248. if ((message as { type?: string }).type === 'boot') current.emit({ type: 'log', text: 'x'.repeat(1_000) })
  249. }),
  250. new FakeHandle((message, current) => {
  251. if ((message as { type?: string }).type === 'boot') current.emitRaw('not-base64\n')
  252. }),
  253. new FakeHandle((message, current) => {
  254. if ((message as { type?: string }).type === 'boot') current.emitRaw('é')
  255. }),
  256. new FakeHandle((message, current) => {
  257. if ((message as { type?: string }).type === 'boot') current.stdout?.emit('error', new Error('stdout broke'))
  258. }),
  259. ]
  260. const fixture = await setup(handles, { maxOutputBytes: 128, maxFrameBytes: 4_096 })
  261. expect((await fixture.runtime.run(request())).error?.kind).toBe('output-limit')
  262. const malformed = (await fixture.runtime.run(request())).error
  263. expect(malformed?.kind).toBe('worker-exit')
  264. expect(malformed?.message).toContain('bridge failed')
  265. expect((await fixture.runtime.run(request())).error?.message).toContain('non-ASCII')
  266. expect((await fixture.runtime.run(request())).error).toEqual({ kind: 'worker-exit', message: 'E2B runtime stdout failed: stdout broke' })
  267. await fixture.fiber.dispose()
  268. })
  269. it('contains stdin errors, process exits, spawn failures, and missing pipes', async () => {
  270. const writeError = new FakeHandle(() => {}, { writeError: new Error('write callback broke') })
  271. const stdinError = new FakeHandle((message, current) => {
  272. if ((message as { type?: string }).type === 'boot') current.stdin?.emit('error', new Error('stdin broke'))
  273. })
  274. const earlyExit = new FakeHandle(() => {}, { stderr: 'remote diagnostic' })
  275. const quietExit = new FakeHandle()
  276. const emptyStderrExit = new FakeHandle(() => {}, { stderr: '' })
  277. const spawnFailure = new FakeHandle()
  278. const missingStdin = new FakeHandle(() => {}, { stdin: false })
  279. const missingStdout = new FakeHandle(() => {}, { stdout: false, waitError: new Error('missing-stream process query failed') })
  280. const truncated = new FakeHandle((message, current) => {
  281. if ((message as { type?: string }).type === 'boot') {
  282. current.emitRaw('YQ==')
  283. setImmediate(() => { current.exit() })
  284. }
  285. })
  286. const cleanupFailure = new FakeHandle((message, current) => {
  287. if ((message as { type?: string }).type === 'boot') current.emit({ type: 'done' })
  288. }, { waitError: new Error('process query failed') })
  289. const fixture = await setup([
  290. writeError, stdinError, earlyExit, quietExit, emptyStderrExit,
  291. spawnFailure, missingStdin, missingStdout, truncated, cleanupFailure,
  292. ])
  293. expect((await fixture.runtime.run(request())).error).toEqual({ kind: 'worker-exit', message: 'E2B runtime bridge write failed: write callback broke' })
  294. expect((await fixture.runtime.run(request())).error).toEqual({ kind: 'worker-exit', message: 'E2B runtime stdin failed: stdin broke' })
  295. setImmediate(() => { earlyExit.exit() })
  296. expect((await fixture.runtime.run(request())).error).toEqual({ kind: 'worker-exit', message: 'E2B runtime exited before completing: remote diagnostic' })
  297. setImmediate(() => { quietExit.exit() })
  298. expect((await fixture.runtime.run(request())).error).toEqual({ kind: 'worker-exit', message: 'E2B runtime exited before completing' })
  299. setImmediate(() => { emptyStderrExit.exit() })
  300. expect((await fixture.runtime.run(request())).error).toEqual({ kind: 'worker-exit', message: 'E2B runtime exited before completing' })
  301. setImmediate(() => { spawnFailure.crash('spawn rejected') })
  302. expect((await fixture.runtime.run(request())).error).toEqual({ kind: 'worker-exit', message: 'E2B runtime spawn failed: spawn rejected' })
  303. expect((await fixture.runtime.run(request())).error?.message).toContain('dropped a piped runtime stream')
  304. expect((await fixture.runtime.run(request())).error).toEqual({ kind: 'worker-exit', message: 'E2B runtime cleanup failed: missing-stream process query failed' })
  305. expect(missingStdin.terminated).toBe(1)
  306. expect(missingStdin.waitCalls).toBe(1)
  307. expect(missingStdout.terminated).toBe(1)
  308. expect(missingStdout.waitCalls).toBe(1)
  309. expect((await fixture.runtime.run(request())).error).toEqual({ kind: 'worker-exit', message: 'E2B frame stream ended mid-frame' })
  310. expect((await fixture.runtime.run(request())).error).toEqual({ kind: 'worker-exit', message: 'E2B runtime cleanup failed: process query failed' })
  311. await fixture.fiber.dispose()
  312. })
  313. it('reports wall timeout, abort, pre-abort, type-strip failure, and disposal', async () => {
  314. const timeout = new FakeHandle()
  315. const abort = new FakeHandle()
  316. const disposing = new FakeHandle()
  317. const fixture = await setup([timeout, abort, disposing], { maxWallMs: 20 })
  318. expect((await fixture.runtime.run(request())).error).toEqual({ kind: 'timeout', message: 'wall-clock ceiling reached (20ms)' })
  319. const controller = new AbortController()
  320. const aborting = fixture.runtime.run({ ...request(), signal: controller.signal })
  321. controller.abort('stop')
  322. expect((await aborting).error).toEqual({ kind: 'abort', message: 'stop' })
  323. expect((await fixture.runtime.run({ ...request(), signal: AbortSignal.abort('already') })).error)
  324. .toEqual({ kind: 'abort', message: 'already' })
  325. expect((await fixture.runtime.run(request('enum E { A }'))).error?.kind).toBe('exception')
  326. const live = fixture.runtime.run(request())
  327. await new Promise(resolve => setImmediate(resolve))
  328. await fixture.fiber.dispose()
  329. expect((await live).error).toEqual({ kind: 'abort', message: 'runtime disposed' })
  330. await expect(fixture.runtime.run(request())).rejects.toThrow('after disposal')
  331. })
  332. it('drops binding replies that settle after abort', async () => {
  333. const controller = new AbortController()
  334. const resolution = Promise.withResolvers<string>()
  335. const invoked = Promise.withResolvers<undefined>()
  336. const handle = new FakeHandle((message, current) => {
  337. if ((message as { type?: string }).type === 'boot') {
  338. current.emit({ type: 'call', id: 1, global: 'bridge', name: 'late', args: encodeWorkerJson(null) })
  339. }
  340. })
  341. const fixture = await setup([handle])
  342. const running = fixture.runtime.run({
  343. program: 'return await bridge.late(null)',
  344. bindings: [{
  345. global: 'bridge',
  346. functions: {
  347. late: async () => {
  348. invoked.resolve(undefined)
  349. return await resolution.promise
  350. },
  351. },
  352. }],
  353. signal: controller.signal,
  354. })
  355. await invoked.promise
  356. controller.abort('stop')
  357. expect((await running).error).toEqual({ kind: 'abort', message: 'stop' })
  358. resolution.resolve('late')
  359. await new Promise(resolve => setImmediate(resolve))
  360. expect(handle.writes).toHaveLength(1)
  361. await fixture.fiber.dispose()
  362. })
  363. it('validates binding and runtime configuration before remote execution', async () => {
  364. const fixture = await setup([])
  365. const invalidRequests = [
  366. { global: 'not-valid!', functions: {} },
  367. { global: 'await', functions: {} },
  368. { global: 'console', functions: {} },
  369. { global: 'same', functions: {} },
  370. { global: 'same', functions: {} },
  371. { global: 'ok', functions: {}, errorClass: { name: 'not-valid!', memberNameProperty: 'member' } },
  372. { global: 'ok', functions: {}, errorClass: { name: 'await', memberNameProperty: 'member' } },
  373. { global: 'Clash', functions: {}, errorClass: { name: 'Clash', memberNameProperty: 'member' } },
  374. { global: 'one', functions: {}, errorClass: { name: 'Err', memberNameProperty: 'member' } },
  375. { global: 'two', functions: {}, errorClass: { name: 'Err', memberNameProperty: 'member' } },
  376. { global: 'ok', functions: {}, errorClass: { name: 'Err', memberNameProperty: '' } },
  377. { global: 'ok', functions: {}, errorClass: { name: 'Err', memberNameProperty: 'message' } },
  378. ]
  379. for (const bindings of [
  380. [invalidRequests[0]], [invalidRequests[1]], [invalidRequests[2]],
  381. invalidRequests.slice(3, 5), [invalidRequests[5]], [invalidRequests[6]],
  382. [invalidRequests[7]], invalidRequests.slice(8, 10), [invalidRequests[10]], [invalidRequests[11]],
  383. ]) {
  384. await expect(fixture.runtime.run({ program: 'return 1', bindings: bindings as never })).rejects.toThrow()
  385. }
  386. await fixture.fiber.dispose()
  387. for (const config of [
  388. { computeMs: 0 }, { computeMs: 1.5 }, { maxOutputBytes: 3 },
  389. { maxWallMs: 2_147_483_648 }, { maxFrameBytes: 10, maxOutputBytes: 20 },
  390. ]) {
  391. const ctx = new Context()
  392. const subprocess = Object.create(E2BSubprocessService.prototype) as E2BSubprocessService
  393. ctx.provide('e2b', { getSandbox: async () => ({}) } as never)
  394. ctx.provide('subprocess', subprocess)
  395. await expect(ctx.plugin(E2BCodeRuntime, config)).rejects.toThrow()
  396. }
  397. const wrong = new Context()
  398. wrong.provide('e2b', { getSandbox: async () => ({}) } as never)
  399. wrong.provide('subprocess', {} as never)
  400. await expect(wrong.plugin(E2BCodeRuntime, {})).rejects.toThrow('dsh-subprocess-e2b')
  401. })
  402. it('turns asynchronous runtime preparation failure into a run result', async () => {
  403. const sandbox = {
  404. files: { write: vi.fn().mockRejectedValue(new Error('upload failed')) },
  405. commands: { run: vi.fn() },
  406. } as unknown as Sandbox
  407. const fixture = await setup([], {}, sandbox)
  408. expect((await fixture.runtime.run(request())).error).toEqual({
  409. kind: 'worker-exit',
  410. message: 'E2B runtime setup failed: upload failed',
  411. })
  412. await fixture.fiber.dispose()
  413. })
  414. it('returns disposal when remote preparation completes after teardown', async () => {
  415. const gate = Promise.withResolvers<Sandbox>()
  416. const fixture = await setup([], {}, {}, () => gate.promise)
  417. const running = fixture.runtime.run(request())
  418. await (fixture.runtime as unknown as { teardown(): Promise<void> }).teardown()
  419. gate.resolve(fixture.sandbox)
  420. expect((await running).error).toEqual({ kind: 'abort', message: 'runtime disposed' })
  421. await fixture.fiber.dispose()
  422. })
  423. it('registers the package-owned invariant companion', async () => {
  424. const ctx = new Context()
  425. await ctx.plugin(InvariantService, { enabled: true })
  426. const fiber = await ctx.plugin(E2BCodeRuntimeInvariant).await()
  427. await fiber.dispose()
  428. })
  429. })