DoDiODev opened a new pull request, #9179:
URL: https://github.com/apache/devlake/pull/9179
### Summary
Fixes #9088.
`backend/mocks/` is git-ignored, but `helpers/unithelper` and 22 test files
import five of its packages. On a fresh clone these import paths do not exist
inside the main module, so `go mod tidy` tries to resolve them as external
modules and fails:
```
go: github.com/apache/devlake/core/migration tested by
github.com/apache/devlake/core/migration.test imports
github.com/apache/devlake/mocks/core/dal: no matching versions for
query "latest"
```
This also keeps Dependabot's `gomod` updater from producing any update.
### Changes
- **Placeholders:** one `doc.go` (`package mocks`, no code) in each mock
package imported by tracked sources: `core/context`, `core/dal`, `core/log`,
`core/plugin`, `helpers/pluginhelper/api`. The import paths now resolve inside
the main module.
- **`.gitignore`:** `backend/mocks/` → `backend/mocks/**/*.go` +
`!backend/mocks/**/doc.go`. Generated mocks stay untracked.
- **`make mock`:** removes only generated files (keeps `doc.go`) instead of
`rm -rf mocks`; still works when `mocks/` does not exist (Docker build context,
`.dockerignore` unchanged).
- **`unit-test` workflow:** new step right after installing Go, i.e. on the
fresh checkout before any mocks exist:
```yaml
- name: Check go.mod is tidy without generated mocks
run: |
cd backend
go mod tidy
git diff --exit-code -- go.mod go.sum
```
A new mock import without placeholder, or an untidy `go.mod`, fails here.
No Go source, test, `go.mod` or `go.sum` change.
### Verification
Fresh clone, Go 1.26.6 (same as CI):
| Check | Result |
|---|---|
| `go mod tidy` + `git diff --exit-code` without mocks | ✅ exit 0, no diff |
| `make mock` (mockery v3.7.4), twice | ✅ placeholders kept, `git status`
clean |
| `go mod tidy` with generated mocks | ✅ no diff |
| unit tests of all 17 packages importing mocks | ✅ 16 ok (+ `unithelper`,
no tests) |
| negative test: remove `mocks/core/log/doc.go` | ✅ guard fails (`no
matching versions … mocks/core/log`) |
| `make mock` with no `mocks/` directory | ✅ exit 0 |
Unmodified upstream workflows in the fork (same
`mericodev/lake-builder:latest`, [unit-test
run](https://github.com/DoDiODev/devlake/actions/runs/36413442684)):
NOTICE-year-check, lint-commit-message, check-grafana-dashboards,
golangci-lint, migration-script-lint, yaml-lint, unit-test (new step green),
test-e2e mysql + postgres — all green.
### Alternatives considered
- **Commit the generated mocks** (option 1 in #9088): works too, but
reverses the long-standing convention of not tracking generated code (same as
the Swagger files) and adds ~65 files / ~644 KB that churn on every mockery
bump.
- **Remove all imports of generated packages** (option 2): must also cover
test files, since `go mod tidy` resolves test imports — 25 files in 17 packages.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]