docs(tools): widen the 182 reachability shape and finish the note's two language-binding facts

"Reachable only through a raw register() whose parameters is
array-rooted" was too narrow. A root oneOf reaches the same 182: the
union arm propagates listDepth unchanged because `A | B` opens no
bracket, so an array branch starts its chain at 0 exactly as an array
root does. Say "root opens an array chain -- rooted at the array, or at
an array branch of a root oneOf", in the JSDoc and the test comment,
and assert the union shape alongside the array-rooted one.

The note's Decision paragraph said the flavor guard is reached under
"a language that has a renderer but no flavor entry, and a test covers
it". The test uses ruby, absent from both tables, and the mechanism is
that schemas() reaches run_code's getters without passing
requireCodeRuntime -- so any language absent from the flavor table hits
it. State that instead.

The Consequences paragraph recorded the language-binding obligation as
two reads, assembly and execution. Within one projection there are more:
run_code's description and parameters getters each call
resolveFlavor(peekRuntime()) and schemaOf destructures both, so a reload
between them yields one schema whose halves name different languages.
This commit is contained in:
Chinesezjc
2026-08-05 19:37:11 +08:00
parent b44acab888
commit 015bef2f5f
5 changed files with 23 additions and 12 deletions

View File

@@ -191,9 +191,11 @@ const MAX_CLASS_NAME_BASE = 120
* - Argument annotation, `async def f(self, args: chain) -> Y:` — the `(` IS
* still open around it: 180 `list[` plus `Literal[` plus the paren, 182, the
* worst case. Reachable only through a raw `register()` whose `parameters`
* is array-rooted; `defineTool` compiles an object root, so the annotation
* is a bare TypedDict class name or `dict[str, Any]` — neither carries a
* chain.
* root opens an array chain — rooted at the array, or at an array branch of
* a root `oneOf`, which inherits the enclosing depth because a union adds no
* brackets. `defineTool` compiles an object root, so the annotation is a
* bare TypedDict class name or a one-bracket `dict[str, Any]` when that
* object degrades — never a chain.
*
* A CPython grammar limit, not a deployment choice, so it is fixed rather than
* configurable. The sibling `ts-types` renderer needs no counterpart: nothing

View File

@@ -575,9 +575,11 @@ describe('renderToolsSdkPy', () => {
it('caps the argument annotation, the site whose enclosing paren stays open', () => {
// The worst of the three emission sites: the parameter list's `(` is still
// open around this annotation, so 180 `list[` plus the innermost bracket
// plus that paren is 182 of CPython's 200. Only a raw `register()` reaches
// it — `defineTool` compiles an object root, whose annotation is a bare
// TypedDict name or `dict[str, Any]`, neither of which carries a chain.
// plus that paren is 182 of CPython's 200. Only a raw `register()` whose
// `parameters` root opens an array chain reaches it — rooted at the array,
// or at an array branch of a root `oneOf`, since a union adds no brackets.
// `defineTool` compiles an object root, whose annotation is a bare
// TypedDict name or a one-bracket `dict[str, Any]`, never a chain.
const rooted = (depth: number): ToolSdkSchema => {
let schema: Record<string, unknown> = { type: 'string', const: 'x' }
for (let i = 0; i < depth; i++) schema = { type: 'array', items: schema }
@@ -596,6 +598,13 @@ describe('renderToolsSdkPy', () => {
// rather than on another `list[`, so the count cannot grow past that.
expect(renderToolsSdkPy([rooted(181)]))
.toContain(`async def rooted(self, args: ${'list['.repeat(180)}Any${']'.repeat(180)}) -> str:`)
// A root union reaches the same 182: its branches inherit the enclosing
// depth because `A | B` opens nothing, so the chain under one of them
// starts at 0 exactly as the array-rooted case does.
const union = { ...rooted(180), parameters: { oneOf: [rooted(180).parameters, { type: 'string' }] } }
const text = renderToolsSdkPy([union])
expect(text).toContain(`args: ${'list['.repeat(180)}Literal["x"]${']'.repeat(180)} | str) -> str:`)
expect(text.split('async def rooted(self, args: ')[1]!.split(') -> str:')[0]!.split('[').length - 1).toBe(181)
})
it('renders a deeply nested oneOf chain in linear time (no per-level re-materialization)', () => {