module scheme import arena import os fn nested_first_goops_use(mut instance BoundedVM, alternate bool) !Value { if alternate { return instance.eval_alt('class-name(class-of(1))') } return instance.eval('(class-name (class-of 1))') } fn test_nested_first_goops_denial_quarantines_both_frontends_and_closes_owned_files() { for alternate in [false, true] { path := os.join_path(os.temp_dir(), 'vile-goops-nested428-${os.getpid()}-${alternate}.txt') defer { os.rm(path) or {} } mut instance := new_bounded(Options{max_open_files: 1}, arena.ChunkLimits{max_live_bytes: 512 * 1024}) or { panic(err) } defer { instance.close() or { panic(err) } } instance.eval('(define sink (open-output-file "${path}"))') or { panic(err) } assert instance.vm.goops.deferred stream := instance.files.head.stream assert stream.file.is_opened if _ := nested_first_goops_use(mut instance, alternate) { panic('GOOPS initialization exceeded its hard budget') } else { assert err is ResourceLimitRequest if err is ResourceLimitRequest { assert err.kind == .vm_chunk_bytes } } assert instance.vm.goops.bootstrap_failed && !instance.vm.goops.starting assert instance.state == .failed && !stream.file.is_opened && isnil(instance.files.head) if _ := instance.eval('42') { panic('reused partial nested bootstrap metadata') } } } fn test_host_publication_first_goops_denial_disables_further_bounded_callbacks() { mut instance := new_bounded(Options{}, arena.ChunkLimits{max_live_bytes: 256 * 1024}) or { panic(err) } defer { instance.close() or { panic(err) } } assert instance.vm.goops.deferred if _ := instance.run(fn (mut vm VM) !Value { vm.define('class-of', integer(7))! return unspecified() }) { panic('host publication exceeded its hard GOOPS initialization budget') } else { assert err is ResourceLimitRequest if err is ResourceLimitRequest { assert err.kind == .vm_chunk_bytes } } assert instance.vm.goops.bootstrap_failed && !instance.vm.goops.starting if _ := instance.run(fn (mut _vm VM) !Value { return integer(7) }) { panic('host callback ran on a partially initialized bounded VM') } } fn test_handled_publication_error_still_reports_bootstrap_exhaustion_to_the_handle() { mut instance := new_bounded(Options{}, arena.ChunkLimits{max_live_bytes: 256 * 1024}) or { panic(err) } defer { instance.close() or { panic(err) } } if _ := instance.run(fn (mut vm VM) !Value { vm.define('class-of', integer(7)) or {} return integer(99) }) { panic('handled error concealed an interrupted GOOPS bootstrap') } else { assert err is ResourceLimitRequest if err is ResourceLimitRequest { assert err.kind == .vm_chunk_bytes } } assert instance.state == .failed if _ := instance.run(fn (mut _vm VM) !Value { return integer(7) }) { panic('host callback ran after handled bootstrap exhaustion') } }