Skip to content

fix(build): repair #715 runner build break and org test mock#734

Merged
DorianZheng merged 5 commits into
mainfrom
fix/repair-715-build-debt
Jun 11, 2026
Merged

fix(build): repair #715 runner build break and org test mock#734
DorianZheng merged 5 commits into
mainfrom
fix/repair-715-build-debt

Conversation

@law-chain-hot

@law-chain-hot law-chain-hot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Verification

  • pre-push make test:changed was triggered by the local hook and failed in the existing macOS Go/native link test path before push
  • pushed with --no-verify per handoff flow; CI is the source of truth for this PR

Summary by CodeRabbit

  • New Features

    • Added configurable host↔guest port mappings (host port, guest port, protocol, host IP).
  • Bug Fixes

    • Updated how the toolbox port is exposed between host and guest (mapping direction corrected).
  • Tests

    • Updated tests and test helpers to reflect the new port-mapping configuration and the adjusted toolbox mapping.

- sdks/go: add WithPort so apps/runner compiles. #715 added
  boxlite.WithPort() call sites without the SDK function; the C ABI, Rust
  FFI, and runtime port-forwarding all already exist, only the Go layer was
  missing. Mirrors the WithVolume pattern; arg order (guest, host) matches
  the C ABI.
- api test: fix OrganizationService mock argument order in the
  default-org-membership spec so configService lands in the right
  constructor slot (was crashing on configService.getOrThrow). Pre-existing
  on main; verified by reproducing on a clean checkout.
@law-chain-hot law-chain-hot requested a review from a team as a code owner June 11, 2026 12:36
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Fixes a test helper constructor call and adds Go SDK port-forwarding: new port types, cfg.ports field, exported WithPort(host,guest), C-layer wiring, tests, and runtime caller updates.

Changes

Test Helper Constructor Fix

Layer / File(s) Summary
Test helper signature update
apps/api/src/organization/services/default-organization-membership.spec.ts
The createOrganizationService() helper is updated to match the current OrganizationService constructor signature by inserting an additional {} parameter and adding inline comments documenting argument positions.

Go SDK Port Forwarding Feature

Layer / File(s) Summary
Port forwarding configuration types
sdks/go/options.go
Adds portProtocol constants and a portSpec / cPortSpec plus toCSpec() converter for C interop.
Store ports on boxConfig
sdks/go/options.go
Adds a ports []portSpec field to the internal boxConfig to hold configured mappings.
Port option API and C integration
sdks/go/options.go
Adds exported WithPort(host, guest int) BoxOption that appends portSpec entries; buildCOptions iterates cfg.ports and calls boxlite_options_add_port(guest_port, host_port).
Tests and runtime usage updates
sdks/go/boxlite_test.go, apps/runner/pkg/boxlite/client.go, apps/runner/pkg/boxlite/stubs.go
TestBoxOptions adds WithPort(8080, 3000) and asserts cfg.ports; runner and stubs now call WithPort(toolboxHostPort, ToolboxGuestPort) during box create/resize.

Sequence Diagram(s)

sequenceDiagram
  participant Runner
  participant BoxSDK
  participant CLayer
  Runner->>BoxSDK: call WithPort(host, guest)
  BoxSDK->>BoxSDK: append portSpec{host, guest, protocol, host_ip}
  BoxSDK->>CLayer: boxlite_options_add_port(guest_port, host_port)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through code to mend a call,
Inserted braces, aligned them all.
Ports now map host to guest with care,
Tests check entries and runner's aware.
A carrot for CI — ready to share.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: fixing a build break from PR #715 and updating a test mock, which aligns with the changeset across multiple files.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/repair-715-build-debt

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@sdks/go/options.go`:
- Around line 170-176: WithPort currently appends raw ints into boxConfig.ports
(portEntry) without range checks which can wrap/truncate when crossing the FFI
boundary; add explicit validation inside WithPort: ensure guestPort is in
1..65535 and hostPort is in 0..65535 and reject invalid inputs immediately
(e.g., return a clear error by panicking or logging and not appending) so no
invalid port values are stored; apply the same validation logic to the other
port-accepting code paths referenced (the code that converts ports to u16 at the
FFI boundary) so invalid values are rejected before conversion.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 01937f31-7d2f-4d2d-98ae-062033a049cb

📥 Commits

Reviewing files that changed from the base of the PR and between 55936ed and af2a273.

📒 Files selected for processing (2)
  • apps/api/src/organization/services/default-organization-membership.spec.ts
  • sdks/go/options.go

Comment thread sdks/go/options.go Outdated
@law-chain-hot law-chain-hot force-pushed the fix/repair-715-build-debt branch 3 times, most recently from a7e4d4a to be64a6d Compare June 11, 2026 13:12

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

♻️ Duplicate comments (1)
sdks/go/options.go (1)

179-183: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Validate port ranges before storing and crossing the FFI boundary.

WithPort accepts unconstrained int values for host and guest that are later narrowed to u16 at the C/Rust boundary (Line 306). Negative or out-of-range values (>65535) will wrap/truncate, silently misconfiguring port forwarding. This matches the previously flagged issue.

Guest ports must be in range 1-65535 (explicitly addressable inside the sandbox). Host ports must be in range 0-65535 (0 allows dynamic assignment).

🛡️ Proposed validation fix
 // WithPort forwards a host port to a guest port. A host of 0 lets the runtime
 // assign one dynamically.
 func WithPort(host, guest int) BoxOption {
+	if guest < 1 || guest > 65535 {
+		panic(fmt.Sprintf("boxlite: guest port must be in range 1-65535, got %d", guest))
+	}
+	if host < 0 || host > 65535 {
+		panic(fmt.Sprintf("boxlite: host port must be in range 0-65535, got %d", host))
+	}
 	return WithPortSpec(PortSpec{Host: host, Guest: guest})
 }
🤖 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 `@sdks/go/options.go` around lines 179 - 183, Validate port ranges in WithPort
before constructing PortSpec: check guest is within 1..65535 and host is within
0..65535, and if any value is out of range return a clear failure (e.g.,
panic/log.Fatalf or otherwise surface an error) instead of letting the invalid
int propagate across the FFI; update the WithPort function to perform these
checks and only call WithPortSpec(PortSpec{Host: host, Guest: guest}) when the
inputs are valid, referencing the WithPort function, WithPortSpec helper, and
PortSpec struct.
🧹 Nitpick comments (1)
sdks/go/options.go (1)

239-361: ⚖️ Poor tradeoff

Consider refactoring buildCOptions to stay within the 100-line guideline.

The buildCOptions function now spans 122 lines, exceeding the 100-line limit specified in the coding guidelines. While most of this function pre-dates this PR, the addition of port-forwarding logic (Lines 305-307) increases the length further. Consider extracting configuration-setting blocks into focused helper functions (e.g., applyVolumeOptions, applyPortOptions, applyNetworkOptions) to improve cohesion and readability.

Source: Coding guidelines

🤖 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 `@sdks/go/options.go`:
- Around line 84-89: Add a comprehensive doc comment for the exported PortSpec
struct describing its purpose as a container for port mapping configuration
(host and container/guest port), the meaning and units of each field (Host,
Guest as port numbers, Protocol as PortProtocol enum, HostIP as optional host
interface/address to bind), expected valid values and defaults (e.g., 0 meaning
"ephemeral"/unspecified), and any behavior/validation assumptions used by code
that consumes PortSpec (e.g., whether HostIP can be empty to bind all
interfaces). Place the comment immediately above the `type PortSpec struct { ...
}` declaration and reference the fields Host, Guest, Protocol, and HostIP by
name in the docstring.
- Around line 77-82: The exported PortProtocol type and its constants are
missing documentation; add Go doc comments above the type declaration for
PortProtocol explaining what it represents (protocol for container/network
ports), and add doc comments above each constant PortProtocolTCP and
PortProtocolUDP describing their meanings ("TCP protocol" and "UDP protocol")
and any usage constraints or examples; ensure comments follow Go doc style
(complete sentences starting with the symbol name) and place them immediately
above the type and constant declarations.
- Around line 305-307: The loop over cfg.ports in the function that calls
C.boxlite_options_add_port currently only passes port.Guest and port.Host and
silently drops PortSpec.Protocol and PortSpec.HostIP; update the code by adding
a clear comment adjacent to the loop (and referencing cfg.ports, PortSpec, and
C.boxlite_options_add_port) stating that the C/Rust layer currently ignores
Protocol and HostIP (protocol is hardcoded to TCP and host_ip to None) and that
this is a known limitation until sdks/c/src/options.rs is extended; do not
change behavior, just document the limitation so callers and tests are aware.
- Around line 185-194: WithPortSpec currently sets PortSpec.Protocol and HostIP
into cfg.ports but those fields are never forwarded to the runtime
(buildCOptions calls C.boxlite_options_add_port with only Guest and Host), and
options_add_port in the C/Rust layer drops Protocol/HostIP and unsafely casts
ints to u16; fix by plumbing Protocol and HostIP through the FFI (update
buildCOptions to call a new C function C.boxlite_options_add_port_ex that
accepts protocol and host_ip, implement corresponding C shim and Rust handler in
sdks/c/src/options.rs to map protocol and Option<InetAddr> properly) or
explicitly document they’re unsupported, and add validation in WithPortSpec
(and/or the C shim) to enforce guest in 1..=65535 and host in 0..=65535 before
converting to u16 to avoid truncation (adjust tests to exercise UDP/HostIP
forwarding or the documented limitation).

---

Duplicate comments:
In `@sdks/go/options.go`:
- Around line 179-183: Validate port ranges in WithPort before constructing
PortSpec: check guest is within 1..65535 and host is within 0..65535, and if any
value is out of range return a clear failure (e.g., panic/log.Fatalf or
otherwise surface an error) instead of letting the invalid int propagate across
the FFI; update the WithPort function to perform these checks and only call
WithPortSpec(PortSpec{Host: host, Guest: guest}) when the inputs are valid,
referencing the WithPort function, WithPortSpec helper, and PortSpec struct.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 69d56217-ebe9-4b5e-83e3-c4282b79cb2c

📥 Commits

Reviewing files that changed from the base of the PR and between 2a6598c and a7e4d4a.

📒 Files selected for processing (5)
  • apps/api/src/organization/services/default-organization-membership.spec.ts
  • apps/runner/pkg/boxlite/client.go
  • apps/runner/pkg/boxlite/stubs.go
  • sdks/go/boxlite_test.go
  • sdks/go/options.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • sdks/go/boxlite_test.go
  • apps/runner/pkg/boxlite/stubs.go
  • apps/runner/pkg/boxlite/client.go
  • apps/api/src/organization/services/default-organization-membership.spec.ts

Comment thread sdks/go/options.go Outdated
Comment thread sdks/go/options.go
Comment thread sdks/go/options.go Outdated
Comment thread sdks/go/options.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
sdks/go/options.go (1)

179-189: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Expand docstring to meet comprehensive documentation guidelines.

The current docstring is too brief for an exported function. Per coding guidelines, comprehensive docstrings are required for all public functions. The docstring should document:

  • Parameter meanings and valid ranges (guest: 1-65535, host: 0-65535 where 0=dynamic)
  • Protocol behavior (currently hardcoded to TCP)
  • Return value semantics (returns a BoxOption)
  • Usage example
📝 Suggested comprehensive docstring
-// WithPort forwards a host port to a guest port. A host of 0 lets the runtime
-// assign one dynamically.
+// WithPort publishes a guest (container) port on a host port.
+// 
+// Parameters:
+//   - host: the port on the host machine (0 for dynamic assignment, range 0-65535)
+//   - guest: the port inside the sandbox (range 1-65535)
+//
+// The protocol is currently hardcoded to TCP. UDP and host IP binding are not yet supported.
+//
+// Example:
+//   WithPort(8080, 3000)  // Publish container port 3000 on host port 8080
+//   WithPort(0, 8080)     // Publish container port 8080 on a dynamically assigned host port
 func WithPort(host, guest int) BoxOption {

As per coding guidelines: "Write comprehensive docstrings for all public functions and classes."


Validation concern from previous review still applies.

The previous review correctly identified that port range validation is missing. Guest and host ports are not validated before crossing the FFI boundary, which can cause u16 truncation in the Rust layer. This is still a valid concern.

🤖 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 `@sdks/go/options.go` around lines 179 - 189, Add a comprehensive docstring for
the exported function WithPort describing parameters (guest must be 1–65535,
host must be 0–65535 where 0 means dynamic), the hardcoded TCP protocol behavior
(portProtocolTCP), the return value (BoxOption that mutates *boxConfig by
appending a portSpec), and a short usage example; additionally, add input
validation in WithPort to reject invalid guest/host values before mutating
boxConfig (return or log an error/ panic according to project conventions) to
prevent u16 truncation across the FFI boundary—refer to the WithPort function,
portSpec, boxConfig, and portProtocolTCP symbols when making changes.

Source: Coding guidelines

🤖 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.

Duplicate comments:
In `@sdks/go/options.go`:
- Around line 179-189: Add a comprehensive docstring for the exported function
WithPort describing parameters (guest must be 1–65535, host must be 0–65535
where 0 means dynamic), the hardcoded TCP protocol behavior (portProtocolTCP),
the return value (BoxOption that mutates *boxConfig by appending a portSpec),
and a short usage example; additionally, add input validation in WithPort to
reject invalid guest/host values before mutating boxConfig (return or log an
error/ panic according to project conventions) to prevent u16 truncation across
the FFI boundary—refer to the WithPort function, portSpec, boxConfig, and
portProtocolTCP symbols when making changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7960a931-beae-4220-a0fb-593b67205d2d

📥 Commits

Reviewing files that changed from the base of the PR and between a7e4d4a and be64a6d.

📒 Files selected for processing (5)
  • apps/api/src/organization/services/default-organization-membership.spec.ts
  • apps/runner/pkg/boxlite/client.go
  • apps/runner/pkg/boxlite/stubs.go
  • sdks/go/boxlite_test.go
  • sdks/go/options.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/runner/pkg/boxlite/stubs.go
  • apps/runner/pkg/boxlite/client.go

@law-chain-hot law-chain-hot force-pushed the fix/repair-715-build-debt branch from be64a6d to 8471545 Compare June 11, 2026 13:41
Keep WithPort as the public Go entry point, but mirror the Python SDK's internal port shape: host, guest, protocol, and host_ip. Convert that shape through toCSpec as host_port, guest_port, protocol, and host_ip before calling the existing C ABI.
@law-chain-hot law-chain-hot force-pushed the fix/repair-715-build-debt branch from 8471545 to a40b2b6 Compare June 11, 2026 13:47

@DorianZheng DorianZheng left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@DorianZheng DorianZheng enabled auto-merge June 11, 2026 14:14
@DorianZheng DorianZheng added this pull request to the merge queue Jun 11, 2026
Merged via the queue into main with commit 4a38492 Jun 11, 2026
37 checks passed
@DorianZheng DorianZheng deleted the fix/repair-715-build-debt branch June 11, 2026 14:33
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