tui-status-line-items.test.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. import { afterEach, describe, expect, it } from 'vitest';
  2. import { TuiStatusLine } from '../../src/tui/shell/chrome.js';
  3. import { stripAnsi, visibleWidth } from '../../src/tui/rendering/text.js';
  4. import { setCapabilityOverrides } from '../../src/tui/engine/public.js';
  5. import type { TuiShellState } from '../../src/tui/shell/contracts.js';
  6. import { resolveTuiAgentRef } from '../../src/tui/shell/status-protocol.js';
  7. import {
  8. TUI_STATUS_LINE_DEFAULT_ITEMS,
  9. parseTuiStatusLineItem,
  10. parseTuiStatusLineItems,
  11. } from '../../src/tui/shell/status-line-items.js';
  12. const BASE_STATE: TuiShellState = {
  13. version: '0.1.0',
  14. workspace: '/home/dev/repo',
  15. homeDir: '/home/dev',
  16. runtimeStatus: 'ready',
  17. sessionTitle: 'Ship status line',
  18. model: 'minimax/m2',
  19. thinking: 'on',
  20. permissionMode: 'auto',
  21. workspaceGit: {
  22. isGitRepo: true,
  23. branch: 'feat/status-line',
  24. detached: false,
  25. isWorktree: false,
  26. },
  27. };
  28. function render(state: TuiShellState, width = 200): string {
  29. return new TuiStatusLine(state).render(width).join('\n');
  30. }
  31. describe('status line item parsing', () => {
  32. it('resolves canonical ids and known aliases', () => {
  33. expect(parseTuiStatusLineItem('current-dir')).toBe('current-dir');
  34. expect(parseTuiStatusLineItem('workspace')).toBe('current-dir');
  35. expect(parseTuiStatusLineItem('permissions')).toBe('approval-mode');
  36. expect(parseTuiStatusLineItem('context')).toBe('context-remaining');
  37. expect(parseTuiStatusLineItem('context-window')).toBe('context-window');
  38. expect(parseTuiStatusLineItem('cache-read')).toBe('cache-read-ratio');
  39. expect(parseTuiStatusLineItem('build-mode')).toBe('build-mode');
  40. expect(parseTuiStatusLineItem('status-protocol')).toBe('build-mode');
  41. expect(parseTuiStatusLineItem('vela')).toBe('build-mode');
  42. expect(parseTuiStatusLineItem('custom-command')).toBe('custom-command');
  43. expect(parseTuiStatusLineItem('custom')).toBe('custom-command');
  44. expect(parseTuiStatusLineItem('tips')).toBeUndefined();
  45. });
  46. it('is case and whitespace insensitive', () => {
  47. expect(parseTuiStatusLineItem(' Model-With-Reasoning ')).toBe('model-with-reasoning');
  48. });
  49. it('ignores unknown ids instead of failing', () => {
  50. expect(parseTuiStatusLineItem('five-hour-limit')).toBeUndefined();
  51. expect(parseTuiStatusLineItems(['current-dir', 'not-a-real-item', 'git-branch'])).toEqual([
  52. 'current-dir',
  53. 'git-branch',
  54. ]);
  55. });
  56. it('preserves configured order and drops duplicates', () => {
  57. expect(parseTuiStatusLineItems(['git-branch', 'current-dir', 'branch'])).toEqual([
  58. 'git-branch',
  59. 'current-dir',
  60. ]);
  61. });
  62. });
  63. describe('TuiStatusLine default items', () => {
  64. it('keeps build-mode and cache diagnostics out of the default order', () => {
  65. expect(TUI_STATUS_LINE_DEFAULT_ITEMS).not.toContain('build-mode');
  66. expect(TUI_STATUS_LINE_DEFAULT_ITEMS).toContain('context-remaining');
  67. expect(TUI_STATUS_LINE_DEFAULT_ITEMS).not.toContain('custom-command');
  68. expect(TUI_STATUS_LINE_DEFAULT_ITEMS).not.toContain('tips');
  69. expect(TUI_STATUS_LINE_DEFAULT_ITEMS).not.toContain('cache-read-ratio');
  70. });
  71. it('replaces capacity with live context headroom while preserving explicit configuration', () => {
  72. const state = {
  73. ...BASE_STATE,
  74. sessionCacheReadRatio: 0.9,
  75. contextUsage: { usedTokens: 80_000, contextWindowTokens: 100_000 },
  76. };
  77. const lowContext = stripAnsi(render(state));
  78. expect(lowContext).toContain('Context 20% left');
  79. expect(lowContext).not.toContain('Context 100K');
  80. expect(lowContext).not.toContain('Cache');
  81. const healthyContext = stripAnsi(
  82. render({
  83. ...state,
  84. contextUsage: { usedTokens: 50_000, contextWindowTokens: 100_000 },
  85. }),
  86. );
  87. expect(healthyContext).toContain('Context 50% left');
  88. expect(healthyContext).not.toContain('Context 100K');
  89. expect(render({ ...state, statusLineItems: ['model'] })).not.toContain('Context');
  90. expect(render({ ...state, statusLineItems: ['cache-read-ratio'] })).toContain('Cache 90%');
  91. expect(
  92. render({
  93. ...state,
  94. contextUsage: { usedTokens: Number.NaN, contextWindowTokens: 100_000 },
  95. }),
  96. ).not.toContain('NaN');
  97. });
  98. it('keeps explicitly configured capacity and headroom independent', () => {
  99. const explicit = stripAnsi(
  100. render({
  101. ...BASE_STATE,
  102. statusLineItems: ['context-window', 'context-remaining'],
  103. contextUsage: { usedTokens: 50_000, contextWindowTokens: 100_000 },
  104. }),
  105. );
  106. expect(explicit).toContain('Context 100K');
  107. expect(explicit).toContain('Context 50% left');
  108. });
  109. it('keeps rotating prose out of the stable status rail', () => {
  110. expect(render(BASE_STATE)).not.toContain('Tip:');
  111. });
  112. it('lets build-mode own the line when conditional items are also configured', () => {
  113. const line = render({
  114. ...BASE_STATE,
  115. statusLineItems: ['build-mode', 'context-remaining'],
  116. agentStatus: 'ready',
  117. contextUsage: { usedTokens: 40_000, contextWindowTokens: 200_000 },
  118. });
  119. expect(line).toContain('[V]');
  120. expect(line).not.toContain('Context 80% left');
  121. });
  122. });
  123. describe('context window capacity', () => {
  124. it.each([
  125. [1_000_000, '1M'],
  126. [512_000, '512K'],
  127. [128_001, '128001'],
  128. ] as const)('shows %d tokens by default before any usage is available', (tokens, label) => {
  129. expect(stripAnsi(render({ ...BASE_STATE, contextWindowTokens: tokens }))).toContain(
  130. `Context ${label}`,
  131. );
  132. });
  133. it('uses the Runtime usage window before the model fallback', () => {
  134. const line = stripAnsi(
  135. render({
  136. ...BASE_STATE,
  137. statusLineItems: ['context-window'],
  138. contextWindowTokens: 1_000_000,
  139. contextUsage: { usedTokens: 1_000, contextWindowTokens: 512_000 },
  140. }),
  141. );
  142. expect(line).toContain('Context 512K');
  143. expect(line).not.toContain('Context 1M');
  144. expect(line).not.toContain('% left');
  145. });
  146. it.each([undefined, 0, -1, Number.NaN, Number.POSITIVE_INFINITY])(
  147. 'hides unavailable capacity %s',
  148. (tokens) => {
  149. expect(
  150. render({
  151. ...BASE_STATE,
  152. statusLineItems: ['context-window'],
  153. contextWindowTokens: tokens,
  154. }).trim(),
  155. ).toBe('');
  156. },
  157. );
  158. it('honours configured items and keeps capacity readable at common widths', () => {
  159. const state = { ...BASE_STATE, contextWindowTokens: 1_000_000 };
  160. expect(render({ ...state, statusLineItems: ['model'] })).not.toContain('Context');
  161. expect(stripAnsi(render({ ...state, statusLineItems: ['context-window'] }))).toContain(
  162. 'Context 1M',
  163. );
  164. for (const width of [80, 120]) {
  165. const line = render(state, width);
  166. expect(stripAnsi(line)).toMatch(/(?:Context|Ctx) 1M/u);
  167. expect(line.split('\n').every((row) => visibleWidth(row) <= width)).toBe(true);
  168. }
  169. });
  170. });
  171. describe('agent ref', () => {
  172. it('is stable, bounded, and opaque', () => {
  173. const firstTurn = 'turn_550e8400-e29b-41d4-a716-446655440000';
  174. const secondTurn = 'turn_6ba7b810-9dad-11d1-80b4-00c04fd430c8';
  175. const firstRef = resolveTuiAgentRef(firstTurn);
  176. expect(firstRef).toMatch(/^[a-z0-9]{6}$/u);
  177. expect(resolveTuiAgentRef(firstTurn)).toBe(firstRef);
  178. expect(resolveTuiAgentRef(secondTurn)).toMatch(/^[a-z0-9]{6}$/u);
  179. expect(resolveTuiAgentRef(secondTurn)).not.toBe(firstRef);
  180. expect(firstRef).not.toContain('550e8400');
  181. });
  182. it('uses none when no Runtime turn id is available', () => {
  183. expect(resolveTuiAgentRef(undefined)).toBe('none');
  184. expect(resolveTuiAgentRef(' ')).toBe('none');
  185. });
  186. });
  187. describe('TuiStatusLine configured items', () => {
  188. it('renders only the configured items, in the configured order', () => {
  189. const line = render({
  190. ...BASE_STATE,
  191. statusLineItems: ['model-with-reasoning', 'current-dir'],
  192. });
  193. // The model label keeps only its last path segment, matching existing behaviour.
  194. expect(line).toContain('m2');
  195. expect(line).toContain('~/repo');
  196. // Git and session title are omitted because they were not configured.
  197. expect(line).not.toContain('feat/status-line');
  198. expect(line).not.toContain('Ship status line');
  199. expect(line.indexOf('m2')).toBeLessThan(line.indexOf('~/repo'));
  200. });
  201. it('honours an empty configured list as a blank status line', () => {
  202. expect(render({ ...BASE_STATE, statusLineItems: [] }).trim()).toBe('');
  203. });
  204. it('renders the model without the reasoning suffix for the model item', () => {
  205. const line = render({ ...BASE_STATE, statusLineItems: ['model'] });
  206. expect(line).toContain('m2');
  207. expect(line).not.toContain('Thinking');
  208. });
  209. });
  210. describe('context-remaining item', () => {
  211. const items: TuiShellState['statusLineItems'] = ['context-remaining'];
  212. it('falls back to the model context window when usage omits one', () => {
  213. const line = render({
  214. ...BASE_STATE,
  215. statusLineItems: items,
  216. contextUsage: { usedTokens: 50_000 },
  217. contextWindowTokens: 100_000,
  218. });
  219. expect(line).toContain('Context 50% left');
  220. });
  221. it('renders nothing when no context window can be resolved', () => {
  222. const line = render({
  223. ...BASE_STATE,
  224. statusLineItems: items,
  225. contextUsage: { usedTokens: 1_000 },
  226. });
  227. expect(line.trim()).toBe('');
  228. });
  229. it('clamps overflow to zero rather than reporting negative headroom', () => {
  230. const line = render({
  231. ...BASE_STATE,
  232. statusLineItems: items,
  233. contextUsage: { usedTokens: 150_000, contextWindowTokens: 100_000 },
  234. });
  235. expect(line).toContain('Context 0% left');
  236. });
  237. it('shrinks to a compact label on a narrow terminal', () => {
  238. const state: TuiShellState = {
  239. ...BASE_STATE,
  240. statusLineItems: ['current-dir', 'context-remaining'],
  241. contextUsage: { usedTokens: 25_000, contextWindowTokens: 100_000 },
  242. };
  243. expect(render(state)).toContain('Context 75% left');
  244. const narrow = render(state, 16);
  245. expect(narrow).not.toContain('Context 75% left');
  246. expect(narrow).toContain('75%');
  247. });
  248. });
  249. describe('cache-read-ratio item', () => {
  250. it('renders the Session-wide cache read ratio when prompt usage is available', () => {
  251. const line = render({
  252. ...BASE_STATE,
  253. statusLineItems: ['cache-read-ratio'],
  254. sessionCacheReadRatio: 0.8,
  255. });
  256. expect(line).toContain('Cache 80%');
  257. });
  258. it('renders nothing before the Runtime supplies a Session metric', () => {
  259. expect(render({ ...BASE_STATE, statusLineItems: ['cache-read-ratio'] }).trim()).toBe('');
  260. });
  261. it('shrinks to a compact label without changing the percentage', () => {
  262. const state: TuiShellState = {
  263. ...BASE_STATE,
  264. statusLineItems: ['current-dir', 'cache-read-ratio'],
  265. sessionCacheReadRatio: 0.923,
  266. };
  267. expect(render(state)).toContain('Cache 92%');
  268. expect(render(state, 16)).toContain('92%');
  269. });
  270. });
  271. describe('custom-command block display', () => {
  272. const blockState: TuiShellState = {
  273. ...BASE_STATE,
  274. statusLineItems: ['current-dir', 'custom-command', 'model'],
  275. customStatusText:
  276. 'Context ready\nCI passed\nEnvironment test\nTasks idle\nExtra status\nToo many',
  277. };
  278. it.each([undefined, 'above', 'below'] as const)(
  279. 'places custom rows %s without changing the original footer at any width',
  280. (position) => {
  281. const status = new TuiStatusLine(blockState, { display: 'block', maxLines: 2, position });
  282. const original = new TuiStatusLine({
  283. ...blockState,
  284. statusLineItems: ['current-dir', 'model'],
  285. });
  286. for (const width of [160, 40, 1]) {
  287. const lines = status.render(width).map(stripAnsi);
  288. const originalLines = original.render(width).slice(1).map(stripAnsi);
  289. expect(lines).toHaveLength(3 + originalLines.length);
  290. expect(
  291. position === 'below' ? lines.slice(1, 1 + originalLines.length) : lines.slice(3),
  292. ).toEqual(originalLines);
  293. expect(lines.every((line) => visibleWidth(line) <= width)).toBe(true);
  294. }
  295. const lines = status.render(160).map(stripAnsi);
  296. expect(position === 'below' ? lines.slice(-2) : lines.slice(1, 3)).toEqual([
  297. 'Context ready',
  298. 'CI passed',
  299. ]);
  300. },
  301. );
  302. it.each([
  303. [undefined, 3],
  304. [Number.NaN, 3],
  305. [0, 1],
  306. [2.9, 2],
  307. [100, 5],
  308. ])('bounds maxLines %s to %s visible rows', (maxLines, expected) => {
  309. const status = new TuiStatusLine(blockState, { display: 'block', maxLines });
  310. expect(status.render(120)).toHaveLength(expected + 2);
  311. });
  312. it('sanitizes multiline controls, discards blank rows and truncates wide Unicode text', () => {
  313. const status = new TuiStatusLine(
  314. {
  315. ...blockState,
  316. statusLineItems: ['custom-command'],
  317. customStatusText:
  318. '\u001b[31m中文状态很长\u001b[0m\r\n\n\u0007\nCI\tpassed\rOK\n\u001b]0;title\u0007ready',
  319. },
  320. { display: 'block' },
  321. );
  322. const lines = status.render(10).map(stripAnsi);
  323. expect(lines).toEqual(['', '中文状态…', 'CI passed…', 'ready']);
  324. expect(lines.every((line) => visibleWidth(line) <= 10)).toBe(true);
  325. expect(lines.join('')).not.toMatch(/[\r\n\t\u0007\u001b]/u);
  326. });
  327. it.each(['above', 'below'] as const)(
  328. 'shrinks custom rows %s first and restores them when the viewport grows',
  329. (position) => {
  330. const status = new TuiStatusLine(blockState, { display: 'block', maxLines: 5, position });
  331. const original = new TuiStatusLine({
  332. ...blockState,
  333. statusLineItems: ['current-dir', 'model'],
  334. });
  335. const lines = status.renderViewport(120, 3).map(stripAnsi);
  336. expect(position === 'below' ? lines.slice(-1) : lines.slice(1, -1)).toEqual([
  337. 'Context ready',
  338. ]);
  339. expect(status.renderViewport(120, 2)).toEqual(original.render(120));
  340. expect(status.renderViewport(120, 0)).toEqual(original.render(120));
  341. expect(status.renderViewport(120, 20)).toHaveLength(7);
  342. },
  343. );
  344. it('does not reserve rows for empty or control-only output', () => {
  345. const original = new TuiStatusLine({
  346. ...blockState,
  347. statusLineItems: ['current-dir', 'model'],
  348. });
  349. for (const text of ['', '\n\u0007\u001b[0m\n', undefined]) {
  350. const status = new TuiStatusLine(
  351. { ...blockState, customStatusText: text },
  352. { display: 'block' },
  353. );
  354. expect(status.render(120)).toEqual(original.render(120));
  355. }
  356. });
  357. it('keeps an explicit custom-only block empty when there is no output or room', () => {
  358. const status = new TuiStatusLine(
  359. { ...blockState, statusLineItems: ['custom-command'] },
  360. { display: 'block' },
  361. );
  362. expect(status.renderViewport(120, 1)).toEqual([]);
  363. status.setState({ ...blockState, statusLineItems: ['custom-command'], customStatusText: '' });
  364. expect(status.render(120)).toEqual([]);
  365. });
  366. it('does not enable custom output through the block settings alone', () => {
  367. for (const statusLineItems of [undefined, [], ['model']] as const) {
  368. const state = { ...blockState, statusLineItems };
  369. expect(new TuiStatusLine(state, { display: 'block' }).render(120)).toEqual(
  370. new TuiStatusLine(state).render(120),
  371. );
  372. }
  373. });
  374. });
  375. describe('custom-command item', () => {
  376. it('ignores block position in inline mode and keeps only the first line', () => {
  377. const state: TuiShellState = {
  378. ...BASE_STATE,
  379. statusLineItems: ['current-dir', 'custom-command', 'model'],
  380. customStatusText: 'first\nsecond',
  381. };
  382. const above = new TuiStatusLine(state, { position: 'above' }).render(200);
  383. const below = new TuiStatusLine(state, { display: 'inline', position: 'below' }).render(200);
  384. expect(below).toEqual(above);
  385. expect(above.join('')).toContain('first');
  386. expect(above.join('')).not.toContain('second');
  387. expect(stripAnsi(above[1] ?? '')).toMatch(/repo.*first.*m2/u);
  388. });
  389. it('renders the latest command output as one ordinary muted segment', () => {
  390. const line = stripAnsi(
  391. render({
  392. ...BASE_STATE,
  393. statusLineItems: ['custom-command'],
  394. customStatusText: 'Cost $1.23',
  395. }),
  396. );
  397. expect(line).toContain('Cost $1.23');
  398. });
  399. it('renders nothing before the first successful command run', () => {
  400. expect(render({ ...BASE_STATE, statusLineItems: ['custom-command'] }).trim()).toBe('');
  401. });
  402. it('renders nothing when the last run deliberately blanked the item', () => {
  403. expect(
  404. render({ ...BASE_STATE, statusLineItems: ['custom-command'], customStatusText: '' }).trim(),
  405. ).toBe('');
  406. });
  407. it('strips ANSI and control characters from untrusted command output', () => {
  408. const line = render({
  409. ...BASE_STATE,
  410. statusLineItems: ['custom-command'],
  411. customStatusText: '\u001b[31mCost\u001b[0m \u0007$1.23',
  412. });
  413. expect(line).not.toContain('\u001b[31m');
  414. expect(line).not.toContain('\u0007');
  415. expect(stripAnsi(line)).toContain('Cost $1.23');
  416. });
  417. it('truncates long output instead of flooding the rail', () => {
  418. const line = stripAnsi(
  419. render({
  420. ...BASE_STATE,
  421. statusLineItems: ['custom-command'],
  422. customStatusText: 'x'.repeat(100),
  423. }),
  424. );
  425. expect(line).toContain('…');
  426. expect(line).not.toContain('x'.repeat(61));
  427. });
  428. it('yields the whole line to build-mode when both are configured', () => {
  429. const line = render({
  430. ...BASE_STATE,
  431. statusLineItems: ['build-mode', 'custom-command'],
  432. agentStatus: 'ready',
  433. customStatusText: 'Cost $1.23',
  434. });
  435. expect(line).toContain('[V]');
  436. expect(line).not.toContain('Cost $1.23');
  437. });
  438. });
  439. describe('review link status item', () => {
  440. afterEach(() => {
  441. setCapabilityOverrides({});
  442. });
  443. const withReview = (
  444. reviewLink: NonNullable<TuiShellState['workspaceGit']>['reviewLink'],
  445. ): TuiShellState => ({
  446. ...BASE_STATE,
  447. statusLineItems: ['review-link'],
  448. workspaceGit: { ...BASE_STATE.workspaceGit!, reviewLink },
  449. });
  450. it('resolves the vendor-neutral aliases users are likely to configure', () => {
  451. expect(parseTuiStatusLineItem('review-link')).toBe('review-link');
  452. expect(parseTuiStatusLineItem('pr')).toBe('review-link');
  453. expect(parseTuiStatusLineItem('mr')).toBe('review-link');
  454. expect(parseTuiStatusLineItem('merge-request')).toBe('review-link');
  455. });
  456. it('renders a GitLab merge request with its ! shorthand', () => {
  457. const line = stripAnsi(
  458. render(withReview({ vendor: 'gitlab', url: 'https://x/-/merge_requests/312', number: 312 })),
  459. );
  460. expect(line).toContain('MR');
  461. expect(line).toContain('!312');
  462. });
  463. it('renders a GitHub pull request with its # shorthand', () => {
  464. const line = stripAnsi(
  465. render(withReview({ vendor: 'github', url: 'https://x/pull/88', number: 88 })),
  466. );
  467. expect(line).toContain('PR');
  468. expect(line).toContain('#88');
  469. });
  470. it('renders nothing when the branch has no recorded review', () => {
  471. // The whole line collapses because `review-link` was the only item
  472. // configured — an unrecorded branch must not reserve a blank rail.
  473. expect(render({ ...BASE_STATE, statusLineItems: ['review-link'] })).toBe('');
  474. });
  475. it('stays in the default order next to the branch it belongs to', () => {
  476. expect(TUI_STATUS_LINE_DEFAULT_ITEMS).toContain('review-link');
  477. expect(TUI_STATUS_LINE_DEFAULT_ITEMS.indexOf('review-link')).toBe(
  478. TUI_STATUS_LINE_DEFAULT_ITEMS.indexOf('git-branch') + 1,
  479. );
  480. });
  481. it('wraps the segment in an OSC 8 hyperlink so the review can be opened', () => {
  482. setCapabilityOverrides({ hyperlinks: true });
  483. const url = 'https://github.com/acme/widgets/pull/50';
  484. const line = render(withReview({ vendor: 'github', url, number: 50 }));
  485. expect(line).toContain(`\u001b]8;;${url}\u001b\\`);
  486. expect(line).toContain('\u001b]8;;\u001b\\');
  487. expect(stripAnsi(line)).toContain('#50');
  488. });
  489. it('emits no escape where the terminal does not forward hyperlinks', () => {
  490. // tmux and screen without passthrough would render the escape as garbage.
  491. setCapabilityOverrides({ hyperlinks: false });
  492. const line = render(
  493. withReview({ vendor: 'github', url: 'https://github.com/acme/widgets/pull/50', number: 50 }),
  494. );
  495. expect(line).not.toContain(']8;;');
  496. expect(stripAnsi(line)).toContain('#50');
  497. });
  498. it('does not let the hyperlink escape count toward the line width', () => {
  499. setCapabilityOverrides({ hyperlinks: true });
  500. const url = 'https://github.com/acme/widgets/pull/50';
  501. const linked = stripAnsi(render(withReview({ vendor: 'github', url, number: 50 })));
  502. setCapabilityOverrides({ hyperlinks: false });
  503. const plain = stripAnsi(render(withReview({ vendor: 'github', url, number: 50 })));
  504. expect(linked).toBe(plain);
  505. });
  506. it('keeps the number visible when the line is too narrow for the vendor label', () => {
  507. const narrow = stripAnsi(
  508. render(
  509. withReview({ vendor: 'gitlab', url: 'https://x/-/merge_requests/312', number: 312 }),
  510. 24,
  511. ),
  512. );
  513. expect(narrow).toContain('!312');
  514. });
  515. });