Skip to content

Commit 263f3aa

Browse files
committed
Extract macro package helper
1 parent 8082f12 commit 263f3aa

3 files changed

Lines changed: 16 additions & 8 deletions

File tree

PLAN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ Exit criteria:
569569

570570
- M0 is complete as the Zig `0.16.0` runtime scaffold.
571571
- M1 has started on stacked branches with native Zig artifact-first parser slices.
572-
- M1A has started with behavior-preserving `src/project/types.zig`, `src/project/selector.zig`, `src/project/manifest.zig`, `src/project/util.zig`, `src/project/config.zig`, `src/project/fs.zig`, `src/project/jinja.zig`, `src/project/resolve.zig`, and `src/project/parse.zig` extractions. `src/project/manifest.zig` owns selected-resource JSON and partial `manifest.json` writing with native tests for selected JSON shape, JSON escaping, exposure dependency ordering, disabled-resource filtering, and graph-map output. `src/project/util.zig` owns shared display, membership, append-dedup, string sorting, and narrow YAML scalar/list helpers. `src/project/config.zig` owns `dbt_project.yml` loading, project path/docs config parsing, and applying parsed project path/docs configs to graph nodes. `src/project/fs.zig` owns deterministic resource file discovery, Linux directory traversal helpers, and resource path/name helpers. `src/project/jinja.zig` owns lexical Jinja call, parenthesis, quoted string, and literal argument helpers while graph-aware scanning remains in `src/project.zig`. `src/project/resolve.zig` owns graph lookup/count helpers, canonical graph resource ordering, duplicate resource validation, low-level ref/source resolution helpers, and dependency-map mutation for refs, sources, and known macro dependencies. `src/project/parse.zig` owns narrow parser scalar helpers for YAML booleans, JSON-compatible scalar classification, generic-test YAML item names, generic-test definition construction/cloning, and generic-test identity/name/hash helpers with native tests. `src/project.zig` remains the public parser/list facade and still owns most loader, resource parser, scanner, and resolver orchestration code until follow-up extractions move those pieces behind focused internal modules.
572+
- M1A has started with behavior-preserving `src/project/types.zig`, `src/project/selector.zig`, `src/project/manifest.zig`, `src/project/util.zig`, `src/project/config.zig`, `src/project/fs.zig`, `src/project/jinja.zig`, `src/project/resolve.zig`, and `src/project/parse.zig` extractions. `src/project/manifest.zig` owns selected-resource JSON and partial `manifest.json` writing with native tests for selected JSON shape, JSON escaping, exposure dependency ordering, disabled-resource filtering, and graph-map output. `src/project/util.zig` owns shared display, membership, append-dedup, string sorting, and narrow YAML scalar/list helpers. `src/project/config.zig` owns `dbt_project.yml` loading, project path/docs config parsing, and applying parsed project path/docs configs to graph nodes. `src/project/fs.zig` owns deterministic resource file discovery, Linux directory traversal helpers, and resource path/name helpers. `src/project/jinja.zig` owns lexical Jinja call, parenthesis, quoted string, and literal argument helpers while graph-aware scanning remains in `src/project.zig`. `src/project/resolve.zig` owns graph lookup/count helpers, canonical graph resource ordering, duplicate resource validation, macro unique-id package extraction, low-level ref/source resolution helpers, and dependency-map mutation for refs, sources, and known macro dependencies. `src/project/parse.zig` owns narrow parser scalar helpers for YAML booleans, JSON-compatible scalar classification, generic-test YAML item names, generic-test definition construction/cloning, and generic-test identity/name/hash helpers with native tests. `src/project.zig` remains the public parser/list facade and still owns most loader, resource parser, scanner, and resolver orchestration code until follow-up extractions move those pieces behind focused internal modules.
573573
- `dxt parse` now targets the supported Tier 0 subset: project name/model paths/seed paths/macro paths, project and package model path configs for literal `+materialized`, `+tags`, and model/seed `+docs.node_color`, root-project model config overrides for installed packages, SQL model discovery, CSV seed discovery, installed package SQL model and CSV seed discovery from `dbt_packages`, source discovery, installed package source discovery, exposure discovery, installed package exposure discovery, project macro discovery, installed package macro discovery from `dbt_packages`, macro property YAML for project macro descriptions and arguments, project and package docs block discovery, literal `ref` to models or seeds, two-argument package refs, package-local refs in installed package models and exposures, unique installed-package fallback for unqualified refs, literal `source`, package-local sources in installed package models, unique installed-package fallback for unqualified sources, literal `doc` in project and package descriptions, inline `config(materialized=..., tags=...)`, known project/package-qualified/package-local macro call dependencies, narrow project and package YAML model properties for scalar descriptions, simple columns, tags, materialization, disabled SQL models, dbt-shaped `unique`, `not_null`, `accepted_values`, and `relationships` generic test nodes, model/test `refs` and `sources` artifact fields, dependency maps, and deterministic partial `manifest.json`. The manifest includes the v12 top-level maps needed by the M1 artifact shape and is covered by a pinned local dbt Manifest v12 schema slice. YAML generic test arguments are currently supported for scalar values plus inline and block lists required by public Jaffle Shop DuckDB-style tests.
574574
- `dxt ls` now lists dbt-selectable resources from the same parser graph with stable text/JSON output and basic name/FQN wildcards, tag wildcards, slash-aware `path:` wildcards, exact `package:`/`package:this`, `source:` wildcards including package-qualified source selectors, `exposure:` wildcards, `resource_type:`, `test_type:generic`, config materialization, comma intersection, whitespace union, multi-argument selector lists, repeated selector flags, leading/trailing `+` graph expansion, and exact exclude filters; macros are emitted in artifacts but not exposed as `ls` resources.
575575
- Synthetic fixtures cover one model, model refs, seed refs, source refs, exposure refs to models and sources, combined source/model YAML, inline config/tag selection, config materialization selection, comma-intersection selection, YAML model properties and columns, emitted `unique`, `not_null`, `accepted_values`, and `relationships` generic test nodes, project macro artifacts and macro properties, configured `macro-paths` replacing the default macro directory, installed package macros with package-qualified calls and package-local macro calls, installed package models, seeds, sources, docs, exposures, package YAML model properties, root package config overrides, and package-qualified/package-local refs/sources, macro calls recorded in model and macro `depends_on.macros`, docs blocks with literal `doc` descriptions, disabled models, disabled ref diagnostics, unmatched model-property warnings, duplicate model and docs diagnostics, unsupported dynamic ref/doc diagnostics, missing doc diagnostics, malformed docs block diagnostics, unresolved package macro diagnostics, and unsupported unknown macro-call diagnostics.

src/project.zig

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const findMacroIdForUnqualifiedCall = project_resolve.findMacroIdForUnqualifiedC
7878
const findMacroIndexByPackageAndName = project_resolve.findMacroIndexByPackageAndName;
7979
const findModelIndexByName = project_resolve.findModelIndexByName;
8080
const hasMacroPackage = project_resolve.hasMacroPackage;
81+
const packageNameFromMacroUniqueId = project_resolve.packageNameFromMacroUniqueId;
8182
const rejectDuplicateDocs = project_resolve.rejectDuplicateDocs;
8283
const rejectDuplicateExposures = project_resolve.rejectDuplicateExposures;
8384
const rejectDuplicateMacroProperties = project_resolve.rejectDuplicateMacroProperties;
@@ -1442,13 +1443,6 @@ fn sortColumns(columns: []ColumnDef) void {
14421443
}.lessThan);
14431444
}
14441445

1445-
fn packageNameFromMacroUniqueId(unique_id: []const u8) ?[]const u8 {
1446-
if (!std.mem.startsWith(u8, unique_id, "macro.")) return null;
1447-
const package_start = "macro.".len;
1448-
const package_end = std.mem.indexOfPos(u8, unique_id, package_start, ".") orelse return null;
1449-
return unique_id[package_start..package_end];
1450-
}
1451-
14521446
test "sql scanner extracts refs sources and config tags from jinja spans" {
14531447
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
14541448
defer arena.deinit();

src/project/resolve.zig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ pub fn findMacroIndexByPackageAndName(graph: *const Graph, package_name: []const
8989
return null;
9090
}
9191

92+
pub fn packageNameFromMacroUniqueId(unique_id: []const u8) ?[]const u8 {
93+
if (!std.mem.startsWith(u8, unique_id, "macro.")) return null;
94+
const package_start = "macro.".len;
95+
const package_end = std.mem.indexOfPos(u8, unique_id, package_start, ".") orelse return null;
96+
return unique_id[package_start..package_end];
97+
}
98+
9299
pub fn resolveRefDependency(graph: *const Graph, current_package: []const u8, ref_dep: RefDep) ![]const u8 {
93100
const package = ref_dep.package orelse current_package;
94101
if (try resolveRefInPackage(graph, package, ref_dep.name)) |unique_id| return unique_id;
@@ -408,6 +415,13 @@ test "unqualified macro lookup prefers current package then project package" {
408415
try std.testing.expect(!hasMacroPackage(&graph, "other"));
409416
}
410417

418+
test "macro unique id package extraction accepts only macro ids" {
419+
try std.testing.expectEqualStrings("pkg", packageNameFromMacroUniqueId("macro.pkg.some_macro").?);
420+
try std.testing.expect(packageNameFromMacroUniqueId("model.pkg.some_macro") == null);
421+
try std.testing.expect(packageNameFromMacroUniqueId("macro.") == null);
422+
try std.testing.expect(packageNameFromMacroUniqueId("macro.pkg") == null);
423+
}
424+
411425
test "ref resolution handles package refs seed refs disabled refs fallback and ambiguity" {
412426
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
413427
defer arena.deinit();

0 commit comments

Comments
 (0)