Skip to content

Fix cmd tests by mocking builtin paths#37369

Merged
wxiaoguang merged 6 commits intogo-gitea:mainfrom
peyremorgan:fix/install-lock-cmd-tests
Apr 22, 2026
Merged

Fix cmd tests by mocking builtin paths#37369
wxiaoguang merged 6 commits intogo-gitea:mainfrom
peyremorgan:fix/install-lock-cmd-tests

Conversation

@peyremorgan
Copy link
Copy Markdown
Contributor

@peyremorgan peyremorgan commented Apr 22, 2026

After 07ada36, PrepareConsoleLoggerLevel can fail in tests when InstallLock is true, due to the incorrect config file is loaded. This PR fixes cmd test setup by mocking builtin paths

Fixes #37368

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 22, 2026
After 07ada36, PrepareConsoleLoggerLevel can fail in tests when InstallLock is true.
This commit fixes cmd test setup by forcing InstallLock=false in shared test execution paths.

Changes:
- cmd/main_test.go: set InstallLock=false in runTestApp and remove redundant per-subtest InstallLock mock in TestCliCmd.
- cmd/config_test.go: set InstallLock=false in TestConfigEdit and add required imports.

Co-Authored-By: GitHub Copilot <copilot@github.com> (GPT-5.3-Codex)
@peyremorgan peyremorgan force-pushed the fix/install-lock-cmd-tests branch from 63c7fec to 95479fc Compare April 22, 2026 16:52
@wxiaoguang
Copy link
Copy Markdown
Contributor

Thank you very much, I will add some comments

@peyremorgan
Copy link
Copy Markdown
Contributor Author

Sharing diagnostic logs. Adding this to setting.go
image

Then running TAGS="bindata sqlite sqlite_unlock_notify" GO_TEST_PACKAGES=./cmd make clean deps build test on df8aa2f produces the attached test.log

@wxiaoguang
Copy link
Copy Markdown
Contributor

I think I found the root problem now.

This one can be a complete fix: 94dea67

@peyremorgan
Copy link
Copy Markdown
Contributor Author

Great! 😀

@wxiaoguang
Copy link
Copy Markdown
Contributor

I reverted some test.MockVariableValue(&setting.InstallLock, false) related changes in 7399490, does it still pass on your side? If yes, then I think the root problem is fixed. If no .... let's revert the revert

@peyremorgan
Copy link
Copy Markdown
Contributor Author

peyremorgan commented Apr 22, 2026

testing now on 7399490

Copy link
Copy Markdown
Contributor

@wxiaoguang wxiaoguang left a comment

Choose a reason for hiding this comment

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

CI passes, vote my approval ahead.

(even if we would need to take some test.MockVariableValue(&setting.InstallLock, false back, it doesn't really block)

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Apr 22, 2026
@peyremorgan
Copy link
Copy Markdown
Contributor Author

Reset the devcontainer, unfortunately it seems that the tests fail on 7399490 😕
Still working on 95479fc

Here's the failed run: test-739949.log

@wxiaoguang
Copy link
Copy Markdown
Contributor

So weird. No more idea at the moment.

I took the InstallLock=false back and added some TODO comments ee8dbdc

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 22, 2026
@lunny lunny added the type/bug label Apr 22, 2026
@wxiaoguang wxiaoguang marked this pull request as draft April 22, 2026 19:32
@wxiaoguang
Copy link
Copy Markdown
Contributor

wxiaoguang commented Apr 22, 2026

Another fix. I think I am 99% sure the bug is fixed.

The root problem is still related to that the incorrect "app.ini" is loaded. Especially when you have an installed instance in your working directory (that's what your log shows: Please fix it. CustomConf=/workspaces/gitea/custom/conf/app.ini)

To reproduce it, this command is enough (and very fast, it only takes a few seconds):

GOTESTFLAGS="-v" GO_TEST_PACKAGES="code.gitea.io/gitea/cmd" TAGS="bindata sqlite sqlite_unlock_notify" make test-backend
  • On main branch: it fails as your log
  • After the latest commit 610fee9: succeed!

@wxiaoguang wxiaoguang marked this pull request as ready for review April 22, 2026 20:05
@peyremorgan
Copy link
Copy Markdown
Contributor Author

Trying that right now!

@peyremorgan
Copy link
Copy Markdown
Contributor Author

Can confirm test-backend in a devcontainer fails on main and passes on 610fee9 🎉

image

@wxiaoguang wxiaoguang changed the title Fix cmd tests by centralizing InstallLock mock Fix cmd tests by mocking builtin paths Apr 22, 2026
@wxiaoguang wxiaoguang enabled auto-merge (squash) April 22, 2026 20:34
@wxiaoguang wxiaoguang added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Apr 22, 2026
@lunny lunny added this to the 1.27.0 milestone Apr 22, 2026
@wxiaoguang wxiaoguang merged commit 8cfcef3 into go-gitea:main Apr 22, 2026
26 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Apr 22, 2026
zjjhot added a commit to zjjhot/gitea that referenced this pull request Apr 23, 2026
* main:
  fix: commit status reporting (go-gitea#37372)
  Support for Custom URI Schemes in OAuth2 Redirect URIs (go-gitea#37356)
  Fix cmd tests by mocking builtin paths (go-gitea#37369)
  chore: upgrade Go version in devcontainer image to 1.26 (go-gitea#37374)
  Fix button layout shift when collapsing file tree in editor (go-gitea#37363)
  Update `Block a user` form (go-gitea#37359)
  Remove IsValidExternalURL/IsAPIURL and use IsValidURL at call sites (go-gitea#37364)
silverwind added a commit to silverwind/gitea that referenced this pull request Apr 23, 2026
* origin/main: (32 commits)
  fix: commit status reporting (go-gitea#37372)
  Support for Custom URI Schemes in OAuth2 Redirect URIs (go-gitea#37356)
  Fix cmd tests by mocking builtin paths (go-gitea#37369)
  chore: upgrade Go version in devcontainer image to 1.26 (go-gitea#37374)
  Fix button layout shift when collapsing file tree in editor (go-gitea#37363)
  Update `Block a user` form (go-gitea#37359)
  Remove IsValidExternalURL/IsAPIURL and use IsValidURL at call sites (go-gitea#37364)
  Add URL to `Learn more about blocking a user` (go-gitea#37355)
  fix: use TriggerEvent instead of Event in workflow runs API response for scheduled runs (go-gitea#37288)
  Add event.schedule context for schedule actions task (go-gitea#37320)
  Fix typos (go-gitea#37346)
  Fix an issue where changing an organization’s visibility caused problems when users had forked its repositories. (go-gitea#37324)
  Fail vite build on rolldown warnings via NODE_ENV=test (go-gitea#37270)
  Use modern "git update-index --cacheinfo" syntax to support more file names (go-gitea#37338)
  Fix URL related escaping for oauth2 (go-gitea#37334)
  When the requested arch rpm is missing fall back to noarch (go-gitea#37236)
  Fix `relative-time` error and improve global error handler (go-gitea#37241)
  Enhance styling in actions page (go-gitea#37323)
  fix(oauth): Error on auth sources with spaces (go-gitea#37327)
  Fix actions concurrency groups cross-branch leak (go-gitea#37311)
  ...

# Conflicts:
#	services/actions/commit_status.go
silverwind added a commit to silverwind/gitea that referenced this pull request Apr 23, 2026
* origin/main: (204 commits)
  fix: commit status reporting (go-gitea#37372)
  Support for Custom URI Schemes in OAuth2 Redirect URIs (go-gitea#37356)
  Fix cmd tests by mocking builtin paths (go-gitea#37369)
  chore: upgrade Go version in devcontainer image to 1.26 (go-gitea#37374)
  Fix button layout shift when collapsing file tree in editor (go-gitea#37363)
  Update `Block a user` form (go-gitea#37359)
  Remove IsValidExternalURL/IsAPIURL and use IsValidURL at call sites (go-gitea#37364)
  Add URL to `Learn more about blocking a user` (go-gitea#37355)
  fix: use TriggerEvent instead of Event in workflow runs API response for scheduled runs (go-gitea#37288)
  Add event.schedule context for schedule actions task (go-gitea#37320)
  Fix typos (go-gitea#37346)
  Fix an issue where changing an organization’s visibility caused problems when users had forked its repositories. (go-gitea#37324)
  Fail vite build on rolldown warnings via NODE_ENV=test (go-gitea#37270)
  Use modern "git update-index --cacheinfo" syntax to support more file names (go-gitea#37338)
  Fix URL related escaping for oauth2 (go-gitea#37334)
  When the requested arch rpm is missing fall back to noarch (go-gitea#37236)
  Fix `relative-time` error and improve global error handler (go-gitea#37241)
  Enhance styling in actions page (go-gitea#37323)
  fix(oauth): Error on auth sources with spaces (go-gitea#37327)
  Fix actions concurrency groups cross-branch leak (go-gitea#37311)
  ...

# Conflicts:
#	web_src/js/index-domready.ts
#	web_src/js/markup/content.ts
#	web_src/js/markup/refissue.ts
silverwind added a commit to silverwind/gitea that referenced this pull request Apr 23, 2026
* origin/main: (204 commits)
  fix: commit status reporting (go-gitea#37372)
  Support for Custom URI Schemes in OAuth2 Redirect URIs (go-gitea#37356)
  Fix cmd tests by mocking builtin paths (go-gitea#37369)
  chore: upgrade Go version in devcontainer image to 1.26 (go-gitea#37374)
  Fix button layout shift when collapsing file tree in editor (go-gitea#37363)
  Update `Block a user` form (go-gitea#37359)
  Remove IsValidExternalURL/IsAPIURL and use IsValidURL at call sites (go-gitea#37364)
  Add URL to `Learn more about blocking a user` (go-gitea#37355)
  fix: use TriggerEvent instead of Event in workflow runs API response for scheduled runs (go-gitea#37288)
  Add event.schedule context for schedule actions task (go-gitea#37320)
  Fix typos (go-gitea#37346)
  Fix an issue where changing an organization’s visibility caused problems when users had forked its repositories. (go-gitea#37324)
  Fail vite build on rolldown warnings via NODE_ENV=test (go-gitea#37270)
  Use modern "git update-index --cacheinfo" syntax to support more file names (go-gitea#37338)
  Fix URL related escaping for oauth2 (go-gitea#37334)
  When the requested arch rpm is missing fall back to noarch (go-gitea#37236)
  Fix `relative-time` error and improve global error handler (go-gitea#37241)
  Enhance styling in actions page (go-gitea#37323)
  fix(oauth): Error on auth sources with spaces (go-gitea#37327)
  Fix actions concurrency groups cross-branch leak (go-gitea#37311)
  ...

Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>

# Conflicts:
#	web_src/js/index-domready.ts
#	web_src/js/markup/content.ts
#	web_src/js/markup/refissue.ts
silverwind added a commit to mohammad-rj/gitea that referenced this pull request Apr 24, 2026
* origin/main: (127 commits)
  Refactor pull request view (1) (go-gitea#37380)
  Improve AGENTS.md (go-gitea#37382)
  Remove dead CSS (go-gitea#37376)
  Add pr-review e2e test and speed up e2e tests (go-gitea#37345)
  Drop Fomantic tab, checkbox and form patches (go-gitea#37377)
  fix: dump with default zip type produces uncompressed zip (go-gitea#37401)
  Allow fast-forward-only merge when signed commits are required (go-gitea#37335)
  Introduce `ActionRunAttempt` to represent each execution of a run (go-gitea#37119)
  Move review request functions to a standalone file (go-gitea#37358)
  Fix repo init README EOL (go-gitea#37388)
  Fix org team assignee/reviewer lookups for team member permissions (go-gitea#37365)
  Remove external service dependencies in migration tests (go-gitea#36866)
  Extend issue context popup beyond markdown content (go-gitea#36908)
  fix: commit status reporting (go-gitea#37372)
  Support for Custom URI Schemes in OAuth2 Redirect URIs (go-gitea#37356)
  Fix cmd tests by mocking builtin paths (go-gitea#37369)
  chore: upgrade Go version in devcontainer image to 1.26 (go-gitea#37374)
  Fix button layout shift when collapsing file tree in editor (go-gitea#37363)
  Update `Block a user` form (go-gitea#37359)
  Remove IsValidExternalURL/IsAPIURL and use IsValidURL at call sites (go-gitea#37364)
  ...

# Conflicts:
#	modules/eventsource/event.go
#	tests/e2e/events.test.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InstallLock guard causes some cmd unit tests to fail

5 participants