fix: correct newline removal from fs_write and fs_patch
This commit is contained in:
@@ -33,7 +33,11 @@ source "$LLM_PROMPT_UTILS_FILE"
|
|||||||
|
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
main() {
|
main() {
|
||||||
argc_contents="$(jq -r '.content' <<< "$LLM_TOOL_RAW_JSON")"
|
# Command substitution strips *all* trailing newlines and `jq -r` appends one
|
||||||
|
# of its own, so read with `-j` and pin the real end of the content with a
|
||||||
|
# sentinel that is removed afterwards.
|
||||||
|
argc_contents="$(jq -j '.content' <<< "$LLM_TOOL_RAW_JSON"; printf x)"
|
||||||
|
argc_contents="${argc_contents%x}"
|
||||||
argc_path="$(jq -r '.path' <<< "$LLM_TOOL_RAW_JSON")"
|
argc_path="$(jq -r '.path' <<< "$LLM_TOOL_RAW_JSON")"
|
||||||
|
|
||||||
if [[ ! -f "$argc_path" ]]; then
|
if [[ ! -f "$argc_path" ]]; then
|
||||||
@@ -41,7 +45,11 @@ main() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
new_contents="$(patch_file "$argc_path" <(printf "%s" "$argc_contents"))"
|
# Same sentinel guard on the patched result, otherwise the trailing newline
|
||||||
|
# is stripped again on the way back out. `rc` preserves patch_file's exit
|
||||||
|
# status so a failure still aborts under `set -e`.
|
||||||
|
new_contents="$(patch_file "$argc_path" <(printf "%s" "$argc_contents"); rc=$?; printf x; exit "$rc")"
|
||||||
|
new_contents="${new_contents%x}"
|
||||||
printf "%s" "$new_contents" | git diff --no-index "$argc_path" - || true
|
printf "%s" "$new_contents" | git diff --no-index "$argc_path" - || true
|
||||||
|
|
||||||
guard_operation "Apply changes?"
|
guard_operation "Apply changes?"
|
||||||
|
|||||||
@@ -15,7 +15,12 @@ source "$LLM_PROMPT_UTILS_FILE"
|
|||||||
|
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
main() {
|
main() {
|
||||||
argc_contents="$(jq -r '.content' <<< "$LLM_TOOL_RAW_JSON")"
|
# Command substitution strips *all* trailing newlines and `jq -r` appends one
|
||||||
|
# of its own, so read with `-j` and pin the real end of the content with a
|
||||||
|
# sentinel that is removed afterwards. Without this every written file loses
|
||||||
|
# its final newline, which breaks formatters such as `cargo fmt --check`.
|
||||||
|
argc_contents="$(jq -j '.content' <<< "$LLM_TOOL_RAW_JSON"; printf x)"
|
||||||
|
argc_contents="${argc_contents%x}"
|
||||||
argc_path="$(jq -r '.path' <<< "$LLM_TOOL_RAW_JSON")"
|
argc_path="$(jq -r '.path' <<< "$LLM_TOOL_RAW_JSON")"
|
||||||
|
|
||||||
if [[ -f "$argc_path" ]]; then
|
if [[ -f "$argc_path" ]]; then
|
||||||
|
|||||||
+4
-4
@@ -3044,7 +3044,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn reciprocal_rank_fusion_empty_lists() {
|
fn reciprocal_rank_fusion_empty_lists() {
|
||||||
let result = super::reciprocal_rank_fusion(vec![], vec![], 5);
|
let result = reciprocal_rank_fusion(vec![], vec![], 5);
|
||||||
assert!(result.is_empty(), "empty input should produce empty output");
|
assert!(result.is_empty(), "empty input should produce empty output");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3052,7 +3052,7 @@ mod tests {
|
|||||||
fn reciprocal_rank_fusion_deduplicates_across_signals() {
|
fn reciprocal_rank_fusion_deduplicates_across_signals() {
|
||||||
let doc_a = DocumentId::new(0, 0);
|
let doc_a = DocumentId::new(0, 0);
|
||||||
let doc_b = DocumentId::new(0, 1);
|
let doc_b = DocumentId::new(0, 1);
|
||||||
let result = super::reciprocal_rank_fusion(
|
let result = reciprocal_rank_fusion(
|
||||||
vec![vec![doc_a, doc_b], vec![doc_a, doc_b]],
|
vec![vec![doc_a, doc_b], vec![doc_a, doc_b]],
|
||||||
vec![1.0, 1.0],
|
vec![1.0, 1.0],
|
||||||
5,
|
5,
|
||||||
@@ -3069,7 +3069,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn reciprocal_rank_fusion_respects_top_k() {
|
fn reciprocal_rank_fusion_respects_top_k() {
|
||||||
let docs: Vec<DocumentId> = (0..10).map(|i| DocumentId::new(0, i)).collect();
|
let docs: Vec<DocumentId> = (0..10).map(|i| DocumentId::new(0, i)).collect();
|
||||||
let result = super::reciprocal_rank_fusion(vec![docs], vec![1.0], 3);
|
let result = reciprocal_rank_fusion(vec![docs], vec![1.0], 3);
|
||||||
assert_eq!(result.len(), 3, "result should be capped at top_k=3");
|
assert_eq!(result.len(), 3, "result should be capped at top_k=3");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3077,7 +3077,7 @@ mod tests {
|
|||||||
fn reciprocal_rank_fusion_weights_affect_ranking() {
|
fn reciprocal_rank_fusion_weights_affect_ranking() {
|
||||||
let doc_a = DocumentId::new(0, 0);
|
let doc_a = DocumentId::new(0, 0);
|
||||||
let doc_b = DocumentId::new(0, 1);
|
let doc_b = DocumentId::new(0, 1);
|
||||||
let result = super::reciprocal_rank_fusion(
|
let result = reciprocal_rank_fusion(
|
||||||
vec![vec![doc_a, doc_b], vec![doc_b, doc_a]],
|
vec![vec![doc_a, doc_b], vec![doc_b, doc_a]],
|
||||||
vec![10.0, 1.0],
|
vec![10.0, 1.0],
|
||||||
2,
|
2,
|
||||||
|
|||||||
Reference in New Issue
Block a user