docs(pi): name the loader mechanism behind the default-export requirement
Two contributors independently sent the same fix for #1550 while ours was already in CI (#1553 by @musichen, who also reported the bug, and #1564 by @henri-edh). Rather than close both as duplicates, this takes the part of theirs that ours was missing. @henri-edh's comment names the actual mechanism: Pi loads an extension via jiti.import(path, { default: true }) and rejects anything that is not a function, so a named-only export hands the loader the module namespace object and the install fails with "Extension does not export a valid factory function". Ours said "Pi calls the default export" — true, but it does not tell the next reader why a named export cannot simply be added alongside, which is exactly the change someone would try. Their wording is now ours. The assertion is tightened the same way, from `export default function` to `export default function (pi)`, so a default export with the wrong shape cannot satisfy it. Co-Authored-By: musichen <musichen@users.noreply.github.com> Co-Authored-By: henri-edh <henri-edh@users.noreply.github.com> Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
This commit is contained in:
@@ -157,12 +157,13 @@ char *cbm_client_adapter_pi(const char *binary_path) {
|
||||
/* Register every tool the registry advertises — never a hand-picked subset,
|
||||
* which is the drift this generator exists to prevent.
|
||||
*
|
||||
* DEFAULT export, and it must stay that way: Pi loads an extension by
|
||||
* calling its default export as a factory. A named `register` export made
|
||||
* the file fail to load, and a Pi extension that fails to load takes EVERY
|
||||
* pi command down with it — `pi doctor` included — not just cbm's tools
|
||||
* (#1550). The named binding is kept alongside for anything that imported
|
||||
* it by name. */
|
||||
* DEFAULT export, and it must stay that way. Pi loads an extension via
|
||||
* jiti.import(path, { default: true }) and rejects anything that is not a
|
||||
* function, so a named `export function register(pi)` hands the loader the
|
||||
* module namespace object instead and every install fails with "Extension
|
||||
* does not export a valid factory function". A Pi extension that fails to
|
||||
* load takes EVERY pi command down with it — `pi doctor` included — not
|
||||
* just cbm's tools (#1550). */
|
||||
sb_append(&sb, "export default function (pi) {\n");
|
||||
for (int i = 0; i < count; i++) {
|
||||
const char *name = cbm_mcp_tool_name(i);
|
||||
|
||||
@@ -1106,7 +1106,7 @@ TEST(client_adapter_pi_registers_every_registry_tool) {
|
||||
TEST(client_adapter_pi_default_exports_its_factory_issue1550) {
|
||||
char *js = cbm_client_adapter_pi("/usr/local/bin/codebase-memory-mcp");
|
||||
ASSERT_NOT_NULL(js);
|
||||
ASSERT_NOT_NULL(strstr(js, "export default function"));
|
||||
ASSERT_NOT_NULL(strstr(js, "export default function (pi)"));
|
||||
/* The old shape must be gone: a bare `export function register(pi)` is the
|
||||
* exact form Pi rejects. */
|
||||
ASSERT_NULL(strstr(js, "export function register(pi)"));
|
||||
|
||||
Reference in New Issue
Block a user