- GraphQL schema and database migrations (changes to SQL schema) are available in https://github.com/sourcegraph/artifacts
### GitHub Actions workflows
actionlint
### Markdown files
uv run rumdl check .
### Non-ASCII characters in tracked text files
uv run python tests/unicode_scan.py
### Python files
# Lint + auto-fix safe issues
uv run ruff check src/src_auth_perms_sync/ --fix
# Format
uv run ruff format src/src_auth_perms_sync/
# Type check
uv run pyright
# Basic test
uv run src-auth-perms-sync --helpAll testing runs through one entrypoint: tests/run.py. Output goes to the
console and to a per-run log file under logs/. Each level runs only its
own checks.
# Fast, no network (also what the pre-commit hook runs):
# lint, format, pyright, non-ASCII character scan, unit + fixture
# tests, CLI rejection matrix,
# randomized permission invariants
uv run tests/run.py
# End-to-end runs against the .env test instance with independent GraphQL
# read-back verification, and a wheel install smoke test
uv run tests/run.py --live
# Run a subset: comma-delimited test names, substring match
uv run tests/run.py --live full-overwrite-unions
uv run tests/run.py --live wheel,baseline
# Repeated timed runs with Jaeger trace retention, RSS sampling,
# optional kubectl load monitoring, and baseline comparison
uv run tests/run.py --performance --repeat 3
uv run tests/run.py --performance --baseline-command "uvx src-auth-perms-sync@latest" \
--fail-on-memory-regression-percent 10
# Regenerate fixture goldens after editing tests/e2e/fixtures/ cases
uv run tests/run.py --update-golden- Fixture cases live in
tests/e2e/fixtures/<case>/- see the README there for the format. Add cases there to cover new mapping behaviors. - For manual verification against a real instance, dry-run first (no
--apply), read the planned changes, then--applyon a scratch instance and inspect the before/after snapshots undersrc-auth-perms-sync-runs/<endpoint>/runs/.
- Package versions are derived from Git tags through
hatch-vcs. pyproject.tomlmust usedynamic = ["version"]; do not add a hard-codedproject.versionfor releases.- The release tag must be
vMAJOR.MINOR.PATCHand point at a commit reachable fromorigin/main. - The release workflow builds from the tag and checks that wheel and source distribution filenames match the tag version before publishing.
- The release workflow upgrades every dependency to its latest release that
pyproject.tomlallows (uv lock --upgrade), validates and builds the wheelhouse with that lockfile, and does not commit it. - Keep the checkout that builds the distributions unmodified:
hatch-vcsgives a modified checkout a development version. build-requirements.txtpins the build backend and everything it installs to hashes.uv buildfails on any build requirement missing from it, so a new entry inbuild-system.requiresneeds the file regenerated.- Validate the remote head of
mainbefore tagging it:
set -euo pipefail
VERSION_INPUT=<next-version>
VERSION="${VERSION_INPUT#v}"
[[ "${VERSION_INPUT}" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]]
git fetch origin --tags --prune
git switch main
git pull --ff-only
test "$(git rev-parse HEAD)" = "$(git rev-parse origin/main)"
uv lock --check
actionlint
uv run ruff check src/src_auth_perms_sync/ tests/
uv run ruff format --check src/src_auth_perms_sync/ tests/
uv run pyright
uv run python -m unittest discover -s tests
uv run src-auth-perms-sync --help
uv run rumdl check .
uv build --wheel --sdist --out-dir /tmp/src-auth-perms-sync-release-check --no-create-gitignore \
--build-constraints build-requirements.txt --require-hashes
rm -rf /tmp/src-auth-perms-sync-release-check- Tag the remote head of
maindirectly:
set -euo pipefail
VERSION_INPUT=<next-version>
VERSION="${VERSION_INPUT#v}"
GH_REPO="sourcegraph/src-auth-perms-sync"
[[ "${VERSION_INPUT}" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]]
git fetch origin --tags --prune
MAIN_COMMIT="$(git rev-parse origin/main)"
git tag -a "v${VERSION}" "${MAIN_COMMIT}" -m "Release v${VERSION}"
git push origin "v${VERSION}"
RUN_ID="$(
gh run list \
--repo "${GH_REPO}" \
--workflow release.yml \
--branch "v${VERSION}" \
--limit 1 \
--json databaseId \
--jq '.[0].databaseId // empty'
)"
test -n "${RUN_ID}"
gh run watch "${RUN_ID}" --repo "${GH_REPO}" --exit-status
gh release view "v${VERSION}" --repo "${GH_REPO}"- If a pushed tag points at the wrong commit, move it only after explicit human approval:
set -euo pipefail
VERSION_INPUT=<version-to-fix>
VERSION="${VERSION_INPUT#v}"
GH_REPO="sourcegraph/src-auth-perms-sync"
[[ "${VERSION_INPUT}" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]]
git fetch origin --tags --prune
git tag -f -a "v${VERSION}" origin/main -m "Release v${VERSION}"
git push origin "refs/tags/v${VERSION}" --force
RUN_ID="$(
gh run list \
--repo "${GH_REPO}" \
--workflow release.yml \
--branch "v${VERSION}" \
--limit 1 \
--json databaseId \
--jq '.[0].databaseId // empty'
)"
test -n "${RUN_ID}"
gh run watch "${RUN_ID}" --repo "${GH_REPO}" --exit-status
gh release view "v${VERSION}" --repo "${GH_REPO}"Violating these can silently grant the wrong users access to the wrong repos.
- bindID is always Sourcegraph username, never email. Multiple users
can share an email; renaming would let one user inherit another's
permissions. Enforced by
validate_site_config(). - Apply unions across rules, then overwrites per repo.
setRepositoryPermissionsForUsersreplaces a repo's explicit list, so compute the per-repo union BEFORE dispatching mutations. - Snapshots gate reversibility.
--applyand--restore --applydefault to before/after snapshots.--no-backupis an escape hatch; never make it the default or remove the snapshot path unprompted. - Retries fire only on transient transport failures (network errors, HTTP 408/429/500/502/503/504). GraphQL application errors propagate on the first attempt.
- Don't hallucinate GraphQL fields, read the schema in
dev/schema.gql
- Always use meaningful, human-understandable, whole words when naming things
- The human should be able to read a name, and understand what it is / does / stores, without needing to read a bunch of other code to figure it out
- Refactor the code to improve brevity, simplicity, and code style
A Python CLI that syncs Sourcegraph repo permissions and organizations from auth-provider data. Repo permissions map users to code-host repos; organization sync maps SAML groups to Sourcegraph org membership. Read README.md first.
CLI lives in src/src_auth_perms_sync/; invoke with uv run src-auth-perms-sync.
Strict pyright covers the package. Root modules are entrypoints only:
cli.py-main(), arg parsing, owns the CLI description. Module wrappers (Get/Set/Restore/SyncSamlOrgs) return result dataclasses and never install logging handlers; onlymain()runs CLI-mode logging.shared/- cross-workflow helpers: Sourcegraph auth-provider/user list helpers, shared GraphQL operations and TypedDicts, site-config validation, and SAML group parsing.shared/backups.pydefinesRunPaths: every filesystem path for one run, resolved once at the edge (resolve_run_paths) and threaded explicitly - never recompute paths from cwd or globals below the edge, and honorrun_paths.write_files(False under--no-files) before any disk write.
Business workflows live in packages:
permissions/- repo permission sync (command.py,maps.py,mapping.py,sourcegraph.py,snapshot.py,apply.py,queries.py,types.py). Add new mapping filters inpermissions/types.pyandpermissions/mapping.py.orgs/- SAML group -> Sourcegraph organization sync (command.py,queries.py,types.py).
- Python 3.11 + uv. Never invoke
pythondirectly; alwaysuv run .... uv run pyrightmust be clean. No# type: ignoreto silence - fix the underlying type.- Local tests use stdlib
unittest:uv run python -m unittest discover -s tests. - Dependencies wait 3 days after release (
src-py-libis exempt):exclude-newerinpyproject.toml,minimumReleaseAgeinrenovate.json, and--uploaded-prior-to P3Dwhere workflowspip installuv. pip reports a younger pin asNo matching distribution found. - To take a release younger than 3 days, add its name to
exclude-newer-packageunder[tool.uv], runuv lock --upgrade-package <name>, and remove it once the release is 3 days old. A young release that requires another young release needs both names. - Renovate merges its own pull requests when the checks pass, major updates
included. It opens one grouped pull request for minor and patch updates and
one lock file maintenance pull request a week, one pull request per major
update, and security fixes and
src-py-libat any time. - For Sourcegraph mutation-path changes, also verify by dry-running
--get/--set/--restoreagainst a real instance and diffing. If the expected changes look right, run--applyagainst a scratch instance and inspect before/after snapshots.
- Wrap non-trivial operations in
event(...); usestage(...)orlogging_context(...)at command / phase boundaries. from __future__ import annotationsat the top of new modules.- Paginate via
src_py_lib.clients.graphql.stream_connection_nodes(). - Concurrency: use
submit_with_log_context(...)when work leaves the main thread so structured log context is preserved.
Per the human's "meaningful, human-understandable, whole words" rule,
prefer full words over abbreviations. Two sweeps of renames have already
removed names like ev, ex, exc, cfg, conn, resp, fn,
op_name, cur, tok, sha, mem, sdl, ts, dt, cv, es,
rid, u, p, r, i, k, v, etc. Don't reintroduce them.
Short names that ARE acceptable (don't rewrite these on sight):
- Established domain abbreviations:
org/orgsfor Sourcegraph organizations, matching thesync-saml-orgscommand, theorgs/package, and thesync_saml_orgsconfig field. Do not expand these back toorganization(s)in identifiers. - TypedDict / dataclass fields that mirror the wire format:
id,url,kindonExternalServiceetc. These match GraphQL/JSON keys and renaming would break the contract. - Real English words even if short:
raw,head,old,new,key,value,name,kind. - Stdlib idioms:
ctxforcontextvars.copy_context(). - Loop / comprehension variables when the type is obvious from one
line of context is still discouraged - prefer
user,repo,provider,service,permission,node,entry,match,account,future,executor,exception,event,connection,response,timestamp,current,outcome,index,field_name.
If you need a 3-character abbreviation for a brand-new concept, write out the full word; almost any name shorter than ~6 chars probably should be longer.