Skip to content

Fix artisan make imports to use full go module path#1422

Merged
hwbrzzl merged 3 commits into
masterfrom
copilot/fix-artisan-make-imports
Mar 26, 2026
Merged

Fix artisan make imports to use full go module path#1422
hwbrzzl merged 3 commits into
masterfrom
copilot/fix-artisan-make-imports

Conversation

Copilot AI commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

artisan make:* generation was building non-module imports from only the last segment of go.mod module path (e.g. backend/...), which breaks projects using nested/private module paths (e.g. git.site.com/path/backend/...). This change aligns generated imports with the full declared module path.

  • Import path resolution

    • Updated packages/paths.Path.Import() to use the full normalized main module path as the prefix for non-module paths.
    • Preserved existing isModule behavior: framework module paths are still returned as-is.
    • Kept empty-main fallback behavior explicit for safety.
  • Behavioral contract updates (tests)

    • Updated packages/paths/paths_test.go expectations to validate full-module imports across:
      • standard path generation (App, Config, Facades, etc.),
      • nested/complex module roots,
      • custom configured paths,
      • cross-host module patterns (e.g. gitlab.com/..., internal domains).
// before
main := "git.site.com/path/backend"
path := "app/facades"
// => "backend/app/facades"

// after
main := "git.site.com/path/backend"
path := "app/facades"
// => "git.site.com/path/backend/app/facades"
Original prompt

This section details on the original issue you should resolve

<issue_title>Artisan make: commands import incorrect project module</issue_title>
<issue_description>### Before feedback (在反馈之前)

  • I've searched the existing Issues, Discussions and Google (我已经搜索了现有的 Issues, Discussions 和 Google)
  • The problem can be stably reproduced (这个问题可以被稳定复现)
  • The problem is generated after upgrading (问题是在升级之后产生的)

Operating System (操作系统)

Linux

Golang Version (Go 版本)

1.25.8

Goravel Version (Goravel 版本)

1.17.1

Describe The Problem (描述问题)

In go.mod i've set custom module name based on git repository path, like this:

module git.site.com/path/backend

But when generating any files with make: commands, e.g:

./artisan make:migration create_test_table

I get imports like this:

package migrations

import (
	"github.com/goravel/framework/contracts/database/schema"

	"backend/app/facades"
)
....

While imported package should be git.site.com/path/backend/app/facades

From what I saw in goravel/framework sources, it is expected behavior, judging by Paths.Import() description. While I have correct r.main in there, it removes everything before first slash for some reason.
But that doesn't seem correct, at least for make: commands, since I need full module name in import.

Reproduction Code (复现代码或截图)

No response</issue_description>

Comments on the Issue (you are @copilot in this section)


⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.

Summary by CodeRabbit

  • Bug Fixes

    • Improved import path generation to use complete module paths for consistency.
  • Tests

    • Updated test expectations to align with import path behavior changes.
  • Chores

    • Updated gRPC dependency to a newer version.

Copilot AI changed the title [WIP] Fix artisan make: commands import for project module Fix artisan make imports to use full go module path Mar 25, 2026
Copilot AI requested a review from hwbrzzl March 25, 2026 10:17
@codecov

codecov Bot commented Mar 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.97%. Comparing base (de1f301) to head (9962a71).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
packages/paths/paths.go 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1422   +/-   ##
=======================================
  Coverage   67.97%   67.97%           
=======================================
  Files         354      354           
  Lines       27521    27522    +1     
=======================================
+ Hits        18708    18709    +1     
  Misses       7964     7964           
  Partials      849      849           

☔ View full report in Codecov by Sentry.
📢 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.

@hwbrzzl
hwbrzzl marked this pull request as ready for review March 26, 2026 08:07
@hwbrzzl
hwbrzzl requested a review from a team as a code owner March 26, 2026 08:07
@hwbrzzl

hwbrzzl commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Mar 26, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Mar 26, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes fix an issue where Path.Import() incorrectly shortened custom module paths to only the last component. The fix derives mainImport from the full normalized r.main path (converting backslashes to forward slashes and trimming slashes), and updates test assertions to reflect the correct full module path behavior.

Changes

Cohort / File(s) Summary
Import path normalization logic
packages/paths/paths.go
Modified (*Path).Import() to normalize the full r.main path by replacing path separators and trimming slashes, then use it directly instead of extracting the last component. Adjusted documentation to reflect full module path inclusion.
Test assertion updates
packages/paths/paths_test.go
Updated test expectations across TestImport, TestModuleImportBehavior, TestPathWithCustomConfigs, and TestPathWithDifferentMainPaths to align with full module path results (e.g., github.com/goravel/goravel/... instead of goravel/...).
Dependency version update
tests/go.mod
Incremented indirect dependency google.golang.org/grpc from v1.79.2 to v1.79.3.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Wiggles nose excitedly
The paths once lost in trimming woe,
Now the full module path will show!
From git.site.com/path/backend clear,
Custom imports finally appear! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The grpc dependency version bump in tests/go.mod from v1.79.2 to v1.79.3 is unrelated to the main objective of fixing artisan make imports to use full module paths. Remove the unrelated grpc dependency version bump from tests/go.mod or include justification if the change is intentional and necessary for this PR.
✅ 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 reflects the main change: fixing artisan make imports to use the full go module path instead of just the last segment.
Linked Issues check ✅ Passed The PR directly addresses issue #935 by updating Path.Import() to use the full normalized main module path (e.g., git.site.com/path/backend) instead of just the last segment (backend) for generated imports.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 copilot/fix-artisan-make-imports

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 and usage tips.

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

🧹 Nitpick comments (1)
packages/paths/paths_test.go (1)

444-450: Consider adding a test case for Windows-style main path.

The implementation at Line 131 in paths.go handles backslashes in r.main, but there's no corresponding test case. While module paths from go.mod are unlikely to contain backslashes, adding a test would ensure this edge case is covered.

🧪 Optional test case to add
 		{
 			name:     "with windows-style path",
 			path:     "app\\http\\controllers",
 			main:     "github.com/goravel/goravel",
 			isModule: false,
 			expected: "github.com/goravel/goravel/app/http/controllers",
 		},
+		{
+			name:     "with windows-style main path",
+			path:     "app/http/controllers",
+			main:     "github.com\\goravel\\goravel",
+			isModule: false,
+			expected: "github.com/goravel/goravel/app/http/controllers",
+		},
 		{
 			name:     "with complex main path",
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/paths/paths_test.go` around lines 444 - 450, Add a unit test row to
the existing table in packages/paths/paths_test.go that covers a Windows-style
main containing backslashes so we verify the code path that normalizes
backslashes in r.main (the logic introduced in paths.go that replaces
backslashes). Create a test case similar to the existing "with windows-style
path" entry but set main to a backslash-containing value (e.g.,
"github\\com\\goravel\\goravel") and assert expected uses forward-slashes (e.g.,
"github.com/goravel/goravel/app/http/controllers"); keep the same fields (name,
path, main, isModule, expected) so the table-driven test picks it up.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/paths/paths_test.go`:
- Around line 444-450: Add a unit test row to the existing table in
packages/paths/paths_test.go that covers a Windows-style main containing
backslashes so we verify the code path that normalizes backslashes in r.main
(the logic introduced in paths.go that replaces backslashes). Create a test case
similar to the existing "with windows-style path" entry but set main to a
backslash-containing value (e.g., "github\\com\\goravel\\goravel") and assert
expected uses forward-slashes (e.g.,
"github.com/goravel/goravel/app/http/controllers"); keep the same fields (name,
path, main, isModule, expected) so the table-driven test picks it up.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 615bf801-9f0c-424c-ac57-d25e93d8d6ad

📥 Commits

Reviewing files that changed from the base of the PR and between de1f301 and 9962a71.

⛔ Files ignored due to path filters (1)
  • tests/go.sum is excluded by !**/*.sum
📒 Files selected for processing (3)
  • packages/paths/paths.go
  • packages/paths/paths_test.go
  • tests/go.mod

@hwbrzzl
hwbrzzl merged commit 3d30cb7 into master Mar 26, 2026
15 of 17 checks passed
@hwbrzzl
hwbrzzl deleted the copilot/fix-artisan-make-imports branch March 26, 2026 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Artisan make: commands import incorrect project module

2 participants