@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
|
@@ -1,685 +0,0 @@
|
|
|
1
|
-
import type { PersistSource } from "@malloydata/malloy";
|
|
2
|
-
import { describe, expect, it } from "bun:test";
|
|
3
|
-
import * as sinon from "sinon";
|
|
4
|
-
import type { BuildGraph as MalloyBuildGraph } from "@malloydata/malloy";
|
|
5
|
-
import {
|
|
6
|
-
compilePackageBuildPlan,
|
|
7
|
-
computeSourceEntityId,
|
|
8
|
-
computePackageBuildPlan,
|
|
9
|
-
deriveAnnotationFields,
|
|
10
|
-
deriveBuildPlan,
|
|
11
|
-
flattenDependsOn,
|
|
12
|
-
iterGraphSources,
|
|
13
|
-
projectToPublicColumns,
|
|
14
|
-
resolveFreshness,
|
|
15
|
-
resolveQueryMetadata,
|
|
16
|
-
resolvePackageConnections,
|
|
17
|
-
} from "./build_plan";
|
|
18
|
-
import { MaterializationEligibilityError } from "../errors";
|
|
19
|
-
import { fakeSource } from "./materialization_test_fixtures";
|
|
20
|
-
import { Model } from "./model";
|
|
21
|
-
|
|
22
|
-
describe("flattenDependsOn", () => {
|
|
23
|
-
it("maps nested dependsOn entries to a flat sourceID list", () => {
|
|
24
|
-
expect(
|
|
25
|
-
flattenDependsOn({
|
|
26
|
-
dependsOn: [{ sourceID: "a" }, { sourceID: "b" }],
|
|
27
|
-
}),
|
|
28
|
-
).toEqual(["a", "b"]);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe("iterGraphSources", () => {
|
|
33
|
-
it("yields resolvable sources in dependency order, skipping missing ones", () => {
|
|
34
|
-
const a = fakeSource({ name: "a", sourceEntityId: "ba" });
|
|
35
|
-
const b = fakeSource({ name: "b", sourceEntityId: "bb" });
|
|
36
|
-
const graph = {
|
|
37
|
-
connectionName: "duckdb",
|
|
38
|
-
nodes: [
|
|
39
|
-
[{ sourceID: "a@m", dependsOn: [] }],
|
|
40
|
-
[
|
|
41
|
-
{ sourceID: "missing@m", dependsOn: [] },
|
|
42
|
-
{ sourceID: "b@m", dependsOn: [] },
|
|
43
|
-
],
|
|
44
|
-
],
|
|
45
|
-
} as unknown as MalloyBuildGraph;
|
|
46
|
-
|
|
47
|
-
const names = [...iterGraphSources(graph, { "a@m": a, "b@m": b })].map(
|
|
48
|
-
(s) => s.name,
|
|
49
|
-
);
|
|
50
|
-
expect(names).toEqual(["a", "b"]);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("walks each root's nested dependsOn tree, deps before dependents", () => {
|
|
54
|
-
// root -> mid -> leaf, with only `root` at the graph's node level — this
|
|
55
|
-
// mirrors malloy getBuildPlan(): terminal persist sources are the nodes,
|
|
56
|
-
// and every transitive persist dependency is nested in dependsOn. All
|
|
57
|
-
// three must be yielded (so all get built), leaf-first so a downstream
|
|
58
|
-
// build reads its upstream's freshly materialized table.
|
|
59
|
-
const root = fakeSource({ name: "root", sourceEntityId: "br" });
|
|
60
|
-
const mid = fakeSource({ name: "mid", sourceEntityId: "bm" });
|
|
61
|
-
const leaf = fakeSource({ name: "leaf", sourceEntityId: "bl" });
|
|
62
|
-
const graph = {
|
|
63
|
-
connectionName: "duckdb",
|
|
64
|
-
nodes: [
|
|
65
|
-
[
|
|
66
|
-
{
|
|
67
|
-
sourceID: "root@m",
|
|
68
|
-
dependsOn: [
|
|
69
|
-
{
|
|
70
|
-
sourceID: "mid@m",
|
|
71
|
-
dependsOn: [{ sourceID: "leaf@m", dependsOn: [] }],
|
|
72
|
-
},
|
|
73
|
-
],
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
],
|
|
77
|
-
} as unknown as MalloyBuildGraph;
|
|
78
|
-
|
|
79
|
-
const names = [
|
|
80
|
-
...iterGraphSources(graph, {
|
|
81
|
-
"root@m": root,
|
|
82
|
-
"mid@m": mid,
|
|
83
|
-
"leaf@m": leaf,
|
|
84
|
-
}),
|
|
85
|
-
].map((s) => s.name);
|
|
86
|
-
expect(names).toEqual(["leaf", "mid", "root"]);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("deduplicates a shared (diamond) dependency across roots", () => {
|
|
90
|
-
// r1 and r2 both depend on `shared`; it must be yielded exactly once and
|
|
91
|
-
// before both dependents.
|
|
92
|
-
const r1 = fakeSource({ name: "r1", sourceEntityId: "b1" });
|
|
93
|
-
const r2 = fakeSource({ name: "r2", sourceEntityId: "b2" });
|
|
94
|
-
const shared = fakeSource({ name: "shared", sourceEntityId: "bs" });
|
|
95
|
-
const graph = {
|
|
96
|
-
connectionName: "duckdb",
|
|
97
|
-
nodes: [
|
|
98
|
-
[
|
|
99
|
-
{
|
|
100
|
-
sourceID: "r1@m",
|
|
101
|
-
dependsOn: [{ sourceID: "shared@m", dependsOn: [] }],
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
sourceID: "r2@m",
|
|
105
|
-
dependsOn: [{ sourceID: "shared@m", dependsOn: [] }],
|
|
106
|
-
},
|
|
107
|
-
],
|
|
108
|
-
],
|
|
109
|
-
} as unknown as MalloyBuildGraph;
|
|
110
|
-
|
|
111
|
-
const names = [
|
|
112
|
-
...iterGraphSources(graph, {
|
|
113
|
-
"r1@m": r1,
|
|
114
|
-
"r2@m": r2,
|
|
115
|
-
"shared@m": shared,
|
|
116
|
-
}),
|
|
117
|
-
].map((s) => s.name);
|
|
118
|
-
expect(names).toEqual(["shared", "r1", "r2"]);
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
describe("deriveAnnotationFields", () => {
|
|
123
|
-
it("returns all key=value fields of the #@ persist annotation", () => {
|
|
124
|
-
const source = {
|
|
125
|
-
annotations: {
|
|
126
|
-
parseAsTag: () => ({
|
|
127
|
-
tag: {
|
|
128
|
-
*entries() {
|
|
129
|
-
yield ["name", { text: () => "engaged_events" }];
|
|
130
|
-
yield ["realization", { text: () => "COPY" }];
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
}),
|
|
134
|
-
},
|
|
135
|
-
} as unknown as PersistSource;
|
|
136
|
-
|
|
137
|
-
expect(deriveAnnotationFields(source)).toEqual({
|
|
138
|
-
name: "engaged_events",
|
|
139
|
-
realization: "COPY",
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it("degrades to {} when the annotation is absent or unparseable", () => {
|
|
144
|
-
const source = {
|
|
145
|
-
annotations: {
|
|
146
|
-
parseAsTag: () => {
|
|
147
|
-
throw new Error("no @ annotation");
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
} as unknown as PersistSource;
|
|
151
|
-
|
|
152
|
-
expect(deriveAnnotationFields(source)).toEqual({});
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
describe("projectToPublicColumns", () => {
|
|
157
|
-
// A source whose PUBLIC surface (intrinsic atomic fields) is `cols` — i.e. any
|
|
158
|
-
// `except:`-ed / access-restricted column is already absent here, as Malloy
|
|
159
|
-
// reflects it. deriveColumns reads exactly this.
|
|
160
|
-
const sourceWithPublicCols = (cols: string[]): PersistSource =>
|
|
161
|
-
({
|
|
162
|
-
dialectName: "postgres",
|
|
163
|
-
_explore: {
|
|
164
|
-
intrinsicFields: cols.map((name) => ({
|
|
165
|
-
name,
|
|
166
|
-
isAtomicField: () => true,
|
|
167
|
-
type: "string",
|
|
168
|
-
})),
|
|
169
|
-
},
|
|
170
|
-
}) as unknown as PersistSource;
|
|
171
|
-
|
|
172
|
-
it("wraps the build SQL to project only the source's public columns", () => {
|
|
173
|
-
const src = sourceWithPublicCols(["order_date", "amount"]); // `region` hidden → absent
|
|
174
|
-
const out = projectToPublicColumns(
|
|
175
|
-
src,
|
|
176
|
-
"SELECT order_date, region, amount FROM t",
|
|
177
|
-
);
|
|
178
|
-
// Outer projection lists ONLY the public columns; the hidden one is dropped.
|
|
179
|
-
expect(out).toMatch(/^SELECT\b/);
|
|
180
|
-
expect(out).toContain("order_date");
|
|
181
|
-
expect(out).toContain("amount");
|
|
182
|
-
expect(out).toContain(
|
|
183
|
-
"FROM (SELECT order_date, region, amount FROM t) AS __public",
|
|
184
|
-
);
|
|
185
|
-
// `region` must not appear in the OUTER projection (before the subquery).
|
|
186
|
-
const outerProjection = out.slice(0, out.indexOf("FROM ("));
|
|
187
|
-
expect(outerProjection).not.toContain("region");
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
// Fails closed, like the rest of the eligibility surface: a public surface we
|
|
191
|
-
// can't determine refuses the build rather than widening to everything getSQL
|
|
192
|
-
// projects (which is where the hidden columns are).
|
|
193
|
-
it("refuses the build when the field list can't be read", () => {
|
|
194
|
-
const noExplore = {} as unknown as PersistSource;
|
|
195
|
-
expect(() => projectToPublicColumns(noExplore, "SELECT 1")).toThrow(
|
|
196
|
-
/public column surface could not be determined/,
|
|
197
|
-
);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it("refuses the build when the source exposes no public atomic columns", () => {
|
|
201
|
-
// Everything getSQL projects is hidden — the worst case to materialize.
|
|
202
|
-
expect(() =>
|
|
203
|
-
projectToPublicColumns(sourceWithPublicCols([]), "SELECT 1"),
|
|
204
|
-
).toThrow(/no public atomic columns/);
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
it("refuses with an eligibility error (422), naming the source", () => {
|
|
208
|
-
const src = { ...sourceWithPublicCols([]), name: "daily" };
|
|
209
|
-
try {
|
|
210
|
-
projectToPublicColumns(src as unknown as PersistSource, "SELECT 1");
|
|
211
|
-
throw new Error("expected a refusal");
|
|
212
|
-
} catch (err) {
|
|
213
|
-
expect(err).toBeInstanceOf(MaterializationEligibilityError);
|
|
214
|
-
expect((err as Error).message).toContain("'daily'");
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
describe("computeSourceEntityId", () => {
|
|
220
|
-
it("delegates to PersistSource.makeBuildId with the connection digest and SQL", () => {
|
|
221
|
-
const makeBuildId = sinon.stub().returns("computed-id");
|
|
222
|
-
const source = {
|
|
223
|
-
connectionName: "duckdb",
|
|
224
|
-
makeBuildId,
|
|
225
|
-
getSQL: () => "SELECT 7",
|
|
226
|
-
} as unknown as PersistSource;
|
|
227
|
-
|
|
228
|
-
const id = computeSourceEntityId(source, { duckdb: "dig-1" });
|
|
229
|
-
|
|
230
|
-
expect(id).toBe("computed-id");
|
|
231
|
-
expect(makeBuildId.calledOnceWithExactly("dig-1", "SELECT 7")).toBe(true);
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
describe("resolvePackageConnections", () => {
|
|
236
|
-
it("resolves each unique name once and omits failures", async () => {
|
|
237
|
-
const getMalloyConnection = sinon.stub();
|
|
238
|
-
getMalloyConnection.withArgs("ok").resolves({ id: "ok-conn" });
|
|
239
|
-
getMalloyConnection.withArgs("bad").rejects(new Error("nope"));
|
|
240
|
-
|
|
241
|
-
const map = await resolvePackageConnections({ getMalloyConnection }, [
|
|
242
|
-
"ok",
|
|
243
|
-
"ok",
|
|
244
|
-
"bad",
|
|
245
|
-
]);
|
|
246
|
-
|
|
247
|
-
expect(map.has("ok")).toBe(true);
|
|
248
|
-
expect(map.has("bad")).toBe(false);
|
|
249
|
-
// "ok" requested twice but resolved once (dedupe).
|
|
250
|
-
expect(getMalloyConnection.withArgs("ok").callCount).toBe(1);
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
describe("deriveBuildPlan", () => {
|
|
255
|
-
it("projects graphs and sources into the wire build plan", () => {
|
|
256
|
-
const orders = fakeSource({
|
|
257
|
-
name: "orders",
|
|
258
|
-
sourceEntityId: "bid-orders",
|
|
259
|
-
sql: "SELECT 1",
|
|
260
|
-
});
|
|
261
|
-
const plan = deriveBuildPlan(
|
|
262
|
-
[
|
|
263
|
-
{
|
|
264
|
-
connectionName: "duckdb",
|
|
265
|
-
nodes: [[{ sourceID: "orders@m", dependsOn: [] }]],
|
|
266
|
-
},
|
|
267
|
-
] as unknown as Parameters<typeof deriveBuildPlan>[0],
|
|
268
|
-
{ "orders@m": orders },
|
|
269
|
-
{ duckdb: "dig" },
|
|
270
|
-
);
|
|
271
|
-
|
|
272
|
-
expect(plan.graphs[0].connectionName).toBe("duckdb");
|
|
273
|
-
expect(plan.sources["orders@m"]).toMatchObject({
|
|
274
|
-
name: "orders",
|
|
275
|
-
connectionName: "duckdb",
|
|
276
|
-
sourceEntityId: "bid-orders",
|
|
277
|
-
sql: "SELECT 1",
|
|
278
|
-
columns: [],
|
|
279
|
-
});
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
it("reports declared refresh verbatim (null when unset) and does not emit sharing/schedule", () => {
|
|
283
|
-
// `refresh` is a metadata pass-through; `sharing`/`schedule` were retired
|
|
284
|
-
// from the contract and must not be emitted as typed fields (they stay in
|
|
285
|
-
// the raw annotationFields for the publish-time validator to detect).
|
|
286
|
-
const declared = fakeSource({
|
|
287
|
-
name: "declared",
|
|
288
|
-
sourceEntityId: "bid-d",
|
|
289
|
-
annotationFields: {
|
|
290
|
-
name: "d_table",
|
|
291
|
-
sharing: "private",
|
|
292
|
-
refresh: "incremental",
|
|
293
|
-
},
|
|
294
|
-
});
|
|
295
|
-
const unset = fakeSource({ name: "unset", sourceEntityId: "bid-u" });
|
|
296
|
-
const plan = deriveBuildPlan(
|
|
297
|
-
[
|
|
298
|
-
{
|
|
299
|
-
connectionName: "duckdb",
|
|
300
|
-
nodes: [
|
|
301
|
-
[
|
|
302
|
-
{ sourceID: "declared@m", dependsOn: [] },
|
|
303
|
-
{ sourceID: "unset@m", dependsOn: [] },
|
|
304
|
-
],
|
|
305
|
-
],
|
|
306
|
-
},
|
|
307
|
-
] as unknown as Parameters<typeof deriveBuildPlan>[0],
|
|
308
|
-
{ "declared@m": declared, "unset@m": unset },
|
|
309
|
-
{ duckdb: "dig" },
|
|
310
|
-
);
|
|
311
|
-
|
|
312
|
-
expect(plan.sources["declared@m"].refresh).toBe("incremental");
|
|
313
|
-
// Retired typed fields are absent from the wire projection.
|
|
314
|
-
expect(
|
|
315
|
-
(plan.sources["declared@m"] as Record<string, unknown>).sharing,
|
|
316
|
-
).toBeUndefined();
|
|
317
|
-
expect(
|
|
318
|
-
(plan.sources["declared@m"] as Record<string, unknown>).schedule,
|
|
319
|
-
).toBeUndefined();
|
|
320
|
-
// The raw annotation map still carries every field (so the validator can
|
|
321
|
-
// reject a source-level sharing/schedule at publish).
|
|
322
|
-
expect(plan.sources["declared@m"].annotationFields).toEqual({
|
|
323
|
-
name: "d_table",
|
|
324
|
-
sharing: "private",
|
|
325
|
-
refresh: "incremental",
|
|
326
|
-
});
|
|
327
|
-
// Unset refresh is null on the wire.
|
|
328
|
-
expect(plan.sources["unset@m"].refresh).toBeNull();
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
it("honors the sourceNames filter", () => {
|
|
332
|
-
const a = fakeSource({ name: "a", sourceEntityId: "bid-a" });
|
|
333
|
-
const b = fakeSource({ name: "b", sourceEntityId: "bid-b" });
|
|
334
|
-
const plan = deriveBuildPlan(
|
|
335
|
-
[
|
|
336
|
-
{
|
|
337
|
-
connectionName: "duckdb",
|
|
338
|
-
nodes: [[{ sourceID: "a@m", dependsOn: [] }]],
|
|
339
|
-
},
|
|
340
|
-
] as unknown as Parameters<typeof deriveBuildPlan>[0],
|
|
341
|
-
{ "a@m": a, "b@m": b },
|
|
342
|
-
{ duckdb: "dig" },
|
|
343
|
-
["a"],
|
|
344
|
-
);
|
|
345
|
-
|
|
346
|
-
expect(Object.keys(plan.sources)).toEqual(["a@m"]);
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
it("carries the per-source package-relative modelPath", () => {
|
|
350
|
-
const a = fakeSource({ name: "a", sourceEntityId: "bid-a" });
|
|
351
|
-
const b = fakeSource({ name: "b", sourceEntityId: "bid-b" });
|
|
352
|
-
const plan = deriveBuildPlan(
|
|
353
|
-
[
|
|
354
|
-
{
|
|
355
|
-
connectionName: "duckdb",
|
|
356
|
-
nodes: [[{ sourceID: "a@m", dependsOn: [] }]],
|
|
357
|
-
},
|
|
358
|
-
] as unknown as Parameters<typeof deriveBuildPlan>[0],
|
|
359
|
-
{ "a@m": a, "b@m": b },
|
|
360
|
-
{ duckdb: "dig" },
|
|
361
|
-
undefined,
|
|
362
|
-
{ "a@m": "rollup.malloy" },
|
|
363
|
-
);
|
|
364
|
-
|
|
365
|
-
// Mapped source gets its model path; an unmapped source stays undefined.
|
|
366
|
-
expect(plan.sources["a@m"].modelPath).toBe("rollup.malloy");
|
|
367
|
-
expect(plan.sources["b@m"].modelPath).toBeUndefined();
|
|
368
|
-
});
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
describe("resolveFreshness", () => {
|
|
372
|
-
it("reports source-level freshness verbatim", () => {
|
|
373
|
-
const source = fakeSource({
|
|
374
|
-
name: "s",
|
|
375
|
-
sourceEntityId: "bid",
|
|
376
|
-
freshnessSchedule: {
|
|
377
|
-
freshness: { window: "1h", fallback: "stale_ok" },
|
|
378
|
-
},
|
|
379
|
-
});
|
|
380
|
-
expect(resolveFreshness(source, null)).toEqual({
|
|
381
|
-
window: "1h",
|
|
382
|
-
fallback: "stale_ok",
|
|
383
|
-
});
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
it("returns null when unset at every level", () => {
|
|
387
|
-
const source = fakeSource({ name: "s", sourceEntityId: "bid" });
|
|
388
|
-
expect(resolveFreshness(source, null)).toBeNull();
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
it("falls back to model-file then package per field (most-specific-wins)", () => {
|
|
392
|
-
// freshness.window from source, freshness.fallback from model-file.
|
|
393
|
-
const source = fakeSource({
|
|
394
|
-
name: "s",
|
|
395
|
-
sourceEntityId: "bid",
|
|
396
|
-
freshnessSchedule: { freshness: { window: "1h" } },
|
|
397
|
-
modelFreshnessSchedule: { freshness: { fallback: "fail" } },
|
|
398
|
-
});
|
|
399
|
-
const pkg = {
|
|
400
|
-
schedule: null,
|
|
401
|
-
freshness: { window: "24h", fallback: "live" as const },
|
|
402
|
-
};
|
|
403
|
-
expect(resolveFreshness(source, pkg)).toEqual({
|
|
404
|
-
window: "1h",
|
|
405
|
-
fallback: "fail",
|
|
406
|
-
});
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
it("inherits the package freshness when the source and model are unset", () => {
|
|
410
|
-
const source = fakeSource({ name: "s", sourceEntityId: "bid" });
|
|
411
|
-
const pkg = { schedule: null, freshness: { window: "24h" } };
|
|
412
|
-
expect(resolveFreshness(source, pkg)).toEqual({ window: "24h" });
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
it("drops an invalid fallback rather than defaulting it", () => {
|
|
416
|
-
const source = fakeSource({
|
|
417
|
-
name: "s",
|
|
418
|
-
sourceEntityId: "bid",
|
|
419
|
-
freshnessSchedule: { freshness: { window: "1h", fallback: "bogus" } },
|
|
420
|
-
});
|
|
421
|
-
expect(resolveFreshness(source, null)).toEqual({ window: "1h" });
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
it("reads the model-file `materialization` envelope", () => {
|
|
425
|
-
const source = fakeSource({
|
|
426
|
-
name: "s",
|
|
427
|
-
sourceEntityId: "bid",
|
|
428
|
-
modelMaterialization: { freshness: { freshness: { window: "12h" } } },
|
|
429
|
-
});
|
|
430
|
-
expect(resolveFreshness(source, null)).toEqual({ window: "12h" });
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
it("prefers the envelope over the deprecated bare model-file form", () => {
|
|
434
|
-
const source = fakeSource({
|
|
435
|
-
name: "s",
|
|
436
|
-
sourceEntityId: "bid",
|
|
437
|
-
modelFreshnessSchedule: { freshness: { window: "48h" } },
|
|
438
|
-
modelMaterialization: { freshness: { freshness: { window: "12h" } } },
|
|
439
|
-
});
|
|
440
|
-
expect(resolveFreshness(source, null)).toEqual({ window: "12h" });
|
|
441
|
-
});
|
|
442
|
-
|
|
443
|
-
it("still reads a bare model-file knob the envelope does not declare", () => {
|
|
444
|
-
// A package published before the envelope existed keeps resolving, and the
|
|
445
|
-
// envelope does not hide the knobs it says nothing about.
|
|
446
|
-
const source = fakeSource({
|
|
447
|
-
name: "s",
|
|
448
|
-
sourceEntityId: "bid",
|
|
449
|
-
modelFreshnessSchedule: { freshness: { fallback: "fail" } },
|
|
450
|
-
modelMaterialization: { freshness: { freshness: { window: "12h" } } },
|
|
451
|
-
});
|
|
452
|
-
expect(resolveFreshness(source, null)).toEqual({
|
|
453
|
-
window: "12h",
|
|
454
|
-
fallback: "fail",
|
|
455
|
-
});
|
|
456
|
-
});
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
describe("resolveQueryMetadata", () => {
|
|
460
|
-
it("returns null when no layer declares anything", () => {
|
|
461
|
-
const source = fakeSource({ name: "s", sourceEntityId: "bid" });
|
|
462
|
-
expect(resolveQueryMetadata(source, null)).toBeNull();
|
|
463
|
-
expect(
|
|
464
|
-
resolveQueryMetadata(source, {
|
|
465
|
-
schedule: null,
|
|
466
|
-
freshness: null,
|
|
467
|
-
queryMetadata: null,
|
|
468
|
-
}),
|
|
469
|
-
).toBeNull();
|
|
470
|
-
});
|
|
471
|
-
|
|
472
|
-
it("reads the source's `#@ persist queryMetadata.*` properties", () => {
|
|
473
|
-
const source = fakeSource({
|
|
474
|
-
name: "s",
|
|
475
|
-
sourceEntityId: "bid",
|
|
476
|
-
queryMetadata: { team: "finance", workload: "orders" },
|
|
477
|
-
});
|
|
478
|
-
expect(resolveQueryMetadata(source, null)).toEqual({
|
|
479
|
-
team: "finance",
|
|
480
|
-
workload: "orders",
|
|
481
|
-
});
|
|
482
|
-
});
|
|
483
|
-
|
|
484
|
-
it("resolves most-specific-wins PER PROPERTY across all four layers", () => {
|
|
485
|
-
// Package declares team+tier, the model-file envelope overrides tier and
|
|
486
|
-
// adds one of its own, the source overrides only workload: every property
|
|
487
|
-
// nothing more specific overrides has to survive.
|
|
488
|
-
const source = fakeSource({
|
|
489
|
-
name: "s",
|
|
490
|
-
sourceEntityId: "bid",
|
|
491
|
-
queryMetadata: { workload: "orders" },
|
|
492
|
-
modelMaterialization: {
|
|
493
|
-
queryMetadata: { tier: "gold", surface: "marts" },
|
|
494
|
-
},
|
|
495
|
-
});
|
|
496
|
-
expect(
|
|
497
|
-
resolveQueryMetadata(source, {
|
|
498
|
-
schedule: null,
|
|
499
|
-
freshness: null,
|
|
500
|
-
queryMetadata: { team: "finance", tier: "bronze" },
|
|
501
|
-
}),
|
|
502
|
-
).toEqual({
|
|
503
|
-
team: "finance",
|
|
504
|
-
tier: "gold",
|
|
505
|
-
surface: "marts",
|
|
506
|
-
workload: "orders",
|
|
507
|
-
});
|
|
508
|
-
});
|
|
509
|
-
|
|
510
|
-
it("prefers the model-file envelope over the bare form, per property", () => {
|
|
511
|
-
const source = fakeSource({
|
|
512
|
-
name: "s",
|
|
513
|
-
sourceEntityId: "bid",
|
|
514
|
-
modelQueryMetadata: { tier: "bronze", legacy: "kept" },
|
|
515
|
-
modelMaterialization: { queryMetadata: { tier: "gold" } },
|
|
516
|
-
});
|
|
517
|
-
expect(resolveQueryMetadata(source, null)).toEqual({
|
|
518
|
-
tier: "gold",
|
|
519
|
-
legacy: "kept",
|
|
520
|
-
});
|
|
521
|
-
});
|
|
522
|
-
|
|
523
|
-
it("keeps a contract-violating property for the validator to report", () => {
|
|
524
|
-
const source = fakeSource({
|
|
525
|
-
name: "s",
|
|
526
|
-
sourceEntityId: "bid",
|
|
527
|
-
queryMetadata: { "team.name": "finance" },
|
|
528
|
-
});
|
|
529
|
-
expect(resolveQueryMetadata(source, null)).toEqual({
|
|
530
|
-
"team.name": "finance",
|
|
531
|
-
});
|
|
532
|
-
});
|
|
533
|
-
|
|
534
|
-
it("does not confuse the scalar `#@ persist` fields beside it", () => {
|
|
535
|
-
const source = fakeSource({
|
|
536
|
-
name: "s",
|
|
537
|
-
sourceEntityId: "bid",
|
|
538
|
-
annotationFields: { name: "s_table", refresh: "full" },
|
|
539
|
-
queryMetadata: { team: "finance" },
|
|
540
|
-
});
|
|
541
|
-
expect(resolveQueryMetadata(source, null)).toEqual({ team: "finance" });
|
|
542
|
-
expect(deriveAnnotationFields(source)).toEqual({
|
|
543
|
-
name: "s_table",
|
|
544
|
-
refresh: "full",
|
|
545
|
-
});
|
|
546
|
-
});
|
|
547
|
-
});
|
|
548
|
-
|
|
549
|
-
describe("deriveBuildPlan freshness", () => {
|
|
550
|
-
it("projects the resolved per-source freshness onto the plan (no schedule/sharing)", () => {
|
|
551
|
-
const source = fakeSource({
|
|
552
|
-
name: "s",
|
|
553
|
-
sourceEntityId: "bid",
|
|
554
|
-
annotationFields: { name: "s_table" },
|
|
555
|
-
freshnessSchedule: { freshness: { window: "1h" } },
|
|
556
|
-
});
|
|
557
|
-
const plan = deriveBuildPlan(
|
|
558
|
-
[
|
|
559
|
-
{
|
|
560
|
-
connectionName: "duckdb",
|
|
561
|
-
nodes: [[{ sourceID: "s@m", dependsOn: [] }]],
|
|
562
|
-
},
|
|
563
|
-
] as unknown as Parameters<typeof deriveBuildPlan>[0],
|
|
564
|
-
{ "s@m": source },
|
|
565
|
-
{ duckdb: "dig" },
|
|
566
|
-
undefined,
|
|
567
|
-
undefined,
|
|
568
|
-
{
|
|
569
|
-
schedule: null,
|
|
570
|
-
freshness: { window: "24h", fallback: "live" as const },
|
|
571
|
-
},
|
|
572
|
-
);
|
|
573
|
-
|
|
574
|
-
// Source window wins over the package default; package fallback fills the
|
|
575
|
-
// unset source fallback.
|
|
576
|
-
expect(plan.sources["s@m"].freshness).toEqual({
|
|
577
|
-
window: "1h",
|
|
578
|
-
fallback: "live",
|
|
579
|
-
});
|
|
580
|
-
// Retired fields are not emitted.
|
|
581
|
-
expect(
|
|
582
|
-
(plan.sources["s@m"] as Record<string, unknown>).schedule,
|
|
583
|
-
).toBeUndefined();
|
|
584
|
-
expect(
|
|
585
|
-
(plan.sources["s@m"] as Record<string, unknown>).sharing,
|
|
586
|
-
).toBeUndefined();
|
|
587
|
-
});
|
|
588
|
-
});
|
|
589
|
-
|
|
590
|
-
describe("compilePackageBuildPlan", () => {
|
|
591
|
-
it("skips .malloynb notebooks without compiling them", async () => {
|
|
592
|
-
// A notebook would throw on its `>>>` cell delimiter if compiled as a
|
|
593
|
-
// flat model, aborting the whole package plan; it must be skipped.
|
|
594
|
-
const getModelRuntime = sinon.stub(Model, "getModelRuntime");
|
|
595
|
-
try {
|
|
596
|
-
const pkg = {
|
|
597
|
-
getModelPaths: () => ["notes.malloynb"],
|
|
598
|
-
getPackagePath: () => "/test",
|
|
599
|
-
getMalloyConfig: () => ({}),
|
|
600
|
-
getMalloyConnection: async () => ({}),
|
|
601
|
-
} as unknown as Parameters<typeof compilePackageBuildPlan>[0];
|
|
602
|
-
|
|
603
|
-
const compiled = await compilePackageBuildPlan(pkg);
|
|
604
|
-
|
|
605
|
-
expect(compiled.graphs).toEqual([]);
|
|
606
|
-
expect(getModelRuntime.called).toBe(false);
|
|
607
|
-
} finally {
|
|
608
|
-
getModelRuntime.restore();
|
|
609
|
-
}
|
|
610
|
-
});
|
|
611
|
-
|
|
612
|
-
it("skips a model lacking ##! experimental.persistence instead of aborting the package", async () => {
|
|
613
|
-
// getBuildPlan() THROWS on a model without the flag (it does not return
|
|
614
|
-
// empty), so a header-less non-persist model — e.g. an imported base that
|
|
615
|
-
// only defines raw sources — must be skipped, or it would abort the whole
|
|
616
|
-
// package plan and drop the persist source in the sibling model.
|
|
617
|
-
const fakeModel = (hasFlag: boolean, graphs: MalloyBuildGraph[]) => ({
|
|
618
|
-
modelAnnotations: {
|
|
619
|
-
parseAsTag: () => ({ tag: { has: () => hasFlag } }),
|
|
620
|
-
},
|
|
621
|
-
getBuildPlan: () => {
|
|
622
|
-
if (!hasFlag) {
|
|
623
|
-
throw new Error(
|
|
624
|
-
"Model must have ##! experimental.persistence to use getBuildPlan()",
|
|
625
|
-
);
|
|
626
|
-
}
|
|
627
|
-
return { graphs, sources: {}, tagParseLog: [] };
|
|
628
|
-
},
|
|
629
|
-
});
|
|
630
|
-
const models: Record<string, ReturnType<typeof fakeModel>> = {
|
|
631
|
-
"base.malloy": fakeModel(false, []), // header-less: must be skipped
|
|
632
|
-
"agg.malloy": fakeModel(true, [
|
|
633
|
-
{
|
|
634
|
-
connectionName: "duckdb",
|
|
635
|
-
nodes: [[{ sourceID: "daily@agg", dependsOn: [] }]],
|
|
636
|
-
},
|
|
637
|
-
] as unknown as MalloyBuildGraph[]),
|
|
638
|
-
};
|
|
639
|
-
const getModelRuntime = sinon
|
|
640
|
-
.stub(Model, "getModelRuntime")
|
|
641
|
-
.callsFake((async (_path: unknown, modelPath: unknown) => ({
|
|
642
|
-
runtime: {
|
|
643
|
-
loadModel: () => ({
|
|
644
|
-
getModel: async () => models[modelPath as string],
|
|
645
|
-
}),
|
|
646
|
-
},
|
|
647
|
-
modelURL: new URL(`file:///${modelPath}`),
|
|
648
|
-
importBaseURL: new URL("file:///"),
|
|
649
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
650
|
-
})) as any);
|
|
651
|
-
try {
|
|
652
|
-
const pkg = {
|
|
653
|
-
getModelPaths: () => ["base.malloy", "agg.malloy"],
|
|
654
|
-
getPackagePath: () => "/test",
|
|
655
|
-
getMalloyConfig: () => ({}),
|
|
656
|
-
getMalloyConnection: async () => ({ getDigest: async () => "dig" }),
|
|
657
|
-
} as unknown as Parameters<typeof compilePackageBuildPlan>[0];
|
|
658
|
-
|
|
659
|
-
// Would throw here before the guard (base.malloy's getBuildPlan).
|
|
660
|
-
const compiled = await compilePackageBuildPlan(pkg);
|
|
661
|
-
|
|
662
|
-
// The header-less model is skipped; the persist source in agg survives.
|
|
663
|
-
expect(compiled.graphs).toHaveLength(1);
|
|
664
|
-
expect(compiled.graphs[0].nodes[0][0].sourceID).toBe("daily@agg");
|
|
665
|
-
} finally {
|
|
666
|
-
getModelRuntime.restore();
|
|
667
|
-
}
|
|
668
|
-
});
|
|
669
|
-
});
|
|
670
|
-
|
|
671
|
-
describe("computePackageBuildPlan", () => {
|
|
672
|
-
it("returns a null plan and no dropped sources when the package declares no persist sources", async () => {
|
|
673
|
-
const pkg = {
|
|
674
|
-
getModelPaths: () => [],
|
|
675
|
-
getPackagePath: () => "/test",
|
|
676
|
-
getMalloyConfig: () => ({}),
|
|
677
|
-
getMalloyConnection: async () => ({}),
|
|
678
|
-
} as unknown as Parameters<typeof computePackageBuildPlan>[0];
|
|
679
|
-
|
|
680
|
-
const { plan, droppedPersistSources } =
|
|
681
|
-
await computePackageBuildPlan(pkg);
|
|
682
|
-
expect(plan).toBeNull();
|
|
683
|
-
expect(droppedPersistSources).toEqual([]);
|
|
684
|
-
});
|
|
685
|
-
});
|