gui: Tuned for you lets a compaction window be picked, each with its estimated extra tokens and compactions (#1860)

MrMengJ applied the advised 200K auto-compaction window and wanted 250K or
300K instead, seeing what each costs against the cheapest. A compaction
row now has "Other window…", which opens the app menu (never a native
select) with every value of the curve the card already replays. Each says
its estimated extra tokens over the fewest (or "Fewest tokens" / "As few
tokens") and about how many compactions it would have made over the range.
The head says it is estimated from the reader's calls. The one picked is put
in through /api/tune/apply like Use, with Undo.

tune.Point gains compacts, counted by the same replayCompact that prices
the point, so tokens and compactions come from one model.

Run: go test ./internal/tune ./internal/gui; TestCompactCurveCountsCompactions
(compactions fall as the window grows; the last point is close to
Facts.Compacts). gofmt -l; go vet internal/tune on darwin, linux -tags
nogui, windows. GUI: context-*, gui-zh-tw/ja/de, compact-at, click-scroll,
i18n-keys in chromium and webkit, 144 pass. The new context-tune test covers
5 languages at 360 and 1100px: menu inside the window, 300K ticked, notes
for 250K and 160K, picking 250K posts apply with no page scroll, Escape
posts nothing. On HEAD~ assets context-tune fails 22 of 23.
Not run: against a real Claude Code settings.json (the apply path is
unchanged from Use).
This commit is contained in:
yetone
2026-10-13 04:31:07 +08:00
parent 6e5f4fc97f
commit 0102915fe0
6 changed files with 173 additions and 12 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ something else shows up as drift.
| Keeping configs current | `Reseat` moves agents off a model magpie no longer serves (#200). `OnGateway` and `Rewire` write the new gateway address into every connected agent when the port changes. `Source` and `Stale` say what an unconnected agent runs on, and whether running copies still use the old list. | [`reseat.go`](../../internal/agent/reseat.go), [`rewire.go`](../../internal/agent/rewire.go), [`connectinfo.go`](../../internal/agent/connectinfo.go) |
| Named omp profiles | omp keeps a profile's settings under `~/.omp/profiles/<name>` (or under `PI_CONFIG_DIR`), each with its own `config.yml` and `models.yml`. Every such profile is an agent of its own — `omp#<name>` on Windows, `omp#<name>@wsl:<distro>` in a distro — so each can be connected, drifted and disconnected on its own. They share omp's model lists (`ListsFor`), and the default `omp` row is the folder `ompDir`/`ompIn` already pick, so an `OMP_PROFILE` that row is already pointed at is not listed twice. A name omp refuses is not a row: `default`, a trailing dot, or a Windows reserved device name (`aux`, `nul`, `com1`, `lpt9.x`, `con.work`), on every platform (`ompProfileOK`). A distro's profile names come from its probe and are kept in `wsl.json`; a stopped distro is never started to list them, its profile rows showing what was last seen (`asleep`). | [`omp.go`](../../internal/agent/omp.go), [`wsl.go`](../../internal/agent/wsl.go) |
| WSL twins | On Windows each running distro is probed once, without starting a stopped one. The `wslKinds` agents found there become agents of their own, `<id>@wsl:<distro>`, edited through `\\wsl.localhost\<distro>`. A kind is found by its folder under the distro's home or by its command there (not one on a Windows drive). Where another tool shares one of them, the kind leaves it out: Gemini CLI is found by its command alone, because Antigravity keeps `~/.gemini` too. Goose is found by its folder alone, because a `goose` command can be pressly's migration tool. Reasonix also needs the version its command gives (`accept`), because the old npm client is named `reasonix` too. The gateway address and key follow the distro's networking: mirrored or NAT (`place`, `keyAt`). `ListsFor` keeps a twin's model picks under the Windows twin's id (#927). | [`wsl.go`](../../internal/agent/wsl.go), [`gatewaykey.go`](../../internal/agent/gatewaykey.go) |
| Settings tuned from use | Usage › Context's "Tuned for you" advises, per agent, the settings that would have spent the fewest tokens on the user's own calls of the range, and puts one in on a click. Package `tune` replays the calls `sessions.Calls` reads from the agents' session files under each candidate value (`Compact`, `CacheTTL`); `tuneOf` picks the agents and models (Claude Code per model, Codex pooled). `TuneRead`, `TuneApply` and `TuneUndo` know where each setting lives: Claude Code's `modelSettings.<model>.autoCompactWindow` (where its `/autocompact` saves), `promptCacheTtl` and `subagentPromptCacheTtl` in `~/.claude/settings.json`; Codex's top-level `model_auto_compact_token_limit`. The advice is weighed by tokens alone: it is labelled "Fewest tokens", and a compaction window it would change says it doesn't measure how well the agent keeps the task after a compaction, and that a lower window compacts more often (#1854, `context-tune.test.cjs`). | [`internal/tune`](../../internal/tune/tune.go), [`tune.go`](../../internal/agent/tune.go), [`internal/gui/tune.go`](../../internal/gui/tune.go) |
| Settings tuned from use | Usage › Context's "Tuned for you" advises, per agent, the settings that would have spent the fewest tokens on the user's own calls of the range, and puts one in on a click. Package `tune` replays the calls `sessions.Calls` reads from the agents' session files under each candidate value (`Compact`, `CacheTTL`); `tuneOf` picks the agents and models (Claude Code per model, Codex pooled). `TuneRead`, `TuneApply` and `TuneUndo` know where each setting lives: Claude Code's `modelSettings.<model>.autoCompactWindow` (where its `/autocompact` saves), `promptCacheTtl` and `subagentPromptCacheTtl` in `~/.claude/settings.json`; Codex's top-level `model_auto_compact_token_limit`. The advice is weighed by tokens alone: it is labelled "Fewest tokens", and a compaction window it would change says it doesn't measure how well the agent keeps the task after a compaction, and that a lower window compacts more often (#1854, `context-tune.test.cjs`). A compaction row's "Other window…" opens the app menu with every value of the curve, each with its estimated extra tokens over the fewest and about how many compactions it would have made (`Point.compacts`, from the same replay), and puts the one picked in like Use (#1860). | [`internal/tune`](../../internal/tune/tune.go), [`tune.go`](../../internal/agent/tune.go), [`internal/gui/tune.go`](../../internal/gui/tune.go) |
| Agents a plugin adds | A plugin's `magpie.agent` module (or a `*.agent.js` file) says where an agent magpie has no setup of its own keeps its model (`config`, `format`, `model`, `prefix`), and its `connect` returns the other keys to write. `agentplug` compiles each in moejs (via `jsmod`, as gateway middleware is), reloads it when plugins.json or the file changes, and keeps why one didn't load. `plugged` makes each an `Agent` with `Plugin` set, listed after magpie's own; an id one of magpie's own agents has is refused (`PluginErrors`). | [`agentplug.go`](../../internal/agentplug/agentplug.go), [`plugged.go`](../../internal/agent/plugged.go) |
| Environment-only agents | Agents that read the gateway only from the environment get a `Launch` command. Cursor Private Inference instead gets user-level variables (`cursorLocalOn`, `KeepCursorLocalEnv`), and magpie writes none of Cursor's own files. It is found by its product.json in the apps folders, in the folder Windows' list of installed programs names (`cursorLocalInstalls`, any folder picked in its installer), or as its Linux AppImage (`Cursor_Private_Inference-…AppImage`) in the folders downloads are kept in (#1254). Its effort field is kept in magpie (`provider.AgentEffort`) and asked by the gateway, its levels those of the models it lists (`cursorLocalEfforts`, #1003). | [`cursorlocal.go`](../../internal/agent/cursorlocal.go) |
+30
View File
@@ -1073,6 +1073,36 @@
go.onclick = () => send("apply", best);
foot.append(go);
}
// a window of the reader's own (#1860): one who would spend some tokens
// for fewer compactions picks it from the same replay the advice comes
// from, each value with what it spends past the leanest and how often
// it would have compacted in the range, both estimates
const pts = (a.compact && a.compact.curve) || [];
if (pts.length > 1 && !set.locked) {
const other = el("button", "text ctx-tune-pick", t("Other window…"));
other.type = "button";
other.disabled = tuneBusy === key;
other.setAttribute("aria-haspopup", "menu");
other.setAttribute("aria-expanded", "false");
other.onclick = (e) => {
e.stopPropagation();
const base = (pts.find((p) => p.value === best) || {}).cost ?? r.low;
const now = set.ours && set.value != null ? +set.value : cur;
const near = pts.reduce((x, p) => Math.abs(p.value - now) < Math.abs(x.value - now) ? p : x, pts[0]);
const opts = pts.map((p) => {
const extra = Math.max(0, p.cost - base);
const spend = p.value === best ? t("Fewest tokens")
: base > 0 && extra / base < 0.005 ? t("As few tokens")
: t("+{tokens} tokens (+{pct})", { tokens: fmtK(extra), pct: pct(base > 0 ? extra / base : 0) });
const often = p.compacts == null ? "" : p.compacts ? count(p.compacts, "about 1 compaction", "about {n} compactions") : t("no compaction");
return { v: String(p.value), name: show(p.value), literalName: true, note: [spend, often].filter(Boolean).join(" · ") };
});
openProtoMenu(other, opts, String(near.value), (v) => {
if (v !== String(now)) send("apply", v);
}, "Compact at · estimated from your calls of the range", "ctx-tune-menu");
};
foot.append(other);
}
row.append(foot);
return row;
}
+28
View File
@@ -78,6 +78,13 @@ const I18N = {
"{value}: {tokens} more tokens over the range (+{pct})": "{value}:这段时间多花 {tokens} Token(+{pct})",
"Tokens each setting would have spent past the leanest, on your own calls": "用你自己的调用回放:每个设置比最省的多花多少 Token",
"Fewest tokens": "最省 Token",
"Other window…": "其他阈值…",
"Compact at · estimated from your calls of the range": "压缩阈值 · 按这段时间你的调用估算",
"+{tokens} tokens (+{pct})": "多花 {tokens} Token(+{pct})",
"As few tokens": "几乎一样省",
"about 1 compaction": "约压缩 1 次",
"about {n} compactions": "约压缩 {n} 次",
"no compaction": "不会压缩",
"A token estimate only: it doesn't measure how well the agent keeps the task after a compaction. The lower the window, the more often it compacts.": "只是 Token 估算:没有衡量压缩后 Agent 还能多好地接着做任务。阈值越低,压缩越频繁。",
"Your conversations grow {growth} a call; a compaction leaves {after}, and reading back what it dropped costs {rework}. {n} compactions in the range.": "你的对话每次调用增长 {growth};压缩后剩 {after},把丢掉的内容再读回来要花 {rework}。这段时间共压缩 {n} 次。",
"Your conversations grow {growth} a call, and none was compacted in the range.": "你的对话每次调用增长 {growth},这段时间没有一次压缩。",
@@ -4576,6 +4583,13 @@ const I18N = {
"{value}: {tokens} more tokens over the range (+{pct})": "{value}:這段時間多花 {tokens} Token(+{pct})",
"Tokens each setting would have spent past the leanest, on your own calls": "用你自己的呼叫重放:每個設定比最省的多花多少 Token",
"Fewest tokens": "最省 Token",
"Other window…": "其他閾值…",
"Compact at · estimated from your calls of the range": "壓縮閾值 · 依這段時間你的呼叫估算",
"+{tokens} tokens (+{pct})": "多花 {tokens} Token(+{pct})",
"As few tokens": "幾乎一樣省",
"about 1 compaction": "約壓縮 1 次",
"about {n} compactions": "約壓縮 {n} 次",
"no compaction": "不會壓縮",
"A token estimate only: it doesn't measure how well the agent keeps the task after a compaction. The lower the window, the more often it compacts.": "只是 Token 估算:沒有衡量壓縮後 Agent 還能多好地接著做任務。閾值越低,壓縮越頻繁。",
"Your conversations grow {growth} a call; a compaction leaves {after}, and reading back what it dropped costs {rework}. {n} compactions in the range.": "你的對話每次呼叫增長 {growth};壓縮後剩 {after},把丟掉的內容再讀回來要花 {rework}。這段時間共壓縮 {n} 次。",
"Your conversations grow {growth} a call, and none was compacted in the range.": "你的對話每次呼叫增長 {growth},這段時間沒有一次壓縮。",
@@ -9057,6 +9071,13 @@ const I18N = {
"{value}: {tokens} more tokens over the range (+{pct})": "{value}:この期間で {tokens} トークン多い(+{pct})",
"Tokens each setting would have spent past the leanest, on your own calls": "あなた自身の呼び出しで再生:各設定が最少よりどれだけ多くトークンを使ったか",
"Fewest tokens": "トークン最少",
"Other window…": "ほかの値…",
"Compact at · estimated from your calls of the range": "コンパクトする値 · この期間の呼び出しからの見積もり",
"+{tokens} tokens (+{pct})": "{tokens} トークン多い(+{pct})",
"As few tokens": "ほぼ同じく最少",
"about 1 compaction": "コンパクト約 1 回",
"about {n} compactions": "コンパクト約 {n} 回",
"no compaction": "コンパクトなし",
"A token estimate only: it doesn't measure how well the agent keeps the task after a compaction. The lower the window, the more often it compacts.": "トークンの見積もりだけです。コンパクトのあとエージェントが作業をどれだけ保てるかは測っていません。しきい値が低いほどコンパクトの回数は増えます。",
"Your conversations grow {growth} a call; a compaction leaves {after}, and reading back what it dropped costs {rework}. {n} compactions in the range.": "会話は 1 回の呼び出しごとに {growth} 増えます。コンパクト後は {after} が残り、落とした内容を読み直すのに {rework} かかります。この期間のコンパクトは {n} 回。",
"Your conversations grow {growth} a call, and none was compacted in the range.": "会話は 1 回の呼び出しごとに {growth} 増え、この期間にコンパクトはありませんでした。",
@@ -13540,6 +13561,13 @@ const I18N = {
"{value}: {tokens} more tokens over the range (+{pct})": "{value}: {tokens} Tokens mehr im Zeitraum (+{pct})",
"Tokens each setting would have spent past the leanest, on your own calls": "Mit deinen eigenen Aufrufen nachgespielt: wie viele Tokens jede Einstellung mehr gebraucht hätte als die sparsamste",
"Fewest tokens": "Wenigste Tokens",
"Other window…": "Anderer Wert…",
"Compact at · estimated from your calls of the range": "Kompaktieren bei · geschätzt aus deinen Aufrufen im Zeitraum",
"+{tokens} tokens (+{pct})": "+{tokens} Tokens (+{pct})",
"As few tokens": "Fast genauso sparsam",
"about 1 compaction": "etwa 1 Kompaktierung",
"about {n} compactions": "etwa {n} Kompaktierungen",
"no compaction": "keine Kompaktierung",
"A token estimate only: it doesn't measure how well the agent keeps the task after a compaction. The lower the window, the more often it compacts.": "Nur eine Token-Schätzung: Wie gut der Agent die Aufgabe nach einer Kompaktierung behält, misst sie nicht. Je niedriger die Schwelle, desto öfter wird kompaktiert.",
"Your conversations grow {growth} a call; a compaction leaves {after}, and reading back what it dropped costs {rework}. {n} compactions in the range.": "Deine Unterhaltungen wachsen um {growth} pro Aufruf; eine Kompaktierung lässt {after} übrig, und das Zurücklesen des Entfernten kostet {rework}. {n} Kompaktierungen im Zeitraum.",
"Your conversations grow {growth} a call, and none was compacted in the range.": "Deine Unterhaltungen wachsen um {growth} pro Aufruf, und im Zeitraum wurde keine kompaktiert.",
+76 -3
View File
@@ -19,7 +19,7 @@ const { chromium, webkit } = require("playwright");
const assets = path.resolve(__dirname, "../assets");
const curve = (lo, hi, best) => {
const pts = [];
for (let v = lo; v <= hi; v += 10000) pts.push({ value: v, cost: 1e9 + Math.abs(v - best) * 3000 });
for (let v = lo; v <= hi; v += 10000) pts.push({ value: v, cost: 1e9 + Math.abs(v - best) * 3000, compacts: Math.round(9e6 / v) });
return pts;
};
const facts = { calls: 4100, streams: 60, compacts: 813, peak: 166000, after: 57000, growth: 1000, rework: 4700, quick: 0.95, pause: 0.045, away: 0.005, hour: 0.9 };
@@ -112,9 +112,14 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// Codex had too few calls: no card for it
assert.equal(await page.locator(".ctx-tune").count(), 1);
assert.equal(await rows.count(), 4);
// only the window a change saves on has a button; the locked one says why
// only the window a change saves on has a Use button; the locked one
// says why; each window has a picker of its own (#1860), the cache
// lifetimes none
const buttons = page.locator(".ctx-tune-row button");
assert.equal(await buttons.count(), 1);
assert.equal(await page.locator(".ctx-tune-row button.primary").count(), 1);
assert.equal(await rows.nth(0).locator(".ctx-tune-pick").count(), 1);
assert.equal(await rows.nth(1).locator(".ctx-tune-pick").count(), 1, "a window already the leanest can still be changed");
assert.equal(await page.locator(".ctx-tune-pick").count(), 2);
assert.match(await rows.nth(0).locator(".ctx-tune-val.best b").innerText(), /160K/);
// the advice is named for tokens and says what it doesn't weigh
// (#1854): on a window it would change, not on one already the
@@ -204,3 +209,71 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.deepEqual(errors, []);
});
}
// A window of the reader's own (#1860, MrMengJ: 200K put in, and 250K or
// 300K wanted for fewer compactions): each window's picker lists every
// value the replay tried, with what it spends past the leanest and about
// how many compactions it would have made, in the app's own menu (no native
// select), inside a phone's width; a pick puts it in and Undo stays. The
// row already at the advice keeps its picker. No click scrolls the page.
const pickHead = { en: "Compact at · estimated from your calls of the range", zh: "压缩阈值 · 按这段时间你的调用估算", "zh-TW": "壓縮閾值 · 依這段時間你的呼叫估算", ja: "コンパクトする値 · この期間の呼び出しからの見積もり", de: "Kompaktieren bei · geschätzt aus deinen Aufrufen im Zeitraum" };
const note250 = { en: "+270M tokens (+27%) · about 36 compactions", zh: "多花 270M Token(+27%) · 约压缩 36 次", "zh-TW": "多花 270M Token(+27%) · 約壓縮 36 次", ja: "270M トークン多い(+27%) · コンパクト約 36 回", de: "+270M Tokens (+27%) · etwa 36 Kompaktierungen" };
const note160 = { en: "Fewest tokens · about 56 compactions", zh: "最省 Token · 约压缩 56 次", "zh-TW": "最省 Token · 約壓縮 56 次", ja: "トークン最少 · コンパクト約 56 回", de: "Wenigste Tokens · etwa 56 Kompaktierungen" };
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(`${engine}: a window of the reader's own, with what it costs`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const errors = [];
t.after(() => browser.close());
for (const lang of Object.keys(heading)) for (const [width, height] of [[360, 760], [1100, 760]]) {
await t.test(`${lang}, ${width}x${height}`, async () => {
const ctx = await browser.newContext({ viewport: { width, height }, reducedMotion: "reduce" });
await ctx.addInitScript(() => { try { localStorage.setItem("magpie.usageTab", "context"); } catch {} });
const page = await ctx.newPage();
page.setDefaultTimeout(5000);
page.on("pageerror", (e) => errors.push(e.message));
const posts = [];
await page.route("**/*", serve(lang, posts));
await page.goto("http://magpie.test/?view=usage");
const row = page.locator(".ctx-tune-row").nth(0);
await row.locator(".ctx-tune-pick").waitFor();
await page.locator(".ctx-none").waitFor(); // the history has answered: the pane is its full length
// the reader scrolls to the picker, as a wheel does
await page.mouse.move(width / 2, 300);
for (let i = 0; i < 20 && (await row.locator(".ctx-tune-pick").boundingBox()).y > height * 0.6; i++) {
await page.mouse.wheel(0, 120);
await page.waitForTimeout(60);
}
await page.waitForTimeout(200);
assert.equal(await page.locator("select").count(), 0, "no native select");
const y = await page.evaluate(() => document.querySelector("#view-usage").scrollTop + scrollY);
await row.locator(".ctx-tune-pick").click();
const menu = page.locator(".proto-menu.ctx-tune-menu");
await menu.waitFor();
assert.equal(await menu.locator(".pm-head").innerText(), pickHead[lang]);
// every value the replay tried, 110K to 300K; the one set now ticked
assert.equal(await menu.locator(".pm-item").count(), 20);
const item = (v) => menu.locator(".pm-item", { has: page.locator(".pm-name", { hasText: new RegExp("^" + v + "$") }) });
assert.match(await item("300K").getAttribute("class"), /\bon\b/);
assert.equal(await item("250K").locator(".pm-note").innerText(), note250[lang]);
assert.equal(await item("160K").locator(".pm-note").innerText(), note160[lang]);
const box = await menu.boundingBox();
assert.ok(box.x >= 0 && box.x + box.width <= width + 1, `the menu is inside the window: ${JSON.stringify(box)}`);
await item("250K").click();
await page.locator(".ctx-tune-row").nth(0).locator("button", { hasText: { en: "Undo", zh: "撤销", "zh-TW": "復原", ja: "取り消す", de: "Rückgängig" }[lang] }).waitFor();
assert.deepEqual(posts, [{ path: "/api/tune/apply", agent: "claude", knob: "compact", model: "claude-opus-5-5", value: "250000" }]);
assert.equal(await page.evaluate(() => document.querySelector("#view-usage").scrollTop + scrollY), y, "no click scrolled the page");
// now 250K: the advice and its Use button stand beside it, the
// picker ticks 250K
assert.match(await page.locator(".ctx-tune-row").nth(0).locator(".ctx-tune-val.now b").innerText(), /250K/);
assert.equal(await page.locator(".ctx-tune-row").nth(0).locator("button.primary").count(), 1);
await page.locator(".ctx-tune-row").nth(0).locator(".ctx-tune-pick").click();
await menu.waitFor();
assert.match(await item("250K").getAttribute("class"), /\bon\b/);
await page.keyboard.press("Escape");
assert.equal(posts.length, 1, "closing the menu puts nothing in");
await ctx.close();
});
}
assert.deepEqual(errors, []);
});
}
+11 -8
View File
@@ -81,10 +81,13 @@ func WeightsFor(model string) Weights {
return Weights{Read: 0.1, Write: 1, Write1h: 1, Out: 8}
}
// Point is one setting tried and what the period would have cost with it.
// Point is one setting tried and what the period would have cost with it,
// and how many compactions it would have made there: what a window over
// the leanest buys, said beside what it costs (#1860).
type Point struct {
Value int `json:"value"`
Cost float64 `json:"cost"`
Value int `json:"value"`
Cost float64 `json:"cost"`
Compacts int `json:"compacts"`
}
// Facts are what a replay found of the user's habits, said beside the
@@ -319,13 +322,13 @@ func Compact(cs []Call, o CompactOpts) *Compaction {
// growth, free over it
floor := max(o.Min, roundUp(after+max(after/2, 20*f.Growth)+o.Reserve, o.Step))
r := &Compaction{Model: model, Current: cur, Window: o.Window, Facts: f}
run := func(v int) float64 {
c, _, _ := replayCompact(ss, max(after+1, v-o.Reserve), after, b, rework, w, write)
return c
run := func(v int) Point {
c, n, _ := replayCompact(ss, max(after+1, v-o.Reserve), after, b, rework, w, write)
return Point{Value: v, Cost: c, Compacts: n}
}
r.Cost = run(cur)
r.Cost = run(cur).Cost
for v := floor; v <= top; v += o.Step {
r.Curve = append(r.Curve, Point{Value: v, Cost: run(v)})
r.Curve = append(r.Curve, run(v))
}
if len(r.Curve) == 0 {
return nil
+27
View File
@@ -124,3 +124,30 @@ func TestCompactSettingCappedByWindow(t *testing.T) {
t.Fatalf("curve reaches %d, past the model's window", last)
}
}
// Each window tried says how many compactions it would have made (#1860):
// fewer as the window grows, none once it is over every conversation, and
// at the window the agent ran with, about as many as its files show.
func TestCompactCurveCountsCompactions(t *testing.T) {
cs := many(3, func(id string, t0 time.Time) []Call {
return session(id, t0, 600, 30000, 5000, 967000, 60000, 30*time.Second, false)
})
o := claudeOpts
o.Window, o.Current = 1000000, 1000000
r := Compact(cs, o)
if r == nil {
t.Fatal("no advice")
}
first, last := r.Curve[0], r.Curve[len(r.Curve)-1]
if first.Compacts <= last.Compacts || last.Compacts == 0 {
t.Fatalf("%d compactions at %d, %d at %d: want more at the smaller window, some at the largest", first.Compacts, first.Value, last.Compacts, last.Value)
}
for i := 1; i < len(r.Curve); i++ {
if r.Curve[i].Compacts > r.Curve[i-1].Compacts {
t.Fatalf("%d compactions at %d, more than %d at %d", r.Curve[i].Compacts, r.Curve[i].Value, r.Curve[i-1].Compacts, r.Curve[i-1].Value)
}
}
if d := last.Compacts - r.Facts.Compacts; d < -3 || d > 3 {
t.Fatalf("%d compactions replayed at %d, %d seen in the files", last.Compacts, last.Value, r.Facts.Compacts)
}
}