app
SOLIDWORKS Bridge
Public Made by Adomby adom
Launch, model and quit SOLIDWORKS from any Adom container. Nothing is ever lost.
main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
//! ADVERSARIAL REVIEW OF 0.6.5 — pass eighteen.
//!
//! The Builder's report is right, and it is worse than "the tests pin the wrong
//! guard": re-attribution does not fire in the POSITIVE case either. Built end
//! to end below, with every documented precondition satisfied and COM genuinely
//! attached, the attempt stays `sldworksUpNotAttached` and no
//! `solidworks_launch_reattributed` entry reaches the ledger.
//!
//! That makes this the THIRD release in which the sign-in recovery path is
//! inert, each time for a different reason, and the second in which the tests
//! covering it proved something other than what they claimed.
mod common;
use common::{Bridge, TempDir};
use serde_json::{json, Value};
fn s(v: &Value) -> String {
serde_json::to_string_pretty(v).unwrap_or_default()
}
/// THE POSITIVE CASE, end to end — the live 0.5.9 shape.
///
/// An ATTRIBUTABLE route (`shellExecute`) invokes, its log reaches `Run Begin`,
/// SOLIDWORKS appears, COM does not attach inside the budget (the sign-in), and
/// the ladder stops with `sldworksUpNotAttached` WITHOUT killing the chain. The
/// user then clears the sign-in, COM attaches, and the next status read should
/// re-claim the session: the sldworks' parent is the launcher this attempt
/// recorded and watched run.
///
/// At the point of refusal every precondition the code documents is satisfied,
/// and I verified each from outside:
///
/// ```text
/// com.attached true
/// launch.finished true
/// launch.outcome "sldworksUpNotAttached" (not "attached")
/// launch.foreignChainSeen false
/// routesTried[0] runBeginSeen:true, rootPid:900010, rootConfirmed:true
/// launch.chainPids 900010 (CATSTART) + 900011 (SWXDesktopLauncher), both
/// with creation times, both still ALIVE in the census
/// launch.chainLastSeen [[900010,T,T+2],[900011,T,T+2]]
/// the sldworks in the census has ppid 900011 and was created at T
/// ```
///
/// So the walk should find parent 900011 in `our_identities`, find it alive,
/// match it with `same_process`, and place the child inside
/// `[parent_created, last_seen + grace]`. It refuses anyway, and nothing in the
/// report or the ledger says which clause said no.
///
/// THE DIAGNOSTIC IS THE REAL ASK. Three passes have now failed to determine
/// this from outside the process. `reattribute_after_attach` should record its
/// refusal — `reattributionRefusedBecause` on the launch report, naming the
/// clause — so the next person does not have to infer it.
#[test]
fn re_attribution_succeeds_when_every_precondition_is_met() {
let dir = TempDir::new("adv17-positive");
std::fs::write(
dir.join("routes.json"),
json!({"shellExecute": {"chain": true, "runBeginAfterMs": 0,
"sldworksAfterMs": 0, "attachAfterMs": 6000}})
.to_string(),
)
.unwrap();
std::fs::write(dir.join("preexisting.json"), json!([]).to_string()).unwrap();
let lnk = format!("{}/SOLIDWORKS Design.lnk", dir.path());
std::fs::write(&lnk, "x").unwrap();
let b = Bridge::start_in(
TempDir::new("adv17-scratch"),
&[
("SWX_SOLIDWORKS_SHORTCUT", &lnk),
("SWX_LAUNCH_FAKE_DIR", &dir.path()),
("SWX_LAUNCH_RUN_BEGIN_SECS", "1"),
("SWX_LAUNCH_SLDWORKS_SECS", "2"),
("SWX_LAUNCH_ATTACH_SECS", "2"),
("SWX_LAUNCH_POLL_MS", "100"),
("SWX_LAUNCH_RETRY_SETTLE_MS", "400"),
("SWX_LAUNCH_BACKOFF_SECS", "0"),
],
);
b.call("swx_start", json!({"reason": "starting SOLIDWORKS", "waitSeconds": 0}));
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(30);
loop {
let st = b.call("swx_status", json!({}));
if st["launch"]["finished"] == true || std::time::Instant::now() > deadline {
break;
}
std::thread::sleep(std::time::Duration::from_millis(150));
}
let mid = b.call("swx_status", json!({}));
assert_eq!(
mid["launch"]["outcome"].as_str(),
Some("sldworksUpNotAttached"),
"precondition: the ladder stopped with SOLIDWORKS up and COM unattached: {}",
s(&mid["launch"])
);
assert!(
mid["launch"]["foreignChainSeen"] != true
&& mid["launch"]["chainPids"].as_array().map(|a| a.len()).unwrap_or(0) == 2,
"precondition: no foreign chain, and our own chain is recorded with identities: {}",
s(&mid["launch"])
);
// The sign-in clears and COM attaches. The mock only flips its attached flag
// inside `start`, so poll the way a caller is told to.
std::thread::sleep(std::time::Duration::from_millis(6000));
let started = b.call("swx_start", json!({"reason": "polling after the sign-in"}));
assert_eq!(
started["attached"].as_bool(),
Some(true),
"precondition: COM really did attach: {}",
s(&started)
);
let st = b.call("swx_status", json!({}));
assert_eq!(
st["com"]["attached"].as_bool(),
Some(true),
"precondition: swx_status sees COM attached, so report_with_attach gets `true`: {}",
s(&st["com"])
);
let ledger = s(&b.call("swx_action_ledger", json!({"limit": 200})));
assert!(
st["launch"]["outcome"] == "attachedAfterSignIn"
|| ledger.contains("solidworks_launch_reattributed"),
"re-attribution did not fire although every precondition it documents is met: COM \
attached, the attempt finished un-attached with no foreign chain, a route row carrying \
runBeginSeen and a rootPid, and our own launcher recorded ALIVE with a creation time and \
a lastSeen — with the SOLIDWORKS in the census recording that launcher as its parent. \
Nothing in the report or the ledger names the clause that refused, which is why three \
passes have failed to find it from outside: `reattribute_after_attach` needs to record \
WHY it declined.\nlaunch: {}\nroutesTried: {}\nchainLastSeen: {}",
s(&st["launch"]),
s(&st["launch"]["routesTried"]),
s(&st["launch"]["chainLastSeen"])
);
}