@@ -1238,6 +1238,64 @@ function noteFrom(map, token, clause) {
12381238 set . add ( clause ) ;
12391239}
12401240
1241+ /**
1242+ * Is this quoted span identifier-shaped enough to mint a `literal` anchor?
1243+ *
1244+ * FOUR SHAPES. Three of them say "an identifier starts lowercase" — snake_case,
1245+ * camelCase, a dotted client path. A quoted English word (`'ignore'`, `'utf8'`) is not a
1246+ * surface anyone documents by that spelling, and those three keep it out.
1247+ *
1248+ * THE FOURTH IS SCREAMING_SNAKE, AND IT IS HERE TO END A DISAGREEMENT (#13471). While the
1249+ * three lowercase-initial shapes were the whole rule, this predicate and `isCodeShaped`
1250+ * contradicted each other on every constant name: `isCodeShaped('OS_MODE')` is `true` —
1251+ * pinned as `SCREAMING_SNAKE` in the shape cases below since the guard was written — while
1252+ * this test declined to mint an anchor from it at all. One predicate in the pair called the
1253+ * token an identifier, the other silently called it prose, and nothing reported the split.
1254+ * A page that names env vars and essentially nothing else (`deployment/environment-variables.mdx`)
1255+ * has no other `literal` route onto an advisory.
1256+ *
1257+ * The fourth shape is earned by the same argument that earns `PHRASE_ANCHOR_KINDS` its
1258+ * exemption — DISTINCTIVE BY CONSTRUCTION, not by inspection. `OS_TENANCY_POSTURE` cannot
1259+ * be the English word this guard exists to drop: prose does not shout in underscores. Note
1260+ * the shape is MULTI-SEGMENT by construction (the `_` is required), so a bare all-caps word
1261+ * is not admitted by it — see the deliberate-disagreement pins in `--self-test`.
1262+ *
1263+ * MEASURED BOTH WAYS before widening, over the 60 most recent `packages/**` commits, using
1264+ * the per-row provenance #12824 published so each added row could be attributed to the
1265+ * declaration that minted it rather than counted in a lump:
1266+ * - rows 374 -> 383 (+9, +2.4%), and ZERO rows lost;
1267+ * - `overbroadAnchors` 8 -> 8: the corpus-share guard caught no new hub term, so the
1268+ * widening minted no term broad enough to need catching;
1269+ * - only 2 of the 60 runs moved at all. Every new anchor named its declaration:
1270+ * `FlowRefusalCode`, `AUTHZ_STORE_UNAVAILABLE_CODE`, `codes`.
1271+ * - GROUND TRUTH on `b6d3d76b5`, whose own commit edited three docs pages: the advisory
1272+ * went from 0 of those 3 (it listed two `releases/**` pages and nothing else) to 2 of 3
1273+ * — `api/client-sdk.mdx` and `automation/flows.mdx`, both minted from `FlowRefusalCode`.
1274+ * - the four vendor codes in that window (`ER_DUP_KEYNAME` and friends, from a MySQL
1275+ * driver table) minted anchors and matched NO page, so they cost nothing: an anchor
1276+ * no doc names is not a row.
1277+ *
1278+ * BLAST RADIUS, KEPT HONEST. `4d98d9eab` is the commit this was found on, and the widening
1279+ * adds ZERO rows there: `environment-variables.mdx` was already listed through the `route`
1280+ * anchor `/api/v1/runtime/config`, so all the fourth shape adds is a second `via` clause
1281+ * saying `OS_TELEMETRY_CLIENT_ERROR_REPORTING_ENABLED` also pointed at it. The recall win is
1282+ * real and it is `b6d3d76b5`-shaped, not `4d98d9eab`-shaped.
1283+ *
1284+ * DO NOT COLLAPSE THIS INTO `isCodeShaped`. It looks like the same question and it is not,
1285+ * because the two run over DIFFERENT POPULATIONS: `isCodeShaped` judges a token already
1286+ * known to be a declaration NAME, while this one judges an arbitrary quoted span, which may
1287+ * be prose someone quoted. Measured on the same 60 commits, delegating this test to
1288+ * `isCodeShaped` gives rows 374 -> 408 (+9.1%, versus +2.4%) and admits `'unchanged.'`,
1289+ * `'means.'` and `'version.'` — sentence fragments that reach `isCodeShaped`'s `.` arm.
1290+ * Those three are pinned as non-anchors in `--self-test` so the collapse goes red.
1291+ */
1292+ function isLiteralAnchorShape ( lit ) {
1293+ return / ^ [ a - z ] [ a - z 0 - 9 ] * (?: _ [ a - z 0 - 9 ] + ) + $ / . test ( lit ) // snake_case
1294+ || / ^ [ a - z ] + (?: [ A - Z ] [ A - Z a - z 0 - 9 ] * ) + $ / . test ( lit ) // camelCase
1295+ || / ^ [ a - z ] [ a - z 0 - 9 ] * (?: \. [ a - z ] [ A - Z a - z 0 - 9 ] * ) + $ / . test ( lit ) // a dotted client path
1296+ || / ^ [ A - Z ] [ A - Z 0 - 9 ] * (?: _ [ A - Z 0 - 9 ] + ) + $ / . test ( lit ) ; // SCREAMING_SNAKE (#13471)
1297+ }
1298+
12411299/** Route tails and identifier-shaped string literals appearing on the changed lines. */
12421300function literalAnchorsFromLines ( lines , changed ) {
12431301 const routes = new Set ( ) ;
@@ -1266,9 +1324,7 @@ function literalAnchorsFromLines(lines, changed) {
12661324 for ( const m of line . matchAll ( / [ ' " ] ( [ A - Z a - z ] [ \w . $ - ] { 3 , 63 } ) [ ' " ] / g) ) {
12671325 const lit = m [ 1 ] ;
12681326 if ( GENERIC_ANCHOR_NAMES . has ( lit . toLowerCase ( ) ) ) continue ;
1269- // Identifier-shaped only: snake_case, camelCase or dotted. A quoted English word
1270- // ('ignore', 'utf8') is not a surface anyone documents by that spelling.
1271- if ( ! / ^ [ a - z ] [ a - z 0 - 9 ] * (?: _ [ a - z 0 - 9 ] + ) + $ / . test ( lit ) && ! / ^ [ a - z ] + (?: [ A - Z ] [ A - Z a - z 0 - 9 ] * ) + $ / . test ( lit ) && ! / ^ [ a - z ] [ a - z 0 - 9 ] * (?: \. [ a - z ] [ A - Z a - z 0 - 9 ] * ) + $ / . test ( lit ) ) continue ;
1327+ if ( ! isLiteralAnchorShape ( lit ) ) continue ;
12721328 literals . add ( lit ) ;
12731329 const where = enclosingName ( ) ;
12741330 noteFrom ( from , lit , where ? `a string literal in ${ where } ` : 'a string literal on a changed line' ) ;
@@ -4348,15 +4404,50 @@ function selfTest() {
43484404 check ( 'PHRASE_ANCHOR_KINDS' , 'a rule expression is distinctive by construction' , 'rule' , true , PHRASE_ANCHOR_KINDS . has ( 'rule' ) ) ;
43494405
43504406 // String literals on a changed line: an identifier-shaped one is surface, English is not.
4351- const litLines = [ " if (rule === 'controlled_by_parent') return maskFieldValue(v);" , " fs.readFileSync(p, 'utf8');" , " logger.warn('ignore');" ] ;
4352- const lits = literalAnchorsFromLines ( litLines , [ 1 , 2 , 3 ] ) . literals ;
4407+ const litLines = [ " if (rule === 'controlled_by_parent') return maskFieldValue(v);" , " fs.readFileSync(p, 'utf8');" , " logger.warn('ignore');" ,
4408+ " const ENV = 'OS_TENANCY_POSTURE';" , " if (c === 'FLOW_NO_START_NODE') return refuse(c);" ,
4409+ " // the shape is 'unchanged.' in that arm" , " throw new Error('EEXIT');" ] ;
4410+ const lits = literalAnchorsFromLines ( litLines , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ) . literals ;
43534411 const literalCases = [
43544412 [ 'controlled_by_parent' , true , 'a snake_case literal IS an authoring surface' ] ,
43554413 [ 'utf8' , false , 'an encoding name is not surface' ] ,
43564414 [ 'ignore' , false , 'an English word is not surface' ] ,
4415+ // #13471. The env-var name is the case the whole card was filed on: a page that names
4416+ // env vars and essentially nothing else has no other `literal` route onto an advisory.
4417+ [ 'OS_TENANCY_POSTURE' , true , 'a SCREAMING_SNAKE env-var name IS an authoring surface' ] ,
4418+ [ 'FLOW_NO_START_NODE' , true , 'and so is a refusal code — the measured recall win' ] ,
4419+ // ⛔ The guard rail on the widening, both halves measured on the same 60 commits.
4420+ [ 'unchanged.' , false , 'a quoted sentence fragment is still not surface' ] ,
4421+ [ 'EEXIT' , false , 'a bare all-caps word is not SCREAMING_SNAKE — the shape needs a segment break' ] ,
43574422 ] ;
43584423 for ( const [ lit , want , label ] of literalCases ) check ( 'literalAnchorsFromLines' , label , lit , want , lits . has ( lit ) ) ;
43594424
4425+ // ── THE PAIR MUST AGREE ON SCREAMING_SNAKE (#13471) ──
4426+ // The defect this closed was not "recall too low", it was TWO PREDICATES CONTRADICTING
4427+ // each other with nothing reporting the split: `isCodeShaped` called `OS_MODE` an
4428+ // identifier (pinned in `shapeCases` above) while `literalAnchorsFromLines` declined to
4429+ // mint any anchor from it. Pin the agreement itself, so neither side can drift back out
4430+ // of step silently — a check on one predicate alone could not have caught this.
4431+ for ( const t of [ 'OS_CLOUD_URL' , 'OS_MODE' , 'OS_TENANCY_POSTURE' , 'ERROR_CODE_LEDGER' , 'FLOW_INPUT_SCHEMA_INVALID' ] ) {
4432+ check ( 'isCodeShaped/isLiteralAnchorShape' , 'the pair agrees on a SCREAMING_SNAKE token' , t ,
4433+ true , isCodeShaped ( t ) === isLiteralAnchorShape ( t ) && isLiteralAnchorShape ( t ) ) ;
4434+ }
4435+
4436+ // ⛔ AND THE DISAGREEMENTS THAT REMAIN ARE DELIBERATE, so the next reader does not
4437+ // "finish the job" by collapsing this test into `isCodeShaped`. The two run over
4438+ // DIFFERENT POPULATIONS — a declaration NAME versus an arbitrary quoted span that may be
4439+ // prose — and delegating measured rows 374 -> 408 (+9.1%, versus +2.4% for the shape
4440+ // above) on the same 60 commits. These three fragments are what it admits.
4441+ const deliberateSplits = [
4442+ [ 'unchanged.' , 'a sentence fragment reaches isCodeShaped through its `.` arm' ] ,
4443+ [ 'means.' , 'ditto — measured, not hypothetical' ] ,
4444+ [ 'version.' , 'ditto' ] ,
4445+ [ 'IHttpRequest' , 'a PascalCase name is already reachable through the `symbol` kind' ] ,
4446+ ] ;
4447+ for ( const [ t , label ] of deliberateSplits ) {
4448+ check ( 'isCodeShaped/isLiteralAnchorShape' , label , t , true , isCodeShaped ( t ) && ! isLiteralAnchorShape ( t ) ) ;
4449+ }
4450+
43604451 // ── `computedOn` (#9519): the record that names WHICH TREE the answer is about ──
43614452 // Pinned on the pure shaper, so these stay hermetic; the probing wrapper reads real
43624453 // git state by construction. Two properties carry the field's whole value: a merge
0 commit comments