fixed write semantics and visual bug with newline insertion

This commit is contained in:
Luxferre
2026-09-09 20:23:37 +03:00
parent 208d874cce
commit 4ed12ed213
3 changed files with 73 additions and 27 deletions
+11 -11
View File
@@ -2389,7 +2389,7 @@ func TestSanitizeMessagesCleansReasoningContent(t *testing.T) {
}
}
func TestWriteFileOmittedOrZeroOffsetDoesNotAppend(t *testing.T) {
func TestWriteFileOmittedOverwritesWholeFile(t *testing.T) {
tmp := t.TempDir()
target := filepath.Join(tmp, "test.txt")
@@ -2398,7 +2398,7 @@ func TestWriteFileOmittedOrZeroOffsetDoesNotAppend(t *testing.T) {
t.Fatalf("failed to write initial file: %v", err)
}
// 1. Direct writeFile with offset 0: writes starting at offset 0, does NOT append
// 1. Low-level writeFile with explicit offset 0 / del_bytes 0 still inserts at the start
res, err := writeFile(target, 0, 0, "PREFIX_")
if err != nil {
t.Fatalf("writeFile: %v", err)
@@ -2414,7 +2414,7 @@ func TestWriteFileOmittedOrZeroOffsetDoesNotAppend(t *testing.T) {
t.Errorf("expected 'PREFIX_EXISTING', got %q", string(data))
}
// 2. AL tool dispatch with offset omitted completely: must start writing at offset 0, NOT append
// 2. AL dispatch with offset and del_bytes omitted: overwrite the entire file
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var req struct {
Messages []Message `json:"messages"`
@@ -2448,11 +2448,11 @@ func TestWriteFileOmittedOrZeroOffsetDoesNotAppend(t *testing.T) {
if err != nil {
t.Fatalf("readFile: %v", err)
}
if string(data) != "START_PREFIX_EXISTING" {
t.Errorf("expected 'START_PREFIX_EXISTING', got %q", string(data))
if string(data) != "START_" {
t.Errorf("expected 'START_' (full overwrite), got %q", string(data))
}
// 3. AL tool dispatch with explicit offset: 0
// 3. AL dispatch with explicit offset 0 / del_bytes 0: insertion semantics preserved
srv2 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var req struct {
Messages []Message `json:"messages"`
@@ -2484,11 +2484,11 @@ func TestWriteFileOmittedOrZeroOffsetDoesNotAppend(t *testing.T) {
if err != nil {
t.Fatalf("readFile: %v", err)
}
if string(data) != "ZERO_START_PREFIX_EXISTING" {
t.Errorf("expected 'ZERO_START_PREFIX_EXISTING', got %q", string(data))
if string(data) != "ZERO_START_" {
t.Errorf("expected 'ZERO_START_' (insert at start), got %q", string(data))
}
// 4. AL tool dispatch with offset: null
// 4. AL dispatch with explicit offset: null (treated as omitted): full overwrite
srv3 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var req struct {
Messages []Message `json:"messages"`
@@ -2519,8 +2519,8 @@ func TestWriteFileOmittedOrZeroOffsetDoesNotAppend(t *testing.T) {
if err != nil {
t.Fatalf("readFile: %v", err)
}
if string(data) != "NULL_ZERO_START_PREFIX_EXISTING" {
t.Errorf("expected 'NULL_ZERO_START_PREFIX_EXISTING', got %q", string(data))
if string(data) != "NULL_" {
t.Errorf("expected 'NULL_' (full overwrite), got %q", string(data))
}
}