Skip to content

test(workspace-helpers): add unit tests + fix off-by-one in extractCustomAgentName#599

Merged
rajbos merged 2 commits intomainfrom
test/workspace-helpers-coverage
Apr 12, 2026
Merged

test(workspace-helpers): add unit tests + fix off-by-one in extractCustomAgentName#599
rajbos merged 2 commits intomainfrom
test/workspace-helpers-coverage

Conversation

@rajbos
Copy link
Copy Markdown
Owner

@rajbos rajbos commented Apr 11, 2026

Summary

Adds 36 unit tests for workspaceHelpers.ts, covering the pure string-transformation functions that determine session attribution (editor, repository, mode, MCP tools). Also fixes a pre-existing off-by-one bug discovered by the tests.

Bug fixed

extractCustomAgentName was calling slice(0, -10) to strip the .agent.md suffix, but that suffix is 9 characters, not 10. This silently dropped the last character of every custom agent name (e.g. "my-agent" became "my-agen"). Changed to slice(0, -9).

What's tested

  • getModeType: null/undefined defaults, ask/edit/agent/plan/customAgent routing, plan-agent URI detection, custom .agent.md URI detection
  • getRepoDisplayName: empty/unknown, HTTPS URLs, SSH URLs, git+https, GitHub Enterprise
  • parseGitRemoteUrl: empty input, HTTPS remote, SSH remote, stops at next section boundary, returns undefined when no origin
  • isMcpTool: mcp. and mcp_ prefixes, regular tool names
  • normalizeMcpToolName: mcp_github_github_ -> mcp_io_github_git_, mcp.github.github. -> mcp.io.github.git., passthrough
  • extractMcpServerName: toolNameMap lookup, known prefix fallbacks, generic fallback
  • extractCustomAgentName: non-agent paths, file:/// URI, plain path
  • getEditorNameFromRoot: empty, .copilot, Code Insiders, Cursor, .continue, opencode

Approach

All functions under test are pure string transformations. Tests use inline fixture strings -- no mocks, no file I/O.

rajbos and others added 2 commits April 12, 2026 00:34
…stomAgentName

Add 36 unit tests covering getModeType, getRepoDisplayName, parseGitRemoteUrl,
isMcpTool, normalizeMcpToolName, extractMcpServerName, extractCustomAgentName,
and getEditorNameFromRoot. All functions are pure string transformations so tests
use inline fixtures with no mocks.

Also fix a pre-existing bug discovered by the tests: extractCustomAgentName was
calling slice(0, -10) to strip '.agent.md' but that suffix is only 9 characters,
causing the last character of the agent name to be silently dropped.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rajbos rajbos enabled auto-merge (squash) April 12, 2026 08:30
@rajbos rajbos merged commit f223b3f into main Apr 12, 2026
17 checks passed
@rajbos rajbos deleted the test/workspace-helpers-coverage branch April 12, 2026 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant