Skip to content

Commit 5a85396

Browse files
fix(tui): single guarded ProgressBar render site (#133) (#254)
* fix(tui): single guarded ProgressBar render site (#133) Consolidate the two independent ProgressBar declaration sites in BrainStatusBar into one shared StatusProgress helper so a duplicate/orphan progress bar in the sidebar or home_bottom slot cannot be reintroduced. barWidth stays 12 (sidebar) / 10 (home) and both mounts remain behind showProgress(). Adds a source-integrity regression test (issue #133) and bumps the version to 1.8.21. * test(tui): assert each StatusProgress mount is guarded, add v1.8.21 note (#133)
1 parent 7e3e2b8 commit 5a85396

4 files changed

Lines changed: 78 additions & 3 deletions

File tree

‎HISTORY.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v1.8.21 (2026-11-28)
4+
5+
### Fixed
6+
7+
- TUI status bar rendered a duplicate `ProgressBar` in the non-centered `sidebar` variant. Both variants now mount the bar through the single shared `StatusProgress` helper, each behind its own `showProgress()` guard (#133, #254).
8+
39
## v1.8.20 (2026-11-28)
410

511
### Changed

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@four-bytes/four-opencode-brain",
3-
"version": "1.8.20",
3+
"version": "1.8.21",
44
"description": "Unified brain plugin — single SQLite DB for RAG search, memory, and knowledge base",
55
"license": "Apache-2.0",
66
"type": "module",

‎src/tui.tsx‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ function BrainStatusBar(props: { variant: "sidebar" | "home"; api: TuiPluginApi;
108108
const indicatorColor = () => connecting() ? theme().error : (hasError() ? theme().error : fg());
109109
const textColor = () => connecting() ? theme().error : theme().textMuted;
110110

111+
// Single ProgressBar render site shared by both variants. Keeping the bar in
112+
// one declaration makes a second (orphan) mount in either variant impossible.
113+
const StatusProgress = (p: { barWidth: number }) => (
114+
<ProgressBar
115+
current={current()}
116+
total={total()}
117+
showLabel={false}
118+
width="auto"
119+
barWidth={p.barWidth}
120+
fillBg="#aaa"
121+
fillFg="#000"
122+
/>
123+
);
124+
111125
return (
112126
<box width="100%">
113127
<Show when={props.variant === "sidebar"}>
@@ -127,7 +141,7 @@ function BrainStatusBar(props: { variant: "sidebar" | "home"; api: TuiPluginApi;
127141
</box>
128142
<Show when={showProgress()}>
129143
<box flexShrink={0}>
130-
<ProgressBar current={current()} total={total()} showLabel={false} width="auto" barWidth={12} fillBg="#aaa" fillFg="#000" />
144+
<StatusProgress barWidth={12} />
131145
</box>
132146
</Show>
133147
</box>
@@ -141,7 +155,7 @@ function BrainStatusBar(props: { variant: "sidebar" | "home"; api: TuiPluginApi;
141155
<text fg={textColor()}> {connecting() ? "connecting…" : statusText()}</text>
142156
<Show when={showProgress()}>
143157
<text fg={theme().textMuted}> </text>
144-
<ProgressBar current={current()} total={total()} showLabel={false} width="auto" barWidth={10} fillBg="#aaa" fillFg="#000" />
158+
<StatusProgress barWidth={10} />
145159
</Show>
146160
</box>
147161
</Show>

‎test/dist-integrity.test.ts‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,58 @@ describe("dist-integrity", () => {
4343
expect(existsSync(SPINNER_DIST_PATH)).toBe(false);
4444
});
4545
});
46+
47+
// Issue #133 — the Brain status bar must have exactly one ProgressBar render
48+
// site, mounted at most once per variant, so the duplicate/orphan bar reported
49+
// for the non-centered sidebar cannot come back.
50+
describe("tui ProgressBar render guard (#133)", () => {
51+
const src = readFileSync(join(import.meta.dir, "..", "src", "tui.tsx"), "utf-8");
52+
const count = (haystack: string, needle: string) => haystack.split(needle).length - 1;
53+
const sidebarStart = src.indexOf('props.variant === "sidebar"');
54+
const homeStart = src.indexOf('props.variant === "home"');
55+
const sidebarBranch = src.slice(sidebarStart, homeStart);
56+
const homeBranch = src.slice(homeStart);
57+
58+
test("variant branches are locatable", () => {
59+
expect(sidebarStart).toBeGreaterThan(-1);
60+
expect(homeStart).toBeGreaterThan(sidebarStart);
61+
});
62+
63+
test("declares exactly one ProgressBar render site", () => {
64+
expect(count(src, "<ProgressBar")).toBe(1);
65+
});
66+
67+
test("the ProgressBar lives in the shared StatusProgress helper", () => {
68+
const helperStart = src.indexOf("const StatusProgress");
69+
expect(helperStart).toBeGreaterThan(-1);
70+
const helperEnd = src.indexOf("return (", helperStart);
71+
expect(count(src.slice(helperStart, helperEnd), "<ProgressBar")).toBe(1);
72+
});
73+
74+
test("sidebar and home each mount StatusProgress exactly once", () => {
75+
expect(count(sidebarBranch, "<StatusProgress")).toBe(1);
76+
expect(count(homeBranch, "<StatusProgress")).toBe(1);
77+
});
78+
79+
test("no orphan ProgressBar exists outside the StatusProgress helper", () => {
80+
const helperStart = src.indexOf("const StatusProgress");
81+
const helperEnd = src.indexOf("return (", helperStart);
82+
expect(count(src.slice(0, helperStart) + src.slice(helperEnd), "<ProgressBar")).toBe(0);
83+
});
84+
85+
test("both StatusProgress mounts sit behind the showProgress() guard", () => {
86+
expect(count(src, "<StatusProgress")).toBe(2);
87+
for (const [name, branch] of [
88+
["sidebar", sidebarBranch],
89+
["home", homeBranch],
90+
] as const) {
91+
const mount = branch.indexOf("<StatusProgress");
92+
expect(mount).toBeGreaterThan(-1);
93+
const guard = branch.lastIndexOf("<Show when={showProgress()}>", mount);
94+
expect(guard).toBeGreaterThan(-1);
95+
const guardEnd = branch.indexOf("</Show>", guard);
96+
// The mount must fall inside the guard block of its own variant branch.
97+
expect(guardEnd, `${name} mount not wrapped by showProgress()`).toBeGreaterThan(mount);
98+
}
99+
});
100+
});

0 commit comments

Comments
 (0)