package server import ( "agent-system-backend/internal/store" core "agent-system-core" "crypto/sha256" "encoding/hex" "net/http" "net/http/httptest" "testing" ) func TestTaskSourceContentDoesNotSubstituteLatestVersion(t *testing.T) { srv, st := newTestServer(t) original := []byte("上线六月") a := core.Artifact{Owner: store.OwnerDefault, ProjectID: "p", Name: "input.txt"} if e := st.CreateArtifact(&a, original); e != nil { t.Fatal(e) } sum := sha256.Sum256(original) hash := hex.EncodeToString(sum[:]) get := func() *httptest.ResponseRecorder { r := httptest.NewRequest("GET", "/api/artifacts/"+a.ID+"/content?expectedHash="+hash, nil) r.SetPathValue("id", a.ID) w := httptest.NewRecorder() srv.artifactContent(w, r) return w } if w := get(); w.Code != http.StatusOK || w.Body.String() != string(original) { t.Fatal("original version not readable", w.Code, w.Body.String()) } if e := st.UpdateArtifactContent(store.OwnerDefault, a.ID, []byte("上线七月")); e != nil { t.Fatal(e) } if w := get(); w.Code != http.StatusConflict { t.Fatal("latest content masquerades as processed version", w.Code, w.Body.String()) } }