21 KiB
21 KiB
Code Quality Report — shared
- Project: shared
- Path: /workspace/Personal/Web/shared
- Analyzed: 2026-10-16
- Commit:
5216031on main - Working tree: 9 uncommitted change(s):
.changeset/user-management-roles.mdandpackages/web-ui/src/lib/components/UserManagement.sveltedeleted;.changeset/remove-user-management.mduntracked;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.cssmodified. Findings reflect the working tree (for example, README component count, Q-014). - Stack: Go 1.25 (
backend/); Node.js ESM withpg(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,
.githuband.giteaworkflows,.githooks,scripts/(sync, build, and thescripts/mediatooling), all four language packages (AuthGuard clients, stores, TOTP, config, coreconfig, proxies), Go packages underbackend/(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/distand.svelte-kit(gitignored, not tracked),package-lock.jsonandgo.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.
Summary
| Severity | Count |
|---|---|
| Critical | 0 |
| High | 0 |
| Medium | 9 |
| Low | 7 |
| Info | 0 |
The code is generally tidy: no TODO, FIXME or HACK markers in first-party non-test code, no any or @ts-ignore in the web-ui, and parameterised SQL throughout. The weak spots are operational: several scripts and workflows no longer match the repository layout, Java and most Go packages are not tested in CI, the publish pipeline skips the checks that exist for pull requests, and the four AuthGuard clients have drifted apart in behaviour.
Issues
Q-001 · Node database wrapper: no pool error listener, and writes are retried blindly · Medium
- 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:
pgemits'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, includingINSERTandUPDATE, 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.
Q-002 · Repo-level media lint and test tooling points at directories that no longer exist · Medium
- Location:
scripts/media/lint-all.mjs:26(package listwebui) and:51(fails with "directory not found"),scripts/media/enforce-no-skipped-tests.mjs:18-20(rootstests,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 rootpackage.json, which is false),package.json:49-65(media:*scripts) - Description: This tooling was carried over from a monorepo.
webui/,media-backend/andshared/packagesdo not exist here; the real package ispackages/web-ui.media:lint:allfails immediately, andmedia:enforce:no-skipped-testsscans 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-uiandpackages/*/test(s). Make the no-skipped-tests check fail when it scans zero files, and wire any script that is kept into CI.
Q-003 · Java package has tests, but no CI job runs them · Medium
- 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,Rolesand 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 teston a JDK matching the target) totests.yml, and add unit tests forTotp,ResetManager,Rolesand cookie extraction.
Q-004 · Go test coverage is absent for several packages, including the media core and the sync hub · Medium
- 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.goandbackend/migrate/migrate.go(no tests),backend/auth/proxy.go(1525 lines;proxy_test.gocovers constructors, middleware gating and normalizers only) - Description:
git ls-filesshows no_test.gofile inmediacore,syncsocket,logshipper,configormigrate. Inbackend/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
httptesthandler tests for the auth-gated routes and for websocket message handling, and table tests for the path helpers (SafeRelative,ResolveUnderRoots,thumbnailFile).
Q-005 · The generated root stylesheet keeps a package import that the build was meant to strip · Medium
- 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:1uses double quotes, so the filter misses it. The generatedshared-styles.csskeeps 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.
Q-006 · The sync script can overwrite consumer changes, and the post-commit hook commits into consumer repositories · Medium
- 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-Commitafter every commit),scripts/install-sync-hook.ps1(enables the hook) - Description: With
-Force, uncommitted changes inside a consumer'sshared/folder are deleted or overwritten with no backup. The hook, once installed, runs the sync with-Commitafter 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.
Q-007 · Publish workflows release without running the checks that exist for pull requests · Medium
- 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(runsgo testonly; nogo vetor gofmt) - Description: A
v*tag or a published release publishes whatever is tagged, without the lint and test jobs in.github/workflowsthat 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 lintandnpm test,ruff check,python -m unittest,go vetand gofmt) before upload, or depend on a prior successful workflow run.
Q-008 · The four AuthGuard clients diverge in behaviour and in the stored password-hash format · Medium
- Location:
packages/node-backend/src/auth.js:56-81(PBKDF2salt:hexhashes) vspackages/python-backend/src/shared_backend/auth.py:123-133(bcrypt hashes) in the sameauth_users.password_hashcolumn;packages/python-backend/src/shared_backend/auth.py:225-240(list_usersandcreate_managed_userreturnpassword_hash) vspackages/node-backend/src/auth.js:221-233(excludes it);packages/java-backend/src/main/java/com/gabriel20xx/shared/auth/AuthClient.java:195(IllegalStateExceptionescapesmiddlewarewhile Node returns 401);packages/node-backend/src/db.js:69-74(retries only transient errors) vspackages/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_hashfrom 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.
Q-009 · The Node and web-ui code has no linter, formatter or component tests · Medium
- Location:
.github/workflows/lint.yml(Node job runsnpm run lint, which is svelte-check andnode --checkonly),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-uiorpackages/node-backend. Lint covers type checks and syntax only.packages/web-uihas no tests, so components such asAuthPage,MediaPlayerand 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/sveltesuite coveringAuthPage, the notification store and the primary-color helpers.
Q-010 · Errors on security paths are masked as invalid codes or swallowed · Low
- Location:
packages/python-backend/src/shared_backend/authproxy.py:723and:740(except Exceptionreturns "Invalid authenticator code"),packages/python-backend/src/shared_backend/authproxy.py:506-507(logout ignoresAPIErrorbut clears the cookie),backend/auth/proxy.go:1232-1235(TOTPVerifymaps every error to 401 invalid code),packages/java-backend/src/main/java/com/gabriel20xx/shared/auth/AuthClient.java:282-284(IOExceptiondiscarded without logging) - Description: An AuthGuard outage looks like a wrong authenticator code, so operators and users cannot tell the two apart. Logout clears the browser cookie even when the upstream call fails, which can leave a valid server-side session behind.
- Impact: Harder debugging, misleading user feedback, and possible sessions that survive a logout.
- Recommendation: Catch the specific error classes. Return 502 or 503 for upstream failures, log transport errors at warning level, and clear local cookies only after the upstream logout succeeds or fails in a known way.
Q-011 · Node version drift between publish and CI · Low
- Location:
.gitea/workflows/publish-npm.yml:24(node-version: 22),.github/workflows/lint.ymland.github/workflows/tests.yml(node-version: '24'),packages/node-backend/package.json(engines>=20) - Description: The packages are published from a build on Node 22, while lint and tests run on Node 24, and the package claims support from Node 20.
- Impact: The published artifacts are built with a different toolchain from the one that is tested, and the supported range is not exercised.
- Recommendation: Use one Node version for build and publish that matches what CI tests, and add a matrix entry for the minimum supported version.
Q-012 · Package export maps are incomplete, and the root . export points at the README · Low
- Location:
package.json:19("." : "./README.md"),package.json:28-33(no./node-backend/coreconfigexport, though the file ships infiles),packages/node-backend/package.jsonexports(no./totpor./authclient, although both files exist and are re-exported fromsrc/index.js),packages/python-backend/src/shared_backend/__init__.py(does not re-exportAPIError) - Description: The root package's main entry resolves to a documentation file. Subpath imports for
totpandauthclientfail withERR_PACKAGE_PATH_NOT_EXPORTEDeven though the modules exist, and the root export map omitscoreconfig. - Impact: Consumers cannot import documented modules, and tooling that resolves the package main gets the README.
- Recommendation: Point
.at a real index module or remove it, add the missing subpath exports, and add a smoke test that imports every exported path.
Q-013 · Versioning and changeset hygiene · Low
- Location:
.changeset/config.json:11(ignores@gabriel20xx/shared-workspace, which does not exist; the root package is@gabriel20xx/shared-code),packages/java-backend/pom.xml:6(0.1.0, while the npm and Python packages are0.1.1),packages/python-backend/pyproject.toml(0.1.1, versioned by hand) - Description: Changesets cover only the npm packages. Python and Java versions are maintained by hand, and recent changes to those packages (for example commits
f5a20b7,de9b599and97a5ecd) have no changeset. The ignore entry names a package that does not exist. - Impact: Release notes and version numbers can drift between runtimes.
- Recommendation: Correct the ignore entry. Either add changesets for the Python and Java packages, or document that they are versioned by tag and record the tag in the changelog.
Q-014 · Stale README and comments after the component removal and the monorepo extraction · Low
- Location:
README.md:31("22 components"; the working-tree removal leaves 20 exports inpackages/web-ui/src/lib/index.ts),README.md:24(names amediaauthpackage that is not inbackend/),backend/authproxy/authproxy.go:9andbackend/mediacore/migrate.go:15(refer tomediaauth),.gitignore:4(webui/.svelte-kit/targets a directory that was removed) - Description: Documentation names a package and a count that no longer match the tree, and a
.gitignoreentry targets a directory that no longer exists. - Impact: Misleading documentation for consumers and maintainers.
- Recommendation: Update the component count to match
index.tswhen the removal is committed, delete themediaauthreferences, and remove the stale ignore entry.
Q-015 · Go code hygiene: dead code, an oversized file, duplicated helpers and nil-dependency constructors · Low
- Location:
backend/auth/reset.go(ResetManagerhas no non-test consumer in this repository),backend/auth/totp.go:23(TOTPSecretLengthunused),backend/auth/proxy.go(1525 lines mixing middleware, handlers and platform-user SQL),backend/mediacore/mediacore.go:76-78(Newaccepts nil CarrierNode or Sync; needs verification in the code),backend/authclient/client.go:270-278(two identical branches where the comment says there is a distinction),writeJSONandwriteErrorduplicated across three packages - Description: Exported helpers with no in-repository callers, a 1525-line file that mixes concerns, duplicated HTTP helpers, a constructor that accepts nil dependencies (which panics on first use rather than at startup), and a branch that is meant to separate transport failures from invalid sessions but returns the same result either way.
- Impact: Maintenance cost, and a misconfigured service fails on the first request rather than at startup.
- Recommendation: Remove or move unused code. Split
proxy.gointo middleware, handlers and persistence files. Validate constructor arguments. Share one JSON helper package, and make the authclient branches distinct or merge them.
Q-016 · Web UI: an unkeyed {#each} over a prop, and a login-field length rule that also applies to sign-in · Low
- Location:
packages/web-ui/src/lib/components/Header.svelte:168({#each navItems as item}with no key),packages/web-ui/src/lib/components/AuthPage.svelte:202(minlength="8"on the sign-in password field, not only on setup) - Description: The navigation list comes from a prop and is rendered without a key, so Svelte reconciles it by index. The sign-in field applies the setup minimum, so an account whose existing password is shorter cannot sign in through this form. Whether such accounts exist needs verification; the server enforces eight characters at setup (
backend/auth/proxy.go:1460,packages/node-backend/src/auth.js:57,packages/python-backend/src/shared_backend/auth.py:124). - Impact: Minor re-render inefficiency, and a possible lockout of legacy accounts.
- Recommendation: Key the each block by
item.href, and applyminlengthonly when setup is required.
Notes
- Checked, clean: No
TODO,FIXME,HACKorXXXmarkers in first-party non-test code. Noany,@ts-ignore,@ts-expect-errororsvelte-ignoreinpackages/web-ui/src. No{@html},innerHTML,evalornew Functionin the web-ui or scripts. External links userel="noreferrer". Timers and document listeners are cleaned up inStatusWidget,MediaPlayer,MediaPlayerControls,PrimaryColorPickerandnotifications.svelte.ts. - Checked, consistent: Go code is gofmt-checked and
go vet-checked in CI. Python code is ruff-checked (E,F,I). Node syntax is checked forpackages/node-backend. Parameterised SQL is used across the Go, Node and Python stores. - Duplication by design: The AuthGuard client exists in four languages on purpose. Q-008 covers where the behaviour has drifted.
- Not run: No lint, build, test,
go vet,ruff,svelte-checkornpmcommand was executed. All findings are from reading the code. - Not verified: Whether consumers depend on the removed
UserManagementexport or theMediaPlayerControlsbarrel removal (the changeset says only AuthGuard used it). Whether thepackages/media-shared-assetsandmedia-backendpaths in history were ever shipped. - Excluded from analysis:
packages/web-ui/distand.svelte-kit(gitignored, not tracked),package-lock.jsonandgo.sum(versions only), test bodies beyond coverage notes.