From 22975e5da5916992b4950191b6627b4be8525375 Mon Sep 17 00:00:00 2001 From: KiriAky 107 Date: Tue, 8 Sep 2026 20:02:30 +0800 Subject: [PATCH] =?UTF-8?q?test(core):=20=E4=BD=BF=E7=94=A8=E9=9A=94?= =?UTF-8?q?=E7=A6=BB=E4=BC=9A=E8=AF=9D=E9=AA=8C=E8=AF=81=E4=BA=8C=E5=8D=81?= =?UTF-8?q?=E6=AC=A1=E6=89=93=E5=8C=85=E5=86=B7=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src-tauri/tests/core_bundle.rs | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/frontend/src-tauri/tests/core_bundle.rs b/frontend/src-tauri/tests/core_bundle.rs index 1e8240b..1cafade 100644 --- a/frontend/src-tauri/tests/core_bundle.rs +++ b/frontend/src-tauri/tests/core_bundle.rs @@ -19,3 +19,55 @@ fn bundle_rejects_modified_missing_and_extra_files() { std::fs::remove_file(file).unwrap(); assert!(verify_bundle(dir.path(), manifest).is_err()); } + +#[test] +#[ignore = "requires scripts/build-core.py; run explicitly after building the isolated Core"] +fn packaged_core_twenty_cold_starts_use_isolated_data_and_rotate_sessions() { + use notesagent_host::core::CoreSupervisor; + use std::{ + collections::HashSet, + io::{Read, Write}, + path::Path, + time::Duration, + }; + let output = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.build/sidecar"); + let bundle = output.join("dist/opennexus-core").canonicalize().unwrap(); + let manifest = std::fs::read_to_string(output.join("manifest.json")).unwrap(); + let executable = bundle.join(if cfg!(windows) { + "opennexus-core.exe" + } else { + "opennexus-core" + }); + let temp = tempfile::tempdir().unwrap(); + let mut generations = HashSet::new(); + for attempt in 0..20 { + let mut core = CoreSupervisor::new( + executable.clone(), + vec![], + bundle.clone(), + temp.path().join(format!("run-{attempt}")), + ) + .with_bundle_manifest(manifest.clone()); + let request = core.request_session("/health").unwrap(); + assert!(generations.insert(request.generation.clone())); + let endpoint = request + .url + .trim_start_matches("http://") + .trim_end_matches("/health"); + let mut stream = std::net::TcpStream::connect(endpoint).unwrap(); + stream + .set_read_timeout(Some(Duration::from_secs(20))) + .unwrap(); + write!(stream, "GET /health HTTP/1.1\r\nHost: {endpoint}\r\nAuthorization: {}\r\nX-Core-Generation: {}\r\nConnection: close\r\n\r\n", request.authorization.as_str(), request.generation).unwrap(); + let mut response = String::new(); + stream.read_to_string(&mut response).unwrap(); + assert!( + response.starts_with("HTTP/1.1 200"), + "packaged health failed on attempt {attempt}" + ); + assert!(!response.contains(request.authorization.as_str())); + drop(stream); + drop(core); + assert!(std::net::TcpStream::connect(endpoint).is_err()); + } +}