Apply the AGENTS.md comments guideline to every .ts under tests/: remove what the code already expresses, keep only what it cannot. Removed: spec-header coverage inventories the describe/test tree already names; comments restating the next line's assertion or its message; helper JSDoc whose body already says it; within-file duplicates; five stale claims (trendChart's "six aggregated turns" against agg.length === 8, agentGraph's "six categories" against CATS' seven, fold-timing's "cheapest call LAST" against a loop that feeds it first, fold-surface's unreachable plain-JSON note, contextView's "two turns" for a one-turn fixture). Kept and condensed: the projection-freeze class, strict wire/state-schema hazards, retention and pricing windows, pairing rules, hostile-input rationale, fixture and expectation-array ground truth, jsdom mechanics, and issue-numbered regressions. Comment lines 2604 -> 2014 (-22%); 85 module headers kept, 30 coverage inventories dropped; every surviving comment line is within the 140-column limit, with 36 wrapped lines joined onto fuller ones. No logic, string, identifier, import or directive changed: a comment-strip gate proves each file's comment-free code is byte-identical to HEAD, and a line-level proof pairs all 845 changed lines with an unchanged code part. pnpm run lint && pnpm run test (106 files / 2061 tests, per-file 100% coverage) && pnpm run build all pass.
55 lines
2.5 KiB
TypeScript
55 lines
2.5 KiB
TypeScript
// host/toolSources.ts — best-effort tool-to-plugin attribution: MCP server recovery from the `mcp__`
|
|
// prefix and the pinned first-party map. (A logged `plugin` field passes through headers.ts first.)
|
|
|
|
import assert from 'node:assert/strict'
|
|
import { describe, test } from 'vitest'
|
|
import {
|
|
FIRST_PARTY_SOURCES,
|
|
MCP_PREFIX,
|
|
mcpServerOf,
|
|
mcpSourceOf,
|
|
} from '../../src/host/toolSources'
|
|
|
|
describe('mcpServerOf', () => {
|
|
test('recovers the server from a plain mcp__server__tool name', () => {
|
|
assert.equal(mcpServerOf('mcp__github__get_issue'), 'github')
|
|
assert.equal(mcpServerOf('mcp__my_server__send_message'), 'my_server')
|
|
assert.equal(mcpServerOf('mcp__a__b__c'), 'a__b', 'server names may themselves contain __')
|
|
})
|
|
|
|
test('non-MCP names and malformed prefixes resolve to undefined', () => {
|
|
assert.equal(mcpServerOf('bash'), undefined)
|
|
assert.equal(mcpServerOf('mcp_server_tool'), undefined, 'no mcp__ prefix')
|
|
assert.equal(mcpServerOf('mcp__alone'), undefined, 'the prefix separator is not a server separator')
|
|
assert.equal(mcpServerOf('mcp____'), undefined, 'a second separator right at the prefix edge')
|
|
assert.equal(mcpServerOf('mcp____tool'), undefined, 'an empty server between separators')
|
|
})
|
|
|
|
test('hash-appended overlong names resolve the server that survived truncation', () => {
|
|
const hex64 = '0123456789abcdef'.repeat(4)
|
|
// Overlong names get '_<64-hex>' appended; the last __ separator survives unless the truncation cut into it.
|
|
assert.equal(mcpServerOf(`mcp__github__tool_${hex64}`), 'github')
|
|
assert.equal(mcpServerOf(`mcp__github__tool_${'z'.repeat(64)}`), 'github')
|
|
})
|
|
})
|
|
|
|
describe('mcpSourceOf', () => {
|
|
test('labels proxied tools with their server; other names stay unattributed', () => {
|
|
assert.equal(mcpSourceOf('mcp__github__get_issue'), 'mcp:github')
|
|
assert.equal(mcpSourceOf('mcp__alone'), undefined)
|
|
assert.equal(mcpSourceOf('bash'), undefined)
|
|
})
|
|
})
|
|
|
|
describe('FIRST_PARTY_SOURCES', () => {
|
|
test('the pinned map is frozen and carries the documented core names', () => {
|
|
assert.ok(Object.isFrozen(FIRST_PARTY_SOURCES))
|
|
for (const name of ['read', 'write', 'edit', 'bash', 'pwsh', 'glob', 'grep',
|
|
'web_search', 'web_fetch', 'job_kill', 'ask_user_question', 'plan', 'skill',
|
|
'todo_write', 'subagent', 'send_message', 'ralph', 'workflow', 'run_code']) {
|
|
assert.ok(name in FIRST_PARTY_SOURCES, `expected ${name} in the first-party map`)
|
|
}
|
|
assert.equal(MCP_PREFIX, 'mcp__')
|
|
})
|
|
})
|