Skip to content

Commit dd8f5c9

Browse files
Claudehotlong
andauthored
fix: update metadata plugin tests after ObjectQL engine refactor
- Update tests to use setDataEngine instead of setDatabaseDriver - Fix Studio usePackages hook to import useClient from @objectstack/client-react - Fix plugin-dev tsconfig to avoid parent exclude pattern conflicts All tests now passing after merging latest changes from main. Agent-Logs-Url: https://github.com/objectstack-ai/framework/sessions/95de72a8-ec40-4b5c-a2c6-8f8a9c9f0e1a Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 12f00d9 commit dd8f5c9

File tree

4 files changed

+736
-31
lines changed

4 files changed

+736
-31
lines changed

apps/studio/src/hooks/usePackages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import { useState, useEffect } from 'react';
4-
import { useObjectStackClient as useClient } from '@objectstack/client-react';
4+
import { useClient } from '@objectstack/client-react';
55
import type { InstalledPackage } from '@objectstack/spec/kernel';
66

77
/**

packages/metadata/src/metadata.test.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ describe('MetadataPlugin', () => {
490490
stopWatching = vi.fn();
491491
setTypeRegistry = vi.fn();
492492
setDatabaseDriver = vi.fn();
493+
setDataEngine = vi.fn();
493494
register = vi.fn();
494495
};
495496
return { NodeMetadataManager: MockNodeMetadataManager };
@@ -533,69 +534,72 @@ describe('MetadataPlugin', () => {
533534
expect(ctx.logger.info).toHaveBeenCalled();
534535
});
535536

536-
it('should bridge driver service to MetadataManager in start()', async () => {
537+
it('should bridge ObjectQL engine to MetadataManager in start()', async () => {
537538
const { MetadataPlugin } = await import('./plugin.js');
538539
const plugin = new MetadataPlugin({ rootDir: '/tmp/test', watch: false });
539540

540-
const mockDriver = { name: 'mock-driver', find: vi.fn(), create: vi.fn() };
541-
const services = new Map<string, any>();
542-
services.set('driver.mock-driver', mockDriver);
543-
541+
const mockObjectQL = { name: 'objectql', find: vi.fn(), create: vi.fn() };
544542
const ctx = createMockPluginContext();
545-
ctx.getServices = vi.fn().mockReturnValue(services);
543+
ctx.getService = vi.fn().mockImplementation((serviceName: string) => {
544+
if (serviceName === 'objectql') return mockObjectQL;
545+
throw new Error(`Service ${serviceName} not found`);
546+
});
546547

547548
await plugin.init(ctx);
548549
await plugin.start(ctx);
549550

550-
// Verify setDatabaseDriver was called on the manager with the driver
551+
// Verify setDataEngine was called on the manager with ObjectQL
551552
const manager = (plugin as any).manager;
552-
expect(manager.setDatabaseDriver).toHaveBeenCalledWith(mockDriver);
553+
expect(manager.setDataEngine).toHaveBeenCalledWith(mockObjectQL);
553554
});
554555

555-
it('should bridge driver AFTER filesystem metadata loading', async () => {
556+
it('should bridge ObjectQL AFTER filesystem metadata loading', async () => {
556557
const { MetadataPlugin } = await import('./plugin.js');
557558
const plugin = new MetadataPlugin({ rootDir: '/tmp/test', watch: false });
558559

559560
const callOrder: string[] = [];
560-
const mockDriver = { name: 'mock-driver', find: vi.fn(), create: vi.fn() };
561-
const services = new Map<string, any>();
562-
services.set('driver.mock-driver', mockDriver);
561+
const mockObjectQL = { name: 'objectql', find: vi.fn(), create: vi.fn() };
563562

564563
const manager = (plugin as any).manager;
565564
manager.loadMany = vi.fn().mockImplementation(async () => {
566565
callOrder.push('loadMany');
567566
return [];
568567
});
569-
manager.setDatabaseDriver = vi.fn().mockImplementation(() => {
570-
callOrder.push('setDatabaseDriver');
568+
manager.setDataEngine = vi.fn().mockImplementation(() => {
569+
callOrder.push('setDataEngine');
571570
});
572571

573572
const ctx = createMockPluginContext();
574-
ctx.getServices = vi.fn().mockReturnValue(services);
573+
ctx.getService = vi.fn().mockImplementation((serviceName: string) => {
574+
if (serviceName === 'objectql') return mockObjectQL;
575+
throw new Error(`Service ${serviceName} not found`);
576+
});
575577

576578
await plugin.init(ctx);
577579
await plugin.start(ctx);
578580

579-
// setDatabaseDriver must be called after all loadMany calls
581+
// setDataEngine must be called after all loadMany calls
580582
const lastLoad = callOrder.lastIndexOf('loadMany');
581-
const driverIdx = callOrder.indexOf('setDatabaseDriver');
582-
expect(driverIdx).toBeGreaterThan(lastLoad);
583+
const engineIdx = callOrder.indexOf('setDataEngine');
584+
expect(engineIdx).toBeGreaterThan(lastLoad);
583585
});
584586

585-
it('should not fail when no driver service is available', async () => {
587+
it('should not fail when no ObjectQL service is available', async () => {
586588
const { MetadataPlugin } = await import('./plugin.js');
587589
const plugin = new MetadataPlugin({ rootDir: '/tmp/test', watch: false });
588590

589591
const ctx = createMockPluginContext();
590-
ctx.getServices = vi.fn().mockReturnValue(new Map());
592+
ctx.getService = vi.fn().mockImplementation((serviceName: string) => {
593+
throw new Error(`Service ${serviceName} not found`);
594+
});
591595

592596
await plugin.init(ctx);
593597
// Should not throw
594598
await expect(plugin.start(ctx)).resolves.not.toThrow();
595599

596-
// setDatabaseDriver should not have been called
600+
// setDataEngine should not have been called
597601
const manager = (plugin as any).manager;
598-
expect(manager.setDatabaseDriver).not.toHaveBeenCalled();
602+
expect(manager.setDataEngine).not.toHaveBeenCalled();
599603
});
600604

601605
it('should gracefully handle getServices errors', async () => {

packages/plugins/plugin-dev/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@
99
},
1010
"include": [
1111
"src"
12+
],
13+
"exclude": [
14+
"node_modules",
15+
"dist"
1216
]
1317
}

0 commit comments

Comments
 (0)