Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/dimcode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ dim-agent-capabilities.workspace = true
agent-client-protocol-schema = { version = "=1.12.0", default-features = false }
base64 = "0.22.1"
sha2 = "0.10.9"
dim-client.workspace = true
dim-agent-types.workspace = true
# The legacy prompt-reference flow seeds a real branch through a Session, which
# needs the runtime's test host.
Expand Down
85 changes: 66 additions & 19 deletions crates/dimcode/tests/cli_flow/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,74 @@ fn hooks_toggle_conflict_reads_the_area_again() {
daemon.join().unwrap();
}

/// Creates a Session over the App Server's own wire and waits for its
/// SessionStart hook point. A Session with no first turn runs the hook at
/// activation, so the check does not race a turn's model request.
fn start_hook_session(
home: &Home,
binary: &str,
project: &std::path::Path,
marker: &std::path::Path,
expected: &str,
) {
let endpoint = home.0.join("rust/daemon.sock");
let runtime = tokio::runtime::Runtime::new().unwrap();
runtime.block_on(async {
let mut client = dim_client::Client::connect(&dim_client::ConnectionConfig {
endpoint,
server: dim_client::Server {
program: binary.into(),
embedded: false,
},
profile: None,
client_kind: "other",
client_name: "cli_flow hooks-flow",
protocol_version: 4,
})
.await
.expect("connect to the App Server");
let created = client
.rpc("session.create", json!({"cwd": project.to_str().unwrap()}))
.await
.expect("create the Session");
assert!(created["sessionId"].is_string(), "{created}");
wait_for_hook(marker, expected);
client
.rpc("session.close", json!({"sessionId": created["sessionId"]}))
.await
.expect("close the Session");
});
}

/// Waits for the next hook point to run the saved document, without assuming
/// when the started Session reaches activation.
fn wait_for_hook(marker: &std::path::Path, expected: &str) {
let deadline = Instant::now() + PATIENCE;
loop {
let seen = fs::read_to_string(marker).unwrap_or_default();
if seen == expected {
return;
}
assert!(
Instant::now() < deadline,
"the saved document did not reach the next hook point: {seen:?}"
);
thread::sleep(Duration::from_millis(10));
}
}

#[test]
#[ignore = "requires DIM_TEST_APP_SERVER pointing to the built production App Server"]
fn project_hooks_start_disabled_and_the_user_enables_them() {
let binary = std::env::var("DIM_TEST_APP_SERVER").unwrap();
let home = Home::new();
let _daemon = OwnedDaemon(home.0.join("rust/daemon.sock"));
let (config, model) = rejecting_model_config(&home, 2);
let config = home.0.join("model.json");
fs::write(
&config,
include_str!("../../../dim-agent-aimux/examples/offline.json"),
)
.unwrap();
let project = home.0.join("work");
fs::create_dir_all(project.join(".dimcode")).unwrap();
fs::write(
Expand Down Expand Up @@ -487,18 +548,10 @@ fn project_hooks_start_disabled_and_the_user_enables_them() {
),
"{listed}"
);
// The next hook point runs the document the CLI wrote. SessionStart
// fires before the model is asked, so the rejecting fixture endpoint
// does not keep it from running; that endpoint fails the turn
// immediately without retrying, so `Stop` is not reachable here. A
// turn's own failure is expected and not this test's subject.
// A Session with no first turn reaches its SessionStart hook point at
// activation.
let marker = project.join("user-ran.txt");
let _ = run(&["exec", "-p", "go"]);
assert_eq!(
fs::read_to_string(&marker).unwrap_or_default(),
"user-one",
"the saved document did not reach the next hook point"
);
start_hook_session(&home, &binary, &project, &marker, "user-one");
// A replacement reaches the next hook point too.
fs::write(
&document,
Expand All @@ -511,13 +564,7 @@ fn project_hooks_start_disabled_and_the_user_enables_them() {
.status
.success()
);
let _ = run(&["exec", "-p", "go"]);
assert_eq!(
fs::read_to_string(&marker).unwrap_or_default(),
"user-two",
"the replacement did not reach the next hook point"
);
model.join().unwrap();
start_hook_session(&home, &binary, &project, &marker, "user-two");
assert!(run(&["daemon", "stop"]).status.success());
}

Expand Down
4 changes: 4 additions & 0 deletions docs/architecture/rust-agent/generated/crates.json
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,10 @@
"from": "dimcode",
"to": "dim-agent-types"
},
{
"from": "dimcode",
"to": "dim-client"
},
{
"from": "dimcode",
"to": "rutis"
Expand Down
1 change: 1 addition & 0 deletions docs/architecture/rust-agent/generated/crates.mmd
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ flowchart LR
dimcode["dimcode"] --> dim_agent_capabilities["dim-agent-capabilities"]
dimcode["dimcode"] --> dim_agent_runtime["dim-agent-runtime"]
dimcode["dimcode"] --> dim_agent_types["dim-agent-types"]
dimcode["dimcode"] --> dim_client["dim-client"]
dimcode["dimcode"] --> rutis["rutis"]
xtask["xtask"] --> dim_agent_aimux["dim-agent-aimux"]
xtask["xtask"] --> dim_agent_attachments["dim-agent-attachments"]
Expand Down