From 8e1ff76204e79ca0d0c032cd67edb737cf3787e3 Mon Sep 17 00:00:00 2001 From: sim Date: Thu, 13 Aug 2026 02:56:38 -0400 Subject: [PATCH] refactor(#3309): consolidate adviseRemedy() into the shared types leaf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit adviseRemedy() was defined identically in two of the eight rule-group files (config-validation.cts, agent-install.cts) while the other six repeated the same {action: ADVISE, risk: NONE, args: {command}} object literal inline ~20+ times. Found by the Standards-axis orthogonal review (Duplicated Code smell). Moves the one-line helper into health-diagnostic-types.cts, the leaf module every rule-group file already imports for its enums/types, and uses it consistently across all 8 files. Pure mechanical refactor — no ADVISE remedy's command text, code, or action changed. --- src/health-diagnostic-rules/agent-install.cts | 7 +--- .../config-validation.cts | 7 +--- .../milestone-archive-hygiene.cts | 13 +++---- .../phase-structure.cts | 31 ++++------------ .../roadmap-disk-consistency.cts | 14 ++------ .../root-existence.cts | 20 +++-------- .../state-consistency.cts | 35 +++++-------------- src/health-diagnostic-types.cts | 15 ++++++++ 8 files changed, 44 insertions(+), 98 deletions(-) diff --git a/src/health-diagnostic-rules/agent-install.cts b/src/health-diagnostic-rules/agent-install.cts index 0e27aa758..49392944f 100644 --- a/src/health-diagnostic-rules/agent-install.cts +++ b/src/health-diagnostic-rules/agent-install.cts @@ -26,10 +26,9 @@ // eslint-disable-next-line @typescript-eslint/no-require-imports -- health-diagnostic-types.cjs is an export= CommonJS module import healthDiagnosticMod = require('../health-diagnostic-types.cjs'); -const { SEVERITY, REMEDY_ACTION, REMEDY_RISK } = healthDiagnosticMod; +const { SEVERITY, adviseRemedy } = healthDiagnosticMod; type Rule = healthDiagnosticMod.Rule; type Diagnostic = healthDiagnosticMod.Diagnostic; -type Remedy = healthDiagnosticMod.Remedy; // eslint-disable-next-line @typescript-eslint/no-require-imports -- type-only; erased at compile time, no runtime require emitted import type planningSnapshotMod = require('../planning-snapshot.cjs'); @@ -41,10 +40,6 @@ const { SCOPE } = planningScopeMod; import { PACKAGE_NAME } from '../package-identity.cjs'; -function adviseRemedy(command: string): Remedy { - return { action: REMEDY_ACTION.ADVISE, risk: REMEDY_RISK.NONE, args: { command } }; -} - /** * `check(snapshot)` for W010 — see module header for the exact 4-way * branching this ports from `verify.cts:1992-2027`, and its message/fix diff --git a/src/health-diagnostic-rules/config-validation.cts b/src/health-diagnostic-rules/config-validation.cts index f4bad1f2f..c997767d5 100644 --- a/src/health-diagnostic-rules/config-validation.cts +++ b/src/health-diagnostic-rules/config-validation.cts @@ -56,9 +56,8 @@ type PlanningSnapshot = ReturnType Diagnostic[]; // §8.1 rule 1 signature, verbatim } +// ─── adviseRemedy — shared ADVISE-remedy builder ─────────────────────────── + +/** + * Every rule-group file needs the same `{action: ADVISE, risk: NONE, args: + * {command}}` shape for a non-repairable finding's `fix` string (§8.3 rule + * 5). Was defined identically in `config-validation.cts` and + * `agent-install.cts`, and repeated inline elsewhere — moved to this shared, + * dependency-free leaf so every rule-group file imports one implementation + * instead of duplicating it. + */ +function adviseRemedy(command: string): Remedy { + return { action: REMEDY_ACTION.ADVISE, risk: REMEDY_RISK.NONE, args: { command } }; +} + // ─── Exports ──────────────────────────────────────────────────────────────── const healthDiagnosticTypes = { SEVERITY, REMEDY_ACTION, REMEDY_RISK, + adviseRemedy, }; // Namespace merge (same binding name as the value above) is how a CommonJS