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
47 changes: 1 addition & 46 deletions src/safeoutputs/create_wiki_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,52 +882,7 @@ wiki-name: "MyProject.wiki"
// already-exists guard is reachable; the no-network path verifies the
// guard logic via the unit test below.
let _ = result.execute_impl(&ctx).await;
// (we cannot assert success/failure here without a real server;
// the guard itself is exercised by test_page_already_exists_guard_returns_failure)
}

/// Unit test for the page-already-exists guard logic.
///
/// NOTE: This test verifies the conditional logic prototype in isolation —
/// it does *not* call `execute_impl` directly. If the guard were accidentally
/// removed from `execute_impl`, this test would still pass. The integration
/// tests in `tests/compiler_tests.rs` and the network-level test
/// `test_execute_page_already_exists_is_rejected` (which calls `execute_impl`
/// against a fake host) together catch regressions in the live code path.
#[test]
fn test_page_already_exists_guard_returns_failure() {
// Simulate the logic: if page_exists → failure.
let page_exists = true;
let effective_path = "/Agent/Page";
let result = if page_exists {
Some(ExecutionResult::failure(format!(
"Wiki page '{effective_path}' already exists. \
Use the update-wiki-page safe output to update existing pages."
)))
} else {
None
};
assert!(result.is_some());
assert!(!result.unwrap().success);
}

/// Confirm that a non-existent page (page_exists = false) proceeds past the guard.
///
/// NOTE: Same caveat as `test_page_already_exists_guard_returns_failure` above —
/// this tests the logic prototype, not the live `execute_impl` code path.
#[test]
fn test_new_page_passes_guard() {
let page_exists = false;
let effective_path = "/Agent/NewPage";
let result: Option<ExecutionResult> = if page_exists {
Some(ExecutionResult::failure(format!(
"Wiki page '{effective_path}' already exists. \
Use the update-wiki-page safe output to update existing pages."
)))
} else {
None
};
assert!(result.is_none());
// (we cannot assert success/failure here without a real server)
}

// ── URL encoding ──────────────────────────────────────────────────────────
Expand Down
64 changes: 1 addition & 63 deletions src/safeoutputs/update_wiki_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,68 +854,6 @@ wiki-name: "MyProject.wiki"
// path-not-found guard is reachable; the no-network path verifies the
// guard logic via the unit test below.
let _ = result.execute_impl(&ctx).await;
// (we cannot assert success/failure here without a real server;
// the guard itself is exercised by test_page_not_found_guard_returns_failure)
}

/// Unit test for the page-not-found guard (no HTTP call needed).
#[test]
fn test_page_not_found_guard_returns_failure() {
// Simulate the logic that replaced check_create_if_missing_guard:
// if !page_exists → failure.
let page_exists = false;
let effective_path = "/Agent/Page";
let result = if !page_exists {
Some(ExecutionResult::failure(format!(
"Wiki page '{effective_path}' does not exist. \
Use a separate safe output to create new pages."
)))
} else {
None
};
assert!(result.is_some());
assert!(!result.unwrap().success);
}

/// Confirm that an existing page (page_exists = true) proceeds past the guard.
#[test]
fn test_existing_page_passes_guard() {
let page_exists = true;
let effective_path = "/Agent/Page";
let result: Option<ExecutionResult> = if !page_exists {
Some(ExecutionResult::failure(format!(
"Wiki page '{effective_path}' does not exist. \
Use a separate safe output to create new pages."
)))
} else {
None
};
assert!(result.is_none());
}

// ── URL encoding ──────────────────────────────────────────────────────────

#[test]
fn test_path_segment_encodes_fragment_delimiter() {
let encoded = utf8_percent_encode("wiki#name", PATH_SEGMENT).to_string();
assert_eq!(encoded, "wiki%23name");
}

#[test]
fn test_path_segment_encodes_query_delimiter() {
let encoded = utf8_percent_encode("wiki?name", PATH_SEGMENT).to_string();
assert_eq!(encoded, "wiki%3Fname");
}

#[test]
fn test_path_segment_encodes_space() {
let encoded = utf8_percent_encode("My Project", PATH_SEGMENT).to_string();
assert_eq!(encoded, "My%20Project");
}

#[test]
fn test_path_segment_does_not_encode_safe_chars() {
let encoded = utf8_percent_encode("MyProject.wiki", PATH_SEGMENT).to_string();
assert_eq!(encoded, "MyProject.wiki");
// (we cannot assert success/failure here without a real server)
}
}