]> git.giacomolli.uk - onechat/blobdiff - build_run_test.go
Share general review and documentation rules
[onechat] / build_run_test.go
index 64d0d867790d569795f113895599b6ee868c08ce..7e1bb864682dd1e7e379c1b4f9cdb12373c0bb9b 100644 (file)
@@ -29,22 +29,22 @@ func TestBuildRunStopsOnFailedCallsOrQuotaGrowth(t *testing.T) {
                want    string
        }{
                {
                want    string
        }{
                {
-                       name:    "no calls",
+                       name:    "continues without recorded calls",
                        records: nil,
                        want:    "",
                },
                {
                        records: nil,
                        want:    "",
                },
                {
-                       name:    "growth within the limit",
+                       name:    "continues within the quota limit",
                        records: []ModelUsageRecord{quota("10", "40"), quota("25", "41")},
                        want:    "",
                },
                {
                        records: []ModelUsageRecord{quota("10", "40"), quota("25", "41")},
                        want:    "",
                },
                {
-                       name:    "growth over the limit",
+                       name:    "stops above the quota limit",
                        records: []ModelUsageRecord{quota("10", "40"), quota("12", "55.5")},
                        want:    "x-codex-secondary-used-percent grew from 40 to 55.5",
                },
                {
                        records: []ModelUsageRecord{quota("10", "40"), quota("12", "55.5")},
                        want:    "x-codex-secondary-used-percent grew from 40 to 55.5",
                },
                {
-                       name: "failed call",
+                       name: "stops after a failed call",
                        records: []ModelUsageRecord{quota("10", "40"), {
                                Status: 400,
                                Error:  "model call: HTTP 400",
                        records: []ModelUsageRecord{quota("10", "40"), {
                                Status: 400,
                                Error:  "model call: HTTP 400",
@@ -82,6 +82,7 @@ func TestBuildRunStopsWhenTheQuotaGrows(t *testing.T) {
        require.Greater(t, len(records), int(buildQuotaLimit))
 
        var report strings.Builder
        require.Greater(t, len(records), int(buildQuotaLimit))
 
        var report strings.Builder
+
        require.NoError(t, buildWriteReport(&report, appended, stop, records, sizes))
        require.Contains(t, report.String(), "stopped early: ")
        require.Contains(t, report.String(), "cached (80.0%)")
        require.NoError(t, buildWriteReport(&report, appended, stop, records, sizes))
        require.Contains(t, report.String(), "stopped early: ")
        require.Contains(t, report.String(), "cached (80.0%)")
@@ -111,11 +112,14 @@ func TestBuildRunStopsAtTheCallLimit(t *testing.T) {
 
 func TestBuildRunWaitsOnlyBeforeUserMessages(t *testing.T) {
        gate := make(chan struct{})
 
 func TestBuildRunWaitsOnlyBeforeUserMessages(t *testing.T) {
        gate := make(chan struct{})
+
        var mutex sync.Mutex
        var mutex sync.Mutex
+
        running, most := 0, 0
        server := newModelFake(t)
        running, most := 0, 0
        server := newModelFake(t)
-       server.reply = func(w http.ResponseWriter, call ModelFakeCall) {
+       server.reply = func(w http.ResponseWriter, _ ModelFakeCall) {
                mutex.Lock()
                mutex.Lock()
+
                running++
                most = max(most, running)
                mutex.Unlock()
                running++
                most = max(most, running)
                mutex.Unlock()
@@ -123,6 +127,7 @@ func TestBuildRunWaitsOnlyBeforeUserMessages(t *testing.T) {
                <-gate
 
                mutex.Lock()
                <-gate
 
                mutex.Lock()
+
                running--
                mutex.Unlock()
 
                running--
                mutex.Unlock()
 
@@ -210,7 +215,7 @@ func newTestBuildRun(t *testing.T, server *ModelFake) *BuildRun {
        root := t.TempDir()
        usagePath := filepath.Join(root, "usage.jsonl")
        client := newModelClient(server.URL, ModelAPIKey(modelTestKey), "onechat-"+probeName, usagePath)
        root := t.TempDir()
        usagePath := filepath.Join(root, "usage.jsonl")
        client := newModelClient(server.URL, ModelAPIKey(modelTestKey), "onechat-"+probeName, usagePath)
-       memory, err := openMemory(t.Context(), root, newTestClock().Now, newCompactor(client, probePrompt, defaultConfig().Compactor), discardLog())
+       memory, err := openMemory(t.Context(), root, newTestClock().Now, newCompactor(client, probePrompt, defaultConfig().Compactor, promptTools(), &ImageStore{dir: t.TempDir()}), discardLog())
        require.NoError(t, err)
 
        return &BuildRun{
        require.NoError(t, err)
 
        return &BuildRun{