Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions apps/console/src/mocks/createKernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ export interface KernelOptions {
skipSystemValidation?: boolean;
/** MSWPlugin options; when provided, MSWPlugin is added to the kernel. */
mswOptions?: MSWPluginOptions;
/**
* InMemoryDriver persistence configuration.
*
* - `'auto'` (default) — auto-detect environment (browser → localStorage, Node.js → file)
* - `'local'` — force localStorage persistence (browser only)
* - `false` — disable persistence entirely (useful in tests)
*
* When omitted, defaults to `'auto'`.
*/
persistence?: false | 'auto' | 'local' | 'file';
Comment on lines +28 to +37
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSDoc for persistence lists auto, local, and false, but the type also allows 'file'. Either document the 'file' mode in the comment (including when it’s valid) or remove it from the union to keep the API contract consistent.

Copilot uses AI. Check for mistakes.
}

export interface KernelResult {
Expand Down Expand Up @@ -154,9 +164,11 @@ function patchDriverCreate(driver: InMemoryDriver): void {
* so that kernel setup logic is not duplicated.
*/
export async function createKernel(options: KernelOptions): Promise<KernelResult> {
const { appConfig, skipSystemValidation = true, mswOptions } = options;
const { appConfig, skipSystemValidation = true, mswOptions, persistence } = options;

const driver = new InMemoryDriver();
const driver = new InMemoryDriver(
persistence !== undefined ? { persistence } : undefined,
);

const kernel = new ObjectKernel({
skipSystemValidation
Expand Down Expand Up @@ -190,5 +202,16 @@ export async function createKernel(options: KernelOptions): Promise<KernelResult
await installBrokerShim(kernel);
}

// Initialise persistence adapter and load any previously persisted data.
// On first load this is a no-op (empty localStorage); on subsequent page
// refreshes the persisted data overwrites the seed data so that user
// changes survive a browser reload.
await driver.connect();

// Ensure the current database state (seed data on first load, or the
// just-restored persisted snapshot) is flushed to the persistence layer
// so that localStorage always contains the latest data.
await driver.flush();

return { kernel, driver, mswPlugin };
}
1 change: 1 addition & 0 deletions apps/console/src/mocks/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export async function startMockServer() {

const result = await createKernel({
appConfig,
persistence: false,
mswOptions: {
enableBrowser: false,
baseUrl: '/api/v1',
Expand Down