Enhance script handling and temp ID resolution in ServeSession and Reconciler

- Improved error handling in ServeSession by rolling back temp IDs if encoding fails for new scripts.
- Added logic in applyPatch to remap echoed additions from the DescendantAdded handler, preventing duplicate instances.
- Updated API to resolve intermediate container temp IDs to real tree references, ensuring proper parent-child relationships for new scripts.
- Introduced new tests to verify the presence of server info flags and the resolution of temp IDs in scripts-only mode.

These changes aim to optimize script management and enhance the overall functionality of the session handling.
This commit is contained in:
Joe 2026-02-28 06:39:13 -06:00
parent 4985a3fede
commit 9820ec6534
4 changed files with 175 additions and 9 deletions

View file

@ -1,6 +1,7 @@
use std::collections::HashMap;
use librojo::web_api::{InstanceUpdate, WriteRequest};
use librojo::web_api::{AddedInstance, InstanceUpdate, WriteRequest};
use rbx_dom_weak::types::{Ref, Variant};
use crate::rojo_test::serve_util::run_serve_test;
@ -121,7 +122,7 @@ fn scripts_only_serverinfo_flag() {
}
#[test]
fn scripts_only_serverinfo_flag_absent_when_disabled() {
fn scripts_only_serverinfo_flag_present_for_other_fixture() {
run_serve_test("syncback_scripts_only", |session, _redactions| {
let info = session.get_api_rojo().unwrap();
assert!(
@ -131,6 +132,17 @@ fn scripts_only_serverinfo_flag_absent_when_disabled() {
});
}
#[test]
fn scripts_only_serverinfo_flag_false_when_disabled() {
run_serve_test("empty", |session, _redactions| {
let info = session.get_api_rojo().unwrap();
assert!(
!info.sync_scripts_only,
"syncScriptsOnly should default to false when not set in project"
);
});
}
#[test]
fn scripts_only_write_filters_non_script_updates() {
run_serve_test("scripts_only_read_pruning", |session, _redactions| {
@ -278,3 +290,82 @@ fn scripts_only_websocket_injects_ancestors_for_new_script() {
);
});
}
#[test]
fn scripts_only_write_resolves_intermediate_temp_ids() {
run_serve_test("scripts_only_read_pruning", |session, _redactions| {
let info = session.get_api_rojo().unwrap();
let root_id = info.root_instance_id;
let read_response = session.get_api_read(root_id).unwrap();
let sss_id = read_response
.instances
.iter()
.find(|(_, inst)| inst.class_name == "ServerScriptService")
.map(|(id, _)| *id)
.expect("ServerScriptService should exist");
// PureParts exists on disk but is pruned from the read response.
// Simulate the DescendantAdded handler: send PureParts as an
// intermediate container with a temp ID, and a new script under it.
let temp_folder_ref = Ref::new();
let temp_script_ref = Ref::new();
let folder_added = AddedInstance {
parent: Some(sss_id),
name: "PureParts".to_string(),
class_name: "Folder".to_string(),
properties: HashMap::new(),
children: vec![],
};
let mut script_props = HashMap::new();
script_props.insert(
"Source".to_string(),
Variant::String("return 'temp id test'".to_string()),
);
let script_added = AddedInstance {
parent: Some(temp_folder_ref),
name: "TempIdScript".to_string(),
class_name: "ModuleScript".to_string(),
properties: script_props,
children: vec![],
};
let mut added_map = HashMap::new();
added_map.insert(temp_folder_ref, folder_added);
added_map.insert(temp_script_ref, script_added);
let write_request = WriteRequest {
session_id: info.session_id,
removed: vec![],
added: added_map,
updated: vec![],
stage_ids: Vec::new(),
};
session
.post_api_write(&write_request)
.expect("Write request should succeed");
std::thread::sleep(std::time::Duration::from_millis(500));
let read_after = session.get_api_read(root_id).unwrap();
let names: Vec<&str> = read_after
.instances
.values()
.map(|inst| inst.name.as_ref())
.collect();
assert!(
names.contains(&"TempIdScript"),
"TempIdScript should appear after temp ID resolution. Got: {:?}",
names
);
assert!(
names.contains(&"PureParts"),
"PureParts should now be included (has script descendant). Got: {:?}",
names
);
});
}