11// Qa Lab tests cover qa transport registry plugin behavior.
2- import { describe , expect , it } from "vitest" ;
3- import { normalizeQaTransportId } from "./qa-transport-registry.js" ;
2+ import { describe , expect , it , vi } from "vitest" ;
3+ import { createQaBusState } from "./bus-state.js" ;
4+ import { createQaChannelTransport } from "./qa-channel-transport.js" ;
5+ import {
6+ createQaTransportAdapter ,
7+ createQaTransportAdapterFactoryRegistry ,
8+ normalizeQaTransportId ,
9+ type QaTransportAdapterFactory ,
10+ type QaTransportFactoryContext ,
11+ } from "./qa-transport-registry.js" ;
12+ import type { QaTransportAdapter } from "./qa-transport.js" ;
13+
14+ function createFactoryContext (
15+ overrides : Partial < QaTransportFactoryContext > = { } ,
16+ ) : QaTransportFactoryContext {
17+ return {
18+ channelId : "qa-channel" ,
19+ driver : "qa-channel" ,
20+ outputDir : ".artifacts/qa-e2e/transport-contract-test" ,
21+ state : createQaBusState ( ) ,
22+ ...overrides ,
23+ } ;
24+ }
425
526describe ( "qa transport registry" , ( ) => {
627 it ( "rejects inherited prototype keys as unsupported transport ids" , ( ) => {
@@ -9,4 +30,68 @@ describe("qa transport registry", () => {
930 "unsupported QA transport: __proto__" ,
1031 ) ;
1132 } ) ;
33+
34+ it ( "creates QA Channel through the default async registry" , async ( ) => {
35+ const created = await createQaTransportAdapter ( createFactoryContext ( ) ) ;
36+
37+ expect ( created . adapter . id ) . toBe ( "qa-channel" ) ;
38+ await created . cleanup ( ) ;
39+ } ) ;
40+
41+ it ( "selects an injected matching factory" , async ( ) => {
42+ const adapter = createQaChannelTransport ( createQaBusState ( ) ) ;
43+ const skippedCreate = vi . fn ( async ( ) => adapter ) ;
44+ const selectedCreate = vi . fn ( async ( ) => adapter ) ;
45+ const factories : QaTransportAdapterFactory [ ] = [
46+ { id : "skipped" , matches : ( ) => false , create : skippedCreate } ,
47+ { id : "selected" , matches : ( ) => true , create : selectedCreate } ,
48+ ] ;
49+ const registry = createQaTransportAdapterFactoryRegistry ( factories ) ;
50+
51+ const created = await registry . create ( createFactoryContext ( ) ) ;
52+
53+ expect ( created . adapter ) . toBe ( adapter ) ;
54+ expect ( skippedCreate ) . not . toHaveBeenCalled ( ) ;
55+ expect ( selectedCreate ) . toHaveBeenCalledOnce ( ) ;
56+ } ) ;
57+
58+ it ( "returns cleanup owned by the selected adapter" , async ( ) => {
59+ const cleanup = vi . fn ( async ( ) => undefined ) ;
60+ const adapter : QaTransportAdapter = createQaChannelTransport ( createQaBusState ( ) ) ;
61+ adapter . cleanup = cleanup ;
62+ const factory : QaTransportAdapterFactory = {
63+ id : "cleanup" ,
64+ matches : ( ) => true ,
65+ async create ( ) {
66+ return adapter ;
67+ } ,
68+ } ;
69+ const registry = createQaTransportAdapterFactoryRegistry ( [ factory ] ) ;
70+ const created = await registry . create ( createFactoryContext ( ) ) ;
71+
72+ await created . cleanup ( ) ;
73+
74+ expect ( cleanup ) . toHaveBeenCalledOnce ( ) ;
75+ } ) ;
76+
77+ it ( "reports no-match and startup failures with transport context" , async ( ) => {
78+ const context = createFactoryContext ( ) ;
79+ const emptyRegistry = createQaTransportAdapterFactoryRegistry ( [ ] ) ;
80+ await expect ( emptyRegistry . create ( context ) ) . rejects . toThrow (
81+ "no QA transport factory for qa-channel:qa-channel" ,
82+ ) ;
83+
84+ const brokenRegistry = createQaTransportAdapterFactoryRegistry ( [
85+ {
86+ id : "broken" ,
87+ matches : ( ) => true ,
88+ async create ( ) {
89+ throw new Error ( "provider boot failed" ) ;
90+ } ,
91+ } ,
92+ ] ) ;
93+ await expect ( brokenRegistry . create ( context ) ) . rejects . toThrow (
94+ "broken failed to create QA transport qa-channel:qa-channel: provider boot failed" ,
95+ ) ;
96+ } ) ;
1297} ) ;
0 commit comments