Skip to content

Commit ece5faa

Browse files
fix(lint): warn on a stdio MCP auth that reaches nothing and on a credential typed into transport.credentialEnv (#29664)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8NWPXiR9AzY9UmgJXftg6QH)_ Fixes #29607 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:`connector-credential-literal` 提示规则新增两条警告。一条是 stdio 的 `mcp` 连接器声明了 `bearer` / `api-key` / `basic` 的 `auth` 却没写 `transport.credentialEnv`,凭据被解析后被丢掉;另一条是 `transport.credentialEnv` 里填的像密钥而不是环境变量名。 - 为什么改:作者声明的凭据静默无效,没人告诉作者(#29607 第 1 项,路线 A);`credentialEnv` 会在每次元数据读取时原样返回,误填的密钥会被读出(增补评论 6590066946 第 2 项)。 - 风险与回滚:只加警告,任何保存与启动都不被拒,接受集不变。回滚即 revert 本 PR。 - 先看:`packages/lint/src/lint-connector-credential-literals.ts` 末尾两段新判断;`packages/lint/src/credential-literal.ts` 新函数 `isCredentialShapedName`(防误报的门槛);`rule-explanations.ts` 新段落。 - 两分钟验证:`pnpm --filter @objectstack/lint exec vitest run --maxWorkers=2 src/lint-connector-credential-literals.test.ts src/credential-literal.test.ts`,预期全部通过。 - 需要你做的:无,席位落地。 ## What changes Route A of the card, plus item 2 of addendum 6590066946. Both are warnings on the existing `connector-credential-literal` advisory; no accept set moves, nothing is refused, and `packages/connectors/connector-mcp/src/mcp-provider.ts` is not touched. - **Item 1, a stdio `auth` that reaches nothing** (`lint-connector-credential-literals.ts`). A `provider: 'mcp'` entry whose `providerConfig.transport.kind` is `'stdio'`, with a static `auth` (`bearer`, `api-key` or `basic`) and no `transport.credentialEnv`, draws one warning at `connectors[N].auth`. The message says the credential reaches nothing and names `transport.credentialEnv`. The hint gives the key to add, and says to drop `auth` when the server takes no credential, because an unresolved reference still degrades the instance. Not drawn: an entry that has `credentialEnv`; `auth: { type: 'none' }`; the grant-bearing kinds (`oauth2`, `app-credential`), which the provider already refuses loudly at boot on stdio; an http transport; and a provider other than `mcp`. - **Item 2, a credential in `transport.credentialEnv`.** The existing predicate cannot judge this slot. `isCredentialShapedLiteral('credentialEnv', v)` is true for every non-blank `v`, because R1 reads the key and `credentialEnv` contains the segment `credential`. Judging the value as a name is no better: `GITHUB_TOKEN` draws too. So `credential-literal.ts`, the predicate's one home, gains a sibling, `isCredentialShapedName(value)`. It reuses the R2 auth-scheme pattern and the template pattern, and reads no name list. A value draws when it opens with an auth scheme (`Bearer …`), or when it has a run of 16 or more letters and digits that switches between the two at least four times, the way a generated token does. A conventional name never draws. That includes long capital names with no digits (`ABCDEFGHIJKLMNOPQRSTUVWXY`), names with underscores, and names with one or two digit groups (`SERVICEACCOUNTTOKEN2`, `PROD2024REPOSITORYTOKEN`); the seat asked for those pins. The trade-off is that a token written in letters only does not draw. The finding sits at `connectors[N].providerConfig.transport.credentialEnv`, on any transport (the key is stored and served either way), and never echoes the value. The function is not on the package entry, so the public surface is byte-unchanged. - `rule-explanations.ts`: one new paragraph in `os explain connector-credential-literal` for the two route findings. - `.changeset/29607-stdio-auth-unplaced-advisory.md`: `@objectstack/lint` patch, both declaration lines. ## Why The card's measurement and the order's hypothesis, reproduced on `origin/main` 3482f3d: - **Boot, through the automation service.** This was a scratch copy of the `declarative stdio instance through the automation service` harness in `mcp-stdio-credential-env.test.ts`, with `credentialEnv` removed, and it was deleted after the run. The resolver was asked for the reference (`asked= ["OS_TEST_MCP_STDIO_CREDENTIAL_REF"]`). The instance came up `state= ready` with no degraded reason, and the spawned child reported `unset:0`: the credential never reached it, and nothing said so. The provider-level control (`control: the same instance with no credentialEnv …`) passes the same way. - **Lint, before.** `lintConnectorCredentialLiterals` returned `[]` for both shapes: a stdio `bearer` entry with no `credentialEnv`, and a `credentialEnv` holding a token-shaped value. - **Count: 0.** No shipped template or example declares a static `auth` on a stdio `mcp` instance. I checked `examples/**`, the `create-objectstack` templates, `content/docs/**` and `skills/**` here, plus `objectstack-ai/hotcrm` and `objectstack-ai/docs.objectos.ai`. The one shipped stdio instance (`examples/app-showcase` `showcase_mcp_tools`) declares `auth: { type: 'none' }`, and the docs' stdio example carries `credentialEnv`. So route A breaks nothing and changes no current output. Option B would also have had no producer to migrate, but it stays a ruling's call, as the card says. ## Tests - New pins in `lint-connector-credential-literals.test.ts`: - each static kind on stdio draws exactly one warning at `auth`, with the exact message; - controls for `credentialEnv` set, `none`, `oauth2`, `app-credential`, no `auth`, http and a non-`mcp` provider; - an env literal beside an unplaced `auth` draws both findings, once each; - `credentialEnv` holding a token run or a `Bearer …` value draws at that key, never echoes it, and draws on http too; - four correct names draw nothing; - one sentence each, at most 210 characters; - the runtime publish gate case for `connector`; - three new facts in the `os explain` entry. - New pins in `credential-literal.test.ts`: why `isCredentialShapedLiteral` cannot answer this; 11 correct names that never draw; 5 values that draw; templates, blanks and non-strings draw nothing. - `pnpm --filter @objectstack/lint test && pnpm --filter @objectstack/lint typecheck` under the lock on 9bb1b84: Test Files 192 passed (192), Tests 7924 passed (7924), `tsc --noEmit` and `check:test-typecheck` clean, VERDICT command-exit 0. <details><summary>Ablations on 9bb1b84: tests import the rule from src, so no build leg; each through scripts/ablation-replace.mjs, restored to the HEAD blob with an empty git diff HEAD</summary> - Delete `transport.credentialEnv === undefined &&` (the item 1 guard): 8 failed / 23 passed. The `credentialEnv`-set control and the correct-name pins go red. - The item 1 condition forced false (anchor `transport.credentialEnv === undefined &&` → `false &&`): 6 failed / 25 passed. Every item 1 pin, and the runtime door case, goes red. - `if (isCredentialShapedName(transport.credentialEnv))` → `if (false)`: 4 failed / 27 passed (the item 2 pins). - `alternations(run) >= MIN_TOKEN_ALTERNATIONS` → `>= 0` (the false-positive floor): 7 failed / 86 passed. Every long-capital-name pin goes red in both files. - The first attempt at the item 1 ablation was a no-op that the tool refused: its anchor was a substring of its replacement, so the count did not drop. It was redone with the anchor above. </details> ## Acceptance notes - One rule id, deliberately. Both route findings ride `connector-credential-literal`, because they are about where that rule's steer sends the credential. They need no new registry row, door wiring or explain entry. `authoring-rules.ts` is untouched, and its row comment still reads "four header/env maps". That is now incomplete, but it is not false. - `content/docs/automation/connectors.mdx` ("A stdio transport that names no `credentialEnv` does not apply `auth`") is still true. It could add that the advisory now reports this. That is outside this PR's file surface. - `skills/objectstack-automation/references/integration-recipes.md` recipe 6 still says "a `stdio` server's credentials ride `transport.env`". That predates `credentialEnv`, and it steers toward the literal the advisory warns on. `skills/**` is a governed surface, so this PR leaves it alone (carrier: none, noted for the seat). ## Verification <details><summary>Derived gates on 9bb1b84</summary> - `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` on 9bb1b84: 57 families, from 6 paths vs merge base 3482f3d (+318/-6). The runner ran each one once and captured its exit code before any pipe. 56 exited 0. - `check-plugin-teardown-shape.mjs --self-test` exited 3 on the first round, because its pinned positive control `621a4876` was not in the shallow clone. After `git fetch origin 621a487` it exited 0 (48 cases pass). - `pnpm check:dual-build-cjs-loads` exited 3 (PREREQUISITE NOT MET: the workspace is not fully built). NOT MEASURED locally; CI runs it on a full build. - `dispatch-gates --ran` reconciled: 57 derived, 56 run, 1 NOT-MEASURED (dual-build, from its recorded exit 3), 0 UNRUN. - `pnpm lint` (repo-wide eslint, `--no-inline-config`) on 9bb1b84 exited 0. - The branch is 4 commits behind `origin/main` e0187d0. None of them touches `packages/lint`, `packages/connectors` or any derivation input (the `--ran` banner says the same), so I did not merge main. - The lint package's dependency closure plus `@objectstack/connector-mcp`'s were built under the lock (VERDICT command-exit 0) before the tests and the reproduction ran. </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (No spec change.) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: n/a. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. --- _Generated by [Claude Code](https://claude.ai/code/session_01JQwxbaSFr2XhX4m1qEAiXy)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent 9dd93d0 commit ece5faa

6 files changed

Lines changed: 318 additions & 6 deletions
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/lint': patch
3+
---
4+
5+
Clause-②: no
6+
Metadata-protocol: none
7+
8+
fix(lint): `connector-credential-literal` now also warns when a stdio MCP server's credential goes nowhere, or when a credential is typed into `transport.credentialEnv`
9+
10+
Two new findings on the existing advisory. Both are warnings, so nothing is refused and every save still lands. They reach `os validate`, `os build`, `os lint` and the connector save door (`PUT /meta/connector/:name`), the same doors the rule already runs on.
11+
12+
- **A stdio `auth` that reaches nothing.** Take a `provider: 'mcp'` entry with a stdio transport and a `bearer`, `api-key` or `basic` `auth`, but no `providerConfig.transport.credentialEnv`. Its reference is still resolved, and a missing one still degrades the instance. But the provider hands the credential to a stdio server only in the variable `credentialEnv` names, so the credential was dropped and nothing said so. The finding sits at `auth` and names the fix. Add `credentialEnv`, or drop `auth` if the server takes no credential:
13+
14+
```ts
15+
providerConfig: { transport: { kind: 'stdio', command: 'repo-mcp-server', credentialEnv: 'REPO_MCP_TOKEN' } },
16+
auth: { type: 'bearer', credentialRef: 'REPO_MCP_TOKEN' },
17+
```
18+
19+
- **A credential in `transport.credentialEnv`.** That key holds the name of an environment variable, and it is served on every metadata read. The rule now warns when the value reads as a credential instead of a name. That means it opens with an auth scheme (`Bearer …`), or it has a run of 16 or more letters and digits that switches between the two at least four times, the way a generated token does. A conventional name such as `REPO_MCP_TOKEN`, or a long capital name, never draws. The finding names the key and never echoes the value.

‎packages/lint/src/credential-literal.test.ts‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { dirname, join } from 'node:path';
1414
import { fileURLToPath } from 'node:url';
1515
import { describe, expect, it } from 'vitest';
1616

17-
import { isCredentialShapedLiteral } from './credential-literal.js';
17+
import { isCredentialShapedLiteral, isCredentialShapedName } from './credential-literal.js';
1818
import * as barrel from './index.js';
1919

2020
const SRC = dirname(fileURLToPath(import.meta.url));
@@ -87,6 +87,48 @@ describe('isCredentialShapedLiteral — what is NOT a literal credential', () =>
8787
});
8888
});
8989

90+
describe('isCredentialShapedName — a credential where a variable NAME belongs', () => {
91+
it('cannot be answered by isCredentialShapedLiteral: its R1 judges the key, and the key reads as a credential', () => {
92+
// Why the sibling exists: under `credentialEnv` every value draws, the
93+
// correct name included.
94+
expect(isCredentialShapedLiteral('credentialEnv', 'REPO_MCP_TOKEN')).toBe(true);
95+
expect(isCredentialShapedLiteral('REPO_MCP_TOKEN', 'x')).toBe(true);
96+
});
97+
98+
it.each([
99+
'REPO_MCP_TOKEN',
100+
'GITHUB_TOKEN',
101+
'OS_TEST_MCP_STDIO_CREDENTIAL_REF',
102+
// Long capital names: no digits, underscores, one or two digits.
103+
'ABCDEFGHIJKLMNOPQRSTUVWXY',
104+
'GITHUBPERSONALACCESSTOKENFORTHEREPOSERVER',
105+
'SERVICE_ACCOUNT_ACCESS_TOKEN_FOR_PRODUCTION_USE',
106+
'SERVICEACCOUNTTOKEN2',
107+
'PROD2024REPOSITORYTOKEN',
108+
'REPO_MCP_TOKEN_V2_2024_EU_WEST_1',
109+
'repoMcpTokenForProduction',
110+
'S3_BUCKET_K8S_OAUTH2_TOKEN',
111+
])('a correct name %s never draws', (name) => {
112+
expect(isCredentialShapedName(name)).toBe(false);
113+
});
114+
115+
it.each([
116+
'probe7sentinel3value9token5x',
117+
'PROBE7SENTINEL3VALUE9TOKEN5X',
118+
'probe_7a8b9c0d1e2f3a4b5c6d_sentinel',
119+
'Bearer probe-sentinel',
120+
'token probe-sentinel',
121+
])('a value %j that reads as a credential draws', (value) => {
122+
expect(isCredentialShapedName(value)).toBe(true);
123+
});
124+
125+
it('a template, a blank value and a non-string value draw nothing', () => {
126+
for (const value of ['{{ probe7sentinel3value9token5x }}', '{probe7sentinel3value9token5x}', '', ' ', undefined, null, 42, true, ['x'], { v: 'x' }]) {
127+
expect(isCredentialShapedName(value), JSON.stringify(value)).toBe(false);
128+
}
129+
});
130+
});
131+
90132
describe('one predicate, one home', () => {
91133
it('is exported from the package entry', () => {
92134
expect((barrel as Record<string, unknown>).isCredentialShapedLiteral).toBe(isCredentialShapedLiteral);

‎packages/lint/src/credential-literal.ts‎

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@
5959
* The name lists below are module-private and read by
6060
* {@link isCredentialShapedLiteral} alone. ⛔ Never copy them into a rule, a
6161
* test helper, the CLI or a runtime: a second list is a second rule, and the
62-
* two drift. A caller that needs the verdict asks this function.
62+
* two drift. A caller that needs the verdict asks this function. Its sibling
63+
* {@link isCredentialShapedName} judges a value written where a variable NAME
64+
* belongs, reads no name list, and shares the R2 and template patterns.
6365
*
6466
* ## A heuristic — so its callers ADVISE, never refuse
6567
*
@@ -142,3 +144,53 @@ export function isCredentialShapedLiteral(name: string, value: unknown): boolean
142144
if (PLATFORM_TEMPLATE.test(value)) return false;
143145
return isCredentialName(name) || AUTH_SCHEME_VALUE.test(value);
144146
}
147+
148+
/**
149+
* A run of letters and digits long enough to be a generated token. Shorter
150+
* runs are the words of an ordinary name (`REPO_MCP_TOKEN`).
151+
*/
152+
const TOKEN_RUN = /[A-Za-z0-9]{16,}/g;
153+
154+
/**
155+
* How often a token run must switch between a letter and a digit. A generated
156+
* token interleaves the two; a name made of words does not, however long it
157+
* is (`SERVICEACCOUNTTOKEN2` switches once).
158+
*/
159+
const MIN_TOKEN_ALTERNATIONS = 4;
160+
161+
/** How many times `run` switches between a digit and a letter. */
162+
function alternations(run: string): number {
163+
let count = 0;
164+
for (let i = 1; i < run.length; i++) {
165+
if (/\d/.test(run[i]!) !== /\d/.test(run[i - 1]!)) count++;
166+
}
167+
return count;
168+
}
169+
170+
/**
171+
* `true` when a value written where a NAME belongs — the name of an
172+
* environment variable, such as an `mcp` stdio transport's `credentialEnv` —
173+
* reads as a credential instead: it opens with an auth scheme and a credential
174+
* (R2), or it carries a run of 16 or more letters and digits that switches
175+
* between the two at least four times, as a generated token does.
176+
*
177+
* {@link isCredentialShapedLiteral} cannot answer this: its R1 judges the KEY
178+
* a value sits under, and a key that holds a variable name reads as a
179+
* credential by design (`credentialEnv`, `GITHUB_TOKEN`). This judges the value
180+
* alone. A conventional name never draws: its words are separated by `_`, and a
181+
* word run of capitals, however long, has no digits to switch to. A token
182+
* written in letters only does not draw either, which is the price of never
183+
* warning on a correct name.
184+
*
185+
* @example
186+
* isCredentialShapedName('REPO_MCP_TOKEN') // false (a name)
187+
* isCredentialShapedName('ABCDEFGHIJKLMNOPQRSTUVWXY') // false (no digits)
188+
* isCredentialShapedName('probe7sentinel3value9token5x') // true (a token run)
189+
* isCredentialShapedName('Bearer abc') // true (R2)
190+
*/
191+
export function isCredentialShapedName(value: unknown): boolean {
192+
if (typeof value !== 'string' || value.trim() === '') return false;
193+
if (PLATFORM_TEMPLATE.test(value)) return false;
194+
if (AUTH_SCHEME_VALUE.test(value)) return true;
195+
return (value.match(TOKEN_RUN) ?? []).some((run) => alternations(run) >= MIN_TOKEN_ALTERNATIONS);
196+
}

‎packages/lint/src/lint-connector-credential-literals.test.ts‎

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,112 @@ describe('connector-credential-literal — what draws nothing', () => {
215215
});
216216
});
217217

218+
/** A stdio `mcp` entry routed through `auth.credentialRef`, with the transport keys it is given. */
219+
const stdioAuthEntry = (auth: Record<string, unknown>, transport: Record<string, unknown> = {}) => ({
220+
name: 'repo_tools',
221+
label: 'Repo Tools',
222+
type: 'api',
223+
provider: 'mcp',
224+
providerConfig: { transport: { kind: 'stdio', command: 'repo-mcp-server', env: { LOG_LEVEL: 'info' }, ...transport } },
225+
auth,
226+
});
227+
228+
/** A probe sentinel shaped like a generated token, never a credential. */
229+
const TOKEN_SHAPED = 'probe7sentinel3value9token5x';
230+
231+
describe('connector-credential-literal — a stdio credential that reaches nothing', () => {
232+
it.each([
233+
['bearer', { type: 'bearer', credentialRef: 'REPO_MCP_TOKEN' }],
234+
['api-key', { type: 'api-key', headerName: 'X-Api-Key', credentialRef: 'REPO_MCP_KEY' }],
235+
['basic', { type: 'basic', username: 'service-user', credentialRef: 'REPO_MCP_PASSWORD' }],
236+
] as const)('a %s auth on a stdio transport with no credentialEnv draws one warning at `auth`', (kind, auth) => {
237+
const findings = lintConnectorCredentialLiterals({ connectors: [stdioAuthEntry(auth)] });
238+
expect(findings.map((f) => [f.path, f.severity, f.rule, f.where])).toEqual([
239+
['connectors[0].auth', 'warning', CONNECTOR_CREDENTIAL_LITERAL, "connector 'repo_tools'"],
240+
]);
241+
expect(findings[0]!.message).toBe(
242+
`auth '${kind}' reaches nothing: a stdio transport passes the resolved credential to the server only in the `
243+
+ 'variable `transport.credentialEnv` names, and this entry names none',
244+
);
245+
expect(findings[0]!.hint).toContain("credentialEnv: 'VARIABLE_NAME'");
246+
expect(findings[0]!.hint).toContain('drop `auth`');
247+
});
248+
249+
it('draws nothing once credentialEnv places it, for a kind the provider refuses loudly, off stdio, or off mcp', () => {
250+
const quiet = [
251+
stdioAuthEntry({ type: 'bearer', credentialRef: 'REPO_MCP_TOKEN' }, { credentialEnv: 'REPO_MCP_TOKEN' }),
252+
stdioAuthEntry({ type: 'none' }),
253+
stdioAuthEntry({ type: 'oauth2', grant: 'client_credentials', tokenUrl: 'https://x.invalid/token', clientId: 'c', credentialRef: 'R' }),
254+
stdioAuthEntry({ type: 'app-credential', credentialRef: 'R' }),
255+
{ ...stdioAuthEntry({ type: 'bearer', credentialRef: 'R' }), auth: undefined },
256+
{
257+
...stdioAuthEntry({ type: 'bearer', credentialRef: 'R' }),
258+
providerConfig: { transport: { kind: 'http', url: 'https://mcp.vendor.invalid/mcp' } },
259+
},
260+
{ ...stdioAuthEntry({ type: 'bearer', credentialRef: 'R' }), provider: 'custom_stdio' },
261+
];
262+
for (const [i, entry] of quiet.entries()) {
263+
expect(lintConnectorCredentialLiterals({ connectors: [entry] }), `case ${i}`).toEqual([]);
264+
}
265+
});
266+
267+
it('beside an env literal, each finding is drawn once at its own path', () => {
268+
const entry = stdioAuthEntry({ type: 'bearer', credentialRef: 'REPO_MCP_TOKEN' }, { env: { GITHUB_TOKEN: S.env } });
269+
expect(lintConnectorCredentialLiterals({ connectors: [entry] }).map((f) => f.path)).toEqual([
270+
'connectors[0].providerConfig.transport.env.GITHUB_TOKEN',
271+
'connectors[0].auth',
272+
]);
273+
});
274+
});
275+
276+
describe('connector-credential-literal — a credential typed into transport.credentialEnv', () => {
277+
it.each([TOKEN_SHAPED, 'Bearer probe-sentinel'])('a credentialEnv that reads as a credential (%j) draws one warning at that key', (value) => {
278+
const entry = stdioAuthEntry({ type: 'bearer', credentialRef: 'REPO_MCP_TOKEN' }, { credentialEnv: value });
279+
const findings = lintConnectorCredentialLiterals({ connectors: [entry] });
280+
expect(findings.map((f) => [f.path, f.severity])).toEqual([
281+
['connectors[0].providerConfig.transport.credentialEnv', 'warning'],
282+
]);
283+
expect(findings[0]!.message).toBe(
284+
'providerConfig.transport.credentialEnv reads as a credential, not a variable name, and is served on every '
285+
+ 'metadata read; put the secret behind `auth.credentialRef` and name its variable here',
286+
);
287+
expect(findings[0]!.hint).toContain("auth: { type: 'bearer', credentialRef }");
288+
expect(JSON.stringify(findings).includes(value)).toBe(false);
289+
});
290+
291+
it('is judged whatever the transport, since the key is stored and served either way', () => {
292+
const entry = {
293+
...stdioAuthEntry({ type: 'bearer', credentialRef: 'R' }),
294+
providerConfig: { transport: { kind: 'http', url: 'https://mcp.vendor.invalid/mcp', credentialEnv: TOKEN_SHAPED } },
295+
};
296+
expect(lintConnectorCredentialLiterals({ connectors: [entry] }).map((f) => f.path)).toEqual([
297+
'connectors[0].providerConfig.transport.credentialEnv',
298+
]);
299+
});
300+
301+
it.each(['REPO_MCP_TOKEN', 'ABCDEFGHIJKLMNOPQRSTUVWXY', 'SERVICE_ACCOUNT_ACCESS_TOKEN_FOR_PRODUCTION_USE', 'PROD2024REPOSITORYTOKEN'])(
302+
'a correct variable name %s never draws',
303+
(name) => {
304+
const entry = stdioAuthEntry({ type: 'bearer', credentialRef: 'REPO_MCP_TOKEN' }, { credentialEnv: name });
305+
expect(lintConnectorCredentialLiterals({ connectors: [entry] })).toEqual([]);
306+
},
307+
);
308+
309+
it('both route findings read as one sentence each', () => {
310+
const findings = lintConnectorCredentialLiterals({
311+
connectors: [
312+
stdioAuthEntry({ type: 'basic', username: 'u', credentialRef: 'R' }),
313+
stdioAuthEntry({ type: 'bearer', credentialRef: 'R' }, { credentialEnv: TOKEN_SHAPED }),
314+
],
315+
});
316+
expect(findings).toHaveLength(2);
317+
for (const f of findings) {
318+
expect(f.message.includes('\n'), f.path).toBe(false);
319+
expect(f.message.length, f.path).toBeLessThanOrEqual(210);
320+
}
321+
});
322+
});
323+
218324
describe('connector-credential-literal — the four maps are the redactor\'s', () => {
219325
it('judges exactly the maps the connector read path withholds whole', () => {
220326
// The spec does not export its map list, so it is read through the
@@ -274,6 +380,14 @@ describe('connector-credential-literal — registered once, at every door, as an
274380
]);
275381
});
276382

383+
it('reaches the runtime publish gate for a stdio connector whose auth reaches nothing', () => {
384+
const result = runRuntimeAuthoringRules({ type: 'connector', item: stdioAuthEntry({ type: 'bearer', credentialRef: 'REPO_MCP_TOKEN' }) });
385+
expect(result.errors.filter((f) => f.rule === CONNECTOR_CREDENTIAL_LITERAL)).toEqual([]);
386+
expect(result.advisories.filter((f) => f.rule === CONNECTOR_CREDENTIAL_LITERAL).map((f) => f.path)).toEqual([
387+
'connectors[0].auth',
388+
]);
389+
});
390+
277391
it('a routed connector write draws none at the runtime gate', () => {
278392
const result = runRuntimeAuthoringRules({ type: 'connector', item: routedStack().connectors[0] });
279393
expect(result.advisories.filter((f) => f.rule === CONNECTOR_CREDENTIAL_LITERAL)).toEqual([]);
@@ -300,6 +414,9 @@ describe('connector-credential-literal — `os explain`', () => {
300414
'a heuristic',
301415
'A `{variable}` template is not a literal',
302416
'never the value itself',
417+
'the credential reaches nothing',
418+
'served on every metadata read',
419+
'A conventional name such as `REPO_MCP_TOKEN` never draws',
303420
]) {
304421
expect(text, `explanation names ${fact}`).toContain(fact);
305422
}

0 commit comments

Comments
 (0)