diff --git a/src/markdown/opaque-carry.ts b/src/markdown/opaque-carry.ts index a332b50..9d5db85 100644 --- a/src/markdown/opaque-carry.ts +++ b/src/markdown/opaque-carry.ts @@ -38,7 +38,7 @@ export function readCarriedInline(span: DirectiveSpan): Read | undefine function carriedJson(node: AdfNode, spelling: JsonSpelling, path: ConvertErrorPath, levels: number): Result { 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)) } @@ -50,7 +50,7 @@ function readCarriedJson(raw: string, spelling: JsonSpelling, levels: number): R if (!isJsonValue(value, levels)) { // 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') } - 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) { const shape = spelling === 'compact' ? 'compact, keys sorted' : 'two-space indent, keys sorted' diff --git a/src/markdown/parse/markdown-to-adf.test.ts b/src/markdown/parse/markdown-to-adf.test.ts index 5c44ba2..b93f805 100644 --- a/src/markdown/parse/markdown-to-adf.test.ts +++ b/src/markdown/parse/markdown-to-adf.test.ts @@ -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', () => { 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 deeper = `unsupported-nesting-depth: a carried node's JSON nests the input deeper than the ${largestNesting} levels the parser carries` - assert.equal(content(markdownToAdf(`:adf{json="${nested(largestNesting + 2)}"}\n`)), deeper) - assert.equal(code(markdownToAdf(fence('', largestNesting + 1))), 'unsupported-node-shape') - assert.equal(content(markdownToAdf(fence('> ', largestNesting + 1))), deeper) + 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(largestNesting)) + assert.equal( + 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', () => {