Skip to content

feat: improve builder#165

Open
ascandone wants to merge 2 commits into
mainfrom
feat/improve-builder
Open

feat: improve builder#165
ascandone wants to merge 2 commits into
mainfrom
feat/improve-builder

Conversation

@ascandone

Copy link
Copy Markdown
Contributor

No description provided.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds BuildProgramWithFeatureFlags to builder/builder.go: a helper checkIsFlagValid enforces that flag strings contain only lowercase letters and -, and the exported function prepends a #![feature(...)] header to the BuildProgram output. A new test TestSimpleSendWithFlag validates the generated script with two feature flags.

Changes

Feature Flag Builder

Layer / File(s) Summary
Flag validation and BuildProgramWithFeatureFlags implementation
builder/builder.go
Removes a stale TODO comment. Adds checkIsFlagValid (returns false for empty or non-[a-z-] strings) and exported BuildProgramWithFeatureFlags, which panics on invalid flags, formats the comma-separated feature list, and prepends #![feature(...)] to the script returned by BuildProgram.
TestSimpleSendWithFlag test
builder/builder_test.go
Adds a test that builds a StmtSend via BuildProgramWithFeatureFlags with my-flag and another-flag, and asserts the output script against an inline snapshot containing the feature header and expected vars/send body.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • paul-nicolas
  • Azorlogh

Poem

🐇 Hippity-hop, a flag goes in,
With lowercase letters and dashes within.
#![feature] sits atop the script,
Invalid names get promptly clipped!
The rabbit stamps the snapshot — approved! ✅

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (1 warning, 2 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'feat: improve builder' is vague and generic; it uses a non-descriptive term ('improve') that doesn't clearly convey what specifically was changed or added to the builder. Provide a more specific title that clearly describes the main feature added, such as 'feat: add feature flag support to program builder'.
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to assess whether it relates to the changeset. Add a description that explains the purpose of the new BuildProgramWithFeatureFlags function and how feature flags are validated and applied.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/improve-builder

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ascandone ascandone requested a review from paul-nicolas June 23, 2026 15:08
@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.42857% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.49%. Comparing base (9ca635b) to head (08b4640).

Files with missing lines Patch % Lines
builder/builder.go 71.42% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #165      +/-   ##
==========================================
- Coverage   68.52%   68.49%   -0.03%     
==========================================
  Files          56       56              
  Lines        5417     5438      +21     
==========================================
+ Hits         3712     3725      +13     
- Misses       1494     1498       +4     
- Partials      211      215       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@NumaryBot NumaryBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approve — automated review

The new builder API emits syntactically valid feature declarations and preserves existing BuildProgram behavior. I did not find any discrete regressions introduced by the patch.

No findings.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
builder/builder_test.go (1)

53-68: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a dedicated test for invalid-flag panic behavior.

This PR introduces a strict panic contract for invalid flags, but current coverage only asserts the happy path. Add a focused test to lock panic behavior and prevent silent contract drift.

Example test addition
+func TestBuildProgramWithFeatureFlagsInvalidFlagPanics(t *testing.T) {
+	stmt := builder.StmtSend(
+		builder.ExprMonetary(
+			builder.ExprAsset("USD/2"),
+			builder.ExprNumberBigInt(big.NewInt(1)),
+		),
+		builder.SrcAccount(builder.ExprAccount("src")),
+		builder.DestAccount(builder.ExprAccount("dest")),
+	)
+
+	defer func() {
+		if recover() == nil {
+			t.Fatalf("expected panic for invalid feature flag")
+		}
+	}()
+
+	builder.BuildProgramWithFeatureFlags([]string{"Invalid-Flag"}, stmt)
+}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@builder/builder_test.go` around lines 53 - 68, The current test coverage only
validates the happy path where valid feature flags are passed to the
BuildProgramWithFeatureFlags function. Add a new test function that specifically
tests the panic behavior when an invalid or unsupported flag is provided to
BuildProgramWithFeatureFlags. The test should verify that the function panics
with an appropriate error message when given an invalid flag, ensuring the
strict panic contract is properly covered and preventing regression of the panic
behavior contract.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@builder/builder.go`:
- Around line 175-189: The BuildProgramWithFeatureFlags function validates
featureFlags after calling BuildProgram on the statements, which allows side
effects from BuildProgram to execute even when invalid flags would cause a
panic. Move the flag validation loop that calls checkIsFlagValid before the call
to BuildProgram to ensure invalid flags are caught immediately and prevent any
statement execution or side effects from occurring before the panic.

---

Nitpick comments:
In `@builder/builder_test.go`:
- Around line 53-68: The current test coverage only validates the happy path
where valid feature flags are passed to the BuildProgramWithFeatureFlags
function. Add a new test function that specifically tests the panic behavior
when an invalid or unsupported flag is provided to BuildProgramWithFeatureFlags.
The test should verify that the function panics with an appropriate error
message when given an invalid flag, ensuring the strict panic contract is
properly covered and preventing regression of the panic behavior contract.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0137bf64-5872-438a-8436-36decab91be4

📥 Commits

Reviewing files that changed from the base of the PR and between 9ca635b and 08b4640.

📒 Files selected for processing (2)
  • builder/builder.go
  • builder/builder_test.go

Comment thread builder/builder.go
Comment on lines +175 to +189
func BuildProgramWithFeatureFlags(
featureFlags []string,
statements ...Statement,
) (map[string]string, VarsEnv, string) {
knownBindings, varsEnv, script := BuildProgram(statements...)

var flagsArgs strings.Builder
for index, flag := range featureFlags {
if !checkIsFlagValid(flag) {
// Yes, we are panicking instead of returning an error here.
// That's desidered: flags are meant to be passed manually. Not computed, created conditionally, etc.
// If a feature flag is wrong we want to crash the thing immediately instead of having the user handle that, log that, or whatever.
panic(fmt.Sprintf("Invalid argument: the `%s` feature flag is invalid. Only flags matching `^[a-z-]+$` are accepted.", flag))
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Validate flags before building the script to preserve fail-fast behavior.

Line 179 builds statements before validating featureFlags. Since Statement is executable code, callers can trigger side effects/panics even when flags are invalid, which contradicts the “panic right away” contract documented in Lines 172-173.

Suggested fix
 func BuildProgramWithFeatureFlags(
 	featureFlags []string,
 	statements ...Statement,
 ) (map[string]string, VarsEnv, string) {
-	knownBindings, varsEnv, script := BuildProgram(statements...)
-
 	var flagsArgs strings.Builder
 	for index, flag := range featureFlags {
 		if !checkIsFlagValid(flag) {
 			panic(fmt.Sprintf("Invalid argument: the `%s` feature flag is invalid. Only flags matching `^[a-z-]+$` are accepted.", flag))
 		}
@@
 		flagsArgs.WriteString(flag)
 		flagsArgs.WriteByte('"')
 	}
 
+	knownBindings, varsEnv, script := BuildProgram(statements...)
 	updatedScript := fmt.Sprintf("#![feature(%s)]\n%s", flagsArgs.String(), script)
 	return knownBindings, varsEnv, updatedScript
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func BuildProgramWithFeatureFlags(
featureFlags []string,
statements ...Statement,
) (map[string]string, VarsEnv, string) {
knownBindings, varsEnv, script := BuildProgram(statements...)
var flagsArgs strings.Builder
for index, flag := range featureFlags {
if !checkIsFlagValid(flag) {
// Yes, we are panicking instead of returning an error here.
// That's desidered: flags are meant to be passed manually. Not computed, created conditionally, etc.
// If a feature flag is wrong we want to crash the thing immediately instead of having the user handle that, log that, or whatever.
panic(fmt.Sprintf("Invalid argument: the `%s` feature flag is invalid. Only flags matching `^[a-z-]+$` are accepted.", flag))
}
func BuildProgramWithFeatureFlags(
featureFlags []string,
statements ...Statement,
) (map[string]string, VarsEnv, string) {
var flagsArgs strings.Builder
for index, flag := range featureFlags {
if !checkIsFlagValid(flag) {
// Yes, we are panicking instead of returning an error here.
// That's desidered: flags are meant to be passed manually. Not computed, created conditionally, etc.
// If a feature flag is wrong we want to crash the thing immediately instead of having the user handle that, log that, or whatever.
panic(fmt.Sprintf("Invalid argument: the `%s` feature flag is invalid. Only flags matching `^[a-z-]+$` are accepted.", flag))
}
flagsArgs.WriteString(flag)
flagsArgs.WriteByte('"')
}
knownBindings, varsEnv, script := BuildProgram(statements...)
updatedScript := fmt.Sprintf("#![feature(%s)]\n%s", flagsArgs.String(), script)
return knownBindings, varsEnv, updatedScript
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@builder/builder.go` around lines 175 - 189, The BuildProgramWithFeatureFlags
function validates featureFlags after calling BuildProgram on the statements,
which allows side effects from BuildProgram to execute even when invalid flags
would cause a panic. Move the flag validation loop that calls checkIsFlagValid
before the call to BuildProgram to ensure invalid flags are caught immediately
and prevent any statement execution or side effects from occurring before the
panic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants