Repository navigation
The default reference: is chosen by the election date (Sourcery on #19) - #27
Conversation
…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]>
|
@codex review |
There was a problem hiding this comment.
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.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Reviewer's GuideThe 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 referencesequenceDiagram
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
Sequence diagram for plan-based adoption reference resolutionsequenceDiagram
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
Flow diagram for election-date reference selectionflowchart 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
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
🟡 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 inscripts/shape_materialize.py. - Updates
scaffold-project.pyandadopt-project.pyso--referencedefaults to date-derived behavior and plans/executions resolve omittedreference:from the plan’s ownelected_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.
| @@ -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() | |||
| @@ -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]>
|
There was a problem hiding this comment.
🟢 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



Lane: codex-intake-shape
Claim: #26 (comment)
What
Closes #26. Sourcery's finding on #19: with
--referenceomitted, bothscaffold-project.pyandadopt-project.pywrote the ratifiedopenxFactory docs/project-repo-schema.mdregardless 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) anddefault_reference(elected_on)— staged fragment strictly before the ratification date, ratified document on or after.DEFAULT_REFERENCEkeeps its name and value; other importers are unaffected.scaffold-project.py:--referencedefaults toNone; the date is parsed BEFORE anything is created even when an explicit--referenceis given, thenreference = args.reference or default_reference(elected_on). The printed plan marks a date-chosen default(chosen by the election date).adopt-project.py: same atplantime, and atexecutea plan file that omitsreference:resolves from the plan's OWNelected_on, never from the day the split runs.README.mdandtemplates/assembly-root/project.yaml: the rule, in one sentence each. README cap 509 → 513 intests/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 explicitreference:and a malformedelected_on:still reaches the manifest, exactly as before this change; the scaffolded project's ownvalidate-manifest.pyrefuses it atmake bootstrap(manifest-elected-on). Catching it earlier belongs inadopt-project.py checkas 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.shforwards--elected-on/--referenceverbatim after--;scripts/family.pyandfamily.yamlcarry 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:
--referenceoverrides in both scaffold and adoption workflows.Enhancements:
Documentation:
Tests: