CodeBench: kierroskohtainen output-dir + tiivistetty Go golden example
- runPipeline saa round-parametrin, dir: model__scenario__r1, __r2 jne. - todo-go.md testit 6→4 (poistettu list+update toisteiset), 466→370 riviä
This commit is contained in:
@@ -308,7 +308,7 @@ function starsForScore(score) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// === Pipeline: yhdelle mallille ja skenaariolle ===
|
// === Pipeline: yhdelle mallille ja skenaariolle ===
|
||||||
async function runPipeline(model, scenario) {
|
async function runPipeline(model, scenario, round = 1) {
|
||||||
const result = {
|
const result = {
|
||||||
model, scenario: scenario.id,
|
model, scenario: scenario.id,
|
||||||
reqOk: false, specOk: false, specEntities: 0,
|
reqOk: false, specOk: false, specEntities: 0,
|
||||||
@@ -321,7 +321,8 @@ async function runPipeline(model, scenario) {
|
|||||||
};
|
};
|
||||||
const timings = [];
|
const timings = [];
|
||||||
const { system: CODE_SYSTEM, promptName, profile } = getCodePromptForModel(model);
|
const { system: CODE_SYSTEM, promptName, profile } = getCodePromptForModel(model);
|
||||||
const dir = `${OUTPUT_DIR}/${model.replace(/[/:]/g, '_')}__${scenario.id}`;
|
const roundSuffix = ROUNDS > 1 ? `__r${round}` : '';
|
||||||
|
const dir = `${OUTPUT_DIR}/${model.replace(/[/:]/g, '_')}__${scenario.id}${roundSuffix}`;
|
||||||
mkdirSync(dir, { recursive: true });
|
mkdirSync(dir, { recursive: true });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -651,7 +652,7 @@ async function main() {
|
|||||||
for (const scenario of scenarios) {
|
for (const scenario of scenarios) {
|
||||||
const roundLabel = ROUNDS > 1 ? ` [${round}/${ROUNDS}]` : '';
|
const roundLabel = ROUNDS > 1 ? ` [${round}/${ROUNDS}]` : '';
|
||||||
console.log(`\n━━━ ${model} × ${scenario.id}${roundLabel} ━━━`);
|
console.log(`\n━━━ ${model} × ${scenario.id}${roundLabel} ━━━`);
|
||||||
const r = await runPipeline(model, scenario);
|
const r = await runPipeline(model, scenario, round);
|
||||||
if (ROUNDS > 1) r.round = round;
|
if (ROUNDS > 1) r.round = round;
|
||||||
results.push(r);
|
results.push(r);
|
||||||
|
|
||||||
|
|||||||
@@ -302,16 +302,13 @@ import (
|
|||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
_ "modernc.org/sqlite"
|
_ "modernc.org/sqlite"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setupTestServer(t *testing.T) (*httptest.Server, *sql.DB) {
|
func setupTestServer(t *testing.T) (*httptest.Server, *sql.DB) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
db, err := sql.Open("sqlite", ":memory:")
|
db, err := sql.Open("sqlite", ":memory:")
|
||||||
if err != nil {
|
if err != nil { t.Fatal(err) }
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
InitDB(db)
|
InitDB(db)
|
||||||
return httptest.NewServer(NewRouter(db)), db
|
return httptest.NewServer(NewRouter(db)), db
|
||||||
}
|
}
|
||||||
@@ -320,147 +317,57 @@ func TestCreateTodo(t *testing.T) {
|
|||||||
ts, db := setupTestServer(t)
|
ts, db := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
resp, err := http.Post(ts.URL+"/todos", "application/json",
|
resp, err := http.Post(ts.URL+"/todos", "application/json",
|
||||||
strings.NewReader(`{"title":"Buy groceries","priority":2}`))
|
strings.NewReader(`{"title":"Buy groceries","priority":2}`))
|
||||||
if err != nil {
|
if err != nil { t.Fatal(err) }
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if resp.StatusCode != http.StatusCreated {
|
if resp.StatusCode != http.StatusCreated { t.Fatalf("expected 201, got %d", resp.StatusCode) }
|
||||||
t.Fatalf("expected 201, got %d", resp.StatusCode)
|
|
||||||
}
|
|
||||||
var body map[string]interface{}
|
var body map[string]interface{}
|
||||||
json.NewDecoder(resp.Body).Decode(&body)
|
json.NewDecoder(resp.Body).Decode(&body)
|
||||||
if body["title"] != "Buy groceries" {
|
if body["title"] != "Buy groceries" { t.Fatalf("expected 'Buy groceries', got %v", body["title"]) }
|
||||||
t.Fatalf("expected title 'Buy groceries', got %v", body["title"])
|
if body["id"] == nil { t.Fatal("expected id") }
|
||||||
}
|
|
||||||
if body["id"] == nil {
|
|
||||||
t.Fatal("expected id to be present")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestListTodos(t *testing.T) {
|
|
||||||
ts, db := setupTestServer(t)
|
|
||||||
defer ts.Close()
|
|
||||||
defer db.Close()
|
|
||||||
|
|
||||||
http.Post(ts.URL+"/todos", "application/json",
|
|
||||||
strings.NewReader(`{"title":"Listable task"}`))
|
|
||||||
|
|
||||||
resp, err := http.Get(ts.URL + "/todos")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d", resp.StatusCode)
|
|
||||||
}
|
|
||||||
var body []map[string]interface{}
|
|
||||||
json.NewDecoder(resp.Body).Decode(&body)
|
|
||||||
if len(body) < 1 {
|
|
||||||
t.Fatal("expected at least 1 todo")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetTodoByID(t *testing.T) {
|
func TestGetTodoByID(t *testing.T) {
|
||||||
ts, db := setupTestServer(t)
|
ts, db := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
resp, _ := http.Post(ts.URL+"/todos", "application/json",
|
resp, _ := http.Post(ts.URL+"/todos", "application/json",
|
||||||
strings.NewReader(`{"title":"Fetchable task"}`))
|
strings.NewReader(`{"title":"Fetchable task"}`))
|
||||||
var created map[string]interface{}
|
var created map[string]interface{}
|
||||||
json.NewDecoder(resp.Body).Decode(&created)
|
json.NewDecoder(resp.Body).Decode(&created)
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
|
|
||||||
id := created["id"].(float64)
|
id := created["id"].(float64)
|
||||||
resp, err := http.Get(ts.URL + "/todos/" + fmt.Sprintf("%.0f", id))
|
resp, _ = http.Get(ts.URL + "/todos/" + fmt.Sprintf("%.0f", id))
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK { t.Fatalf("expected 200, got %d", resp.StatusCode) }
|
||||||
t.Fatalf("expected 200, got %d", resp.StatusCode)
|
|
||||||
}
|
|
||||||
var body map[string]interface{}
|
|
||||||
json.NewDecoder(resp.Body).Decode(&body)
|
|
||||||
if body["id"] != id {
|
|
||||||
t.Fatalf("expected id %.0f, got %v", id, body["id"])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetTodoNotFound(t *testing.T) {
|
func TestGetTodoNotFound(t *testing.T) {
|
||||||
ts, db := setupTestServer(t)
|
ts, db := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
resp, _ := http.Get(ts.URL + "/todos/99999")
|
||||||
resp, err := http.Get(ts.URL + "/todos/99999")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if resp.StatusCode != http.StatusNotFound {
|
if resp.StatusCode != http.StatusNotFound { t.Fatalf("expected 404, got %d", resp.StatusCode) }
|
||||||
t.Fatalf("expected 404, got %d", resp.StatusCode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestUpdateTodo(t *testing.T) {
|
|
||||||
ts, db := setupTestServer(t)
|
|
||||||
defer ts.Close()
|
|
||||||
defer db.Close()
|
|
||||||
|
|
||||||
resp, _ := http.Post(ts.URL+"/todos", "application/json",
|
|
||||||
strings.NewReader(`{"title":"Old title"}`))
|
|
||||||
var created map[string]interface{}
|
|
||||||
json.NewDecoder(resp.Body).Decode(&created)
|
|
||||||
resp.Body.Close()
|
|
||||||
|
|
||||||
id := created["id"].(float64)
|
|
||||||
req, _ := http.NewRequest(http.MethodPut, ts.URL+"/todos/"+fmt.Sprintf("%.0f", id),
|
|
||||||
strings.NewReader(`{"title":"New title"}`))
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
resp, err := http.DefaultClient.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
|
||||||
t.Fatalf("expected 200, got %d", resp.StatusCode)
|
|
||||||
}
|
|
||||||
var body map[string]interface{}
|
|
||||||
json.NewDecoder(resp.Body).Decode(&body)
|
|
||||||
if body["title"] != "New title" {
|
|
||||||
t.Fatalf("expected 'New title', got %v", body["title"])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeleteTodo(t *testing.T) {
|
func TestDeleteTodo(t *testing.T) {
|
||||||
ts, db := setupTestServer(t)
|
ts, db := setupTestServer(t)
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
resp, _ := http.Post(ts.URL+"/todos", "application/json",
|
resp, _ := http.Post(ts.URL+"/todos", "application/json",
|
||||||
strings.NewReader(`{"title":"Deletable task"}`))
|
strings.NewReader(`{"title":"Deletable task"}`))
|
||||||
var created map[string]interface{}
|
var created map[string]interface{}
|
||||||
json.NewDecoder(resp.Body).Decode(&created)
|
json.NewDecoder(resp.Body).Decode(&created)
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
|
|
||||||
id := created["id"].(float64)
|
id := created["id"].(float64)
|
||||||
req, _ := http.NewRequest(http.MethodDelete, ts.URL+"/todos/"+fmt.Sprintf("%.0f", id), nil)
|
req, _ := http.NewRequest(http.MethodDelete, ts.URL+"/todos/"+fmt.Sprintf("%.0f", id), nil)
|
||||||
resp, err := http.DefaultClient.Do(req)
|
resp, _ = http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if resp.StatusCode != http.StatusNoContent {
|
if resp.StatusCode != http.StatusNoContent { t.Fatalf("expected 204, got %d", resp.StatusCode) }
|
||||||
t.Fatalf("expected 204, got %d", resp.StatusCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, _ = http.Get(ts.URL + "/todos/" + fmt.Sprintf("%.0f", id))
|
resp, _ = http.Get(ts.URL + "/todos/" + fmt.Sprintf("%.0f", id))
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
if resp.StatusCode != http.StatusNotFound {
|
if resp.StatusCode != http.StatusNotFound { t.Fatalf("expected 404 after delete, got %d", resp.StatusCode) }
|
||||||
t.Fatalf("expected 404 after delete, got %d", resp.StatusCode)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user