Skip to content

Commit f6b095a

Browse files
fix(cli): os doctor advises --verbose only when a warning has a fix for it to show (#35626)
Fixes #35454 repo:objectstack#1 · os-sales · session_01L6bhgTyMahdAdhXSzgy2nt Clause-②: no Metadata-protocol: none ## 维护者速读 1. 用户能看到什么变化:开发者在命令行做项目体检时,如果出现的警告都没有修复建议(例如缺少测试文件),结尾不再叫他打开详细模式重跑一次;有修复建议的警告照旧提示。 2. 为什么做:上一张修复 doctor 结尾提示的卡留下的另一半,开发者第一次用 CLI 时被引去重跑一次,却什么新内容也看不到。 3. 出错会怎样:最坏情况是某类有修复建议的警告不再带这句提示,警告本身和退出码都不变;撤回本 PR 即恢复原样。 4. 要你做什么:无。 ## What changes - `packages/cli/src/commands/doctor.ts`: a new `hasVerboseOnlyFix` flag, tracked beside `hasWarnings`. The summary prints "Run with --verbose to see fix suggestions." only when `--verbose` is off AND that flag is set. Each warning path was read and classified: - sets the flag (a fix that only `--verbose` prints): an environment `HealthCheckResult` with `status === 'warning'` and a `fix`; a dashboard-widget warning with a non-empty `hint`; the config-load-failure finding when it carries a `fix`; any `--scan-deprecations` hit (its `replacement` is printed only under `--verbose`). - does not set it, no fix in either mode: missing tests, `@deprecated` usages, circular dependencies, unused objects, orphan views. - does not set it, fix already printed without the flag: the platform-protocol gap (its hint is printed unconditionally) and the isolated-posture unique-scope advisory (its prescription is printed unconditionally). - The warnings' own text, the verdict line and exit codes are unchanged. No fix text was added. - `.changeset/35454-doctor-verbose-hint-fixless.md`: patch, `@objectstack/cli`. ## Tests - `packages/cli/src/commands/doctor-deprecation-hint-commands.test.ts`, in the existing `describe('the warnings summary')`, which uses the real `Doctor.run()`: a new case writes `packages/spec/src/a.zod.ts` with no test into the temp cwd and runs plain `os doctor`. It asserts that the "Missing test" warning fired, that the summary reached its warnings branch, and that the text after the verdict line does not name `--verbose`. - The two existing cases from PR #35377 still cover the fix-bearing side: a `--scan-deprecations` warning still gets the hint without `--verbose` and gets none with it. ## Acceptance notes - Dashboard-widget warnings whose `hint` is the empty string (`@objectstack/lint` emits `hint: ''` on one path) do not count as fix-bearing here, since `--verbose` would print only a bare arrow for them. That empty arrow line under `--verbose` is not changed here. Observation only, not reproduced at the public door. - Environment rows with status `ok` also print their `fix` under `--verbose`. They are not warnings, so they do not count toward the hint. The behaviour is unchanged. ## Verification Readings are at HEAD `d559e09a` (the fix commit `1dc43d70` merged with origin/main `f981dce3`; the merge brought in no package source). Two-minute check: `pnpm --filter @objectstack/cli exec vitest run --project unit src/commands/doctor-deprecation-hint-commands.test.ts`. Expected: 15 passed. Read first: `packages/cli/src/commands/doctor.ts`, the summary's `if (!flags.verbose && hasVerboseOnlyFix)` and the four places that set the flag. The risk is a fix-bearing path left unclassified. <details><summary>Red first, then green</summary> - At `86ec0951` (the new pin on an unmodified `doctor.ts`): Tests 1 failed, 14 passed (15). The new case failed with `expected '\n Run with --verbose to see fix su…' not to contain '--verbose'`. - At `1dc43d70`: Test Files 1 passed (1), Tests 15 passed (15). </details> <details><summary>Ablation (scripts/ablation-replace.mjs, landed on disk and restored)</summary> - Anchor `if (!flags.verbose && hasVerboseOnlyFix) {` replaced with `if (!flags.verbose) {`. The anchor went from 1 to 0 and the blob from 975d2c6 to ab86dda8. Result: Tests 1 failed, 14 passed. Only "makes no such advice when the only warnings carry no fix to reveal" failed. - Restore: the blob after restore equals HEAD (975d2c6) and `git diff HEAD` is empty. - The test imports the subject as relative source (`./doctor.js`), so the ablation needed no dist rebuild. </details> <details><summary>Package tests and typecheck</summary> - `pnpm run typecheck` in `packages/cli` (tsc, then `check:test-typecheck`) followed by `pnpm exec vitest run --project unit --maxWorkers=2`, as one locked command: VERDICT command-exit 0. Test Files 431 passed (431), Tests 6163 passed (6163). - The `integration` tier is left to CI: the diff touches no integration-tier file and no spawn entry. </details> <details><summary>Gates (derived set, local)</summary> - `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` at `d559e09a` derived 69 families. Each one was run, with its exit code captured before any pipe. - 67 exited 0. 2 are NOT MEASURED, both exit 3 PREREQUISITE NOT MET because they need dist output across the repo: `pnpm check:dual-build-cjs-loads` (no dist for studio, client-react, connector-slack, ...) and `pnpm check:i18n-coverage` (the app-showcase config imports an unbuilt connector-slack dist). CI runs both. - `--ran` reconciliation: "69 derived famil(ies) accounted for — 67 run, 2 NOT-MEASURED (2 DERIVED from a recorded exit 3)". - `node scripts/pm/overlap-check.mjs`: VERDICT clean exit 0. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01L6bhgTyMahdAdhXSzgy2nt)_ --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 36e02fd commit f6b095a

3 files changed

Lines changed: 44 additions & 3 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/cli': patch
3+
---
4+
5+
fix(cli): `os doctor` no longer advises `--verbose` when no warning has a fix for it to show
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
When `os doctor` finished with warnings it closed with "Run with --verbose to see fix suggestions." whenever any warning fired. Several warnings have no fix suggestion in either mode (a missing `*.test.ts` beside a `*.zod.ts`, `@deprecated` usages, circular dependencies, unused objects, orphan views), so for those the re-run printed nothing new. The line is now printed only when at least one warning that fired carries a fix that `--verbose` would reveal. The warnings themselves, and exit codes, are unchanged.

‎packages/cli/src/commands/doctor-deprecation-hint-commands.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,5 +369,20 @@ describe('os doctor --scan-deprecations, end to end', () => {
369369
// What the advice pointed at is printed: the → replacement per finding.
370370
expect(run.out).toContain('Use maxLength (camelCase)');
371371
}, E2E_TIMEOUT);
372+
373+
// The advice is a promise that `--verbose` prints a fix the plain run hid.
374+
// A missing `*.test.ts` beside a `*.zod.ts` warns with no fix line in
375+
// either mode, so when it is the only warning the promise has nothing
376+
// behind it and the summary must not make it.
377+
it('makes no such advice when the only warnings carry no fix to reveal', async () => {
378+
const specSrc = path.join(tmp, 'packages', 'spec', 'src');
379+
fs.mkdirSync(specSrc, { recursive: true });
380+
fs.writeFileSync(path.join(specSrc, 'a.zod.ts'), 'export const a = 1;\n', 'utf8');
381+
382+
const run = await runDoctor([]);
383+
384+
expect(run.out).toContain('Missing test: a.test.ts (for a.zod.ts)');
385+
expect(summaryTail(run.out)).not.toContain('--verbose');
386+
}, E2E_TIMEOUT);
372387
});
373388
});

‎packages/cli/src/commands/doctor.ts‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,6 +2442,13 @@ export default class Doctor extends Command {
24422442
// Display environment results
24432443
let hasErrors = false;
24442444
let hasWarnings = false;
2445+
// Whether some warning that fired carries a fix that only `--verbose`
2446+
// prints. The summary's re-run advice promises exactly that, so it follows
2447+
// this, not `hasWarnings`: a bare `printWarning` (missing tests,
2448+
// `@deprecated` usages, circular dependencies, unused objects, orphan
2449+
// views) has no fix in either mode, and a fix printed unasked (the
2450+
// protocol-gap hint, the unique-scope prescription) is already on screen.
2451+
let hasVerboseOnlyFix = false;
24452452

24462453
console.log('');
24472454
results.forEach((result) => {
@@ -2451,7 +2458,10 @@ export default class Doctor extends Command {
24512458
renderHealthCheckResult(result, flags.verbose);
24522459

24532460
if (result.status === 'error') hasErrors = true;
2454-
if (result.status === 'warning') hasWarnings = true;
2461+
if (result.status === 'warning') {
2462+
hasWarnings = true;
2463+
if (result.fix) hasVerboseOnlyFix = true;
2464+
}
24552465
});
24562466

24572467
// ── Extended Checks ──────────────────────────────────────────────
@@ -2641,6 +2651,7 @@ export default class Doctor extends Command {
26412651
printError(`${f.where}: ${f.message}`);
26422652
} else {
26432653
hasWarnings = true;
2654+
if (f.hint) hasVerboseOnlyFix = true;
26442655
printWarning(`${f.where}: ${f.message}`);
26452656
}
26462657
if (flags.verbose) {
@@ -2677,6 +2688,7 @@ export default class Doctor extends Command {
26772688
// above a warning. Inert today: that list filters on `error`.
26782689
results.push(finding);
26792690
hasWarnings = true;
2691+
if (finding.fix) hasVerboseOnlyFix = true;
26802692
}
26812693
}
26822694

@@ -2687,6 +2699,7 @@ export default class Doctor extends Command {
26872699
const deprecations = scanDeprecatedPatterns(scanDir);
26882700
if (deprecations.length > 0) {
26892701
hasWarnings = true;
2702+
hasVerboseOnlyFix = true;
26902703
for (const dep of deprecations) {
26912704
printWarning(`${dep.file}:${dep.line} — ${dep.description}`);
26922705
if (flags.verbose) {
@@ -2743,8 +2756,11 @@ export default class Doctor extends Command {
27432756
console.log(chalk.yellow('⚠️ Environment is functional but has some warnings.'));
27442757
// Only when the flag is off: under `--verbose` the fix suggestions this
27452758
// line points at are already printed above, so advising the operator to
2746-
// pass the flag they just passed sends them to re-run for nothing.
2747-
if (!flags.verbose) {
2759+
// pass the flag they just passed sends them to re-run for nothing. And
2760+
// only when there is such a suggestion: a re-run whose warnings carry no
2761+
// hidden fix prints nothing more, so the advice would send them for
2762+
// nothing just the same.
2763+
if (!flags.verbose && hasVerboseOnlyFix) {
27482764
console.log(chalk.dim(' Run with --verbose to see fix suggestions.'));
27492765
}
27502766
} else {

0 commit comments

Comments
 (0)