From 635f7fc9146663f291ee783ed4448b22c0bc01b8 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 16 Nov 2026 09:54:23 +0100 Subject: [PATCH] :sparkles: Disable the admin-console by default in the devenv frontend (#13061) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * :sparkles: Disable the admin-console by default in the devenv frontend The devenv does not run the admin-console service, but the frontend showed its UI by default. The devenv containers now build the frontend with PENPOT_DEVENV=true, which prepends disable-admin-console ahead of the developer's config.js flags. Flags parse in order, so enable-admin-console in config.js re-enables it; builds outside devenv are unchanged. Closes #13060 AI-assisted-by: inkling-2-small-free * :books: Require English in all code-facing text Add a hard rule to AGENTS.md: everything in code must be in English — identifiers, comments, docstrings, test descriptions, log hints — with tests not excepted. The only allowed place for another language is product copy rendered through the i18n system. Also restated in mem:clojure/design-rules and mem:testing. AI-assisted-by: inkling-2-small-free --- .serena/memories/clojure/design-rules.md | 1 + .serena/memories/devenv/core.md | 1 + .serena/memories/testing.md | 2 ++ AGENTS.md | 6 +++++ docker/devenv/docker-compose.main.yml | 6 +++++ docs/technical-guide/developer/devenv.md | 8 ++++++ frontend/shadow-cljs.edn | 3 ++- frontend/src/app/config.cljs | 18 ++++++++++++- frontend/test/frontend_tests/config_test.cljs | 27 +++++++++++++++++++ frontend/test/frontend_tests/runner.cljs | 2 ++ 10 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 frontend/test/frontend_tests/config_test.cljs diff --git a/.serena/memories/clojure/design-rules.md b/.serena/memories/clojure/design-rules.md index 2b439ee038..e39facedc3 100644 --- a/.serena/memories/clojure/design-rules.md +++ b/.serena/memories/clojure/design-rules.md @@ -8,6 +8,7 @@ How to shape a function in this codebase. Each rule came from a review round; do - **Functions that obtain data start with `get-` or `fetch-`.** A reader must see at a glance that the function reads (`get-file`, `get-snapshot`, `get-file-json`); a bare noun hides it (`file-json` says nothing about reading). New helpers that fetch by id follow this, never a `current-` prefix: the id parameter already says which one it is. - **`?` marks a predicate, not a data prop.** A var or function that answers a question takes `?` (`export-error?`, `(defn editable? …)`); a map key that names a property does not (`:export-error`, never `:export-error?`), even when its value is a boolean. Existing `?` keys are legacy to remove gradually; do not add a new one. - **Do not shape production code for tests.** No return values added just to assert them; assert on the observable effect. When preconditions move, move the tests with them. +- **All code-facing text MUST be in English** — identifiers, comments, docstrings, test descriptions. No exceptions; see the hard rule in `AGENTS.md`. Reference implementation: the http metrics samplers in `app.http` (`sample-worker-metrics` / `sample-connector-metrics` are guard-free; `sample-http-metrics` guards at the boundary). diff --git a/.serena/memories/devenv/core.md b/.serena/memories/devenv/core.md index 3507a5d6e0..a6645ed04f 100644 --- a/.serena/memories/devenv/core.md +++ b/.serena/memories/devenv/core.md @@ -15,6 +15,7 @@ Compose-based dev environment under `docker/devenv/`, driven by `manage.sh`. Par - For ws1+, `instance-env-overrides` computes the per-instance overrides (container/volume names, host ports offset `10000·N`, `PENPOT_PUBLIC_URI`, `PENPOT_REDIS_URI`, `PENPOT_TEST_DATABASE_URI`, `PENPOT_TEST_REDIS_URI`) and `instance-compose` injects them as env vars at compose time — never written to disk, recomputed each call so they can't drift. ws0 uses `defaults.env` as-is. - Per-instance test databases are created by `ensure-instance-test-database` (called from `start-instance`): `CREATE DATABASE` guarded by a `pg_database` existence check, so it is idempotent. Needed because `postgresql_init.sql` only runs on first volume creation. The backend applies migrations itself on first use, so an empty database is enough. - `backend/scripts/_env`: backend-internal only — secret keys, `PENPOT_FLAGS` (with `enable-backend-worker` gated on `PENPOT_BACKEND_WORKER`), `JAVA_OPTS`, `setup_s3_bucket()`. Never duplicates `defaults.env`. +- Frontend admin-console is off by default in devenv: `docker-compose.main.yml` sets `PENPOT_DEVENV=true`, which makes `app.config` (`goog-define devenv-mode`) prepend `disable-admin-console` ahead of the user `config.js` flags; flags parse in order and user flags win, so `enable-admin-console` in `frontend/resources/public/js/config.js` re-enables it. Outside devenv (prod builds) the default is unset and the admin-console stays on, matching `flags/default`. - Compose files use pure `${VAR}` substitution; missing var = compose fails. ## Invariants diff --git a/.serena/memories/testing.md b/.serena/memories/testing.md index ce301ff5bb..75b775d0ec 100644 --- a/.serena/memories/testing.md +++ b/.serena/memories/testing.md @@ -73,6 +73,8 @@ a test that reproduces it: - **One Assertion Per Concept** — each test verifies one behavior; split compound assertions - **Descriptive Test Names** — names read like specifications +- **English Only** — test names, `testing` strings, comments, and every + code-facing text MUST be in English; see the hard rule in `AGENTS.md`. ## Prefer Real Implementations Over Mocks diff --git a/AGENTS.md b/AGENTS.md index 4e4bf1fec1..261d099e68 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -28,6 +28,12 @@ - Before `gh pr create` / `gh pr edit` → `mem:workflow/creating-prs` (title format, body structure, AI note) Don't infer format from the title of a previous commit/issue/PR — the memory is the source of truth. +- **Everything in code MUST be in English.** Identifiers (functions, + variables, types, namespaces), code comments, docstrings, test + descriptions, log hints — always English, regardless of the language the + author works in. Tests are not an exception. The only place another + language may appear in the codebase is product copy rendered through the + i18n system. ## CRITICAL: Read module memories BEFORE writing any code diff --git a/docker/devenv/docker-compose.main.yml b/docker/devenv/docker-compose.main.yml index c55330a80a..6836861354 100644 --- a/docker/devenv/docker-compose.main.yml +++ b/docker/devenv/docker-compose.main.yml @@ -101,5 +101,11 @@ services: - SERENA_UPDATE_VERSION=2.1.0 - SHADOW_SERVER_URL=${SHADOW_SERVER_URL} + # Frontend dev devenv switch: makes the frontend compile with + # PENPOT_DEVENV=true so the admin-console is disabled by default + # (app.config/devenv-mode). `enable-admin-console` in config.js + # re-enables it. + - PENPOT_DEVENV=true + networks: - default diff --git a/docs/technical-guide/developer/devenv.md b/docs/technical-guide/developer/devenv.md index 697d119b1c..20cd2d8a3c 100644 --- a/docs/technical-guide/developer/devenv.md +++ b/docs/technical-guide/developer/devenv.md @@ -508,6 +508,14 @@ Some examples of commonly used flags: The full list of available flags can be found in `common/src/app/common/flags.cljc`. +One flag is off by default in the devenv: the frontend compiles with +`PENPOT_DEVENV=true` in the development containers, which hides all +admin-console UI (links, routes, team menu entries) whether or not you created +a `config.js`. To test the admin-console against a local Nitrate instance, +reactivate it from your `config.js`: `var penpotFlags = "enable-admin-console";`. +Your flags are parsed after the injected default, so your entry wins. Production +builds are unaffected: `PENPOT_DEVENV` only exists in the devenv containers. + After creating or modifying this file, **reload the browser** (no need to restart anything). ### Backend flags via PENPOT_FLAGS diff --git a/frontend/shadow-cljs.edn b/frontend/shadow-cljs.edn index 9956823eeb..53ffb91aab 100644 --- a/frontend/shadow-cljs.edn +++ b/frontend/shadow-cljs.edn @@ -70,7 +70,8 @@ :compiler-options {:output-feature-set :es2020 :output-wrapper false - :warnings {:fn-deprecated false}} + :warnings {:fn-deprecated false} + :closure-defines {app.config/devenv-mode #shadow/env ["PENPOT_DEVENV" :as :bool :default false]}} :release {:closure-defines {goog.DEBUG false diff --git a/frontend/src/app/config.cljs b/frontend/src/app/config.cljs index 6bdfa17381..370159ca82 100644 --- a/frontend/src/app/config.cljs +++ b/frontend/src/app/config.cljs @@ -73,10 +73,26 @@ :browser :webworker)) +;; --- Compile-time devenv switch +;; +;; Set to true only by the devenv containers (PENPOT_DEVENV=true in +;; docker-compose.main.yml); production builds leave the default. When true, +;; the frontend disables the admin-console by default; `enable-admin-console` +;; in the user's `config.js` re-enables it (user flags parse after the +;; injected default and the last flag wins). +(goog-define devenv-mode false) + +(defn- apply-devenv-defaults + "Prepends the devenv default `disable-admin-console` before the user flags. + User flags are parsed after it, so `enable-admin-console` wins." + [devenv? flags] + (if devenv? (concat [:disable-admin-console] flags) flags)) + (defn- parse-flags [global] (let [flags (obj/get global "penpotFlags" "") - flags (sequence (map keyword) (str/words flags))] + flags (sequence (map keyword) (str/words flags)) + flags (apply-devenv-defaults devenv-mode flags)] (flags/parse flags/default flags))) (defn- parse-version diff --git a/frontend/test/frontend_tests/config_test.cljs b/frontend/test/frontend_tests/config_test.cljs new file mode 100644 index 0000000000..25c9b7d465 --- /dev/null +++ b/frontend/test/frontend_tests/config_test.cljs @@ -0,0 +1,27 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. +;; +;; Copyright (c) KALEIDOS SUBSIDIARY SL + +(ns frontend-tests.config-test + (:require + [app.common.flags :as flags] + [app.config :as cf] + [cljs.test :as t :include-macros true])) + +(def ^:private apply-devenv-defaults @#'cf/apply-devenv-defaults) + +(t/deftest devenv-default-disables-admin-console + (t/testing "in devenv, without user flags, the admin-console is disabled by default" + (t/is (not (contains? (flags/parse flags/default (apply-devenv-defaults true [])) + :admin-console)))) + (t/testing "in devenv, the user can re-enable it with enable-admin-console" + (t/is (contains? (flags/parse flags/default (apply-devenv-defaults true [:enable-admin-console])) + :admin-console))) + (t/testing "in devenv, the user's disable-admin-console is idempotent" + (t/is (not (contains? (flags/parse flags/default (apply-devenv-defaults true [:disable-admin-console])) + :admin-console)))) + (t/testing "outside devenv, no default is injected and the flags defaults apply" + (t/is (contains? (flags/parse flags/default (apply-devenv-defaults false [])) + :admin-console)))) diff --git a/frontend/test/frontend_tests/runner.cljs b/frontend/test/frontend_tests/runner.cljs index 465a0dc7f8..a0b6bce8a7 100644 --- a/frontend/test/frontend_tests/runner.cljs +++ b/frontend/test/frontend_tests/runner.cljs @@ -8,6 +8,7 @@ [frontend-tests.browser-history-test] [frontend-tests.code-gen-style-test] [frontend-tests.composable-tests.comp.sync-test] + [frontend-tests.config-test] [frontend-tests.copy-as-svg-test] [frontend-tests.data.auth-test] [frontend-tests.data.comments-batches-test] @@ -210,6 +211,7 @@ ['frontend-tests.basic-shapes-test 'frontend-tests.code-gen-style-test 'frontend-tests.composable-tests.comp.sync-test + 'frontend-tests.config-test 'frontend-tests.copy-as-svg-test 'frontend-tests.data.auth-test 'frontend-tests.data.comments-batches-test