import { Test } from '@nestjs/testing'; import { describe, expect, it } from 'vitest'; import { MeshService } from '../mesh/mesh.service.js'; import { CommandModule } from './command.module.js'; import { CommandService } from './command.service.js'; describe('DI wiring (module graph)', () => { // compile() instantiates providers but does not run lifecycle hooks, so no TCP connection is opened. it('resolves CommandService with MeshService provided by MeshModule', async () => { process.env.MESH_DB_PATH = ':memory:'; // keep openMessageDb from touching the repo's ./data const moduleRef = await Test.createTestingModule({ imports: [CommandModule], }).compile(); expect(moduleRef.get(CommandService)).toBeInstanceOf(CommandService); expect(moduleRef.get(MeshService)).toBeInstanceOf(MeshService); }); // the MeshService <-> CommandService cycle must resolve to live references on both sides, not undefined it('wires both sides of the circular dependency with real instances', async () => { process.env.MESH_DB_PATH = ':memory:'; const moduleRef = await Test.createTestingModule({ imports: [CommandModule], }).compile(); const mesh = moduleRef.get(MeshService); const commands = moduleRef.get(CommandService); expect((commands as unknown as { mesh?: MeshService }).mesh).toBe(mesh); expect((mesh as unknown as { commands?: CommandService }).commands).toBe( commands, ); }); });