Skip to content

The default reference: is chosen by the election date (Sourcery on #19) - #27

Merged
brettheap merged 2 commits into
mainfrom
fix/reference-by-election-date
Sep 4, 2026
Merged

brettheap merged 2 commits into
mainfrom
fix/reference-by-election-date

Conversation

@brettheap

@brettheap brettheap commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Lane: codex-intake-shape
Claim: #26 (comment)

What

Closes #26. Sourcery's finding on #19: with --reference omitted, both scaffold-project.py and adopt-project.py wrote the ratified openxFactory docs/project-repo-schema.md regardless of --elected-on, so a project dated before 2026-09-02 claimed its election followed a document that did not yet exist. Ruled by Brett Heap, 2026-09-04: "fix the sourcery finding on the default reference by election date."

  • scripts/shape_materialize.py: STAGED_REFERENCE, RATIFICATION_DATE (2026-09-02), election_date() (parse-or-refuse, election-date-malformed) and default_reference(elected_on) — staged fragment strictly before the ratification date, ratified document on or after. DEFAULT_REFERENCE keeps its name and value; other importers are unaffected.
  • scaffold-project.py: --reference defaults to None; the date is parsed BEFORE anything is created even when an explicit --reference is given, then reference = args.reference or default_reference(elected_on). The printed plan marks a date-chosen default (chosen by the election date).
  • adopt-project.py: same at plan time, and at execute a plan file that omits reference: resolves from the plan's OWN elected_on, never from the day the split runs.
  • README.md and templates/assembly-root/project.yaml: the rule, in one sentence each. README cap 509 → 513 in tests/test_repo_hygiene.py.
  • tests/test_reference_default.py (18 tests): boundary dates 2026-09-01 / -02 / -03, malformed dates refused, scaffold and adopt end to end offline for a back-dated and an on-date election, and the explicit override winning in both.

Left as is, on purpose

At execute, a plan file carrying BOTH an explicit reference: and a malformed elected_on: still reaches the manifest, exactly as before this change; the scaffolded project's own validate-manifest.py refuses it at make bootstrap (manifest-elected-on). Catching it earlier belongs in adopt-project.py check as a FINDING, which is outside this ruling — noted here rather than widened into it.

Evidence

  • python3 -m pytest tests -q: 367 passed.
  • python3 scripts/validate-repository-naming.py --explain Atlas Atlas-spec Atlas-code: exit 0, three expected classifications.
  • setup.sh forwards --elected-on/--reference verbatim after --; scripts/family.py and family.yaml carry no reference — confirmed, unchanged.

🤖 Generated with Claude Code

Summary by Sourcery

Select project schema references according to the election date while preserving explicit overrides and validating election dates early.

Bug Fixes:

  • Choose the default project schema reference based on the election date, using the staged document before 2026-09-02 and the ratified document on or after that date.
  • Ensure scaffold and adoption workflows reject malformed election dates before creating repositories or plans and resolve omitted adoption references from the plan's own election date.
  • Preserve explicit --reference overrides in both scaffold and adoption workflows.

Enhancements:

  • Document the election-date-based reference rule and surface when a scaffold reference was selected automatically.

Documentation:

  • Update the README and project template to explain date-based reference selection and explicit overrides.

Tests:

  • Add coverage for ratification boundaries, malformed dates, overrides, and end-to-end scaffold and adoption reference generation.

…ay the tool runs

Sourcery on #19: `scaffold-project.py` and `adopt-project.py` wrote
`DEFAULT_REFERENCE` — the ratified `openxFactory docs/project-repo-schema.md`
— whenever `--reference` was omitted, whatever `--elected-on` said. A project
dated before the 2026-09-02 ratification therefore recorded a manifest
claiming its election followed a document that did not exist that day, when
the doctrine's own sentence is that an earlier election followed the staged
fragment.

`shape_materialize.default_reference(elected_on)` now chooses: the staged
fragment path strictly before 2026-09-02, the ratified document on or after.
`election_date()` parses the date first and REFUSES a malformed value
(`election-date-malformed`) before anything is created, whether or not an
explicit `--reference` would have made the date irrelevant to the choice —
a manifest field no reader can parse is not something an override should let
through. Both tools resolve the reference through it: the scaffold at plan
time (the printed plan marks a date-chosen default), adopt at `plan` time and
again at `execute` for a plan file that omits `reference:`, resolved from the
plan's OWN `elected_on`, never from the machine's calendar. An explicit
`--reference` still wins. `DEFAULT_REFERENCE` keeps its name and value.

README and the manifest template say the rule; `tests/test_reference_default.py`
covers the boundary dates, the refusal, both tools end to end offline, and the
override. README cap 509 -> 513.

Closes #26.

Lane: codex-intake-shape
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI lite review requested due to automatic review settings September 4, 2026 05:20
@brettheap

Copy link
Copy Markdown
Contributor Author

@codex review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 2 days and 9 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@sourcery-ai

sourcery-ai Bot commented Sep 4, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR fixes the default manifest reference by centralizing election-date parsing and selecting the staged schema fragment before 2026-09-02 or the ratified document on and after that date. Scaffold and adoption paths validate dates early, preserve explicit reference overrides, and ensure adoption execution uses the plan’s election date; documentation and comprehensive offline tests accompany the change.

Sequence diagram for date-aware scaffold reference

sequenceDiagram
    participant User
    participant Scaffold as scaffold-project.py
    participant Materializer as shape_materialize.py
    participant Manifest as project.yaml
    User->>Scaffold: run --elected-on [optional] --reference [optional]
    Scaffold->>Materializer: election_date(elected_on)
    alt malformed elected_on
        Materializer-->>Scaffold: Refusal election-date-malformed
        Scaffold-->>User: refuse before creating project
    else valid elected_on
        alt explicit reference supplied
            Scaffold->>Scaffold: use args.reference
        else reference omitted
            Scaffold->>Materializer: default_reference(elected_on)
            Materializer-->>Scaffold: staged or ratified reference
        end
        Scaffold->>Manifest: write reference and elected_on
        Scaffold-->>User: print selected reference
    end
Loading

Sequence diagram for plan-based adoption reference resolution

sequenceDiagram
    participant User
    participant Adopt as adopt-project.py
    participant Plan as adoption plan
    participant Materializer as shape_materialize.py
    participant Manifest as project.yaml
    User->>Adopt: plan --elected-on [optional] --reference [optional]
    Adopt->>Materializer: election_date(elected_on)
    Adopt->>Materializer: default_reference(elected_on)
    Adopt->>Plan: write elected_on and reference
    User->>Adopt: execute plan
    Adopt->>Plan: read plan
    alt plan has reference
        Adopt->>Manifest: use plan reference
    else plan omits reference
        Adopt->>Materializer: default_reference(plan elected_on)
        Materializer-->>Adopt: staged or ratified reference
        Adopt->>Manifest: use reference from plan elected_on
    end
Loading

Flow diagram for election-date reference selection

flowchart TD
    A["elected_on input"] --> B["election_date(elected_on)"]
    B -->|"malformed"| C["Refusal: election-date-malformed"]
    B -->|"valid date"| D{"Before 2026-09-02?"}
    D -->|"yes"| E["STAGED_REFERENCE"]
    D -->|"no"| F["DEFAULT_REFERENCE"]
    E --> G["reference"]
    F --> G
    H["explicit --reference"] --> I["reference override"]
    G --> J["project.yaml manifest"]
    I --> J
Loading

File-Level Changes

Change Details Files
Centralize election-date parsing and date-based default reference selection while preserving the existing ratified-reference constant.
  • Add staged and ratified reference constants with a 2026-09-02 boundary.
  • Reject malformed election dates with a structured refusal.
  • Select the staged reference before ratification and the ratified reference on or after it.
scripts/shape_materialize.py
Make scaffolding resolve and validate election metadata before creating project resources, with explicit references taking precedence.
  • Change --reference to default to None and resolve it from --elected-on.
  • Validate dates even when an explicit reference is supplied.
  • Show when the reference was chosen automatically in the printed plan.
scaffold-project.py
Make adoption plans and executions resolve omitted references from the plan's election date rather than execution date.
  • Validate and resolve the reference during plan creation.
  • At execution, derive omitted references from the plan's own elected_on value.
  • Document the updated command-line default behavior.
adopt-project.py
Document the date-dependent reference rule in repository and generated project metadata.
  • Explain the staged-versus-ratified default and explicit override.
  • Update the generated project template comments.
  • Adjust the README line-count hygiene cap.
README.md
templates/assembly-root/project.yaml
tests/test_repo_hygiene.py
Add focused unit and offline end-to-end coverage for boundary selection, validation, overrides, and adoption behavior.
  • Cover dates before, on, and after ratification.
  • Verify malformed dates fail before scaffold or plan output is created.
  • Verify scaffold and adopt produce the correct references and honor explicit overrides.
tests/test_reference_default.py

Assessment against linked issues

Issue Objective Addressed Explanation
#26 Choose the default reference: from --elected-on: use the staged fragment for elections before 2026-09-02 and the ratified document for elections on or after that date, in both scaffold-project.py and adopt-project.py. ✅
#26 Preserve an explicit --reference override while resolving omitted references in adoption from the plan's own elected_on date rather than the execution date. ✅
#26 Refuse malformed --elected-on values instead of comparing or silently accepting them, and document and test the date-based default behavior. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new “parse-or-refuse” behavior for --elected-on is undermined by args.elected_on or <today> treating an explicitly provided empty string as omitted, bypassing validation and changing behavior silently.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR fixes the default reference: selection so it’s derived from the project’s election date (--elected-on), preventing back-dated projects from recording a schema document that did not yet exist at the time of election.

Changes:

  • Introduces election-date-aware default reference selection (default_reference) with early election date validation in scripts/shape_materialize.py.
  • Updates scaffold-project.py and adopt-project.py so --reference defaults to date-derived behavior and plans/executions resolve omitted reference: from the plan’s own elected_on.
  • Adds end-to-end and boundary tests for default selection, malformed dates, and explicit overrides; updates README/template wording and README length cap.
File summaries
File Description
scripts/shape_materialize.py Adds RATIFICATION_DATE, staged vs ratified reference constants, election_date() validation, and default_reference() selection logic.
scaffold-project.py Validates --elected-on before creating anything and chooses the default reference from election date unless explicitly overridden.
adopt-project.py Applies the same date validation/defaulting at plan time and resolves missing reference: during execute from the plan’s own elected_on.
README.md Documents the election-date-based default reference rule and that --reference overrides it.
templates/assembly-root/project.yaml Updates template comments to describe the election-date-derived default and override behavior.
tests/test_reference_default.py Adds unit + end-to-end coverage for boundary dates, malformed inputs, and override behavior.
tests/test_repo_hygiene.py Updates README length cap for the expanded documentation.
Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread adopt-project.py
@@ -564,6 +564,11 @@ def cmd_plan(args) -> int:
"adopt-no-org", "the source has no `origin` to read an "
"organisation from", "Remediation: pass --org <org>.")
args.elected_on = args.elected_on or _dt.date.today().isoformat()
Comment thread scaffold-project.py
@@ -386,6 +394,11 @@ def _scaffold(args) -> int: # noqa: C901
project_id = checked_value("--id", args.id or project.lower())
display = args.name or project
elected_on = args.elected_on or _dt.date.today().isoformat()
…dex-first) into fix/reference-by-election-date

One conflict, in adopt-project.py _template_values: main derives project_id
via plan.project_id (#24); this branch reads elected_on once beside it. Both kept.

Lane: codex-intake-shape
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI review requested due to automatic review settings September 4, 2026 05:24
@sonarqubecloud

sonarqubecloud Bot commented Sep 4, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The changes consistently implement election-date-based default reference selection across scaffold/adopt, preserve explicit overrides, and are backed by targeted unit and end-to-end tests.

Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@brettheap
brettheap merged commit af9d3f5 into main Sep 4, 2026
4 checks passed
@brettheap
brettheap deleted the fix/reference-by-election-date branch September 11, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default reference: ignores --elected-on: a pre-2026-09-02 election records the ratified document (Sourcery on #19)

2 participants