Bind the preflight scope to pm-github's declared command set

Merged
UN
4mo ago
+155-13

Problem

PR #36 scoped registerPreflight to a fixed six-entry commands array. That array, isMutatingGithubCommand, and the commands the package declares are maintained by hand, with nothing binding them. If a command is added or reclassified as mutating on one side only, the override silently stops running for it — the runtime matches by exact normalized path — and the command executes with no early credential warning. (The runtime swallows preflight throws, and the authoritative handler gate only fires once the command actually runs and fails.) This is the same drift risk CodeRabbit flagged on pm-linear #67, where the deprecated linear-sync import alias silently lost its gate.

Manifest-vs-scope audit

Commands pm-github declares (registerCommand + the github importer/exporter aliases):

commandmutating?in scope?
github syncyes (unless --dry-run)✅
github exportwith --apply/--push✅
github importyes (unless --dry-run)✅
gh-issues import (legacy alias)yes (unless --dry-run)✅
github project importyes (unless --dry-run)✅
github project syncwith --apply✅
github validateread-only— never gated
github project listread-only— never gated
github project fieldsread-only— never gated

Diff: every scoped path is a declared command; the three omitted commands are read-only diagnostics that isMutatingGithubCommand returned false for under the old global registration too — no gate was lost, none had to be restored. Notably the legacy gh-issues import alias was already in scope, so the specific gap caught in pm-linear/pm-jira does not exist here.

Fix

Extend the scoping smoke test into a drift guard:

  • every scoped path must be one isMutatingGithubCommand treats as mutating — the apply-gated github export and github project sync are checked under their apply configuration rather than skipped;
  • every declared-but-omitted path must be read-only — a justified exclusion, not an accidental gap.

Fails if either list drifts (verified by temporarily breaking the classifier).

Verified

  • npm test: 251/251 pass
  • coverage: 92.04 lines / 81.34 branches / 91.49 functions (thresholds 88/79/89 met)
  • npm run release:check exits 0
  • npx pm health --strict-exit: ok: true, zero collision warnings
  • dist/ unchanged after rebuild

pm item

Summary by Sourcery

Guard pm-github’s preflight override scope against drift from its declared mutating command set to prevent commands silently losing credential gating.

Bug Fixes:

  • Ensure every command in the preflight scope is classified as mutating and every declared-but-unscoped command is verified read-only to avoid missing credential gates.

Enhancements:

  • Extend the smoke test into a drift check that binds the preflight override scope to the mutating command classifier.

Documentation:

  • Document the fix and its impact in the changelog and pm agent issue history.

Summary by cubic

Bind the preflight credential gate’s scope to pm-github’s declared mutating commands and harden the test so drift cannot hide. Previously the guard compared against a hand-maintained list and could miss newly mutating commands; the test now derives the declared set from real activation and asserts the scope equals its mutating class. No runtime behavior changes.

Review focus

  • In test/smoke.test.ts, derive declared command paths from activation registrations (registerCommand, registerImporter, registerExporter) and verify they equal dispatch handler paths.
  • Partition that set with isMutatingGithubCommand under maximally mutating options and assert the mutating + read-only classes reconstruct the declared set exactly.
  • Assert the override’s commands equals the mutating class; fail with the command name if a declared mutating path is missing or a read-only/undeclared path is scoped.
  • Minor housekeeping: .gitattributes, changelog entry, and PM issue artifacts (pm-github-4ga9).