Skip to content

Latest commit

 

History

History
105 lines (75 loc) · 4.21 KB

engine.md

File metadata and controls

105 lines (75 loc) · 4.21 KB

engine.py

Revision: 1 Last modified: 2026-12-04T19:00:00Z

Overview

engine.py is the outbound sync engine for the Issues mirror: plan / apply / verify, DB → tracker, one way (anchor §11.4.300(B),(C),(D),(E)).

It is pure given its adapters — all network behaviour lives behind the adapter interface, which is what makes the engine testable without a live tracker. Dry run is the default.

Issue identity is not the issue number

The identity of a mirrored issue is:

  • a title prefix of [ID] followed by one space, plus
  • a hidden footer <!-- workable-item: ID | sha256: HASH -->.

The issue number is never the identity. An issue number is allocated by the tracker, can change if an issue is transferred or recreated, and is not stable across hosts. Keying on the footer means the mirror can find its own issue even after a host-side renumbering, and it means a human editing the title is not mistaken for a new item.

A closed status is recognised by the prefix set Fixed, Implemented, Completed, Obsolete.

Prerequisites

  • python3.
  • A per-host adapter (see registry.py), which owns all network I/O.
  • The workable-items DB (source of truth).
  • Tokens supplied by the adapter layer by variable name; the engine never handles or prints them.

Usage examples

# via the facade (recommended)
python3 -m issue_sync.pipeline plan  --target github/vasic-digital/constitution
python3 -m issue_sync.pipeline apply --apply --target github/vasic-digital/constitution

# via the CLI front door
python3 -m issue_sync.cli plan --target github/vasic-digital/constitution

Exported surface

Name Kind Contract
plan(...) function Computes the changes that would be made. No writes.
apply(...) function Performs the planned changes, honouring the pre-write gate in payload.py.
verify(...) function Three-valued comparison of DB against tracker.
FOOTER regex Matches the hidden identity footer and captures (id, sha256).
CLOSED_STATUS_PREFIXES tuple ("Fixed", "Implemented", "Completed", "Obsolete") — the statuses that mean "closed upstream".

Exit codes

The engine is a library; the facade maps its results onto the package's three-valued convention:

Code Meaning
0 In sync / done.
1 Drift, conflict, or refused.
2 Cannot determine — never a pass.

Edge cases

  • An issue whose footer is absent. It is not ours to manage; the engine must not adopt it by title match alone.
  • An issue whose footer hash differs from the computed content hash. The upstream copy changed, so the write is treated as a potential conflict rather than a blind overwrite.
  • A title edited on the tracker. The title is not the identity, so this is a content change against the footer, not a new item.
  • An issue number changed upstream. Footer-based identity survives it.
  • A closed status. Recognised by the closed-prefix set, so reopening is a deliberate act.
  • A field outside the allowlist. Never sent — see payload.py (atm_id, type, status, title, severity only).
  • A partial leg failure. Reported per leg; the engine does not claim a global success.

Internal behaviour

  1. Reads the items to mirror from store (DB is truth).
  2. For each target, builds the normalised issue payload through payload — allowlist first, redaction gate before any write.
  3. Computes the canonical content hash that goes into the footer.
  4. Resolves which existing issue is ours by footer, never by number.
  5. In plan, reports the diff; in apply, performs it through the adapter.
  6. In verify, compares and returns three-valued.

Related scripts

Imports payload.py and visibility.py.

Called by cli.py and pipeline.py.

Uses adapters from registry.py / adapters/*.

See also docs/scripts/payload.md, docs/scripts/cli.md, docs/scripts/pipeline.md and docs/scripts/store.md.

Last verified

2026-12-04 — python3 -c "import ast;ast.parse(open('scripts/issue_sync/engine.py').read())" → exit 0. The footer regex matches <!-- workable-item: ATM-1 | sha256:<64 hex> --> (verified against the pattern in the source).