Skip to content

feat(scaffold): sync-issues target-branch + schedule knobs (#1228) - #1232

Merged
c-vigo merged 6 commits into
devfrom
feature/1228-sync-target-schedule-knobs
Jul 21, 2026
Merged

c-vigo merged 6 commits into
devfrom
feature/1228-sync-target-schedule-knobs

Conversation

@c-vigo

@c-vigo c-vigo commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Add two optional .vig-os knobs, realized entirely at scaffold time, that steer the scaffolded sync-issues.yml. They remediate #1227: trunk consumers whose main carries a require-PR ruleset cannot let the sync job's direct API push land on main.

  • DEVKIT_SYNC_TARGET — the branch the sync job commits to. Default stays workflow-model-aware (dev gitflow / main trunk), byte-for-byte unchanged when unset. A protected-main consumer points it at an unprotected mirror branch (e.g. sync/issue-mirror); the scaffolded job then gains a bootstrap step that creates the branch from the default branch head if absent. The mirror diverges permanently and is never merged back — each sync regenerates full state.
  • DEVKIT_SYNC_SCHEDULE — cron override for the schedule trigger (default 0 2 * * *). Realized at scaffold time because schedule triggers cannot take inputs.

Both are guarded loudly at scaffold time (git ref-format for the branch, a 5-field cron check) and written back to .vig-os like DEVKIT_CI_RUNNER, so upgrades preserve them with no flags.

Design recap

  • No ruleset bypass for the commit App (rejected for security — a bot that writes a protected main can change whatever that branch controls, e.g. applied org config). The mirror-branch approach keeps the App off protected main.
  • Realized at scaffold time mirroring DEVKIT_WORKFLOW/DEVKIT_CI_RUNNER: read before the template overwrite, guarded, rendered, written back. render_sync_settings() runs after render_workflow_model(), so a custom target overrides the workflow-model default already in the file; both are no-ops when unset.
  • Bootstrap step is injected only when a custom target is set (via sed r after the unique app-token private-key: line, before the sync-job checkout), so an unconfigured workspace is unchanged. It uses the App token (same as the commit push) and gh api .../git/refs; rendered output validated with actionlint.
  • Deliberate exclusion — PR-based sync mode (Trunk model: sync-issues direct push collides with require-PR main rulesets #1227 option (b)): evaluated and deferred (inherent approval toil against a review-requiring ruleset, ruleset-dependent safety value, needs Renovate-class stale-PR machinery, zero consumers asking). Recorded in the docs using the established "deliberate exclusion" pattern.

Decisions / deviations from the issue spec

  • install.sh unchanged. These are pure .vig-os keys with no CLI flag (schedule triggers can't take inputs), so — exactly like DEVKIT_CI_RUNNER / DEVKIT_TAG_PREFIX — they are resolved end-to-end in init-workspace.sh, which reads the consumer's .vig-os directly. install.sh only handles keys it needs for its own flags (mode/workflow) or identity; adding handling there would be dead code against precedent. The issue mentioned "the install script", but following the real precedent keeps the diff minimal and consistent.
  • Docs placement of the PR-sync exclusion. The issue asked to record it "in the same docs section that carries the docs-module v1 exclusions pattern" (the nix docs module in NIX.md). Placing a sync-mode note there is topically wrong, so I applied the pattern (a "Deliberate exclusion" note) in the topically-correct new MIGRATION.md sync subsection.
  • Bats + Python tests. Followed the Per-consumer workflow-model knob (gitflow default / trunk opt-in) #1205 precedent of covering a scaffold-time knob with both the Python executed-bash suite (render matrix, guards, bootstrap, writeback) and a focused bats set.

Test evidence

  • tests/test_sync_settings.py — 14 passed (RED first: 12 failed / 2 unset-preservation passed before implementation).
  • No regressions: test_workflow_model.py, test_ci_runner.py, test_install_script.py, test_scaffold_lint.py, test_workflow_sync_checkout.py, and more — 174 passed together.
  • tests/bats/init-workspace.bats — 237 passed (was 232; +5 for sync-issues knobs: DEVKIT_SYNC_TARGET + DEVKIT_SYNC_SCHEDULE (target 1.4.1) #1228).
  • Rendered mirror-target sync-issues.yml: valid YAML + actionlint clean; bootstrap step sits after the app-token step, before the sync-job checkout.
  • prek run --all-files — green. shellcheck assets/init-workspace.sh — clean.

Target release: 1.4.1

Refs: #1228
Refs: #1227

c-vigo added 6 commits July 21, 2026 09:21
Add the render matrix (workflow model x target/schedule), guard failures
(bad branch name, bad cron), bootstrap-step injection, and manifest
writeback for the two new sync-issues knobs. RED against the current
scaffold: the keys, render_sync_settings, and guards do not exist yet.

Refs: #1228
Two optional .vig-os keys, realized at scaffold time in init-workspace.sh,
that steer the scaffolded sync-issues.yml:

- DEVKIT_SYNC_TARGET overrides the branch the sync job commits to (default
  stays workflow-model-aware: dev gitflow / main trunk). A protected-main
  consumer points it at an unprotected mirror branch so the sync job's
  direct API push is no longer refused by a require-PR main ruleset (#1227);
  the job gains a bootstrap step that creates the branch from the default
  branch head if absent.
- DEVKIT_SYNC_SCHEDULE overrides the schedule trigger's 5-field cron.

Both are guarded loudly at scaffold time (git ref-format for the branch,
a 5-field cron check) and written back to .vig-os like DEVKIT_CI_RUNNER,
so upgrades preserve them. Unset => byte-for-byte unchanged.

Refs: #1228
Add a "Point sync-issues at an unprotected mirror branch" subsection to
the MIGRATION.md Workflow models section: the require-PR-main failure
(#1227), the rejected commit-App ruleset bypass, DEVKIT_SYNC_TARGET +
the branch bootstrap, DEVKIT_SYNC_SCHEDULE, the provisioning note, and
the deliberate deferral of PR-based sync mode. Add both keys to the
.vig-os manifest table and a CHANGELOG Unreleased entry (mirrored into
the devcontainer template by sync-manifest).

Refs: #1228, #1227
Mirror the #1205 bats precedent for a scaffold-time knob: assert the
template ships both keys empty, a custom DEVKIT_SYNC_TARGET renders the
mirror default + bootstrap step and is written back, DEVKIT_SYNC_SCHEDULE
overrides the cron, and malformed values fail the scaffold loudly.

Refs: #1228
git check-ref-format alone accepts quotes, dollar, backticks, semicolons,
pipes, and hashes: such values render invalid YAML, crash the render seds
with a raw sed error, or inject commands into the bootstrap step's
double-quoted shell assignment at sync runtime with the App token in
scope. RED: nine hostile values (foo'bar, x$(id)y, backticks, |, #, ;,
double quote, &, braces) currently pass the guard.

Refs: #1228
The target value is spliced into single-quoted YAML, sed replacement
text, and the bootstrap step's double-quoted shell assignment executed
at sync runtime with the App token in scope. git check-ref-format alone
accepts quotes, dollar, backticks, semicolons, pipes, and hashes, so a
hostile value could render invalid YAML, crash the render seds, or
inject commands. Gate on a strict [A-Za-z0-9._/-] allowlist first and
keep the ref-format check for git-illegal shapes the allowlist admits.
Also drop the unsupported Quartz `?` from the cron field charset.

Refs: #1228
@c-vigo

c-vigo commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Review remediation pushed:

  • 8f74d49 test: RED coverage for hostile DEVKIT_SYNC_TARGET values — nine metacharacter payloads (foo'bar, x$(id)y, backticks, |, #, ;, ", &, {}) plus a bats case; all passed the old guard (scaffold exit 0 or raw sed crash).
  • 976c6be fix(scaffold): the guard now gates on a strict [A-Za-z0-9._/-] allowlist first (load-bearing), keeping git check-ref-format on top for git-illegal shapes the allowlist admits (bad..name, trailing /, .lock). Also dropped the Quartz-only ? from the cron field charset (nit 1).

Verified end-to-end: all reviewer repros (foo'bar, x$(id)y, foo|bar, foo#bar) now exit nonzero with the clean Invalid DEVKIT_SYNC_TARGET message — no render, no sed error. sync/issue-mirror and all legitimate branch names still pass.

Nit 2 checked: the MIGRATION.md anchor #point-sync-issues-at-an-unprotected-mirror-branch-protected-main matches GitHub's generated slug for the heading (parens/backticks stripped) — no change needed.

Evidence: tests/test_sync_settings.py 23 passed (RED first: 9 hostile cases failed); bats 238/238; prek run --all-files green; shellcheck clean.

@c-vigo
c-vigo merged commit a1f1974 into dev Jul 21, 2026
13 checks passed
@c-vigo
c-vigo deleted the feature/1228-sync-target-schedule-knobs branch July 21, 2026 08:10
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.

1 participant