Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions .claude/rules/infrastructure.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ outside the compose file — remap freely to hit the assigned host number.
|---|---|---|
| **Frontend / the app's main entry point** | `8080` | all interfaces |
| **Backend / admin / API / a second web surface** | `8081` | all interfaces |
| **Mail catcher — browsable inbox** | `1080` | all interfaces |
| **Mail catcher — SMTP the app delivers to** | `1025` | all interfaces |
| **Mail catcher — browsable inbox** | `1080` | **`127.0.0.1` only** |
| **Mail catcher — SMTP the app delivers to** | `1025` | **`127.0.0.1` only** |
| **The app's database**, whatever the engine | `3307` | **`127.0.0.1` only** |
| Cache / broker (Redis), *only if the host needs it* | `6380` | **`127.0.0.1` only** |
| Everything else | **not published** | — |
Expand All @@ -57,9 +57,15 @@ every webhook test.
**The mail catcher is `1080`, and this reverses an earlier decision.** The convention was
briefly MailHog's own default of `8025`, chosen so a stack adding MailHog out of the box would
need no remapping. That optimised for the wrong thing: it made the port depend on *which tool*
caught the mail, when the whole registry is meant to depend on *what the port is for*. MailHog
therefore publishes `"1080:8025"`. The SMTP side needs no thought — MailHog and MailCatcher
both listen on `1025`.
caught the mail, when the whole registry is meant to depend on *what the port is for*.

**The mail catcher's tool is fixed too: Mailpit** (`axllent/mailpit` at an exact tag, never
`:latest`), published as `"127.0.0.1:1080:8025"` and `"127.0.0.1:1025:1025"`. Fixing only the
ports let each repo take whatever was current — MailCatcher, MailHog, Mailpit all ran at once.
MailHog has had no release since 2020; Mailpit is maintained and moves through the dependency
gate like any image. One tool also means one API for headless mail tests: Mailpit's
`/api/v1/messages`. Migrating off MailHog moves its `/api/v2/messages` readers too — the JSON
shape differs.

**The database is `3307` whatever the engine** — MySQL, PostgreSQL, anything. Same principle:
one saved connection in a DB client serves every project, and "3307" means "the app I am
Expand Down Expand Up @@ -115,6 +121,25 @@ fails on the laptop, and a runbook cannot name a container that only exists in o
default in the compose file** — `${COMPOSE_PROJECT_NAME:-invotrack}-web` — because a repo with no
`.env` in development expands the bare form to nothing and names the container `-web`.

### The project name gets the same fallback, as `name:` at the top of the base file

```yaml
name: ${COMPOSE_PROJECT_NAME:-allegroit-dk}
```

**Every `docker-compose.yml` opens with this, with the site's identity as the default.** The
container-name default above is not enough on its own: without a `.env`, Compose takes the
*folder* name as the project. A git worktree never has a `.env`, since it is gitignored, so it
became its own project (measured on allegroit-dk, 2026-10-22: project, image and network all
named `php-8-5-12-0f94b3` after the worktree folder). Its literal `container_name`s stayed the
same as the main checkout's. Compose then saw two different projects fighting over one container
name: `up` in one fails with `Conflict. The container name ... is already in use`, and `down` in
one does not see the other's containers.

The variable still wins wherever it is set, so the server's `.env` and a multi-instance repo
like WAPPIT (`wappit-api-staging`) behave exactly as before. The fallback covers only the
checkout that has no `.env`, and gives it the site's name instead of the folder's.

### The service name is on the shared proxy network too

A stack that joins `nginx-proxy-network` registers **both** its `container_name` and its *service
Expand All @@ -139,7 +164,7 @@ the service key.

**Only proxy-facing services need the unified name.** The collision this fixes is on
`nginx-proxy-network`, so it applies to the service that joins it — the web one. A `mysql`,
`redis` or `mailhog` service lives on the project's own `default` network, which is per-project
`redis` or `mailpit` service lives on the project's own `default` network, which is per-project
and cannot collide, so it keeps its short generic key and only needs a distinct
`container_name` for `docker ps` to be readable. **Do not rename an internal service for
tidiness**: the service key *is* the DNS name its siblings connect to, so renaming `mysql` to
Expand Down
40 changes: 20 additions & 20 deletions .claude/rules/secrets.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ In rough order of preference. Pick the first that fits the stack.
2. **A gitignored `.env`.** Fine, and the estate already relies on it — but only the repo's own
`.gitignore` counts; a global ignore is a backstop that does not travel with the clone
(`self-contained-repo.md`). Check with it off: `git -c core.excludesFile= check-ignore -v .env`.
`.env.example` is committed and carries the **key names with empty values**.
**Ignore every copy: `.env*`** (`gitignore-build-output` enforces it) — a copy is the same
credential; on 2026-10-10 a `.env.bak-staging` sat unignored in a production checkout, one
`git add -A` from a push. Admit the example on purpose with `!.env.example`. Never back up a
`.env`: a fresh `.env.example` plus the secret store restores everything in it.
3. **Generated at first run and printed once.** The strongest option where it fits: nothing to
leak because nothing was written down. Good for a first-admin bootstrap, awkward for a demo
cast that documentation names.
Expand All @@ -47,28 +50,26 @@ In rough order of preference. Pick the first that fits the stack.
example, and its lesson applies here: make it *obviously* fake, because a realistic-looking
one invites somebody to "fix" it into a real credential.

## Seeders read credentials; they never contain them
## Seed test systems through an explicit local step — never through configuration

A seeder needs a password to hash, so it takes one — from configuration, never a literal — and
it **refuses rather than defaulting**: a fallback to a built-in value is the committed value
that then gets used wherever nobody set the variable. Throw and name the missing key
(`configuration["Demo:Password"] ?? throw ...`). Two more: **hash it, never store it**, even for
demo data; and **gate it on the environment**, with the guard in the seeder rather than the
caller's good intentions.
Test systems are seeded; the **mechanism** is the rule. A seeder, restore or app that reads an
account password from `.env`, a compose variable or an app setting is a standing "set a
password, get an admin" path on every machine that runs it — whoever can set that value gets
in (`seeded-credential-config` flags the key). Instead (snippets: `templates/seed-users/`):

**And it validates what it was given.** Writing a hash directly skips the framework's password
validators, so a placeholder value yields an account holding a password the application would
refuse — measured: a demo admin whose password was its own e-mail address, three database wipes
before anyone found out. Check configured credentials against the *real* validators at startup;
refuse to start otherwise, naming the failing rule and never the value.
- **A seed command with no values**: reads the accounts as JSON on **stdin**, **refuses unless
the system is local** (guard in the command, not the caller), validates each password against
the *real* validators (a direct hash skips them — a demo admin once held its own e-mail
address as password), **hashes, never stores**, prints only names.
- **A PC-side wrapper** pipes the values file into it; on a server there is nothing to pipe.
- **Logins without the password**: a local-only, single-use, short-lived link — never typed into
a browser through a tool call. **A live guard** fails if the test accounts exist in production.

## The estate's standard local accounts

`localadmin@allegroit.dk` and `localuser@allegroit.dk` are seeded in every repo that needs a
local superadmin or a plain test user, so that one set of credentials works everywhere. **The
addresses may be committed; the passwords may not.** Their values live in the identity notes
under `~/.claude/memory/` — which is exactly the split this file describes, and the reason the
values are in memory rather than in any repo.
`localadmin@allegroit.dk` and `localuser@allegroit.dk` are seeded that way wherever a repo needs
a local login. **The addresses may be committed; the passwords may not**, not even as an empty
key: they are in `~/.claude/shared/dev-seed-users.secret.json`, piped unread, never read by Claude.

## A secret must never reach the client, git or no git

Expand All @@ -90,7 +91,6 @@ git diff --cached | grep -iE 'password|secret|api[_-]?key|token'
```

A hit is not automatically wrong — a key *name* is fine — but every hit deserves the question.
And when a credential has already been committed, rotating it is part of the fix, not an
optional follow-up: history keeps the old one whatever the working tree says.
A committed credential is rotated as part of the fix: history keeps it whatever the tree says.

Source of truth: engineering-standards/claude/rules/secrets.md
2 changes: 1 addition & 1 deletion .claude/rules/self-contained-repo.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ the next — usually without saying why, because the failure is in what is *abse
| Toolchain version | `global.json`, `.python-version`, `.nvmrc`, `packageManager`, `require.php` |
| Repo-local tools and dev dependencies | `.config/dotnet-tools.json`, `requirements*.txt` or a `pyproject.toml` dev group, `devDependencies`, `require-dev` |
| The pack's own prerequisites | `engineering_standards/requirements.txt`, shipped with the pack |
| Ignore rules | the repo's own `.gitignore`, `.env` included (`gitignore-missing` reads only that file) |
| Ignore rules | the repo's own `.gitignore`, every `.env*` copy included and `!.env.example` re-admitted on purpose (`gitignore-missing` reads only that file) |
| Commit gate | `engineering_standards/hooks/` plus the bootstrap that points git at them |
| Configuration keys | `.env.example`: every key, empty values |
| The one documented step | the README: clone → `.env` → build → test → run, every command spelled out |
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
!.claude/rules/

# Environment
.env
.env*
!.env.example

# WordPress uploads (synced separately, not in git)
wp-content/uploads/*
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ database).
- `dev.bat cli` passed the word `cli` on to WP-CLI.
- Line endings are pinned in `.gitattributes`: a clone without `core.autocrlf=true`
checked the batch files out LF-only, where cmd can miss their labels.
- CI's scanner tests are green again: the pack copy (2026.10.08-2) read its
`.gitattributes` template from a path only the pack itself has. Re-synced to pack
2026.10.14-3, which ships the template in `engineering_standards/templates/`.
- `.gitignore` ignores every `.env*` file, not only `.env` (`.env.example` stays
tracked) — a `.env.local` or `.env.bak` holds the same credentials.

## [1.0.0] - 2026-06-22

Expand Down
62 changes: 44 additions & 18 deletions engineering_standards/check-source-limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
(an exception's own text or a bare status code reaching the user -- see
standards_user_errors.py), the constants family
(config-default-in-code, const-environment-literal, plus const-duplicated-literal on
whole-tree scans -- see standards_constants.py), the deployment-contract family (compose-port,
whole-tree scans -- see standards_config_defaults.py and standards_constants.py), the
deployment-contract family (compose-port,
compose-container-name, compose-overlay-name, deploy-gate, env-example-compose),
plus the documentation family on whole-tree scans (docs-missing, docs-frontmatter,
docs-broken-link, docs-orphan-page, docs-stale-symbol, claude-md-length -- see
Expand Down Expand Up @@ -58,6 +59,7 @@
import argparse
import sys
from pathlib import Path
from typing import NamedTuple

# Import the sibling module by path rather than relying on the caller's cwd: the commit
# hook and the CI job both invoke this script from the repo root, not from engineering_standards/.
Expand All @@ -82,7 +84,7 @@
Violation,
)
from standards_coverage import check_coverage # noqa: E402 (same reason)
from standards_dispatch import check_source_file # noqa: E402 (same reason)
from standards_dispatch import check_migration_file, check_source_file # noqa: E402 (same reason)
from standards_docs import check_documentation # noqa: E402 (same reason)
from standards_exemption_report import ( # noqa: E402 (same reason)
collect_exemptions,
Expand All @@ -102,13 +104,24 @@
from standards_registry import NEVER_BASELINED, TOOLCHAINS # noqa: E402,F401 (same reason)
from standards_repository import repository_violations # noqa: E402 (same reason)
from standards_rules import check_rules # noqa: E402 (same reason)
from standards_scope import should_check # noqa: E402 (same reason)
from standards_scope import should_check, should_check_migration # noqa: E402 (same reason)
from standards_tests import check_tests_cover_modules # noqa: E402 (same reason)
from standards_userdocs import check_userdocs, unsynced_change_notes # noqa: E402 (same reason)


def candidate_files(root: Path, config: CheckConfig, only: list[Path] | None = None) -> list[Path]:
"""Every in-scope file, or the in-scope subset of `only`.
class ScanScope(NamedTuple):
"""What one run reads: the in-scope files, and the migrations only a few rules may see."""

paths: list[Path]
migrations: list[Path]


def candidate_files(root: Path, config: CheckConfig, only: list[Path] | None = None) -> ScanScope:
"""Every in-scope file, or the in-scope subset of `only` -- plus the migrations among them.

The migrations come out of the SAME walk rather than a second one: in a consumer with a
`node_modules/` the walk is the expensive half of a scan, and two resolvers would also be
two answers to "what was examined". `should_check_migration` explains why they exist.

One resolver for all three collectors, so a scoped run cannot accidentally walk the
tree for exemptions while checking a subset for violations -- the two would then
Expand All @@ -117,8 +130,8 @@ def candidate_files(root: Path, config: CheckConfig, only: list[Path] | None = N

`only` is filtered through the same `should_check` predicate rather than trusted: a
staged path may be a deleted file, a submodule, or something the scanner is not
supposed to read (a migration, vendored code), and naming it explicitly does not make
it in scope.
supposed to read (vendored code), and naming it explicitly does not make it in scope. A
staged migration is filtered the same way, into the migration route and nothing more.

FILES GIT IGNORES ARE NOT SCANNED. The walk reads the filesystem, but every rule here
is about what a repository CONTAINS -- so a path git is told to ignore, and does not
Expand All @@ -140,8 +153,12 @@ def candidate_files(root: Path, config: CheckConfig, only: list[Path] | None = N
paths = [path for path in paths if path.is_relative_to(root)]

ignored = ignored_files(root)
files = [path for path in paths if path.is_file() and path not in ignored]

return [path for path in paths if path.is_file() and path not in ignored and should_check(path, root, config)]
return ScanScope(
[path for path in files if should_check(path, root, config)],
[path for path in files if should_check_migration(path, root, config)],
)


def collect_oversized_files(root: Path, config: CheckConfig, paths: list[Path]) -> dict[str, int]:
Expand Down Expand Up @@ -173,12 +190,13 @@ def write_baseline(
that gates a write are standards_baseline.py's. Scope narrowing is ignored on purpose --
see write_baseline_file for what a partial baseline silently destroys.
"""
paths = candidate_files(root, config)
scope = candidate_files(root, config)
paths = scope.paths
oversized = collect_oversized_files(root, config, paths)
member_violations = sorted(
violation_key(violation, root)
for violation in (
*collect_violations(root, config, oversized, paths),
*collect_violations(root, config, oversized, scope),
*check_documentation(root, config),
*check_coverage(root, config),
*check_userdocs(root, config),
Expand All @@ -195,16 +213,21 @@ def write_baseline(
return write_baseline_file(baseline_path, config, oversized, member_violations, consent_flag)


def collect_violations(root: Path, config: CheckConfig, baseline: dict[str, int], paths: list[Path]) -> list[Violation]:
def collect_violations(root: Path, config: CheckConfig, baseline: dict[str, int], scope: ScanScope) -> list[Violation]:
violations: list[Violation] = []

for path in paths:
for path in scope.paths:
lines = read_source_lines(path)
if lines is None:
continue

violations.extend(check_source_file(path, lines, config, baseline, root))

for path in scope.migrations:
lines = read_source_lines(path)
if lines is not None:
violations.extend(check_migration_file(path, lines))

return violations


Expand Down Expand Up @@ -330,7 +353,7 @@ def baseline_argument_error(arguments: argparse.Namespace) -> int | None:
def print_summary(
root: Path,
config: CheckConfig,
paths: list[Path],
scope: ScanScope,
only: list[Path] | None,
remaining: list[Violation],
grandfathered: list[Violation],
Expand All @@ -345,7 +368,9 @@ def print_summary(
for setting, value, reason in config.tuning:
print(f"tuned: {setting} = {value} -- {reason}")

exemptions = collect_exemptions(root, config, paths)
# File-scoped markers only, and no rule on the migration route reads one -- so a marker in
# a migration would be printed here as honoured while nothing honours it.
exemptions = collect_exemptions(root, config, scope.paths)
for relative, rule, reason in exemptions:
print(f"exempt: {relative} [{rule}] -- {reason}")

Expand All @@ -355,7 +380,7 @@ def print_summary(
print(f"\ncheck-source-limits: {len(remaining)} violation(s)", file=sys.stderr)
return 1

notes = [f"{len(paths)} file(s)" if only is not None else "whole tree"]
notes = [f"{len(scope.paths) + len(scope.migrations)} file(s)" if only is not None else "whole tree"]
if grandfathered:
notes.append(f"{len(grandfathered)} grandfathered")
if exemptions:
Expand Down Expand Up @@ -400,7 +425,8 @@ def main(argv: list[str]) -> int:
if scope_error:
return scope_error

paths = candidate_files(root, config, only)
scope = candidate_files(root, config, only)
paths = scope.paths

# Named rather than silently tolerated: these are the only files where reading the
# working tree can disagree with what is actually being committed.
Expand All @@ -414,7 +440,7 @@ def main(argv: list[str]) -> int:
oversized_baseline, known_violations = {}, set()
else:
oversized_baseline, known_violations = load_baseline(baseline_path)
violations = collect_violations(root, config, oversized_baseline, paths)
violations = collect_violations(root, config, oversized_baseline, scope)

# The one check about the REPOSITORY rather than about a file, so it runs only on a
# whole-tree scan. Running it at commit would block every commit in a repo whose
Expand Down Expand Up @@ -445,7 +471,7 @@ def main(argv: list[str]) -> int:
return print_summary(
root,
config,
paths,
scope,
only,
remaining,
grandfathered,
Expand Down
3 changes: 2 additions & 1 deletion engineering_standards/standards_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ class CheckConfig:
# The judgment layer judged as a budget -- see standards_rules.py. On by default in every
# repo, because the cost it measures is paid in every repo that received the rules.
check_rules: bool = True
# Where a value that may change is allowed to live -- see standards_constants.py. One flag
# Where a value that may change is allowed to live -- see standards_config_defaults.py and
# standards_constants.py. One flag
# for all three shapes, because a repo that genuinely disagrees disagrees with the premise
# rather than with one detector. Off is a real answer for a repo with no deployment of its
# own -- a library, a shared schema package -- where "read it from the environment" names
Expand Down
Loading
Loading