@malloy-publisher/server 0.0.235 → 0.0.237
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/dist/app/api-doc.yaml +83 -27
- package/dist/app/assets/{EnvironmentPage-BsAnavYN.js → EnvironmentPage-DaP6CpgK.js} +1 -1
- package/dist/app/assets/{HomePage-CADE138j.js → HomePage-C9yNw3iu.js} +1 -1
- package/dist/app/assets/{LightMode-Cfh7KzN8.js → LightMode-Be4-G-dX.js} +1 -1
- package/dist/app/assets/{MainPage-CO3pRlnV.js → MainPage-J_rU2SgI.js} +2 -2
- package/dist/app/assets/{MaterializationsPage-p9YjkRXZ.js → MaterializationsPage-DHgPI4MO.js} +1 -1
- package/dist/app/assets/ModelPage-BzXfjTu5.js +1 -0
- package/dist/app/assets/{PackagePage-e4kN75YR.js → PackagePage-ByoSTLJ4.js} +1 -1
- package/dist/app/assets/RouteError-CrSeKN2r.js +1 -0
- package/dist/app/assets/{ThemeEditorPage-CciagFTq.js → ThemeEditorPage-Btxnmhtk.js} +1 -1
- package/dist/app/assets/{WorkbookPage-DNWmkCXa.js → WorkbookPage-D6JLPnWO.js} +1 -1
- package/dist/app/assets/{core-Rj_4rRnA.es-BZyvITuO.js → core-BSRgt1mG.es-Bc_D2Lq4.js} +1 -1
- package/dist/app/assets/{index-CH2AcDzc.js → index-BRijWj6K.js} +15 -15
- package/dist/app/assets/{index-DQa463gC.js → index-BX4D94xw.js} +1 -1
- package/dist/app/assets/{index-VBbcc8s6.js → index-Cvy0xtb7.js} +1 -1
- package/dist/app/assets/{index-DQpV7MyA.js → index-DMAhIJNC.js} +1 -1
- package/dist/app/index.html +1 -1
- package/dist/package_load_worker.mjs +59 -20
- package/dist/server.mjs +1342 -616
- package/package.json +8 -2
- package/.eslintrc.json +0 -44
- package/.prettierignore +0 -1
- package/.prettierrc +0 -4
- package/build.ts +0 -97
- package/dist/app/assets/ModelPage-C1OSTv-x.js +0 -1
- package/dist/app/assets/RouteError-CzbfOkng.js +0 -1
- package/eslint.config.mjs +0 -76
- package/k6-tests/README.md +0 -144
- package/k6-tests/bun.lock +0 -797
- package/k6-tests/load-test/load-test-crud-connections.ts +0 -263
- package/k6-tests/load-test/load-test-crud-packages.ts +0 -461
- package/k6-tests/load-test/load-test-crud-projects.ts +0 -160
- package/k6-tests/load-test/load-test-crud.ts +0 -142
- package/k6-tests/load-test/load-test.ts +0 -784
- package/k6-tests/package.json +0 -27
- package/k6-tests/scripts/run-with-otel.sh +0 -50
- package/k6-tests/smoke-test/smoke-test.ts +0 -158
- package/k6-tests/tsconfig.json +0 -29
- package/k6-tests/utils/client_factory.ts +0 -128
- package/k6-tests/utils/common.ts +0 -489
- package/k6-tests/utils/logger.ts +0 -62
- package/k6-tests/utils/types.d.ts +0 -35
- package/malloy_mcp.dxt +0 -0
- package/publisher.config.example.bigquery.json +0 -33
- package/publisher.config.example.duckdb.json +0 -23
- package/publisher.config.json +0 -23
- package/scripts/bake-duckdb-extensions.js +0 -110
- package/src/config.spec.ts +0 -1535
- package/src/config.theme.spec.ts +0 -178
- package/src/config.ts +0 -1142
- package/src/constants.ts +0 -105
- package/src/controller/compile.controller.ts +0 -40
- package/src/controller/connection.controller.spec.ts +0 -849
- package/src/controller/connection.controller.ts +0 -901
- package/src/controller/database.controller.ts +0 -24
- package/src/controller/materialization.controller.spec.ts +0 -293
- package/src/controller/materialization.controller.ts +0 -319
- package/src/controller/model.controller.ts +0 -164
- package/src/controller/package.controller.spec.ts +0 -273
- package/src/controller/package.controller.ts +0 -306
- package/src/controller/query.controller.ts +0 -152
- package/src/controller/theme.controller.ts +0 -83
- package/src/controller/watch-mode.controller.ts +0 -243
- package/src/data_styles.ts +0 -71
- package/src/default-publisher.config.json +0 -23
- package/src/ducklake_version.spec.ts +0 -163
- package/src/ducklake_version.ts +0 -153
- package/src/errors.spec.ts +0 -119
- package/src/errors.ts +0 -237
- package/src/filter_deprecation.spec.ts +0 -64
- package/src/filter_deprecation.ts +0 -42
- package/src/health.spec.ts +0 -123
- package/src/health.ts +0 -233
- package/src/heap_check.spec.ts +0 -144
- package/src/heap_check.ts +0 -144
- package/src/instrumentation.ts +0 -214
- package/src/json_utils.spec.ts +0 -51
- package/src/json_utils.ts +0 -33
- package/src/logger.spec.ts +0 -210
- package/src/logger.ts +0 -251
- package/src/malloy_pin_prereqs.spec.ts +0 -25
- package/src/materialization_metrics.spec.ts +0 -169
- package/src/materialization_metrics.ts +0 -346
- package/src/mcp/error_messages.spec.ts +0 -35
- package/src/mcp/error_messages.ts +0 -183
- package/src/mcp/handler_utils.spec.ts +0 -108
- package/src/mcp/handler_utils.ts +0 -251
- package/src/mcp/mcp_constants.ts +0 -6
- package/src/mcp/query_envelope.spec.ts +0 -229
- package/src/mcp/query_envelope.ts +0 -240
- package/src/mcp/server.protocol.spec.ts +0 -250
- package/src/mcp/server.ts +0 -87
- package/src/mcp/skills/build_skills_bundle.spec.ts +0 -51
- package/src/mcp/skills/build_skills_bundle.ts +0 -176
- package/src/mcp/skills/skills_bundle.json +0 -1
- package/src/mcp/skills/skills_bundle.spec.ts +0 -171
- package/src/mcp/tool_response.spec.ts +0 -108
- package/src/mcp/tool_response.ts +0 -138
- package/src/mcp/tools/compile_tool.spec.ts +0 -315
- package/src/mcp/tools/compile_tool.ts +0 -208
- package/src/mcp/tools/docs_search/build_docs_index.ts +0 -132
- package/src/mcp/tools/docs_search/malloy_docs_index.json +0 -1
- package/src/mcp/tools/docs_search_tool.spec.ts +0 -32
- package/src/mcp/tools/docs_search_tool.ts +0 -128
- package/src/mcp/tools/embedding_index.spec.ts +0 -1236
- package/src/mcp/tools/embedding_index.ts +0 -808
- package/src/mcp/tools/execute_query_tool.spec.ts +0 -294
- package/src/mcp/tools/execute_query_tool.ts +0 -316
- package/src/mcp/tools/get_context_eval.ts +0 -275
- package/src/mcp/tools/get_context_tool.spec.ts +0 -592
- package/src/mcp/tools/get_context_tool.ts +0 -585
- package/src/mcp/tools/reload_package_tool.spec.ts +0 -232
- package/src/mcp/tools/reload_package_tool.ts +0 -132
- package/src/mcp_config.spec.ts +0 -919
- package/src/mcp_config.ts +0 -425
- package/src/oom_guards.integration.spec.ts +0 -269
- package/src/package_load/package_load_pool.spec.ts +0 -252
- package/src/package_load/package_load_pool.ts +0 -931
- package/src/package_load/package_load_worker.ts +0 -1034
- package/src/package_load/protocol.ts +0 -364
- package/src/package_load/rpc_wait_accountant.spec.ts +0 -109
- package/src/package_load/rpc_wait_accountant.ts +0 -76
- package/src/package_load_metrics.spec.ts +0 -114
- package/src/package_load_metrics.ts +0 -127
- package/src/path_safety.spec.ts +0 -158
- package/src/path_safety.ts +0 -146
- package/src/pg_helpers.spec.ts +0 -223
- package/src/pg_helpers.ts +0 -52
- package/src/query_cap_metrics.spec.ts +0 -89
- package/src/query_cap_metrics.ts +0 -116
- package/src/query_concurrency.spec.ts +0 -247
- package/src/query_concurrency.ts +0 -237
- package/src/query_metadata_metrics.ts +0 -49
- package/src/query_param_utils.ts +0 -29
- package/src/query_timeout.spec.ts +0 -224
- package/src/query_timeout.ts +0 -179
- package/src/runtime/publisher.js +0 -328
- package/src/server-old.ts +0 -988
- package/src/server.ts +0 -2059
- package/src/service/annotations.spec.ts +0 -118
- package/src/service/annotations.ts +0 -91
- package/src/service/authorize.spec.ts +0 -154
- package/src/service/authorize.ts +0 -498
- package/src/service/authorize_integration.spec.ts +0 -2041
- package/src/service/build_plan.spec.ts +0 -685
- package/src/service/build_plan.ts +0 -797
- package/src/service/compile_authorize.spec.ts +0 -85
- package/src/service/compile_fragment_techniques.spec.ts +0 -156
- package/src/service/connection.spec.ts +0 -2360
- package/src/service/connection.ts +0 -2187
- package/src/service/connection_config.spec.ts +0 -734
- package/src/service/connection_config.ts +0 -899
- package/src/service/connection_federation.spec.ts +0 -184
- package/src/service/connection_fingerprint.spec.ts +0 -102
- package/src/service/connection_service.spec.ts +0 -711
- package/src/service/connection_service.ts +0 -291
- package/src/service/cron_evaluator.spec.ts +0 -79
- package/src/service/cron_evaluator.ts +0 -105
- package/src/service/db_utils.spec.ts +0 -1085
- package/src/service/db_utils.ts +0 -1502
- package/src/service/duckdb_instance_isolation.spec.ts +0 -137
- package/src/service/ducklake_lazy_attach.spec.ts +0 -110
- package/src/service/embedding_provider.spec.ts +0 -329
- package/src/service/embedding_provider.ts +0 -236
- package/src/service/environment.ts +0 -2191
- package/src/service/environment_admission.spec.ts +0 -344
- package/src/service/environment_compile.spec.ts +0 -197
- package/src/service/environment_store.spec.ts +0 -2274
- package/src/service/environment_store.ts +0 -2434
- package/src/service/environment_store_anchoring.spec.ts +0 -107
- package/src/service/environment_store_clone.spec.ts +0 -350
- package/src/service/explore_visibility.spec.ts +0 -434
- package/src/service/exports_probe.spec.ts +0 -107
- package/src/service/extension_fetch_policy.spec.ts +0 -256
- package/src/service/filter.spec.ts +0 -458
- package/src/service/filter.ts +0 -341
- package/src/service/filter_bypass.spec.ts +0 -418
- package/src/service/filter_integration.spec.ts +0 -1004
- package/src/service/freshness.spec.ts +0 -183
- package/src/service/freshness.ts +0 -112
- package/src/service/gcs_s3_utils.ts +0 -427
- package/src/service/given.ts +0 -105
- package/src/service/givens_integration.spec.ts +0 -219
- package/src/service/manifest_loader.spec.ts +0 -189
- package/src/service/manifest_loader.ts +0 -156
- package/src/service/materialization_build_session.spec.ts +0 -435
- package/src/service/materialization_build_session.ts +0 -681
- package/src/service/materialization_config_validation.spec.ts +0 -99
- package/src/service/materialization_config_validation.ts +0 -120
- package/src/service/materialization_eligibility.spec.ts +0 -158
- package/src/service/materialization_eligibility.ts +0 -305
- package/src/service/materialization_schedule_surface.spec.ts +0 -256
- package/src/service/materialization_scheduler.spec.ts +0 -289
- package/src/service/materialization_scheduler.ts +0 -304
- package/src/service/materialization_serve_transform.spec.ts +0 -1003
- package/src/service/materialization_serve_transform.ts +0 -779
- package/src/service/materialization_service.spec.ts +0 -2373
- package/src/service/materialization_service.ts +0 -2342
- package/src/service/materialization_test_fixtures.ts +0 -249
- package/src/service/model.spec.ts +0 -1157
- package/src/service/model.ts +0 -3370
- package/src/service/model_limits.spec.ts +0 -209
- package/src/service/model_limits.ts +0 -131
- package/src/service/model_storage_serve.spec.ts +0 -193
- package/src/service/model_storage_serve_joins.spec.ts +0 -193
- package/src/service/package.spec.ts +0 -612
- package/src/service/package.ts +0 -1799
- package/src/service/package_manifest.spec.ts +0 -230
- package/src/service/package_manifest.ts +0 -241
- package/src/service/package_memory_governor.spec.ts +0 -173
- package/src/service/package_memory_governor.ts +0 -233
- package/src/service/package_quote_bound_tables.spec.ts +0 -171
- package/src/service/package_race.spec.ts +0 -208
- package/src/service/package_reload_safety.spec.ts +0 -193
- package/src/service/package_rollback.spec.ts +0 -190
- package/src/service/package_worker_path.spec.ts +0 -645
- package/src/service/path_injection.spec.ts +0 -39
- package/src/service/persist_annotation_validation.spec.ts +0 -89
- package/src/service/persist_annotation_validation.ts +0 -59
- package/src/service/persistence_policy.spec.ts +0 -374
- package/src/service/proxy.spec.ts +0 -414
- package/src/service/proxy.ts +0 -248
- package/src/service/query_boundary.spec.ts +0 -470
- package/src/service/query_metadata.spec.ts +0 -408
- package/src/service/query_metadata.ts +0 -492
- package/src/service/query_metadata_identity.spec.ts +0 -149
- package/src/service/query_text.spec.ts +0 -79
- package/src/service/query_text.ts +0 -43
- package/src/service/quoting.spec.ts +0 -135
- package/src/service/quoting.ts +0 -78
- package/src/service/resolve_environment.ts +0 -15
- package/src/service/restricted_mode.spec.ts +0 -299
- package/src/service/source_extraction.ts +0 -225
- package/src/service/theme_store.ts +0 -199
- package/src/storage/DatabaseInterface.ts +0 -198
- package/src/storage/StorageManager.ts +0 -113
- package/src/storage/duckdb/ConnectionRepository.ts +0 -143
- package/src/storage/duckdb/DuckDBConnection.ts +0 -123
- package/src/storage/duckdb/DuckDBRepository.ts +0 -208
- package/src/storage/duckdb/EnvironmentRepository.ts +0 -148
- package/src/storage/duckdb/MaterializationRepository.spec.ts +0 -191
- package/src/storage/duckdb/MaterializationRepository.ts +0 -336
- package/src/storage/duckdb/PackageRepository.ts +0 -135
- package/src/storage/duckdb/schema.ts +0 -229
- package/src/stream_helpers.spec.ts +0 -280
- package/src/stream_helpers.ts +0 -162
- package/src/telemetry.ts +0 -20
- package/src/test_helpers/metrics_harness.ts +0 -166
- package/src/theme_key_parity.spec.ts +0 -57
- package/src/utils.ts +0 -29
- package/tests/fixtures/authorize-compile/model.malloy +0 -9
- package/tests/fixtures/authorize-compile/publisher.json +0 -4
- package/tests/fixtures/html-pages-nopublic/model.malloy +0 -1
- package/tests/fixtures/html-pages-nopublic/publisher.json +0 -5
- package/tests/fixtures/html-pages-test/data.csv +0 -3
- package/tests/fixtures/html-pages-test/public/assets/app.css +0 -3
- package/tests/fixtures/html-pages-test/public/barehtml.html +0 -4
- package/tests/fixtures/html-pages-test/public/bodymeta.html +0 -8
- package/tests/fixtures/html-pages-test/public/data.json +0 -1
- package/tests/fixtures/html-pages-test/public/fitcomment.html +0 -11
- package/tests/fixtures/html-pages-test/public/index.html +0 -9
- package/tests/fixtures/html-pages-test/public/nohead.html +0 -8
- package/tests/fixtures/html-pages-test/public/notfit.html +0 -13
- package/tests/fixtures/html-pages-test/public/slides.html +0 -12
- package/tests/fixtures/html-pages-test/public/sub/page2.html +0 -9
- package/tests/fixtures/html-pages-test/public/unterminated.html +0 -10
- package/tests/fixtures/html-pages-test/publisher.json +0 -5
- package/tests/fixtures/html-pages-test/report.malloy +0 -1
- package/tests/fixtures/persist-multi-level/data/orders.csv +0 -5
- package/tests/fixtures/persist-multi-level/multi_level.malloy +0 -18
- package/tests/fixtures/persist-multi-level/publisher.json +0 -5
- package/tests/fixtures/persist-schedule-test/data/orders.csv +0 -5
- package/tests/fixtures/persist-schedule-test/persist_schedule_test.malloy +0 -11
- package/tests/fixtures/persist-schedule-test/publisher.json +0 -7
- package/tests/fixtures/persist-schedule-warn-test/data/orders.csv +0 -5
- package/tests/fixtures/persist-schedule-warn-test/persist_warn_test.malloy +0 -11
- package/tests/fixtures/persist-schedule-warn-test/publisher.json +0 -6
- package/tests/fixtures/persist-test/data/orders.csv +0 -5
- package/tests/fixtures/persist-test/persist_test.malloy +0 -11
- package/tests/fixtures/persist-test/publisher.json +0 -5
- package/tests/fixtures/publisher.config.json +0 -15
- package/tests/fixtures/query-givens/data/orders.csv +0 -7
- package/tests/fixtures/query-givens/model.malloy +0 -34
- package/tests/fixtures/query-givens/publisher.json +0 -5
- package/tests/fixtures/xlsx/database.xlsx +0 -0
- package/tests/harness/mcp_test_setup.ts +0 -332
- package/tests/harness/rest_e2e.ts +0 -68
- package/tests/integration/authorize/compile_authorize_http.integration.spec.ts +0 -92
- package/tests/integration/concurrent_package/concurrent_package.integration.spec.ts +0 -280
- package/tests/integration/duckdb_storage/duckdb_storage.integration.spec.ts +0 -138
- package/tests/integration/first_boot/readiness_line.integration.spec.ts +0 -177
- package/tests/integration/html_pages/html_pages.integration.spec.ts +0 -440
- package/tests/integration/legacy_routes/legacy_routes.integration.spec.ts +0 -259
- package/tests/integration/materialization/environment_list.integration.spec.ts +0 -133
- package/tests/integration/materialization/freshness_gate.integration.spec.ts +0 -292
- package/tests/integration/materialization/manifest_binding.integration.spec.ts +0 -430
- package/tests/integration/materialization/materialization_lifecycle.integration.spec.ts +0 -441
- package/tests/integration/materialization/orchestrated_rebind.integration.spec.ts +0 -150
- package/tests/integration/materialization/reference_manifest.integration.spec.ts +0 -251
- package/tests/integration/materialization/schedule_edit.integration.spec.ts +0 -126
- package/tests/integration/materialization/scheduler.integration.spec.ts +0 -200
- package/tests/integration/materialization/scheduler_recovery.integration.spec.ts +0 -172
- package/tests/integration/materialization/scheduler_transitions.integration.spec.ts +0 -256
- package/tests/integration/materialization/scheduler_wiring.integration.spec.ts +0 -143
- package/tests/integration/mcp/mcp_execute_query_tool.integration.spec.ts +0 -438
- package/tests/integration/mcp/mcp_get_context_semantic.integration.spec.ts +0 -235
- package/tests/integration/mcp/mcp_transport.integration.spec.ts +0 -98
- package/tests/integration/query_givens/query_givens.integration.spec.ts +0 -146
- package/tests/integration/query_givens/query_givens_authorize.integration.spec.ts +0 -121
- package/tests/integration/sdk_givens/sdk_givens.integration.spec.ts +0 -110
- package/tests/integration/watch-mode/watch_mode.integration.spec.ts +0 -421
- package/tests/unit/controller/theme.controller.spec.ts +0 -141
- package/tests/unit/duckdb/attached_databases.test.ts +0 -1243
- package/tests/unit/duckdb/duckdb_connection.test.ts +0 -181
- package/tests/unit/duckdb/legacy_schema_migration.test.ts +0 -197
- package/tests/unit/duckdb/repositories.test.ts +0 -208
- package/tests/unit/ducklake/ducklake.test.ts +0 -952
- package/tests/unit/service/theme_store.spec.ts +0 -139
- package/tsconfig.json +0 -32
package/src/mcp_config.spec.ts
DELETED
|
@@ -1,919 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it } from "bun:test";
|
|
2
|
-
import { execFileSync } from "child_process";
|
|
3
|
-
import * as fs from "fs";
|
|
4
|
-
import * as os from "os";
|
|
5
|
-
import * as path from "path";
|
|
6
|
-
import { logger } from "./logger";
|
|
7
|
-
import {
|
|
8
|
-
ensureMcpConfig,
|
|
9
|
-
logMcpConfigOutcome,
|
|
10
|
-
MCP_CONFIG_FILENAME,
|
|
11
|
-
mcpConfigEnabled,
|
|
12
|
-
mcpEndpoint,
|
|
13
|
-
type McpConfigOutcome,
|
|
14
|
-
resolveBoundPort,
|
|
15
|
-
resolveClientHost,
|
|
16
|
-
} from "./mcp_config";
|
|
17
|
-
|
|
18
|
-
const dirs: string[] = [];
|
|
19
|
-
|
|
20
|
-
/** A scratch directory that is deliberately NOT inside a git work tree. */
|
|
21
|
-
function tmpDir(): string {
|
|
22
|
-
const dir = fs.realpathSync(
|
|
23
|
-
fs.mkdtempSync(path.join(os.tmpdir(), "mcp-config-")),
|
|
24
|
-
);
|
|
25
|
-
dirs.push(dir);
|
|
26
|
-
return dir;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const cfg = (dir: string) => path.join(dir, MCP_CONFIG_FILENAME);
|
|
30
|
-
const run = (dir: string, mcpPort = 4040) =>
|
|
31
|
-
ensureMcpConfig({
|
|
32
|
-
dir,
|
|
33
|
-
endpoint: ep(mcpPort),
|
|
34
|
-
requestedPort: mcpPort,
|
|
35
|
-
boundPort: mcpPort,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
/** The endpoint the server would compute for a loopback bind on `port`. */
|
|
39
|
-
const ep = (port: number) => `http://127.0.0.1:${port}/mcp`;
|
|
40
|
-
|
|
41
|
-
const isWindows = process.platform === "win32";
|
|
42
|
-
|
|
43
|
-
/** Is `mkfifo` available? Absent on Windows and on minimal images. */
|
|
44
|
-
const hasMkfifo = ((): boolean => {
|
|
45
|
-
const probe = fs.mkdtempSync(path.join(os.tmpdir(), "mcp-fifo-probe-"));
|
|
46
|
-
try {
|
|
47
|
-
execFileSync("mkfifo", [path.join(probe, "f")]);
|
|
48
|
-
return true;
|
|
49
|
-
} catch {
|
|
50
|
-
return false;
|
|
51
|
-
} finally {
|
|
52
|
-
fs.rmSync(probe, { recursive: true, force: true });
|
|
53
|
-
}
|
|
54
|
-
})();
|
|
55
|
-
|
|
56
|
-
/** Root ignores the mode bits, so an unwritable directory cannot be staged. */
|
|
57
|
-
const isRoot = typeof process.getuid === "function" && process.getuid() === 0;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Can this process create a symlink? Windows needs a privilege or Developer
|
|
61
|
-
* Mode for it, so several hazards here are unstageable on CI. Probed rather
|
|
62
|
-
* than assumed, and used with `skipIf` so an unstageable test reports as
|
|
63
|
-
* skipped instead of passing without asserting anything.
|
|
64
|
-
*/
|
|
65
|
-
const canSymlink = ((): boolean => {
|
|
66
|
-
const probe = fs.mkdtempSync(path.join(os.tmpdir(), "mcp-symlink-probe-"));
|
|
67
|
-
try {
|
|
68
|
-
fs.symlinkSync(path.join(probe, "target"), path.join(probe, "link"));
|
|
69
|
-
return true;
|
|
70
|
-
} catch {
|
|
71
|
-
return false;
|
|
72
|
-
} finally {
|
|
73
|
-
fs.rmSync(probe, { recursive: true, force: true });
|
|
74
|
-
}
|
|
75
|
-
})();
|
|
76
|
-
|
|
77
|
-
afterEach(() => {
|
|
78
|
-
while (dirs.length) {
|
|
79
|
-
fs.rmSync(dirs.pop() as string, { recursive: true, force: true });
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
describe("ensureMcpConfig", () => {
|
|
84
|
-
it("creates the file when the directory has none", () => {
|
|
85
|
-
const dir = tmpDir();
|
|
86
|
-
expect(run(dir).action).toBe("created");
|
|
87
|
-
expect(JSON.parse(fs.readFileSync(cfg(dir), "utf8"))).toEqual({
|
|
88
|
-
mcpServers: {
|
|
89
|
-
malloy: { type: "http", url: ep(4040) },
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("writes the port it was handed, not the 4040 default", () => {
|
|
95
|
-
// "No ports to know" only holds if the file names the port really bound.
|
|
96
|
-
const dir = tmpDir();
|
|
97
|
-
run(dir, 15040);
|
|
98
|
-
expect(fs.readFileSync(cfg(dir), "utf8")).toContain(ep(15040));
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
describe("an existing file is left byte-identical and unread", () => {
|
|
102
|
-
// The whole reason this module creates rather than merges. An earlier
|
|
103
|
-
// version replaced the malloy entry wholesale and destroyed user fields
|
|
104
|
-
// (auth headers among them) on every boot.
|
|
105
|
-
it("does not touch a file holding a malloy entry with extra fields", () => {
|
|
106
|
-
const dir = tmpDir();
|
|
107
|
-
const body = JSON.stringify(
|
|
108
|
-
{
|
|
109
|
-
mcpServers: {
|
|
110
|
-
malloy: {
|
|
111
|
-
type: "http",
|
|
112
|
-
url: "http://localhost:4040/mcp",
|
|
113
|
-
headers: { Authorization: "Bearer SECRET" },
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
null,
|
|
118
|
-
2,
|
|
119
|
-
);
|
|
120
|
-
fs.writeFileSync(cfg(dir), body);
|
|
121
|
-
const outcome = run(dir, 15040);
|
|
122
|
-
expect(outcome.action).toBe("exists");
|
|
123
|
-
expect(fs.readFileSync(cfg(dir), "utf8")).toBe(body);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("does not touch a stdio bridge entry, which our own docs tell people to write", () => {
|
|
127
|
-
const dir = tmpDir();
|
|
128
|
-
const body = JSON.stringify({
|
|
129
|
-
mcpServers: {
|
|
130
|
-
malloy: { command: "npx", args: ["-y", "mcp-remote"] },
|
|
131
|
-
},
|
|
132
|
-
});
|
|
133
|
-
fs.writeFileSync(cfg(dir), body);
|
|
134
|
-
expect(run(dir).action).toBe("exists");
|
|
135
|
-
expect(fs.readFileSync(cfg(dir), "utf8")).toBe(body);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it("does not touch a file it could not parse, and does not read it", () => {
|
|
139
|
-
const dir = tmpDir();
|
|
140
|
-
const body = "{ this is not json";
|
|
141
|
-
fs.writeFileSync(cfg(dir), body);
|
|
142
|
-
expect(run(dir).action).toBe("exists");
|
|
143
|
-
expect(fs.readFileSync(cfg(dir), "utf8")).toBe(body);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
describe("symlinks", () => {
|
|
148
|
-
it.skipIf(!canSymlink)(
|
|
149
|
-
"does NOT create the target of a dangling symlink",
|
|
150
|
-
() => {
|
|
151
|
-
// The hazard `existsSync`-then-write could not see: the check says
|
|
152
|
-
// absent, and the write follows the link and creates a file elsewhere.
|
|
153
|
-
const dir = tmpDir();
|
|
154
|
-
const victimDir = tmpDir();
|
|
155
|
-
const victim = path.join(victimDir, "victim.json");
|
|
156
|
-
fs.symlinkSync(victim, cfg(dir));
|
|
157
|
-
expect(fs.existsSync(victim)).toBe(false); // precondition
|
|
158
|
-
|
|
159
|
-
const outcome = run(dir);
|
|
160
|
-
|
|
161
|
-
// The safety property, asserted AFTER the call, and now identical on
|
|
162
|
-
// every platform. It used to allow "failed" and skip the exact label
|
|
163
|
-
// on Windows, which hid a real defect: `wx` alone does not refuse a
|
|
164
|
-
// dangling link there, so the target was created. The module rejects
|
|
165
|
-
// symlinks explicitly now, so there is one answer everywhere.
|
|
166
|
-
expect(fs.existsSync(victim)).toBe(false);
|
|
167
|
-
expect(outcome.action).toBe("exists");
|
|
168
|
-
// Note for anyone tempted to delete the explicit symlink guard in
|
|
169
|
-
// ensureMcpConfig as redundant: this test cannot catch you. On POSIX
|
|
170
|
-
// `wx` refuses the link on its own, so removing the guard leaves
|
|
171
|
-
// this green. It is load-bearing only on Windows, where CREATE_NEW
|
|
172
|
-
// resolves the reparse point and creates a dangling link's target,
|
|
173
|
-
// and it was the Windows CI leg that caught the original defect.
|
|
174
|
-
},
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
it.skipIf(!canSymlink)(
|
|
178
|
-
"does not modify the target of a symlink to a real file",
|
|
179
|
-
() => {
|
|
180
|
-
const dir = tmpDir();
|
|
181
|
-
const victimDir = tmpDir();
|
|
182
|
-
const victim = path.join(victimDir, "package.json");
|
|
183
|
-
const body = JSON.stringify({ name: "someone-elses-file" });
|
|
184
|
-
fs.writeFileSync(victim, body);
|
|
185
|
-
fs.symlinkSync(victim, cfg(dir));
|
|
186
|
-
expect(run(dir).action).toBe("exists");
|
|
187
|
-
expect(fs.readFileSync(victim, "utf8")).toBe(body);
|
|
188
|
-
},
|
|
189
|
-
);
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it.skipIf(isWindows || !hasMkfifo)(
|
|
193
|
-
"returns promptly on a FIFO instead of hanging the process",
|
|
194
|
-
() => {
|
|
195
|
-
// A blocking read here stalls the event loop and takes /health with it.
|
|
196
|
-
// `wx` never opens it for reading, so this must be fast and inert.
|
|
197
|
-
// Windows has no FIFO in the filesystem namespace (named pipes live under
|
|
198
|
-
// \\.\pipe), and its mkfifo, if git-bash puts one on PATH, does not make
|
|
199
|
-
// something Node reports as a FIFO. The hazard does not exist there.
|
|
200
|
-
const dir = tmpDir();
|
|
201
|
-
execFileSync("mkfifo", [cfg(dir)]);
|
|
202
|
-
const started = Date.now();
|
|
203
|
-
expect(run(dir).action).toBe("exists");
|
|
204
|
-
expect(Date.now() - started).toBeLessThan(2000);
|
|
205
|
-
expect(fs.lstatSync(cfg(dir)).isFIFO()).toBe(true);
|
|
206
|
-
},
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
describe("directories it stays out of", () => {
|
|
210
|
-
it("skips a git work tree", () => {
|
|
211
|
-
// A checkout belongs to somebody: a clone of this repo already ships a
|
|
212
|
-
// .mcp.json, and an untracked one is a surprise in git status.
|
|
213
|
-
const dir = tmpDir();
|
|
214
|
-
fs.mkdirSync(path.join(dir, ".git"));
|
|
215
|
-
expect(run(dir).action).toBe("skipped-git");
|
|
216
|
-
expect(fs.existsSync(cfg(dir))).toBe(false);
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it("skips a SUBDIRECTORY of a git work tree", () => {
|
|
220
|
-
// The case that made this necessary: `bun run start` cds into
|
|
221
|
-
// packages/server, so the write landed inside the repo but nowhere an
|
|
222
|
-
// agent is ever opened.
|
|
223
|
-
const dir = tmpDir();
|
|
224
|
-
fs.mkdirSync(path.join(dir, ".git"));
|
|
225
|
-
const sub = path.join(dir, "packages", "server");
|
|
226
|
-
fs.mkdirSync(sub, { recursive: true });
|
|
227
|
-
expect(run(sub).action).toBe("skipped-git");
|
|
228
|
-
expect(fs.existsSync(cfg(sub))).toBe(false);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it("treats a .git FILE as a work tree, the way worktrees and submodules store it", () => {
|
|
232
|
-
const dir = tmpDir();
|
|
233
|
-
fs.writeFileSync(path.join(dir, ".git"), "gitdir: /elsewhere\n");
|
|
234
|
-
expect(run(dir).action).toBe("skipped-git");
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
// These inject a scratch home rather than running against the real one.
|
|
238
|
-
// Passing the developer's actual home in is only safe while the guard
|
|
239
|
-
// returns before any write; if that ordering ever regressed, the old form
|
|
240
|
-
// wrote .mcp.json into their home directory instead of going red.
|
|
241
|
-
it("skips the home directory", () => {
|
|
242
|
-
const home = tmpDir();
|
|
243
|
-
const outcome = ensureMcpConfig({
|
|
244
|
-
dir: home,
|
|
245
|
-
homeDir: home,
|
|
246
|
-
endpoint: ep(4040),
|
|
247
|
-
requestedPort: 4040,
|
|
248
|
-
boundPort: 4040,
|
|
249
|
-
});
|
|
250
|
-
expect(outcome.action).toBe("skipped-home");
|
|
251
|
-
expect(fs.existsSync(cfg(home))).toBe(false);
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it("skips home even when the path is not normalised", () => {
|
|
255
|
-
// The guard resolves before comparing; a raw string compare would miss.
|
|
256
|
-
const home = tmpDir();
|
|
257
|
-
const outcome = ensureMcpConfig({
|
|
258
|
-
dir: path.join(home, "..", path.basename(home), "."),
|
|
259
|
-
homeDir: home,
|
|
260
|
-
endpoint: ep(4040),
|
|
261
|
-
requestedPort: 4040,
|
|
262
|
-
boundPort: 4040,
|
|
263
|
-
});
|
|
264
|
-
expect(outcome.action).toBe("skipped-home");
|
|
265
|
-
expect(fs.existsSync(cfg(home))).toBe(false);
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
it.skipIf(!canSymlink)(
|
|
269
|
-
"skips a home directory reached through a symlink",
|
|
270
|
-
() => {
|
|
271
|
-
// Mutation-proven gap: swapping realpathSync back to path.resolve left
|
|
272
|
-
// the whole suite green, because every other test resolves its tmpdir
|
|
273
|
-
// first. An automounted /home is the real-world shape.
|
|
274
|
-
const realHome = tmpDir();
|
|
275
|
-
const linkedHome = path.join(tmpDir(), "home-link");
|
|
276
|
-
fs.symlinkSync(realHome, linkedHome);
|
|
277
|
-
const outcome = ensureMcpConfig({
|
|
278
|
-
dir: realHome,
|
|
279
|
-
homeDir: linkedHome,
|
|
280
|
-
endpoint: ep(4040),
|
|
281
|
-
requestedPort: 4040,
|
|
282
|
-
boundPort: 4040,
|
|
283
|
-
});
|
|
284
|
-
expect(outcome.action).toBe("skipped-home");
|
|
285
|
-
expect(fs.existsSync(cfg(realHome))).toBe(false);
|
|
286
|
-
},
|
|
287
|
-
);
|
|
288
|
-
|
|
289
|
-
it("skips the filesystem root", () => {
|
|
290
|
-
// Also mutation-proven: deleting the root guard left the suite green,
|
|
291
|
-
// because nothing passed "/" in. systemd gives a unit that cwd.
|
|
292
|
-
const root = path.parse(process.cwd()).root;
|
|
293
|
-
const rootCfg = path.join(root, MCP_CONFIG_FILENAME);
|
|
294
|
-
const preexisting = fs.existsSync(rootCfg);
|
|
295
|
-
// try/finally, not a trailing statement: on the failure this cleanup
|
|
296
|
-
// exists for, a regressed guard, the expect throws and anything after
|
|
297
|
-
// it never runs. The home test below is the model.
|
|
298
|
-
try {
|
|
299
|
-
expect(
|
|
300
|
-
ensureMcpConfig({
|
|
301
|
-
dir: root,
|
|
302
|
-
homeDir: tmpDir(),
|
|
303
|
-
endpoint: ep(4040),
|
|
304
|
-
requestedPort: 4040,
|
|
305
|
-
boundPort: 4040,
|
|
306
|
-
}).action,
|
|
307
|
-
).toBe("skipped-root");
|
|
308
|
-
} finally {
|
|
309
|
-
if (!preexisting && fs.existsSync(rootCfg)) fs.rmSync(rootCfg);
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
it.skipIf(!canSymlink)(
|
|
314
|
-
"names a dangling-symlink config, which is what the write path also sees",
|
|
315
|
-
() => {
|
|
316
|
-
// Uncovered until now: swapping the probe's lstat back to existsSync
|
|
317
|
-
// left the suite green, and the only difference is this case. lstat is
|
|
318
|
-
// deliberate, so that reporting and the wx write agree about what
|
|
319
|
-
// counts as present.
|
|
320
|
-
const dir = tmpDir();
|
|
321
|
-
fs.mkdirSync(path.join(dir, ".git"));
|
|
322
|
-
fs.symlinkSync(path.join(dir, "nowhere.json"), cfg(dir));
|
|
323
|
-
const outcome = run(dir);
|
|
324
|
-
expect(outcome.action).toBe("skipped-git");
|
|
325
|
-
if (outcome.action === "skipped-git") {
|
|
326
|
-
expect(outcome.staleConfig).toBe(cfg(dir));
|
|
327
|
-
}
|
|
328
|
-
},
|
|
329
|
-
);
|
|
330
|
-
|
|
331
|
-
it("names a stale config that is already in the directory when it skips", () => {
|
|
332
|
-
// Every skip returns before the write, so EEXIST never fires for them
|
|
333
|
-
// and the file the docs call the main hazard went unmentioned.
|
|
334
|
-
const dir = tmpDir();
|
|
335
|
-
fs.mkdirSync(path.join(dir, ".git"));
|
|
336
|
-
fs.writeFileSync(cfg(dir), "{}");
|
|
337
|
-
const outcome = run(dir);
|
|
338
|
-
expect(outcome.action).toBe("skipped-git");
|
|
339
|
-
if (outcome.action === "skipped-git") {
|
|
340
|
-
expect(outcome.staleConfig).toBe(cfg(dir));
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
it("defaults the home guard to the real os.homedir()", () => {
|
|
345
|
-
// Points at the developer's actual home, so it cleans up after itself:
|
|
346
|
-
// if guard ordering ever regressed, this test would otherwise create
|
|
347
|
-
// ~/.mcp.json on the way to going red, which is the very thing the
|
|
348
|
-
// guard exists to prevent.
|
|
349
|
-
const realCfg = path.join(os.homedir(), MCP_CONFIG_FILENAME);
|
|
350
|
-
const preexisting = fs.existsSync(realCfg);
|
|
351
|
-
try {
|
|
352
|
-
expect(
|
|
353
|
-
ensureMcpConfig({
|
|
354
|
-
dir: os.homedir(),
|
|
355
|
-
endpoint: ep(4040),
|
|
356
|
-
requestedPort: 4040,
|
|
357
|
-
boundPort: 4040,
|
|
358
|
-
}).action,
|
|
359
|
-
).toBe("skipped-home");
|
|
360
|
-
} finally {
|
|
361
|
-
if (!preexisting && fs.existsSync(realCfg)) fs.rmSync(realCfg);
|
|
362
|
-
}
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
// Every way the bound port can differ from the requested one. Checking
|
|
366
|
-
// `requestedPort === 0` missed most of them, and the NaN case is not a
|
|
367
|
-
// typo-only scenario: Kubernetes injects MCP_PORT=tcp://10.96.0.1:4040
|
|
368
|
-
// into every pod in a namespace with a Service named `mcp`, and
|
|
369
|
-
// `Number()` of that is NaN, which bun binds ephemerally.
|
|
370
|
-
const unstable: Array<[string, number]> = [
|
|
371
|
-
["--mcp_port 0", 0],
|
|
372
|
-
["a non-numeric MCP_PORT (NaN)", Number("tcp://10.96.0.1:4040")],
|
|
373
|
-
["a negative port", -1],
|
|
374
|
-
];
|
|
375
|
-
for (const [label, requestedPort] of unstable) {
|
|
376
|
-
it(`skips ${label}, which would be stale from the next boot on`, () => {
|
|
377
|
-
// Create-never-edit means the first boot's file is never corrected,
|
|
378
|
-
// so a port that moves leaves a permanently wrong config.
|
|
379
|
-
const dir = tmpDir();
|
|
380
|
-
const outcome = ensureMcpConfig({
|
|
381
|
-
dir,
|
|
382
|
-
endpoint: ep(51234),
|
|
383
|
-
requestedPort,
|
|
384
|
-
boundPort: 51234,
|
|
385
|
-
});
|
|
386
|
-
expect(outcome.action).toBe("skipped-unstable-port");
|
|
387
|
-
expect(fs.existsSync(cfg(dir))).toBe(false);
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
it("still writes when the bound port is the one that was requested", () => {
|
|
392
|
-
const dir = tmpDir();
|
|
393
|
-
const outcome = ensureMcpConfig({
|
|
394
|
-
dir,
|
|
395
|
-
endpoint: ep(4040),
|
|
396
|
-
requestedPort: 4040,
|
|
397
|
-
boundPort: 4040,
|
|
398
|
-
});
|
|
399
|
-
expect(outcome.action).toBe("created");
|
|
400
|
-
});
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
it("reports rather than throws when the directory does not exist", () => {
|
|
404
|
-
// The portable half of the failure contract: no mode bits involved, so it
|
|
405
|
-
// runs everywhere including Windows, where chmod does not restrict.
|
|
406
|
-
const outcome = run(path.join(tmpDir(), "no", "such", "dir"));
|
|
407
|
-
expect(outcome.action).toBe("failed");
|
|
408
|
-
if (outcome.action === "failed")
|
|
409
|
-
expect(outcome.problem).toContain("ENOENT");
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
// POSIX mode bits do not restrict on Windows; ACLs would.
|
|
413
|
-
it.skipIf(isWindows || isRoot)(
|
|
414
|
-
"reports rather than throws when the directory cannot be written",
|
|
415
|
-
() => {
|
|
416
|
-
const dir = tmpDir();
|
|
417
|
-
fs.chmodSync(dir, 0o500);
|
|
418
|
-
try {
|
|
419
|
-
expect(run(dir).action).toBe("failed");
|
|
420
|
-
} finally {
|
|
421
|
-
fs.chmodSync(dir, 0o700);
|
|
422
|
-
}
|
|
423
|
-
},
|
|
424
|
-
);
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
/**
|
|
428
|
-
* Capture what the logger is told, then put it back EXACTLY as it was.
|
|
429
|
-
*
|
|
430
|
-
* `logger.info` and friends are inherited from winston's prototype, so assigning
|
|
431
|
-
* a replacement creates an own property that shadows it. Restoring by assigning
|
|
432
|
-
* a bound copy therefore leaves the shadow in place for the rest of the process,
|
|
433
|
-
* and this file runs 12th of 99 in the serial suite. The own-property snapshot is
|
|
434
|
-
* the difference between restoring and merely overwriting.
|
|
435
|
-
*/
|
|
436
|
-
function captureLogger(sink: string[]): () => void {
|
|
437
|
-
const levels = ["debug", "info", "warn"] as const;
|
|
438
|
-
const saved = levels.map((level) => ({
|
|
439
|
-
level,
|
|
440
|
-
own: Object.prototype.hasOwnProperty.call(logger, level),
|
|
441
|
-
value: (logger as unknown as Record<string, unknown>)[level],
|
|
442
|
-
}));
|
|
443
|
-
for (const level of levels) {
|
|
444
|
-
(logger as unknown as Record<string, (m: string) => void>)[level] = (
|
|
445
|
-
m,
|
|
446
|
-
) => {
|
|
447
|
-
sink.push(String(m));
|
|
448
|
-
};
|
|
449
|
-
}
|
|
450
|
-
return () => {
|
|
451
|
-
for (const s of saved) {
|
|
452
|
-
if (s.own) {
|
|
453
|
-
(logger as unknown as Record<string, unknown>)[s.level] = s.value;
|
|
454
|
-
} else {
|
|
455
|
-
delete (logger as unknown as Record<string, unknown>)[s.level];
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
};
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
describe("logMcpConfigOutcome", () => {
|
|
462
|
-
// These exist only to produce log text, so without a test nothing covers
|
|
463
|
-
// whether the text is right or even emitted.
|
|
464
|
-
const outcomes: McpConfigOutcome[] = [
|
|
465
|
-
{
|
|
466
|
-
action: "skipped-home",
|
|
467
|
-
dir: "/home/x",
|
|
468
|
-
endpoint: ep(4040),
|
|
469
|
-
staleConfig: undefined,
|
|
470
|
-
},
|
|
471
|
-
{
|
|
472
|
-
action: "skipped-root",
|
|
473
|
-
dir: "/",
|
|
474
|
-
endpoint: ep(4040),
|
|
475
|
-
staleConfig: undefined,
|
|
476
|
-
},
|
|
477
|
-
{
|
|
478
|
-
action: "skipped-git",
|
|
479
|
-
dir: "/repo/sub",
|
|
480
|
-
gitRoot: "/repo",
|
|
481
|
-
rootConfig: undefined,
|
|
482
|
-
endpoint: ep(4040),
|
|
483
|
-
staleConfig: undefined,
|
|
484
|
-
},
|
|
485
|
-
{
|
|
486
|
-
action: "skipped-git",
|
|
487
|
-
dir: "/repo/sub",
|
|
488
|
-
gitRoot: "/repo",
|
|
489
|
-
rootConfig: "/repo/.mcp.json",
|
|
490
|
-
endpoint: ep(4040),
|
|
491
|
-
staleConfig: undefined,
|
|
492
|
-
},
|
|
493
|
-
{
|
|
494
|
-
action: "skipped-unstable-port",
|
|
495
|
-
dir: "/w",
|
|
496
|
-
endpoint: ep(51234),
|
|
497
|
-
requestedPort: 0,
|
|
498
|
-
boundPort: 51234,
|
|
499
|
-
staleConfig: undefined,
|
|
500
|
-
},
|
|
501
|
-
{ action: "created", file: "/w/.mcp.json" },
|
|
502
|
-
{ action: "exists", file: "/w/.mcp.json", endpoint: ep(4040) },
|
|
503
|
-
{
|
|
504
|
-
action: "failed",
|
|
505
|
-
file: "/w/.mcp.json",
|
|
506
|
-
problem: "EACCES",
|
|
507
|
-
endpoint: ep(4040),
|
|
508
|
-
},
|
|
509
|
-
];
|
|
510
|
-
|
|
511
|
-
/** Collect everything the logger is told, at any level. */
|
|
512
|
-
function capture(run: () => void): string {
|
|
513
|
-
const said: string[] = [];
|
|
514
|
-
const restore = captureLogger(said);
|
|
515
|
-
try {
|
|
516
|
-
run();
|
|
517
|
-
} finally {
|
|
518
|
-
restore();
|
|
519
|
-
}
|
|
520
|
-
return said.join("\n");
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
it("handles every outcome variant without throwing", () => {
|
|
524
|
-
for (const outcome of outcomes) {
|
|
525
|
-
expect(() => logMcpConfigOutcome(outcome)).not.toThrow();
|
|
526
|
-
}
|
|
527
|
-
});
|
|
528
|
-
|
|
529
|
-
it("names the real port in the command it tells the reader to run", () => {
|
|
530
|
-
// The one branch whose text the user has to act on. A hardcoded 4040 here
|
|
531
|
-
// would send them to a port nothing is listening on.
|
|
532
|
-
const said: string[] = [];
|
|
533
|
-
const restore = captureLogger(said);
|
|
534
|
-
try {
|
|
535
|
-
logMcpConfigOutcome({
|
|
536
|
-
action: "exists",
|
|
537
|
-
file: "/w/.mcp.json",
|
|
538
|
-
endpoint: ep(15040),
|
|
539
|
-
});
|
|
540
|
-
} finally {
|
|
541
|
-
restore();
|
|
542
|
-
}
|
|
543
|
-
expect(said.join("\n")).toContain(
|
|
544
|
-
`claude mcp add --transport http malloy '${ep(15040)}'`,
|
|
545
|
-
);
|
|
546
|
-
});
|
|
547
|
-
|
|
548
|
-
it("says it wrote the file, and how to turn that off", () => {
|
|
549
|
-
const said: string[] = [];
|
|
550
|
-
const restore = captureLogger(said);
|
|
551
|
-
try {
|
|
552
|
-
logMcpConfigOutcome({ action: "created", file: "/w/.mcp.json" });
|
|
553
|
-
} finally {
|
|
554
|
-
restore();
|
|
555
|
-
}
|
|
556
|
-
expect(said.join("\n")).toContain("/w/.mcp.json");
|
|
557
|
-
expect(said.join("\n")).toContain("--no-mcp-config");
|
|
558
|
-
});
|
|
559
|
-
|
|
560
|
-
// Both skips were silent when this shipped for review, and three separate
|
|
561
|
-
// reviewers landed on the same failure: no file, no tools, no message, and a
|
|
562
|
-
// README that then sends you to relaunch the agent from a directory that has
|
|
563
|
-
// nothing in it. Running inside your own project is the common case, not an
|
|
564
|
-
// edge one, so these lines are load-bearing.
|
|
565
|
-
it("tells a user inside a git repo why there is no file, and what to run", () => {
|
|
566
|
-
const said = capture(() =>
|
|
567
|
-
logMcpConfigOutcome({
|
|
568
|
-
action: "skipped-git",
|
|
569
|
-
dir: "/work/my-project/data",
|
|
570
|
-
gitRoot: "/work/my-project",
|
|
571
|
-
rootConfig: undefined,
|
|
572
|
-
endpoint: ep(15040),
|
|
573
|
-
staleConfig: undefined,
|
|
574
|
-
}),
|
|
575
|
-
);
|
|
576
|
-
expect(said).toContain("/work/my-project/data");
|
|
577
|
-
// Naming the .git that stopped it. With a dotfiles repo in $HOME the cause
|
|
578
|
-
// can be many levels up, and `ls -a` in the working directory shows nothing.
|
|
579
|
-
expect(said).toContain("/work/my-project");
|
|
580
|
-
expect(said).toContain(
|
|
581
|
-
`claude mcp add --transport http malloy '${ep(15040)}'`,
|
|
582
|
-
);
|
|
583
|
-
});
|
|
584
|
-
|
|
585
|
-
it("names an up-tree config without pretending it covers this server", () => {
|
|
586
|
-
// This branch was `logger.debug` for one commit, to keep a clone quiet on
|
|
587
|
-
// every boot. That only looked quiet because the default level is debug:
|
|
588
|
-
// under LOG_LEVEL=info it went silent, which is the very defect three
|
|
589
|
-
// reviewers had already found. A config at the repo root may register an
|
|
590
|
-
// unrelated server, or name a port this run is not on, and the module
|
|
591
|
-
// never reads it to find out, so it must still give the endpoint.
|
|
592
|
-
const said = capture(() =>
|
|
593
|
-
logMcpConfigOutcome({
|
|
594
|
-
action: "skipped-git",
|
|
595
|
-
dir: "/repo/packages/server",
|
|
596
|
-
gitRoot: "/repo",
|
|
597
|
-
rootConfig: "/repo/.mcp.json",
|
|
598
|
-
endpoint: ep(4141),
|
|
599
|
-
staleConfig: undefined,
|
|
600
|
-
}),
|
|
601
|
-
);
|
|
602
|
-
expect(said).toContain("/repo/.mcp.json");
|
|
603
|
-
expect(said).toContain("4141");
|
|
604
|
-
expect(said).toContain("claude mcp add");
|
|
605
|
-
});
|
|
606
|
-
|
|
607
|
-
it("emits every no-file branch at info, never below it", () => {
|
|
608
|
-
// The regression guard for the above. A branch logged at debug is invisible
|
|
609
|
-
// the moment an operator sets LOG_LEVEL=info, which is the production shape,
|
|
610
|
-
// and an invisible skip is indistinguishable from a broken install.
|
|
611
|
-
const noFile = outcomes.filter((o) => o.action !== "created");
|
|
612
|
-
for (const outcome of noFile) {
|
|
613
|
-
const levels: string[] = [];
|
|
614
|
-
// captureLogger snapshots whether each method was an own property and
|
|
615
|
-
// restores that exactly; this test then re-wraps on top to record the
|
|
616
|
-
// LEVEL rather than the text, and hands restoration back to it.
|
|
617
|
-
const restore = captureLogger([]);
|
|
618
|
-
for (const level of ["debug", "info", "warn"] as const) {
|
|
619
|
-
(logger as unknown as Record<string, (m: string) => void>)[level] =
|
|
620
|
-
(_m) => {
|
|
621
|
-
levels.push(level);
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
try {
|
|
625
|
-
logMcpConfigOutcome(outcome);
|
|
626
|
-
} finally {
|
|
627
|
-
restore();
|
|
628
|
-
}
|
|
629
|
-
expect(levels).toEqual(["info"]);
|
|
630
|
-
}
|
|
631
|
-
});
|
|
632
|
-
|
|
633
|
-
it("tells a user in their home directory why there is no file", () => {
|
|
634
|
-
const said = capture(() =>
|
|
635
|
-
logMcpConfigOutcome({
|
|
636
|
-
action: "skipped-home",
|
|
637
|
-
dir: "/Users/x",
|
|
638
|
-
endpoint: ep(15040),
|
|
639
|
-
staleConfig: undefined,
|
|
640
|
-
}),
|
|
641
|
-
);
|
|
642
|
-
expect(said).toContain("/Users/x");
|
|
643
|
-
expect(said).toContain(
|
|
644
|
-
`claude mcp add --transport http malloy '${ep(15040)}'`,
|
|
645
|
-
);
|
|
646
|
-
});
|
|
647
|
-
|
|
648
|
-
it("tells a stuck user what to run when the write itself failed", () => {
|
|
649
|
-
// The branch where the user is most stuck was the only no-file case with a
|
|
650
|
-
// diagnosis but no remedy.
|
|
651
|
-
const said = capture(() =>
|
|
652
|
-
logMcpConfigOutcome({
|
|
653
|
-
action: "failed",
|
|
654
|
-
file: "/w/.mcp.json",
|
|
655
|
-
problem: "EACCES: permission denied",
|
|
656
|
-
endpoint: ep(15040),
|
|
657
|
-
}),
|
|
658
|
-
);
|
|
659
|
-
expect(said).toContain("EACCES");
|
|
660
|
-
expect(said).toContain(
|
|
661
|
-
`claude mcp add --transport http malloy '${ep(15040)}'`,
|
|
662
|
-
);
|
|
663
|
-
});
|
|
664
|
-
|
|
665
|
-
it("quotes the endpoint, because zsh treats an IPv6 bracket as a glob", () => {
|
|
666
|
-
// `claude mcp add ... http://[::1]:4040/mcp` unquoted is `no matches
|
|
667
|
-
// found` in zsh, the macOS default shell, and the docs tell the reader to
|
|
668
|
-
// paste the line as printed. Unquoted was safe only while the command
|
|
669
|
-
// interpolated a number rather than a URL string.
|
|
670
|
-
const said = capture(() =>
|
|
671
|
-
logMcpConfigOutcome({
|
|
672
|
-
action: "skipped-home",
|
|
673
|
-
dir: "/Users/x",
|
|
674
|
-
endpoint: "http://[::1]:4040/mcp",
|
|
675
|
-
staleConfig: undefined,
|
|
676
|
-
}),
|
|
677
|
-
);
|
|
678
|
-
expect(said).toContain("malloy 'http://[::1]:4040/mcp'");
|
|
679
|
-
});
|
|
680
|
-
|
|
681
|
-
// Mutation-proven gap: making staleNote return "" removed the feature
|
|
682
|
-
// outright and all 46 tests stayed green, because every fixture set
|
|
683
|
-
// staleConfig to undefined. These render it.
|
|
684
|
-
it("names a stale config in the message, on every skip that can carry one", () => {
|
|
685
|
-
const withStale: McpConfigOutcome[] = [
|
|
686
|
-
{
|
|
687
|
-
action: "skipped-home",
|
|
688
|
-
dir: "/home/x",
|
|
689
|
-
endpoint: ep(4040),
|
|
690
|
-
staleConfig: "/home/x/.mcp.json",
|
|
691
|
-
},
|
|
692
|
-
{
|
|
693
|
-
action: "skipped-root",
|
|
694
|
-
dir: "/",
|
|
695
|
-
endpoint: ep(4040),
|
|
696
|
-
staleConfig: "/.mcp.json",
|
|
697
|
-
},
|
|
698
|
-
{
|
|
699
|
-
action: "skipped-git",
|
|
700
|
-
dir: "/repo/sub",
|
|
701
|
-
gitRoot: "/repo",
|
|
702
|
-
rootConfig: undefined,
|
|
703
|
-
endpoint: ep(4040),
|
|
704
|
-
staleConfig: "/repo/sub/.mcp.json",
|
|
705
|
-
},
|
|
706
|
-
{
|
|
707
|
-
action: "skipped-unstable-port",
|
|
708
|
-
dir: "/w",
|
|
709
|
-
endpoint: ep(51234),
|
|
710
|
-
requestedPort: 0,
|
|
711
|
-
boundPort: 51234,
|
|
712
|
-
staleConfig: "/w/.mcp.json",
|
|
713
|
-
},
|
|
714
|
-
];
|
|
715
|
-
for (const outcome of withStale) {
|
|
716
|
-
const said = capture(() => logMcpConfigOutcome(outcome));
|
|
717
|
-
expect(said).toContain("was not written by this run");
|
|
718
|
-
expect(said).toContain(
|
|
719
|
-
(outcome as { staleConfig: string }).staleConfig,
|
|
720
|
-
);
|
|
721
|
-
expect(said).not.toContain(".."); // the note must join cleanly
|
|
722
|
-
}
|
|
723
|
-
});
|
|
724
|
-
|
|
725
|
-
it("says nothing about a stale config when there is none", () => {
|
|
726
|
-
const said = capture(() =>
|
|
727
|
-
logMcpConfigOutcome({
|
|
728
|
-
action: "skipped-home",
|
|
729
|
-
dir: "/home/x",
|
|
730
|
-
endpoint: ep(4040),
|
|
731
|
-
staleConfig: undefined,
|
|
732
|
-
}),
|
|
733
|
-
);
|
|
734
|
-
expect(said).not.toContain("was not written by this run");
|
|
735
|
-
});
|
|
736
|
-
|
|
737
|
-
it("does not name the same file twice when cwd is the repo root", () => {
|
|
738
|
-
// A clone of this repo produces exactly this on every boot from its root.
|
|
739
|
-
const said = capture(() =>
|
|
740
|
-
logMcpConfigOutcome({
|
|
741
|
-
action: "skipped-git",
|
|
742
|
-
dir: "/repo",
|
|
743
|
-
gitRoot: "/repo",
|
|
744
|
-
rootConfig: "/repo/.mcp.json",
|
|
745
|
-
endpoint: ep(4040),
|
|
746
|
-
staleConfig: "/repo/.mcp.json",
|
|
747
|
-
}),
|
|
748
|
-
);
|
|
749
|
-
expect(said.split("/repo/.mcp.json").length - 1).toBe(1);
|
|
750
|
-
});
|
|
751
|
-
|
|
752
|
-
it("never advises user scope, which the file that caused the message outranks", () => {
|
|
753
|
-
// Claude Code resolves duplicates by precedence (local, then project, then
|
|
754
|
-
// user) and takes the winning entry whole. Every branch printing this
|
|
755
|
-
// command has, or may have, a project-scope .mcp.json in play, so `-s user`
|
|
756
|
-
// is silently shadowed by the very file being reported.
|
|
757
|
-
for (const outcome of outcomes) {
|
|
758
|
-
const said = capture(() => logMcpConfigOutcome(outcome));
|
|
759
|
-
expect(said).not.toContain("-s user");
|
|
760
|
-
}
|
|
761
|
-
});
|
|
762
|
-
|
|
763
|
-
it("never sends the reader to a hardcoded port on any branch that names one", () => {
|
|
764
|
-
// The whole point of reading back the bound port. A 4040 leaking into any
|
|
765
|
-
// remediation line sends the reader somewhere nothing is listening.
|
|
766
|
-
const branches: McpConfigOutcome[] = [
|
|
767
|
-
{ action: "exists", file: "/w/.mcp.json", endpoint: ep(19999) },
|
|
768
|
-
{
|
|
769
|
-
action: "skipped-git",
|
|
770
|
-
dir: "/repo",
|
|
771
|
-
gitRoot: "/repo",
|
|
772
|
-
rootConfig: undefined,
|
|
773
|
-
endpoint: ep(19999),
|
|
774
|
-
staleConfig: undefined,
|
|
775
|
-
},
|
|
776
|
-
{
|
|
777
|
-
action: "skipped-home",
|
|
778
|
-
dir: "/home/x",
|
|
779
|
-
endpoint: ep(19999),
|
|
780
|
-
staleConfig: undefined,
|
|
781
|
-
},
|
|
782
|
-
{
|
|
783
|
-
action: "skipped-unstable-port",
|
|
784
|
-
dir: "/w",
|
|
785
|
-
endpoint: ep(19999),
|
|
786
|
-
requestedPort: 0,
|
|
787
|
-
boundPort: 19999,
|
|
788
|
-
staleConfig: undefined,
|
|
789
|
-
},
|
|
790
|
-
{
|
|
791
|
-
action: "skipped-root",
|
|
792
|
-
dir: "/",
|
|
793
|
-
endpoint: ep(19999),
|
|
794
|
-
staleConfig: undefined,
|
|
795
|
-
},
|
|
796
|
-
{
|
|
797
|
-
action: "failed",
|
|
798
|
-
file: "/w/.mcp.json",
|
|
799
|
-
problem: "EACCES",
|
|
800
|
-
endpoint: ep(19999),
|
|
801
|
-
},
|
|
802
|
-
];
|
|
803
|
-
for (const outcome of branches) {
|
|
804
|
-
const said = capture(() => logMcpConfigOutcome(outcome));
|
|
805
|
-
expect(said).toContain("19999");
|
|
806
|
-
expect(said).not.toContain("4040");
|
|
807
|
-
}
|
|
808
|
-
});
|
|
809
|
-
});
|
|
810
|
-
|
|
811
|
-
describe("mcpConfigEnabled", () => {
|
|
812
|
-
/** Set the variable for one call and restore it. */
|
|
813
|
-
function withEnv(value: string | undefined, body: () => void): void {
|
|
814
|
-
const saved = process.env.PUBLISHER_NO_MCP_CONFIG;
|
|
815
|
-
if (value === undefined) delete process.env.PUBLISHER_NO_MCP_CONFIG;
|
|
816
|
-
else process.env.PUBLISHER_NO_MCP_CONFIG = value;
|
|
817
|
-
try {
|
|
818
|
-
body();
|
|
819
|
-
} finally {
|
|
820
|
-
if (saved === undefined) delete process.env.PUBLISHER_NO_MCP_CONFIG;
|
|
821
|
-
else process.env.PUBLISHER_NO_MCP_CONFIG = saved;
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
it("is on when the variable is not set or empty", () => {
|
|
826
|
-
for (const value of [undefined, "", " "]) {
|
|
827
|
-
withEnv(value, () => expect(mcpConfigEnabled()).toBe(true));
|
|
828
|
-
}
|
|
829
|
-
});
|
|
830
|
-
|
|
831
|
-
it("stays on for every spelling of no", () => {
|
|
832
|
-
// The bug this guards: `!process.env.X` made =false DISABLE the feature it
|
|
833
|
-
// names, because every non-empty string is truthy.
|
|
834
|
-
for (const value of ["false", "FALSE", "0", "no", "OFF", " false "]) {
|
|
835
|
-
withEnv(value, () => expect(mcpConfigEnabled()).toBe(true));
|
|
836
|
-
}
|
|
837
|
-
});
|
|
838
|
-
|
|
839
|
-
it("turns off for every spelling of yes", () => {
|
|
840
|
-
for (const value of ["1", "true", "YES", "on"]) {
|
|
841
|
-
withEnv(value, () => expect(mcpConfigEnabled()).toBe(false));
|
|
842
|
-
}
|
|
843
|
-
});
|
|
844
|
-
|
|
845
|
-
it("reads the variable when called, not when the module was imported", () => {
|
|
846
|
-
// server.ts sets this from --no-mcp-config in parseArgs() and reads it at
|
|
847
|
-
// module scope afterwards. If the read were ever hoisted above parseArgs,
|
|
848
|
-
// or the value captured at import, the flag would silently stop working.
|
|
849
|
-
withEnv(undefined, () => {
|
|
850
|
-
expect(mcpConfigEnabled()).toBe(true);
|
|
851
|
-
process.env.PUBLISHER_NO_MCP_CONFIG = "true";
|
|
852
|
-
expect(mcpConfigEnabled()).toBe(false);
|
|
853
|
-
});
|
|
854
|
-
});
|
|
855
|
-
|
|
856
|
-
it("throws on a value that is neither, like every other flag in this server", () => {
|
|
857
|
-
withEnv("please", () => expect(() => mcpConfigEnabled()).toThrow());
|
|
858
|
-
});
|
|
859
|
-
});
|
|
860
|
-
|
|
861
|
-
describe("resolveClientHost", () => {
|
|
862
|
-
// `localhost` resolves to BOTH 127.0.0.1 and ::1, while the server binds
|
|
863
|
-
// exactly one family: 0.0.0.0 is the IPv4 wildcard and leaves ::1 free. A
|
|
864
|
-
// local process squatting the same port on the other family then receives the
|
|
865
|
-
// agent's traffic, because fetch prefers the IPv6 answer. Reproduced 3/3
|
|
866
|
-
// before this was changed, so these assertions are the fix, not a preference.
|
|
867
|
-
const v4 = (address: string) =>
|
|
868
|
-
({ address, family: "IPv4", port: 4040 }) as const;
|
|
869
|
-
const v6 = (address: string) =>
|
|
870
|
-
({ address, family: "IPv6", port: 4040 }) as const;
|
|
871
|
-
|
|
872
|
-
it("never writes the ambiguous name", () => {
|
|
873
|
-
for (const addr of [v4("0.0.0.0"), v6("::"), v4("127.0.0.1")]) {
|
|
874
|
-
expect(resolveClientHost(addr, "0.0.0.0")).not.toContain("localhost");
|
|
875
|
-
}
|
|
876
|
-
});
|
|
877
|
-
|
|
878
|
-
it("maps each wildcard to the loopback of its own family", () => {
|
|
879
|
-
expect(resolveClientHost(v4("0.0.0.0"), "0.0.0.0")).toBe("127.0.0.1");
|
|
880
|
-
expect(resolveClientHost(v6("::"), "::")).toBe("[::1]");
|
|
881
|
-
});
|
|
882
|
-
|
|
883
|
-
it("keeps a specific bind address, which is the only one that reaches it", () => {
|
|
884
|
-
expect(resolveClientHost(v4("127.0.0.1"), "0.0.0.0")).toBe("127.0.0.1");
|
|
885
|
-
expect(resolveClientHost(v4("192.168.1.5"), "0.0.0.0")).toBe(
|
|
886
|
-
"192.168.1.5",
|
|
887
|
-
);
|
|
888
|
-
});
|
|
889
|
-
|
|
890
|
-
it("brackets an IPv6 literal so the URL is legal", () => {
|
|
891
|
-
expect(resolveClientHost(v6("::1"), "::")).toBe("[::1]");
|
|
892
|
-
expect(mcpEndpoint(resolveClientHost(v6("::1"), "::"), 4040)).toBe(
|
|
893
|
-
"http://[::1]:4040/mcp",
|
|
894
|
-
);
|
|
895
|
-
});
|
|
896
|
-
|
|
897
|
-
it("falls back to the configured host when there is no address", () => {
|
|
898
|
-
expect(resolveClientHost(null, "127.0.0.1")).toBe("127.0.0.1");
|
|
899
|
-
expect(resolveClientHost("/tmp/sock", "0.0.0.0")).toBe("127.0.0.1");
|
|
900
|
-
});
|
|
901
|
-
});
|
|
902
|
-
|
|
903
|
-
describe("resolveBoundPort", () => {
|
|
904
|
-
// The piece that makes "no ports to know" true. It was inline in the listen
|
|
905
|
-
// callback and therefore untestable.
|
|
906
|
-
it("prefers the port the OS actually bound", () => {
|
|
907
|
-
expect(
|
|
908
|
-
resolveBoundPort({ address: "::", family: "IPv6", port: 51234 }, 0),
|
|
909
|
-
).toBe(51234);
|
|
910
|
-
});
|
|
911
|
-
|
|
912
|
-
it("falls back to the requested port when the address is a pipe path", () => {
|
|
913
|
-
expect(resolveBoundPort("/tmp/sock", 4040)).toBe(4040);
|
|
914
|
-
});
|
|
915
|
-
|
|
916
|
-
it("falls back when there is no address at all", () => {
|
|
917
|
-
expect(resolveBoundPort(null, 4040)).toBe(4040);
|
|
918
|
-
});
|
|
919
|
-
});
|