Skip to content

Commit a5be568

Browse files
fix: update metadata plugin tests to match refactored start() implementation
Tests now verify setDataEngine (via getService('objectql')) instead of the removed setDatabaseDriver (via getServices()) pattern. Added setDataEngine and setRealtimeService to the NodeMetadataManager mock class. Agent-Logs-Url: https://github.com/objectstack-ai/framework/sessions/eab49cb9-b023-444c-a757-c12cfac1d136 Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
1 parent 1f54410 commit a5be568

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
- **Metadata plugin tests** — Updated `MetadataPlugin` test suite in `packages/metadata/src/metadata.test.ts` to match the refactored `start()` implementation. Tests now verify `setDataEngine` (via `getService('objectql')`) instead of the removed `setDatabaseDriver` (via `getServices()`) pattern. Also added `setDataEngine` and `setRealtimeService` to the `NodeMetadataManager` mock class.
12+
1013
### Added
1114
- **Claude Code integration (`CLAUDE.md`)** — Added root `CLAUDE.md` file so that [Claude Code](https://docs.anthropic.com/en/docs/claude-code) automatically loads the project's system prompt when launched in the repository. Content is synced with `.github/copilot-instructions.md` and includes build/test quick-reference commands, all prime directives, monorepo structure, protocol domains, coding patterns, and domain-specific prompt references. This complements the existing GitHub Copilot instructions and `skills/` directory.
1215

packages/metadata/src/metadata.test.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,8 @@ describe('MetadataPlugin', () => {
490490
stopWatching = vi.fn();
491491
setTypeRegistry = vi.fn();
492492
setDatabaseDriver = vi.fn();
493+
setDataEngine = vi.fn();
494+
setRealtimeService = vi.fn();
493495
register = vi.fn();
494496
};
495497
return { NodeMetadataManager: MockNodeMetadataManager };
@@ -533,80 +535,82 @@ describe('MetadataPlugin', () => {
533535
expect(ctx.logger.info).toHaveBeenCalled();
534536
});
535537

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

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);
542+
const mockObjectQL = { find: vi.fn(), create: vi.fn(), update: vi.fn() };
543543

544544
const ctx = createMockPluginContext();
545-
ctx.getServices = vi.fn().mockReturnValue(services);
545+
ctx.getService = vi.fn().mockImplementation((name: string) => {
546+
if (name === 'objectql') return mockObjectQL;
547+
return null;
548+
});
546549

547550
await plugin.init(ctx);
548551
await plugin.start(ctx);
549552

550-
// Verify setDatabaseDriver was called on the manager with the driver
553+
// Verify setDataEngine was called on the manager with the ObjectQL engine
551554
const manager = (plugin as any).manager;
552-
expect(manager.setDatabaseDriver).toHaveBeenCalledWith(mockDriver);
555+
expect(manager.setDataEngine).toHaveBeenCalledWith(mockObjectQL);
553556
});
554557

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

559562
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);
563+
const mockObjectQL = { find: vi.fn(), create: vi.fn(), update: vi.fn() };
563564

564565
const manager = (plugin as any).manager;
565566
manager.loadMany = vi.fn().mockImplementation(async () => {
566567
callOrder.push('loadMany');
567568
return [];
568569
});
569-
manager.setDatabaseDriver = vi.fn().mockImplementation(() => {
570-
callOrder.push('setDatabaseDriver');
570+
manager.setDataEngine = vi.fn().mockImplementation(() => {
571+
callOrder.push('setDataEngine');
571572
});
572573

573574
const ctx = createMockPluginContext();
574-
ctx.getServices = vi.fn().mockReturnValue(services);
575+
ctx.getService = vi.fn().mockImplementation((name: string) => {
576+
if (name === 'objectql') return mockObjectQL;
577+
return null;
578+
});
575579

576580
await plugin.init(ctx);
577581
await plugin.start(ctx);
578582

579-
// setDatabaseDriver must be called after all loadMany calls
583+
// setDataEngine must be called after all loadMany calls
580584
const lastLoad = callOrder.lastIndexOf('loadMany');
581-
const driverIdx = callOrder.indexOf('setDatabaseDriver');
585+
const driverIdx = callOrder.indexOf('setDataEngine');
582586
expect(driverIdx).toBeGreaterThan(lastLoad);
583587
});
584588

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

589593
const ctx = createMockPluginContext();
590-
ctx.getServices = vi.fn().mockReturnValue(new Map());
594+
// getService returns null by default — no objectql available
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

601-
it('should gracefully handle getServices errors', async () => {
605+
it('should gracefully handle getService errors', async () => {
602606
const { MetadataPlugin } = await import('./plugin.js');
603607
const plugin = new MetadataPlugin({ rootDir: '/tmp/test', watch: false });
604608

605609
const ctx = createMockPluginContext();
606-
ctx.getServices = vi.fn().mockImplementation(() => { throw new Error('services unavailable'); });
610+
ctx.getService = vi.fn().mockImplementation(() => { throw new Error('service unavailable'); });
607611

608612
await plugin.init(ctx);
609-
// Should not throw even when getServices fails
613+
// Should not throw even when getService fails
610614
await expect(plugin.start(ctx)).resolves.not.toThrow();
611615
});
612616
});

0 commit comments

Comments
 (0)