Name the budget the carry's depth message applies, and pin the canonical refusal it met
CI / gate (push) Successful in 9s

This commit is contained in:
2026-09-03 08:09:40 +02:00
parent 4d0ad3728c
commit 85ec1cd35c
2 changed files with 9 additions and 6 deletions
+2 -2
View File
@@ -38,7 +38,7 @@ export function readCarriedInline(span: DirectiveSpan): Read<AdfNode> | undefine
function carriedJson(node: AdfNode, spelling: JsonSpelling, path: ConvertErrorPath, levels: number): Result<string> { function carriedJson(node: AdfNode, spelling: JsonSpelling, path: ConvertErrorPath, levels: number): Result<string> {
if (!isJsonValue(node, levels)) { if (!isJsonValue(node, levels)) {
return failure('unsupported-nesting-depth', `a carried node's JSON nests the document deeper than the ${largestNesting} levels the emitter carries`, path) return failure('unsupported-nesting-depth', `a carried node's JSON nests deeper than the ${levels} levels its position leaves`, path)
} }
return success(serializeCanonicalJson(node, spelling)) return success(serializeCanonicalJson(node, spelling))
} }
@@ -50,7 +50,7 @@ function readCarriedJson(raw: string, spelling: JsonSpelling, levels: number): R
if (!isJsonValue(value, levels)) { if (!isJsonValue(value, levels)) {
// Unbounded, the same walk parts the two causes one `false` holds (AGENTS.md §8). // Unbounded, the same walk parts the two causes one `false` holds (AGENTS.md §8).
if (!isJsonValue(value, Number.POSITIVE_INFINITY)) return { fault: unsupportedNodeShape('the opaque carry holds a number JSON cannot spell') } if (!isJsonValue(value, Number.POSITIVE_INFINITY)) return { fault: unsupportedNodeShape('the opaque carry holds a number JSON cannot spell') }
return { fault: { code: 'unsupported-nesting-depth', message: `a carried node's JSON nests the input deeper than the ${largestNesting} levels the parser carries` } } return { fault: { code: 'unsupported-nesting-depth', message: `a carried node's JSON nests deeper than the ${levels} levels its position leaves` } }
} }
if (serializeCanonicalJson(value, spelling) !== raw) { if (serializeCanonicalJson(value, spelling) !== raw) {
const shape = spelling === 'compact' ? 'compact, keys sorted' : 'two-space indent, keys sorted' const shape = spelling === 'compact' ? 'compact, keys sorted' : 'two-space indent, keys sorted'
+7 -4
View File
@@ -315,10 +315,13 @@ test('names the shape the inline carry reads alone', () => {
test('holds a carried JSON value to the nesting its position leaves', () => { test('holds a carried JSON value to the nesting its position leaves', () => {
const nested = (levels: number): string => `${'['.repeat(levels)}${']'.repeat(levels)}` const nested = (levels: number): string => `${'['.repeat(levels)}${']'.repeat(levels)}`
const fence = (prefix: string, levels: number): string => `${prefix}\`\`\`adf\n${prefix}${nested(levels)}\n${prefix}\`\`\`\n` const fence = (prefix: string, levels: number): string => `${prefix}\`\`\`adf\n${prefix}${nested(levels)}\n${prefix}\`\`\`\n`
const deeper = `unsupported-nesting-depth: a carried node's JSON nests the input deeper than the ${largestNesting} levels the parser carries` const deeper = (levels: number): string => `unsupported-nesting-depth: a carried node's JSON nests deeper than the ${levels} levels its position leaves`
assert.equal(content(markdownToAdf(`:adf{json="${nested(largestNesting + 2)}"}\n`)), deeper) assert.equal(content(markdownToAdf(`:adf{json="${nested(largestNesting + 2)}"}\n`)), deeper(largestNesting))
assert.equal(code(markdownToAdf(fence('', largestNesting + 1))), 'unsupported-node-shape') assert.equal(
assert.equal(content(markdownToAdf(fence('> ', largestNesting + 1))), deeper) content(markdownToAdf(fence('', largestNesting + 1))),
"unsupported-node-shape: the opaque carry spells its node's JSON canonically: two-space indent, keys sorted",
)
assert.equal(content(markdownToAdf(fence('> ', largestNesting + 1))), deeper(largestNesting - 1))
}) })
test('names the number no JSON spelling carries in an opaque carry', () => { test('names the number no JSON spelling carries in an opaque carry', () => {