@@ -7,6 +7,8 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
77import * as Effect from "effect/Effect" ;
88import * as FileSystem from "effect/FileSystem" ;
99import * as Path from "effect/Path" ;
10+ import * as Stream from "effect/Stream" ;
11+ import { ChildProcess , ChildProcessSpawner } from "effect/process" ;
1012import { describe , expect } from "vite-plus/test" ;
1113
1214import {
@@ -15,6 +17,65 @@ import {
1517} from "./DesktopTelemetryReceiver.ts" ;
1618
1719describe ( "DesktopTelemetryReceiver" , ( ) => {
20+ it . live (
21+ "preserves system and bundled roots when the first snapshot withdraws overlapping extras" ,
22+ ( ) =>
23+ Effect . gen ( function * ( ) {
24+ const fs = yield * FileSystem . FileSystem ;
25+ const path = yield * Path . Path ;
26+ const spawner = yield * ChildProcessSpawner . ChildProcessSpawner ;
27+ const directory = yield * fs . makeTempDirectoryScoped ( ) ;
28+ const certificatePath = path . join ( directory , "startup-extra-ca.pem" ) ;
29+ yield * fs . writeFileString (
30+ certificatePath ,
31+ [ ...NodeTls . getCACertificates ( "system" ) , ...NodeTls . rootCertificates ] . join ( "\n" ) ,
32+ ) ;
33+ const child = yield * spawner . spawn (
34+ ChildProcess . make (
35+ process . execPath ,
36+ [
37+ "--use-bundled-ca" ,
38+ "--use-system-ca" ,
39+ "--input-type=module" ,
40+ "--eval" ,
41+ `
42+ import * as NodeAssert from "node:assert/strict";
43+ import * as NodeCrypto from "node:crypto";
44+ import * as NodeTls from "node:tls";
45+ import * as Effect from "effect/Effect";
46+ import * as NodeServices from "@effect/platform-node/NodeServices";
47+ import { makeApplyDesktopShellEnvironmentSnapshot } from ${ JSON . stringify ( new URL ( "./DesktopTelemetryReceiver.ts" , import . meta. url ) . href ) } ;
48+ const fingerprints = (certificates) => [...new Set(certificates.map((pem) => new NodeCrypto.X509Certificate(pem).fingerprint256))].sort();
49+ const expected = fingerprints([...NodeTls.getCACertificates("bundled"), ...NodeTls.getCACertificates("system")]);
50+ const applySnapshot = makeApplyDesktopShellEnvironmentSnapshot(process.env, process.platform);
51+ await Effect.runPromise(applySnapshot({
52+ version: 1,
53+ type: "shellEnvironment",
54+ platform: process.platform,
55+ discovered: true,
56+ environment: { NODE_EXTRA_CA_CERTS: null },
57+ }).pipe(Effect.provide(NodeServices.layer)));
58+ NodeAssert.equal(process.env.NODE_EXTRA_CA_CERTS, undefined);
59+ NodeAssert.deepEqual(fingerprints(NodeTls.getCACertificates("default")), expected);
60+ ` ,
61+ ] ,
62+ {
63+ cwd : path . resolve ( import . meta. dirname , "../.." ) ,
64+ env : { NODE_OPTIONS : "" , NODE_EXTRA_CA_CERTS : certificatePath } ,
65+ } ,
66+ ) ,
67+ ) ;
68+ const result = yield * Effect . all (
69+ {
70+ stderr : child . stderr . pipe ( Stream . decodeText ( ) , Stream . mkString ) ,
71+ exitCode : child . exitCode . pipe ( Effect . map ( Number ) ) ,
72+ } ,
73+ { concurrency : "unbounded" } ,
74+ ) ;
75+ expect ( result . exitCode , result . stderr ) . toBe ( 0 ) ;
76+ } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
77+ ) ;
78+
1879 it . effect ( "updates live TLS trust when shell certificates arrive after startup" , ( ) =>
1980 Effect . gen ( function * ( ) {
2081 const fs = yield * FileSystem . FileSystem ;
0 commit comments