@hunt-labs/bytekit-mcp 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/README.md +10 -10
- package/dist/client.d.ts +45 -0
- package/dist/client.js +206 -21
- package/dist/docs-bundle/docs-bundle.json +133 -123
- package/dist/docs-bundle/helpers.d.ts +17 -1
- package/dist/docs-bundle/helpers.js +25 -0
- package/dist/lib/render-scrape.d.ts +27 -0
- package/dist/lib/render-scrape.js +83 -0
- package/dist/tools/get-result.js +15 -3
- package/dist/tools/list-docs.d.ts +6 -0
- package/dist/tools/list-docs.js +8 -4
- package/dist/tools/scrape-url.js +5 -69
- package/dist/tools/web-search.js +6 -2
- package/package.json +1 -1
- package/dist/docs-bundle/load-bundle.test.d.ts +0 -9
- package/dist/docs-bundle/load-bundle.test.js +0 -50
|
@@ -5,6 +5,22 @@
|
|
|
5
5
|
* without spinning up the Next.js server. The build script imports them at
|
|
6
6
|
* runtime; the test suite imports them for unit coverage.
|
|
7
7
|
*/
|
|
8
|
+
/**
|
|
9
|
+
* Every section label `slugToSection` can return.
|
|
10
|
+
*
|
|
11
|
+
* This is the single source of truth for the docs taxonomy: the bundle
|
|
12
|
+
* generator stamps `section` from `slugToSection`, and `list_docs` advertises
|
|
13
|
+
* its `section` filter values by joining this tuple. Adding a mapping below
|
|
14
|
+
* without adding its label here (or vice versa) is caught by the bundle
|
|
15
|
+
* invariant test in `src/__tests__/build-docs-bundle.test.ts`.
|
|
16
|
+
*
|
|
17
|
+
* `'General'` is the deliberate fallback for bare top-level pages
|
|
18
|
+
* (`changelog`, `introduction`, `mcp`, `quickstart`) — not a catch-all for
|
|
19
|
+
* unmapped directories (issue #2570).
|
|
20
|
+
*/
|
|
21
|
+
export declare const DOC_SECTIONS: readonly ["Guides", "API Reference", "SDK Reference", "CLI Reference", "Libraries", "General"];
|
|
22
|
+
/** One of the section labels enumerated by {@link DOC_SECTIONS}. */
|
|
23
|
+
export type DocSection = (typeof DOC_SECTIONS)[number];
|
|
8
24
|
/**
|
|
9
25
|
* Maps a page slug (array of path segments) to a human-readable section
|
|
10
26
|
* label for the bundle schema.
|
|
@@ -12,7 +28,7 @@
|
|
|
12
28
|
* Slug segments come from the fumadocs source manifest and mirror the
|
|
13
29
|
* directory structure under `content/docs/`.
|
|
14
30
|
*/
|
|
15
|
-
export declare function slugToSection(slug: string[]):
|
|
31
|
+
export declare function slugToSection(slug: string[]): DocSection;
|
|
16
32
|
/**
|
|
17
33
|
* Returns true for the root landing page, which should be excluded from
|
|
18
34
|
* the bundle (it contains only JSX nav cards, no prose content).
|
|
@@ -5,6 +5,27 @@
|
|
|
5
5
|
* without spinning up the Next.js server. The build script imports them at
|
|
6
6
|
* runtime; the test suite imports them for unit coverage.
|
|
7
7
|
*/
|
|
8
|
+
/**
|
|
9
|
+
* Every section label `slugToSection` can return.
|
|
10
|
+
*
|
|
11
|
+
* This is the single source of truth for the docs taxonomy: the bundle
|
|
12
|
+
* generator stamps `section` from `slugToSection`, and `list_docs` advertises
|
|
13
|
+
* its `section` filter values by joining this tuple. Adding a mapping below
|
|
14
|
+
* without adding its label here (or vice versa) is caught by the bundle
|
|
15
|
+
* invariant test in `src/__tests__/build-docs-bundle.test.ts`.
|
|
16
|
+
*
|
|
17
|
+
* `'General'` is the deliberate fallback for bare top-level pages
|
|
18
|
+
* (`changelog`, `introduction`, `mcp`, `quickstart`) — not a catch-all for
|
|
19
|
+
* unmapped directories (issue #2570).
|
|
20
|
+
*/
|
|
21
|
+
export const DOC_SECTIONS = [
|
|
22
|
+
'Guides',
|
|
23
|
+
'API Reference',
|
|
24
|
+
'SDK Reference',
|
|
25
|
+
'CLI Reference',
|
|
26
|
+
'Libraries',
|
|
27
|
+
'General',
|
|
28
|
+
];
|
|
8
29
|
/**
|
|
9
30
|
* Maps a page slug (array of path segments) to a human-readable section
|
|
10
31
|
* label for the bundle schema.
|
|
@@ -20,6 +41,10 @@ export function slugToSection(slug) {
|
|
|
20
41
|
return 'API Reference';
|
|
21
42
|
if (first === 'sdk')
|
|
22
43
|
return 'SDK Reference';
|
|
44
|
+
if (first === 'cli')
|
|
45
|
+
return 'CLI Reference';
|
|
46
|
+
if (first === 'libraries')
|
|
47
|
+
return 'Libraries';
|
|
23
48
|
return 'General';
|
|
24
49
|
}
|
|
25
50
|
/**
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ScrapeResult } from '../client.js';
|
|
2
|
+
/**
|
|
3
|
+
* Renders a scrape envelope (from POST /v1/scrape or GET /v1/scrape/{id}) into
|
|
4
|
+
* human-readable lines for MCP tool output.
|
|
5
|
+
*
|
|
6
|
+
* This is the single scrape formatter (issue #2538, E3). Both `scrape_url` (which
|
|
7
|
+
* produces an envelope) and `get_result` (which redeems an `sc_` handle) render through
|
|
8
|
+
* it, so the two surfaces cannot drift: a render-requiring scrape answered with 202 +
|
|
9
|
+
* queued envelope is described the same way whether the agent saw it at submit time or
|
|
10
|
+
* at poll time.
|
|
11
|
+
*
|
|
12
|
+
* Handles all three envelope shapes the API returns (scrape-contract.generated.ts):
|
|
13
|
+
* - queued: `{ status:'queued', id, url, status_url, queued_at, events }` — the async
|
|
14
|
+
* handle, and also what GET returns while the job is pending/processing (gateway
|
|
15
|
+
* routes/scrape.ts `handleGetScrapeById`). Non-error: the agent should poll, not fail.
|
|
16
|
+
* - failed: `{ status:'failed', id, error:{ code, message, ... } }` — flagged as a tool
|
|
17
|
+
* error, rendering the public error code + message only.
|
|
18
|
+
* - success: full envelope; primary content prefers markdown → html → raw_html, with
|
|
19
|
+
* optional links/images blocks appended.
|
|
20
|
+
*
|
|
21
|
+
* Every optional line is omitted when absent, so no `undefined`/`null` literal is ever
|
|
22
|
+
* emitted (issue #2419).
|
|
23
|
+
*/
|
|
24
|
+
export declare function renderScrapeResult(result: ScrapeResult): {
|
|
25
|
+
text: string;
|
|
26
|
+
isError: boolean;
|
|
27
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { truncateContent } from './truncate.js';
|
|
2
|
+
function renderLinks(links) {
|
|
3
|
+
return links
|
|
4
|
+
.map((link) => typeof link === 'string' ? link : `${link.url}${link.text ? ` — ${link.text}` : ''}`)
|
|
5
|
+
.join('\n');
|
|
6
|
+
}
|
|
7
|
+
function renderImages(images) {
|
|
8
|
+
return images
|
|
9
|
+
.map((image) => typeof image === 'string' ? image : `${image.url}${image.alt ? ` — ${image.alt}` : ''}`)
|
|
10
|
+
.join('\n');
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Renders a scrape envelope (from POST /v1/scrape or GET /v1/scrape/{id}) into
|
|
14
|
+
* human-readable lines for MCP tool output.
|
|
15
|
+
*
|
|
16
|
+
* This is the single scrape formatter (issue #2538, E3). Both `scrape_url` (which
|
|
17
|
+
* produces an envelope) and `get_result` (which redeems an `sc_` handle) render through
|
|
18
|
+
* it, so the two surfaces cannot drift: a render-requiring scrape answered with 202 +
|
|
19
|
+
* queued envelope is described the same way whether the agent saw it at submit time or
|
|
20
|
+
* at poll time.
|
|
21
|
+
*
|
|
22
|
+
* Handles all three envelope shapes the API returns (scrape-contract.generated.ts):
|
|
23
|
+
* - queued: `{ status:'queued', id, url, status_url, queued_at, events }` — the async
|
|
24
|
+
* handle, and also what GET returns while the job is pending/processing (gateway
|
|
25
|
+
* routes/scrape.ts `handleGetScrapeById`). Non-error: the agent should poll, not fail.
|
|
26
|
+
* - failed: `{ status:'failed', id, error:{ code, message, ... } }` — flagged as a tool
|
|
27
|
+
* error, rendering the public error code + message only.
|
|
28
|
+
* - success: full envelope; primary content prefers markdown → html → raw_html, with
|
|
29
|
+
* optional links/images blocks appended.
|
|
30
|
+
*
|
|
31
|
+
* Every optional line is omitted when absent, so no `undefined`/`null` literal is ever
|
|
32
|
+
* emitted (issue #2419).
|
|
33
|
+
*/
|
|
34
|
+
export function renderScrapeResult(result) {
|
|
35
|
+
if (result.status === 'queued') {
|
|
36
|
+
return {
|
|
37
|
+
text: [
|
|
38
|
+
`ID: ${result.id}`,
|
|
39
|
+
'Status: queued',
|
|
40
|
+
`URL: ${result.url}`,
|
|
41
|
+
`Status URL: ${result.status_url}`,
|
|
42
|
+
].join('\n'),
|
|
43
|
+
isError: false,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (result.status === 'failed') {
|
|
47
|
+
return {
|
|
48
|
+
text: [
|
|
49
|
+
`ID: ${result.id}`,
|
|
50
|
+
'Status: failed',
|
|
51
|
+
`Error: ${result.error.code}`,
|
|
52
|
+
result.error.message,
|
|
53
|
+
].join('\n'),
|
|
54
|
+
isError: true,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
// Primary content for display: prefer markdown → html → rawHtml
|
|
58
|
+
const content = result.formats.markdown ?? result.formats.html ?? result.formats.raw_html ?? '';
|
|
59
|
+
const { text, truncated } = truncateContent(content);
|
|
60
|
+
const metaLines = [
|
|
61
|
+
`ID: ${result.id}`,
|
|
62
|
+
`URL: ${result.url}`,
|
|
63
|
+
result.final_url !== result.url ? `Final URL: ${result.final_url}` : null,
|
|
64
|
+
result.status_code !== null ? `Status Code: ${result.status_code}` : null,
|
|
65
|
+
result.content_type ? `Content-Type: ${result.content_type}` : null,
|
|
66
|
+
result.metadata.title ? `Title: ${result.metadata.title}` : null,
|
|
67
|
+
truncated ? 'Note: Content was truncated to 100KB' : null,
|
|
68
|
+
]
|
|
69
|
+
.filter(Boolean)
|
|
70
|
+
.join('\n');
|
|
71
|
+
let body = `${metaLines}\n\n---\n\n${text}`;
|
|
72
|
+
// Append links block when present
|
|
73
|
+
if (Array.isArray(result.formats.links) && result.formats.links.length > 0) {
|
|
74
|
+
const linkList = renderLinks(result.formats.links);
|
|
75
|
+
body += `\n\nLinks (${result.formats.links.length}):\n${linkList}`;
|
|
76
|
+
}
|
|
77
|
+
// Append images block when present
|
|
78
|
+
if (Array.isArray(result.formats.images) && result.formats.images.length > 0) {
|
|
79
|
+
const imgList = renderImages(result.formats.images);
|
|
80
|
+
body += `\n\nImages (${result.formats.images.length}):\n${imgList}`;
|
|
81
|
+
}
|
|
82
|
+
return { text: body, isError: false };
|
|
83
|
+
}
|
package/dist/tools/get-result.js
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { renderScrapeResult } from '../lib/render-scrape.js';
|
|
2
3
|
import { renderScreenshotResult } from '../lib/render-screenshot.js';
|
|
3
4
|
export function getResultTool(server, client) {
|
|
4
|
-
server.tool('get_result', 'Get the result of a previous
|
|
5
|
-
id: z.string().describe('
|
|
5
|
+
server.tool('get_result', 'Get the result of a previous capture by ID: a screenshot (ss_ prefix) or a scrape (sc_ prefix, as returned by scrape_url when a page needs rendering).', {
|
|
6
|
+
id: z.string().describe('Result ID — ss_... (screenshot) or sc_... (scrape)'),
|
|
6
7
|
}, async (params) => {
|
|
7
8
|
try {
|
|
8
9
|
const id = params.id;
|
|
10
|
+
// Prefix dispatch: the id itself selects the resource, so one tool redeems both
|
|
11
|
+
// handle kinds (issue #2538). A render-requiring scrape answers 202 with an `sc_`
|
|
12
|
+
// id; before this, get_result rejected it outright and the handle was a dead end.
|
|
13
|
+
if (id.startsWith('sc_')) {
|
|
14
|
+
const result = await client.getScrape(id);
|
|
15
|
+
const { text, isError } = renderScrapeResult(result);
|
|
16
|
+
return {
|
|
17
|
+
...(isError ? { isError: true } : {}),
|
|
18
|
+
content: [{ type: 'text', text }],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
9
21
|
if (!id.startsWith('ss_')) {
|
|
10
22
|
return {
|
|
11
23
|
isError: true,
|
|
12
24
|
content: [
|
|
13
25
|
{
|
|
14
26
|
type: 'text',
|
|
15
|
-
text: `Invalid ID prefix. Expected ss_ (screenshot), got: ${id.substring(0, 3)}`,
|
|
27
|
+
text: `Invalid ID prefix. Expected ss_ (screenshot) or sc_ (scrape), got: ${id.substring(0, 3)}`,
|
|
16
28
|
},
|
|
17
29
|
],
|
|
18
30
|
};
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
/**
|
|
3
|
+
* The advertised description of the `section` filter, derived from
|
|
4
|
+
* `DOC_SECTIONS` so it can never drift from what `slugToSection` actually
|
|
5
|
+
* stamps onto bundle entries (issue #2570).
|
|
6
|
+
*/
|
|
7
|
+
export declare const SECTION_FILTER_DESCRIPTION: string;
|
|
2
8
|
export declare function listDocsTool(server: McpServer): void;
|
package/dist/tools/list-docs.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { loadBundle } from '../docs-bundle/load-bundle.js';
|
|
3
|
+
import { DOC_SECTIONS } from '../docs-bundle/helpers.js';
|
|
4
|
+
/**
|
|
5
|
+
* The advertised description of the `section` filter, derived from
|
|
6
|
+
* `DOC_SECTIONS` so it can never drift from what `slugToSection` actually
|
|
7
|
+
* stamps onto bundle entries (issue #2570).
|
|
8
|
+
*/
|
|
9
|
+
export const SECTION_FILTER_DESCRIPTION = `Optional section filter. One of: ${DOC_SECTIONS.map((section) => `"${section}"`).join(', ')}`;
|
|
3
10
|
export function listDocsTool(server) {
|
|
4
11
|
server.tool('list_docs', 'List all pages in the ByteKit documentation bundle. Returns a section tree of { title, section, path } for every bundled page. Use the optional section filter to narrow results.', {
|
|
5
|
-
section: z
|
|
6
|
-
.string()
|
|
7
|
-
.optional()
|
|
8
|
-
.describe('Optional section filter (e.g. "Guides", "API Reference", "SDK Reference")'),
|
|
12
|
+
section: z.string().optional().describe(SECTION_FILTER_DESCRIPTION),
|
|
9
13
|
}, async (params) => {
|
|
10
14
|
try {
|
|
11
15
|
const bundle = await loadBundle();
|
package/dist/tools/scrape-url.js
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
3
|
-
function renderLinks(links) {
|
|
4
|
-
return links
|
|
5
|
-
.map((link) => typeof link === 'string' ? link : `${link.url}${link.text ? ` — ${link.text}` : ''}`)
|
|
6
|
-
.join('\n');
|
|
7
|
-
}
|
|
8
|
-
function renderImages(images) {
|
|
9
|
-
return images
|
|
10
|
-
.map((image) => typeof image === 'string' ? image : `${image.url}${image.alt ? ` — ${image.alt}` : ''}`)
|
|
11
|
-
.join('\n');
|
|
12
|
-
}
|
|
2
|
+
import { renderScrapeResult } from '../lib/render-scrape.js';
|
|
13
3
|
export function scrapeUrlTool(server, client) {
|
|
14
|
-
server.tool('scrape_url', 'Scrape a webpage and return its content. Returns markdown by default. Use the formats parameter to request additional representations (rawHtml, html, links, images).', {
|
|
4
|
+
server.tool('scrape_url', 'Scrape a webpage and return its content. Returns markdown by default. Use the formats parameter to request additional representations (rawHtml, html, links, images). A render-requiring page may come back as Status: queued with an sc_ ID — redeem it with get_result.', {
|
|
15
5
|
url: z.string().url().describe('The URL to scrape'),
|
|
16
6
|
formats: z
|
|
17
7
|
.array(z.enum(['rawHtml', 'html', 'markdown', 'links', 'images']))
|
|
@@ -26,64 +16,10 @@ export function scrapeUrlTool(server, client) {
|
|
|
26
16
|
formats,
|
|
27
17
|
...(params.country !== undefined && { country: params.country }),
|
|
28
18
|
});
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
content: [
|
|
32
|
-
{
|
|
33
|
-
type: 'text',
|
|
34
|
-
text: [
|
|
35
|
-
`ID: ${result.id}`,
|
|
36
|
-
'Status: queued',
|
|
37
|
-
`URL: ${result.url}`,
|
|
38
|
-
`Status URL: ${result.status_url}`,
|
|
39
|
-
].join('\n'),
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
if (result.status === 'failed') {
|
|
45
|
-
return {
|
|
46
|
-
isError: true,
|
|
47
|
-
content: [
|
|
48
|
-
{
|
|
49
|
-
type: 'text',
|
|
50
|
-
text: [
|
|
51
|
-
`ID: ${result.id}`,
|
|
52
|
-
'Status: failed',
|
|
53
|
-
`Error: ${result.error.code}`,
|
|
54
|
-
result.error.message,
|
|
55
|
-
].join('\n'),
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
// Primary content for display: prefer markdown → html → rawHtml
|
|
61
|
-
const content = result.formats.markdown ?? result.formats.html ?? result.formats.raw_html ?? '';
|
|
62
|
-
const { text, truncated } = truncateContent(content);
|
|
63
|
-
const metaLines = [
|
|
64
|
-
`ID: ${result.id}`,
|
|
65
|
-
`URL: ${result.url}`,
|
|
66
|
-
result.final_url !== result.url ? `Final URL: ${result.final_url}` : null,
|
|
67
|
-
result.status_code !== null ? `Status Code: ${result.status_code}` : null,
|
|
68
|
-
result.content_type ? `Content-Type: ${result.content_type}` : null,
|
|
69
|
-
result.metadata.title ? `Title: ${result.metadata.title}` : null,
|
|
70
|
-
truncated ? 'Note: Content was truncated to 100KB' : null,
|
|
71
|
-
]
|
|
72
|
-
.filter(Boolean)
|
|
73
|
-
.join('\n');
|
|
74
|
-
let body = `${metaLines}\n\n---\n\n${text}`;
|
|
75
|
-
// Append links block when present
|
|
76
|
-
if (Array.isArray(result.formats.links) && result.formats.links.length > 0) {
|
|
77
|
-
const linkList = renderLinks(result.formats.links);
|
|
78
|
-
body += `\n\nLinks (${result.formats.links.length}):\n${linkList}`;
|
|
79
|
-
}
|
|
80
|
-
// Append images block when present
|
|
81
|
-
if (Array.isArray(result.formats.images) && result.formats.images.length > 0) {
|
|
82
|
-
const imgList = renderImages(result.formats.images);
|
|
83
|
-
body += `\n\nImages (${result.formats.images.length}):\n${imgList}`;
|
|
84
|
-
}
|
|
19
|
+
const { text, isError } = renderScrapeResult(result);
|
|
85
20
|
return {
|
|
86
|
-
|
|
21
|
+
...(isError ? { isError: true } : {}),
|
|
22
|
+
content: [{ type: 'text', text }],
|
|
87
23
|
};
|
|
88
24
|
}
|
|
89
25
|
catch (error) {
|
package/dist/tools/web-search.js
CHANGED
|
@@ -60,8 +60,12 @@ export function webSearchTool(server, client) {
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
catch (error) {
|
|
63
|
-
// Surface the API error code (e.g. search_provider_error
|
|
64
|
-
//
|
|
63
|
+
// Surface the API error code (e.g. search_provider_error, which /v1/search
|
|
64
|
+
// sends on a 502 as the flat body {"error":"search_provider_error"} — see
|
|
65
|
+
// docs/api/openapi.yaml §/v1/search 502 — and which client.ts's flat-shape
|
|
66
|
+
// branch parses into errorCode, issue #2541) without exposing any
|
|
67
|
+
// underlying provider name: the gateway's 502 body is a fixed constant, so
|
|
68
|
+
// the client error message is already vendor-free.
|
|
65
69
|
let message = error instanceof Error ? error.message : 'Unknown error';
|
|
66
70
|
if (error instanceof BytekitApiError && error.errorCode) {
|
|
67
71
|
message = `${message} (${error.errorCode})`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hunt-labs/bytekit-mcp",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "ByteKit MCP server — exposes ByteKit web-data tools (scrape, screenshot, search, docs) to AI agents over the Model Context Protocol, hosted or as a local stdio server.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Behavior tests for loadBundle's error surface (#2469).
|
|
3
|
-
*
|
|
4
|
-
* The thrown Error.message becomes the MCP tool result text (list-docs/search-docs/get-doc catch
|
|
5
|
-
* the error and surface `error.message`), so on a missing bundle the customer-facing message must
|
|
6
|
-
* be neutral and must NOT leak the internal pnpm build command. The dev hint moves to a
|
|
7
|
-
* server-side console.warn.
|
|
8
|
-
*/
|
|
9
|
-
export {};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Behavior tests for loadBundle's error surface (#2469).
|
|
3
|
-
*
|
|
4
|
-
* The thrown Error.message becomes the MCP tool result text (list-docs/search-docs/get-doc catch
|
|
5
|
-
* the error and surface `error.message`), so on a missing bundle the customer-facing message must
|
|
6
|
-
* be neutral and must NOT leak the internal pnpm build command. The dev hint moves to a
|
|
7
|
-
* server-side console.warn.
|
|
8
|
-
*/
|
|
9
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
10
|
-
const readFileMock = vi.fn();
|
|
11
|
-
vi.mock('node:fs/promises', () => ({
|
|
12
|
-
readFile: (...args) => readFileMock(...args),
|
|
13
|
-
}));
|
|
14
|
-
function enoent() {
|
|
15
|
-
const err = new Error('ENOENT');
|
|
16
|
-
err.code = 'ENOENT';
|
|
17
|
-
return err;
|
|
18
|
-
}
|
|
19
|
-
describe('loadBundle error surface', () => {
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
readFileMock.mockReset();
|
|
22
|
-
vi.spyOn(console, 'warn').mockImplementation(() => { });
|
|
23
|
-
});
|
|
24
|
-
afterEach(() => {
|
|
25
|
-
vi.restoreAllMocks();
|
|
26
|
-
});
|
|
27
|
-
// Covers #2469 DoD bullet 6 / E5 / E6: the customer-facing message on a missing bundle is
|
|
28
|
-
// neutral and contains no internal command (no pnpm / --filter / prebuild / file path).
|
|
29
|
-
it('throws a neutral message with no internal command when the bundle is missing', async () => {
|
|
30
|
-
readFileMock.mockRejectedValueOnce(enoent());
|
|
31
|
-
readFileMock.mockRejectedValueOnce(enoent());
|
|
32
|
-
const { loadBundle } = await import('./load-bundle.js');
|
|
33
|
-
await expect(loadBundle()).rejects.toThrow(/temporarily unavailable/i);
|
|
34
|
-
await expect(loadBundle()).rejects.not.toThrow(/pnpm|--filter|prebuild/);
|
|
35
|
-
});
|
|
36
|
-
// Covers #2469 E5: the operator-facing build hint is logged server-side (console.warn), never
|
|
37
|
-
// surfaced in the thrown message.
|
|
38
|
-
it('logs the internal build hint via console.warn', async () => {
|
|
39
|
-
readFileMock.mockRejectedValueOnce(enoent());
|
|
40
|
-
const { loadBundle } = await import('./load-bundle.js');
|
|
41
|
-
await expect(loadBundle()).rejects.toThrow();
|
|
42
|
-
expect(console.warn).toHaveBeenCalledWith(expect.stringMatching(/docs bundle/i));
|
|
43
|
-
});
|
|
44
|
-
// Non-ENOENT read errors propagate unchanged (not swallowed by the neutral-message path).
|
|
45
|
-
it('re-throws non-ENOENT read errors unchanged', async () => {
|
|
46
|
-
readFileMock.mockRejectedValueOnce(new Error('EACCES: permission denied'));
|
|
47
|
-
const { loadBundle } = await import('./load-bundle.js');
|
|
48
|
-
await expect(loadBundle()).rejects.toThrow(/EACCES/);
|
|
49
|
-
});
|
|
50
|
-
});
|