Skip to content

Latest commit

 

History

History
123 lines (90 loc) · 6.1 KB

config.md

File metadata and controls

123 lines (90 loc) · 6.1 KB

config.py

Revision: 2 Last modified: 2026-12-04T21:12:29Z

Overview

config.py loads and validates .workable-items-sync.yaml, the declaration that turns the Issues mirror on (anchor §11.4.300(A)).

It is fail-closed: any problem is an error string, and an invalid declaration is never treated as "on". That is the safe direction for a mechanism that writes to external trackers.

But it is deliberately not fail-closed about absence: a missing file means the mechanism is OFF (default-OFF), and that is not an error. Not opting in is a legitimate state, not a fault — so a project that has never configured the mirror does not get a red build for it.

Two strictness details worth knowing

  • Duplicate mapping keys are refused. A plain yaml.safe_load lets the last key win silently, so enabled: false followed by enabled: true would quietly enable the mirror. _StrictLoader refuses the ambiguity instead.
  • Only true/false are booleans. A YAML yes / on / 1 is not silently coerced into a boolean decision about whether to write to external trackers.

Prerequisites

  • python3 and PyYAML (yaml is imported directly; its absence is an import failure, not a soft disable).
  • A .workable-items-sync.yaml in the project root if the mechanism is to be enabled.
  • No credentials are read here; the module imports redact for its primitives.

Usage examples

from issue_sync import config as cfgmod

result = cfgmod.load(path)          # UNCONFIRMED: exact loader name
if isinstance(result, str):
    # an error string -- fail closed
    raise SystemExit(2)
if result is None or result.disabled:
    pass                            # default-OFF, not an error

UNCONFIRMED: the exact loader/validator entry-point names were not read while writing this guide. Inspect them first: python3 -c "import issue_sync.config as c; print([n for n in dir(c) if not n.startswith('_')])".

Exported surface

Name Kind Contract
_StrictLoader class yaml.SafeLoader subclass that (1) refuses a duplicate mapping key and (2) reads only true/false as booleans.
load(...) / validator function Returns a validated config, or an error string on any problem. A missing file ⇒ mechanism OFF, not an error.

Exit codes

A library. Callers map its two outcomes onto the package's convention:

Outcome Effect
Missing file Mechanism OFF — callers exit 0 (disabled).
Valid config Proceed.
Any validation error Fail closed — callers report 2 (cannot determine) rather than enabling a partially understood configuration.

Edge cases

  • No config file. Default-OFF, exit 0. Not an error.
  • A duplicate key. Refused — this is how "enabled: false then enabled: true" is prevented from silently enabling writes.
  • enabled: yes / on / 1. Not coerced to a boolean decision; strict reading applies.
  • A malformed YAML document. An error string; fail closed.
  • A config with an unknown key. Validation is the seam where an unrecognised declaration is caught rather than ignored.
  • PyYAML missing. Import failure — cannot determine, never a silent "disabled".
  • A config that enables the mirror but names no targets. Valid-but-empty scope; nothing to mirror, and the caller must not report success for work it did not do.

Internal behaviour

  1. Checks whether the config file exists; absent ⇒ mechanism OFF (not an error).
  2. Parses with _StrictLoader: duplicate keys refused, booleans restricted to true/false.
  3. Validates the declared structure and values; any problem returns an error string.
  4. Returns the validated configuration for mode.py, cli.py and pipeline.py to act on.

Related scripts

Imported by mode.py, cli.py, pipeline.py, registry.py (indirectly) and the rest of the package.

Related: redact.py (imported here for its primitives), mode.py (the one-word effective mode, decided by this same validator).

See also docs/scripts/mode.md, docs/scripts/cli.md and docs/scripts/redact.md.

The other config — scripts/pr/lib/config.sh (different file, same basename)

The §11.4.18 ratchet keys a guide on the script's BASENAME, so docs/scripts/config.md is the one guide the tool credits to every config.{sh,py} in the tree. The pull-request delivery engine's scripts/pr/lib/config.sh is a DIFFERENT program and is documented here so that credit is not misleading.

scripts/pr/lib/config.sh loads and validates config/delivery.conf, the §11.4.297(A) delivery declaration:

  • Key set is closed and typed. 32 keys, each declared R required, S:<a|b> closed set, I positive integer, N non-negative, L comma list, T free text, B on|off or M none|<positive int>.
  • Fail-closed on anything it cannot read: an absent or unreadable file (config_absent), a line without =, a bad key shape or an empty key (config_malformed_line:<n>), an unknown key (config_unknown_key), a repeated key (config_duplicate) and a value outside its closed set (config_invalid_value:<key>) are all refusals with exit 6 — never a silently ignored line.
  • Closed-set membership is exact: the set is matched as |a|b| against |value|, so a substring test can never accept pr inside prerelease.
  • Typed refinements: pr_repository must be owner/repo, base a legal branch name, branch_prefix one path component, review_fanout_min at most 8, and approval_mode=approve-event requires an approver distinct from pr_assignees (config_invalid_combination:approval_mode).
  • pr_cfg_audit prints every key with its closed set, so the data can be reviewed without reading code: bash scripts/pr/pr_deliver.sh config --audit.

Full reference: docs/manuals/pr_delivery_engine_manual.md §5.

Last verified

2026-12-04 — python3 -c "import ast;ast.parse(open('scripts/issue_sync/config.py').read())" → exit 0. python3 -c "import issue_sync.config as c; print(c._StrictLoader.__name__)" prints _StrictLoader.