ci: expand CI checks and make consumer sync opt-in
- Add Go, npm, Python, and Java validation to CI - Run Go tests against PostgreSQL - Record performance fixes in the report
This commit is contained in:
1 parent
199a5efaef
commit
22887fef03
100 files changed
+9740
-429
No files matched your search
+19
-9
@@ -7,6 +7,7 @@
|
||||
- **Working tree:** 9 uncommitted change(s): `.changeset/user-management-roles.md` and `packages/web-ui/src/lib/components/UserManagement.svelte` deleted; `.changeset/remove-user-management.md` untracked; `README.md`, `MediaPlayerControls.svelte`, `packages/web-ui/src/lib/index.ts`, `packages/web-ui/src/lib/styles.css`, `packages/web-ui/src/lib/types.ts`, `shared-styles.css` modified. Findings reflect the working tree (for example, README component count, Q-014).
|
||||
- **Stack:** Go 1.25 (`backend/`); Node.js ESM with `pg` (`packages/node-backend`); Python 3.10+ with asyncpg, bcrypt and optional FastAPI (`packages/python-backend`, ruff configured); Java 8 target with Jackson and JUnit 5 (`packages/java-backend`); Svelte 5 and TypeScript with svelte-check (`packages/web-ui`); PowerShell and Node build and sync scripts; Gitea and GitHub Actions.
|
||||
- **Scope:** A shared library consumed by other projects as a vendored snapshot. Read: root manifests and changesets, `.github` and `.gitea` workflows, `.githooks`, `scripts/` (sync, build, and the `scripts/media` tooling), all four language packages (AuthGuard clients, stores, TOTP, config, coreconfig, proxies), Go packages under `backend/` (auth read in a separate pass), and the web-ui library source (barrel, styles, primary-color, notifications, components that do I/O or timers). Excluded: `node_modules`, `packages/web-ui/dist` and `.svelte-kit` (gitignored, not tracked), `package-lock.json` and `go.sum` (versions only), and test bodies except for coverage notes. Backend findings come from read-only static review passes; the highest-impact citations were re-checked in the code. No lint, build or test was executed.
|
||||
- **Updated:** 2026-10-19 — Medium findings handled in the working tree (not committed): Q-004 and Q-009 fixed; Q-008 stays open for the cross-runtime hash-format decision.
|
||||
|
||||
## Summary
|
||||
|
||||
@@ -22,59 +23,68 @@ The code is generally tidy: no TODO, FIXME or HACK markers in first-party non-te
|
||||
|
||||
## Issues
|
||||
|
||||
### Q-001 · Node database wrapper: no pool `error` listener, and writes are retried blindly · **Medium**
|
||||
### Q-001 · Node database wrapper: no pool `error` listener, and writes are retried blindly · **Medium** · Fixed
|
||||
- **Location:** `packages/node-backend/src/db.js:43` (`new Pool(...)` with no `'error'` handler; grep of the package finds none), `packages/node-backend/src/db.js:80-88` (`query()` retries once on any transient error)
|
||||
- **Description:** `pg` emits `'error'` on the pool when an idle client fails, for example after a database restart. With no listener, that event is thrown and can terminate the process. Separately, `query()` retries once on any transient error for every statement, including `INSERT` and `UPDATE`, so a write that committed before the connection dropped can be applied twice.
|
||||
- **Impact:** A database restart can crash a service that uses this wrapper, and non-idempotent writes can be duplicated.
|
||||
- **Recommendation:** Attach a logging `pool.on('error', ...)` handler. Retry only reads, or require the caller to opt in to retrying a specific statement.
|
||||
- **Status:** Fixed 2026-10-19 — `Database` attaches a logging `error` listener to the pool, so a failed idle client is logged instead of thrown. `query()` retries after a transient error only for plain read-only SELECTs, and a caller can opt a statement in with `{ retry: true }`. Behaviour change: a write that hits a transient error is no longer retried by default. Files: `packages/node-backend/src/db.js`, `packages/node-backend/test/db.test.js`.
|
||||
|
||||
### Q-002 · Repo-level media lint and test tooling points at directories that no longer exist · **Medium**
|
||||
### Q-002 · Repo-level media lint and test tooling points at directories that no longer exist · **Medium** · Fixed
|
||||
- **Location:** `scripts/media/lint-all.mjs:26` (package list `webui`) and `:51` (fails with "directory not found"), `scripts/media/enforce-no-skipped-tests.mjs:18-20` (roots `tests`, `webui/src`, `shared/packages`) and `:99-102` (prints OK when nothing is scanned), `scripts/media/upgrade-deps.mjs:102-104` (comment asserts there is no root `package.json`, which is false), `package.json:49-65` (`media:*` scripts)
|
||||
- **Description:** This tooling was carried over from a monorepo. `webui/`, `media-backend/` and `shared/packages` do not exist here; the real package is `packages/web-ui`. `media:lint:all` fails immediately, and `media:enforce:no-skipped-tests` scans zero files and still reports success, which gives false confidence. None of these scripts runs in CI.
|
||||
- **Impact:** Dead tooling that either fails or passes vacuously, and misleading comments about the repository layout.
|
||||
- **Recommendation:** Delete the unused scripts, or repoint them at `packages/web-ui` and `packages/*/test(s)`. Make the no-skipped-tests check fail when it scans zero files, and wire any script that is kept into CI.
|
||||
- **Status:** Fixed 2026-10-19 — `lint-all.mjs` and `lint-all-json.mjs` point at `packages/web-ui`, `upgrade-deps.mjs` names the real local packages, and `enforce-no-skipped-tests.mjs` scans `packages/web-ui/src` and `packages/node-backend/test` and fails when it finds no files. The no-skipped-tests check now runs in `lint.yml`; `lint-all` is still not wired into CI because web-ui has no ESLint config (Q-009). Files: `scripts/media/lint-all.mjs`, `scripts/media/lint-all-json.mjs`, `scripts/media/upgrade-deps.mjs`, `scripts/media/enforce-no-skipped-tests.mjs`, `.github/workflows/lint.yml`.
|
||||
|
||||
### Q-003 · Java package has tests, but no CI job runs them · **Medium**
|
||||
### Q-003 · Java package has tests, but no CI job runs them · **Medium** · Fixed
|
||||
- **Location:** `packages/java-backend/pom.xml`, `packages/java-backend/src/test/java/com/gabriel20xx/shared/auth/AuthClientTest.java`, `.github/workflows/tests.yml`, `.github/workflows/lint.yml` (neither mentions Java or Maven)
|
||||
- **Description:** The only Java test class is `AuthClientTest`. `Totp`, `ResetManager`, `Roles` and cookie extraction have no direct tests. The package is compiled into a consuming project as source, so a regression here reaches that project without any signal in this repository.
|
||||
- **Impact:** Java changes can break without detection.
|
||||
- **Recommendation:** Add a Java job (`mvn -B test` on a JDK matching the target) to `tests.yml`, and add unit tests for `Totp`, `ResetManager`, `Roles` and cookie extraction.
|
||||
- **Status:** Fixed 2026-10-19 — `tests.yml` has a `java` job that runs `mvn -B test` on JDK 17 in `packages/java-backend`. Not compiled or run: no JDK or Maven is available here, so the workflow and the Java test classes were checked by reading only. Files: `.github/workflows/tests.yml`, `packages/java-backend/src/test/java/com/gabriel20xx/shared/auth/AuthClientTest.java`.
|
||||
|
||||
### Q-004 · Go test coverage is absent for several packages, including the media core and the sync hub · **Medium**
|
||||
### Q-004 · Go test coverage is absent for several packages, including the media core and the sync hub · **Medium** · Fixed
|
||||
- **Location:** `backend/mediacore/mediacore.go` (1107 lines, no tests), `backend/syncsocket/syncsocket.go` (581 lines, no tests), `backend/logshipper/shipper.go` (438 lines, no tests), `backend/config/config.go` and `backend/migrate/migrate.go` (no tests), `backend/auth/proxy.go` (1525 lines; `proxy_test.go` covers constructors, middleware gating and normalizers only)
|
||||
- **Description:** `git ls-files` shows no `_test.go` file in `mediacore`, `syncsocket`, `logshipper`, `config` or `migrate`. In `backend/auth`, the handler-level behaviour of Signup, Login, Logout, UpdateMe, the managed-user endpoints, the TOTP endpoints and the platform-user SQL is untested (per review pass).
|
||||
- **Impact:** The largest and most security-relevant code paths (media routes, websocket hub message handling, log redaction) change without tests.
|
||||
- **Recommendation:** Add `httptest` handler tests for the auth-gated routes and for websocket message handling, and table tests for the path helpers (`SafeRelative`, `ResolveUnderRoots`, `thumbnailFile`).
|
||||
- **Status:** Fixed 2026-10-19 — every gap the finding names now has tests. `syncsocket`: connection cap, origin handling, identity, the per-peer message rate (`allowMessage`, and a flooding client is closed with 1008), and a stuck peer being dropped without holding up `Broadcast`. `logshipper`: levels, the local line, ID scrubbing, batching, the bounded buffer, flush and close, and a failing sink never failing the caller. `config` and `migrate`: the environment helpers, the argument and connection errors, and real goose runs. `mediacore`: the auth gate on every `Require` route, the sync routes (validation, clamping, broadcast to the session only), and, against PostgreSQL, stream and thumbnail (hidden media, escaped and refused paths), likes, saves, views, tags, and playlists including reorder and ownership. `auth`: handler tests for Login, Signup, Logout, UpdateMe, the managed-user routes, the TOTP routes, the gating middlewares and `Me` against a fake AuthGuard, the platform-user SQL against PostgreSQL, and the new contract file. Writing them found and fixed two defects: `Broadcast` could block for five seconds in the close handshake of a stuck peer (see P-002), and `GET /media/{id}/tags` always answered an empty list because the query's `tag` column was ambiguous (`backend/mediacore/mediacore.go`). The PostgreSQL tests skip unless `DATABASE_URL` (auth store) or `SHARED_TEST_DATABASE_URL` names a scratch database; `.github/workflows/tests.yml` now provides one to the Go job (`go test -p 1 ./...`). Files: `backend/syncsocket/syncsocket_test.go`, `backend/logshipper/shipper_test.go`, `backend/config/config_test.go`, `backend/migrate/migrate_test.go`, `backend/mediacore/routes_test.go`, `backend/mediacore/routes_db_test.go`, `backend/auth/proxy_handlers_test.go`, `backend/auth/platform_users_integration_test.go`, `backend/auth/store_integration_test.go`, `backend/auth/contract_test.go`, `backend/auth/proxy_test.go`, `.github/workflows/tests.yml`.
|
||||
|
||||
### Q-005 · The generated root stylesheet keeps a package import that the build was meant to strip · **Medium**
|
||||
### Q-005 · The generated root stylesheet keeps a package import that the build was meant to strip · **Medium** · Fixed
|
||||
- **Location:** `scripts/build-root-styles.mjs:4` (token import as a single-quoted string) and `:7` (filter compares exact text), `shared-styles.css:3` (`@import "@gabriel20xx/design-tokens/theme.css";` kept)
|
||||
- **Description:** The build removes the token import only when it matches the single-quoted string. `packages/web-ui/src/lib/styles.css:1` uses double quotes, so the filter misses it. The generated `shared-styles.css` keeps a bare package import on line 3 beside the relative import on line 1. This was already present at HEAD. No CI step checks that the committed generated file matches the build output.
|
||||
- **Impact:** Consumers that vendor this file must resolve a package they may not install, or their bundler fails. The duplicated import also shows that the generation step is not verified.
|
||||
- **Recommendation:** Normalise quotes in the filter (or match both forms), then add a CI step that rebuilds and runs `git diff --exit-code shared-styles.css`.
|
||||
- **Status:** Fixed 2026-10-19 — the build's token-import filter matches both quote styles and an optional semicolon, so the package import is stripped. Running the build reproduces `shared-styles.css` byte for byte, and `lint.yml` now runs `git diff --exit-code -- shared-styles.css` after `npm ci`. Files: `scripts/build-root-styles.mjs`, `shared-styles.css`, `.github/workflows/lint.yml`.
|
||||
|
||||
### Q-006 · The sync script can overwrite consumer changes, and the post-commit hook commits into consumer repositories · **Medium**
|
||||
### Q-006 · The sync script can overwrite consumer changes, and the post-commit hook commits into consumer repositories · **Medium** · Fixed
|
||||
- **Location:** `scripts/sync-consumers.ps1:273` (dirty-destination check bypassed by `-Force`), `scripts/sync-consumers.ps1:291` (stale files removed) and `:301` (files overwritten), `.githooks/post-commit:8-10` (runs the sync with `-Commit` after every commit), `scripts/install-sync-hook.ps1` (enables the hook)
|
||||
- **Description:** With `-Force`, uncommitted changes inside a consumer's `shared/` folder are deleted or overwritten with no backup. The hook, once installed, runs the sync with `-Commit` after every commit in this repository, which creates commits in each registered consumer repository (22 entries in `$consumerProjects`).
|
||||
- **Impact:** Possible loss of uncommitted consumer work, and unexpected commits in other projects after an unrelated commit here.
|
||||
- **Recommendation:** Make destructive overwrite require an explicit flag that first stashes or backs up the destination. Make the hook opt-in, or have it report what would change instead of committing. Document the behaviour in the README.
|
||||
- **Status:** Fixed 2026-10-19 — the post-commit hook runs the consumer sync only when `SHARED_SYNC_COMMIT=1` is set for that commit, and `sync-consumers.ps1` copies a dirty destination to a temp backup before `-Force` overwrites it. Behaviour change: an ordinary commit no longer syncs or commits into consumer repositories. Not run: PowerShell is not installed here, so the script change is unparsed. Files: `.githooks/post-commit`, `scripts/sync-consumers.ps1`, `scripts/install-sync-hook.ps1`.
|
||||
|
||||
### Q-007 · Publish workflows release without running the checks that exist for pull requests · **Medium**
|
||||
### Q-007 · Publish workflows release without running the checks that exist for pull requests · **Medium** · Fixed
|
||||
- **Location:** `.gitea/workflows/publish-npm.yml:27-49` (builds, then publishes; no lint or test step), `.gitea/workflows/publish-python.yml:26-39` (builds and uploads; no ruff or unittest), `.gitea/workflows/publish-go.yml:29-31` (runs `go test` only; no `go vet` or gofmt)
|
||||
- **Description:** A `v*` tag or a published release publishes whatever is tagged, without the lint and test jobs in `.github/workflows` that gate changes. The publish workflows run in a separate system, so the same checks are not enforced at release time.
|
||||
- **Impact:** Broken or unlinted code can reach the shared registries that projects consume.
|
||||
- **Recommendation:** Make each publish job run the same checks as CI (`npm run lint` and `npm test`, `ruff check`, `python -m unittest`, `go vet` and gofmt) before upload, or depend on a prior successful workflow run.
|
||||
- **Status:** Fixed 2026-10-19 — each publish workflow runs the checks that gate pull requests before it uploads: npm runs `npm run lint` and `npm test`, Python runs ruff and the unittest suite, and Go runs gofmt and `go vet` before `go test`. Not run: no Gitea runner is available here. The Go gofmt step will fail until `backend/authclient/client.go` and `backend/syncsocket/syncsocket.go` are gofmt-clean; their in-progress hunks were not reformatted in this pass. Files: `.gitea/workflows/publish-npm.yml`, `.gitea/workflows/publish-python.yml`, `.gitea/workflows/publish-go.yml`.
|
||||
|
||||
### Q-008 · The four AuthGuard clients diverge in behaviour and in the stored password-hash format · **Medium**
|
||||
### Q-008 · The four AuthGuard clients diverge in behaviour and in the stored password-hash format · **Medium** · Open
|
||||
- **Location:** `packages/node-backend/src/auth.js:56-81` (PBKDF2 `salt:hex` hashes) vs `packages/python-backend/src/shared_backend/auth.py:123-133` (bcrypt hashes) in the same `auth_users.password_hash` column; `packages/python-backend/src/shared_backend/auth.py:225-240` (`list_users` and `create_managed_user` return `password_hash`) vs `packages/node-backend/src/auth.js:221-233` (excludes it); `packages/java-backend/src/main/java/com/gabriel20xx/shared/auth/AuthClient.java:195` (`IllegalStateException` escapes `middleware` while Node returns 401); `packages/node-backend/src/db.js:69-74` (retries only transient errors) vs `packages/python-backend/src/shared_backend/postgres.py:63` (retries every exception); `packages/java-backend/src/main/java/com/gabriel20xx/shared/auth/Totp.java:80` (`String.equals`) vs constant-time comparison in Node and Python
|
||||
- **Description:** Node and Python write incompatible hash formats into the same column, so a database shared between them cannot be verified by both. Python's list and create paths return the hash in their payloads; Node's do not. Java's middleware lets an unchecked exception escape where Node returns 401. The startup retry policy differs, so Python retries forever on errors that Node would surface immediately.
|
||||
- **Impact:** A service behaves differently depending on which runtime serves it, and a password hash can reach an API response in Python.
|
||||
- **Recommendation:** Standardise the hash format (or rehash on login), strip `password_hash` from every DTO, align the retry policy and the middleware failure modes, and add cross-language contract tests that run the same fixtures against each client.
|
||||
- **Status:** Open 2026-10-19 — partly fixed: Python list and create payloads no longer return `password_hash`, Python startup retries only transient connection errors like Node, the Java middleware answers 401 when no base URL is set, and Java `Totp` compares with `MessageDigest.isEqual`. Node, Python and Go version their password hashes and rewrite older ones on login (see S-013). New in this pass: `contract/auth-contract.json` holds shared fixtures (password hashes per runtime, RFC 6238 TOTP cases, client-address cases) that the Go, Node and Python suites all load (`backend/auth/contract_test.go`, `packages/node-backend/test/contract.test.js`, `packages/python-backend/tests/test_contract.py`); it records the remaining hash divergence on purpose. Running it found Python `verify_totp` raising `TypeError` on a six-digit token written in non-ASCII digits where Go and Node answer false, fixed in `totp.py`. The Node and Python stores now share Go's guards (see S-016), and Python refuses passwords over 72 bytes like Go. Still open: Node (PBKDF2) writes a different hash format into `auth_users.password_hash` than Python and Go (bcrypt); Node cannot verify bcrypt, and Python and Go cannot verify Node's. Decision needed: pick one write scheme for all runtimes (or accept a new bcrypt dependency in Node), because letting one runtime verify another's format would make a shared database ping-pong between schemes on re-key. The Java client is not in the contract tests: no JDK or Maven is available here to compile them. Files: `contract/auth-contract.json`, `backend/auth/contract_test.go`, `packages/node-backend/test/contract.test.js`, `packages/python-backend/tests/test_contract.py`, `packages/python-backend/src/shared_backend/totp.py`, `packages/python-backend/src/shared_backend/auth.py`, `packages/python-backend/src/shared_backend/postgres.py`, `packages/java-backend/src/main/java/com/gabriel20xx/shared/auth/AuthClient.java`, `packages/java-backend/src/main/java/com/gabriel20xx/shared/auth/Totp.java`, `packages/node-backend/src/auth.js`, `backend/auth/password.go`.
|
||||
|
||||
### Q-009 · The Node and web-ui code has no linter, formatter or component tests · **Medium**
|
||||
### Q-009 · The Node and web-ui code has no linter, formatter or component tests · **Medium** · Fixed
|
||||
- **Location:** `.github/workflows/lint.yml` (Node job runs `npm run lint`, which is svelte-check and `node --check` only), `scripts/media/lint-all.mjs:57-64` (expects ESLint and Prettier configs in a package that does not have them), `packages/web-ui/` (no test files and no test script), `packages/node-backend/package.json` (no lint script)
|
||||
- **Description:** No ESLint, Prettier or Stylelint configuration is tracked for `packages/web-ui` or `packages/node-backend`. Lint covers type checks and syntax only. `packages/web-ui` has no tests, so components such as `AuthPage`, `MediaPlayer` and the notification and primary-color stores are unverified.
|
||||
- **Impact:** Style drift and behavioural regressions in a UI library that several applications consume.
|
||||
- **Recommendation:** Add ESLint (with `eslint-plugin-svelte`) and Prettier configuration at package level, and a small Vitest and `@testing-library/svelte` suite covering `AuthPage`, the notification store and the primary-color helpers.
|
||||
- **Status:** Fixed 2026-10-19 — ESLint (flat config `eslint.config.js`: `@eslint/js`, `typescript-eslint`, `eslint-plugin-svelte`) now lints `packages/web-ui`, `packages/node-backend` and `scripts` with `--max-warnings=0`; it is part of `npm run lint` (so of `lint.yml` and the publish gate) and each package has a `lint` script. Prettier 3 with `prettier-plugin-svelte` is configured in `.prettierrc.json`, with `npm run format` and `format:check` (also a `lint.yml` step). `packages/web-ui` has a Vitest and `@testing-library/svelte` suite in `packages/web-ui/tests` (27 tests: `AuthPage` login, two-factor challenge, setup and reset flows; the notification store and `NotificationStack`; the primary-color helpers), run by `npm run test:web-ui`, which `npm test` and `release` now include. All of it is root `devDependencies` (`eslint`, `@eslint/js`, `typescript-eslint`, `eslint-plugin-svelte`, `globals`, `prettier`, `prettier-plugin-svelte`, `vitest`, `jsdom`, `@testing-library/svelte`; no way to fix the finding without them), so `packages/web-ui/package.json`'s dependencies and the consumers' lockfile entries for it are unchanged; only a `lint` and a `test` script were added there. The existing code passes ESLint without code changes beyond three unused bindings in `scripts/media`; three Svelte rules that would change how shipped components render or hold state (`require-each-key`, `prefer-writable-derived`, `prefer-svelte-reactivity`) are turned off with a comment. Not done: Prettier is enforced only on the files written to its style (44 older files differ from it and were not reformatted, to keep the mirrored diff small), and Stylelint was not added. Files: `eslint.config.js`, `.prettierrc.json`, `.prettierignore`, `package.json`, `package-lock.json`, `packages/web-ui/{package.json,vitest.config.ts,tests/}`, `packages/node-backend/package.json`, `scripts/media/{lint-all,lint-all-json,list-skipped-tests,enforce-no-skipped-tests}.mjs`, `.github/workflows/lint.yml`.
|
||||
|
||||
### Q-010 · Errors on security paths are masked as invalid codes or swallowed · **Low**
|
||||
- **Location:** `packages/python-backend/src/shared_backend/authproxy.py:723` and `:740` (`except Exception` returns "Invalid authenticator code"), `packages/python-backend/src/shared_backend/authproxy.py:506-507` (logout ignores `APIError` but clears the cookie), `backend/auth/proxy.go:1232-1235` (`TOTPVerify` maps every error to 401 invalid code), `packages/java-backend/src/main/java/com/gabriel20xx/shared/auth/AuthClient.java:282-284` (`IOException` discarded without logging)
|
||||
|
||||
Reference in new issue
Block a user