Skip to content

cli: write local policy paths with forward slashes on Windows - #3913

Open
Jayzilva wants to merge 1 commit into
wso2:mainfrom
Jayzilva:fix/cli-local-policy-path-windows
Open

Jayzilva wants to merge 1 commit into
wso2:mainfrom
Jayzilva:fix/cli-local-policy-path-windows

Conversation

@Jayzilva

Copy link
Copy Markdown

Purpose

ap gateway image build fails on Windows for any build file containing a local (filePath:) policy. CopyPolicyToWorkspace returns the workspace-relative path with filepath.Join, which is policies\<dir> on Windows, and that path is written into the build file read by the Linux gateway-builder container, so discovery fails with policy path does not exist: /workspace/policies\<dir>.

Resolves #3912

Goals

Local policies build on Windows hosts the same way they do on Linux and macOS.

Approach

  • Use path.Join instead of filepath.Join for the path returned to the build file, since it is consumed inside a Linux container and must be slash-separated on every host OS. The host-side copy (workspacePolicyDir) still uses filepath.
  • Add TestCopyPolicyToWorkspaceReturnsSlashSeparatedBuildPath.

User stories

As a policy developer on Windows, I can build a custom gateway image with my local policy using ap gateway image build.

Documentation

N/A — bug fix, no behaviour change on Linux/macOS.

Automation tests

  • Unit tests
    • New: TestCopyPolicyToWorkspaceReturnsSlashSeparatedBuildPath.
    • Verified on Windows: the test fails without the fix ("policies\\my-policy", want "policies/my-policy") and passes with it.
    • On Linux/macOS the test passes with or without the fix (filepath.Join already uses / there), so it guards only when run on a Windows runner.
    • go vet ./utils and go test ./utils pass (Linux, Go 1.26).
  • Integration tests
    • Manually: built a gateway image with a local Go policy on Windows using the patched CLI; the policy loaded in the gateway controller and ran on the policy engine.

Security checks

Samples

N/A

Related PRs

None.

Test environment

Windows 11 Pro 10.0.26100, Docker Desktop 4.87.0, Go 1.26, gateway-builder 1.2.1.

Unrelated observation while testing on Windows: TestSetupTempGatewayWorkspaceCreatesSharedTempDirectories fails there because it sets HOME, while os.UserHomeDir() reads USERPROFILE on Windows. Happy to send a separate PR if useful.

CopyPolicyToWorkspace returned the workspace-relative policy path via
filepath.Join, which yields "policies\<dir>" on Windows. The path is
written into the build file that the Linux gateway-builder container
reads, so every local (filePath) policy failed discovery on Windows hosts:

  policy path does not exist: /workspace/policies\<dir>

Use path.Join so the build-file path is slash-separated on every host OS,
and add a test pinning the returned path.
@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 9a5e1fa and 96d8298.

Files selected for processing: 2
  • cli/src/utils/policy_utils.go
  • cli/src/utils/policy_utils_test.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

CopyPolicyToWorkspace now uses path.Join to return slash-separated workspace-relative policy paths on all host operating systems. A test checks that the returned path is policies/my-policy.

Changes: Local policy path construction

Layer / File(s) Summary
Construct and verify the workspace path
cli/src/utils/policy_utils.go, cli/src/utils/policy_utils_test.go
CopyPolicyToWorkspace uses path.Join to construct the workspace-relative path. The new test expects policies/my-policy.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: renuka-fernando, krishanx92

Merge Risk: Minimal · up to 96d82

No actionable merge-blocking risk remains for the local policy path change.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title is concise and clearly identifies the Windows-specific fix: writing local policy paths with forward slashes.
Description check Passed The description covers the required sections, explains the Windows failure and fix, references issue #3912, documents unit and integration testing, records security checks, and specifies the test envi…
Linked Issues check Passed Issue #3912 requires local policy paths in the generated build file to use forward slashes on Windows. CopyPolicyToWorkspace now uses path.Join for the container-facing path and retains filepath…
Out of Scope Changes check Passed The diff changes only local policy path construction and adds its unit test. Both changes directly support issue #3912. No unrelated product behavior or files are changed.
Full details: Description check

Explanation

The description covers the required sections, explains the Windows failure and fix, references issue #3912, documents unit and integration testing, records security checks, and specifies the test environment.

Full details: Linked Issues check

Explanation

Issue #3912 requires local policy paths in the generated build file to use forward slashes on Windows. CopyPolicyToWorkspace now uses path.Join for the container-facing path and retains filepath for host-side paths. TestCopyPolicyToWorkspaceReturnsSlashSeparatedBuildPath verifies policies/my-policy.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

This branch has not been deployed

No deployments
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.

[Bug]: ap gateway image build cannot find local policies on Windows

3 participants