3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-19 14:45:44 +01:00

Answer architecture round 2: every builder joins its pieces through one bounded join, the readers take the engine guard, every refusal stands at the document's path, and a portable list's refusal names its own place

This commit is contained in:
2026-10-12 17:42:24 +02:00
committed by Lillem4n
parent 2b5d22cbc6
commit 3414c8690a
25 changed files with 379 additions and 249 deletions
-39
View File
@@ -4,12 +4,6 @@ import { fileURLToPath } from 'node:url'
import { readFileSync, readdirSync } from 'node:fs'
import test from 'node:test'
import { success, withinEngineLimits, type Result } from './result.ts'
function code(result: Result<string>): string {
return result.ok ? `converted ${result.value}` : result.error.code
}
const sourceRoot = dirname(fileURLToPath(import.meta.url))
const union = /export type ConvertErrorCode =\n((?:\s+\| '[a-z-]+'\n)+)/
const declared = /'([a-z-]+)'/g
@@ -35,36 +29,3 @@ function calledCodes(): string[] {
test('every ConvertErrorCode is the code of a production call site, and every call site names a declared one', () => {
assert.deepEqual(calledCodes(), declaredCodes())
})
test('refuses where the engine runs out of string or array, and lets a stack overflow or any other throw through', () => {
const overflow = new Error('allocation size overflow')
overflow.name = 'InternalError'
assert.deepEqual(
withinEngineLimits(() => {
throw overflow
}),
{ error: { code: 'unsupported-node-shape', message: 'the output would be longer than the longest string or array this JavaScript engine builds (allocation size overflow)', path: [] }, ok: false },
)
assert.equal(
code(
withinEngineLimits(() => {
throw new RangeError('Invalid array length')
}),
),
'unsupported-node-shape',
)
assert.throws(() =>
withinEngineLimits(() => {
throw new RangeError('Maximum call stack size exceeded')
}),
)
assert.throws(() =>
withinEngineLimits(() => {
throw new TypeError('a bug')
}),
)
assert.deepEqual(
withinEngineLimits(() => success('x')),
{ ok: true, value: 'x' },
)
})