@@ -5,12 +5,14 @@ import * as NodeOS from "node:os";
55import * as NodePath from "node:path" ;
66
77import * as NodeServices from "@effect/platform-node/NodeServices" ;
8- import { AuthStandardClientScopes } from "@t3tools/contracts" ;
8+ import { AuthStandardClientScopes , ORCHESTRATION_PROTOCOL_VERSION } from "@t3tools/contracts" ;
99import * as NetService from "@t3tools/shared/Net" ;
1010import * as HostProcess from "@t3tools/shared/HostProcess" ;
1111import { assert , describe , expect , it } from "@effect/vitest" ;
12+ import * as Cause from "effect/Cause" ;
1213import * as ConfigProvider from "effect/ConfigProvider" ;
1314import * as Effect from "effect/Effect" ;
15+ import * as Exit from "effect/Exit" ;
1416import * as Layer from "effect/Layer" ;
1517import * as Sink from "effect/Sink" ;
1618import * as Stream from "effect/Stream" ;
@@ -89,19 +91,21 @@ const testDescriptor = {
8991 label : "pair-test" ,
9092 platform : { os : "linux" , arch : "x64" } ,
9193 serverVersion : "0.0.1" ,
94+ orchestrationProtocolVersion : ORCHESTRATION_PROTOCOL_VERSION ,
9295 capabilities : { repositoryIdentity : true } ,
9396} ;
9497
9598const withDescriptorServer = < A , E , R > (
9699 run : ( origin : string ) => Effect . Effect < A , E , R > ,
97100 host = "127.0.0.1" ,
101+ descriptor : object = testDescriptor ,
98102) =>
99103 Effect . acquireUseRelease (
100104 Effect . callback < NodeHttp . Server > ( ( resume ) => {
101105 const server = NodeHttp . createServer ( ( request , response ) => {
102106 if ( request . url === "/.well-known/t3/environment" ) {
103107 response . writeHead ( 200 , { "content-type" : "application/json" } ) ;
104- response . end ( JSON . stringify ( testDescriptor ) ) ;
108+ response . end ( JSON . stringify ( descriptor ) ) ;
105109 return ;
106110 }
107111 response . writeHead ( 404 ) ;
@@ -328,6 +332,40 @@ describe("t3 pair", () => {
328332 ) . pipe ( Effect . provide ( NodeServices . layer ) ) ,
329333 ) ;
330334
335+ // regression: #15492 an older CLI minted into a V1 database the protocol 2
336+ // server never reads, so pairing must refuse before opening the database.
337+ it . effect ( "rejects a server on another protocol before opening its database" , ( ) =>
338+ withDescriptorServer (
339+ ( origin ) =>
340+ Effect . gen ( function * ( ) {
341+ const baseDir = NodeFS . mkdtempSync (
342+ NodePath . join ( NodeOS . tmpdir ( ) , "t3-pair-protocol-test-" ) ,
343+ ) ;
344+ yield * persistServerRuntimeState ( {
345+ path : NodePath . join ( baseDir , "userdata" , "server-runtime.json" ) ,
346+ state : yield * makePersistedServerRuntimeState ( {
347+ config : { host : "127.0.0.1" , devUrl : undefined } ,
348+ port : Number ( new URL ( origin ) . port ) ,
349+ } ) ,
350+ } ) ;
351+
352+ const exit = yield * provideCliTestLayers (
353+ runCli ( [ "pair" , "--base-dir" , baseDir ] ) . pipe ( Effect . exit ) ,
354+ ) ;
355+
356+ assert . deepEqual ( NodeFS . readdirSync ( NodePath . join ( baseDir , "userdata" ) ) , [
357+ "server-runtime.json" ,
358+ ] ) ;
359+ assert . isTrue ( Exit . isFailure ( exit ) ) ;
360+ if ( Exit . isFailure ( exit ) ) {
361+ assert . include ( String ( Cause . squash ( exit . cause ) ) , "[email protected] pair" ) ; 362+ }
363+ } ) ,
364+ "127.0.0.1" ,
365+ { ...testDescriptor , serverVersion : "0.0.45" , orchestrationProtocolVersion : 1 } ,
366+ ) . pipe ( Effect . provide ( NodeServices . layer ) ) ,
367+ ) ;
368+
331369 // Without the capability `tailscale serve` blocks on an enablement URL, so
332370 // pairing must stop at status instead of spawning it.
333371 it . effect ( "explains a tailnet without HTTPS serve instead of running tailscale serve" , ( ) =>
0 commit comments