|
| 1 | +import { |
| 2 | + DBTCloudProjectIntegration, |
| 3 | + DBTCommandExecutionInfrastructure, |
| 4 | + DBTCommandFactory, |
| 5 | + DBTConfiguration, |
| 6 | + DBTDiagnosticData, |
| 7 | + DBTTerminal, |
| 8 | + DbtCloudVariantDetector, |
| 9 | + DbtIntegrationClient, |
| 10 | + DeferConfig, |
| 11 | + PythonDBTCommandExecutionStrategy, |
| 12 | + PythonEnvironmentProvider, |
| 13 | + RuntimePythonEnvironment, |
| 14 | +} from "@altimateai/dbt-integration"; |
| 15 | +import { describe, expect, it, jest } from "@jest/globals"; |
| 16 | + |
| 17 | +// Documents the runtime contract that Factory<DBTCloudProjectIntegration> must |
| 18 | +// satisfy. The Cloud integration only constructs its engine inside |
| 19 | +// refreshProjectConfig(), and for any non-Fusion variant (including the |
| 20 | +// "no ~/.dbt/dbt_cloud.yml" / "API call failed" case where detect() returns |
| 21 | +// null) it routes through CloudCoreCommandIntegration — which requires |
| 22 | +// coreEngineDependencies to be passed in. Without those, the engine is never |
| 23 | +// constructed and every subsequent dialect call throws "engine not initialized". |
| 24 | + |
| 25 | +const noopTerminal = (): DBTTerminal => |
| 26 | + ({ |
| 27 | + debug: jest.fn(), |
| 28 | + info: jest.fn(), |
| 29 | + warn: jest.fn(), |
| 30 | + error: jest.fn(), |
| 31 | + log: jest.fn(), |
| 32 | + show: jest.fn(), |
| 33 | + }) as unknown as DBTTerminal; |
| 34 | + |
| 35 | +const stubVariantDetectorReturningNull = (): DbtCloudVariantDetector => |
| 36 | + ({ |
| 37 | + detect: jest.fn(async () => null), |
| 38 | + }) as unknown as DbtCloudVariantDetector; |
| 39 | + |
| 40 | +const buildIntegration = (opts: { |
| 41 | + withCoreEngineDeps: boolean; |
| 42 | +}): DBTCloudProjectIntegration => { |
| 43 | + const terminal = noopTerminal(); |
| 44 | + const detector = stubVariantDetectorReturningNull(); |
| 45 | + const onDiagnosticsChanged = () => {}; |
| 46 | + const coreEngineDeps = opts.withCoreEngineDeps |
| 47 | + ? { |
| 48 | + pythonDBTCommandExecutionStrategy: |
| 49 | + {} as unknown as PythonDBTCommandExecutionStrategy, |
| 50 | + dbtConfiguration: {} as unknown as DBTConfiguration, |
| 51 | + dbtIntegrationClient: {} as unknown as DbtIntegrationClient, |
| 52 | + } |
| 53 | + : undefined; |
| 54 | + return new DBTCloudProjectIntegration( |
| 55 | + {} as unknown as DBTCommandExecutionInfrastructure, |
| 56 | + {} as unknown as DBTCommandFactory, |
| 57 | + () => ({}) as never, |
| 58 | + {} as unknown as RuntimePythonEnvironment, |
| 59 | + {} as unknown as PythonEnvironmentProvider, |
| 60 | + terminal, |
| 61 | + "/tmp/project", |
| 62 | + [] as DBTDiagnosticData[], |
| 63 | + {} as DeferConfig, |
| 64 | + onDiagnosticsChanged, |
| 65 | + detector, |
| 66 | + coreEngineDeps, |
| 67 | + ); |
| 68 | +}; |
| 69 | + |
| 70 | +describe("DBTCloudProjectIntegration coreEngineDependencies contract", () => { |
| 71 | + it("createEngine throws on a non-Fusion variant when coreEngineDependencies is omitted (the v0.61.0 regression — Factory<DBTCloudProjectIntegration> must wire these up)", () => { |
| 72 | + const integration = buildIntegration({ withCoreEngineDeps: false }); |
| 73 | + expect(() => |
| 74 | + ( |
| 75 | + integration as unknown as { |
| 76 | + createEngine: () => unknown; |
| 77 | + } |
| 78 | + ).createEngine(), |
| 79 | + ).toThrow(/cannot construct CloudCoreCommandIntegration/); |
| 80 | + }); |
| 81 | + |
| 82 | + it("createEngine clears the coreEngineDependencies guard once they are provided", () => { |
| 83 | + // Pinpoints the guard at the top of createEngine. Construction past the |
| 84 | + // guard reaches into CloudCoreCommandIntegration's super-chain which needs |
| 85 | + // real DBTCommandExecutionInfrastructure / RuntimePythonEnvironment |
| 86 | + // wiring; here we only prove the missing-deps gate is no longer hit. |
| 87 | + const integration = buildIntegration({ withCoreEngineDeps: true }); |
| 88 | + expect(() => |
| 89 | + ( |
| 90 | + integration as unknown as { |
| 91 | + createEngine: () => unknown; |
| 92 | + } |
| 93 | + ).createEngine(), |
| 94 | + ).not.toThrow(/cannot construct CloudCoreCommandIntegration/); |
| 95 | + }); |
| 96 | +}); |
0 commit comments