Repository navigation
Add worktree-specific favicon branding - #540
Conversation
Greptile SummaryThis PR introduces worktree-specific favicon branding: a new Key points:
Confidence Score: 3/5
Important Files Changed
Last reviewed commit: c799fca |
| export function applyUiBranding(html: string, env: NodeJS.ProcessEnv = process.env): string { | ||
| const start = html.indexOf(FAVICON_BLOCK_START); | ||
| const end = html.indexOf(FAVICON_BLOCK_END); | ||
| if (start === -1 || end === -1 || end < start) return html; | ||
|
|
||
| const before = html.slice(0, start + FAVICON_BLOCK_START.length); | ||
| const after = html.slice(end); | ||
| const links = renderFaviconLinks(isWorktreeUiBrandingEnabled(env)); | ||
| return `${before}\n${links}\n ${after}`; | ||
| } |
There was a problem hiding this comment.
DEFAULT_FAVICON_LINKS silently overwrites production favicon HTML
In non-worktree mode, applyUiBranding still replaces the entire favicon block with the hardcoded DEFAULT_FAVICON_LINKS constant instead of leaving the original HTML untouched. This creates a fragile coupling: DEFAULT_FAVICON_LINKS must always remain byte-for-byte in sync with what's between the markers in ui/index.html. If anyone adds, removes, or changes a favicon <link> in ui/index.html without also updating this constant, production will silently serve the stale hardcoded set.
The simplest fix is to bail out early when branding is not needed, preserving the original HTML exactly as built:
| export function applyUiBranding(html: string, env: NodeJS.ProcessEnv = process.env): string { | |
| const start = html.indexOf(FAVICON_BLOCK_START); | |
| const end = html.indexOf(FAVICON_BLOCK_END); | |
| if (start === -1 || end === -1 || end < start) return html; | |
| const before = html.slice(0, start + FAVICON_BLOCK_START.length); | |
| const after = html.slice(end); | |
| const links = renderFaviconLinks(isWorktreeUiBrandingEnabled(env)); | |
| return `${before}\n${links}\n ${after}`; | |
| } | |
| export function applyUiBranding(html: string, env: NodeJS.ProcessEnv = process.env): string { | |
| if (!isWorktreeUiBrandingEnabled(env)) return html; | |
| const start = html.indexOf(FAVICON_BLOCK_START); | |
| const end = html.indexOf(FAVICON_BLOCK_END); | |
| if (start === -1 || end === -1 || end < start) return html; | |
| const before = html.slice(0, start + FAVICON_BLOCK_START.length); | |
| const after = html.slice(end); | |
| const links = renderFaviconLinks(true); | |
| return `${before}\n${links}\n ${after}`; | |
| } |
With this change DEFAULT_FAVICON_LINKS (and renderFaviconLinks(false)) become dead code that can be removed, eliminating the sync hazard entirely.
Prompt To Fix With AI
This is a comment left during a code review.
Path: server/src/ui-branding.ts
Line: 32-41
Comment:
**`DEFAULT_FAVICON_LINKS` silently overwrites production favicon HTML**
In non-worktree mode, `applyUiBranding` still replaces the entire favicon block with the hardcoded `DEFAULT_FAVICON_LINKS` constant instead of leaving the original HTML untouched. This creates a fragile coupling: `DEFAULT_FAVICON_LINKS` must always remain byte-for-byte in sync with what's between the markers in `ui/index.html`. If anyone adds, removes, or changes a favicon `<link>` in `ui/index.html` without also updating this constant, production will silently serve the stale hardcoded set.
The simplest fix is to bail out early when branding is not needed, preserving the original HTML exactly as built:
```suggestion
export function applyUiBranding(html: string, env: NodeJS.ProcessEnv = process.env): string {
if (!isWorktreeUiBrandingEnabled(env)) return html;
const start = html.indexOf(FAVICON_BLOCK_START);
const end = html.indexOf(FAVICON_BLOCK_END);
if (start === -1 || end === -1 || end < start) return html;
const before = html.slice(0, start + FAVICON_BLOCK_START.length);
const after = html.slice(end);
const links = renderFaviconLinks(true);
return `${before}\n${links}\n ${after}`;
}
```
With this change `DEFAULT_FAVICON_LINKS` (and `renderFaviconLinks(false)`) become dead code that can be removed, eliminating the sync hazard entirely.
How can I resolve this? If you propose a fix, please make it concise.| it("detects worktree mode from PAPERCLIP_IN_WORKTREE", () => { | ||
| expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "true" })).toBe(true); | ||
| expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "1" })).toBe(true); | ||
| expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "false" })).toBe(false); | ||
| }); |
There was a problem hiding this comment.
Missing test case: PAPERCLIP_IN_WORKTREE absent or undefined
The test covers "true", "1", and "false" but doesn't cover the common case where the env var is not set at all (i.e., {}). isTruthyEnvValue handles this with its if (!value) return false guard, but it's worth explicitly asserting to prevent regressions:
| it("detects worktree mode from PAPERCLIP_IN_WORKTREE", () => { | |
| expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "true" })).toBe(true); | |
| expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "1" })).toBe(true); | |
| expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "false" })).toBe(false); | |
| }); | |
| it("detects worktree mode from PAPERCLIP_IN_WORKTREE", () => { | |
| expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "true" })).toBe(true); | |
| expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "1" })).toBe(true); | |
| expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "false" })).toBe(false); | |
| expect(isWorktreeUiBrandingEnabled({})).toBe(false); | |
| expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: undefined })).toBe(false); | |
| }); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: server/src/__tests__/ui-branding.test.ts
Line: 15-19
Comment:
**Missing test case: `PAPERCLIP_IN_WORKTREE` absent or `undefined`**
The test covers `"true"`, `"1"`, and `"false"` but doesn't cover the common case where the env var is not set at all (i.e., `{}`). `isTruthyEnvValue` handles this with its `if (!value) return false` guard, but it's worth explicitly asserting to prevent regressions:
```suggestion
it("detects worktree mode from PAPERCLIP_IN_WORKTREE", () => {
expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "true" })).toBe(true);
expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "1" })).toBe(true);
expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: "false" })).toBe(false);
expect(isWorktreeUiBrandingEnabled({})).toBe(false);
expect(isWorktreeUiBrandingEnabled({ PAPERCLIP_IN_WORKTREE: undefined })).toBe(false);
});
```
How can I resolve this? If you propose a fix, please make it concise.Add worktree-specific favicon branding
Add worktree-specific favicon branding
Summary
Testing