Follow-up corner cases for import-alias function-call resolution (#769)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 65/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Ít trao đổi
- Công nghệ
- rust
- Lĩnh vực
- compilers, testing-qa
Hướng nghiên cứu
Bắt đầu tại src/interpreter.rs quanh các dòng 1291, 1322 và 1331, sau đó kiểm tra src/languages/rego/compiler/function_calls.rs quanh dòng 223. Thêm hoặc cập nhật các trường hợp được đề xuất trong tests/interpreter/cases/import/tests.yaml và tests/rvm/rego/cases/imports.yaml, bao gồm cả trường hợp RVM bị bỏ qua. Hoàn thành khi các trường hợp biên có thể xử lý đã được sửa và các khác biệt được ghi nhận đã được cố định bằng các bài kiểm thử.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Follow-up to #769 (fixes #747). That PR resolves function calls through import aliases in the interpreter and RVM. During deep review, several corner cases were identified that are either small bugs, a known RVM limitation, or intentional OPA divergences that should be pinned by tests. Tracking them here.
Actionable bugs (interpreter with handling)
1. Default-only imported function is dropped as a with … as replacement (src/interpreter.rs:~1331)
resolve_fcn_path_through_imports accepts default-only functions, but the caller re-filters with functions.contains_key(r), dropping them.
Fix: .filter(|r| self.compiled_policy.functions.contains_key(r) || self.is_default_function(r)).
2. Default-only imported function as a with target is misclassified as a data override (src/interpreter.rs:~1291)
target_is_function only checks lookup_function_by_name + is_builtin, missing default-only functions after alias rewrite.
Fix: also consider self.is_default_function(&target).
3. with … as <alias.fn> replacement resolves a local-module function before the import alias (src/interpreter.rs:~1322)
The replacement path is looked up with the current-module prefix before the leading import alias is resolved, so a colliding local rule wins over the imported target.
Known limitation
4. RVM rejects imported default-only functions (src/languages/rego/compiler/function_calls.rs:~223)
Alias resolution gates on functions.contains_key only. Mirror the interpreter's is_default_function detection (via rule_paths + default_rules), then unskip default_function_value_via_import in tests/rvm/rego/cases/imports.yaml.
Documented divergences to pin with tests (not bugs)
5. Bracketed dotted-key import flattening — import data["a.b"] is collapsed to data.a.b by get_path_string/join("."). Pre-existing engine-wide limitation (value refs behave the same); low priority. Add a pinning test.
6. Alias whose target lacks the called member falls back to builtin/local — intentional per #769 ("the rewrite never changes the meaning of existing policies"), diverges from OPA. Add pinning tests so the behavior can't change silently.
Proposed test cases
Interpreter cases → tests/interpreter/cases/import/tests.yaml; RVM equivalents → tests/rvm/rego/cases/imports.yaml. Each want_result/want_error marks the desired outcome; comments note where current behavior differs.
# Bug #1 — default-only imported fn as `with ... as` replacement (currently undefined)
- note: with_replacement_is_default_only_imported_function
modules:
- |
package real
import rego.v1
double(x) := 2 * x
- |
package mock
import rego.v1
default repl(_) := 99
- |
package rules
import rego.v1
import data.mock
main := y if {
y := data.real.double(1) with data.real.double as mock.repl
}
query: data.rules.main
want_result: 99 # current (buggy): undefined / skip_exec
# Bug #2 — default-only imported fn as `with` target (currently a data override)
- note: with_target_is_default_only_imported_function
modules:
- |
package lib
import rego.v1
default dfl(_) := 1
dfl(x) := x if x == "a"
- |
package rules
import rego.v1
import data.lib
main := lib.dfl("a") with lib.dfl as 7
query: data.rules.main
want_result: 7 # current (buggy): override not applied
# Bug #3 — replacement alias must win over a colliding local rule head
- note: with_replacement_alias_precedes_local_function
modules:
- |
package real
import rego.v1
double(x) := 2 * x
- |
package other
import rego.v1
fake(x) := 1000 + x
- |
package rules
import rego.v1
import data.other as repl
repl.fake(x) := x # local head collides with the alias `repl`
main := y if {
y := data.real.double(5) with data.real.double as repl.fake
}
query: data.rules.main
want_result: 1005 # expected data.other.fake; current may pick local
# Limitation #4 — RVM default-only imported function (unskip after RVM fix)
# note: default_function_value_via_import # already present, skip:true in RVM suite
# -> remove `skip: true` once the RVM compiler mirrors is_default_function
# Limitation #5 — bracketed dotted key must not collapse into a nested package
- note: bracketed_key_import_not_confused_with_nested_package
modules:
- |
package a.b
import rego.v1
f(_) := "nested-package"
- |
package rules
import rego.v1
import data["a.b"] as ab
result := ab.f(1)
query: data.rules.result
# DESIRED (OPA): data["a.b"].f is undefined -> unknown function
# CURRENT: flattened to data.a.b.f -> wrongly calls the package fn
want_error: "Unknown function"
# Divergence #6 — intentional builtin fallback when alias target lacks the member (pin it)
- note: alias_missing_member_falls_back_to_builtin_intentional
modules:
- |
package lib
import rego.v1
other(_) := 1 # no `unmarshal` defined
- |
package rules
import rego.v1
import data.lib as json
result := json.unmarshal(`[1,2]`)
query: data.rules.result
want_result: [1, 2] # INTENTIONAL: builtin json.unmarshal runs (diverges from OPA)
Identified via deep code review of #769. Related: #747.
- Ngôn ngữ chính
- Rust
- Star
- 375
- Fork
- 81
- Merge trung bình
- 1 ngày 11 giờ
- Pull request đã merge (30 ngày)
- 78
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/regorus
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 80/100
Maintainer thường phản hồi trong vòng 1 ngày
-
RVM: errors and conflicts in rule bodies evaluate to undefined, even with strict builtin errorsCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
microsoft/regorus#932 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 32/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của microsoft/regorus
Issue tương tự
-
[Windows] Hidden title bar: a maximized window restored from minimized on a secondary monitor gets the primary monitor's work area as its client areaCó thể đã có người làm @lijy91 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
libnativeapi/nativeapi#53 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area:mcp enhancement large-monorepo v0.34.1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
awxkee/yuvutils-rs#149 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày