From de3cdf8c88989cfb6970647174ee52488e6d6830 Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Wed, 25 Nov 2026 15:46:49 +0900 Subject: [PATCH 1/8] feat: ask to keep only tests the project's test rule justifies when the test share is exceeded With --base, a change that edits tests while the test share exceeds its limit is now told to keep a test it adds only when the project's test rule justifies it and to delete or merge the others, instead of being told to add no test code. The limit, its level, and the whole-project message are unchanged. Co-authored-by: WillBooster (Claude Code) --- README.md | 5 ++++- src/checkCommand.ts | 2 +- src/thresholds.ts | 7 ++++--- test/e2e/checkCli.test.ts | 4 ---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 9341f06..889f28c 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,10 @@ warning says so). With `--base`, it is reported only when the share exceeds its change touches a test: git lists a path as changed since the merge-base or untracked, and the check's files still include it under the target as a test by its name. A change that touches no test, or only deletes or moves tests out, is never blamed for a share it did not raise; -one that does is told to delete or merge tests so that it adds no test code. No directive allows it, and no override can change +one that does is told to keep a test it adds only when the project's test rule (the project's own +criteria for when a test is worth having) justifies it, and to delete or merge the others. Without +`--base`, a violation names the test NCSS to delete or merge to bring the share within its limit. +No directive allows it, and no override can change its limit: `"testNcssPercent": "off"` in the config's `rules`, or `--warn testNcssPercent=off --error testNcssPercent=off` on the command line, disables it at both levels. diff --git a/src/checkCommand.ts b/src/checkCommand.ts index f2f79f9..db66387 100644 --- a/src/checkCommand.ts +++ b/src/checkCommand.ts @@ -695,7 +695,7 @@ function describeViolation(violation: Violation, exceeded: string, checksChange: switch (violation.kind) { case 'project': { const remedy = checksChange - ? `this change edits tests while test code exceeds ${violation.exceeded[0]?.limit}% of production code: delete or merge tests so the change adds no test code` + ? `this change edits tests while test code exceeds ${violation.exceeded[0]?.limit}% of production code: keep a test it adds only when the project's test rule justifies it, and delete or merge the others` : `delete or merge ${violation.excessTestNcss} test NCSS`; return `${violation.file}: ${exceeded}, test NCSS ${violation.testNcss} of production NCSS ${violation.productionNcss}; ${remedy}`; } diff --git a/src/thresholds.ts b/src/thresholds.ts index e8595e0..a02ecf0 100644 --- a/src/thresholds.ts +++ b/src/thresholds.ts @@ -130,14 +130,15 @@ export interface TestShare { } /** - * Test code is kept in proportion to the production code it checks. The limit applies to the whole - * checked project, so no override for file patterns can change it. + * Test code in proportion to the production code it checks; exceeding the limit calls for reviewing + * tests against the project's test rule. The limit applies to the whole checked project, so no + * override for file patterns can change it. */ export const testShareThreshold: Threshold = { metric: 'testNcssPercent', label: 'test NCSS percent', defaultLimits: { warning: Infinity, error: 30 }, - hint: 'delete or merge tests as the violation says, in the same change.', + hint: "keep a test only when the project's test rule justifies it, and delete or merge the others as the violation says, in the same change.", measure: ({ testNcss, productionNcss }) => (testNcss * 100) / productionNcss, }; diff --git a/test/e2e/checkCli.test.ts b/test/e2e/checkCli.test.ts index 2a6008f..0167b60 100644 --- a/test/e2e/checkCli.test.ts +++ b/test/e2e/checkCli.test.ts @@ -1380,10 +1380,6 @@ describe('code-gauge check: test share', () => { expect(projectViolations(['--base', 'HEAD']), 'a change that only deletes tests').toEqual([]); writeSource('test/calc.test.ts', testCode(59)); - const changed = runCheck(['--base', 'HEAD']); - expect(changed.stdout).toMatch( - /^error: \.: test NCSS percent [\d.]+ \(max 30\), test NCSS \d+ of production NCSS \d+; this change edits tests while test code exceeds 30% of production code: delete or merge tests so the change adds no test code$/mu - ); expect(projectViolations(['--base', 'HEAD'])).toMatchObject([{ kind: 'project', level: 'error' }]); }); From c0fc304de63cfbfff367d98ec4ca2d099924d005 Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Wed, 25 Nov 2026 15:51:17 +0900 Subject: [PATCH 2/8] feat: tell when a reviewed test share needs no further change With --base, the test-share remedy now says that once every test the change adds is justified, the error needs no further change, so a reader rerunning the check is not steered back to deleting justified tests. The shared hint asks to review the tests against the project's test rule and act as the violation says, which reads true with and without --base. Co-authored-by: WillBooster (Claude Code) --- README.md | 6 ++++-- src/checkCommand.ts | 2 +- src/thresholds.ts | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 889f28c..3205cf6 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,8 @@ change touches a test: git lists a path as changed since the merge-base or untra check's files still include it under the target as a test by its name. A change that touches no test, or only deletes or moves tests out, is never blamed for a share it did not raise; one that does is told to keep a test it adds only when the project's test rule (the project's own -criteria for when a test is worth having) justifies it, and to delete or merge the others. Without +criteria for when a test is worth having) justifies it, and to delete or merge the others; once every test the change adds is justified, the +error stays reported and needs no further change. Without `--base`, a violation names the test NCSS to delete or merge to bring the share within its limit. No directive allows it, and no override can change its limit: `"testNcssPercent": "off"` in the config's `rules`, or `--warn testNcssPercent=off @@ -135,7 +136,8 @@ its limit: `"testNcssPercent": "off"` in the config's `rules`, or `--warn testNc Every threshold has a limit per level, and a value is reported at the most severe level whose limit it violates. The warning limits mark code worth simplifying when it is touched; the error limits -mark code to fix, and only errors fail the check (exit code 1). +mark code to fix (except a `--base` test share whose added tests are all justified, as above), and +only errors fail the check (exit code 1). The defaults, except that of `testNcssPercent`, come from the 45,123 functions the WillBooster organization wrote in its repositories (of 153,771 measured; copies of third-party projects and course material are left out), and from diff --git a/src/checkCommand.ts b/src/checkCommand.ts index db66387..55acbc5 100644 --- a/src/checkCommand.ts +++ b/src/checkCommand.ts @@ -695,7 +695,7 @@ function describeViolation(violation: Violation, exceeded: string, checksChange: switch (violation.kind) { case 'project': { const remedy = checksChange - ? `this change edits tests while test code exceeds ${violation.exceeded[0]?.limit}% of production code: keep a test it adds only when the project's test rule justifies it, and delete or merge the others` + ? `this change edits tests while test code exceeds ${violation.exceeded[0]?.limit}% of production code: keep a test it adds only when the project's test rule justifies it, and delete or merge the others; once every test it adds is justified, the error needs no further change` : `delete or merge ${violation.excessTestNcss} test NCSS`; return `${violation.file}: ${exceeded}, test NCSS ${violation.testNcss} of production NCSS ${violation.productionNcss}; ${remedy}`; } diff --git a/src/thresholds.ts b/src/thresholds.ts index a02ecf0..3acf48d 100644 --- a/src/thresholds.ts +++ b/src/thresholds.ts @@ -138,7 +138,7 @@ export const testShareThreshold: Threshold = { metric: 'testNcssPercent', label: 'test NCSS percent', defaultLimits: { warning: Infinity, error: 30 }, - hint: "keep a test only when the project's test rule justifies it, and delete or merge the others as the violation says, in the same change.", + hint: "review the tests against the project's test rule and delete or merge them as the violation says, in the same change.", measure: ({ testNcss, productionNcss }) => (testNcss * 100) / productionNcss, }; From d5d1614245f8f2fc38f359658f39f2d3830e468b Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Wed, 25 Nov 2026 15:53:40 +0900 Subject: [PATCH 3/8] fix: name the test-share report a violation, not an error, in its remedy The test share can be reported at the warning level, where calling it an error pointed the reader at an error the report does not contain. Co-authored-by: WillBooster (Claude Code) --- README.md | 2 +- src/checkCommand.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3205cf6..7318a7e 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ check's files still include it under the target as a test by its name. A change touches no test, or only deletes or moves tests out, is never blamed for a share it did not raise; one that does is told to keep a test it adds only when the project's test rule (the project's own criteria for when a test is worth having) justifies it, and to delete or merge the others; once every test the change adds is justified, the -error stays reported and needs no further change. Without +violation stays reported and needs no further change. Without `--base`, a violation names the test NCSS to delete or merge to bring the share within its limit. No directive allows it, and no override can change its limit: `"testNcssPercent": "off"` in the config's `rules`, or `--warn testNcssPercent=off diff --git a/src/checkCommand.ts b/src/checkCommand.ts index 55acbc5..15753b4 100644 --- a/src/checkCommand.ts +++ b/src/checkCommand.ts @@ -695,7 +695,7 @@ function describeViolation(violation: Violation, exceeded: string, checksChange: switch (violation.kind) { case 'project': { const remedy = checksChange - ? `this change edits tests while test code exceeds ${violation.exceeded[0]?.limit}% of production code: keep a test it adds only when the project's test rule justifies it, and delete or merge the others; once every test it adds is justified, the error needs no further change` + ? `this change edits tests while test code exceeds ${violation.exceeded[0]?.limit}% of production code: keep a test it adds only when the project's test rule justifies it, and delete or merge the others; once every test it adds is justified, the violation needs no further change` : `delete or merge ${violation.excessTestNcss} test NCSS`; return `${violation.file}: ${exceeded}, test NCSS ${violation.testNcss} of production NCSS ${violation.productionNcss}; ${remedy}`; } From 690f468a90d17a4e5590811522ac61bd54ad761f Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Wed, 25 Nov 2026 16:01:44 +0900 Subject: [PATCH 4/8] feat: default the test share to a warning at 30 and state its excess as a fact The test share limit of 30 is the median test share in NCSS of 62 of the organization's repositories, with no ratings behind it, so exceeding it now asks for a review of the tests rather than marking code to fix: the default becomes a warning at 30 with no error. The whole-project text states how much test NCSS is above the limit and asks to review the tests against the project's test rule and delete or merge those it does not justify, and the hint reads true for both texts. The calibration notes record the NCSS measurement behind the default. Co-authored-by: WillBooster (Claude Code) --- README.md | 20 +++++++++++--------- docs/threshold-calibration.md | 27 ++++++++++++++++++++------- src/checkCommand.ts | 6 +++--- src/thresholds.ts | 4 ++-- test/e2e/checkCli.test.ts | 13 ++++--------- 5 files changed, 40 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 7318a7e..61e5e75 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ like the ranking command. The thresholds: | `functionDepDegree` | a function's DepDegree is above it | off | off | | `fileNcss` | a file's NCSS is above it | 400 | 1000 | | `duplicateLines` | a duplicated block holds at least this many lines matched in a copy | 15 | off | -| `testNcssPercent` | the target's test NCSS, as a percentage of its other NCSS, is above | off | 30 | +| `testNcssPercent` | the target's test NCSS, as a percentage of its other NCSS, is above | 30 | off | `testNcssPercent` holds the test code of the checked directory in proportion to its production code: the NCSS of its test files against that of the other files the check measures. A file counts @@ -129,14 +129,16 @@ touches no test, or only deletes or moves tests out, is never blamed for a share one that does is told to keep a test it adds only when the project's test rule (the project's own criteria for when a test is worth having) justifies it, and to delete or merge the others; once every test the change adds is justified, the violation stays reported and needs no further change. Without -`--base`, a violation names the test NCSS to delete or merge to bring the share within its limit. +`--base`, a violation states how much test NCSS is above the limit and asks to review the tests +against the project's test rule and delete or merge those it does not justify; a share still above +the limit after that needs no further change. No directive allows it, and no override can change its limit: `"testNcssPercent": "off"` in the config's `rules`, or `--warn testNcssPercent=off --error testNcssPercent=off` on the command line, disables it at both levels. Every threshold has a limit per level, and a value is reported at the most severe level whose limit it violates. The warning limits mark code worth simplifying when it is touched; the error limits -mark code to fix (except a `--base` test share whose added tests are all justified, as above), and +mark code to fix (except a test share whose tests the project's test rule justifies, as above), and only errors fail the check (exit code 1). The defaults, except that of `testNcssPercent`, come from the 45,123 functions the WillBooster organization wrote in its repositories @@ -148,8 +150,9 @@ thresholds that are off, nesting depth flags no function that cognitive complexi cyclomatic complexity and Halstead difficulty flag functions rated like unflagged ones; Halstead volume, Halstead effort, and DepDegree are high mostly where a function is long or takes many parameters, which the limits above already flag. -The `testNcssPercent` default sits just below the median test share, in lines, of 50 of the -organization's repositories; no ratings back it. +The `testNcssPercent` default is a warning at the median test share, in NCSS, of 62 of the +organization's repositories, and no error: no ratings back it, so it asks for a review of the tests +rather than marking code to fix. [How the default thresholds were calibrated](docs/threshold-calibration.md) holds the corpus, the distributions per language, the ratings, and the reasoning per threshold. @@ -371,9 +374,8 @@ touches. kind `file`, the first and last line of the file; for kind `project`, only `file`, the checked directory relative to the repository root (`.` for the root); - `testNcss`, `productionNcss`, and `excessTestNcss`: only for kind `project`; the NCSS of the - test files and of the other files, and the test NCSS above the strictest active limit (what a - whole project deletes or merges to clear every level, which can exceed what clears the level - reported); + test files and of the other files, and the test NCSS above the strictest active limit (which + can exceed what is above the limit of the level reported); - `name`: only for kind `function`; a member's name follows the type, module, or object it belongs to (`Rules.decide`), and a function without a name is ``; - `exceeded`: every violated threshold with its `metric` (the rule's name in the config and on @@ -423,7 +425,7 @@ with `--config`). The following config reproduces every built-in default: "functionDepDegree": "off", "fileNcss": { "warn": 400, "error": 1000 }, "duplicateLines": { "warn": 15, "error": "off" }, - "testNcssPercent": { "warn": "off", "error": 30 } + "testNcssPercent": { "warn": 30, "error": "off" } }, "overrides": [], "exclude": [], diff --git a/docs/threshold-calibration.md b/docs/threshold-calibration.md index 3c7ae4e..cf69797 100644 --- a/docs/threshold-calibration.md +++ b/docs/threshold-calibration.md @@ -320,13 +320,26 @@ With these limits, `check` reports 464 errors and 2,430 warnings in the calibrat ## Test share -`testNcssPercent` defaults to an error above 30, and to no warning. It was set in November 2026 -from the 50 WillBooster repositories on a developer's machine whose production code exceeds 3,000 -lines: their test code, counted in lines rather than NCSS, was 33% of their production code at the -median. The limit sits just below that median. Its effect in NCSS was not measured on the corpus, -which would tell how many projects it holds and whether halving the tests of the median project -brings it under the limit: a line of test code can hold more or fewer statements than a line of -production code. +`testNcssPercent` defaults to a warning above 30, and to no error. The value was first set in +November 2026 from the 50 WillBooster repositories on a developer's machine whose production code +exceeds 3,000 lines: their test code, counted in lines rather than NCSS, was 33% of their production +code at the median. + +The share was then measured in NCSS on the 62 WillBooster repositories on one developer's machine +whose production NCSS is at least 1,000 (the sample includes second clones and forks), with +`check` of code-gauge 11.1.0 reporting every share as a warning: + +| Percentile | Test NCSS percent | +| ---------- | ----------------: | +| 50th | 31.6 | +| 75th | 60.8 | +| 90th | 76.2 | + +32 of the 62 (52%) are above 30%, and 17 (27%) above 60%. A limit of 30 thus sits at the median in +NCSS too. No ratings tell whether a share above it holds tests worth deleting, so it is a warning, +which marks code worth simplifying when it is touched, and not an error, which would mark half of +these repositories as code to fix: exceeding it asks for a review of the tests against the +project's test rule. ## Duplicated blocks measured in matched lines diff --git a/src/checkCommand.ts b/src/checkCommand.ts index 15753b4..aaa1cc9 100644 --- a/src/checkCommand.ts +++ b/src/checkCommand.ts @@ -695,9 +695,9 @@ function describeViolation(violation: Violation, exceeded: string, checksChange: switch (violation.kind) { case 'project': { const remedy = checksChange - ? `this change edits tests while test code exceeds ${violation.exceeded[0]?.limit}% of production code: keep a test it adds only when the project's test rule justifies it, and delete or merge the others; once every test it adds is justified, the violation needs no further change` - : `delete or merge ${violation.excessTestNcss} test NCSS`; - return `${violation.file}: ${exceeded}, test NCSS ${violation.testNcss} of production NCSS ${violation.productionNcss}; ${remedy}`; + ? `; this change edits tests while test code exceeds ${violation.exceeded[0]?.limit}% of production code: keep a test it adds only when the project's test rule justifies it, and delete or merge the others; once every test it adds is justified, the violation needs no further change` + : `, ${violation.excessTestNcss} above the limit; review the tests against the project's test rule and delete or merge those it does not justify`; + return `${violation.file}: ${exceeded}, test NCSS ${violation.testNcss} of production NCSS ${violation.productionNcss}${remedy}`; } case 'file': { return `${violation.file}: ${exceeded}`; diff --git a/src/thresholds.ts b/src/thresholds.ts index 3acf48d..35a7aa7 100644 --- a/src/thresholds.ts +++ b/src/thresholds.ts @@ -137,8 +137,8 @@ export interface TestShare { export const testShareThreshold: Threshold = { metric: 'testNcssPercent', label: 'test NCSS percent', - defaultLimits: { warning: Infinity, error: 30 }, - hint: "review the tests against the project's test rule and delete or merge them as the violation says, in the same change.", + defaultLimits: { warning: 30, error: Infinity }, + hint: "review the tests against the project's test rule and delete or merge those it does not justify; a share still above the limit after that needs no further change.", measure: ({ testNcss, productionNcss }) => (testNcss * 100) / productionNcss, }; diff --git a/test/e2e/checkCli.test.ts b/test/e2e/checkCli.test.ts index 0167b60..9e7eb2a 100644 --- a/test/e2e/checkCli.test.ts +++ b/test/e2e/checkCli.test.ts @@ -1257,13 +1257,8 @@ describe('code-gauge check: test share', () => { it('reports a project whose test code exceeds 30% of its production code, unless the config disables it', () => { writeSource('test/calc.test.ts', testCode(60)); - const result = runCheck([]); - expect(result.status).toBe(1); - expect(result.stdout).toMatch( - /^error: \.: test NCSS percent [\d.]+ \(max 30\), test NCSS \d+ of production NCSS \d+; delete or merge \d+ test NCSS$/mu - ); const [violation] = projectViolations([]); - expect(violation).toMatchObject({ kind: 'project', file: '.', level: 'error' }); + expect(violation).toMatchObject({ kind: 'project', file: '.', level: 'warning' }); expect((violation?.testNcss ?? 0) * 100).toBeGreaterThan((violation?.productionNcss ?? 0) * 30); writeConfig({ rules: { ...baseConfig.rules, testNcssPercent: 'off' } }); @@ -1272,7 +1267,7 @@ describe('code-gauge check: test share', () => { it.each([ ['the default limit', [], 0], - ['a warning limit stricter than the error limit', ['--warn', 'testNcssPercent=10'], 0], + ['an error limit looser than the warning limit', ['--error', 'testNcssPercent=50'], 0], // 375 production NCSS at 18.4% admit 69 test NCSS, which multiplying and flooring puts at 68. ['a fractional limit', ['--error', 'testNcssPercent=18.4'], 326], ])('names the least test NCSS whose deletion clears the share under %s', (_, limits, extraProduction) => { @@ -1380,7 +1375,7 @@ describe('code-gauge check: test share', () => { expect(projectViolations(['--base', 'HEAD']), 'a change that only deletes tests').toEqual([]); writeSource('test/calc.test.ts', testCode(59)); - expect(projectViolations(['--base', 'HEAD'])).toMatchObject([{ kind: 'project', level: 'error' }]); + expect(projectViolations(['--base', 'HEAD'])).toMatchObject([{ kind: 'project', level: 'warning' }]); }); it('reports the share of a targeted directory with --base only for a test edited inside it', () => { @@ -1470,7 +1465,7 @@ describe('code-gauge check: test share', () => { chmodSync(path.join(repoDir, 'private'), 0o000); try { const result = runCheck(['--json']); - expect(result.status, result.stderr).toBe(1); + expect(result.status, result.stderr).toBe(0); expect((JSON.parse(result.stdout) as ProjectReport).violations).toContainEqual( expect.objectContaining({ kind: 'project' }) ); From d9e0351fa974c60d809fc28c03ab98b92a7bdd7e Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Wed, 25 Nov 2026 16:04:12 +0900 Subject: [PATCH 5/8] fix: say the whole-project test excess is above the strictest limit The excess is measured against the strictest active limit, while the line prints the limit of the most severe level, so "above the limit" read as the gap to the printed limit when the levels differ. Co-authored-by: WillBooster (Claude Code) --- README.md | 2 +- src/checkCommand.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 61e5e75..f1c349d 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ touches no test, or only deletes or moves tests out, is never blamed for a share one that does is told to keep a test it adds only when the project's test rule (the project's own criteria for when a test is worth having) justifies it, and to delete or merge the others; once every test the change adds is justified, the violation stays reported and needs no further change. Without -`--base`, a violation states how much test NCSS is above the limit and asks to review the tests +`--base`, a violation states how much test NCSS is above the strictest active limit and asks to review the tests against the project's test rule and delete or merge those it does not justify; a share still above the limit after that needs no further change. No directive allows it, and no override can change diff --git a/src/checkCommand.ts b/src/checkCommand.ts index aaa1cc9..5b32fd6 100644 --- a/src/checkCommand.ts +++ b/src/checkCommand.ts @@ -696,7 +696,7 @@ function describeViolation(violation: Violation, exceeded: string, checksChange: case 'project': { const remedy = checksChange ? `; this change edits tests while test code exceeds ${violation.exceeded[0]?.limit}% of production code: keep a test it adds only when the project's test rule justifies it, and delete or merge the others; once every test it adds is justified, the violation needs no further change` - : `, ${violation.excessTestNcss} above the limit; review the tests against the project's test rule and delete or merge those it does not justify`; + : `, ${violation.excessTestNcss} above the strictest limit; review the tests against the project's test rule and delete or merge those it does not justify`; return `${violation.file}: ${exceeded}, test NCSS ${violation.testNcss} of production NCSS ${violation.productionNcss}${remedy}`; } case 'file': { From f08d9d703685d0351ac863f48dfc4d9808efa03f Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Wed, 25 Nov 2026 16:04:51 +0900 Subject: [PATCH 6/8] fix: scope the test-share hint to the tests the violation names With --base the violation asks to review the tests the change adds, so the shared hint now says so instead of reading as a review of every test. Co-authored-by: WillBooster (Claude Code) --- src/thresholds.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thresholds.ts b/src/thresholds.ts index 35a7aa7..45b2060 100644 --- a/src/thresholds.ts +++ b/src/thresholds.ts @@ -138,7 +138,7 @@ export const testShareThreshold: Threshold = { metric: 'testNcssPercent', label: 'test NCSS percent', defaultLimits: { warning: 30, error: Infinity }, - hint: "review the tests against the project's test rule and delete or merge those it does not justify; a share still above the limit after that needs no further change.", + hint: "review the tests the violation names (with --base, those the change adds) against the project's test rule and delete or merge those it does not justify; a share still above the limit after that needs no further change.", measure: ({ testNcss, productionNcss }) => (testNcss * 100) / productionNcss, }; From 3693e86c050d71541b6d0b01f4191d9506050ca4 Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Wed, 25 Nov 2026 16:11:49 +0900 Subject: [PATCH 7/8] fix: drop the claim that a reviewed test share needs no further change With the share a warning by default, a residual warning already does not fail the check, while a project that configures an error limit chose to fail on it, so promising that a share above the limit needs no further change was wrong for configured errors and unneeded for warnings. Co-authored-by: WillBooster (Claude Code) --- README.md | 9 +++------ src/checkCommand.ts | 2 +- src/thresholds.ts | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f1c349d..4dbbfd0 100644 --- a/README.md +++ b/README.md @@ -127,19 +127,16 @@ change touches a test: git lists a path as changed since the merge-base or untra check's files still include it under the target as a test by its name. A change that touches no test, or only deletes or moves tests out, is never blamed for a share it did not raise; one that does is told to keep a test it adds only when the project's test rule (the project's own -criteria for when a test is worth having) justifies it, and to delete or merge the others; once every test the change adds is justified, the -violation stays reported and needs no further change. Without +criteria for when a test is worth having) justifies it, and to delete or merge the others. Without `--base`, a violation states how much test NCSS is above the strictest active limit and asks to review the tests -against the project's test rule and delete or merge those it does not justify; a share still above -the limit after that needs no further change. +against the project's test rule and delete or merge those it does not justify. No directive allows it, and no override can change its limit: `"testNcssPercent": "off"` in the config's `rules`, or `--warn testNcssPercent=off --error testNcssPercent=off` on the command line, disables it at both levels. Every threshold has a limit per level, and a value is reported at the most severe level whose limit it violates. The warning limits mark code worth simplifying when it is touched; the error limits -mark code to fix (except a test share whose tests the project's test rule justifies, as above), and -only errors fail the check (exit code 1). +mark code to fix, and only errors fail the check (exit code 1). The defaults, except that of `testNcssPercent`, come from the 45,123 functions the WillBooster organization wrote in its repositories (of 153,771 measured; copies of third-party projects and course material are left out), and from diff --git a/src/checkCommand.ts b/src/checkCommand.ts index 5b32fd6..c14b6d9 100644 --- a/src/checkCommand.ts +++ b/src/checkCommand.ts @@ -695,7 +695,7 @@ function describeViolation(violation: Violation, exceeded: string, checksChange: switch (violation.kind) { case 'project': { const remedy = checksChange - ? `; this change edits tests while test code exceeds ${violation.exceeded[0]?.limit}% of production code: keep a test it adds only when the project's test rule justifies it, and delete or merge the others; once every test it adds is justified, the violation needs no further change` + ? `; this change edits tests while test code exceeds ${violation.exceeded[0]?.limit}% of production code: keep a test it adds only when the project's test rule justifies it, and delete or merge the others` : `, ${violation.excessTestNcss} above the strictest limit; review the tests against the project's test rule and delete or merge those it does not justify`; return `${violation.file}: ${exceeded}, test NCSS ${violation.testNcss} of production NCSS ${violation.productionNcss}${remedy}`; } diff --git a/src/thresholds.ts b/src/thresholds.ts index 45b2060..3659eb7 100644 --- a/src/thresholds.ts +++ b/src/thresholds.ts @@ -138,7 +138,7 @@ export const testShareThreshold: Threshold = { metric: 'testNcssPercent', label: 'test NCSS percent', defaultLimits: { warning: 30, error: Infinity }, - hint: "review the tests the violation names (with --base, those the change adds) against the project's test rule and delete or merge those it does not justify; a share still above the limit after that needs no further change.", + hint: "review the tests the violation names (with --base, those the change adds) against the project's test rule and delete or merge those it does not justify.", measure: ({ testNcss, productionNcss }) => (testNcss * 100) / productionNcss, }; From 3625e9886be3d1b703bd71b1c2e93f6f509a0fbf Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Wed, 25 Nov 2026 16:12:42 +0900 Subject: [PATCH 8/8] docs: describe the test share sample as checkouts and 30 as just below its median Co-authored-by: WillBooster (Claude Code) --- README.md | 4 ++-- docs/threshold-calibration.md | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4dbbfd0..e59ab21 100644 --- a/README.md +++ b/README.md @@ -147,8 +147,8 @@ thresholds that are off, nesting depth flags no function that cognitive complexi cyclomatic complexity and Halstead difficulty flag functions rated like unflagged ones; Halstead volume, Halstead effort, and DepDegree are high mostly where a function is long or takes many parameters, which the limits above already flag. -The `testNcssPercent` default is a warning at the median test share, in NCSS, of 62 of the -organization's repositories, and no error: no ratings back it, so it asks for a review of the tests +The `testNcssPercent` default is a warning just below the median test share in NCSS (31.6%) of 62 +checkouts of the organization's repositories on one developer's machine, and no error: no ratings back it, so it asks for a review of the tests rather than marking code to fix. [How the default thresholds were calibrated](docs/threshold-calibration.md) holds the corpus, the distributions per language, the ratings, and the reasoning per threshold. diff --git a/docs/threshold-calibration.md b/docs/threshold-calibration.md index cf69797..5f49c2c 100644 --- a/docs/threshold-calibration.md +++ b/docs/threshold-calibration.md @@ -325,8 +325,8 @@ November 2026 from the 50 WillBooster repositories on a developer's machine whos exceeds 3,000 lines: their test code, counted in lines rather than NCSS, was 33% of their production code at the median. -The share was then measured in NCSS on the 62 WillBooster repositories on one developer's machine -whose production NCSS is at least 1,000 (the sample includes second clones and forks), with +The share was then measured in NCSS on the 62 checkouts of WillBooster repositories on one +developer's machine whose production NCSS is at least 1,000 (second clones and forks among them), with `check` of code-gauge 11.1.0 reporting every share as a warning: | Percentile | Test NCSS percent | @@ -335,10 +335,10 @@ whose production NCSS is at least 1,000 (the sample includes second clones and f | 75th | 60.8 | | 90th | 76.2 | -32 of the 62 (52%) are above 30%, and 17 (27%) above 60%. A limit of 30 thus sits at the median in -NCSS too. No ratings tell whether a share above it holds tests worth deleting, so it is a warning, +32 of the 62 (52%) are above 30%, and 17 (27%) above 60%. A limit of 30 thus sits just below the +median in NCSS too. No ratings tell whether a share above it holds tests worth deleting, so it is a warning, which marks code worth simplifying when it is touched, and not an error, which would mark half of -these repositories as code to fix: exceeding it asks for a review of the tests against the +these checkouts as code to fix: exceeding it asks for a review of the tests against the project's test rule. ## Duplicated blocks measured in matched lines