11import '@ocap/shims/endoify' ;
2- import { kunser } from '@ocap/kernel' ;
2+ import { Kernel , kunser } from '@ocap/kernel' ;
3+ import type { KernelDatabase } from '@ocap/store' ;
34import { makeSQLKernelDatabase } from '@ocap/store/sqlite/nodejs' ;
45import { waitUntilQuiescent } from '@ocap/utils' ;
5- import { describe , expect , it } from 'vitest' ;
6+ import { beforeEach , describe , expect , it } from 'vitest' ;
67
78import {
89 extractVatLogs ,
@@ -33,18 +34,23 @@ const testSubcluster = {
3334} ;
3435
3536describe ( 'virtual objects functionality' , async ( ) => {
36- it ( 'successfully creates and uses exo objects and scalar stores' , async ( ) => {
37- const kernelDatabase = await makeSQLKernelDatabase ( {
37+ let kernel : Kernel ;
38+ let kernelDatabase : KernelDatabase ;
39+ let bootstrapResult : unknown ;
40+
41+ beforeEach ( async ( ) => {
42+ kernelDatabase = await makeSQLKernelDatabase ( {
3843 dbFilename : ':memory:' ,
3944 } ) ;
40- const kernel = await makeKernel ( kernelDatabase , true ) ;
45+ kernel = await makeKernel ( kernelDatabase , true ) ;
4146 buffered = '' ;
47+ bootstrapResult = await runTestVats ( kernel , testSubcluster ) ;
48+ await waitUntilQuiescent ( ) ;
49+ } ) ;
4250
43- const bootstrapResult = await runTestVats ( kernel , testSubcluster ) ;
51+ it ( 'successfully creates and uses exo objects and scalar stores' , async ( ) => {
4452 expect ( bootstrapResult ) . toBe ( 'exo-test-complete' ) ;
45- await waitUntilQuiescent ( ) ;
4653 const vatLogs = extractVatLogs ( buffered ) ;
47-
4854 // Verify exo objects were created and used
4955 expect ( vatLogs ) . toContain ( 'ExoTest: initializing state' ) ;
5056 expect ( vatLogs ) . toContain ( 'ExoTest: counter value from baggage: 0' ) ;
@@ -70,24 +76,12 @@ describe('virtual objects functionality', async () => {
7076 } , 30000 ) ;
7177
7278 it ( 'preserves state across vat restarts' , async ( ) => {
73- const kernelDatabase = await makeSQLKernelDatabase ( {
74- dbFilename : ':memory:' ,
75- } ) ;
76- const kernel = await makeKernel ( kernelDatabase , true ) ;
77- buffered = '' ;
78-
79- // Run the test vat first time
80- await runTestVats ( kernel , testSubcluster ) ;
81- await waitUntilQuiescent ( ) ;
8279 // Restart the vat
8380 await kernel . restartVat ( 'v1' ) ;
8481 buffered = '' ;
85-
8682 // Create and send a message to the root
8783 await kernel . queueMessageFromKernel ( 'ko1' , 'resume' , [ ] ) ;
8884 await waitUntilQuiescent ( ) ;
89-
90- // Extract logs to verify operations worked correctly
9185 const vatLogs = extractVatLogs ( buffered ) ;
9286 // Verify state was preserved
9387 expect ( vatLogs ) . toContain ( 'ExoTest: state already initialized' ) ;
@@ -98,24 +92,13 @@ describe('virtual objects functionality', async () => {
9892 } , 30000 ) ;
9993
10094 it ( 'tests scalar store functionality' , async ( ) => {
101- const kernelDatabase = await makeSQLKernelDatabase ( {
102- dbFilename : ':memory:' ,
103- } ) ;
104- const kernel = await makeKernel ( kernelDatabase , true ) ;
105-
106- // Run the test vat
107- await runTestVats ( kernel , testSubcluster ) ;
108- await waitUntilQuiescent ( ) ;
109- buffered = '' ;
110-
11195 const storeResult = await kernel . queueMessageFromKernel (
11296 'ko1' ,
11397 'testScalarStore' ,
11498 [ ] ,
11599 ) ;
116100 await waitUntilQuiescent ( ) ;
117101 const vatLogs = extractVatLogs ( buffered ) ;
118-
119102 // Verify test result
120103 expect ( kunser ( storeResult ) ) . toBe ( 'scalar-store-tests-complete' ) ;
121104 // Verify map store operations
@@ -128,16 +111,6 @@ describe('virtual objects functionality', async () => {
128111 } , 30000 ) ;
129112
130113 it ( 'can create and use objects through messaging' , async ( ) => {
131- const kernelDatabase = await makeSQLKernelDatabase ( {
132- dbFilename : ':memory:' ,
133- } ) ;
134- const kernel = await makeKernel ( kernelDatabase , true ) ;
135-
136- // Run the test vat
137- await runTestVats ( kernel , testSubcluster ) ;
138- await waitUntilQuiescent ( ) ;
139- buffered = '' ;
140-
141114 // Create a counter through messaging
142115 const counterResult = await kernel . queueMessageFromKernel (
143116 'ko1' ,
0 commit comments