johnandersen777.bsky.social/knotless
git that lives in your Atmosphere account
Forked from chadtmiller.com/knotless
0
0
// Holds every write the app makes, as ios/ModelCheck made them, to its method's
// lexicon: a procedure of that name, given what it takes. So a name or field
// that drifts fails here, and not on someone's phone. What a procedure then does
// with them is tested with the pages' own flows (harness/e2e/flows.spec.mjs).
import { readFileSync, readdirSync } from 'node:fs'
import { createRequire } from 'node:module'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
const root = dirname(dirname(fileURLToPath(import.meta.url)))
const { Lexicons } = createRequire(join(root, 'harness/package.json'))('@atproto/lexicon')
const dir = join(root, 'lexicons/dev/knotless')
const docs = readdirSync(dir, { recursive: true }).filter((f) => f.endsWith('.json')).map((f) => JSON.parse(readFileSync(join(dir, f), 'utf8')))
const lexicons = new Lexicons(docs)
let failed = 0
const writes = JSON.parse(readFileSync(process.argv[2], 'utf8'))
for (const { method, input } of writes) {
const nsid = `dev.knotless.${method}`
try {
if (lexicons.getDef(nsid)?.type !== 'procedure') throw new Error('no such procedure')
lexicons.assertValidXrpcInput(nsid, input)
} catch (e) {
console.log(`${nsid} ${JSON.stringify(input)}\n ${e.message}`)
failed++
}
}
console.log(`${writes.length} writes held to their lexicons, ${failed} not`)
if (failed) process.exit(1)